blob: d3e4366acee4fe6ef51eaaa718718be6a7a22342 [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 Madillb9293972015-02-19 11:07:54 -050012#include <iterator>
13#include <sstream>
Sami Väisänene45e53b2016-05-25 10:36:04 +030014#include <string.h>
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"
Geoff Lang2b5420c2014-11-19 14:20:15 -050023#include "libANGLE/Fence.h"
24#include "libANGLE/Framebuffer.h"
25#include "libANGLE/FramebufferAttachment.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030026#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050027#include "libANGLE/Program.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050028#include "libANGLE/Query.h"
Jiawei-Shao2597fb62016-12-09 16:38:02 +080029#include "libANGLE/queryutils.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"
37#include "libANGLE/formatutils.h"
38#include "libANGLE/validationES.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070039#include "libANGLE/Workarounds.h"
Jamie Madill437fa652016-05-03 15:13:24 -040040#include "libANGLE/renderer/ContextImpl.h"
Jamie Madill53ea9cc2016-05-17 10:12:52 -040041#include "libANGLE/renderer/EGLImplFactory.h"
Martin Radev66fb8202016-07-28 11:45:20 +030042#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040043#include "libANGLE/queryutils.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000044
Geoff Langf6db0982015-08-25 13:04:00 -040045namespace
46{
47
Ian Ewell3ffd78b2016-01-22 16:09:42 -050048template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050049std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030050 GLsizei numPaths,
51 const void *paths,
52 GLuint pathBase)
53{
54 std::vector<gl::Path *> ret;
55 ret.reserve(numPaths);
56
57 const auto *nameArray = static_cast<const T *>(paths);
58
59 for (GLsizei i = 0; i < numPaths; ++i)
60 {
61 const GLuint pathName = nameArray[i] + pathBase;
62
63 ret.push_back(resourceManager.getPath(pathName));
64 }
65
66 return ret;
67}
68
Geoff Lang4ddf5af2016-12-01 14:30:44 -050069std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030070 GLsizei numPaths,
71 GLenum pathNameType,
72 const void *paths,
73 GLuint pathBase)
74{
75 switch (pathNameType)
76 {
77 case GL_UNSIGNED_BYTE:
78 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
79
80 case GL_BYTE:
81 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
82
83 case GL_UNSIGNED_SHORT:
84 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
85
86 case GL_SHORT:
87 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
88
89 case GL_UNSIGNED_INT:
90 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
91
92 case GL_INT:
93 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
94 }
95
96 UNREACHABLE();
97 return std::vector<gl::Path *>();
98}
99
100template <typename T>
Geoff Lang2186c382016-10-14 10:54:54 -0400101gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500102{
Geoff Lang2186c382016-10-14 10:54:54 -0400103 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500104
105 switch (pname)
106 {
107 case GL_QUERY_RESULT_EXT:
Geoff Lang2186c382016-10-14 10:54:54 -0400108 return query->getResult(params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500109 case GL_QUERY_RESULT_AVAILABLE_EXT:
110 {
111 bool available;
Geoff Lang2186c382016-10-14 10:54:54 -0400112 gl::Error error = query->isResultAvailable(&available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500113 if (!error.isError())
114 {
Geoff Lang2186c382016-10-14 10:54:54 -0400115 *params = gl::ConvertFromGLboolean<T>(available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500116 }
117 return error;
118 }
119 default:
120 UNREACHABLE();
121 return gl::Error(GL_INVALID_OPERATION, "Unreachable Error");
122 }
123}
124
Geoff Langf6db0982015-08-25 13:04:00 -0400125void MarkTransformFeedbackBufferUsage(gl::TransformFeedback *transformFeedback)
126{
Geoff Lang1a683462015-09-29 15:09:59 -0400127 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400128 {
129 for (size_t tfBufferIndex = 0; tfBufferIndex < transformFeedback->getIndexedBufferCount();
130 tfBufferIndex++)
131 {
132 const OffsetBindingPointer<gl::Buffer> &buffer =
133 transformFeedback->getIndexedBuffer(tfBufferIndex);
134 if (buffer.get() != nullptr)
135 {
136 buffer->onTransformFeedback();
137 }
138 }
139 }
140}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500141
142// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300143EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500144{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400145 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500146}
147
Martin Radev1be913c2016-07-11 17:59:16 +0300148EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
149{
150 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
151}
152
Geoff Langeb66a6e2016-10-31 13:06:12 -0400153gl::Version GetClientVersion(const egl::AttributeMap &attribs)
154{
155 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
156}
157
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500158GLenum GetResetStrategy(const egl::AttributeMap &attribs)
159{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400160 EGLAttrib attrib = attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT,
161 EGL_NO_RESET_NOTIFICATION_EXT);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500162 switch (attrib)
163 {
164 case EGL_NO_RESET_NOTIFICATION:
165 return GL_NO_RESET_NOTIFICATION_EXT;
166 case EGL_LOSE_CONTEXT_ON_RESET:
167 return GL_LOSE_CONTEXT_ON_RESET_EXT;
168 default:
169 UNREACHABLE();
170 return GL_NONE;
171 }
172}
173
174bool GetRobustAccess(const egl::AttributeMap &attribs)
175{
Geoff Lang077f20a2016-11-01 10:08:02 -0400176 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
177 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
178 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500179}
180
181bool GetDebug(const egl::AttributeMap &attribs)
182{
Geoff Lang077f20a2016-11-01 10:08:02 -0400183 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
184 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500185}
186
187bool GetNoError(const egl::AttributeMap &attribs)
188{
189 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
190}
191
Geoff Langc287ea62016-09-16 14:46:51 -0400192bool GetWebGLContext(const egl::AttributeMap &attribs)
193{
194 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
195}
196
Geoff Langf41a7152016-09-19 15:11:17 -0400197bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
198{
199 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
200}
201
Geoff Langfeb8c682017-02-13 16:07:35 -0500202bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
203{
204 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
205}
206
Martin Radev9d901792016-07-15 15:58:58 +0300207std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
208{
209 std::string labelName;
210 if (label != nullptr)
211 {
212 size_t labelLength = length < 0 ? strlen(label) : length;
213 labelName = std::string(label, labelLength);
214 }
215 return labelName;
216}
217
218void GetObjectLabelBase(const std::string &objectLabel,
219 GLsizei bufSize,
220 GLsizei *length,
221 GLchar *label)
222{
223 size_t writeLength = objectLabel.length();
224 if (label != nullptr && bufSize > 0)
225 {
226 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
227 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
228 label[writeLength] = '\0';
229 }
230
231 if (length != nullptr)
232 {
233 *length = static_cast<GLsizei>(writeLength);
234 }
235}
236
Geoff Langf6db0982015-08-25 13:04:00 -0400237} // anonymous namespace
238
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000239namespace gl
240{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000241
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400242Context::Context(rx::EGLImplFactory *implFactory,
243 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400244 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500245 TextureManager *shareTextures,
Corentin Wallezc295e512017-01-27 17:47:50 -0500246 const egl::AttributeMap &attribs,
247 const egl::DisplayExtensions &displayExtensions)
Martin Radev1be913c2016-07-11 17:59:16 +0300248
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500249 : ValidationContext(shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500250 shareTextures,
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500251 GetClientVersion(attribs),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700252 &mGLState,
Jamie Madillf25855c2015-11-03 11:06:18 -0500253 mCaps,
254 mTextureCaps,
255 mExtensions,
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500256 mLimitations,
257 GetNoError(attribs)),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700258 mImplementation(implFactory->createContext(mState)),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500259 mCompiler(nullptr),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400260 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500261 mClientType(EGL_OPENGL_ES_API),
262 mHasBeenCurrent(false),
263 mContextLost(false),
264 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700265 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500266 mResetStrategy(GetResetStrategy(attribs)),
267 mRobustAccess(GetRobustAccess(attribs)),
Corentin Wallezccab69d2017-01-27 16:57:15 -0500268 mCurrentSurface(nullptr),
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500269 mSurfacelessFramebuffer(nullptr),
270 mWebGLContext(GetWebGLContext(attribs))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000271{
Geoff Lang077f20a2016-11-01 10:08:02 -0400272 if (mRobustAccess)
273 {
274 UNIMPLEMENTED();
275 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000276
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500277 initCaps(displayExtensions);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700278 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400279
Geoff Langeb66a6e2016-10-31 13:06:12 -0400280 mGLState.initialize(mCaps, mExtensions, getClientVersion(), GetDebug(attribs),
Geoff Langfeb8c682017-02-13 16:07:35 -0500281 GetBindGeneratesResource(attribs), GetClientArraysEnabled(attribs));
Régis Fénéon83107972015-02-05 12:57:44 +0100282
Shannon Woods53a94a82014-06-24 15:20:36 -0400283 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400284
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000285 // [OpenGL ES 2.0.24] section 3.7 page 83:
286 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have twodimensional
287 // and cube map texture state vectors respectively associated with them.
288 // In order that access to these initial textures not be lost, they are treated as texture
289 // objects all of whose names are 0.
290
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400291 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500292 mZeroTextures[GL_TEXTURE_2D].set(zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500293
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400294 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, GL_TEXTURE_CUBE_MAP);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500295 mZeroTextures[GL_TEXTURE_CUBE_MAP].set(zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400296
Geoff Langeb66a6e2016-10-31 13:06:12 -0400297 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400298 {
299 // TODO: These could also be enabled via extension
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400300 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, GL_TEXTURE_3D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500301 mZeroTextures[GL_TEXTURE_3D].set(zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400302
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400303 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_ARRAY);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500304 mZeroTextures[GL_TEXTURE_2D_ARRAY].set(zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400305 }
Geoff Lang3b573612016-10-31 14:08:10 -0400306 if (getClientVersion() >= Version(3, 1))
307 {
308 Texture *zeroTexture2DMultisample =
309 new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_MULTISAMPLE);
310 mZeroTextures[GL_TEXTURE_2D_MULTISAMPLE].set(zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800311
312 bindGenericAtomicCounterBuffer(0);
313 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
314 {
315 bindIndexedAtomicCounterBuffer(0, i, 0, 0);
316 }
Geoff Lang3b573612016-10-31 14:08:10 -0400317 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000318
Ian Ewellbda75592016-04-18 17:25:54 -0400319 if (mExtensions.eglImageExternal || mExtensions.eglStreamConsumerExternal)
320 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400321 Texture *zeroTextureExternal =
322 new Texture(mImplementation.get(), 0, GL_TEXTURE_EXTERNAL_OES);
Ian Ewellbda75592016-04-18 17:25:54 -0400323 mZeroTextures[GL_TEXTURE_EXTERNAL_OES].set(zeroTextureExternal);
324 }
325
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700326 mGLState.initializeZeroTextures(mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500327
Jamie Madill57a89722013-07-02 11:57:03 -0400328 bindVertexArray(0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000329 bindArrayBuffer(0);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800330 bindDrawIndirectBuffer(0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000331 bindElementArrayBuffer(0);
Geoff Lang76b10c92014-09-05 16:28:14 -0400332
Jamie Madill01a80ee2016-11-07 12:06:18 -0500333 bindRenderbuffer(GL_RENDERBUFFER, 0);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000334
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000335 bindGenericUniformBuffer(0);
Geoff Lang4dc3af02016-11-18 14:09:27 -0500336 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +0000337 {
338 bindIndexedUniformBuffer(0, i, 0, -1);
339 }
340
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000341 bindCopyReadBuffer(0);
342 bindCopyWriteBuffer(0);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +0000343 bindPixelPackBuffer(0);
344 bindPixelUnpackBuffer(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000345
Geoff Langeb66a6e2016-10-31 13:06:12 -0400346 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400347 {
348 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
349 // In the initial state, a default transform feedback object is bound and treated as
350 // a transform feedback object with a name of zero. That object is bound any time
351 // BindTransformFeedback is called with id of zero
Geoff Lang1a683462015-09-29 15:09:59 -0400352 bindTransformFeedback(0);
353 }
Geoff Langc8058452014-02-03 12:04:11 -0500354
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700355 mCompiler = new Compiler(mImplementation.get(), mState);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500356
357 // Initialize dirty bit masks
358 // TODO(jmadill): additional ES3 state
359 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_ALIGNMENT);
360 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_ROW_LENGTH);
361 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_IMAGE_HEIGHT);
362 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_IMAGES);
363 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_ROWS);
364 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_PIXELS);
Corentin Wallezbbd663a2016-04-20 17:49:17 -0400365 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500366 // No dirty objects.
367
368 // Readpixels uses the pack state and read FBO
369 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_ALIGNMENT);
370 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_REVERSE_ROW_ORDER);
371 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_ROW_LENGTH);
372 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_SKIP_ROWS);
373 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_SKIP_PIXELS);
Corentin Wallezbbd663a2016-04-20 17:49:17 -0400374 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500375 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
376
377 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
378 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
379 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
380 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
381 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
382 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
383 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
384 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
385 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
386 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
387 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
388 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
389
390 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
391 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700392 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500393 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
394 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400395
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400396 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000397}
398
Jamie Madill70ee0f62017-02-06 16:04:20 -0500399void Context::destroy(egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000400{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500401 mGLState.reset(this);
Geoff Lang21329412014-12-02 20:50:30 +0000402
Corentin Wallez80b24112015-08-25 16:41:57 -0400403 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000404 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400405 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000406 }
407
Corentin Wallez80b24112015-08-25 16:41:57 -0400408 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000409 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400410 if (query.second != nullptr)
411 {
412 query.second->release();
413 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000414 }
415
Corentin Wallez80b24112015-08-25 16:41:57 -0400416 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400417 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400418 SafeDelete(vertexArray.second);
Jamie Madill57a89722013-07-02 11:57:03 -0400419 }
420
Corentin Wallez80b24112015-08-25 16:41:57 -0400421 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500422 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500423 if (transformFeedback.second != nullptr)
424 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500425 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500426 }
Geoff Langc8058452014-02-03 12:04:11 -0500427 }
428
Jamie Madilldedd7b92014-11-05 16:30:36 -0500429 for (auto &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400430 {
Jamie Madilldedd7b92014-11-05 16:30:36 -0500431 zeroTexture.second.set(NULL);
Geoff Lang76b10c92014-09-05 16:28:14 -0400432 }
433 mZeroTextures.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000434
Corentin Wallezccab69d2017-01-27 16:57:15 -0500435 SafeDelete(mSurfacelessFramebuffer);
436
Jamie Madill70ee0f62017-02-06 16:04:20 -0500437 releaseSurface(display);
Corentin Wallez51706ea2015-08-07 14:39:22 -0400438
Geoff Lang492a7e42014-11-05 13:27:06 -0500439 SafeDelete(mCompiler);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500440
441 mState.mBuffers->release(this);
442 mState.mShaderPrograms->release(this);
443 mState.mTextures->release(this);
444 mState.mRenderbuffers->release(this);
445 mState.mSamplers->release(this);
446 mState.mFenceSyncs->release(this);
447 mState.mPaths->release(this);
448 mState.mFramebuffers->release(this);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000449}
450
Jamie Madill70ee0f62017-02-06 16:04:20 -0500451Context::~Context()
452{
453}
454
455void Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000456{
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000457 if (!mHasBeenCurrent)
458 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000459 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500460 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400461 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000462
Corentin Wallezc295e512017-01-27 17:47:50 -0500463 int width = 0;
464 int height = 0;
465 if (surface != nullptr)
466 {
467 width = surface->getWidth();
468 height = surface->getHeight();
469 }
470
471 mGLState.setViewportParams(0, 0, width, height);
472 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000473
474 mHasBeenCurrent = true;
475 }
476
Jamie Madill1b94d432015-08-07 13:23:23 -0400477 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700478 mGLState.setAllDirtyBits();
Jamie Madill1b94d432015-08-07 13:23:23 -0400479
Jamie Madill70ee0f62017-02-06 16:04:20 -0500480 releaseSurface(display);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500481
482 Framebuffer *newDefault = nullptr;
483 if (surface != nullptr)
484 {
Jamie Madill70ee0f62017-02-06 16:04:20 -0500485 surface->setIsCurrent(display, true);
Corentin Wallezccab69d2017-01-27 16:57:15 -0500486 mCurrentSurface = surface;
487 newDefault = surface->getDefaultFramebuffer();
488 }
489 else
490 {
491 if (mSurfacelessFramebuffer == nullptr)
492 {
493 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
494 }
495
496 newDefault = mSurfacelessFramebuffer;
497 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000498
Corentin Wallez37c39792015-08-20 14:19:46 -0400499 // Update default framebuffer, the binding of the previous default
500 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400501 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700502 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400503 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700504 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400505 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700506 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400507 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700508 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400509 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500510 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400511 }
Ian Ewell292f0052016-02-04 10:37:32 -0500512
513 // Notify the renderer of a context switch
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700514 mImplementation->onMakeCurrent(mState);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000515}
516
Jamie Madill70ee0f62017-02-06 16:04:20 -0500517void Context::releaseSurface(egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400518{
Corentin Wallez37c39792015-08-20 14:19:46 -0400519 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500520 Framebuffer *currentDefault = nullptr;
521 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400522 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500523 currentDefault = mCurrentSurface->getDefaultFramebuffer();
524 }
525 else if (mSurfacelessFramebuffer != nullptr)
526 {
527 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400528 }
529
Corentin Wallezc295e512017-01-27 17:47:50 -0500530 if (mGLState.getReadFramebuffer() == currentDefault)
531 {
532 mGLState.setReadFramebufferBinding(nullptr);
533 }
534 if (mGLState.getDrawFramebuffer() == currentDefault)
535 {
536 mGLState.setDrawFramebufferBinding(nullptr);
537 }
538 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
539
540 if (mCurrentSurface)
541 {
Jamie Madill70ee0f62017-02-06 16:04:20 -0500542 mCurrentSurface->setIsCurrent(display, false);
Corentin Wallezc295e512017-01-27 17:47:50 -0500543 mCurrentSurface = nullptr;
544 }
Jamie Madill77a72f62015-04-14 11:18:32 -0400545}
546
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000547GLuint Context::createBuffer()
548{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500549 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000550}
551
552GLuint Context::createProgram()
553{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500554 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000555}
556
557GLuint Context::createShader(GLenum type)
558{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500559 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000560}
561
562GLuint Context::createTexture()
563{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500564 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000565}
566
567GLuint Context::createRenderbuffer()
568{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500569 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000570}
571
Geoff Lang882033e2014-09-30 11:26:07 -0400572GLsync Context::createFenceSync()
Jamie Madillcd055f82013-07-26 11:55:15 -0400573{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500574 GLuint handle = mState.mFenceSyncs->createFenceSync(mImplementation.get());
Jamie Madillcd055f82013-07-26 11:55:15 -0400575
Cooper Partind8e62a32015-01-29 15:21:25 -0800576 return reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madillcd055f82013-07-26 11:55:15 -0400577}
578
Sami Väisänene45e53b2016-05-25 10:36:04 +0300579GLuint Context::createPaths(GLsizei range)
580{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500581 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300582 if (resultOrError.isError())
583 {
584 handleError(resultOrError.getError());
585 return 0;
586 }
587 return resultOrError.getResult();
588}
589
Jamie Madill57a89722013-07-02 11:57:03 -0400590GLuint Context::createVertexArray()
591{
Geoff Lang36167ab2015-12-07 10:27:14 -0500592 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
593 mVertexArrayMap[vertexArray] = nullptr;
594 return vertexArray;
Jamie Madill57a89722013-07-02 11:57:03 -0400595}
596
Jamie Madilldc356042013-07-19 16:36:57 -0400597GLuint Context::createSampler()
598{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500599 return mState.mSamplers->createSampler();
Jamie Madilldc356042013-07-19 16:36:57 -0400600}
601
Geoff Langc8058452014-02-03 12:04:11 -0500602GLuint Context::createTransformFeedback()
603{
Geoff Lang36167ab2015-12-07 10:27:14 -0500604 GLuint transformFeedback = mTransformFeedbackAllocator.allocate();
605 mTransformFeedbackMap[transformFeedback] = nullptr;
606 return transformFeedback;
Geoff Langc8058452014-02-03 12:04:11 -0500607}
608
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000609// Returns an unused framebuffer name
610GLuint Context::createFramebuffer()
611{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500612 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000613}
614
Jamie Madill33dc8432013-07-26 11:55:05 -0400615GLuint Context::createFenceNV()
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000616{
Jamie Madill33dc8432013-07-26 11:55:05 -0400617 GLuint handle = mFenceNVHandleAllocator.allocate();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000618
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400619 mFenceNVMap[handle] = new FenceNV(mImplementation->createFenceNV());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000620
621 return handle;
622}
623
624// Returns an unused query name
625GLuint Context::createQuery()
626{
627 GLuint handle = mQueryHandleAllocator.allocate();
628
629 mQueryMap[handle] = NULL;
630
631 return handle;
632}
633
634void Context::deleteBuffer(GLuint buffer)
635{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500636 if (mState.mBuffers->getBuffer(buffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000637 {
638 detachBuffer(buffer);
639 }
Jamie Madill893ab082014-05-16 16:56:10 -0400640
Jamie Madill6c1f6712017-02-14 19:08:04 -0500641 mState.mBuffers->deleteObject(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000642}
643
644void Context::deleteShader(GLuint shader)
645{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500646 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000647}
648
649void Context::deleteProgram(GLuint program)
650{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500651 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000652}
653
654void Context::deleteTexture(GLuint texture)
655{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500656 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000657 {
658 detachTexture(texture);
659 }
660
Jamie Madill6c1f6712017-02-14 19:08:04 -0500661 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000662}
663
664void Context::deleteRenderbuffer(GLuint renderbuffer)
665{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500666 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000667 {
668 detachRenderbuffer(renderbuffer);
669 }
Jamie Madill893ab082014-05-16 16:56:10 -0400670
Jamie Madill6c1f6712017-02-14 19:08:04 -0500671 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000672}
673
Jamie Madillcd055f82013-07-26 11:55:15 -0400674void Context::deleteFenceSync(GLsync fenceSync)
675{
676 // The spec specifies the underlying Fence object is not deleted until all current
677 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
678 // and since our API is currently designed for being called from a single thread, we can delete
679 // the fence immediately.
Jamie Madill6c1f6712017-02-14 19:08:04 -0500680 mState.mFenceSyncs->deleteObject(this,
681 static_cast<GLuint>(reinterpret_cast<uintptr_t>(fenceSync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400682}
683
Sami Väisänene45e53b2016-05-25 10:36:04 +0300684void Context::deletePaths(GLuint first, GLsizei range)
685{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500686 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300687}
688
689bool Context::hasPathData(GLuint path) const
690{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500691 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300692 if (pathObj == nullptr)
693 return false;
694
695 return pathObj->hasPathData();
696}
697
698bool Context::hasPath(GLuint path) const
699{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500700 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300701}
702
703void Context::setPathCommands(GLuint path,
704 GLsizei numCommands,
705 const GLubyte *commands,
706 GLsizei numCoords,
707 GLenum coordType,
708 const void *coords)
709{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500710 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300711
712 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
713}
714
715void Context::setPathParameterf(GLuint path, GLenum pname, GLfloat value)
716{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500717 auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300718
719 switch (pname)
720 {
721 case GL_PATH_STROKE_WIDTH_CHROMIUM:
722 pathObj->setStrokeWidth(value);
723 break;
724 case GL_PATH_END_CAPS_CHROMIUM:
725 pathObj->setEndCaps(static_cast<GLenum>(value));
726 break;
727 case GL_PATH_JOIN_STYLE_CHROMIUM:
728 pathObj->setJoinStyle(static_cast<GLenum>(value));
729 break;
730 case GL_PATH_MITER_LIMIT_CHROMIUM:
731 pathObj->setMiterLimit(value);
732 break;
733 case GL_PATH_STROKE_BOUND_CHROMIUM:
734 pathObj->setStrokeBound(value);
735 break;
736 default:
737 UNREACHABLE();
738 break;
739 }
740}
741
742void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value) const
743{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500744 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300745
746 switch (pname)
747 {
748 case GL_PATH_STROKE_WIDTH_CHROMIUM:
749 *value = pathObj->getStrokeWidth();
750 break;
751 case GL_PATH_END_CAPS_CHROMIUM:
752 *value = static_cast<GLfloat>(pathObj->getEndCaps());
753 break;
754 case GL_PATH_JOIN_STYLE_CHROMIUM:
755 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
756 break;
757 case GL_PATH_MITER_LIMIT_CHROMIUM:
758 *value = pathObj->getMiterLimit();
759 break;
760 case GL_PATH_STROKE_BOUND_CHROMIUM:
761 *value = pathObj->getStrokeBound();
762 break;
763 default:
764 UNREACHABLE();
765 break;
766 }
767}
768
769void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
770{
771 mGLState.setPathStencilFunc(func, ref, mask);
772}
773
Jamie Madill57a89722013-07-02 11:57:03 -0400774void Context::deleteVertexArray(GLuint vertexArray)
775{
Geoff Lang36167ab2015-12-07 10:27:14 -0500776 auto iter = mVertexArrayMap.find(vertexArray);
777 if (iter != mVertexArrayMap.end())
Geoff Lang50b3fe82015-12-08 14:49:12 +0000778 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500779 VertexArray *vertexArrayObject = iter->second;
780 if (vertexArrayObject != nullptr)
781 {
782 detachVertexArray(vertexArray);
783 delete vertexArrayObject;
784 }
Geoff Lang50b3fe82015-12-08 14:49:12 +0000785
Geoff Lang36167ab2015-12-07 10:27:14 -0500786 mVertexArrayMap.erase(iter);
787 mVertexArrayHandleAllocator.release(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -0400788 }
789}
790
Jamie Madilldc356042013-07-19 16:36:57 -0400791void Context::deleteSampler(GLuint sampler)
792{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500793 if (mState.mSamplers->getSampler(sampler))
Jamie Madilldc356042013-07-19 16:36:57 -0400794 {
795 detachSampler(sampler);
796 }
797
Jamie Madill6c1f6712017-02-14 19:08:04 -0500798 mState.mSamplers->deleteObject(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -0400799}
800
Geoff Langc8058452014-02-03 12:04:11 -0500801void Context::deleteTransformFeedback(GLuint transformFeedback)
802{
Jamie Madill5fd0b2d2015-01-05 13:38:44 -0500803 auto iter = mTransformFeedbackMap.find(transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -0500804 if (iter != mTransformFeedbackMap.end())
805 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500806 TransformFeedback *transformFeedbackObject = iter->second;
807 if (transformFeedbackObject != nullptr)
808 {
809 detachTransformFeedback(transformFeedback);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500810 transformFeedbackObject->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500811 }
812
Geoff Lang50b3fe82015-12-08 14:49:12 +0000813 mTransformFeedbackMap.erase(iter);
Geoff Lang36167ab2015-12-07 10:27:14 -0500814 mTransformFeedbackAllocator.release(transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -0500815 }
816}
817
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000818void Context::deleteFramebuffer(GLuint framebuffer)
819{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500820 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000821 {
822 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000823 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500824
Jamie Madill6c1f6712017-02-14 19:08:04 -0500825 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000826}
827
Jamie Madill33dc8432013-07-26 11:55:05 -0400828void Context::deleteFenceNV(GLuint fence)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000829{
Jamie Madill4e25a0d2016-03-08 13:53:03 -0500830 auto fenceObject = mFenceNVMap.find(fence);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000831
Jamie Madill33dc8432013-07-26 11:55:05 -0400832 if (fenceObject != mFenceNVMap.end())
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000833 {
Jamie Madill33dc8432013-07-26 11:55:05 -0400834 mFenceNVHandleAllocator.release(fenceObject->first);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000835 delete fenceObject->second;
Jamie Madill33dc8432013-07-26 11:55:05 -0400836 mFenceNVMap.erase(fenceObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000837 }
838}
839
840void Context::deleteQuery(GLuint query)
841{
Jamie Madill4e25a0d2016-03-08 13:53:03 -0500842 auto queryObject = mQueryMap.find(query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000843 if (queryObject != mQueryMap.end())
844 {
845 mQueryHandleAllocator.release(queryObject->first);
846 if (queryObject->second)
847 {
848 queryObject->second->release();
849 }
850 mQueryMap.erase(queryObject);
851 }
852}
853
Geoff Lang70d0f492015-12-10 17:45:46 -0500854Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000855{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500856 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000857}
858
Jamie Madill570f7c82014-07-03 10:38:54 -0400859Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000860{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500861 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000862}
863
Geoff Lang70d0f492015-12-10 17:45:46 -0500864Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000865{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500866 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000867}
868
Jamie Madillcd055f82013-07-26 11:55:15 -0400869FenceSync *Context::getFenceSync(GLsync handle) const
870{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500871 return mState.mFenceSyncs->getFenceSync(
872 static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400873}
874
Jamie Madill57a89722013-07-02 11:57:03 -0400875VertexArray *Context::getVertexArray(GLuint handle) const
876{
877 auto vertexArray = mVertexArrayMap.find(handle);
Geoff Lang36167ab2015-12-07 10:27:14 -0500878 return (vertexArray != mVertexArrayMap.end()) ? vertexArray->second : nullptr;
Jamie Madill57a89722013-07-02 11:57:03 -0400879}
880
Jamie Madilldc356042013-07-19 16:36:57 -0400881Sampler *Context::getSampler(GLuint handle) const
882{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500883 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400884}
885
Geoff Langc8058452014-02-03 12:04:11 -0500886TransformFeedback *Context::getTransformFeedback(GLuint handle) const
887{
Geoff Lang36167ab2015-12-07 10:27:14 -0500888 auto iter = mTransformFeedbackMap.find(handle);
889 return (iter != mTransformFeedbackMap.end()) ? iter->second : nullptr;
Geoff Langc8058452014-02-03 12:04:11 -0500890}
891
Geoff Lang70d0f492015-12-10 17:45:46 -0500892LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
893{
894 switch (identifier)
895 {
896 case GL_BUFFER:
897 return getBuffer(name);
898 case GL_SHADER:
899 return getShader(name);
900 case GL_PROGRAM:
901 return getProgram(name);
902 case GL_VERTEX_ARRAY:
903 return getVertexArray(name);
904 case GL_QUERY:
905 return getQuery(name);
906 case GL_TRANSFORM_FEEDBACK:
907 return getTransformFeedback(name);
908 case GL_SAMPLER:
909 return getSampler(name);
910 case GL_TEXTURE:
911 return getTexture(name);
912 case GL_RENDERBUFFER:
913 return getRenderbuffer(name);
914 case GL_FRAMEBUFFER:
915 return getFramebuffer(name);
916 default:
917 UNREACHABLE();
918 return nullptr;
919 }
920}
921
922LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
923{
924 return getFenceSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
925}
926
Martin Radev9d901792016-07-15 15:58:58 +0300927void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
928{
929 LabeledObject *object = getLabeledObject(identifier, name);
930 ASSERT(object != nullptr);
931
932 std::string labelName = GetObjectLabelFromPointer(length, label);
933 object->setLabel(labelName);
934}
935
936void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
937{
938 LabeledObject *object = getLabeledObjectFromPtr(ptr);
939 ASSERT(object != nullptr);
940
941 std::string labelName = GetObjectLabelFromPointer(length, label);
942 object->setLabel(labelName);
943}
944
945void Context::getObjectLabel(GLenum identifier,
946 GLuint name,
947 GLsizei bufSize,
948 GLsizei *length,
949 GLchar *label) const
950{
951 LabeledObject *object = getLabeledObject(identifier, name);
952 ASSERT(object != nullptr);
953
954 const std::string &objectLabel = object->getLabel();
955 GetObjectLabelBase(objectLabel, bufSize, length, label);
956}
957
958void Context::getObjectPtrLabel(const void *ptr,
959 GLsizei bufSize,
960 GLsizei *length,
961 GLchar *label) const
962{
963 LabeledObject *object = getLabeledObjectFromPtr(ptr);
964 ASSERT(object != nullptr);
965
966 const std::string &objectLabel = object->getLabel();
967 GetObjectLabelBase(objectLabel, bufSize, length, label);
968}
969
Jamie Madilldc356042013-07-19 16:36:57 -0400970bool Context::isSampler(GLuint samplerName) const
971{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500972 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400973}
974
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500975void Context::bindArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000976{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500977 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700978 mGLState.setArrayBufferBinding(buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000979}
980
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800981void Context::bindDrawIndirectBuffer(GLuint bufferHandle)
982{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500983 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jiajia Qin9d7d0b12016-11-29 16:30:31 +0800984 mGLState.setDrawIndirectBufferBinding(buffer);
985}
986
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500987void Context::bindElementArrayBuffer(GLuint bufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000988{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500989 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700990 mGLState.getVertexArray()->setElementArrayBuffer(buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000991}
992
Jamie Madilldedd7b92014-11-05 16:30:36 -0500993void Context::bindTexture(GLenum target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000994{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500995 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000996
Jamie Madilldedd7b92014-11-05 16:30:36 -0500997 if (handle == 0)
998 {
999 texture = mZeroTextures[target].get();
1000 }
1001 else
1002 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001003 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -05001004 }
1005
1006 ASSERT(texture);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001007 mGLState.setSamplerTexture(target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +00001008}
1009
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001010void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001011{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001012 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1013 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001014 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001015}
1016
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001017void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001018{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001019 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1020 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001021 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001022}
1023
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001024void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001025{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001026 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001027 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001028}
1029
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001030void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001031{
Geoff Lang76b10c92014-09-05 16:28:14 -04001032 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001033 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001034 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001035 mGLState.setSamplerBinding(textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001036}
1037
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001038void Context::bindGenericUniformBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001039{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001040 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001041 mGLState.setGenericUniformBufferBinding(buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001042}
1043
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001044void Context::bindIndexedUniformBuffer(GLuint bufferHandle,
1045 GLuint index,
1046 GLintptr offset,
1047 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001048{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001049 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001050 mGLState.setIndexedUniformBufferBinding(index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001051}
1052
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001053void Context::bindGenericTransformFeedbackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001054{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001055 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001056 mGLState.getCurrentTransformFeedback()->bindGenericBuffer(buffer);
shannon.woods%transgaming.com@gtempaccount.com667a29c2013-04-13 03:39:04 +00001057}
1058
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001059void Context::bindIndexedTransformFeedbackBuffer(GLuint bufferHandle,
1060 GLuint index,
1061 GLintptr offset,
1062 GLsizeiptr size)
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001063{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001064 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001065 mGLState.getCurrentTransformFeedback()->bindIndexedBuffer(index, buffer, offset, size);
shannon.woods%transgaming.com@gtempaccount.com34089352013-04-13 03:36:57 +00001066}
1067
Jiajia Qin6eafb042016-12-27 17:04:07 +08001068void Context::bindGenericAtomicCounterBuffer(GLuint bufferHandle)
1069{
1070 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
1071 mGLState.setGenericAtomicCounterBufferBinding(buffer);
1072}
1073
1074void Context::bindIndexedAtomicCounterBuffer(GLuint bufferHandle,
1075 GLuint index,
1076 GLintptr offset,
1077 GLsizeiptr size)
1078{
1079 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
1080 mGLState.setIndexedAtomicCounterBufferBinding(index, buffer, offset, size);
1081}
1082
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001083void Context::bindCopyReadBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001084{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001085 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001086 mGLState.setCopyReadBufferBinding(buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001087}
1088
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001089void Context::bindCopyWriteBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001090{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001091 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001092 mGLState.setCopyWriteBufferBinding(buffer);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +00001093}
1094
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001095void Context::bindPixelPackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001096{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001097 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001098 mGLState.setPixelPackBufferBinding(buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001099}
1100
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001101void Context::bindPixelUnpackBuffer(GLuint bufferHandle)
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001102{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001103 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001104 mGLState.setPixelUnpackBufferBinding(buffer);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001105}
1106
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001107void Context::useProgram(GLuint program)
1108{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001109 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001110}
1111
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001112void Context::bindTransformFeedback(GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001113{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001114 TransformFeedback *transformFeedback =
1115 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001116 mGLState.setTransformFeedbackBinding(transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001117}
1118
Geoff Lang5aad9672014-09-08 11:10:42 -04001119Error Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001120{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001121 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001122 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001123
Geoff Lang5aad9672014-09-08 11:10:42 -04001124 // begin query
1125 Error error = queryObject->begin();
1126 if (error.isError())
1127 {
1128 return error;
1129 }
1130
1131 // set query as active for specified target only if begin succeeded
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001132 mGLState.setActiveQuery(target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001133
He Yunchaoacd18982017-01-04 10:46:42 +08001134 return NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001135}
1136
Geoff Lang5aad9672014-09-08 11:10:42 -04001137Error Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001138{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001139 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001140 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001141
Geoff Lang5aad9672014-09-08 11:10:42 -04001142 gl::Error error = queryObject->end();
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001143
Geoff Lang5aad9672014-09-08 11:10:42 -04001144 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001145 mGLState.setActiveQuery(target, NULL);
Geoff Lang5aad9672014-09-08 11:10:42 -04001146
1147 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001148}
1149
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001150Error Context::queryCounter(GLuint id, GLenum target)
1151{
1152 ASSERT(target == GL_TIMESTAMP_EXT);
1153
1154 Query *queryObject = getQuery(id, true, target);
1155 ASSERT(queryObject);
1156
1157 return queryObject->queryCounter();
1158}
1159
1160void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1161{
1162 switch (pname)
1163 {
1164 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001165 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001166 break;
1167 case GL_QUERY_COUNTER_BITS_EXT:
1168 switch (target)
1169 {
1170 case GL_TIME_ELAPSED_EXT:
1171 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1172 break;
1173 case GL_TIMESTAMP_EXT:
1174 params[0] = getExtensions().queryCounterBitsTimestamp;
1175 break;
1176 default:
1177 UNREACHABLE();
1178 params[0] = 0;
1179 break;
1180 }
1181 break;
1182 default:
1183 UNREACHABLE();
1184 return;
1185 }
1186}
1187
Geoff Lang2186c382016-10-14 10:54:54 -04001188void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001189{
Geoff Lang2186c382016-10-14 10:54:54 -04001190 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001191}
1192
Geoff Lang2186c382016-10-14 10:54:54 -04001193void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001194{
Geoff Lang2186c382016-10-14 10:54:54 -04001195 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001196}
1197
Geoff Lang2186c382016-10-14 10:54:54 -04001198void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001199{
Geoff Lang2186c382016-10-14 10:54:54 -04001200 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001201}
1202
Geoff Lang2186c382016-10-14 10:54:54 -04001203void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001204{
Geoff Lang2186c382016-10-14 10:54:54 -04001205 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001206}
1207
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001208Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001209{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001210 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001211}
1212
Jamie Madill33dc8432013-07-26 11:55:05 -04001213FenceNV *Context::getFenceNV(unsigned int handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001214{
Jamie Madill4e25a0d2016-03-08 13:53:03 -05001215 auto fence = mFenceNVMap.find(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001216
Jamie Madill33dc8432013-07-26 11:55:05 -04001217 if (fence == mFenceNVMap.end())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001218 {
1219 return NULL;
1220 }
1221 else
1222 {
1223 return fence->second;
1224 }
1225}
1226
1227Query *Context::getQuery(unsigned int handle, bool create, GLenum type)
1228{
Jamie Madill4e25a0d2016-03-08 13:53:03 -05001229 auto query = mQueryMap.find(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001230
1231 if (query == mQueryMap.end())
1232 {
1233 return NULL;
1234 }
1235 else
1236 {
1237 if (!query->second && create)
1238 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001239 query->second = new Query(mImplementation->createQuery(type), handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001240 query->second->addRef();
1241 }
1242 return query->second;
1243 }
1244}
1245
Geoff Lang70d0f492015-12-10 17:45:46 -05001246Query *Context::getQuery(GLuint handle) const
1247{
1248 auto iter = mQueryMap.find(handle);
1249 return (iter != mQueryMap.end()) ? iter->second : nullptr;
1250}
1251
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001252Texture *Context::getTargetTexture(GLenum target) const
1253{
Ian Ewellbda75592016-04-18 17:25:54 -04001254 ASSERT(ValidTextureTarget(this, target) || ValidTextureExternalTarget(this, target));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001255 return mGLState.getTargetTexture(target);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001256}
1257
Geoff Lang76b10c92014-09-05 16:28:14 -04001258Texture *Context::getSamplerTexture(unsigned int sampler, GLenum type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001259{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001260 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001261}
1262
Geoff Lang492a7e42014-11-05 13:27:06 -05001263Compiler *Context::getCompiler() const
1264{
1265 return mCompiler;
1266}
1267
Jamie Madill893ab082014-05-16 16:56:10 -04001268void Context::getBooleanv(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001269{
1270 switch (pname)
1271 {
daniel@transgaming.comf39967e2012-11-28 19:35:56 +00001272 case GL_SHADER_COMPILER: *params = GL_TRUE; break;
daniel@transgaming.comf39967e2012-11-28 19:35:56 +00001273 case GL_CONTEXT_ROBUST_ACCESS_EXT: *params = mRobustAccess ? GL_TRUE : GL_FALSE; break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001274 default:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001275 mGLState.getBooleanv(pname, params);
1276 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001277 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001278}
1279
Jamie Madill893ab082014-05-16 16:56:10 -04001280void Context::getFloatv(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001281{
Shannon Woods53a94a82014-06-24 15:20:36 -04001282 // Queries about context capabilities and maximums are answered by Context.
1283 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001284 switch (pname)
1285 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001286 case GL_ALIASED_LINE_WIDTH_RANGE:
Geoff Langc0b9ef42014-07-02 10:02:37 -04001287 params[0] = mCaps.minAliasedLineWidth;
1288 params[1] = mCaps.maxAliasedLineWidth;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001289 break;
1290 case GL_ALIASED_POINT_SIZE_RANGE:
Geoff Langc0b9ef42014-07-02 10:02:37 -04001291 params[0] = mCaps.minAliasedPointSize;
1292 params[1] = mCaps.maxAliasedPointSize;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001293 break;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00001294 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
Geoff Langc0b9ef42014-07-02 10:02:37 -04001295 ASSERT(mExtensions.textureFilterAnisotropic);
1296 *params = mExtensions.maxTextureAnisotropy;
daniel@transgaming.com07ab8412012-07-12 15:17:09 +00001297 break;
Geoff Lange6d4e122015-06-29 13:33:55 -04001298 case GL_MAX_TEXTURE_LOD_BIAS:
1299 *params = mCaps.maxLODBias;
1300 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001301
1302 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1303 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1304 {
1305 ASSERT(mExtensions.pathRendering);
1306 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1307 memcpy(params, m, 16 * sizeof(GLfloat));
1308 }
1309 break;
1310
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001311 default:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001312 mGLState.getFloatv(pname, params);
1313 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001314 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001315}
1316
Jamie Madill893ab082014-05-16 16:56:10 -04001317void Context::getIntegerv(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001318{
Shannon Woods53a94a82014-06-24 15:20:36 -04001319 // Queries about context capabilities and maximums are answered by Context.
1320 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001321
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001322 switch (pname)
1323 {
Geoff Lang301d1612014-07-09 10:34:37 -04001324 case GL_MAX_VERTEX_ATTRIBS: *params = mCaps.maxVertexAttributes; break;
1325 case GL_MAX_VERTEX_UNIFORM_VECTORS: *params = mCaps.maxVertexUniformVectors; break;
1326 case GL_MAX_VERTEX_UNIFORM_COMPONENTS: *params = mCaps.maxVertexUniformComponents; break;
Geoff Lang3a61c322014-07-10 13:01:54 -04001327 case GL_MAX_VARYING_VECTORS: *params = mCaps.maxVaryingVectors; break;
1328 case GL_MAX_VARYING_COMPONENTS: *params = mCaps.maxVertexOutputComponents; break;
1329 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: *params = mCaps.maxCombinedTextureImageUnits; break;
Geoff Lang301d1612014-07-09 10:34:37 -04001330 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS: *params = mCaps.maxVertexTextureImageUnits; break;
1331 case GL_MAX_TEXTURE_IMAGE_UNITS: *params = mCaps.maxTextureImageUnits; break;
1332 case GL_MAX_FRAGMENT_UNIFORM_VECTORS: *params = mCaps.maxFragmentUniformVectors; break;
Geoff Lange7468902015-10-02 10:46:24 -04001333 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS: *params = mCaps.maxFragmentUniformComponents; break;
Geoff Langc0b9ef42014-07-02 10:02:37 -04001334 case GL_MAX_RENDERBUFFER_SIZE: *params = mCaps.maxRenderbufferSize; break;
1335 case GL_MAX_COLOR_ATTACHMENTS_EXT: *params = mCaps.maxColorAttachments; break;
1336 case GL_MAX_DRAW_BUFFERS_EXT: *params = mCaps.maxDrawBuffers; break;
Jamie Madill1caff072013-07-19 16:36:56 -04001337 //case GL_FRAMEBUFFER_BINDING: // now equivalent to GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
Jamie Madill1caff072013-07-19 16:36:56 -04001338 case GL_SUBPIXEL_BITS: *params = 4; break;
Geoff Langc0b9ef42014-07-02 10:02:37 -04001339 case GL_MAX_TEXTURE_SIZE: *params = mCaps.max2DTextureSize; break;
1340 case GL_MAX_CUBE_MAP_TEXTURE_SIZE: *params = mCaps.maxCubeMapTextureSize; break;
1341 case GL_MAX_3D_TEXTURE_SIZE: *params = mCaps.max3DTextureSize; break;
1342 case GL_MAX_ARRAY_TEXTURE_LAYERS: *params = mCaps.maxArrayTextureLayers; break;
Geoff Lang3a61c322014-07-10 13:01:54 -04001343 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT: *params = mCaps.uniformBufferOffsetAlignment; break;
1344 case GL_MAX_UNIFORM_BUFFER_BINDINGS: *params = mCaps.maxUniformBufferBindings; break;
Geoff Lang301d1612014-07-09 10:34:37 -04001345 case GL_MAX_VERTEX_UNIFORM_BLOCKS: *params = mCaps.maxVertexUniformBlocks; break;
1346 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS: *params = mCaps.maxFragmentUniformBlocks; break;
Geoff Lang3a61c322014-07-10 13:01:54 -04001347 case GL_MAX_COMBINED_UNIFORM_BLOCKS: *params = mCaps.maxCombinedTextureImageUnits; break;
Geoff Lange6d4e122015-06-29 13:33:55 -04001348 case GL_MAX_VERTEX_OUTPUT_COMPONENTS: *params = mCaps.maxVertexOutputComponents; break;
1349 case GL_MAX_FRAGMENT_INPUT_COMPONENTS: *params = mCaps.maxFragmentInputComponents; break;
1350 case GL_MIN_PROGRAM_TEXEL_OFFSET: *params = mCaps.minProgramTexelOffset; break;
1351 case GL_MAX_PROGRAM_TEXEL_OFFSET: *params = mCaps.maxProgramTexelOffset; break;
Martin Radev1be913c2016-07-11 17:59:16 +03001352 case GL_MAJOR_VERSION:
Geoff Langeb66a6e2016-10-31 13:06:12 -04001353 *params = getClientVersion().major;
Martin Radev1be913c2016-07-11 17:59:16 +03001354 break;
1355 case GL_MINOR_VERSION:
Geoff Langeb66a6e2016-10-31 13:06:12 -04001356 *params = getClientVersion().minor;
Martin Radev1be913c2016-07-11 17:59:16 +03001357 break;
Geoff Lang900013c2014-07-07 11:32:19 -04001358 case GL_MAX_ELEMENTS_INDICES: *params = mCaps.maxElementsIndices; break;
1359 case GL_MAX_ELEMENTS_VERTICES: *params = mCaps.maxElementsVertices; break;
Geoff Lang05881a02014-07-10 14:05:30 -04001360 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS: *params = mCaps.maxTransformFeedbackInterleavedComponents; break;
1361 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS: *params = mCaps.maxTransformFeedbackSeparateAttributes; break;
1362 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS: *params = mCaps.maxTransformFeedbackSeparateComponents; break;
Cooper Partin4d61f7e2015-08-12 10:56:50 -07001363 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1364 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1365 break;
Geoff Langdef624b2015-04-13 10:46:56 -04001366 case GL_MAX_SAMPLES_ANGLE: *params = mCaps.maxSamples; break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001367 case GL_MAX_VIEWPORT_DIMS:
1368 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001369 params[0] = mCaps.maxViewportWidth;
1370 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001371 }
1372 break;
1373 case GL_COMPRESSED_TEXTURE_FORMATS:
Geoff Lang900013c2014-07-07 11:32:19 -04001374 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(), params);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001375 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001376 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1377 *params = mResetStrategy;
1378 break;
Geoff Lang900013c2014-07-07 11:32:19 -04001379 case GL_NUM_SHADER_BINARY_FORMATS:
Cooper Partin4d61f7e2015-08-12 10:56:50 -07001380 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001381 break;
Geoff Lang900013c2014-07-07 11:32:19 -04001382 case GL_SHADER_BINARY_FORMATS:
1383 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1384 break;
1385 case GL_NUM_PROGRAM_BINARY_FORMATS:
Cooper Partin4d61f7e2015-08-12 10:56:50 -07001386 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
Geoff Lang900013c2014-07-07 11:32:19 -04001387 break;
1388 case GL_PROGRAM_BINARY_FORMATS:
1389 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001390 break;
Geoff Lang23c81692013-08-12 10:46:58 -04001391 case GL_NUM_EXTENSIONS:
Geoff Langcec35902014-04-16 10:52:36 -04001392 *params = static_cast<GLint>(mExtensionStrings.size());
Geoff Lang23c81692013-08-12 10:46:58 -04001393 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001394
1395 // GL_KHR_debug
1396 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1397 *params = mExtensions.maxDebugMessageLength;
1398 break;
1399 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1400 *params = mExtensions.maxDebugLoggedMessages;
1401 break;
1402 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1403 *params = mExtensions.maxDebugGroupStackDepth;
1404 break;
1405 case GL_MAX_LABEL_LENGTH:
1406 *params = mExtensions.maxLabelLength;
1407 break;
1408
Ian Ewell53f59f42016-01-28 17:36:55 -05001409 // GL_EXT_disjoint_timer_query
1410 case GL_GPU_DISJOINT_EXT:
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001411 *params = mImplementation->getGPUDisjoint();
Ian Ewell53f59f42016-01-28 17:36:55 -05001412 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001413 case GL_MAX_FRAMEBUFFER_WIDTH:
1414 *params = mCaps.maxFramebufferWidth;
1415 break;
1416 case GL_MAX_FRAMEBUFFER_HEIGHT:
1417 *params = mCaps.maxFramebufferHeight;
1418 break;
1419 case GL_MAX_FRAMEBUFFER_SAMPLES:
1420 *params = mCaps.maxFramebufferSamples;
1421 break;
1422 case GL_MAX_SAMPLE_MASK_WORDS:
1423 *params = mCaps.maxSampleMaskWords;
1424 break;
1425 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1426 *params = mCaps.maxColorTextureSamples;
1427 break;
1428 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1429 *params = mCaps.maxDepthTextureSamples;
1430 break;
1431 case GL_MAX_INTEGER_SAMPLES:
1432 *params = mCaps.maxIntegerSamples;
1433 break;
1434 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1435 *params = mCaps.maxVertexAttribRelativeOffset;
1436 break;
1437 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1438 *params = mCaps.maxVertexAttribBindings;
1439 break;
1440 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1441 *params = mCaps.maxVertexAttribStride;
1442 break;
1443 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1444 *params = mCaps.maxVertexAtomicCounterBuffers;
1445 break;
1446 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1447 *params = mCaps.maxVertexAtomicCounters;
1448 break;
1449 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1450 *params = mCaps.maxVertexImageUniforms;
1451 break;
1452 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1453 *params = mCaps.maxVertexShaderStorageBlocks;
1454 break;
1455 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1456 *params = mCaps.maxFragmentAtomicCounterBuffers;
1457 break;
1458 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1459 *params = mCaps.maxFragmentAtomicCounters;
1460 break;
1461 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1462 *params = mCaps.maxFragmentImageUniforms;
1463 break;
1464 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1465 *params = mCaps.maxFragmentShaderStorageBlocks;
1466 break;
1467 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1468 *params = mCaps.minProgramTextureGatherOffset;
1469 break;
1470 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1471 *params = mCaps.maxProgramTextureGatherOffset;
1472 break;
1473 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1474 *params = mCaps.maxComputeWorkGroupInvocations;
1475 break;
1476 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1477 *params = mCaps.maxComputeUniformBlocks;
1478 break;
1479 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1480 *params = mCaps.maxComputeTextureImageUnits;
1481 break;
1482 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1483 *params = mCaps.maxComputeSharedMemorySize;
1484 break;
1485 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1486 *params = mCaps.maxComputeUniformComponents;
1487 break;
1488 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1489 *params = mCaps.maxComputeAtomicCounterBuffers;
1490 break;
1491 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1492 *params = mCaps.maxComputeAtomicCounters;
1493 break;
1494 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1495 *params = mCaps.maxComputeImageUniforms;
1496 break;
1497 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1498 *params = mCaps.maxCombinedComputeUniformComponents;
1499 break;
1500 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1501 *params = mCaps.maxComputeShaderStorageBlocks;
1502 break;
1503 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1504 *params = mCaps.maxCombinedShaderOutputResources;
1505 break;
1506 case GL_MAX_UNIFORM_LOCATIONS:
1507 *params = mCaps.maxUniformLocations;
1508 break;
1509 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1510 *params = mCaps.maxAtomicCounterBufferBindings;
1511 break;
1512 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1513 *params = mCaps.maxAtomicCounterBufferSize;
1514 break;
1515 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1516 *params = mCaps.maxCombinedAtomicCounterBuffers;
1517 break;
1518 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1519 *params = mCaps.maxCombinedAtomicCounters;
1520 break;
1521 case GL_MAX_IMAGE_UNITS:
1522 *params = mCaps.maxImageUnits;
1523 break;
1524 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1525 *params = mCaps.maxCombinedImageUniforms;
1526 break;
1527 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1528 *params = mCaps.maxShaderStorageBufferBindings;
1529 break;
1530 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1531 *params = mCaps.maxCombinedShaderStorageBlocks;
1532 break;
1533 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1534 *params = mCaps.shaderStorageBufferOffsetAlignment;
1535 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001536 default:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001537 mGLState.getIntegerv(mState, pname, params);
1538 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001539 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001540}
1541
Jamie Madill893ab082014-05-16 16:56:10 -04001542void Context::getInteger64v(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001543{
Shannon Woods53a94a82014-06-24 15:20:36 -04001544 // Queries about context capabilities and maximums are answered by Context.
1545 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001546 switch (pname)
1547 {
1548 case GL_MAX_ELEMENT_INDEX:
Geoff Langc0b9ef42014-07-02 10:02:37 -04001549 *params = mCaps.maxElementIndex;
Jamie Madill0fda9862013-07-19 16:36:55 -04001550 break;
1551 case GL_MAX_UNIFORM_BLOCK_SIZE:
Geoff Lang3a61c322014-07-10 13:01:54 -04001552 *params = mCaps.maxUniformBlockSize;
Jamie Madill0fda9862013-07-19 16:36:55 -04001553 break;
1554 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
Geoff Lang3a61c322014-07-10 13:01:54 -04001555 *params = mCaps.maxCombinedVertexUniformComponents;
Jamie Madill0fda9862013-07-19 16:36:55 -04001556 break;
1557 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
Geoff Lang3a61c322014-07-10 13:01:54 -04001558 *params = mCaps.maxCombinedFragmentUniformComponents;
Jamie Madill0fda9862013-07-19 16:36:55 -04001559 break;
1560 case GL_MAX_SERVER_WAIT_TIMEOUT:
Geoff Lang900013c2014-07-07 11:32:19 -04001561 *params = mCaps.maxServerWaitTimeout;
Jamie Madill0fda9862013-07-19 16:36:55 -04001562 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001563
1564 // GL_EXT_disjoint_timer_query
1565 case GL_TIMESTAMP_EXT:
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001566 *params = mImplementation->getTimestamp();
Ian Ewell53f59f42016-01-28 17:36:55 -05001567 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001568
1569 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1570 *params = mCaps.maxShaderStorageBlockSize;
1571 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001572 default:
Jamie Madill893ab082014-05-16 16:56:10 -04001573 UNREACHABLE();
1574 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001575 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001576}
1577
Geoff Lang70d0f492015-12-10 17:45:46 -05001578void Context::getPointerv(GLenum pname, void **params) const
1579{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001580 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001581}
1582
Martin Radev66fb8202016-07-28 11:45:20 +03001583void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001584{
Shannon Woods53a94a82014-06-24 15:20:36 -04001585 // Queries about context capabilities and maximums are answered by Context.
1586 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001587
1588 GLenum nativeType;
1589 unsigned int numParams;
1590 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1591 ASSERT(queryStatus);
1592
1593 if (nativeType == GL_INT)
1594 {
1595 switch (target)
1596 {
1597 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1598 ASSERT(index < 3u);
1599 *data = mCaps.maxComputeWorkGroupCount[index];
1600 break;
1601 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1602 ASSERT(index < 3u);
1603 *data = mCaps.maxComputeWorkGroupSize[index];
1604 break;
1605 default:
1606 mGLState.getIntegeri_v(target, index, data);
1607 }
1608 }
1609 else
1610 {
1611 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1612 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001613}
1614
Martin Radev66fb8202016-07-28 11:45:20 +03001615void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001616{
Shannon Woods53a94a82014-06-24 15:20:36 -04001617 // Queries about context capabilities and maximums are answered by Context.
1618 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001619
1620 GLenum nativeType;
1621 unsigned int numParams;
1622 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1623 ASSERT(queryStatus);
1624
1625 if (nativeType == GL_INT_64_ANGLEX)
1626 {
1627 mGLState.getInteger64i_v(target, index, data);
1628 }
1629 else
1630 {
1631 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1632 }
1633}
1634
1635void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1636{
1637 // Queries about context capabilities and maximums are answered by Context.
1638 // Queries about current GL state values are answered by State.
1639
1640 GLenum nativeType;
1641 unsigned int numParams;
1642 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1643 ASSERT(queryStatus);
1644
1645 if (nativeType == GL_BOOL)
1646 {
1647 mGLState.getBooleani_v(target, index, data);
1648 }
1649 else
1650 {
1651 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1652 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001653}
1654
He Yunchao010e4db2017-03-03 14:22:06 +08001655void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
1656{
1657 Buffer *buffer = mGLState.getTargetBuffer(target);
1658 QueryBufferParameteriv(buffer, pname, params);
1659}
1660
1661void Context::getFramebufferAttachmentParameteriv(GLenum target,
1662 GLenum attachment,
1663 GLenum pname,
1664 GLint *params)
1665{
1666 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
1667 QueryFramebufferAttachmentParameteriv(framebuffer, attachment, pname, params);
1668}
1669
1670void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1671{
1672 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1673 QueryRenderbufferiv(this, renderbuffer, pname, params);
1674}
1675
1676void Context::getTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
1677{
1678 Texture *texture = getTargetTexture(target);
1679 QueryTexParameterfv(texture, pname, params);
1680}
1681
1682void Context::getTexParameteriv(GLenum target, GLenum pname, GLint *params)
1683{
1684 Texture *texture = getTargetTexture(target);
1685 QueryTexParameteriv(texture, pname, params);
1686}
1687void Context::texParameterf(GLenum target, GLenum pname, GLfloat param)
1688{
1689 Texture *texture = getTargetTexture(target);
1690 SetTexParameterf(texture, pname, param);
1691}
1692
1693void Context::texParameterfv(GLenum target, GLenum pname, const GLfloat *params)
1694{
1695 Texture *texture = getTargetTexture(target);
1696 SetTexParameterfv(texture, pname, params);
1697}
1698
1699void Context::texParameteri(GLenum target, GLenum pname, GLint param)
1700{
1701 Texture *texture = getTargetTexture(target);
1702 SetTexParameteri(texture, pname, param);
1703}
1704
1705void Context::texParameteriv(GLenum target, GLenum pname, const GLint *params)
1706{
1707 Texture *texture = getTargetTexture(target);
1708 SetTexParameteriv(texture, pname, params);
1709}
1710
Jamie Madill675fe712016-12-19 13:07:54 -05001711void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001712{
Jamie Madill1b94d432015-08-07 13:23:23 -04001713 syncRendererState();
Jamie Madill675fe712016-12-19 13:07:54 -05001714 auto error = mImplementation->drawArrays(mode, first, count);
1715 handleError(error);
1716 if (!error.isError())
1717 {
1718 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
1719 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001720}
1721
Jamie Madill675fe712016-12-19 13:07:54 -05001722void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001723{
1724 syncRendererState();
Jamie Madill675fe712016-12-19 13:07:54 -05001725 auto error = mImplementation->drawArraysInstanced(mode, first, count, instanceCount);
1726 handleError(error);
1727 if (!error.isError())
1728 {
1729 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
1730 }
Geoff Langf6db0982015-08-25 13:04:00 -04001731}
1732
Jamie Madill675fe712016-12-19 13:07:54 -05001733void Context::drawElements(GLenum mode,
1734 GLsizei count,
1735 GLenum type,
1736 const GLvoid *indices,
1737 const IndexRange &indexRange)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001738{
Jamie Madill1b94d432015-08-07 13:23:23 -04001739 syncRendererState();
Jamie Madill675fe712016-12-19 13:07:54 -05001740 handleError(mImplementation->drawElements(mode, count, type, indices, indexRange));
Geoff Langf6db0982015-08-25 13:04:00 -04001741}
1742
Jamie Madill675fe712016-12-19 13:07:54 -05001743void Context::drawElementsInstanced(GLenum mode,
1744 GLsizei count,
1745 GLenum type,
1746 const GLvoid *indices,
1747 GLsizei instances,
1748 const IndexRange &indexRange)
Geoff Langf6db0982015-08-25 13:04:00 -04001749{
1750 syncRendererState();
Jamie Madill675fe712016-12-19 13:07:54 -05001751 handleError(
1752 mImplementation->drawElementsInstanced(mode, count, type, indices, instances, indexRange));
Geoff Langf6db0982015-08-25 13:04:00 -04001753}
1754
Jamie Madill675fe712016-12-19 13:07:54 -05001755void Context::drawRangeElements(GLenum mode,
1756 GLuint start,
1757 GLuint end,
1758 GLsizei count,
1759 GLenum type,
1760 const GLvoid *indices,
1761 const IndexRange &indexRange)
Geoff Langf6db0982015-08-25 13:04:00 -04001762{
1763 syncRendererState();
Jamie Madill675fe712016-12-19 13:07:54 -05001764 handleError(
1765 mImplementation->drawRangeElements(mode, start, end, count, type, indices, indexRange));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001766}
1767
Jiajia Qind9671222016-11-29 16:30:31 +08001768void Context::drawArraysIndirect(GLenum mode, const GLvoid *indirect)
1769{
1770 syncRendererState();
1771 handleError(mImplementation->drawArraysIndirect(mode, indirect));
1772}
1773
1774void Context::drawElementsIndirect(GLenum mode, GLenum type, const GLvoid *indirect)
1775{
1776 syncRendererState();
1777 handleError(mImplementation->drawElementsIndirect(mode, type, indirect));
1778}
1779
Jamie Madill675fe712016-12-19 13:07:54 -05001780void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001781{
Jamie Madill675fe712016-12-19 13:07:54 -05001782 handleError(mImplementation->flush());
Geoff Lang129753a2015-01-09 16:52:09 -05001783}
1784
Jamie Madill675fe712016-12-19 13:07:54 -05001785void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001786{
Jamie Madill675fe712016-12-19 13:07:54 -05001787 handleError(mImplementation->finish());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001788}
1789
Austin Kinross6ee1e782015-05-29 17:05:37 -07001790void Context::insertEventMarker(GLsizei length, const char *marker)
1791{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001792 ASSERT(mImplementation);
1793 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001794}
1795
1796void Context::pushGroupMarker(GLsizei length, const char *marker)
1797{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001798 ASSERT(mImplementation);
1799 mImplementation->pushGroupMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001800}
1801
1802void Context::popGroupMarker()
1803{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001804 ASSERT(mImplementation);
1805 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001806}
1807
Geoff Langd8605522016-04-13 10:19:12 -04001808void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1809{
1810 Program *programObject = getProgram(program);
1811 ASSERT(programObject);
1812
1813 programObject->bindUniformLocation(location, name);
1814}
1815
Sami Väisänena797e062016-05-12 15:23:40 +03001816void Context::setCoverageModulation(GLenum components)
1817{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001818 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001819}
1820
Sami Väisänene45e53b2016-05-25 10:36:04 +03001821void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1822{
1823 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1824}
1825
1826void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1827{
1828 GLfloat I[16];
1829 angle::Matrix<GLfloat>::setToIdentity(I);
1830
1831 mGLState.loadPathRenderingMatrix(matrixMode, I);
1832}
1833
1834void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1835{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001836 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001837 if (!pathObj)
1838 return;
1839
1840 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1841 syncRendererState();
1842
1843 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1844}
1845
1846void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1847{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001848 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001849 if (!pathObj)
1850 return;
1851
1852 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1853 syncRendererState();
1854
1855 mImplementation->stencilStrokePath(pathObj, reference, mask);
1856}
1857
1858void Context::coverFillPath(GLuint path, GLenum coverMode)
1859{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001860 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001861 if (!pathObj)
1862 return;
1863
1864 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1865 syncRendererState();
1866
1867 mImplementation->coverFillPath(pathObj, coverMode);
1868}
1869
1870void Context::coverStrokePath(GLuint path, GLenum coverMode)
1871{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001872 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001873 if (!pathObj)
1874 return;
1875
1876 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1877 syncRendererState();
1878
1879 mImplementation->coverStrokePath(pathObj, coverMode);
1880}
1881
1882void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1883{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001884 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001885 if (!pathObj)
1886 return;
1887
1888 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1889 syncRendererState();
1890
1891 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
1892}
1893
1894void Context::stencilThenCoverStrokePath(GLuint path,
1895 GLint reference,
1896 GLuint mask,
1897 GLenum coverMode)
1898{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001899 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001900 if (!pathObj)
1901 return;
1902
1903 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1904 syncRendererState();
1905
1906 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
1907}
1908
Sami Väisänend59ca052016-06-21 16:10:00 +03001909void Context::coverFillPathInstanced(GLsizei numPaths,
1910 GLenum pathNameType,
1911 const void *paths,
1912 GLuint pathBase,
1913 GLenum coverMode,
1914 GLenum transformType,
1915 const GLfloat *transformValues)
1916{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001917 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001918
1919 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1920 syncRendererState();
1921
1922 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
1923}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001924
Sami Väisänend59ca052016-06-21 16:10:00 +03001925void Context::coverStrokePathInstanced(GLsizei numPaths,
1926 GLenum pathNameType,
1927 const void *paths,
1928 GLuint pathBase,
1929 GLenum coverMode,
1930 GLenum transformType,
1931 const GLfloat *transformValues)
1932{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001933 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001934
1935 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1936 syncRendererState();
1937
1938 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
1939 transformValues);
1940}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001941
Sami Väisänend59ca052016-06-21 16:10:00 +03001942void Context::stencilFillPathInstanced(GLsizei numPaths,
1943 GLenum pathNameType,
1944 const void *paths,
1945 GLuint pathBase,
1946 GLenum fillMode,
1947 GLuint mask,
1948 GLenum transformType,
1949 const GLfloat *transformValues)
1950{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001951 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001952
1953 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1954 syncRendererState();
1955
1956 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
1957 transformValues);
1958}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001959
Sami Väisänend59ca052016-06-21 16:10:00 +03001960void Context::stencilStrokePathInstanced(GLsizei numPaths,
1961 GLenum pathNameType,
1962 const void *paths,
1963 GLuint pathBase,
1964 GLint reference,
1965 GLuint mask,
1966 GLenum transformType,
1967 const GLfloat *transformValues)
1968{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001969 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001970
1971 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1972 syncRendererState();
1973
1974 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
1975 transformValues);
1976}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001977
Sami Väisänend59ca052016-06-21 16:10:00 +03001978void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
1979 GLenum pathNameType,
1980 const void *paths,
1981 GLuint pathBase,
1982 GLenum fillMode,
1983 GLuint mask,
1984 GLenum coverMode,
1985 GLenum transformType,
1986 const GLfloat *transformValues)
1987{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001988 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001989
1990 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1991 syncRendererState();
1992
1993 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
1994 transformType, transformValues);
1995}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001996
Sami Väisänend59ca052016-06-21 16:10:00 +03001997void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
1998 GLenum pathNameType,
1999 const void *paths,
2000 GLuint pathBase,
2001 GLint reference,
2002 GLuint mask,
2003 GLenum coverMode,
2004 GLenum transformType,
2005 const GLfloat *transformValues)
2006{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002007 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002008
2009 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2010 syncRendererState();
2011
2012 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2013 transformType, transformValues);
2014}
2015
Sami Väisänen46eaa942016-06-29 10:26:37 +03002016void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2017{
2018 auto *programObject = getProgram(program);
2019
2020 programObject->bindFragmentInputLocation(location, name);
2021}
2022
2023void Context::programPathFragmentInputGen(GLuint program,
2024 GLint location,
2025 GLenum genMode,
2026 GLint components,
2027 const GLfloat *coeffs)
2028{
2029 auto *programObject = getProgram(program);
2030
2031 programObject->pathFragmentInputGen(location, genMode, components, coeffs);
2032}
2033
Jamie Madill437fa652016-05-03 15:13:24 -04002034void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002035{
Geoff Langda5777c2014-07-11 09:52:58 -04002036 if (error.isError())
2037 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002038 GLenum code = error.getCode();
2039 mErrors.insert(code);
2040 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2041 {
2042 markContextLost();
2043 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002044
2045 if (!error.getMessage().empty())
2046 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002047 auto *debug = &mGLState.getDebug();
2048 debug->insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2049 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Lang70d0f492015-12-10 17:45:46 -05002050 }
Geoff Langda5777c2014-07-11 09:52:58 -04002051 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002052}
2053
2054// Get one of the recorded errors and clear its flag, if any.
2055// [OpenGL ES 2.0.24] section 2.5 page 13.
2056GLenum Context::getError()
2057{
Geoff Langda5777c2014-07-11 09:52:58 -04002058 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002059 {
Geoff Langda5777c2014-07-11 09:52:58 -04002060 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002061 }
Geoff Langda5777c2014-07-11 09:52:58 -04002062 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002063 {
Geoff Langda5777c2014-07-11 09:52:58 -04002064 GLenum error = *mErrors.begin();
2065 mErrors.erase(mErrors.begin());
2066 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002067 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002068}
2069
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002070// NOTE: this function should not assume that this context is current!
2071void Context::markContextLost()
2072{
2073 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002074 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002075 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002076 mContextLostForced = true;
2077 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002078 mContextLost = true;
2079}
2080
2081bool Context::isContextLost()
2082{
2083 return mContextLost;
2084}
2085
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002086GLenum Context::getResetStatus()
2087{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002088 // Even if the application doesn't want to know about resets, we want to know
2089 // as it will allow us to skip all the calls.
2090 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002091 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002092 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002093 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002094 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002095 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002096
2097 // EXT_robustness, section 2.6: If the reset notification behavior is
2098 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2099 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2100 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002101 }
2102
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002103 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2104 // status should be returned at least once, and GL_NO_ERROR should be returned
2105 // once the device has finished resetting.
2106 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002107 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002108 ASSERT(mResetStatus == GL_NO_ERROR);
2109 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002110
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002111 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002112 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002113 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002114 }
2115 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002116 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002117 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002118 // If markContextLost was used to mark the context lost then
2119 // assume that is not recoverable, and continue to report the
2120 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002121 mResetStatus = mImplementation->getResetStatus();
2122 }
Jamie Madill893ab082014-05-16 16:56:10 -04002123
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002124 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002125}
2126
2127bool Context::isResetNotificationEnabled()
2128{
2129 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2130}
2131
Corentin Walleze3b10e82015-05-20 11:06:25 -04002132const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002133{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002134 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002135}
2136
2137EGLenum Context::getClientType() const
2138{
2139 return mClientType;
2140}
2141
2142EGLenum Context::getRenderBuffer() const
2143{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002144 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2145 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002146 {
2147 return EGL_NONE;
2148 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002149
2150 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(GL_BACK);
2151 ASSERT(backAttachment != nullptr);
2152 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002153}
2154
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002155VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002156{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002157 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002158 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2159 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002160 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002161 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2162 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002163
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002164 mVertexArrayMap[vertexArrayHandle] = vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002165 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002166
2167 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002168}
2169
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002170TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002171{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002172 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002173 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2174 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002175 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002176 transformFeedback =
2177 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002178 transformFeedback->addRef();
2179 mTransformFeedbackMap[transformFeedbackHandle] = transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002180 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002181
2182 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002183}
2184
2185bool Context::isVertexArrayGenerated(GLuint vertexArray)
2186{
Geoff Langf41a7152016-09-19 15:11:17 -04002187 ASSERT(mVertexArrayMap.find(0) != mVertexArrayMap.end());
Geoff Lang36167ab2015-12-07 10:27:14 -05002188 return mVertexArrayMap.find(vertexArray) != mVertexArrayMap.end();
2189}
2190
2191bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2192{
Geoff Langf41a7152016-09-19 15:11:17 -04002193 ASSERT(mTransformFeedbackMap.find(0) != mTransformFeedbackMap.end());
Geoff Lang36167ab2015-12-07 10:27:14 -05002194 return mTransformFeedbackMap.find(transformFeedback) != mTransformFeedbackMap.end();
2195}
2196
Shannon Woods53a94a82014-06-24 15:20:36 -04002197void Context::detachTexture(GLuint texture)
2198{
2199 // Simple pass-through to State's detachTexture method, as textures do not require
2200 // allocation map management either here or in the resource manager at detach time.
2201 // Zero textures are held by the Context, and we don't attempt to request them from
2202 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002203 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002204}
2205
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002206void Context::detachBuffer(GLuint buffer)
2207{
Yuly Novikov5807a532015-12-03 13:01:22 -05002208 // Simple pass-through to State's detachBuffer method, since
2209 // only buffer attachments to container objects that are bound to the current context
2210 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002211
Yuly Novikov5807a532015-12-03 13:01:22 -05002212 // [OpenGL ES 3.2] section 5.1.2 page 45:
2213 // Attachments to unbound container objects, such as
2214 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2215 // are not affected and continue to act as references on the deleted object
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002216 mGLState.detachBuffer(buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002217}
2218
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002219void Context::detachFramebuffer(GLuint framebuffer)
2220{
Shannon Woods53a94a82014-06-24 15:20:36 -04002221 // Framebuffer detachment is handled by Context, because 0 is a valid
2222 // Framebuffer object, and a pointer to it must be passed from Context
2223 // to State at binding time.
2224
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002225 // [OpenGL ES 2.0.24] section 4.4 page 107:
2226 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as though
2227 // BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of zero.
2228
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002229 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002230 {
2231 bindReadFramebuffer(0);
2232 }
2233
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002234 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002235 {
2236 bindDrawFramebuffer(0);
2237 }
2238}
2239
2240void Context::detachRenderbuffer(GLuint renderbuffer)
2241{
Jamie Madilla02315b2017-02-23 14:14:47 -05002242 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002243}
2244
Jamie Madill57a89722013-07-02 11:57:03 -04002245void Context::detachVertexArray(GLuint vertexArray)
2246{
Jamie Madill77a72f62015-04-14 11:18:32 -04002247 // Vertex array detachment is handled by Context, because 0 is a valid
2248 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002249 // binding time.
2250
Jamie Madill57a89722013-07-02 11:57:03 -04002251 // [OpenGL ES 3.0.2] section 2.10 page 43:
2252 // If a vertex array object that is currently bound is deleted, the binding
2253 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002254 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002255 {
2256 bindVertexArray(0);
2257 }
2258}
2259
Geoff Langc8058452014-02-03 12:04:11 -05002260void Context::detachTransformFeedback(GLuint transformFeedback)
2261{
Corentin Walleza2257da2016-04-19 16:43:12 -04002262 // Transform feedback detachment is handled by Context, because 0 is a valid
2263 // transform feedback, and a pointer to it must be passed from Context to State at
2264 // binding time.
2265
2266 // The OpenGL specification doesn't mention what should happen when the currently bound
2267 // transform feedback object is deleted. Since it is a container object, we treat it like
2268 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002269 if (mGLState.removeTransformFeedbackBinding(transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002270 {
2271 bindTransformFeedback(0);
2272 }
Geoff Langc8058452014-02-03 12:04:11 -05002273}
2274
Jamie Madilldc356042013-07-19 16:36:57 -04002275void Context::detachSampler(GLuint sampler)
2276{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002277 mGLState.detachSampler(sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002278}
2279
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002280void Context::setVertexAttribDivisor(GLuint index, GLuint divisor)
2281{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002282 mGLState.setVertexAttribDivisor(index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002283}
2284
Jamie Madille29d1672013-07-19 16:36:57 -04002285void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2286{
Geoff Langc1984ed2016-10-07 12:41:00 -04002287 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002288 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002289 SetSamplerParameteri(samplerObject, pname, param);
2290}
Jamie Madille29d1672013-07-19 16:36:57 -04002291
Geoff Langc1984ed2016-10-07 12:41:00 -04002292void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2293{
2294 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002295 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002296 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002297}
2298
2299void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2300{
Geoff Langc1984ed2016-10-07 12:41:00 -04002301 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002302 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002303 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madille29d1672013-07-19 16:36:57 -04002304}
2305
Geoff Langc1984ed2016-10-07 12:41:00 -04002306void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002307{
Geoff Langc1984ed2016-10-07 12:41:00 -04002308 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002309 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002310 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill9675b802013-07-19 16:36:59 -04002311}
2312
Geoff Langc1984ed2016-10-07 12:41:00 -04002313void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002314{
Geoff Langc1984ed2016-10-07 12:41:00 -04002315 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002316 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002317 QuerySamplerParameteriv(samplerObject, pname, params);
2318}
Jamie Madill9675b802013-07-19 16:36:59 -04002319
Geoff Langc1984ed2016-10-07 12:41:00 -04002320void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2321{
2322 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002323 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002324 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill9675b802013-07-19 16:36:59 -04002325}
2326
Olli Etuahof0fee072016-03-30 15:11:58 +03002327void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2328{
2329 gl::Program *programObject = getProgram(program);
2330 ASSERT(programObject != nullptr);
2331
2332 ASSERT(pname == GL_PROGRAM_BINARY_RETRIEVABLE_HINT);
2333 programObject->setBinaryRetrievableHint(value != GL_FALSE);
2334}
2335
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002336void Context::initRendererString()
2337{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002338 std::ostringstream rendererString;
2339 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002340 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002341 rendererString << ")";
2342
Geoff Langcec35902014-04-16 10:52:36 -04002343 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002344}
2345
Geoff Langc339c4e2016-11-29 10:37:36 -05002346void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002347{
Geoff Langc339c4e2016-11-29 10:37:36 -05002348 const Version &clientVersion = getClientVersion();
2349
2350 std::ostringstream versionString;
2351 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2352 << ANGLE_VERSION_STRING << ")";
2353 mVersionString = MakeStaticString(versionString.str());
2354
2355 std::ostringstream shadingLanguageVersionString;
2356 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2357 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2358 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2359 << ")";
2360 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002361}
2362
Geoff Langcec35902014-04-16 10:52:36 -04002363void Context::initExtensionStrings()
2364{
Geoff Langc339c4e2016-11-29 10:37:36 -05002365 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2366 std::ostringstream combinedStringStream;
2367 std::copy(strings.begin(), strings.end(),
2368 std::ostream_iterator<const char *>(combinedStringStream, " "));
2369 return MakeStaticString(combinedStringStream.str());
2370 };
2371
2372 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002373 for (const auto &extensionString : mExtensions.getStrings())
2374 {
2375 mExtensionStrings.push_back(MakeStaticString(extensionString));
2376 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002377 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002378
Bryan Bernhart58806562017-01-05 13:09:31 -08002379 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2380
Geoff Langc339c4e2016-11-29 10:37:36 -05002381 mRequestableExtensionStrings.clear();
2382 for (const auto &extensionInfo : GetExtensionInfoMap())
2383 {
2384 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002385 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2386 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002387 {
2388 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2389 }
2390 }
2391 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002392}
2393
Geoff Langc339c4e2016-11-29 10:37:36 -05002394const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002395{
Geoff Langc339c4e2016-11-29 10:37:36 -05002396 switch (name)
2397 {
2398 case GL_VENDOR:
2399 return reinterpret_cast<const GLubyte *>("Google Inc.");
2400
2401 case GL_RENDERER:
2402 return reinterpret_cast<const GLubyte *>(mRendererString);
2403
2404 case GL_VERSION:
2405 return reinterpret_cast<const GLubyte *>(mVersionString);
2406
2407 case GL_SHADING_LANGUAGE_VERSION:
2408 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2409
2410 case GL_EXTENSIONS:
2411 return reinterpret_cast<const GLubyte *>(mExtensionString);
2412
2413 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2414 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2415
2416 default:
2417 UNREACHABLE();
2418 return nullptr;
2419 }
Geoff Langcec35902014-04-16 10:52:36 -04002420}
2421
Geoff Langc339c4e2016-11-29 10:37:36 -05002422const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002423{
Geoff Langc339c4e2016-11-29 10:37:36 -05002424 switch (name)
2425 {
2426 case GL_EXTENSIONS:
2427 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2428
2429 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2430 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2431
2432 default:
2433 UNREACHABLE();
2434 return nullptr;
2435 }
Geoff Langcec35902014-04-16 10:52:36 -04002436}
2437
2438size_t Context::getExtensionStringCount() const
2439{
2440 return mExtensionStrings.size();
2441}
2442
Geoff Langc339c4e2016-11-29 10:37:36 -05002443void Context::requestExtension(const char *name)
2444{
2445 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2446 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2447 const auto &extension = extensionInfos.at(name);
2448 ASSERT(extension.Requestable);
2449
2450 if (mExtensions.*(extension.ExtensionsMember))
2451 {
2452 // Extension already enabled
2453 return;
2454 }
2455
2456 mExtensions.*(extension.ExtensionsMember) = true;
2457 updateCaps();
2458 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002459
2460 // Re-create the compiler with the requested extensions enabled.
2461 SafeDelete(mCompiler);
2462 mCompiler = new Compiler(mImplementation.get(), mState);
Geoff Langc339c4e2016-11-29 10:37:36 -05002463}
2464
2465size_t Context::getRequestableExtensionStringCount() const
2466{
2467 return mRequestableExtensionStrings.size();
2468}
2469
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002470void Context::beginTransformFeedback(GLenum primitiveMode)
2471{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002472 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002473 ASSERT(transformFeedback != nullptr);
2474 ASSERT(!transformFeedback->isPaused());
2475
Jamie Madill6c1f6712017-02-14 19:08:04 -05002476 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002477}
2478
2479bool Context::hasActiveTransformFeedback(GLuint program) const
2480{
2481 for (auto pair : mTransformFeedbackMap)
2482 {
2483 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2484 {
2485 return true;
2486 }
2487 }
2488 return false;
2489}
2490
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002491void Context::initCaps(const egl::DisplayExtensions &displayExtensions)
Geoff Lang493daf52014-07-03 13:38:44 -04002492{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002493 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002494
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002495 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002496
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002497 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002498
Geoff Langeb66a6e2016-10-31 13:06:12 -04002499 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002500 {
2501 // Disable ES3+ extensions
2502 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002503 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002504 mExtensions.textureNorm16 = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002505 }
2506
Geoff Langeb66a6e2016-10-31 13:06:12 -04002507 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002508 {
2509 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
2510 //mExtensions.sRGB = false;
2511 }
2512
Jamie Madill00ed7a12016-05-19 13:13:38 -04002513 // Some extensions are always available because they are implemented in the GL layer.
2514 mExtensions.bindUniformLocation = true;
2515 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002516 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002517 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002518 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002519
2520 // Enable the no error extension if the context was created with the flag.
2521 mExtensions.noError = mSkipValidation;
2522
Corentin Wallezccab69d2017-01-27 16:57:15 -05002523 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002524 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002525
Geoff Lang70d0f492015-12-10 17:45:46 -05002526 // Explicitly enable GL_KHR_debug
2527 mExtensions.debug = true;
2528 mExtensions.maxDebugMessageLength = 1024;
2529 mExtensions.maxDebugLoggedMessages = 1024;
2530 mExtensions.maxDebugGroupStackDepth = 1024;
2531 mExtensions.maxLabelLength = 1024;
2532
Geoff Langff5b2d52016-09-07 11:32:23 -04002533 // Explicitly enable GL_ANGLE_robust_client_memory
2534 mExtensions.robustClientMemory = true;
2535
Geoff Lang301d1612014-07-09 10:34:37 -04002536 // Apply implementation limits
2537 mCaps.maxVertexAttributes = std::min<GLuint>(mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002538 mCaps.maxVertexAttribBindings =
2539 getClientVersion() < ES_3_1
2540 ? mCaps.maxVertexAttributes
2541 : std::min<GLuint>(mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2542
Geoff Lang301d1612014-07-09 10:34:37 -04002543 mCaps.maxVertexUniformBlocks = std::min<GLuint>(mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2544 mCaps.maxVertexOutputComponents = std::min<GLuint>(mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2545
2546 mCaps.maxFragmentInputComponents = std::min<GLuint>(mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
Geoff Lang3a61c322014-07-10 13:01:54 -04002547
Geoff Langc287ea62016-09-16 14:46:51 -04002548 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002549 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002550 for (const auto &extensionInfo : GetExtensionInfoMap())
2551 {
2552 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002553 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002554 {
2555 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2556 }
2557 }
2558
2559 // Generate texture caps
2560 updateCaps();
2561}
2562
2563void Context::updateCaps()
2564{
Geoff Lang900013c2014-07-07 11:32:19 -04002565 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002566 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002567
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002568 for (auto capsIt : mImplementation->getNativeTextureCaps())
Geoff Lang493daf52014-07-03 13:38:44 -04002569 {
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002570 GLenum format = capsIt.first;
2571 TextureCaps formatCaps = capsIt.second;
Geoff Lang493daf52014-07-03 13:38:44 -04002572
Geoff Lang5d601382014-07-22 15:14:06 -04002573 const InternalFormat &formatInfo = GetInternalFormatInfo(format);
Geoff Langd87878e2014-09-19 15:42:59 -04002574
Geoff Lang0d8b7242015-09-09 14:56:53 -04002575 // Update the format caps based on the client version and extensions.
2576 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2577 // ES3.
2578 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002579 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002580 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002581 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002582 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002583 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002584
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002585 // OpenGL ES does not support multisampling with non-rendererable formats
2586 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
2587 if (!formatInfo.renderSupport ||
2588 (getClientVersion() < ES_3_1 &&
2589 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002590 {
Geoff Langd87878e2014-09-19 15:42:59 -04002591 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002592 }
Geoff Langd87878e2014-09-19 15:42:59 -04002593
2594 if (formatCaps.texturable && formatInfo.compressed)
2595 {
2596 mCaps.compressedTextureFormats.push_back(format);
2597 }
2598
2599 mTextureCaps.insert(format, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002600 }
2601}
2602
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002603void Context::initWorkarounds()
2604{
2605 // Lose the context upon out of memory error if the application is
2606 // expecting to watch for those events.
2607 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2608}
2609
Jamie Madill1b94d432015-08-07 13:23:23 -04002610void Context::syncRendererState()
2611{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002612 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Frank Henigman5a53d542017-02-16 21:24:10 -05002613 mImplementation->syncState(dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002614 mGLState.clearDirtyBits();
2615 mGLState.syncDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -04002616}
2617
Jamie Madillad9f24e2016-02-12 09:27:24 -05002618void Context::syncRendererState(const State::DirtyBits &bitMask,
2619 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002620{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002621 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Frank Henigman5a53d542017-02-16 21:24:10 -05002622 mImplementation->syncState(dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002623 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillc9d442d2016-01-20 11:17:24 -05002624
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002625 mGLState.syncDirtyObjects(objectMask);
Jamie Madill1b94d432015-08-07 13:23:23 -04002626}
Jamie Madillc29968b2016-01-20 11:17:23 -05002627
2628void Context::blitFramebuffer(GLint srcX0,
2629 GLint srcY0,
2630 GLint srcX1,
2631 GLint srcY1,
2632 GLint dstX0,
2633 GLint dstY0,
2634 GLint dstX1,
2635 GLint dstY1,
2636 GLbitfield mask,
2637 GLenum filter)
2638{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002639 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002640 ASSERT(drawFramebuffer);
2641
2642 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2643 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2644
Jamie Madillad9f24e2016-02-12 09:27:24 -05002645 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002646
Jamie Madill8415b5f2016-04-26 13:41:39 -04002647 handleError(drawFramebuffer->blit(mImplementation.get(), srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002648}
Jamie Madillc29968b2016-01-20 11:17:23 -05002649
2650void Context::clear(GLbitfield mask)
2651{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002652 syncStateForClear();
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002653 handleError(mGLState.getDrawFramebuffer()->clear(mImplementation.get(), mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002654}
2655
2656void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2657{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002658 syncStateForClear();
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002659 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(mImplementation.get(), buffer,
2660 drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002661}
2662
2663void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2664{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002665 syncStateForClear();
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002666 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(mImplementation.get(), buffer,
2667 drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002668}
2669
2670void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2671{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002672 syncStateForClear();
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002673 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(mImplementation.get(), buffer,
2674 drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002675}
2676
2677void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2678{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002679 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002680 ASSERT(framebufferObject);
2681
2682 // If a buffer is not present, the clear has no effect
2683 if (framebufferObject->getDepthbuffer() == nullptr &&
2684 framebufferObject->getStencilbuffer() == nullptr)
2685 {
2686 return;
2687 }
2688
Jamie Madillad9f24e2016-02-12 09:27:24 -05002689 syncStateForClear();
Jamie Madill8415b5f2016-04-26 13:41:39 -04002690 handleError(framebufferObject->clearBufferfi(mImplementation.get(), buffer, drawbuffer, depth,
2691 stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05002692}
2693
2694void Context::readPixels(GLint x,
2695 GLint y,
2696 GLsizei width,
2697 GLsizei height,
2698 GLenum format,
2699 GLenum type,
2700 GLvoid *pixels)
2701{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002702 if (width == 0 || height == 0)
2703 {
2704 return;
2705 }
2706
Jamie Madillad9f24e2016-02-12 09:27:24 -05002707 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05002708
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002709 Framebuffer *framebufferObject = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002710 ASSERT(framebufferObject);
2711
2712 Rectangle area(x, y, width, height);
Jamie Madill8415b5f2016-04-26 13:41:39 -04002713 handleError(framebufferObject->readPixels(mImplementation.get(), area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05002714}
2715
2716void Context::copyTexImage2D(GLenum target,
2717 GLint level,
2718 GLenum internalformat,
2719 GLint x,
2720 GLint y,
2721 GLsizei width,
2722 GLsizei height,
2723 GLint border)
2724{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002725 // Only sync the read FBO
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002726 mGLState.syncDirtyObject(GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002727
Jamie Madillc29968b2016-01-20 11:17:23 -05002728 Rectangle sourceArea(x, y, width, height);
2729
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002730 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002731 Texture *texture =
2732 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002733 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002734}
2735
2736void Context::copyTexSubImage2D(GLenum target,
2737 GLint level,
2738 GLint xoffset,
2739 GLint yoffset,
2740 GLint x,
2741 GLint y,
2742 GLsizei width,
2743 GLsizei height)
2744{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002745 if (width == 0 || height == 0)
2746 {
2747 return;
2748 }
2749
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002750 // Only sync the read FBO
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002751 mGLState.syncDirtyObject(GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002752
Jamie Madillc29968b2016-01-20 11:17:23 -05002753 Offset destOffset(xoffset, yoffset, 0);
2754 Rectangle sourceArea(x, y, width, height);
2755
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002756 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002757 Texture *texture =
2758 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002759 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002760}
2761
2762void Context::copyTexSubImage3D(GLenum target,
2763 GLint level,
2764 GLint xoffset,
2765 GLint yoffset,
2766 GLint zoffset,
2767 GLint x,
2768 GLint y,
2769 GLsizei width,
2770 GLsizei height)
2771{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002772 if (width == 0 || height == 0)
2773 {
2774 return;
2775 }
2776
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002777 // Only sync the read FBO
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002778 mGLState.syncDirtyObject(GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002779
Jamie Madillc29968b2016-01-20 11:17:23 -05002780 Offset destOffset(xoffset, yoffset, zoffset);
2781 Rectangle sourceArea(x, y, width, height);
2782
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002783 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002784 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002785 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002786}
2787
2788void Context::framebufferTexture2D(GLenum target,
2789 GLenum attachment,
2790 GLenum textarget,
2791 GLuint texture,
2792 GLint level)
2793{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002794 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05002795 ASSERT(framebuffer);
2796
2797 if (texture != 0)
2798 {
2799 Texture *textureObj = getTexture(texture);
2800
2801 ImageIndex index = ImageIndex::MakeInvalid();
2802
2803 if (textarget == GL_TEXTURE_2D)
2804 {
2805 index = ImageIndex::Make2D(level);
2806 }
JiangYizhoubddc46b2016-12-09 09:50:51 +08002807 else if (textarget == GL_TEXTURE_2D_MULTISAMPLE)
2808 {
2809 ASSERT(level == 0);
2810 index = ImageIndex::Make2DMultisample();
2811 }
Jamie Madillc29968b2016-01-20 11:17:23 -05002812 else
2813 {
2814 ASSERT(IsCubeMapTextureTarget(textarget));
2815 index = ImageIndex::MakeCube(textarget, level);
2816 }
2817
Jamie Madilla02315b2017-02-23 14:14:47 -05002818 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05002819 }
2820 else
2821 {
Jamie Madilla02315b2017-02-23 14:14:47 -05002822 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05002823 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002824
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002825 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05002826}
2827
2828void Context::framebufferRenderbuffer(GLenum target,
2829 GLenum attachment,
2830 GLenum renderbuffertarget,
2831 GLuint renderbuffer)
2832{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002833 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05002834 ASSERT(framebuffer);
2835
2836 if (renderbuffer != 0)
2837 {
2838 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05002839
2840 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05002841 renderbufferObject);
2842 }
2843 else
2844 {
Jamie Madilla02315b2017-02-23 14:14:47 -05002845 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05002846 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002847
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002848 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05002849}
2850
2851void Context::framebufferTextureLayer(GLenum target,
2852 GLenum attachment,
2853 GLuint texture,
2854 GLint level,
2855 GLint layer)
2856{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002857 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05002858 ASSERT(framebuffer);
2859
2860 if (texture != 0)
2861 {
2862 Texture *textureObject = getTexture(texture);
2863
2864 ImageIndex index = ImageIndex::MakeInvalid();
2865
2866 if (textureObject->getTarget() == GL_TEXTURE_3D)
2867 {
2868 index = ImageIndex::Make3D(level, layer);
2869 }
2870 else
2871 {
2872 ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY);
2873 index = ImageIndex::Make2DArray(level, layer);
2874 }
2875
Jamie Madilla02315b2017-02-23 14:14:47 -05002876 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05002877 }
2878 else
2879 {
Jamie Madilla02315b2017-02-23 14:14:47 -05002880 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05002881 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002882
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002883 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05002884}
2885
2886void Context::drawBuffers(GLsizei n, const GLenum *bufs)
2887{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002888 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002889 ASSERT(framebuffer);
2890 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002891 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05002892}
2893
2894void Context::readBuffer(GLenum mode)
2895{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002896 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002897 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002898 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05002899}
2900
2901void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
2902{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002903 // Only sync the FBO
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002904 mGLState.syncDirtyObject(target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002905
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002906 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05002907 ASSERT(framebuffer);
2908
2909 // The specification isn't clear what should be done when the framebuffer isn't complete.
2910 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill437fa652016-05-03 15:13:24 -04002911 handleError(framebuffer->discard(numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05002912}
2913
2914void Context::invalidateFramebuffer(GLenum target,
2915 GLsizei numAttachments,
2916 const GLenum *attachments)
2917{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002918 // Only sync the FBO
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002919 mGLState.syncDirtyObject(target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002920
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002921 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05002922 ASSERT(framebuffer);
2923
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002924 if (framebuffer->checkStatus(mState) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05002925 {
Jamie Madill437fa652016-05-03 15:13:24 -04002926 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05002927 }
Jamie Madill437fa652016-05-03 15:13:24 -04002928
2929 handleError(framebuffer->invalidate(numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05002930}
2931
2932void Context::invalidateSubFramebuffer(GLenum target,
2933 GLsizei numAttachments,
2934 const GLenum *attachments,
2935 GLint x,
2936 GLint y,
2937 GLsizei width,
2938 GLsizei height)
2939{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002940 // Only sync the FBO
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002941 mGLState.syncDirtyObject(target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002942
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002943 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05002944 ASSERT(framebuffer);
2945
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002946 if (framebuffer->checkStatus(mState) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05002947 {
Jamie Madill437fa652016-05-03 15:13:24 -04002948 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05002949 }
Jamie Madill437fa652016-05-03 15:13:24 -04002950
2951 Rectangle area(x, y, width, height);
2952 handleError(framebuffer->invalidateSub(numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05002953}
2954
Jamie Madill73a84962016-02-12 09:27:23 -05002955void Context::texImage2D(GLenum target,
2956 GLint level,
2957 GLint internalformat,
2958 GLsizei width,
2959 GLsizei height,
2960 GLint border,
2961 GLenum format,
2962 GLenum type,
2963 const GLvoid *pixels)
2964{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002965 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05002966
2967 Extents size(width, height, 1);
2968 Texture *texture =
2969 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002970 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
2971 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05002972}
2973
2974void Context::texImage3D(GLenum target,
2975 GLint level,
2976 GLint internalformat,
2977 GLsizei width,
2978 GLsizei height,
2979 GLsizei depth,
2980 GLint border,
2981 GLenum format,
2982 GLenum type,
2983 const GLvoid *pixels)
2984{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002985 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05002986
2987 Extents size(width, height, depth);
2988 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002989 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
2990 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05002991}
2992
2993void Context::texSubImage2D(GLenum target,
2994 GLint level,
2995 GLint xoffset,
2996 GLint yoffset,
2997 GLsizei width,
2998 GLsizei height,
2999 GLenum format,
3000 GLenum type,
3001 const GLvoid *pixels)
3002{
3003 // Zero sized uploads are valid but no-ops
3004 if (width == 0 || height == 0)
3005 {
3006 return;
3007 }
3008
Jamie Madillad9f24e2016-02-12 09:27:24 -05003009 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003010
3011 Box area(xoffset, yoffset, 0, width, height, 1);
3012 Texture *texture =
3013 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003014 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3015 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003016}
3017
3018void Context::texSubImage3D(GLenum target,
3019 GLint level,
3020 GLint xoffset,
3021 GLint yoffset,
3022 GLint zoffset,
3023 GLsizei width,
3024 GLsizei height,
3025 GLsizei depth,
3026 GLenum format,
3027 GLenum type,
3028 const GLvoid *pixels)
3029{
3030 // Zero sized uploads are valid but no-ops
3031 if (width == 0 || height == 0 || depth == 0)
3032 {
3033 return;
3034 }
3035
Jamie Madillad9f24e2016-02-12 09:27:24 -05003036 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003037
3038 Box area(xoffset, yoffset, zoffset, width, height, depth);
3039 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003040 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3041 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003042}
3043
3044void Context::compressedTexImage2D(GLenum target,
3045 GLint level,
3046 GLenum internalformat,
3047 GLsizei width,
3048 GLsizei height,
3049 GLint border,
3050 GLsizei imageSize,
3051 const GLvoid *data)
3052{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003053 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003054
3055 Extents size(width, height, 1);
3056 Texture *texture =
3057 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003058 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003059 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003060 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003061}
3062
3063void Context::compressedTexImage3D(GLenum target,
3064 GLint level,
3065 GLenum internalformat,
3066 GLsizei width,
3067 GLsizei height,
3068 GLsizei depth,
3069 GLint border,
3070 GLsizei imageSize,
3071 const GLvoid *data)
3072{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003073 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003074
3075 Extents size(width, height, depth);
3076 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003077 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003078 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003079 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003080}
3081
3082void Context::compressedTexSubImage2D(GLenum target,
3083 GLint level,
3084 GLint xoffset,
3085 GLint yoffset,
3086 GLsizei width,
3087 GLsizei height,
3088 GLenum format,
3089 GLsizei imageSize,
3090 const GLvoid *data)
3091{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003092 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003093
3094 Box area(xoffset, yoffset, 0, width, height, 1);
3095 Texture *texture =
3096 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003097 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003098 format, imageSize,
3099 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003100}
3101
3102void Context::compressedTexSubImage3D(GLenum target,
3103 GLint level,
3104 GLint xoffset,
3105 GLint yoffset,
3106 GLint zoffset,
3107 GLsizei width,
3108 GLsizei height,
3109 GLsizei depth,
3110 GLenum format,
3111 GLsizei imageSize,
3112 const GLvoid *data)
3113{
3114 // Zero sized uploads are valid but no-ops
3115 if (width == 0 || height == 0)
3116 {
3117 return;
3118 }
3119
Jamie Madillad9f24e2016-02-12 09:27:24 -05003120 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003121
3122 Box area(xoffset, yoffset, zoffset, width, height, depth);
3123 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003124 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003125 format, imageSize,
3126 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003127}
3128
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003129void Context::generateMipmap(GLenum target)
3130{
3131 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003132 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003133}
3134
Geoff Lang97073d12016-04-20 10:42:34 -07003135void Context::copyTextureCHROMIUM(GLuint sourceId,
3136 GLuint destId,
3137 GLint internalFormat,
3138 GLenum destType,
3139 GLboolean unpackFlipY,
3140 GLboolean unpackPremultiplyAlpha,
3141 GLboolean unpackUnmultiplyAlpha)
3142{
3143 syncStateForTexImage();
3144
3145 gl::Texture *sourceTexture = getTexture(sourceId);
3146 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003147 handleError(destTexture->copyTexture(this, internalFormat, destType, unpackFlipY == GL_TRUE,
Geoff Lang97073d12016-04-20 10:42:34 -07003148 unpackPremultiplyAlpha == GL_TRUE,
3149 unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
3150}
3151
3152void Context::copySubTextureCHROMIUM(GLuint sourceId,
3153 GLuint destId,
3154 GLint xoffset,
3155 GLint yoffset,
3156 GLint x,
3157 GLint y,
3158 GLsizei width,
3159 GLsizei height,
3160 GLboolean unpackFlipY,
3161 GLboolean unpackPremultiplyAlpha,
3162 GLboolean unpackUnmultiplyAlpha)
3163{
3164 // Zero sized copies are valid but no-ops
3165 if (width == 0 || height == 0)
3166 {
3167 return;
3168 }
3169
3170 syncStateForTexImage();
3171
3172 gl::Texture *sourceTexture = getTexture(sourceId);
3173 gl::Texture *destTexture = getTexture(destId);
3174 Offset offset(xoffset, yoffset, 0);
3175 Rectangle area(x, y, width, height);
Jamie Madill8897afa2017-02-06 17:17:23 -05003176 handleError(destTexture->copySubTexture(this, offset, area, unpackFlipY == GL_TRUE,
Geoff Lang97073d12016-04-20 10:42:34 -07003177 unpackPremultiplyAlpha == GL_TRUE,
3178 unpackUnmultiplyAlpha == GL_TRUE, sourceTexture));
3179}
3180
Geoff Lang47110bf2016-04-20 11:13:22 -07003181void Context::compressedCopyTextureCHROMIUM(GLuint sourceId, GLuint destId)
3182{
3183 syncStateForTexImage();
3184
3185 gl::Texture *sourceTexture = getTexture(sourceId);
3186 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003187 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003188}
3189
Geoff Lang496c02d2016-10-20 11:38:11 -07003190void Context::getBufferPointerv(GLenum target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003191{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003192 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003193 ASSERT(buffer);
3194
Geoff Lang496c02d2016-10-20 11:38:11 -07003195 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003196}
3197
3198GLvoid *Context::mapBuffer(GLenum target, GLenum access)
3199{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003200 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003201 ASSERT(buffer);
3202
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003203 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003204 if (error.isError())
3205 {
Jamie Madill437fa652016-05-03 15:13:24 -04003206 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003207 return nullptr;
3208 }
3209
3210 return buffer->getMapPointer();
3211}
3212
3213GLboolean Context::unmapBuffer(GLenum target)
3214{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003215 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003216 ASSERT(buffer);
3217
3218 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003219 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003220 if (error.isError())
3221 {
Jamie Madill437fa652016-05-03 15:13:24 -04003222 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003223 return GL_FALSE;
3224 }
3225
3226 return result;
3227}
3228
3229GLvoid *Context::mapBufferRange(GLenum target,
3230 GLintptr offset,
3231 GLsizeiptr length,
3232 GLbitfield access)
3233{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003234 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003235 ASSERT(buffer);
3236
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003237 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003238 if (error.isError())
3239 {
Jamie Madill437fa652016-05-03 15:13:24 -04003240 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003241 return nullptr;
3242 }
3243
3244 return buffer->getMapPointer();
3245}
3246
3247void Context::flushMappedBufferRange(GLenum /*target*/, GLintptr /*offset*/, GLsizeiptr /*length*/)
3248{
3249 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3250}
3251
Jamie Madillad9f24e2016-02-12 09:27:24 -05003252void Context::syncStateForReadPixels()
3253{
3254 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3255}
3256
3257void Context::syncStateForTexImage()
3258{
3259 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3260}
3261
3262void Context::syncStateForClear()
3263{
3264 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3265}
3266
3267void Context::syncStateForBlit()
3268{
3269 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3270}
3271
Jamie Madillc20ab272016-06-09 07:20:46 -07003272void Context::activeTexture(GLenum texture)
3273{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003274 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003275}
3276
3277void Context::blendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
3278{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003279 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003280}
3281
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003282void Context::blendEquation(GLenum mode)
3283{
3284 mGLState.setBlendEquation(mode, mode);
3285}
3286
Jamie Madillc20ab272016-06-09 07:20:46 -07003287void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3288{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003289 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003290}
3291
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003292void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3293{
3294 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3295}
3296
Jamie Madillc20ab272016-06-09 07:20:46 -07003297void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3298{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003299 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003300}
3301
3302void Context::clearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha)
3303{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003304 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003305}
3306
3307void Context::clearDepthf(GLclampf depth)
3308{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003309 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003310}
3311
3312void Context::clearStencil(GLint s)
3313{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003314 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003315}
3316
3317void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3318{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003319 mGLState.setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003320}
3321
3322void Context::cullFace(GLenum mode)
3323{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003324 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003325}
3326
3327void Context::depthFunc(GLenum func)
3328{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003329 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003330}
3331
3332void Context::depthMask(GLboolean flag)
3333{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003334 mGLState.setDepthMask(flag != GL_FALSE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003335}
3336
3337void Context::depthRangef(GLclampf zNear, GLclampf zFar)
3338{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003339 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003340}
3341
3342void Context::disable(GLenum cap)
3343{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003344 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003345}
3346
3347void Context::disableVertexAttribArray(GLuint index)
3348{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003349 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003350}
3351
3352void Context::enable(GLenum cap)
3353{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003354 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003355}
3356
3357void Context::enableVertexAttribArray(GLuint index)
3358{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003359 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003360}
3361
3362void Context::frontFace(GLenum mode)
3363{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003364 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003365}
3366
3367void Context::hint(GLenum target, GLenum mode)
3368{
3369 switch (target)
3370 {
3371 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003372 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003373 break;
3374
3375 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003376 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003377 break;
3378
3379 default:
3380 UNREACHABLE();
3381 return;
3382 }
3383}
3384
3385void Context::lineWidth(GLfloat width)
3386{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003387 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003388}
3389
3390void Context::pixelStorei(GLenum pname, GLint param)
3391{
3392 switch (pname)
3393 {
3394 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003395 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003396 break;
3397
3398 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003399 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003400 break;
3401
3402 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003403 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003404 break;
3405
3406 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003407 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003408 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003409 break;
3410
3411 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003412 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003413 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003414 break;
3415
3416 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003417 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003418 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003419 break;
3420
3421 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003422 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003423 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003424 break;
3425
3426 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003427 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003428 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003429 break;
3430
3431 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003432 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003433 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003434 break;
3435
3436 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003437 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003438 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003439 break;
3440
3441 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003442 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003443 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003444 break;
3445
3446 default:
3447 UNREACHABLE();
3448 return;
3449 }
3450}
3451
3452void Context::polygonOffset(GLfloat factor, GLfloat units)
3453{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003454 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003455}
3456
3457void Context::sampleCoverage(GLclampf value, GLboolean invert)
3458{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003459 mGLState.setSampleCoverageParams(clamp01(value), invert == GL_TRUE);
Jamie Madillc20ab272016-06-09 07:20:46 -07003460}
3461
3462void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3463{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003464 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003465}
3466
3467void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3468{
3469 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3470 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003471 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003472 }
3473
3474 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3475 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003476 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003477 }
3478}
3479
3480void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3481{
3482 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3483 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003484 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003485 }
3486
3487 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3488 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003489 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003490 }
3491}
3492
3493void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3494{
3495 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3496 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003497 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003498 }
3499
3500 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3501 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003502 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003503 }
3504}
3505
3506void Context::vertexAttrib1f(GLuint index, GLfloat x)
3507{
3508 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003509 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003510}
3511
3512void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3513{
3514 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003515 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003516}
3517
3518void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3519{
3520 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003521 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003522}
3523
3524void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3525{
3526 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003527 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003528}
3529
3530void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3531{
3532 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003533 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003534}
3535
3536void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3537{
3538 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003539 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003540}
3541
3542void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3543{
3544 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003545 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003546}
3547
3548void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3549{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003550 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003551}
3552
3553void Context::vertexAttribPointer(GLuint index,
3554 GLint size,
3555 GLenum type,
3556 GLboolean normalized,
3557 GLsizei stride,
3558 const GLvoid *ptr)
3559{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003560 mGLState.setVertexAttribState(index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size, type,
3561 normalized == GL_TRUE, false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003562}
3563
3564void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3565{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003566 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003567}
3568
3569void Context::vertexAttribIPointer(GLuint index,
3570 GLint size,
3571 GLenum type,
3572 GLsizei stride,
3573 const GLvoid *pointer)
3574{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003575 mGLState.setVertexAttribState(index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size, type,
3576 false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003577}
3578
3579void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3580{
3581 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003582 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003583}
3584
3585void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
3586{
3587 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003588 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003589}
3590
3591void Context::vertexAttribI4iv(GLuint index, const GLint *v)
3592{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003593 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003594}
3595
3596void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
3597{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003598 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003599}
3600
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003601void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
3602{
3603 const VertexAttribCurrentValueData &currentValues =
3604 getGLState().getVertexAttribCurrentValue(index);
3605 const VertexArray *vao = getGLState().getVertexArray();
3606 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3607 currentValues, pname, params);
3608}
3609
3610void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
3611{
3612 const VertexAttribCurrentValueData &currentValues =
3613 getGLState().getVertexAttribCurrentValue(index);
3614 const VertexArray *vao = getGLState().getVertexArray();
3615 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3616 currentValues, pname, params);
3617}
3618
3619void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
3620{
3621 const VertexAttribCurrentValueData &currentValues =
3622 getGLState().getVertexAttribCurrentValue(index);
3623 const VertexArray *vao = getGLState().getVertexArray();
3624 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3625 currentValues, pname, params);
3626}
3627
3628void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
3629{
3630 const VertexAttribCurrentValueData &currentValues =
3631 getGLState().getVertexAttribCurrentValue(index);
3632 const VertexArray *vao = getGLState().getVertexArray();
3633 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3634 currentValues, pname, params);
3635}
3636
3637void Context::getVertexAttribPointerv(GLuint index, GLenum pname, GLvoid **pointer)
3638{
3639 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
3640 QueryVertexAttribPointerv(attrib, pname, pointer);
3641}
3642
Jamie Madillc20ab272016-06-09 07:20:46 -07003643void Context::debugMessageControl(GLenum source,
3644 GLenum type,
3645 GLenum severity,
3646 GLsizei count,
3647 const GLuint *ids,
3648 GLboolean enabled)
3649{
3650 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003651 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
3652 (enabled != GL_FALSE));
Jamie Madillc20ab272016-06-09 07:20:46 -07003653}
3654
3655void Context::debugMessageInsert(GLenum source,
3656 GLenum type,
3657 GLuint id,
3658 GLenum severity,
3659 GLsizei length,
3660 const GLchar *buf)
3661{
3662 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003663 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003664}
3665
3666void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
3667{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003668 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07003669}
3670
3671GLuint Context::getDebugMessageLog(GLuint count,
3672 GLsizei bufSize,
3673 GLenum *sources,
3674 GLenum *types,
3675 GLuint *ids,
3676 GLenum *severities,
3677 GLsizei *lengths,
3678 GLchar *messageLog)
3679{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003680 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
3681 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07003682}
3683
3684void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
3685{
3686 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003687 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07003688}
3689
3690void Context::popDebugGroup()
3691{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003692 mGLState.getDebug().popGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07003693}
3694
Jamie Madill29639852016-09-02 15:00:09 -04003695void Context::bufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage)
3696{
3697 Buffer *buffer = mGLState.getTargetBuffer(target);
3698 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08003699 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04003700}
3701
3702void Context::bufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data)
3703{
3704 if (data == nullptr)
3705 {
3706 return;
3707 }
3708
3709 Buffer *buffer = mGLState.getTargetBuffer(target);
3710 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08003711 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04003712}
3713
Jamie Madillef300b12016-10-07 15:12:09 -04003714void Context::attachShader(GLuint program, GLuint shader)
3715{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05003716 auto programObject = mState.mShaderPrograms->getProgram(program);
3717 auto shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04003718 ASSERT(programObject && shaderObject);
3719 programObject->attachShader(shaderObject);
3720}
3721
Kenneth Russellf2f6f652016-10-05 19:53:23 -07003722const Workarounds &Context::getWorkarounds() const
3723{
3724 return mWorkarounds;
3725}
3726
Jamie Madillb0817d12016-11-01 15:48:31 -04003727void Context::copyBufferSubData(GLenum readTarget,
3728 GLenum writeTarget,
3729 GLintptr readOffset,
3730 GLintptr writeOffset,
3731 GLsizeiptr size)
3732{
3733 // if size is zero, the copy is a successful no-op
3734 if (size == 0)
3735 {
3736 return;
3737 }
3738
3739 // TODO(jmadill): cache these.
3740 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
3741 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
3742
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003743 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04003744}
3745
Jamie Madill01a80ee2016-11-07 12:06:18 -05003746void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
3747{
3748 Program *programObject = getProgram(program);
3749 // TODO(jmadill): Re-use this from the validation if possible.
3750 ASSERT(programObject);
3751 programObject->bindAttributeLocation(index, name);
3752}
3753
3754void Context::bindBuffer(GLenum target, GLuint buffer)
3755{
3756 switch (target)
3757 {
3758 case GL_ARRAY_BUFFER:
3759 bindArrayBuffer(buffer);
3760 break;
3761 case GL_ELEMENT_ARRAY_BUFFER:
3762 bindElementArrayBuffer(buffer);
3763 break;
3764 case GL_COPY_READ_BUFFER:
3765 bindCopyReadBuffer(buffer);
3766 break;
3767 case GL_COPY_WRITE_BUFFER:
3768 bindCopyWriteBuffer(buffer);
3769 break;
3770 case GL_PIXEL_PACK_BUFFER:
3771 bindPixelPackBuffer(buffer);
3772 break;
3773 case GL_PIXEL_UNPACK_BUFFER:
3774 bindPixelUnpackBuffer(buffer);
3775 break;
3776 case GL_UNIFORM_BUFFER:
3777 bindGenericUniformBuffer(buffer);
3778 break;
3779 case GL_TRANSFORM_FEEDBACK_BUFFER:
3780 bindGenericTransformFeedbackBuffer(buffer);
3781 break;
Geoff Lang3b573612016-10-31 14:08:10 -04003782 case GL_ATOMIC_COUNTER_BUFFER:
Jiajia Qin6eafb042016-12-27 17:04:07 +08003783 bindGenericAtomicCounterBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04003784 break;
3785 case GL_SHADER_STORAGE_BUFFER:
Geoff Lang9f090372016-12-02 10:20:43 -05003786 if (buffer != 0)
3787 {
3788 // Binding buffers to this binding point is not implemented yet.
3789 UNIMPLEMENTED();
3790 }
Geoff Lang3b573612016-10-31 14:08:10 -04003791 break;
3792 case GL_DRAW_INDIRECT_BUFFER:
Jiajia Qin9d7d0b12016-11-29 16:30:31 +08003793 bindDrawIndirectBuffer(buffer);
Geoff Lang3b573612016-10-31 14:08:10 -04003794 break;
3795 case GL_DISPATCH_INDIRECT_BUFFER:
Geoff Lang9f090372016-12-02 10:20:43 -05003796 if (buffer != 0)
3797 {
3798 // Binding buffers to this binding point is not implemented yet.
3799 UNIMPLEMENTED();
3800 }
Geoff Lang3b573612016-10-31 14:08:10 -04003801 break;
Jamie Madill01a80ee2016-11-07 12:06:18 -05003802
3803 default:
3804 UNREACHABLE();
3805 break;
3806 }
3807}
3808
Jiajia Qin6eafb042016-12-27 17:04:07 +08003809void Context::bindBufferBase(GLenum target, GLuint index, GLuint buffer)
3810{
3811 bindBufferRange(target, index, buffer, 0, 0);
3812}
3813
3814void Context::bindBufferRange(GLenum target,
3815 GLuint index,
3816 GLuint buffer,
3817 GLintptr offset,
3818 GLsizeiptr size)
3819{
3820 switch (target)
3821 {
3822 case GL_TRANSFORM_FEEDBACK_BUFFER:
3823 bindIndexedTransformFeedbackBuffer(buffer, index, offset, size);
3824 bindGenericTransformFeedbackBuffer(buffer);
3825 break;
3826 case GL_UNIFORM_BUFFER:
3827 bindIndexedUniformBuffer(buffer, index, offset, size);
3828 bindGenericUniformBuffer(buffer);
3829 break;
3830 case GL_ATOMIC_COUNTER_BUFFER:
3831 bindIndexedAtomicCounterBuffer(buffer, index, offset, size);
3832 bindGenericAtomicCounterBuffer(buffer);
3833 break;
3834 case GL_SHADER_STORAGE_BUFFER:
3835 if (buffer != 0)
3836 {
3837 // Binding buffers to this binding point is not implemented yet.
3838 UNIMPLEMENTED();
3839 }
3840 break;
3841 default:
3842 UNREACHABLE();
3843 break;
3844 }
3845}
3846
Jamie Madill01a80ee2016-11-07 12:06:18 -05003847void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
3848{
3849 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
3850 {
3851 bindReadFramebuffer(framebuffer);
3852 }
3853
3854 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
3855 {
3856 bindDrawFramebuffer(framebuffer);
3857 }
3858}
3859
3860void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
3861{
3862 ASSERT(target == GL_RENDERBUFFER);
3863 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05003864 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill01a80ee2016-11-07 12:06:18 -05003865 mGLState.setRenderbufferBinding(object);
3866}
3867
JiangYizhoubddc46b2016-12-09 09:50:51 +08003868void Context::texStorage2DMultisample(GLenum target,
3869 GLsizei samples,
3870 GLenum internalformat,
3871 GLsizei width,
3872 GLsizei height,
3873 GLboolean fixedsamplelocations)
3874{
3875 Extents size(width, height, 1);
3876 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003877 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
JiangYizhoubddc46b2016-12-09 09:50:51 +08003878 fixedsamplelocations));
3879}
3880
3881void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
3882{
3883 mGLState.syncDirtyObject(GL_READ_FRAMEBUFFER);
3884 const Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3885
3886 switch (pname)
3887 {
3888 case GL_SAMPLE_POSITION:
3889 handleError(framebuffer->getSamplePosition(index, val));
3890 break;
3891 default:
3892 UNREACHABLE();
3893 }
3894}
3895
Jamie Madille8fb6402017-02-14 17:56:40 -05003896void Context::renderbufferStorage(GLenum target,
3897 GLenum internalformat,
3898 GLsizei width,
3899 GLsizei height)
3900{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003901 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
3902 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
3903
Jamie Madille8fb6402017-02-14 17:56:40 -05003904 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003905 handleError(renderbuffer->setStorage(convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05003906}
3907
3908void Context::renderbufferStorageMultisample(GLenum target,
3909 GLsizei samples,
3910 GLenum internalformat,
3911 GLsizei width,
3912 GLsizei height)
3913{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003914 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
3915 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05003916
3917 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05003918 handleError(
3919 renderbuffer->setStorageMultisample(samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05003920}
3921
JiangYizhoue18e6392017-02-20 10:32:23 +08003922void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
3923{
3924 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3925 QueryFramebufferParameteriv(framebuffer, pname, params);
3926}
3927
3928void Context::setFramebufferParameteri(GLenum target, GLenum pname, GLint param)
3929{
3930 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3931 SetFramebufferParameteri(framebuffer, pname, param);
3932}
3933
Jamie Madillc29968b2016-01-20 11:17:23 -05003934} // namespace gl