blob: 3d480b3538548442684dea2f99e73d5fcc2e4d54 [file] [log] [blame]
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001//
Geoff Langeeba6e12014-02-03 13:12:30 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Context.cpp: Implements the gl::Context class, managing all GL state and performing
8// rendering operations. It is the GLES2 specific implementation of EGLContext.
9
Geoff Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/Context.h"
apatrick@chromium.org144f2802012-07-12 01:42:34 +000011
Jamie Madill231c7f52017-04-26 13:45:37 -040012#include <string.h>
Jamie Madillb9293972015-02-19 11:07:54 -050013#include <iterator>
14#include <sstream>
Sami Väisänend59ca052016-06-21 16:10:00 +030015#include <vector>
Jamie Madillb9293972015-02-19 11:07:54 -050016
Sami Väisänene45e53b2016-05-25 10:36:04 +030017#include "common/matrix_utils.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040018#include "common/platform.h"
Jamie Madillb9293972015-02-19 11:07:54 -050019#include "common/utilities.h"
Geoff Langc339c4e2016-11-29 10:37:36 -050020#include "common/version.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050021#include "libANGLE/Buffer.h"
Jamie Madillb9293972015-02-19 11:07:54 -050022#include "libANGLE/Compiler.h"
Jamie Madill948bbe52017-06-01 13:10:42 -040023#include "libANGLE/Display.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050024#include "libANGLE/Fence.h"
25#include "libANGLE/Framebuffer.h"
26#include "libANGLE/FramebufferAttachment.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030027#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050028#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080029#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050030#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050031#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050032#include "libANGLE/ResourceManager.h"
33#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050034#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050035#include "libANGLE/Texture.h"
36#include "libANGLE/TransformFeedback.h"
37#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070038#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040039#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030040#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040041#include "libANGLE/queryutils.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040042#include "libANGLE/renderer/ContextImpl.h"
43#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040044#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040045#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000046
Geoff Langf6db0982015-08-25 13:04:00 -040047namespace
48{
49
Jamie Madillb6664922017-07-25 12:55:04 -040050#define ANGLE_HANDLE_ERR(X) \
51 handleError(X); \
52 return;
53#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
54
Ian Ewell3ffd78b2016-01-22 16:09:42 -050055template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050056std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030057 GLsizei numPaths,
58 const void *paths,
59 GLuint pathBase)
60{
61 std::vector<gl::Path *> ret;
62 ret.reserve(numPaths);
63
64 const auto *nameArray = static_cast<const T *>(paths);
65
66 for (GLsizei i = 0; i < numPaths; ++i)
67 {
68 const GLuint pathName = nameArray[i] + pathBase;
69
70 ret.push_back(resourceManager.getPath(pathName));
71 }
72
73 return ret;
74}
75
Geoff Lang4ddf5af2016-12-01 14:30:44 -050076std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030077 GLsizei numPaths,
78 GLenum pathNameType,
79 const void *paths,
80 GLuint pathBase)
81{
82 switch (pathNameType)
83 {
84 case GL_UNSIGNED_BYTE:
85 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
86
87 case GL_BYTE:
88 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
89
90 case GL_UNSIGNED_SHORT:
91 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
92
93 case GL_SHORT:
94 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
95
96 case GL_UNSIGNED_INT:
97 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
98
99 case GL_INT:
100 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
101 }
102
103 UNREACHABLE();
104 return std::vector<gl::Path *>();
105}
106
107template <typename T>
Geoff Lang2186c382016-10-14 10:54:54 -0400108gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500109{
Geoff Lang2186c382016-10-14 10:54:54 -0400110 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500111
112 switch (pname)
113 {
114 case GL_QUERY_RESULT_EXT:
Geoff Lang2186c382016-10-14 10:54:54 -0400115 return query->getResult(params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500116 case GL_QUERY_RESULT_AVAILABLE_EXT:
117 {
118 bool available;
Geoff Lang2186c382016-10-14 10:54:54 -0400119 gl::Error error = query->isResultAvailable(&available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500120 if (!error.isError())
121 {
jchen10a99ed552017-09-22 08:10:32 +0800122 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500123 }
124 return error;
125 }
126 default:
127 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500128 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500129 }
130}
131
Geoff Langf6db0982015-08-25 13:04:00 -0400132void MarkTransformFeedbackBufferUsage(gl::TransformFeedback *transformFeedback)
133{
Geoff Lang1a683462015-09-29 15:09:59 -0400134 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400135 {
136 for (size_t tfBufferIndex = 0; tfBufferIndex < transformFeedback->getIndexedBufferCount();
137 tfBufferIndex++)
138 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400139 const gl::OffsetBindingPointer<gl::Buffer> &buffer =
Geoff Langf6db0982015-08-25 13:04:00 -0400140 transformFeedback->getIndexedBuffer(tfBufferIndex);
141 if (buffer.get() != nullptr)
142 {
143 buffer->onTransformFeedback();
144 }
145 }
146 }
147}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500148
149// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300150EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500151{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400152 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500153}
154
Martin Radev1be913c2016-07-11 17:59:16 +0300155EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
156{
157 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
158}
159
Geoff Langeb66a6e2016-10-31 13:06:12 -0400160gl::Version GetClientVersion(const egl::AttributeMap &attribs)
161{
162 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
163}
164
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500165GLenum GetResetStrategy(const egl::AttributeMap &attribs)
166{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800167 EGLAttrib attrib =
168 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500169 switch (attrib)
170 {
171 case EGL_NO_RESET_NOTIFICATION:
172 return GL_NO_RESET_NOTIFICATION_EXT;
173 case EGL_LOSE_CONTEXT_ON_RESET:
174 return GL_LOSE_CONTEXT_ON_RESET_EXT;
175 default:
176 UNREACHABLE();
177 return GL_NONE;
178 }
179}
180
181bool GetRobustAccess(const egl::AttributeMap &attribs)
182{
Geoff Lang077f20a2016-11-01 10:08:02 -0400183 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
184 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
185 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500186}
187
188bool GetDebug(const egl::AttributeMap &attribs)
189{
Geoff Lang077f20a2016-11-01 10:08:02 -0400190 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
191 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500192}
193
194bool GetNoError(const egl::AttributeMap &attribs)
195{
196 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
197}
198
Geoff Langc287ea62016-09-16 14:46:51 -0400199bool GetWebGLContext(const egl::AttributeMap &attribs)
200{
201 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
202}
203
Geoff Langf41a7152016-09-19 15:11:17 -0400204bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
205{
206 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
207}
208
Geoff Langfeb8c682017-02-13 16:07:35 -0500209bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
210{
211 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
212}
213
Geoff Langb433e872017-10-05 14:01:47 -0400214bool GetRobustResourceInit(const egl::AttributeMap &attribs)
215{
216 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
217}
218
Martin Radev9d901792016-07-15 15:58:58 +0300219std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
220{
221 std::string labelName;
222 if (label != nullptr)
223 {
224 size_t labelLength = length < 0 ? strlen(label) : length;
225 labelName = std::string(label, labelLength);
226 }
227 return labelName;
228}
229
230void GetObjectLabelBase(const std::string &objectLabel,
231 GLsizei bufSize,
232 GLsizei *length,
233 GLchar *label)
234{
235 size_t writeLength = objectLabel.length();
236 if (label != nullptr && bufSize > 0)
237 {
238 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
239 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
240 label[writeLength] = '\0';
241 }
242
243 if (length != nullptr)
244 {
245 *length = static_cast<GLsizei>(writeLength);
246 }
247}
248
Jamie Madill0f80ed82017-09-19 00:24:56 -0400249template <typename CapT, typename MaxT>
250void LimitCap(CapT *cap, MaxT maximum)
251{
252 *cap = std::min(*cap, static_cast<CapT>(maximum));
253}
254
Geoff Langf6db0982015-08-25 13:04:00 -0400255} // anonymous namespace
256
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000257namespace gl
258{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000259
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400260Context::Context(rx::EGLImplFactory *implFactory,
261 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400262 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500263 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400264 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500265 const egl::AttributeMap &attribs,
Geoff Langb433e872017-10-05 14:01:47 -0400266 const egl::DisplayExtensions &displayExtensions)
Jamie Madill5b772312018-03-08 20:28:32 -0500267 : mState(reinterpret_cast<ContextID>(this),
268 shareContext ? &shareContext->mState : nullptr,
269 shareTextures,
270 GetClientVersion(attribs),
271 &mGLState,
272 mCaps,
273 mTextureCaps,
274 mExtensions,
275 mLimitations),
276 mSkipValidation(GetNoError(attribs)),
277 mDisplayTextureShareGroup(shareTextures != nullptr),
278 mSavedArgsType(nullptr),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700279 mImplementation(implFactory->createContext(mState)),
Jamie Madill2f348d22017-06-05 10:50:59 -0400280 mCompiler(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400281 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500282 mClientType(EGL_OPENGL_ES_API),
283 mHasBeenCurrent(false),
284 mContextLost(false),
285 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700286 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500287 mResetStrategy(GetResetStrategy(attribs)),
288 mRobustAccess(GetRobustAccess(attribs)),
Jamie Madill61e16b42017-06-19 11:13:23 -0400289 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
290 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500291 mSurfacelessFramebuffer(nullptr),
Jamie Madille14951e2017-03-09 18:55:16 -0500292 mWebGLContext(GetWebGLContext(attribs)),
Jamie Madill32447362017-06-28 14:53:52 -0400293 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400294 mScratchBuffer(1000u),
295 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000296{
Jamie Madill5b772312018-03-08 20:28:32 -0500297 // Needed to solve a Clang warning of unused variables.
298 UNUSED_VARIABLE(mSavedArgsType);
299 UNUSED_VARIABLE(mParamsBuffer);
300
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400301 mImplementation->setMemoryProgramCache(memoryProgramCache);
302
Geoff Langb433e872017-10-05 14:01:47 -0400303 bool robustResourceInit = GetRobustResourceInit(attribs);
304 initCaps(displayExtensions, robustResourceInit);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700305 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400306
Jamie Madill4928b7c2017-06-20 12:57:39 -0400307 mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs),
Jamie Madillc43be722017-07-13 16:22:14 -0400308 GetClientArraysEnabled(attribs), robustResourceInit,
309 mMemoryProgramCache != nullptr);
Régis Fénéon83107972015-02-05 12:57:44 +0100310
Shannon Woods53a94a82014-06-24 15:20:36 -0400311 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400312
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000313 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400314 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000315 // and cube map texture state vectors respectively associated with them.
316 // In order that access to these initial textures not be lost, they are treated as texture
317 // objects all of whose names are 0.
318
Corentin Wallez99d492c2018-02-27 15:17:10 -0500319 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800320 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500321
Corentin Wallez99d492c2018-02-27 15:17:10 -0500322 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800323 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400324
Geoff Langeb66a6e2016-10-31 13:06:12 -0400325 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400326 {
327 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500328 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800329 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400330
Corentin Wallez99d492c2018-02-27 15:17:10 -0500331 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800332 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400333 }
Geoff Lang3b573612016-10-31 14:08:10 -0400334 if (getClientVersion() >= Version(3, 1))
335 {
336 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500337 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800338 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800339
Jiajia Qin6eafb042016-12-27 17:04:07 +0800340 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
341 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800342 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800343 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800344
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800345 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
346 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400347 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800348 }
Geoff Lang3b573612016-10-31 14:08:10 -0400349 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000350
Geoff Lang4751aab2017-10-30 15:14:52 -0400351 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
352 if (nativeExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400353 {
354 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500355 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800356 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400357 }
358
Geoff Lang4751aab2017-10-30 15:14:52 -0400359 if (nativeExtensions.eglImageExternal || nativeExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400360 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500361 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800362 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400363 }
364
Jamie Madill4928b7c2017-06-20 12:57:39 -0400365 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500366
Jamie Madill57a89722013-07-02 11:57:03 -0400367 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000368
Geoff Langeb66a6e2016-10-31 13:06:12 -0400369 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400370 {
371 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
372 // In the initial state, a default transform feedback object is bound and treated as
373 // a transform feedback object with a name of zero. That object is bound any time
374 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400375 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400376 }
Geoff Langc8058452014-02-03 12:04:11 -0500377
Corentin Wallez336129f2017-10-17 15:55:40 -0400378 for (auto type : angle::AllEnums<BufferBinding>())
379 {
380 bindBuffer(type, 0);
381 }
382
383 bindRenderbuffer(GL_RENDERBUFFER, 0);
384
385 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
386 {
387 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
388 }
389
Jamie Madillad9f24e2016-02-12 09:27:24 -0500390 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400391 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500392 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500393 // No dirty objects.
394
395 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400396 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500397 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500398 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
399
400 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
401 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
402 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
403 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
404 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
405 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
406 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
407 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
408 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
409 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
410 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
411 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
412
413 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
414 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700415 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500416 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
417 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400418
Xinghua Cao10a4d432017-11-28 14:46:26 +0800419 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
420 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
421 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
422 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
423 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
424 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800425 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800426
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400427 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000428}
429
Jamie Madill4928b7c2017-06-20 12:57:39 -0400430egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000431{
Corentin Wallez80b24112015-08-25 16:41:57 -0400432 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000433 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400434 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000435 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400436 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000437
Corentin Wallez80b24112015-08-25 16:41:57 -0400438 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000439 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400440 if (query.second != nullptr)
441 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400442 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400443 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000444 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400445 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000446
Corentin Wallez80b24112015-08-25 16:41:57 -0400447 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400448 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400449 if (vertexArray.second)
450 {
451 vertexArray.second->onDestroy(this);
452 }
Jamie Madill57a89722013-07-02 11:57:03 -0400453 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400454 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400455
Corentin Wallez80b24112015-08-25 16:41:57 -0400456 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500457 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500458 if (transformFeedback.second != nullptr)
459 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500460 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500461 }
Geoff Langc8058452014-02-03 12:04:11 -0500462 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400463 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500464
Jamie Madill5b772312018-03-08 20:28:32 -0500465 for (BindingPointer<Texture> &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400466 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800467 if (zeroTexture.get() != nullptr)
468 {
469 ANGLE_TRY(zeroTexture->onDestroy(this));
470 zeroTexture.set(this, nullptr);
471 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400472 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000473
Corentin Wallezccab69d2017-01-27 16:57:15 -0500474 SafeDelete(mSurfacelessFramebuffer);
475
Jamie Madill4928b7c2017-06-20 12:57:39 -0400476 ANGLE_TRY(releaseSurface(display));
Jamie Madill2f348d22017-06-05 10:50:59 -0400477 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500478
Jamie Madill4928b7c2017-06-20 12:57:39 -0400479 mGLState.reset(this);
480
Jamie Madill6c1f6712017-02-14 19:08:04 -0500481 mState.mBuffers->release(this);
482 mState.mShaderPrograms->release(this);
483 mState.mTextures->release(this);
484 mState.mRenderbuffers->release(this);
485 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400486 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500487 mState.mPaths->release(this);
488 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800489 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400490
Jamie Madill76e471e2017-10-21 09:56:01 -0400491 mImplementation->onDestroy(this);
492
Jamie Madill4928b7c2017-06-20 12:57:39 -0400493 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000494}
495
Jamie Madill70ee0f62017-02-06 16:04:20 -0500496Context::~Context()
497{
498}
499
Jamie Madill4928b7c2017-06-20 12:57:39 -0400500egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000501{
Jamie Madill61e16b42017-06-19 11:13:23 -0400502 mCurrentDisplay = display;
503
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000504 if (!mHasBeenCurrent)
505 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000506 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500507 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400508 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000509
Corentin Wallezc295e512017-01-27 17:47:50 -0500510 int width = 0;
511 int height = 0;
512 if (surface != nullptr)
513 {
514 width = surface->getWidth();
515 height = surface->getHeight();
516 }
517
518 mGLState.setViewportParams(0, 0, width, height);
519 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000520
521 mHasBeenCurrent = true;
522 }
523
Jamie Madill1b94d432015-08-07 13:23:23 -0400524 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700525 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400526 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400527
Jamie Madill4928b7c2017-06-20 12:57:39 -0400528 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500529
530 Framebuffer *newDefault = nullptr;
531 if (surface != nullptr)
532 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400533 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500534 mCurrentSurface = surface;
535 newDefault = surface->getDefaultFramebuffer();
536 }
537 else
538 {
539 if (mSurfacelessFramebuffer == nullptr)
540 {
541 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
542 }
543
544 newDefault = mSurfacelessFramebuffer;
545 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000546
Corentin Wallez37c39792015-08-20 14:19:46 -0400547 // Update default framebuffer, the binding of the previous default
548 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400549 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700550 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400551 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700552 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400553 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700554 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400555 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700556 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400557 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500558 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400559 }
Ian Ewell292f0052016-02-04 10:37:32 -0500560
561 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400562 mImplementation->onMakeCurrent(this);
563 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000564}
565
Jamie Madill4928b7c2017-06-20 12:57:39 -0400566egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400567{
Corentin Wallez37c39792015-08-20 14:19:46 -0400568 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500569 Framebuffer *currentDefault = nullptr;
570 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400571 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500572 currentDefault = mCurrentSurface->getDefaultFramebuffer();
573 }
574 else if (mSurfacelessFramebuffer != nullptr)
575 {
576 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400577 }
578
Corentin Wallezc295e512017-01-27 17:47:50 -0500579 if (mGLState.getReadFramebuffer() == currentDefault)
580 {
581 mGLState.setReadFramebufferBinding(nullptr);
582 }
583 if (mGLState.getDrawFramebuffer() == currentDefault)
584 {
585 mGLState.setDrawFramebufferBinding(nullptr);
586 }
587 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
588
589 if (mCurrentSurface)
590 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400591 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500592 mCurrentSurface = nullptr;
593 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400594
595 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400596}
597
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000598GLuint Context::createBuffer()
599{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500600 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000601}
602
603GLuint Context::createProgram()
604{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500605 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000606}
607
608GLuint Context::createShader(GLenum type)
609{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500610 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000611}
612
613GLuint Context::createTexture()
614{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500615 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000616}
617
618GLuint Context::createRenderbuffer()
619{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500620 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000621}
622
Sami Väisänene45e53b2016-05-25 10:36:04 +0300623GLuint Context::createPaths(GLsizei range)
624{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500625 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300626 if (resultOrError.isError())
627 {
628 handleError(resultOrError.getError());
629 return 0;
630 }
631 return resultOrError.getResult();
632}
633
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000634// Returns an unused framebuffer name
635GLuint Context::createFramebuffer()
636{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500637 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000638}
639
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500640void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000641{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500642 for (int i = 0; i < n; i++)
643 {
644 GLuint handle = mFenceNVHandleAllocator.allocate();
645 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
646 fences[i] = handle;
647 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000648}
649
Yunchao Hea336b902017-08-02 16:05:21 +0800650GLuint Context::createProgramPipeline()
651{
652 return mState.mPipelines->createProgramPipeline();
653}
654
Jiajia Qin5451d532017-11-16 17:16:34 +0800655GLuint Context::createShaderProgramv(GLenum type, GLsizei count, const GLchar *const *strings)
656{
657 UNIMPLEMENTED();
658 return 0u;
659}
660
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000661void Context::deleteBuffer(GLuint buffer)
662{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500663 if (mState.mBuffers->getBuffer(buffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000664 {
665 detachBuffer(buffer);
666 }
Jamie Madill893ab082014-05-16 16:56:10 -0400667
Jamie Madill6c1f6712017-02-14 19:08:04 -0500668 mState.mBuffers->deleteObject(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000669}
670
671void Context::deleteShader(GLuint shader)
672{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500673 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000674}
675
676void Context::deleteProgram(GLuint program)
677{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500678 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000679}
680
681void Context::deleteTexture(GLuint texture)
682{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500683 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000684 {
685 detachTexture(texture);
686 }
687
Jamie Madill6c1f6712017-02-14 19:08:04 -0500688 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000689}
690
691void Context::deleteRenderbuffer(GLuint renderbuffer)
692{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500693 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000694 {
695 detachRenderbuffer(renderbuffer);
696 }
Jamie Madill893ab082014-05-16 16:56:10 -0400697
Jamie Madill6c1f6712017-02-14 19:08:04 -0500698 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000699}
700
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400701void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400702{
703 // The spec specifies the underlying Fence object is not deleted until all current
704 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
705 // and since our API is currently designed for being called from a single thread, we can delete
706 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400707 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400708}
709
Yunchao Hea336b902017-08-02 16:05:21 +0800710void Context::deleteProgramPipeline(GLuint pipeline)
711{
712 if (mState.mPipelines->getProgramPipeline(pipeline))
713 {
714 detachProgramPipeline(pipeline);
715 }
716
717 mState.mPipelines->deleteObject(this, pipeline);
718}
719
Sami Väisänene45e53b2016-05-25 10:36:04 +0300720void Context::deletePaths(GLuint first, GLsizei range)
721{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500722 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300723}
724
725bool Context::hasPathData(GLuint path) const
726{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500727 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300728 if (pathObj == nullptr)
729 return false;
730
731 return pathObj->hasPathData();
732}
733
734bool Context::hasPath(GLuint path) const
735{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500736 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300737}
738
739void Context::setPathCommands(GLuint path,
740 GLsizei numCommands,
741 const GLubyte *commands,
742 GLsizei numCoords,
743 GLenum coordType,
744 const void *coords)
745{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500746 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300747
748 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
749}
750
Jamie Madill007530e2017-12-28 14:27:04 -0500751void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300752{
Jamie Madill007530e2017-12-28 14:27:04 -0500753 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300754
755 switch (pname)
756 {
757 case GL_PATH_STROKE_WIDTH_CHROMIUM:
758 pathObj->setStrokeWidth(value);
759 break;
760 case GL_PATH_END_CAPS_CHROMIUM:
761 pathObj->setEndCaps(static_cast<GLenum>(value));
762 break;
763 case GL_PATH_JOIN_STYLE_CHROMIUM:
764 pathObj->setJoinStyle(static_cast<GLenum>(value));
765 break;
766 case GL_PATH_MITER_LIMIT_CHROMIUM:
767 pathObj->setMiterLimit(value);
768 break;
769 case GL_PATH_STROKE_BOUND_CHROMIUM:
770 pathObj->setStrokeBound(value);
771 break;
772 default:
773 UNREACHABLE();
774 break;
775 }
776}
777
Jamie Madill007530e2017-12-28 14:27:04 -0500778void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300779{
Jamie Madill007530e2017-12-28 14:27:04 -0500780 // TODO(jmadill): Should use proper clamping/casting.
781 pathParameterf(path, pname, static_cast<GLfloat>(value));
782}
783
784void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
785{
786 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300787
788 switch (pname)
789 {
790 case GL_PATH_STROKE_WIDTH_CHROMIUM:
791 *value = pathObj->getStrokeWidth();
792 break;
793 case GL_PATH_END_CAPS_CHROMIUM:
794 *value = static_cast<GLfloat>(pathObj->getEndCaps());
795 break;
796 case GL_PATH_JOIN_STYLE_CHROMIUM:
797 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
798 break;
799 case GL_PATH_MITER_LIMIT_CHROMIUM:
800 *value = pathObj->getMiterLimit();
801 break;
802 case GL_PATH_STROKE_BOUND_CHROMIUM:
803 *value = pathObj->getStrokeBound();
804 break;
805 default:
806 UNREACHABLE();
807 break;
808 }
809}
810
Jamie Madill007530e2017-12-28 14:27:04 -0500811void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
812{
813 GLfloat val = 0.0f;
814 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
815 if (value)
816 *value = static_cast<GLint>(val);
817}
818
Sami Väisänene45e53b2016-05-25 10:36:04 +0300819void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
820{
821 mGLState.setPathStencilFunc(func, ref, mask);
822}
823
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000824void Context::deleteFramebuffer(GLuint framebuffer)
825{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500826 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000827 {
828 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000829 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500830
Jamie Madill6c1f6712017-02-14 19:08:04 -0500831 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000832}
833
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500834void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000835{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500836 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000837 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500838 GLuint fence = fences[i];
839
840 FenceNV *fenceObject = nullptr;
841 if (mFenceNVMap.erase(fence, &fenceObject))
842 {
843 mFenceNVHandleAllocator.release(fence);
844 delete fenceObject;
845 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000846 }
847}
848
Geoff Lang70d0f492015-12-10 17:45:46 -0500849Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000850{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500851 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000852}
853
Jamie Madill570f7c82014-07-03 10:38:54 -0400854Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000855{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500856 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000857}
858
Geoff Lang70d0f492015-12-10 17:45:46 -0500859Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000860{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500861 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000862}
863
Jamie Madill70b5bb02017-08-28 13:32:37 -0400864Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400865{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400866 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400867}
868
Jamie Madill57a89722013-07-02 11:57:03 -0400869VertexArray *Context::getVertexArray(GLuint handle) const
870{
Jamie Madill96a483b2017-06-27 16:49:21 -0400871 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400872}
873
Jamie Madilldc356042013-07-19 16:36:57 -0400874Sampler *Context::getSampler(GLuint handle) const
875{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500876 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400877}
878
Geoff Langc8058452014-02-03 12:04:11 -0500879TransformFeedback *Context::getTransformFeedback(GLuint handle) const
880{
Jamie Madill96a483b2017-06-27 16:49:21 -0400881 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500882}
883
Yunchao Hea336b902017-08-02 16:05:21 +0800884ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
885{
886 return mState.mPipelines->getProgramPipeline(handle);
887}
888
Geoff Lang70d0f492015-12-10 17:45:46 -0500889LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
890{
891 switch (identifier)
892 {
893 case GL_BUFFER:
894 return getBuffer(name);
895 case GL_SHADER:
896 return getShader(name);
897 case GL_PROGRAM:
898 return getProgram(name);
899 case GL_VERTEX_ARRAY:
900 return getVertexArray(name);
901 case GL_QUERY:
902 return getQuery(name);
903 case GL_TRANSFORM_FEEDBACK:
904 return getTransformFeedback(name);
905 case GL_SAMPLER:
906 return getSampler(name);
907 case GL_TEXTURE:
908 return getTexture(name);
909 case GL_RENDERBUFFER:
910 return getRenderbuffer(name);
911 case GL_FRAMEBUFFER:
912 return getFramebuffer(name);
913 default:
914 UNREACHABLE();
915 return nullptr;
916 }
917}
918
919LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
920{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400921 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500922}
923
Martin Radev9d901792016-07-15 15:58:58 +0300924void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
925{
926 LabeledObject *object = getLabeledObject(identifier, name);
927 ASSERT(object != nullptr);
928
929 std::string labelName = GetObjectLabelFromPointer(length, label);
930 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400931
932 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
933 // specified object is active until we do this.
934 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300935}
936
937void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
938{
939 LabeledObject *object = getLabeledObjectFromPtr(ptr);
940 ASSERT(object != nullptr);
941
942 std::string labelName = GetObjectLabelFromPointer(length, label);
943 object->setLabel(labelName);
944}
945
946void Context::getObjectLabel(GLenum identifier,
947 GLuint name,
948 GLsizei bufSize,
949 GLsizei *length,
950 GLchar *label) const
951{
952 LabeledObject *object = getLabeledObject(identifier, name);
953 ASSERT(object != nullptr);
954
955 const std::string &objectLabel = object->getLabel();
956 GetObjectLabelBase(objectLabel, bufSize, length, label);
957}
958
959void Context::getObjectPtrLabel(const void *ptr,
960 GLsizei bufSize,
961 GLsizei *length,
962 GLchar *label) const
963{
964 LabeledObject *object = getLabeledObjectFromPtr(ptr);
965 ASSERT(object != nullptr);
966
967 const std::string &objectLabel = object->getLabel();
968 GetObjectLabelBase(objectLabel, bufSize, length, label);
969}
970
Jamie Madilldc356042013-07-19 16:36:57 -0400971bool Context::isSampler(GLuint samplerName) const
972{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500973 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400974}
975
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800976void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000977{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500978 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000979
Jamie Madilldedd7b92014-11-05 16:30:36 -0500980 if (handle == 0)
981 {
982 texture = mZeroTextures[target].get();
983 }
984 else
985 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500986 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500987 }
988
989 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400990 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000991}
992
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500993void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000994{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500995 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
996 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700997 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000998}
999
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001000void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001001{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001002 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1003 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001004 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001005}
1006
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001007void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001008{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001009 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001010 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001011}
1012
Shao80957d92017-02-20 21:25:59 +08001013void Context::bindVertexBuffer(GLuint bindingIndex,
1014 GLuint bufferHandle,
1015 GLintptr offset,
1016 GLsizei stride)
1017{
1018 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001019 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001020}
1021
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001022void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001023{
Geoff Lang76b10c92014-09-05 16:28:14 -04001024 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001025 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001026 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001027 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001028}
1029
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001030void Context::bindImageTexture(GLuint unit,
1031 GLuint texture,
1032 GLint level,
1033 GLboolean layered,
1034 GLint layer,
1035 GLenum access,
1036 GLenum format)
1037{
1038 Texture *tex = mState.mTextures->getTexture(texture);
1039 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1040}
1041
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001042void Context::useProgram(GLuint program)
1043{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001044 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001045}
1046
Jiajia Qin5451d532017-11-16 17:16:34 +08001047void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1048{
1049 UNIMPLEMENTED();
1050}
1051
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001052void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001053{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001054 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001055 TransformFeedback *transformFeedback =
1056 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001057 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001058}
1059
Yunchao Hea336b902017-08-02 16:05:21 +08001060void Context::bindProgramPipeline(GLuint pipelineHandle)
1061{
1062 ProgramPipeline *pipeline =
1063 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1064 mGLState.setProgramPipelineBinding(this, pipeline);
1065}
1066
Jamie Madillf0e04492017-08-26 15:28:42 -04001067void Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001068{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001069 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001070 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001071
Geoff Lang5aad9672014-09-08 11:10:42 -04001072 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001073 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001074
1075 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001076 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001077}
1078
Jamie Madillf0e04492017-08-26 15:28:42 -04001079void Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001080{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001081 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001082 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001083
Jamie Madillf0e04492017-08-26 15:28:42 -04001084 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001085
Geoff Lang5aad9672014-09-08 11:10:42 -04001086 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001087 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001088}
1089
Jamie Madillf0e04492017-08-26 15:28:42 -04001090void Context::queryCounter(GLuint id, GLenum target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001091{
1092 ASSERT(target == GL_TIMESTAMP_EXT);
1093
1094 Query *queryObject = getQuery(id, true, target);
1095 ASSERT(queryObject);
1096
Jamie Madillf0e04492017-08-26 15:28:42 -04001097 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001098}
1099
1100void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1101{
1102 switch (pname)
1103 {
1104 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001105 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001106 break;
1107 case GL_QUERY_COUNTER_BITS_EXT:
1108 switch (target)
1109 {
1110 case GL_TIME_ELAPSED_EXT:
1111 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1112 break;
1113 case GL_TIMESTAMP_EXT:
1114 params[0] = getExtensions().queryCounterBitsTimestamp;
1115 break;
1116 default:
1117 UNREACHABLE();
1118 params[0] = 0;
1119 break;
1120 }
1121 break;
1122 default:
1123 UNREACHABLE();
1124 return;
1125 }
1126}
1127
Geoff Lang2186c382016-10-14 10:54:54 -04001128void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001129{
Geoff Lang2186c382016-10-14 10:54:54 -04001130 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001131}
1132
Geoff Lang2186c382016-10-14 10:54:54 -04001133void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001134{
Geoff Lang2186c382016-10-14 10:54:54 -04001135 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001136}
1137
Geoff Lang2186c382016-10-14 10:54:54 -04001138void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001139{
Geoff Lang2186c382016-10-14 10:54:54 -04001140 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001141}
1142
Geoff Lang2186c382016-10-14 10:54:54 -04001143void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001144{
Geoff Lang2186c382016-10-14 10:54:54 -04001145 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001146}
1147
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001148Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001149{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001150 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001151}
1152
Jamie Madill2f348d22017-06-05 10:50:59 -04001153FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001154{
Jamie Madill96a483b2017-06-27 16:49:21 -04001155 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001156}
1157
Jamie Madill2f348d22017-06-05 10:50:59 -04001158Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001159{
Jamie Madill96a483b2017-06-27 16:49:21 -04001160 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001161 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001162 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001163 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001164
1165 Query *query = mQueryMap.query(handle);
1166 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001167 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001168 query = new Query(mImplementation->createQuery(type), handle);
1169 query->addRef();
1170 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001171 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001172 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001173}
1174
Geoff Lang70d0f492015-12-10 17:45:46 -05001175Query *Context::getQuery(GLuint handle) const
1176{
Jamie Madill96a483b2017-06-27 16:49:21 -04001177 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001178}
1179
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001180Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001181{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001182 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1183 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001184}
1185
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001186Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001187{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001188 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001189}
1190
Geoff Lang492a7e42014-11-05 13:27:06 -05001191Compiler *Context::getCompiler() const
1192{
Jamie Madill2f348d22017-06-05 10:50:59 -04001193 if (mCompiler.get() == nullptr)
1194 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001195 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001196 }
1197 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001198}
1199
Jamie Madillc1d770e2017-04-13 17:31:24 -04001200void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001201{
1202 switch (pname)
1203 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001204 case GL_SHADER_COMPILER:
1205 *params = GL_TRUE;
1206 break;
1207 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1208 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1209 break;
1210 default:
1211 mGLState.getBooleanv(pname, params);
1212 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001213 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001214}
1215
Jamie Madillc1d770e2017-04-13 17:31:24 -04001216void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001217{
Shannon Woods53a94a82014-06-24 15:20:36 -04001218 // Queries about context capabilities and maximums are answered by Context.
1219 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001220 switch (pname)
1221 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001222 case GL_ALIASED_LINE_WIDTH_RANGE:
1223 params[0] = mCaps.minAliasedLineWidth;
1224 params[1] = mCaps.maxAliasedLineWidth;
1225 break;
1226 case GL_ALIASED_POINT_SIZE_RANGE:
1227 params[0] = mCaps.minAliasedPointSize;
1228 params[1] = mCaps.maxAliasedPointSize;
1229 break;
1230 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1231 ASSERT(mExtensions.textureFilterAnisotropic);
1232 *params = mExtensions.maxTextureAnisotropy;
1233 break;
1234 case GL_MAX_TEXTURE_LOD_BIAS:
1235 *params = mCaps.maxLODBias;
1236 break;
1237
1238 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1239 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1240 {
1241 ASSERT(mExtensions.pathRendering);
1242 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1243 memcpy(params, m, 16 * sizeof(GLfloat));
1244 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001245 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001246
Jamie Madill231c7f52017-04-26 13:45:37 -04001247 default:
1248 mGLState.getFloatv(pname, params);
1249 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001250 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001251}
1252
Jamie Madillc1d770e2017-04-13 17:31:24 -04001253void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001254{
Shannon Woods53a94a82014-06-24 15:20:36 -04001255 // Queries about context capabilities and maximums are answered by Context.
1256 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001257
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001258 switch (pname)
1259 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001260 case GL_MAX_VERTEX_ATTRIBS:
1261 *params = mCaps.maxVertexAttributes;
1262 break;
1263 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1264 *params = mCaps.maxVertexUniformVectors;
1265 break;
1266 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1267 *params = mCaps.maxVertexUniformComponents;
1268 break;
1269 case GL_MAX_VARYING_VECTORS:
1270 *params = mCaps.maxVaryingVectors;
1271 break;
1272 case GL_MAX_VARYING_COMPONENTS:
1273 *params = mCaps.maxVertexOutputComponents;
1274 break;
1275 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1276 *params = mCaps.maxCombinedTextureImageUnits;
1277 break;
1278 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1279 *params = mCaps.maxVertexTextureImageUnits;
1280 break;
1281 case GL_MAX_TEXTURE_IMAGE_UNITS:
1282 *params = mCaps.maxTextureImageUnits;
1283 break;
1284 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1285 *params = mCaps.maxFragmentUniformVectors;
1286 break;
1287 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1288 *params = mCaps.maxFragmentUniformComponents;
1289 break;
1290 case GL_MAX_RENDERBUFFER_SIZE:
1291 *params = mCaps.maxRenderbufferSize;
1292 break;
1293 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1294 *params = mCaps.maxColorAttachments;
1295 break;
1296 case GL_MAX_DRAW_BUFFERS_EXT:
1297 *params = mCaps.maxDrawBuffers;
1298 break;
1299 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1300 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1301 case GL_SUBPIXEL_BITS:
1302 *params = 4;
1303 break;
1304 case GL_MAX_TEXTURE_SIZE:
1305 *params = mCaps.max2DTextureSize;
1306 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001307 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1308 *params = mCaps.maxRectangleTextureSize;
1309 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001310 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1311 *params = mCaps.maxCubeMapTextureSize;
1312 break;
1313 case GL_MAX_3D_TEXTURE_SIZE:
1314 *params = mCaps.max3DTextureSize;
1315 break;
1316 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1317 *params = mCaps.maxArrayTextureLayers;
1318 break;
1319 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1320 *params = mCaps.uniformBufferOffsetAlignment;
1321 break;
1322 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1323 *params = mCaps.maxUniformBufferBindings;
1324 break;
1325 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1326 *params = mCaps.maxVertexUniformBlocks;
1327 break;
1328 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1329 *params = mCaps.maxFragmentUniformBlocks;
1330 break;
1331 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1332 *params = mCaps.maxCombinedTextureImageUnits;
1333 break;
1334 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1335 *params = mCaps.maxVertexOutputComponents;
1336 break;
1337 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1338 *params = mCaps.maxFragmentInputComponents;
1339 break;
1340 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1341 *params = mCaps.minProgramTexelOffset;
1342 break;
1343 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1344 *params = mCaps.maxProgramTexelOffset;
1345 break;
1346 case GL_MAJOR_VERSION:
1347 *params = getClientVersion().major;
1348 break;
1349 case GL_MINOR_VERSION:
1350 *params = getClientVersion().minor;
1351 break;
1352 case GL_MAX_ELEMENTS_INDICES:
1353 *params = mCaps.maxElementsIndices;
1354 break;
1355 case GL_MAX_ELEMENTS_VERTICES:
1356 *params = mCaps.maxElementsVertices;
1357 break;
1358 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1359 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1360 break;
1361 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1362 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1363 break;
1364 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1365 *params = mCaps.maxTransformFeedbackSeparateComponents;
1366 break;
1367 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1368 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1369 break;
1370 case GL_MAX_SAMPLES_ANGLE:
1371 *params = mCaps.maxSamples;
1372 break;
1373 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001374 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001375 params[0] = mCaps.maxViewportWidth;
1376 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001377 }
1378 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001379 case GL_COMPRESSED_TEXTURE_FORMATS:
1380 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1381 params);
1382 break;
1383 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1384 *params = mResetStrategy;
1385 break;
1386 case GL_NUM_SHADER_BINARY_FORMATS:
1387 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1388 break;
1389 case GL_SHADER_BINARY_FORMATS:
1390 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1391 break;
1392 case GL_NUM_PROGRAM_BINARY_FORMATS:
1393 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1394 break;
1395 case GL_PROGRAM_BINARY_FORMATS:
1396 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1397 break;
1398 case GL_NUM_EXTENSIONS:
1399 *params = static_cast<GLint>(mExtensionStrings.size());
1400 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001401
Jamie Madill231c7f52017-04-26 13:45:37 -04001402 // GL_KHR_debug
1403 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1404 *params = mExtensions.maxDebugMessageLength;
1405 break;
1406 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1407 *params = mExtensions.maxDebugLoggedMessages;
1408 break;
1409 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1410 *params = mExtensions.maxDebugGroupStackDepth;
1411 break;
1412 case GL_MAX_LABEL_LENGTH:
1413 *params = mExtensions.maxLabelLength;
1414 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001415
Martin Radeve5285d22017-07-14 16:23:53 +03001416 // GL_ANGLE_multiview
1417 case GL_MAX_VIEWS_ANGLE:
1418 *params = mExtensions.maxViews;
1419 break;
1420
Jamie Madill231c7f52017-04-26 13:45:37 -04001421 // GL_EXT_disjoint_timer_query
1422 case GL_GPU_DISJOINT_EXT:
1423 *params = mImplementation->getGPUDisjoint();
1424 break;
1425 case GL_MAX_FRAMEBUFFER_WIDTH:
1426 *params = mCaps.maxFramebufferWidth;
1427 break;
1428 case GL_MAX_FRAMEBUFFER_HEIGHT:
1429 *params = mCaps.maxFramebufferHeight;
1430 break;
1431 case GL_MAX_FRAMEBUFFER_SAMPLES:
1432 *params = mCaps.maxFramebufferSamples;
1433 break;
1434 case GL_MAX_SAMPLE_MASK_WORDS:
1435 *params = mCaps.maxSampleMaskWords;
1436 break;
1437 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1438 *params = mCaps.maxColorTextureSamples;
1439 break;
1440 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1441 *params = mCaps.maxDepthTextureSamples;
1442 break;
1443 case GL_MAX_INTEGER_SAMPLES:
1444 *params = mCaps.maxIntegerSamples;
1445 break;
1446 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1447 *params = mCaps.maxVertexAttribRelativeOffset;
1448 break;
1449 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1450 *params = mCaps.maxVertexAttribBindings;
1451 break;
1452 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1453 *params = mCaps.maxVertexAttribStride;
1454 break;
1455 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1456 *params = mCaps.maxVertexAtomicCounterBuffers;
1457 break;
1458 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1459 *params = mCaps.maxVertexAtomicCounters;
1460 break;
1461 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1462 *params = mCaps.maxVertexImageUniforms;
1463 break;
1464 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1465 *params = mCaps.maxVertexShaderStorageBlocks;
1466 break;
1467 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1468 *params = mCaps.maxFragmentAtomicCounterBuffers;
1469 break;
1470 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1471 *params = mCaps.maxFragmentAtomicCounters;
1472 break;
1473 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1474 *params = mCaps.maxFragmentImageUniforms;
1475 break;
1476 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1477 *params = mCaps.maxFragmentShaderStorageBlocks;
1478 break;
1479 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1480 *params = mCaps.minProgramTextureGatherOffset;
1481 break;
1482 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1483 *params = mCaps.maxProgramTextureGatherOffset;
1484 break;
1485 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1486 *params = mCaps.maxComputeWorkGroupInvocations;
1487 break;
1488 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1489 *params = mCaps.maxComputeUniformBlocks;
1490 break;
1491 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1492 *params = mCaps.maxComputeTextureImageUnits;
1493 break;
1494 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1495 *params = mCaps.maxComputeSharedMemorySize;
1496 break;
1497 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1498 *params = mCaps.maxComputeUniformComponents;
1499 break;
1500 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1501 *params = mCaps.maxComputeAtomicCounterBuffers;
1502 break;
1503 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1504 *params = mCaps.maxComputeAtomicCounters;
1505 break;
1506 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1507 *params = mCaps.maxComputeImageUniforms;
1508 break;
1509 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1510 *params = mCaps.maxCombinedComputeUniformComponents;
1511 break;
1512 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1513 *params = mCaps.maxComputeShaderStorageBlocks;
1514 break;
1515 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1516 *params = mCaps.maxCombinedShaderOutputResources;
1517 break;
1518 case GL_MAX_UNIFORM_LOCATIONS:
1519 *params = mCaps.maxUniformLocations;
1520 break;
1521 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1522 *params = mCaps.maxAtomicCounterBufferBindings;
1523 break;
1524 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1525 *params = mCaps.maxAtomicCounterBufferSize;
1526 break;
1527 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1528 *params = mCaps.maxCombinedAtomicCounterBuffers;
1529 break;
1530 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1531 *params = mCaps.maxCombinedAtomicCounters;
1532 break;
1533 case GL_MAX_IMAGE_UNITS:
1534 *params = mCaps.maxImageUnits;
1535 break;
1536 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1537 *params = mCaps.maxCombinedImageUniforms;
1538 break;
1539 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1540 *params = mCaps.maxShaderStorageBufferBindings;
1541 break;
1542 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1543 *params = mCaps.maxCombinedShaderStorageBlocks;
1544 break;
1545 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1546 *params = mCaps.shaderStorageBufferOffsetAlignment;
1547 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001548
1549 // GL_EXT_geometry_shader
1550 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1551 *params = mCaps.maxFramebufferLayers;
1552 break;
1553 case GL_LAYER_PROVOKING_VERTEX_EXT:
1554 *params = mCaps.layerProvokingVertex;
1555 break;
1556 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1557 *params = mCaps.maxGeometryUniformComponents;
1558 break;
1559 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
1560 *params = mCaps.maxGeometryUniformBlocks;
1561 break;
1562 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1563 *params = mCaps.maxCombinedGeometryUniformComponents;
1564 break;
1565 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1566 *params = mCaps.maxGeometryInputComponents;
1567 break;
1568 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1569 *params = mCaps.maxGeometryOutputComponents;
1570 break;
1571 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1572 *params = mCaps.maxGeometryOutputVertices;
1573 break;
1574 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1575 *params = mCaps.maxGeometryTotalOutputComponents;
1576 break;
1577 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1578 *params = mCaps.maxGeometryShaderInvocations;
1579 break;
1580 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
1581 *params = mCaps.maxGeometryTextureImageUnits;
1582 break;
1583 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
1584 *params = mCaps.maxGeometryAtomicCounterBuffers;
1585 break;
1586 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
1587 *params = mCaps.maxGeometryAtomicCounters;
1588 break;
1589 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
1590 *params = mCaps.maxGeometryImageUniforms;
1591 break;
1592 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
1593 *params = mCaps.maxGeometryShaderStorageBlocks;
1594 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001595 default:
1596 mGLState.getIntegerv(this, pname, params);
1597 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001598 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001599}
1600
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001601void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001602{
Shannon Woods53a94a82014-06-24 15:20:36 -04001603 // Queries about context capabilities and maximums are answered by Context.
1604 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001605 switch (pname)
1606 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001607 case GL_MAX_ELEMENT_INDEX:
1608 *params = mCaps.maxElementIndex;
1609 break;
1610 case GL_MAX_UNIFORM_BLOCK_SIZE:
1611 *params = mCaps.maxUniformBlockSize;
1612 break;
1613 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1614 *params = mCaps.maxCombinedVertexUniformComponents;
1615 break;
1616 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1617 *params = mCaps.maxCombinedFragmentUniformComponents;
1618 break;
1619 case GL_MAX_SERVER_WAIT_TIMEOUT:
1620 *params = mCaps.maxServerWaitTimeout;
1621 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001622
Jamie Madill231c7f52017-04-26 13:45:37 -04001623 // GL_EXT_disjoint_timer_query
1624 case GL_TIMESTAMP_EXT:
1625 *params = mImplementation->getTimestamp();
1626 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001627
Jamie Madill231c7f52017-04-26 13:45:37 -04001628 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1629 *params = mCaps.maxShaderStorageBlockSize;
1630 break;
1631 default:
1632 UNREACHABLE();
1633 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001634 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001635}
1636
Geoff Lang70d0f492015-12-10 17:45:46 -05001637void Context::getPointerv(GLenum pname, void **params) const
1638{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001639 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001640}
1641
Martin Radev66fb8202016-07-28 11:45:20 +03001642void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001643{
Shannon Woods53a94a82014-06-24 15:20:36 -04001644 // Queries about context capabilities and maximums are answered by Context.
1645 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001646
1647 GLenum nativeType;
1648 unsigned int numParams;
1649 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1650 ASSERT(queryStatus);
1651
1652 if (nativeType == GL_INT)
1653 {
1654 switch (target)
1655 {
1656 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1657 ASSERT(index < 3u);
1658 *data = mCaps.maxComputeWorkGroupCount[index];
1659 break;
1660 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1661 ASSERT(index < 3u);
1662 *data = mCaps.maxComputeWorkGroupSize[index];
1663 break;
1664 default:
1665 mGLState.getIntegeri_v(target, index, data);
1666 }
1667 }
1668 else
1669 {
1670 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1671 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001672}
1673
Martin Radev66fb8202016-07-28 11:45:20 +03001674void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001675{
Shannon Woods53a94a82014-06-24 15:20:36 -04001676 // Queries about context capabilities and maximums are answered by Context.
1677 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001678
1679 GLenum nativeType;
1680 unsigned int numParams;
1681 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1682 ASSERT(queryStatus);
1683
1684 if (nativeType == GL_INT_64_ANGLEX)
1685 {
1686 mGLState.getInteger64i_v(target, index, data);
1687 }
1688 else
1689 {
1690 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1691 }
1692}
1693
1694void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1695{
1696 // Queries about context capabilities and maximums are answered by Context.
1697 // Queries about current GL state values are answered by State.
1698
1699 GLenum nativeType;
1700 unsigned int numParams;
1701 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1702 ASSERT(queryStatus);
1703
1704 if (nativeType == GL_BOOL)
1705 {
1706 mGLState.getBooleani_v(target, index, data);
1707 }
1708 else
1709 {
1710 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1711 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001712}
1713
Corentin Wallez336129f2017-10-17 15:55:40 -04001714void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001715{
1716 Buffer *buffer = mGLState.getTargetBuffer(target);
1717 QueryBufferParameteriv(buffer, pname, params);
1718}
1719
1720void Context::getFramebufferAttachmentParameteriv(GLenum target,
1721 GLenum attachment,
1722 GLenum pname,
1723 GLint *params)
1724{
1725 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001726 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001727}
1728
1729void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1730{
1731 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1732 QueryRenderbufferiv(this, renderbuffer, pname, params);
1733}
1734
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001735void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001736{
1737 Texture *texture = getTargetTexture(target);
1738 QueryTexParameterfv(texture, pname, params);
1739}
1740
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001741void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001742{
1743 Texture *texture = getTargetTexture(target);
1744 QueryTexParameteriv(texture, pname, params);
1745}
Jiajia Qin5451d532017-11-16 17:16:34 +08001746
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001747void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001748{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001749 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001750 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001751}
1752
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001753void Context::getTexLevelParameterfv(TextureTarget target,
1754 GLint level,
1755 GLenum pname,
1756 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001757{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001758 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001759 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001760}
1761
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001762void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08001763{
1764 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001765 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001766 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001767}
1768
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001769void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001770{
1771 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001772 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001773 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001774}
1775
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001776void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08001777{
1778 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001779 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001780 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001781}
1782
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001783void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001784{
1785 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001786 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001787 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001788}
1789
Jamie Madill675fe712016-12-19 13:07:54 -05001790void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001791{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001792 // No-op if zero count
1793 if (count == 0)
1794 {
1795 return;
1796 }
1797
Jamie Madill05b35b22017-10-03 09:01:44 -04001798 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001799 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
1800 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001801}
1802
Jamie Madill675fe712016-12-19 13:07:54 -05001803void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001804{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001805 // No-op if zero count
1806 if (count == 0 || instanceCount == 0)
1807 {
1808 return;
1809 }
1810
Jamie Madill05b35b22017-10-03 09:01:44 -04001811 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001812 ANGLE_CONTEXT_TRY(
1813 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
1814 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
Geoff Langf6db0982015-08-25 13:04:00 -04001815}
1816
Jamie Madill876429b2017-04-20 15:46:24 -04001817void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001818{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001819 // No-op if zero count
1820 if (count == 0)
1821 {
1822 return;
1823 }
1824
Jamie Madill05b35b22017-10-03 09:01:44 -04001825 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001826 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001827}
1828
Jamie Madill675fe712016-12-19 13:07:54 -05001829void Context::drawElementsInstanced(GLenum mode,
1830 GLsizei count,
1831 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001832 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001833 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001834{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001835 // No-op if zero count
1836 if (count == 0 || instances == 0)
1837 {
1838 return;
1839 }
1840
Jamie Madill05b35b22017-10-03 09:01:44 -04001841 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001842 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001843 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001844}
1845
Jamie Madill675fe712016-12-19 13:07:54 -05001846void Context::drawRangeElements(GLenum mode,
1847 GLuint start,
1848 GLuint end,
1849 GLsizei count,
1850 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001851 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001852{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001853 // No-op if zero count
1854 if (count == 0)
1855 {
1856 return;
1857 }
1858
Jamie Madill05b35b22017-10-03 09:01:44 -04001859 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001860 ANGLE_CONTEXT_TRY(
1861 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001862}
1863
Jamie Madill876429b2017-04-20 15:46:24 -04001864void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001865{
Jamie Madill05b35b22017-10-03 09:01:44 -04001866 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001867 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001868}
1869
Jamie Madill876429b2017-04-20 15:46:24 -04001870void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001871{
Jamie Madill05b35b22017-10-03 09:01:44 -04001872 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001873 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001874}
1875
Jamie Madill675fe712016-12-19 13:07:54 -05001876void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001877{
Jamie Madillafa02a22017-11-23 12:57:38 -05001878 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05001879}
1880
Jamie Madill675fe712016-12-19 13:07:54 -05001881void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001882{
Jamie Madillafa02a22017-11-23 12:57:38 -05001883 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001884}
1885
Austin Kinross6ee1e782015-05-29 17:05:37 -07001886void Context::insertEventMarker(GLsizei length, const char *marker)
1887{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001888 ASSERT(mImplementation);
1889 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001890}
1891
1892void Context::pushGroupMarker(GLsizei length, const char *marker)
1893{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001894 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05001895
1896 if (marker == nullptr)
1897 {
1898 // From the EXT_debug_marker spec,
1899 // "If <marker> is null then an empty string is pushed on the stack."
1900 mImplementation->pushGroupMarker(length, "");
1901 }
1902 else
1903 {
1904 mImplementation->pushGroupMarker(length, marker);
1905 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07001906}
1907
1908void Context::popGroupMarker()
1909{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001910 ASSERT(mImplementation);
1911 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001912}
1913
Geoff Langd8605522016-04-13 10:19:12 -04001914void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1915{
1916 Program *programObject = getProgram(program);
1917 ASSERT(programObject);
1918
1919 programObject->bindUniformLocation(location, name);
1920}
1921
Sami Väisänena797e062016-05-12 15:23:40 +03001922void Context::setCoverageModulation(GLenum components)
1923{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001924 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001925}
1926
Sami Väisänene45e53b2016-05-25 10:36:04 +03001927void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1928{
1929 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1930}
1931
1932void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1933{
1934 GLfloat I[16];
1935 angle::Matrix<GLfloat>::setToIdentity(I);
1936
1937 mGLState.loadPathRenderingMatrix(matrixMode, I);
1938}
1939
1940void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1941{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001942 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001943 if (!pathObj)
1944 return;
1945
1946 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Jamie Madillbc918e72018-03-08 09:47:21 -05001947 ANGLE_CONTEXT_TRY(syncRendererState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001948
1949 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1950}
1951
1952void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1953{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001954 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001955 if (!pathObj)
1956 return;
1957
1958 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Jamie Madillbc918e72018-03-08 09:47:21 -05001959 ANGLE_CONTEXT_TRY(syncRendererState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001960
1961 mImplementation->stencilStrokePath(pathObj, reference, mask);
1962}
1963
1964void Context::coverFillPath(GLuint path, GLenum coverMode)
1965{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001966 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001967 if (!pathObj)
1968 return;
1969
1970 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Jamie Madillbc918e72018-03-08 09:47:21 -05001971 ANGLE_CONTEXT_TRY(syncRendererState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001972
1973 mImplementation->coverFillPath(pathObj, coverMode);
1974}
1975
1976void Context::coverStrokePath(GLuint path, GLenum coverMode)
1977{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001978 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001979 if (!pathObj)
1980 return;
1981
1982 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Jamie Madillbc918e72018-03-08 09:47:21 -05001983 ANGLE_CONTEXT_TRY(syncRendererState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001984
1985 mImplementation->coverStrokePath(pathObj, coverMode);
1986}
1987
1988void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1989{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001990 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001991 if (!pathObj)
1992 return;
1993
1994 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Jamie Madillbc918e72018-03-08 09:47:21 -05001995 ANGLE_CONTEXT_TRY(syncRendererState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001996
1997 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
1998}
1999
2000void Context::stencilThenCoverStrokePath(GLuint path,
2001 GLint reference,
2002 GLuint mask,
2003 GLenum coverMode)
2004{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002005 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002006 if (!pathObj)
2007 return;
2008
2009 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Jamie Madillbc918e72018-03-08 09:47:21 -05002010 ANGLE_CONTEXT_TRY(syncRendererState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002011
2012 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2013}
2014
Sami Väisänend59ca052016-06-21 16:10:00 +03002015void Context::coverFillPathInstanced(GLsizei numPaths,
2016 GLenum pathNameType,
2017 const void *paths,
2018 GLuint pathBase,
2019 GLenum coverMode,
2020 GLenum transformType,
2021 const GLfloat *transformValues)
2022{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002023 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002024
2025 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Jamie Madillbc918e72018-03-08 09:47:21 -05002026 ANGLE_CONTEXT_TRY(syncRendererState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002027
2028 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2029}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002030
Sami Väisänend59ca052016-06-21 16:10:00 +03002031void Context::coverStrokePathInstanced(GLsizei numPaths,
2032 GLenum pathNameType,
2033 const void *paths,
2034 GLuint pathBase,
2035 GLenum coverMode,
2036 GLenum transformType,
2037 const GLfloat *transformValues)
2038{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002039 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002040
2041 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Jamie Madillbc918e72018-03-08 09:47:21 -05002042 ANGLE_CONTEXT_TRY(syncRendererState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002043
2044 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2045 transformValues);
2046}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002047
Sami Väisänend59ca052016-06-21 16:10:00 +03002048void Context::stencilFillPathInstanced(GLsizei numPaths,
2049 GLenum pathNameType,
2050 const void *paths,
2051 GLuint pathBase,
2052 GLenum fillMode,
2053 GLuint mask,
2054 GLenum transformType,
2055 const GLfloat *transformValues)
2056{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002057 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002058
2059 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Jamie Madillbc918e72018-03-08 09:47:21 -05002060 ANGLE_CONTEXT_TRY(syncRendererState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002061
2062 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2063 transformValues);
2064}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002065
Sami Väisänend59ca052016-06-21 16:10:00 +03002066void Context::stencilStrokePathInstanced(GLsizei numPaths,
2067 GLenum pathNameType,
2068 const void *paths,
2069 GLuint pathBase,
2070 GLint reference,
2071 GLuint mask,
2072 GLenum transformType,
2073 const GLfloat *transformValues)
2074{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002075 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002076
2077 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Jamie Madillbc918e72018-03-08 09:47:21 -05002078 ANGLE_CONTEXT_TRY(syncRendererState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002079
2080 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2081 transformValues);
2082}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002083
Sami Väisänend59ca052016-06-21 16:10:00 +03002084void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2085 GLenum pathNameType,
2086 const void *paths,
2087 GLuint pathBase,
2088 GLenum fillMode,
2089 GLuint mask,
2090 GLenum coverMode,
2091 GLenum transformType,
2092 const GLfloat *transformValues)
2093{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002094 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002095
2096 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Jamie Madillbc918e72018-03-08 09:47:21 -05002097 ANGLE_CONTEXT_TRY(syncRendererState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002098
2099 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2100 transformType, transformValues);
2101}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002102
Sami Väisänend59ca052016-06-21 16:10:00 +03002103void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2104 GLenum pathNameType,
2105 const void *paths,
2106 GLuint pathBase,
2107 GLint reference,
2108 GLuint mask,
2109 GLenum coverMode,
2110 GLenum transformType,
2111 const GLfloat *transformValues)
2112{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002113 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002114
2115 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Jamie Madillbc918e72018-03-08 09:47:21 -05002116 ANGLE_CONTEXT_TRY(syncRendererState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002117
2118 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2119 transformType, transformValues);
2120}
2121
Sami Väisänen46eaa942016-06-29 10:26:37 +03002122void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2123{
2124 auto *programObject = getProgram(program);
2125
2126 programObject->bindFragmentInputLocation(location, name);
2127}
2128
2129void Context::programPathFragmentInputGen(GLuint program,
2130 GLint location,
2131 GLenum genMode,
2132 GLint components,
2133 const GLfloat *coeffs)
2134{
2135 auto *programObject = getProgram(program);
2136
Jamie Madillbd044ed2017-06-05 12:59:21 -04002137 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002138}
2139
jchen1015015f72017-03-16 13:54:21 +08002140GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2141{
jchen10fd7c3b52017-03-21 15:36:03 +08002142 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002143 return QueryProgramResourceIndex(programObject, programInterface, name);
2144}
2145
jchen10fd7c3b52017-03-21 15:36:03 +08002146void Context::getProgramResourceName(GLuint program,
2147 GLenum programInterface,
2148 GLuint index,
2149 GLsizei bufSize,
2150 GLsizei *length,
2151 GLchar *name)
2152{
2153 const auto *programObject = getProgram(program);
2154 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2155}
2156
jchen10191381f2017-04-11 13:59:04 +08002157GLint Context::getProgramResourceLocation(GLuint program,
2158 GLenum programInterface,
2159 const GLchar *name)
2160{
2161 const auto *programObject = getProgram(program);
2162 return QueryProgramResourceLocation(programObject, programInterface, name);
2163}
2164
jchen10880683b2017-04-12 16:21:55 +08002165void Context::getProgramResourceiv(GLuint program,
2166 GLenum programInterface,
2167 GLuint index,
2168 GLsizei propCount,
2169 const GLenum *props,
2170 GLsizei bufSize,
2171 GLsizei *length,
2172 GLint *params)
2173{
2174 const auto *programObject = getProgram(program);
2175 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2176 length, params);
2177}
2178
jchen10d9cd7b72017-08-30 15:04:25 +08002179void Context::getProgramInterfaceiv(GLuint program,
2180 GLenum programInterface,
2181 GLenum pname,
2182 GLint *params)
2183{
2184 const auto *programObject = getProgram(program);
2185 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2186}
2187
Jamie Madill71c88b32017-09-14 22:20:29 -04002188void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002189{
Geoff Langda5777c2014-07-11 09:52:58 -04002190 if (error.isError())
2191 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002192 GLenum code = error.getCode();
2193 mErrors.insert(code);
2194 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2195 {
2196 markContextLost();
2197 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002198
Geoff Langee6884e2017-11-09 16:51:11 -05002199 ASSERT(!error.getMessage().empty());
2200 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2201 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002202 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002203}
2204
2205// Get one of the recorded errors and clear its flag, if any.
2206// [OpenGL ES 2.0.24] section 2.5 page 13.
2207GLenum Context::getError()
2208{
Geoff Langda5777c2014-07-11 09:52:58 -04002209 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002210 {
Geoff Langda5777c2014-07-11 09:52:58 -04002211 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002212 }
Geoff Langda5777c2014-07-11 09:52:58 -04002213 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002214 {
Geoff Langda5777c2014-07-11 09:52:58 -04002215 GLenum error = *mErrors.begin();
2216 mErrors.erase(mErrors.begin());
2217 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002218 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002219}
2220
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002221// NOTE: this function should not assume that this context is current!
2222void Context::markContextLost()
2223{
2224 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002225 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002226 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002227 mContextLostForced = true;
2228 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002229 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002230}
2231
2232bool Context::isContextLost()
2233{
2234 return mContextLost;
2235}
2236
Jamie Madillfa920eb2018-01-04 11:45:50 -05002237GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002238{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002239 // Even if the application doesn't want to know about resets, we want to know
2240 // as it will allow us to skip all the calls.
2241 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002242 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002243 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002244 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002245 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002246 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002247
2248 // EXT_robustness, section 2.6: If the reset notification behavior is
2249 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2250 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2251 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002252 }
2253
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002254 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2255 // status should be returned at least once, and GL_NO_ERROR should be returned
2256 // once the device has finished resetting.
2257 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002258 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002259 ASSERT(mResetStatus == GL_NO_ERROR);
2260 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002261
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002262 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002263 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002264 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002265 }
2266 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002267 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002268 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002269 // If markContextLost was used to mark the context lost then
2270 // assume that is not recoverable, and continue to report the
2271 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002272 mResetStatus = mImplementation->getResetStatus();
2273 }
Jamie Madill893ab082014-05-16 16:56:10 -04002274
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002275 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002276}
2277
2278bool Context::isResetNotificationEnabled()
2279{
2280 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2281}
2282
Corentin Walleze3b10e82015-05-20 11:06:25 -04002283const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002284{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002285 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002286}
2287
2288EGLenum Context::getClientType() const
2289{
2290 return mClientType;
2291}
2292
2293EGLenum Context::getRenderBuffer() const
2294{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002295 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2296 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002297 {
2298 return EGL_NONE;
2299 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002300
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002301 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002302 ASSERT(backAttachment != nullptr);
2303 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002304}
2305
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002306VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002307{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002308 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002309 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2310 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002311 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002312 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2313 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002314
Jamie Madill96a483b2017-06-27 16:49:21 -04002315 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002316 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002317
2318 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002319}
2320
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002321TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002322{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002323 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002324 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2325 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002326 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002327 transformFeedback =
2328 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002329 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002330 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002331 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002332
2333 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002334}
2335
2336bool Context::isVertexArrayGenerated(GLuint vertexArray)
2337{
Jamie Madill96a483b2017-06-27 16:49:21 -04002338 ASSERT(mVertexArrayMap.contains(0));
2339 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002340}
2341
2342bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2343{
Jamie Madill96a483b2017-06-27 16:49:21 -04002344 ASSERT(mTransformFeedbackMap.contains(0));
2345 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002346}
2347
Shannon Woods53a94a82014-06-24 15:20:36 -04002348void Context::detachTexture(GLuint texture)
2349{
2350 // Simple pass-through to State's detachTexture method, as textures do not require
2351 // allocation map management either here or in the resource manager at detach time.
2352 // Zero textures are held by the Context, and we don't attempt to request them from
2353 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002354 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002355}
2356
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002357void Context::detachBuffer(GLuint buffer)
2358{
Yuly Novikov5807a532015-12-03 13:01:22 -05002359 // Simple pass-through to State's detachBuffer method, since
2360 // only buffer attachments to container objects that are bound to the current context
2361 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002362
Yuly Novikov5807a532015-12-03 13:01:22 -05002363 // [OpenGL ES 3.2] section 5.1.2 page 45:
2364 // Attachments to unbound container objects, such as
2365 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2366 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002367 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002368}
2369
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002370void Context::detachFramebuffer(GLuint framebuffer)
2371{
Shannon Woods53a94a82014-06-24 15:20:36 -04002372 // Framebuffer detachment is handled by Context, because 0 is a valid
2373 // Framebuffer object, and a pointer to it must be passed from Context
2374 // to State at binding time.
2375
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002376 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002377 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2378 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2379 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002380
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002381 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002382 {
2383 bindReadFramebuffer(0);
2384 }
2385
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002386 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002387 {
2388 bindDrawFramebuffer(0);
2389 }
2390}
2391
2392void Context::detachRenderbuffer(GLuint renderbuffer)
2393{
Jamie Madilla02315b2017-02-23 14:14:47 -05002394 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002395}
2396
Jamie Madill57a89722013-07-02 11:57:03 -04002397void Context::detachVertexArray(GLuint vertexArray)
2398{
Jamie Madill77a72f62015-04-14 11:18:32 -04002399 // Vertex array detachment is handled by Context, because 0 is a valid
2400 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002401 // binding time.
2402
Jamie Madill57a89722013-07-02 11:57:03 -04002403 // [OpenGL ES 3.0.2] section 2.10 page 43:
2404 // If a vertex array object that is currently bound is deleted, the binding
2405 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002406 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002407 {
2408 bindVertexArray(0);
2409 }
2410}
2411
Geoff Langc8058452014-02-03 12:04:11 -05002412void Context::detachTransformFeedback(GLuint transformFeedback)
2413{
Corentin Walleza2257da2016-04-19 16:43:12 -04002414 // Transform feedback detachment is handled by Context, because 0 is a valid
2415 // transform feedback, and a pointer to it must be passed from Context to State at
2416 // binding time.
2417
2418 // The OpenGL specification doesn't mention what should happen when the currently bound
2419 // transform feedback object is deleted. Since it is a container object, we treat it like
2420 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002421 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002422 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002423 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002424 }
Geoff Langc8058452014-02-03 12:04:11 -05002425}
2426
Jamie Madilldc356042013-07-19 16:36:57 -04002427void Context::detachSampler(GLuint sampler)
2428{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002429 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002430}
2431
Yunchao Hea336b902017-08-02 16:05:21 +08002432void Context::detachProgramPipeline(GLuint pipeline)
2433{
2434 mGLState.detachProgramPipeline(this, pipeline);
2435}
2436
Jamie Madill3ef140a2017-08-26 23:11:21 -04002437void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002438{
Shaodde78e82017-05-22 14:13:27 +08002439 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002440}
2441
Jamie Madille29d1672013-07-19 16:36:57 -04002442void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2443{
Geoff Langc1984ed2016-10-07 12:41:00 -04002444 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002445 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002446 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002447 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002448}
Jamie Madille29d1672013-07-19 16:36:57 -04002449
Geoff Langc1984ed2016-10-07 12:41:00 -04002450void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2451{
2452 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002453 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002454 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002455 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002456}
2457
2458void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2459{
Geoff Langc1984ed2016-10-07 12:41:00 -04002460 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002461 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002462 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002463 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002464}
2465
Geoff Langc1984ed2016-10-07 12:41:00 -04002466void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002467{
Geoff Langc1984ed2016-10-07 12:41:00 -04002468 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002469 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002470 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002471 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002472}
2473
Geoff Langc1984ed2016-10-07 12:41:00 -04002474void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002475{
Geoff Langc1984ed2016-10-07 12:41:00 -04002476 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002477 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002478 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002479 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002480}
Jamie Madill9675b802013-07-19 16:36:59 -04002481
Geoff Langc1984ed2016-10-07 12:41:00 -04002482void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2483{
2484 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002485 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002486 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002487 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002488}
2489
Olli Etuahof0fee072016-03-30 15:11:58 +03002490void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2491{
2492 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002493 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002494}
2495
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002496void Context::initRendererString()
2497{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002498 std::ostringstream rendererString;
2499 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002500 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002501 rendererString << ")";
2502
Geoff Langcec35902014-04-16 10:52:36 -04002503 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002504}
2505
Geoff Langc339c4e2016-11-29 10:37:36 -05002506void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002507{
Geoff Langc339c4e2016-11-29 10:37:36 -05002508 const Version &clientVersion = getClientVersion();
2509
2510 std::ostringstream versionString;
2511 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2512 << ANGLE_VERSION_STRING << ")";
2513 mVersionString = MakeStaticString(versionString.str());
2514
2515 std::ostringstream shadingLanguageVersionString;
2516 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2517 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2518 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2519 << ")";
2520 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002521}
2522
Geoff Langcec35902014-04-16 10:52:36 -04002523void Context::initExtensionStrings()
2524{
Geoff Langc339c4e2016-11-29 10:37:36 -05002525 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2526 std::ostringstream combinedStringStream;
2527 std::copy(strings.begin(), strings.end(),
2528 std::ostream_iterator<const char *>(combinedStringStream, " "));
2529 return MakeStaticString(combinedStringStream.str());
2530 };
2531
2532 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002533 for (const auto &extensionString : mExtensions.getStrings())
2534 {
2535 mExtensionStrings.push_back(MakeStaticString(extensionString));
2536 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002537 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002538
Bryan Bernhart58806562017-01-05 13:09:31 -08002539 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2540
Geoff Langc339c4e2016-11-29 10:37:36 -05002541 mRequestableExtensionStrings.clear();
2542 for (const auto &extensionInfo : GetExtensionInfoMap())
2543 {
2544 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002545 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2546 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002547 {
2548 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2549 }
2550 }
2551 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002552}
2553
Geoff Langc339c4e2016-11-29 10:37:36 -05002554const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002555{
Geoff Langc339c4e2016-11-29 10:37:36 -05002556 switch (name)
2557 {
2558 case GL_VENDOR:
2559 return reinterpret_cast<const GLubyte *>("Google Inc.");
2560
2561 case GL_RENDERER:
2562 return reinterpret_cast<const GLubyte *>(mRendererString);
2563
2564 case GL_VERSION:
2565 return reinterpret_cast<const GLubyte *>(mVersionString);
2566
2567 case GL_SHADING_LANGUAGE_VERSION:
2568 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2569
2570 case GL_EXTENSIONS:
2571 return reinterpret_cast<const GLubyte *>(mExtensionString);
2572
2573 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2574 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2575
2576 default:
2577 UNREACHABLE();
2578 return nullptr;
2579 }
Geoff Langcec35902014-04-16 10:52:36 -04002580}
2581
Geoff Langc339c4e2016-11-29 10:37:36 -05002582const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002583{
Geoff Langc339c4e2016-11-29 10:37:36 -05002584 switch (name)
2585 {
2586 case GL_EXTENSIONS:
2587 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2588
2589 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2590 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2591
2592 default:
2593 UNREACHABLE();
2594 return nullptr;
2595 }
Geoff Langcec35902014-04-16 10:52:36 -04002596}
2597
2598size_t Context::getExtensionStringCount() const
2599{
2600 return mExtensionStrings.size();
2601}
2602
Geoff Lang111a99e2017-10-17 10:58:41 -04002603bool Context::isExtensionRequestable(const char *name)
2604{
2605 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2606 auto extension = extensionInfos.find(name);
2607
2608 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2609 return extension != extensionInfos.end() && extension->second.Requestable &&
2610 nativeExtensions.*(extension->second.ExtensionsMember);
2611}
2612
Geoff Langc339c4e2016-11-29 10:37:36 -05002613void Context::requestExtension(const char *name)
2614{
2615 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2616 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2617 const auto &extension = extensionInfos.at(name);
2618 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002619 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002620
2621 if (mExtensions.*(extension.ExtensionsMember))
2622 {
2623 // Extension already enabled
2624 return;
2625 }
2626
2627 mExtensions.*(extension.ExtensionsMember) = true;
2628 updateCaps();
2629 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002630
Jamie Madill2f348d22017-06-05 10:50:59 -04002631 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2632 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002633
Jamie Madill81c2e252017-09-09 23:32:46 -04002634 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2635 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002636 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002637 for (auto &zeroTexture : mZeroTextures)
2638 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002639 if (zeroTexture.get() != nullptr)
2640 {
2641 zeroTexture->signalDirty(this, InitState::Initialized);
2642 }
Geoff Lang9aded172017-04-05 11:07:56 -04002643 }
2644
2645 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002646}
2647
2648size_t Context::getRequestableExtensionStringCount() const
2649{
2650 return mRequestableExtensionStrings.size();
2651}
2652
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002653void Context::beginTransformFeedback(GLenum primitiveMode)
2654{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002655 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002656 ASSERT(transformFeedback != nullptr);
2657 ASSERT(!transformFeedback->isPaused());
2658
Jamie Madill6c1f6712017-02-14 19:08:04 -05002659 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002660}
2661
2662bool Context::hasActiveTransformFeedback(GLuint program) const
2663{
2664 for (auto pair : mTransformFeedbackMap)
2665 {
2666 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2667 {
2668 return true;
2669 }
2670 }
2671 return false;
2672}
2673
Geoff Langb433e872017-10-05 14:01:47 -04002674void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002675{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002676 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002677
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08002678 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
2679 if (getClientVersion() < Version(2, 0))
2680 {
2681 mCaps.maxMultitextureUnits = 4;
2682 mCaps.maxClipPlanes = 6;
2683 mCaps.maxLights = 8;
2684 mCaps.maxModelviewMatrixStackDepth = 16;
2685 mCaps.maxProjectionMatrixStackDepth = 16;
2686 mCaps.maxTextureMatrixStackDepth = 16;
2687 }
2688
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002689 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002690
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002691 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002692
Geoff Langeb66a6e2016-10-31 13:06:12 -04002693 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002694 {
2695 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002696 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002697 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002698 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002699 mExtensions.multiview = false;
2700 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002701 }
2702
Jiawei Shao89be29a2017-11-06 14:36:45 +08002703 if (getClientVersion() < ES_3_1)
2704 {
2705 // Disable ES3.1+ extensions
2706 mExtensions.geometryShader = false;
2707 }
2708
Geoff Langeb66a6e2016-10-31 13:06:12 -04002709 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002710 {
2711 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002712 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002713 }
2714
Jamie Madill00ed7a12016-05-19 13:13:38 -04002715 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002716 mExtensions.bindUniformLocation = true;
2717 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002718 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002719 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002720 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002721
2722 // Enable the no error extension if the context was created with the flag.
2723 mExtensions.noError = mSkipValidation;
2724
Corentin Wallezccab69d2017-01-27 16:57:15 -05002725 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002726 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002727
Geoff Lang70d0f492015-12-10 17:45:46 -05002728 // Explicitly enable GL_KHR_debug
2729 mExtensions.debug = true;
2730 mExtensions.maxDebugMessageLength = 1024;
2731 mExtensions.maxDebugLoggedMessages = 1024;
2732 mExtensions.maxDebugGroupStackDepth = 1024;
2733 mExtensions.maxLabelLength = 1024;
2734
Geoff Langff5b2d52016-09-07 11:32:23 -04002735 // Explicitly enable GL_ANGLE_robust_client_memory
2736 mExtensions.robustClientMemory = true;
2737
Jamie Madille08a1d32017-03-07 17:24:06 -05002738 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002739 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002740
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002741 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2742 // supports it.
2743 mExtensions.robustBufferAccessBehavior =
2744 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2745
Jamie Madillc43be722017-07-13 16:22:14 -04002746 // Enable the cache control query unconditionally.
2747 mExtensions.programCacheControl = true;
2748
Geoff Lang301d1612014-07-09 10:34:37 -04002749 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002750 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002751
Jamie Madill0f80ed82017-09-19 00:24:56 -04002752 if (getClientVersion() < ES_3_1)
2753 {
2754 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2755 }
2756 else
2757 {
2758 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2759 }
Geoff Lang301d1612014-07-09 10:34:37 -04002760
Jamie Madill0f80ed82017-09-19 00:24:56 -04002761 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2762 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2763 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2764
2765 // Limit textures as well, so we can use fast bitsets with texture bindings.
2766 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2767 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2768 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002769
Jiawei Shaodb342272017-09-27 10:21:45 +08002770 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2771
Geoff Langc287ea62016-09-16 14:46:51 -04002772 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002773 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002774 for (const auto &extensionInfo : GetExtensionInfoMap())
2775 {
2776 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002777 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002778 {
2779 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2780 }
2781 }
2782
2783 // Generate texture caps
2784 updateCaps();
2785}
2786
2787void Context::updateCaps()
2788{
Geoff Lang900013c2014-07-07 11:32:19 -04002789 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002790 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002791
Jamie Madill7b62cf92017-11-02 15:20:49 -04002792 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04002793 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04002794 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04002795 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002796
Geoff Lang0d8b7242015-09-09 14:56:53 -04002797 // Update the format caps based on the client version and extensions.
2798 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2799 // ES3.
2800 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002801 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002802 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002803 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002804 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002805 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002806
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002807 // OpenGL ES does not support multisampling with non-rendererable formats
2808 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002809 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002810 (getClientVersion() < ES_3_1 &&
2811 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002812 {
Geoff Langd87878e2014-09-19 15:42:59 -04002813 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002814 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002815 else
2816 {
2817 // We may have limited the max samples for some required renderbuffer formats due to
2818 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2819 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2820
2821 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2822 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2823 // exception of signed and unsigned integer formats."
2824 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2825 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2826 {
2827 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2828 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2829 }
2830
2831 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2832 if (getClientVersion() >= ES_3_1)
2833 {
2834 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2835 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2836 // the exception that the signed and unsigned integer formats are required only to
2837 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2838 // multisamples, which must be at least one."
2839 if (formatInfo.componentType == GL_INT ||
2840 formatInfo.componentType == GL_UNSIGNED_INT)
2841 {
2842 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2843 }
2844
2845 // GLES 3.1 section 19.3.1.
2846 if (formatCaps.texturable)
2847 {
2848 if (formatInfo.depthBits > 0)
2849 {
2850 mCaps.maxDepthTextureSamples =
2851 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2852 }
2853 else if (formatInfo.redBits > 0)
2854 {
2855 mCaps.maxColorTextureSamples =
2856 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2857 }
2858 }
2859 }
2860 }
Geoff Langd87878e2014-09-19 15:42:59 -04002861
2862 if (formatCaps.texturable && formatInfo.compressed)
2863 {
Geoff Langca271392017-04-05 12:30:00 -04002864 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002865 }
2866
Geoff Langca271392017-04-05 12:30:00 -04002867 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002868 }
Jamie Madill32447362017-06-28 14:53:52 -04002869
2870 // If program binary is disabled, blank out the memory cache pointer.
2871 if (!mImplementation->getNativeExtensions().getProgramBinary)
2872 {
2873 mMemoryProgramCache = nullptr;
2874 }
Corentin Walleze4477002017-12-01 14:39:58 -05002875
2876 // Compute which buffer types are allowed
2877 mValidBufferBindings.reset();
2878 mValidBufferBindings.set(BufferBinding::ElementArray);
2879 mValidBufferBindings.set(BufferBinding::Array);
2880
2881 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
2882 {
2883 mValidBufferBindings.set(BufferBinding::PixelPack);
2884 mValidBufferBindings.set(BufferBinding::PixelUnpack);
2885 }
2886
2887 if (getClientVersion() >= ES_3_0)
2888 {
2889 mValidBufferBindings.set(BufferBinding::CopyRead);
2890 mValidBufferBindings.set(BufferBinding::CopyWrite);
2891 mValidBufferBindings.set(BufferBinding::TransformFeedback);
2892 mValidBufferBindings.set(BufferBinding::Uniform);
2893 }
2894
2895 if (getClientVersion() >= ES_3_1)
2896 {
2897 mValidBufferBindings.set(BufferBinding::AtomicCounter);
2898 mValidBufferBindings.set(BufferBinding::ShaderStorage);
2899 mValidBufferBindings.set(BufferBinding::DrawIndirect);
2900 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
2901 }
Geoff Lang493daf52014-07-03 13:38:44 -04002902}
2903
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002904void Context::initWorkarounds()
2905{
Jamie Madill761b02c2017-06-23 16:27:06 -04002906 // Apply back-end workarounds.
2907 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2908
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002909 // Lose the context upon out of memory error if the application is
2910 // expecting to watch for those events.
2911 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2912}
2913
Jamie Madill05b35b22017-10-03 09:01:44 -04002914Error Context::prepareForDraw()
2915{
Geoff Langd4fff502017-09-22 11:28:28 -04002916 ANGLE_TRY(syncRendererDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04002917
2918 if (isRobustResourceInitEnabled())
2919 {
2920 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
2921 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
2922 }
2923
Geoff Langd4fff502017-09-22 11:28:28 -04002924 ANGLE_TRY(syncRendererDirtyBits());
2925 return NoError();
2926}
2927
2928Error Context::prepareForClear(GLbitfield mask)
2929{
2930 ANGLE_TRY(syncRendererDirtyObjects(mClearDirtyObjects));
2931 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
2932 ANGLE_TRY(syncRendererDirtyBits(mClearDirtyBits));
2933 return NoError();
2934}
2935
2936Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
2937{
2938 ANGLE_TRY(syncRendererDirtyObjects(mClearDirtyObjects));
2939 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
2940 drawbuffer));
2941 ANGLE_TRY(syncRendererDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04002942 return NoError();
2943}
2944
Jamie Madillbc918e72018-03-08 09:47:21 -05002945Error Context::syncRendererState()
Jamie Madill1b94d432015-08-07 13:23:23 -04002946{
Geoff Langd4fff502017-09-22 11:28:28 -04002947 ANGLE_TRY(syncRendererDirtyObjects());
2948 ANGLE_TRY(syncRendererDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05002949 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04002950}
2951
Jamie Madillbc918e72018-03-08 09:47:21 -05002952Error Context::syncRendererState(const State::DirtyBits &bitMask,
2953 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002954{
Geoff Langd4fff502017-09-22 11:28:28 -04002955 ANGLE_TRY(syncRendererDirtyObjects(objectMask));
2956 ANGLE_TRY(syncRendererDirtyBits(bitMask));
2957 return NoError();
2958}
2959
2960Error Context::syncRendererDirtyBits()
2961{
2962 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
2963 mImplementation->syncState(this, dirtyBits);
2964 mGLState.clearDirtyBits();
2965 return NoError();
2966}
2967
2968Error Context::syncRendererDirtyBits(const State::DirtyBits &bitMask)
2969{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002970 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002971 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002972 mGLState.clearDirtyBits(dirtyBits);
Jamie Madillbc918e72018-03-08 09:47:21 -05002973 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04002974}
Jamie Madillc29968b2016-01-20 11:17:23 -05002975
Geoff Langd4fff502017-09-22 11:28:28 -04002976Error Context::syncRendererDirtyObjects()
2977{
2978 return mGLState.syncDirtyObjects(this);
2979}
2980
2981Error Context::syncRendererDirtyObjects(const State::DirtyObjects &objectMask)
2982{
2983 return mGLState.syncDirtyObjects(this, objectMask);
2984}
2985
Jamie Madillc29968b2016-01-20 11:17:23 -05002986void Context::blitFramebuffer(GLint srcX0,
2987 GLint srcY0,
2988 GLint srcX1,
2989 GLint srcY1,
2990 GLint dstX0,
2991 GLint dstY0,
2992 GLint dstX1,
2993 GLint dstY1,
2994 GLbitfield mask,
2995 GLenum filter)
2996{
Qin Jiajiaaef92162018-02-27 13:51:44 +08002997 if (mask == 0)
2998 {
2999 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
3000 // buffers are copied.
3001 return;
3002 }
3003
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003004 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003005 ASSERT(drawFramebuffer);
3006
3007 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
3008 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
3009
Jamie Madillbc918e72018-03-08 09:47:21 -05003010 ANGLE_CONTEXT_TRY(syncStateForBlit());
Jamie Madillc29968b2016-01-20 11:17:23 -05003011
Jamie Madillc564c072017-06-01 12:45:42 -04003012 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003013}
Jamie Madillc29968b2016-01-20 11:17:23 -05003014
3015void Context::clear(GLbitfield mask)
3016{
Geoff Langd4fff502017-09-22 11:28:28 -04003017 ANGLE_CONTEXT_TRY(prepareForClear(mask));
3018 ANGLE_CONTEXT_TRY(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05003019}
3020
3021void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
3022{
Geoff Langd4fff502017-09-22 11:28:28 -04003023 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3024 ANGLE_CONTEXT_TRY(
3025 mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003026}
3027
3028void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
3029{
Geoff Langd4fff502017-09-22 11:28:28 -04003030 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3031 ANGLE_CONTEXT_TRY(
3032 mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003033}
3034
3035void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
3036{
Geoff Langd4fff502017-09-22 11:28:28 -04003037 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3038 ANGLE_CONTEXT_TRY(
3039 mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05003040}
3041
3042void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
3043{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003044 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003045 ASSERT(framebufferObject);
3046
3047 // If a buffer is not present, the clear has no effect
3048 if (framebufferObject->getDepthbuffer() == nullptr &&
3049 framebufferObject->getStencilbuffer() == nullptr)
3050 {
3051 return;
3052 }
3053
Geoff Langd4fff502017-09-22 11:28:28 -04003054 ANGLE_CONTEXT_TRY(prepareForClearBuffer(buffer, drawbuffer));
3055 ANGLE_CONTEXT_TRY(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003056}
3057
3058void Context::readPixels(GLint x,
3059 GLint y,
3060 GLsizei width,
3061 GLsizei height,
3062 GLenum format,
3063 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003064 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003065{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003066 if (width == 0 || height == 0)
3067 {
3068 return;
3069 }
3070
Jamie Madillbc918e72018-03-08 09:47:21 -05003071 ANGLE_CONTEXT_TRY(syncStateForReadPixels());
Jamie Madillc29968b2016-01-20 11:17:23 -05003072
Jamie Madillb6664922017-07-25 12:55:04 -04003073 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3074 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003075
3076 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003077 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003078}
3079
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003080void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003081 GLint level,
3082 GLenum internalformat,
3083 GLint x,
3084 GLint y,
3085 GLsizei width,
3086 GLsizei height,
3087 GLint border)
3088{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003089 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003090 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003091
Jamie Madillc29968b2016-01-20 11:17:23 -05003092 Rectangle sourceArea(x, y, width, height);
3093
Jamie Madill05b35b22017-10-03 09:01:44 -04003094 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003095 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003096 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003097}
3098
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003099void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003100 GLint level,
3101 GLint xoffset,
3102 GLint yoffset,
3103 GLint x,
3104 GLint y,
3105 GLsizei width,
3106 GLsizei height)
3107{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003108 if (width == 0 || height == 0)
3109 {
3110 return;
3111 }
3112
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003113 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003114 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003115
Jamie Madillc29968b2016-01-20 11:17:23 -05003116 Offset destOffset(xoffset, yoffset, 0);
3117 Rectangle sourceArea(x, y, width, height);
3118
Jamie Madill05b35b22017-10-03 09:01:44 -04003119 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003120 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003121 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003122}
3123
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003124void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003125 GLint level,
3126 GLint xoffset,
3127 GLint yoffset,
3128 GLint zoffset,
3129 GLint x,
3130 GLint y,
3131 GLsizei width,
3132 GLsizei height)
3133{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003134 if (width == 0 || height == 0)
3135 {
3136 return;
3137 }
3138
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003139 // Only sync the read FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003140 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003141
Jamie Madillc29968b2016-01-20 11:17:23 -05003142 Offset destOffset(xoffset, yoffset, zoffset);
3143 Rectangle sourceArea(x, y, width, height);
3144
Jamie Madill05b35b22017-10-03 09:01:44 -04003145 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3146 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003147 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3148 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003149}
3150
3151void Context::framebufferTexture2D(GLenum target,
3152 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003153 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003154 GLuint texture,
3155 GLint level)
3156{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003157 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003158 ASSERT(framebuffer);
3159
3160 if (texture != 0)
3161 {
3162 Texture *textureObj = getTexture(texture);
3163
3164 ImageIndex index = ImageIndex::MakeInvalid();
3165
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003166 if (textarget == TextureTarget::_2D)
Jamie Madillc29968b2016-01-20 11:17:23 -05003167 {
3168 index = ImageIndex::Make2D(level);
3169 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003170 else if (textarget == TextureTarget::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003171 {
3172 index = ImageIndex::MakeRectangle(level);
3173 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003174 else if (textarget == TextureTarget::_2DMultisample)
JiangYizhoubddc46b2016-12-09 09:50:51 +08003175 {
3176 ASSERT(level == 0);
3177 index = ImageIndex::Make2DMultisample();
3178 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003179 else
3180 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003181 ASSERT(TextureTargetToType(textarget) == TextureType::CubeMap);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003182 index = ImageIndex::MakeCube(textarget, level);
Jamie Madillc29968b2016-01-20 11:17:23 -05003183 }
3184
Jamie Madilla02315b2017-02-23 14:14:47 -05003185 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003186 }
3187 else
3188 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003189 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003190 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003191
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003192 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003193}
3194
3195void Context::framebufferRenderbuffer(GLenum target,
3196 GLenum attachment,
3197 GLenum renderbuffertarget,
3198 GLuint renderbuffer)
3199{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003200 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003201 ASSERT(framebuffer);
3202
3203 if (renderbuffer != 0)
3204 {
3205 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003206
3207 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003208 renderbufferObject);
3209 }
3210 else
3211 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003212 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003213 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003214
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003215 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003216}
3217
3218void Context::framebufferTextureLayer(GLenum target,
3219 GLenum attachment,
3220 GLuint texture,
3221 GLint level,
3222 GLint layer)
3223{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003224 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003225 ASSERT(framebuffer);
3226
3227 if (texture != 0)
3228 {
3229 Texture *textureObject = getTexture(texture);
3230
3231 ImageIndex index = ImageIndex::MakeInvalid();
3232
Corentin Wallez99d492c2018-02-27 15:17:10 -05003233 if (textureObject->getType() == TextureType::_3D)
Jamie Madillc29968b2016-01-20 11:17:23 -05003234 {
3235 index = ImageIndex::Make3D(level, layer);
3236 }
3237 else
3238 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05003239 ASSERT(textureObject->getType() == TextureType::_2DArray);
Jamie Madillc29968b2016-01-20 11:17:23 -05003240 index = ImageIndex::Make2DArray(level, layer);
3241 }
3242
Jamie Madilla02315b2017-02-23 14:14:47 -05003243 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003244 }
3245 else
3246 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003247 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003248 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003249
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003250 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003251}
3252
Martin Radev137032d2017-07-13 10:11:12 +03003253void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3254 GLenum attachment,
3255 GLuint texture,
3256 GLint level,
3257 GLint baseViewIndex,
3258 GLsizei numViews)
3259{
Martin Radev82ef7742017-08-08 17:44:58 +03003260 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3261 ASSERT(framebuffer);
3262
3263 if (texture != 0)
3264 {
3265 Texture *textureObj = getTexture(texture);
3266
Martin Radev18b75ba2017-08-15 15:50:40 +03003267 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003268 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3269 numViews, baseViewIndex);
3270 }
3271 else
3272 {
3273 framebuffer->resetAttachment(this, attachment);
3274 }
3275
3276 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003277}
3278
3279void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3280 GLenum attachment,
3281 GLuint texture,
3282 GLint level,
3283 GLsizei numViews,
3284 const GLint *viewportOffsets)
3285{
Martin Radev5dae57b2017-07-14 16:15:55 +03003286 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3287 ASSERT(framebuffer);
3288
3289 if (texture != 0)
3290 {
3291 Texture *textureObj = getTexture(texture);
3292
3293 ImageIndex index = ImageIndex::Make2D(level);
3294 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3295 textureObj, numViews, viewportOffsets);
3296 }
3297 else
3298 {
3299 framebuffer->resetAttachment(this, attachment);
3300 }
3301
3302 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003303}
3304
Jamie Madillc29968b2016-01-20 11:17:23 -05003305void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3306{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003307 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003308 ASSERT(framebuffer);
3309 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003310 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003311}
3312
3313void Context::readBuffer(GLenum mode)
3314{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003315 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003316 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003317 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003318}
3319
3320void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3321{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003322 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003323 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003324
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003325 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003326 ASSERT(framebuffer);
3327
3328 // The specification isn't clear what should be done when the framebuffer isn't complete.
3329 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003330 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003331}
3332
3333void Context::invalidateFramebuffer(GLenum target,
3334 GLsizei numAttachments,
3335 const GLenum *attachments)
3336{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003337 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003338 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003339
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003340 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003341 ASSERT(framebuffer);
3342
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003343 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003344 {
Jamie Madill437fa652016-05-03 15:13:24 -04003345 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003346 }
Jamie Madill437fa652016-05-03 15:13:24 -04003347
Jamie Madill4928b7c2017-06-20 12:57:39 -04003348 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003349}
3350
3351void Context::invalidateSubFramebuffer(GLenum target,
3352 GLsizei numAttachments,
3353 const GLenum *attachments,
3354 GLint x,
3355 GLint y,
3356 GLsizei width,
3357 GLsizei height)
3358{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003359 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003360 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003361
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003362 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003363 ASSERT(framebuffer);
3364
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003365 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003366 {
Jamie Madill437fa652016-05-03 15:13:24 -04003367 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003368 }
Jamie Madill437fa652016-05-03 15:13:24 -04003369
3370 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003371 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003372}
3373
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003374void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003375 GLint level,
3376 GLint internalformat,
3377 GLsizei width,
3378 GLsizei height,
3379 GLint border,
3380 GLenum format,
3381 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003382 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003383{
Jamie Madillbc918e72018-03-08 09:47:21 -05003384 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003385
3386 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003387 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003388 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3389 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003390}
3391
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003392void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003393 GLint level,
3394 GLint internalformat,
3395 GLsizei width,
3396 GLsizei height,
3397 GLsizei depth,
3398 GLint border,
3399 GLenum format,
3400 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003401 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003402{
Jamie Madillbc918e72018-03-08 09:47:21 -05003403 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003404
3405 Extents size(width, height, depth);
3406 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003407 handleError(texture->setImage(this, mGLState.getUnpackState(),
3408 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3409 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003410}
3411
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003412void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003413 GLint level,
3414 GLint xoffset,
3415 GLint yoffset,
3416 GLsizei width,
3417 GLsizei height,
3418 GLenum format,
3419 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003420 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003421{
3422 // Zero sized uploads are valid but no-ops
3423 if (width == 0 || height == 0)
3424 {
3425 return;
3426 }
3427
Jamie Madillbc918e72018-03-08 09:47:21 -05003428 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003429
3430 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003431 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003432 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3433 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003434}
3435
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003436void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003437 GLint level,
3438 GLint xoffset,
3439 GLint yoffset,
3440 GLint zoffset,
3441 GLsizei width,
3442 GLsizei height,
3443 GLsizei depth,
3444 GLenum format,
3445 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003446 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003447{
3448 // Zero sized uploads are valid but no-ops
3449 if (width == 0 || height == 0 || depth == 0)
3450 {
3451 return;
3452 }
3453
Jamie Madillbc918e72018-03-08 09:47:21 -05003454 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003455
3456 Box area(xoffset, yoffset, zoffset, width, height, depth);
3457 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003458 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3459 NonCubeTextureTypeToTarget(target), level, area, format, type,
3460 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003461}
3462
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003463void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003464 GLint level,
3465 GLenum internalformat,
3466 GLsizei width,
3467 GLsizei height,
3468 GLint border,
3469 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003470 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003471{
Jamie Madillbc918e72018-03-08 09:47:21 -05003472 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003473
3474 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003475 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003476 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3477 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003478 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003479}
3480
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003481void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003482 GLint level,
3483 GLenum internalformat,
3484 GLsizei width,
3485 GLsizei height,
3486 GLsizei depth,
3487 GLint border,
3488 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003489 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003490{
Jamie Madillbc918e72018-03-08 09:47:21 -05003491 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003492
3493 Extents size(width, height, depth);
3494 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003495 handleError(texture->setCompressedImage(
3496 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3497 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003498}
3499
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003500void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003501 GLint level,
3502 GLint xoffset,
3503 GLint yoffset,
3504 GLsizei width,
3505 GLsizei height,
3506 GLenum format,
3507 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003508 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003509{
Jamie Madillbc918e72018-03-08 09:47:21 -05003510 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003511
3512 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003513 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003514 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3515 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003516 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003517}
3518
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003519void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003520 GLint level,
3521 GLint xoffset,
3522 GLint yoffset,
3523 GLint zoffset,
3524 GLsizei width,
3525 GLsizei height,
3526 GLsizei depth,
3527 GLenum format,
3528 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003529 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003530{
3531 // Zero sized uploads are valid but no-ops
3532 if (width == 0 || height == 0)
3533 {
3534 return;
3535 }
3536
Jamie Madillbc918e72018-03-08 09:47:21 -05003537 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003538
3539 Box area(xoffset, yoffset, zoffset, width, height, depth);
3540 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003541 handleError(texture->setCompressedSubImage(
3542 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
3543 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003544}
3545
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003546void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003547{
3548 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003549 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003550}
3551
Jamie Madill007530e2017-12-28 14:27:04 -05003552void Context::copyTexture(GLuint sourceId,
3553 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003554 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05003555 GLuint destId,
3556 GLint destLevel,
3557 GLint internalFormat,
3558 GLenum destType,
3559 GLboolean unpackFlipY,
3560 GLboolean unpackPremultiplyAlpha,
3561 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003562{
Jamie Madillbc918e72018-03-08 09:47:21 -05003563 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07003564
3565 gl::Texture *sourceTexture = getTexture(sourceId);
3566 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05003567 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
3568 sourceLevel, ConvertToBool(unpackFlipY),
3569 ConvertToBool(unpackPremultiplyAlpha),
3570 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003571}
3572
Jamie Madill007530e2017-12-28 14:27:04 -05003573void Context::copySubTexture(GLuint sourceId,
3574 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003575 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05003576 GLuint destId,
3577 GLint destLevel,
3578 GLint xoffset,
3579 GLint yoffset,
3580 GLint x,
3581 GLint y,
3582 GLsizei width,
3583 GLsizei height,
3584 GLboolean unpackFlipY,
3585 GLboolean unpackPremultiplyAlpha,
3586 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003587{
3588 // Zero sized copies are valid but no-ops
3589 if (width == 0 || height == 0)
3590 {
3591 return;
3592 }
3593
Jamie Madillbc918e72018-03-08 09:47:21 -05003594 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07003595
3596 gl::Texture *sourceTexture = getTexture(sourceId);
3597 gl::Texture *destTexture = getTexture(destId);
3598 Offset offset(xoffset, yoffset, 0);
3599 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05003600 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
3601 ConvertToBool(unpackFlipY),
3602 ConvertToBool(unpackPremultiplyAlpha),
3603 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003604}
3605
Jamie Madill007530e2017-12-28 14:27:04 -05003606void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07003607{
Jamie Madillbc918e72018-03-08 09:47:21 -05003608 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07003609
3610 gl::Texture *sourceTexture = getTexture(sourceId);
3611 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003612 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003613}
3614
Corentin Wallez336129f2017-10-17 15:55:40 -04003615void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003616{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003617 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003618 ASSERT(buffer);
3619
Geoff Lang496c02d2016-10-20 11:38:11 -07003620 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003621}
3622
Corentin Wallez336129f2017-10-17 15:55:40 -04003623void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003624{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003625 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003626 ASSERT(buffer);
3627
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003628 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003629 if (error.isError())
3630 {
Jamie Madill437fa652016-05-03 15:13:24 -04003631 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003632 return nullptr;
3633 }
3634
3635 return buffer->getMapPointer();
3636}
3637
Corentin Wallez336129f2017-10-17 15:55:40 -04003638GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003639{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003640 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003641 ASSERT(buffer);
3642
3643 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003644 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003645 if (error.isError())
3646 {
Jamie Madill437fa652016-05-03 15:13:24 -04003647 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003648 return GL_FALSE;
3649 }
3650
3651 return result;
3652}
3653
Corentin Wallez336129f2017-10-17 15:55:40 -04003654void *Context::mapBufferRange(BufferBinding target,
3655 GLintptr offset,
3656 GLsizeiptr length,
3657 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003658{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003659 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003660 ASSERT(buffer);
3661
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003662 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003663 if (error.isError())
3664 {
Jamie Madill437fa652016-05-03 15:13:24 -04003665 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003666 return nullptr;
3667 }
3668
3669 return buffer->getMapPointer();
3670}
3671
Corentin Wallez336129f2017-10-17 15:55:40 -04003672void Context::flushMappedBufferRange(BufferBinding /*target*/,
3673 GLintptr /*offset*/,
3674 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03003675{
3676 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3677}
3678
Jamie Madillbc918e72018-03-08 09:47:21 -05003679Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003680{
Jamie Madillbc918e72018-03-08 09:47:21 -05003681 return syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003682}
3683
Jamie Madillbc918e72018-03-08 09:47:21 -05003684Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003685{
Jamie Madillbc918e72018-03-08 09:47:21 -05003686 return syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003687}
3688
Jamie Madillbc918e72018-03-08 09:47:21 -05003689Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003690{
Jamie Madillbc918e72018-03-08 09:47:21 -05003691 return syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003692}
3693
Jiajia Qin5451d532017-11-16 17:16:34 +08003694void Context::activeShaderProgram(GLuint pipeline, GLuint program)
3695{
3696 UNIMPLEMENTED();
3697}
3698
Jamie Madillc20ab272016-06-09 07:20:46 -07003699void Context::activeTexture(GLenum texture)
3700{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003701 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003702}
3703
Jamie Madill876429b2017-04-20 15:46:24 -04003704void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003705{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003706 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003707}
3708
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003709void Context::blendEquation(GLenum mode)
3710{
3711 mGLState.setBlendEquation(mode, mode);
3712}
3713
Jamie Madillc20ab272016-06-09 07:20:46 -07003714void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3715{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003716 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003717}
3718
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003719void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3720{
3721 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3722}
3723
Jamie Madillc20ab272016-06-09 07:20:46 -07003724void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3725{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003726 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003727}
3728
Jamie Madill876429b2017-04-20 15:46:24 -04003729void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003730{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003731 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003732}
3733
Jamie Madill876429b2017-04-20 15:46:24 -04003734void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003735{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003736 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003737}
3738
3739void Context::clearStencil(GLint s)
3740{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003741 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003742}
3743
3744void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3745{
Geoff Lang92019432017-11-20 13:09:34 -05003746 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
3747 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003748}
3749
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003750void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003751{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003752 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003753}
3754
3755void Context::depthFunc(GLenum func)
3756{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003757 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003758}
3759
3760void Context::depthMask(GLboolean flag)
3761{
Geoff Lang92019432017-11-20 13:09:34 -05003762 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07003763}
3764
Jamie Madill876429b2017-04-20 15:46:24 -04003765void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003766{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003767 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003768}
3769
3770void Context::disable(GLenum cap)
3771{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003772 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003773}
3774
3775void Context::disableVertexAttribArray(GLuint index)
3776{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003777 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003778}
3779
3780void Context::enable(GLenum cap)
3781{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003782 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003783}
3784
3785void Context::enableVertexAttribArray(GLuint index)
3786{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003787 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003788}
3789
3790void Context::frontFace(GLenum mode)
3791{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003792 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003793}
3794
3795void Context::hint(GLenum target, GLenum mode)
3796{
3797 switch (target)
3798 {
3799 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003800 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003801 break;
3802
3803 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003804 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003805 break;
3806
3807 default:
3808 UNREACHABLE();
3809 return;
3810 }
3811}
3812
3813void Context::lineWidth(GLfloat width)
3814{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003815 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003816}
3817
3818void Context::pixelStorei(GLenum pname, GLint param)
3819{
3820 switch (pname)
3821 {
3822 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003823 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003824 break;
3825
3826 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003827 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003828 break;
3829
3830 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003831 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003832 break;
3833
3834 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003835 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003836 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003837 break;
3838
3839 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003840 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003841 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003842 break;
3843
3844 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003845 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003846 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003847 break;
3848
3849 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003850 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003851 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003852 break;
3853
3854 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003855 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003856 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003857 break;
3858
3859 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003860 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003861 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003862 break;
3863
3864 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003865 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003866 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003867 break;
3868
3869 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003870 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003871 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003872 break;
3873
3874 default:
3875 UNREACHABLE();
3876 return;
3877 }
3878}
3879
3880void Context::polygonOffset(GLfloat factor, GLfloat units)
3881{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003882 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003883}
3884
Jamie Madill876429b2017-04-20 15:46:24 -04003885void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003886{
Geoff Lang92019432017-11-20 13:09:34 -05003887 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07003888}
3889
Jiawei Shaodb342272017-09-27 10:21:45 +08003890void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3891{
3892 mGLState.setSampleMaskParams(maskNumber, mask);
3893}
3894
Jamie Madillc20ab272016-06-09 07:20:46 -07003895void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3896{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003897 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003898}
3899
3900void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3901{
3902 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3903 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003904 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003905 }
3906
3907 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3908 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003909 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003910 }
3911}
3912
3913void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3914{
3915 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3916 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003917 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003918 }
3919
3920 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3921 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003922 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003923 }
3924}
3925
3926void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3927{
3928 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3929 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003930 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003931 }
3932
3933 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3934 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003935 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003936 }
3937}
3938
3939void Context::vertexAttrib1f(GLuint index, GLfloat x)
3940{
3941 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003942 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003943}
3944
3945void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3946{
3947 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003948 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003949}
3950
3951void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3952{
3953 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003954 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003955}
3956
3957void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3958{
3959 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003960 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003961}
3962
3963void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3964{
3965 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003966 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003967}
3968
3969void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3970{
3971 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003972 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003973}
3974
3975void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3976{
3977 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003978 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003979}
3980
3981void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3982{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003983 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003984}
3985
3986void Context::vertexAttribPointer(GLuint index,
3987 GLint size,
3988 GLenum type,
3989 GLboolean normalized,
3990 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003991 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003992{
Corentin Wallez336129f2017-10-17 15:55:40 -04003993 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05003994 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003995}
3996
Shao80957d92017-02-20 21:25:59 +08003997void Context::vertexAttribFormat(GLuint attribIndex,
3998 GLint size,
3999 GLenum type,
4000 GLboolean normalized,
4001 GLuint relativeOffset)
4002{
Geoff Lang92019432017-11-20 13:09:34 -05004003 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004004 relativeOffset);
4005}
4006
4007void Context::vertexAttribIFormat(GLuint attribIndex,
4008 GLint size,
4009 GLenum type,
4010 GLuint relativeOffset)
4011{
4012 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4013}
4014
4015void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4016{
Shaodde78e82017-05-22 14:13:27 +08004017 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004018}
4019
Jiajia Qin5451d532017-11-16 17:16:34 +08004020void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004021{
4022 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4023}
4024
Jamie Madillc20ab272016-06-09 07:20:46 -07004025void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4026{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004027 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004028}
4029
4030void Context::vertexAttribIPointer(GLuint index,
4031 GLint size,
4032 GLenum type,
4033 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004034 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004035{
Corentin Wallez336129f2017-10-17 15:55:40 -04004036 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4037 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004038}
4039
4040void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4041{
4042 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004043 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004044}
4045
4046void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4047{
4048 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004049 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004050}
4051
4052void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4053{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004054 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004055}
4056
4057void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4058{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004059 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004060}
4061
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004062void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4063{
4064 const VertexAttribCurrentValueData &currentValues =
4065 getGLState().getVertexAttribCurrentValue(index);
4066 const VertexArray *vao = getGLState().getVertexArray();
4067 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4068 currentValues, pname, params);
4069}
4070
4071void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4072{
4073 const VertexAttribCurrentValueData &currentValues =
4074 getGLState().getVertexAttribCurrentValue(index);
4075 const VertexArray *vao = getGLState().getVertexArray();
4076 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4077 currentValues, pname, params);
4078}
4079
4080void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4081{
4082 const VertexAttribCurrentValueData &currentValues =
4083 getGLState().getVertexAttribCurrentValue(index);
4084 const VertexArray *vao = getGLState().getVertexArray();
4085 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4086 currentValues, pname, params);
4087}
4088
4089void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4090{
4091 const VertexAttribCurrentValueData &currentValues =
4092 getGLState().getVertexAttribCurrentValue(index);
4093 const VertexArray *vao = getGLState().getVertexArray();
4094 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4095 currentValues, pname, params);
4096}
4097
Jamie Madill876429b2017-04-20 15:46:24 -04004098void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004099{
4100 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4101 QueryVertexAttribPointerv(attrib, pname, pointer);
4102}
4103
Jamie Madillc20ab272016-06-09 07:20:46 -07004104void Context::debugMessageControl(GLenum source,
4105 GLenum type,
4106 GLenum severity,
4107 GLsizei count,
4108 const GLuint *ids,
4109 GLboolean enabled)
4110{
4111 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004112 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004113 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004114}
4115
4116void Context::debugMessageInsert(GLenum source,
4117 GLenum type,
4118 GLuint id,
4119 GLenum severity,
4120 GLsizei length,
4121 const GLchar *buf)
4122{
4123 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004124 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004125}
4126
4127void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4128{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004129 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004130}
4131
4132GLuint Context::getDebugMessageLog(GLuint count,
4133 GLsizei bufSize,
4134 GLenum *sources,
4135 GLenum *types,
4136 GLuint *ids,
4137 GLenum *severities,
4138 GLsizei *lengths,
4139 GLchar *messageLog)
4140{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004141 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4142 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004143}
4144
4145void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4146{
4147 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004148 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004149 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004150}
4151
4152void Context::popDebugGroup()
4153{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004154 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004155 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004156}
4157
Corentin Wallez336129f2017-10-17 15:55:40 -04004158void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004159{
4160 Buffer *buffer = mGLState.getTargetBuffer(target);
4161 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004162 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004163}
4164
Corentin Wallez336129f2017-10-17 15:55:40 -04004165void Context::bufferSubData(BufferBinding target,
4166 GLintptr offset,
4167 GLsizeiptr size,
4168 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004169{
4170 if (data == nullptr)
4171 {
4172 return;
4173 }
4174
4175 Buffer *buffer = mGLState.getTargetBuffer(target);
4176 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004177 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004178}
4179
Jamie Madillef300b12016-10-07 15:12:09 -04004180void Context::attachShader(GLuint program, GLuint shader)
4181{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004182 Program *programObject = mState.mShaderPrograms->getProgram(program);
4183 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004184 ASSERT(programObject && shaderObject);
4185 programObject->attachShader(shaderObject);
4186}
4187
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004188const Workarounds &Context::getWorkarounds() const
4189{
4190 return mWorkarounds;
4191}
4192
Corentin Wallez336129f2017-10-17 15:55:40 -04004193void Context::copyBufferSubData(BufferBinding readTarget,
4194 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004195 GLintptr readOffset,
4196 GLintptr writeOffset,
4197 GLsizeiptr size)
4198{
4199 // if size is zero, the copy is a successful no-op
4200 if (size == 0)
4201 {
4202 return;
4203 }
4204
4205 // TODO(jmadill): cache these.
4206 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4207 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4208
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004209 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004210}
4211
Jamie Madill01a80ee2016-11-07 12:06:18 -05004212void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4213{
4214 Program *programObject = getProgram(program);
4215 // TODO(jmadill): Re-use this from the validation if possible.
4216 ASSERT(programObject);
4217 programObject->bindAttributeLocation(index, name);
4218}
4219
Corentin Wallez336129f2017-10-17 15:55:40 -04004220void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004221{
Corentin Wallez336129f2017-10-17 15:55:40 -04004222 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4223 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004224}
4225
Corentin Wallez336129f2017-10-17 15:55:40 -04004226void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004227{
4228 bindBufferRange(target, index, buffer, 0, 0);
4229}
4230
Corentin Wallez336129f2017-10-17 15:55:40 -04004231void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004232 GLuint index,
4233 GLuint buffer,
4234 GLintptr offset,
4235 GLsizeiptr size)
4236{
Corentin Wallez336129f2017-10-17 15:55:40 -04004237 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4238 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004239}
4240
Jamie Madill01a80ee2016-11-07 12:06:18 -05004241void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4242{
4243 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4244 {
4245 bindReadFramebuffer(framebuffer);
4246 }
4247
4248 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4249 {
4250 bindDrawFramebuffer(framebuffer);
4251 }
4252}
4253
4254void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4255{
4256 ASSERT(target == GL_RENDERBUFFER);
4257 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004258 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004259 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004260}
4261
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004262void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004263 GLsizei samples,
4264 GLenum internalformat,
4265 GLsizei width,
4266 GLsizei height,
4267 GLboolean fixedsamplelocations)
4268{
4269 Extents size(width, height, 1);
4270 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004271 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4272 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004273}
4274
4275void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4276{
JiangYizhou5b03f472017-01-09 10:22:53 +08004277 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4278 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004279 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004280 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004281
4282 switch (pname)
4283 {
4284 case GL_SAMPLE_POSITION:
4285 handleError(framebuffer->getSamplePosition(index, val));
4286 break;
4287 default:
4288 UNREACHABLE();
4289 }
4290}
4291
Jamie Madille8fb6402017-02-14 17:56:40 -05004292void Context::renderbufferStorage(GLenum target,
4293 GLenum internalformat,
4294 GLsizei width,
4295 GLsizei height)
4296{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004297 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4298 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4299
Jamie Madille8fb6402017-02-14 17:56:40 -05004300 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004301 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004302}
4303
4304void Context::renderbufferStorageMultisample(GLenum target,
4305 GLsizei samples,
4306 GLenum internalformat,
4307 GLsizei width,
4308 GLsizei height)
4309{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004310 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4311 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004312
4313 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004314 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004315 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004316}
4317
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004318void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4319{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004320 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004321 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004322}
4323
JiangYizhoue18e6392017-02-20 10:32:23 +08004324void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4325{
4326 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4327 QueryFramebufferParameteriv(framebuffer, pname, params);
4328}
4329
Jiajia Qin5451d532017-11-16 17:16:34 +08004330void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004331{
4332 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4333 SetFramebufferParameteri(framebuffer, pname, param);
4334}
4335
Jamie Madillb3f26b92017-07-19 15:07:41 -04004336Error Context::getScratchBuffer(size_t requstedSizeBytes,
4337 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004338{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004339 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4340 {
4341 return OutOfMemory() << "Failed to allocate internal buffer.";
4342 }
4343 return NoError();
4344}
4345
4346Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4347 angle::MemoryBuffer **zeroBufferOut) const
4348{
4349 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004350 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004351 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004352 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004353 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004354}
4355
Xinghua Cao10a4d432017-11-28 14:46:26 +08004356Error Context::prepareForDispatch()
4357{
Jamie Madillbc918e72018-03-08 09:47:21 -05004358 ANGLE_TRY(syncRendererState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004359
4360 if (isRobustResourceInitEnabled())
4361 {
4362 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4363 }
4364
4365 return NoError();
4366}
4367
Xinghua Cao2b396592017-03-29 15:36:04 +08004368void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4369{
4370 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4371 {
4372 return;
4373 }
4374
Xinghua Cao10a4d432017-11-28 14:46:26 +08004375 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004376 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004377}
4378
Jiajia Qin5451d532017-11-16 17:16:34 +08004379void Context::dispatchComputeIndirect(GLintptr indirect)
4380{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004381 ANGLE_CONTEXT_TRY(prepareForDispatch());
4382 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004383}
4384
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004385void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004386 GLsizei levels,
4387 GLenum internalFormat,
4388 GLsizei width,
4389 GLsizei height)
4390{
4391 Extents size(width, height, 1);
4392 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004393 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004394}
4395
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004396void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004397 GLsizei levels,
4398 GLenum internalFormat,
4399 GLsizei width,
4400 GLsizei height,
4401 GLsizei depth)
4402{
4403 Extents size(width, height, depth);
4404 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004405 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004406}
4407
Jiajia Qin5451d532017-11-16 17:16:34 +08004408void Context::memoryBarrier(GLbitfield barriers)
4409{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004410 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004411}
4412
4413void Context::memoryBarrierByRegion(GLbitfield barriers)
4414{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004415 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004416}
4417
Jamie Madillc1d770e2017-04-13 17:31:24 -04004418GLenum Context::checkFramebufferStatus(GLenum target)
4419{
4420 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4421 ASSERT(framebuffer);
4422
4423 return framebuffer->checkStatus(this);
4424}
4425
4426void Context::compileShader(GLuint shader)
4427{
4428 Shader *shaderObject = GetValidShader(this, shader);
4429 if (!shaderObject)
4430 {
4431 return;
4432 }
4433 shaderObject->compile(this);
4434}
4435
4436void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4437{
4438 for (int i = 0; i < n; i++)
4439 {
4440 deleteBuffer(buffers[i]);
4441 }
4442}
4443
4444void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4445{
4446 for (int i = 0; i < n; i++)
4447 {
4448 if (framebuffers[i] != 0)
4449 {
4450 deleteFramebuffer(framebuffers[i]);
4451 }
4452 }
4453}
4454
4455void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4456{
4457 for (int i = 0; i < n; i++)
4458 {
4459 deleteRenderbuffer(renderbuffers[i]);
4460 }
4461}
4462
4463void Context::deleteTextures(GLsizei n, const GLuint *textures)
4464{
4465 for (int i = 0; i < n; i++)
4466 {
4467 if (textures[i] != 0)
4468 {
4469 deleteTexture(textures[i]);
4470 }
4471 }
4472}
4473
4474void Context::detachShader(GLuint program, GLuint shader)
4475{
4476 Program *programObject = getProgram(program);
4477 ASSERT(programObject);
4478
4479 Shader *shaderObject = getShader(shader);
4480 ASSERT(shaderObject);
4481
4482 programObject->detachShader(this, shaderObject);
4483}
4484
4485void Context::genBuffers(GLsizei n, GLuint *buffers)
4486{
4487 for (int i = 0; i < n; i++)
4488 {
4489 buffers[i] = createBuffer();
4490 }
4491}
4492
4493void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4494{
4495 for (int i = 0; i < n; i++)
4496 {
4497 framebuffers[i] = createFramebuffer();
4498 }
4499}
4500
4501void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4502{
4503 for (int i = 0; i < n; i++)
4504 {
4505 renderbuffers[i] = createRenderbuffer();
4506 }
4507}
4508
4509void Context::genTextures(GLsizei n, GLuint *textures)
4510{
4511 for (int i = 0; i < n; i++)
4512 {
4513 textures[i] = createTexture();
4514 }
4515}
4516
4517void Context::getActiveAttrib(GLuint program,
4518 GLuint index,
4519 GLsizei bufsize,
4520 GLsizei *length,
4521 GLint *size,
4522 GLenum *type,
4523 GLchar *name)
4524{
4525 Program *programObject = getProgram(program);
4526 ASSERT(programObject);
4527 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4528}
4529
4530void Context::getActiveUniform(GLuint program,
4531 GLuint index,
4532 GLsizei bufsize,
4533 GLsizei *length,
4534 GLint *size,
4535 GLenum *type,
4536 GLchar *name)
4537{
4538 Program *programObject = getProgram(program);
4539 ASSERT(programObject);
4540 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4541}
4542
4543void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4544{
4545 Program *programObject = getProgram(program);
4546 ASSERT(programObject);
4547 programObject->getAttachedShaders(maxcount, count, shaders);
4548}
4549
4550GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4551{
4552 Program *programObject = getProgram(program);
4553 ASSERT(programObject);
4554 return programObject->getAttributeLocation(name);
4555}
4556
4557void Context::getBooleanv(GLenum pname, GLboolean *params)
4558{
4559 GLenum nativeType;
4560 unsigned int numParams = 0;
4561 getQueryParameterInfo(pname, &nativeType, &numParams);
4562
4563 if (nativeType == GL_BOOL)
4564 {
4565 getBooleanvImpl(pname, params);
4566 }
4567 else
4568 {
4569 CastStateValues(this, nativeType, pname, numParams, params);
4570 }
4571}
4572
4573void Context::getFloatv(GLenum pname, GLfloat *params)
4574{
4575 GLenum nativeType;
4576 unsigned int numParams = 0;
4577 getQueryParameterInfo(pname, &nativeType, &numParams);
4578
4579 if (nativeType == GL_FLOAT)
4580 {
4581 getFloatvImpl(pname, params);
4582 }
4583 else
4584 {
4585 CastStateValues(this, nativeType, pname, numParams, params);
4586 }
4587}
4588
4589void Context::getIntegerv(GLenum pname, GLint *params)
4590{
4591 GLenum nativeType;
4592 unsigned int numParams = 0;
4593 getQueryParameterInfo(pname, &nativeType, &numParams);
4594
4595 if (nativeType == GL_INT)
4596 {
4597 getIntegervImpl(pname, params);
4598 }
4599 else
4600 {
4601 CastStateValues(this, nativeType, pname, numParams, params);
4602 }
4603}
4604
4605void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4606{
4607 Program *programObject = getProgram(program);
4608 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004609 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004610}
4611
Jiajia Qin5451d532017-11-16 17:16:34 +08004612void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
4613{
4614 UNIMPLEMENTED();
4615}
4616
Jamie Madillbe849e42017-05-02 15:49:00 -04004617void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004618{
4619 Program *programObject = getProgram(program);
4620 ASSERT(programObject);
4621 programObject->getInfoLog(bufsize, length, infolog);
4622}
4623
Jiajia Qin5451d532017-11-16 17:16:34 +08004624void Context::getProgramPipelineInfoLog(GLuint pipeline,
4625 GLsizei bufSize,
4626 GLsizei *length,
4627 GLchar *infoLog)
4628{
4629 UNIMPLEMENTED();
4630}
4631
Jamie Madillc1d770e2017-04-13 17:31:24 -04004632void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4633{
4634 Shader *shaderObject = getShader(shader);
4635 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004636 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004637}
4638
4639void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4640{
4641 Shader *shaderObject = getShader(shader);
4642 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004643 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004644}
4645
4646void Context::getShaderPrecisionFormat(GLenum shadertype,
4647 GLenum precisiontype,
4648 GLint *range,
4649 GLint *precision)
4650{
4651 // TODO(jmadill): Compute shaders.
4652
4653 switch (shadertype)
4654 {
4655 case GL_VERTEX_SHADER:
4656 switch (precisiontype)
4657 {
4658 case GL_LOW_FLOAT:
4659 mCaps.vertexLowpFloat.get(range, precision);
4660 break;
4661 case GL_MEDIUM_FLOAT:
4662 mCaps.vertexMediumpFloat.get(range, precision);
4663 break;
4664 case GL_HIGH_FLOAT:
4665 mCaps.vertexHighpFloat.get(range, precision);
4666 break;
4667
4668 case GL_LOW_INT:
4669 mCaps.vertexLowpInt.get(range, precision);
4670 break;
4671 case GL_MEDIUM_INT:
4672 mCaps.vertexMediumpInt.get(range, precision);
4673 break;
4674 case GL_HIGH_INT:
4675 mCaps.vertexHighpInt.get(range, precision);
4676 break;
4677
4678 default:
4679 UNREACHABLE();
4680 return;
4681 }
4682 break;
4683
4684 case GL_FRAGMENT_SHADER:
4685 switch (precisiontype)
4686 {
4687 case GL_LOW_FLOAT:
4688 mCaps.fragmentLowpFloat.get(range, precision);
4689 break;
4690 case GL_MEDIUM_FLOAT:
4691 mCaps.fragmentMediumpFloat.get(range, precision);
4692 break;
4693 case GL_HIGH_FLOAT:
4694 mCaps.fragmentHighpFloat.get(range, precision);
4695 break;
4696
4697 case GL_LOW_INT:
4698 mCaps.fragmentLowpInt.get(range, precision);
4699 break;
4700 case GL_MEDIUM_INT:
4701 mCaps.fragmentMediumpInt.get(range, precision);
4702 break;
4703 case GL_HIGH_INT:
4704 mCaps.fragmentHighpInt.get(range, precision);
4705 break;
4706
4707 default:
4708 UNREACHABLE();
4709 return;
4710 }
4711 break;
4712
4713 default:
4714 UNREACHABLE();
4715 return;
4716 }
4717}
4718
4719void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4720{
4721 Shader *shaderObject = getShader(shader);
4722 ASSERT(shaderObject);
4723 shaderObject->getSource(bufsize, length, source);
4724}
4725
4726void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4727{
4728 Program *programObject = getProgram(program);
4729 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004730 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004731}
4732
4733void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4734{
4735 Program *programObject = getProgram(program);
4736 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004737 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004738}
4739
4740GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4741{
4742 Program *programObject = getProgram(program);
4743 ASSERT(programObject);
4744 return programObject->getUniformLocation(name);
4745}
4746
4747GLboolean Context::isBuffer(GLuint buffer)
4748{
4749 if (buffer == 0)
4750 {
4751 return GL_FALSE;
4752 }
4753
4754 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4755}
4756
4757GLboolean Context::isEnabled(GLenum cap)
4758{
4759 return mGLState.getEnableFeature(cap);
4760}
4761
4762GLboolean Context::isFramebuffer(GLuint framebuffer)
4763{
4764 if (framebuffer == 0)
4765 {
4766 return GL_FALSE;
4767 }
4768
4769 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4770}
4771
4772GLboolean Context::isProgram(GLuint program)
4773{
4774 if (program == 0)
4775 {
4776 return GL_FALSE;
4777 }
4778
4779 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4780}
4781
4782GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4783{
4784 if (renderbuffer == 0)
4785 {
4786 return GL_FALSE;
4787 }
4788
4789 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4790}
4791
4792GLboolean Context::isShader(GLuint shader)
4793{
4794 if (shader == 0)
4795 {
4796 return GL_FALSE;
4797 }
4798
4799 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4800}
4801
4802GLboolean Context::isTexture(GLuint texture)
4803{
4804 if (texture == 0)
4805 {
4806 return GL_FALSE;
4807 }
4808
4809 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4810}
4811
4812void Context::linkProgram(GLuint program)
4813{
4814 Program *programObject = getProgram(program);
4815 ASSERT(programObject);
4816 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004817 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004818}
4819
4820void Context::releaseShaderCompiler()
4821{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004822 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004823}
4824
4825void Context::shaderBinary(GLsizei n,
4826 const GLuint *shaders,
4827 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004828 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004829 GLsizei length)
4830{
4831 // No binary shader formats are supported.
4832 UNIMPLEMENTED();
4833}
4834
4835void Context::shaderSource(GLuint shader,
4836 GLsizei count,
4837 const GLchar *const *string,
4838 const GLint *length)
4839{
4840 Shader *shaderObject = getShader(shader);
4841 ASSERT(shaderObject);
4842 shaderObject->setSource(count, string, length);
4843}
4844
4845void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4846{
4847 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4848}
4849
4850void Context::stencilMask(GLuint mask)
4851{
4852 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4853}
4854
4855void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4856{
4857 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4858}
4859
4860void Context::uniform1f(GLint location, GLfloat x)
4861{
4862 Program *program = mGLState.getProgram();
4863 program->setUniform1fv(location, 1, &x);
4864}
4865
4866void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4867{
4868 Program *program = mGLState.getProgram();
4869 program->setUniform1fv(location, count, v);
4870}
4871
4872void Context::uniform1i(GLint location, GLint x)
4873{
4874 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004875 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4876 {
4877 mGLState.setObjectDirty(GL_PROGRAM);
4878 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004879}
4880
4881void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4882{
4883 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004884 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4885 {
4886 mGLState.setObjectDirty(GL_PROGRAM);
4887 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004888}
4889
4890void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4891{
4892 GLfloat xy[2] = {x, y};
4893 Program *program = mGLState.getProgram();
4894 program->setUniform2fv(location, 1, xy);
4895}
4896
4897void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4898{
4899 Program *program = mGLState.getProgram();
4900 program->setUniform2fv(location, count, v);
4901}
4902
4903void Context::uniform2i(GLint location, GLint x, GLint y)
4904{
4905 GLint xy[2] = {x, y};
4906 Program *program = mGLState.getProgram();
4907 program->setUniform2iv(location, 1, xy);
4908}
4909
4910void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4911{
4912 Program *program = mGLState.getProgram();
4913 program->setUniform2iv(location, count, v);
4914}
4915
4916void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4917{
4918 GLfloat xyz[3] = {x, y, z};
4919 Program *program = mGLState.getProgram();
4920 program->setUniform3fv(location, 1, xyz);
4921}
4922
4923void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4924{
4925 Program *program = mGLState.getProgram();
4926 program->setUniform3fv(location, count, v);
4927}
4928
4929void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4930{
4931 GLint xyz[3] = {x, y, z};
4932 Program *program = mGLState.getProgram();
4933 program->setUniform3iv(location, 1, xyz);
4934}
4935
4936void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4937{
4938 Program *program = mGLState.getProgram();
4939 program->setUniform3iv(location, count, v);
4940}
4941
4942void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4943{
4944 GLfloat xyzw[4] = {x, y, z, w};
4945 Program *program = mGLState.getProgram();
4946 program->setUniform4fv(location, 1, xyzw);
4947}
4948
4949void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4950{
4951 Program *program = mGLState.getProgram();
4952 program->setUniform4fv(location, count, v);
4953}
4954
4955void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4956{
4957 GLint xyzw[4] = {x, y, z, w};
4958 Program *program = mGLState.getProgram();
4959 program->setUniform4iv(location, 1, xyzw);
4960}
4961
4962void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4963{
4964 Program *program = mGLState.getProgram();
4965 program->setUniform4iv(location, count, v);
4966}
4967
4968void Context::uniformMatrix2fv(GLint location,
4969 GLsizei count,
4970 GLboolean transpose,
4971 const GLfloat *value)
4972{
4973 Program *program = mGLState.getProgram();
4974 program->setUniformMatrix2fv(location, count, transpose, value);
4975}
4976
4977void Context::uniformMatrix3fv(GLint location,
4978 GLsizei count,
4979 GLboolean transpose,
4980 const GLfloat *value)
4981{
4982 Program *program = mGLState.getProgram();
4983 program->setUniformMatrix3fv(location, count, transpose, value);
4984}
4985
4986void Context::uniformMatrix4fv(GLint location,
4987 GLsizei count,
4988 GLboolean transpose,
4989 const GLfloat *value)
4990{
4991 Program *program = mGLState.getProgram();
4992 program->setUniformMatrix4fv(location, count, transpose, value);
4993}
4994
4995void Context::validateProgram(GLuint program)
4996{
4997 Program *programObject = getProgram(program);
4998 ASSERT(programObject);
4999 programObject->validate(mCaps);
5000}
5001
Jiajia Qin5451d532017-11-16 17:16:34 +08005002void Context::validateProgramPipeline(GLuint pipeline)
5003{
5004 UNIMPLEMENTED();
5005}
5006
Jamie Madilld04908b2017-06-09 14:15:35 -04005007void Context::getProgramBinary(GLuint program,
5008 GLsizei bufSize,
5009 GLsizei *length,
5010 GLenum *binaryFormat,
5011 void *binary)
5012{
5013 Program *programObject = getProgram(program);
5014 ASSERT(programObject != nullptr);
5015
5016 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5017}
5018
5019void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5020{
5021 Program *programObject = getProgram(program);
5022 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005023
Jamie Madilld04908b2017-06-09 14:15:35 -04005024 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5025}
5026
Jamie Madillff325f12017-08-26 15:06:05 -04005027void Context::uniform1ui(GLint location, GLuint v0)
5028{
5029 Program *program = mGLState.getProgram();
5030 program->setUniform1uiv(location, 1, &v0);
5031}
5032
5033void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5034{
5035 Program *program = mGLState.getProgram();
5036 const GLuint xy[] = {v0, v1};
5037 program->setUniform2uiv(location, 1, xy);
5038}
5039
5040void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5041{
5042 Program *program = mGLState.getProgram();
5043 const GLuint xyz[] = {v0, v1, v2};
5044 program->setUniform3uiv(location, 1, xyz);
5045}
5046
5047void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5048{
5049 Program *program = mGLState.getProgram();
5050 const GLuint xyzw[] = {v0, v1, v2, v3};
5051 program->setUniform4uiv(location, 1, xyzw);
5052}
5053
5054void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5055{
5056 Program *program = mGLState.getProgram();
5057 program->setUniform1uiv(location, count, value);
5058}
5059void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5060{
5061 Program *program = mGLState.getProgram();
5062 program->setUniform2uiv(location, count, value);
5063}
5064
5065void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5066{
5067 Program *program = mGLState.getProgram();
5068 program->setUniform3uiv(location, count, value);
5069}
5070
5071void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5072{
5073 Program *program = mGLState.getProgram();
5074 program->setUniform4uiv(location, count, value);
5075}
5076
Jamie Madillf0e04492017-08-26 15:28:42 -04005077void Context::genQueries(GLsizei n, GLuint *ids)
5078{
5079 for (GLsizei i = 0; i < n; i++)
5080 {
5081 GLuint handle = mQueryHandleAllocator.allocate();
5082 mQueryMap.assign(handle, nullptr);
5083 ids[i] = handle;
5084 }
5085}
5086
5087void Context::deleteQueries(GLsizei n, const GLuint *ids)
5088{
5089 for (int i = 0; i < n; i++)
5090 {
5091 GLuint query = ids[i];
5092
5093 Query *queryObject = nullptr;
5094 if (mQueryMap.erase(query, &queryObject))
5095 {
5096 mQueryHandleAllocator.release(query);
5097 if (queryObject)
5098 {
5099 queryObject->release(this);
5100 }
5101 }
5102 }
5103}
5104
5105GLboolean Context::isQuery(GLuint id)
5106{
5107 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
5108}
5109
Jamie Madillc8c95812017-08-26 18:40:09 -04005110void Context::uniformMatrix2x3fv(GLint location,
5111 GLsizei count,
5112 GLboolean transpose,
5113 const GLfloat *value)
5114{
5115 Program *program = mGLState.getProgram();
5116 program->setUniformMatrix2x3fv(location, count, transpose, value);
5117}
5118
5119void Context::uniformMatrix3x2fv(GLint location,
5120 GLsizei count,
5121 GLboolean transpose,
5122 const GLfloat *value)
5123{
5124 Program *program = mGLState.getProgram();
5125 program->setUniformMatrix3x2fv(location, count, transpose, value);
5126}
5127
5128void Context::uniformMatrix2x4fv(GLint location,
5129 GLsizei count,
5130 GLboolean transpose,
5131 const GLfloat *value)
5132{
5133 Program *program = mGLState.getProgram();
5134 program->setUniformMatrix2x4fv(location, count, transpose, value);
5135}
5136
5137void Context::uniformMatrix4x2fv(GLint location,
5138 GLsizei count,
5139 GLboolean transpose,
5140 const GLfloat *value)
5141{
5142 Program *program = mGLState.getProgram();
5143 program->setUniformMatrix4x2fv(location, count, transpose, value);
5144}
5145
5146void Context::uniformMatrix3x4fv(GLint location,
5147 GLsizei count,
5148 GLboolean transpose,
5149 const GLfloat *value)
5150{
5151 Program *program = mGLState.getProgram();
5152 program->setUniformMatrix3x4fv(location, count, transpose, value);
5153}
5154
5155void Context::uniformMatrix4x3fv(GLint location,
5156 GLsizei count,
5157 GLboolean transpose,
5158 const GLfloat *value)
5159{
5160 Program *program = mGLState.getProgram();
5161 program->setUniformMatrix4x3fv(location, count, transpose, value);
5162}
5163
Jamie Madilld7576732017-08-26 18:49:50 -04005164void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5165{
5166 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5167 {
5168 GLuint vertexArray = arrays[arrayIndex];
5169
5170 if (arrays[arrayIndex] != 0)
5171 {
5172 VertexArray *vertexArrayObject = nullptr;
5173 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5174 {
5175 if (vertexArrayObject != nullptr)
5176 {
5177 detachVertexArray(vertexArray);
5178 vertexArrayObject->onDestroy(this);
5179 }
5180
5181 mVertexArrayHandleAllocator.release(vertexArray);
5182 }
5183 }
5184 }
5185}
5186
5187void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5188{
5189 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5190 {
5191 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5192 mVertexArrayMap.assign(vertexArray, nullptr);
5193 arrays[arrayIndex] = vertexArray;
5194 }
5195}
5196
5197bool Context::isVertexArray(GLuint array)
5198{
5199 if (array == 0)
5200 {
5201 return GL_FALSE;
5202 }
5203
5204 VertexArray *vao = getVertexArray(array);
5205 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5206}
5207
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005208void Context::endTransformFeedback()
5209{
5210 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5211 transformFeedback->end(this);
5212}
5213
5214void Context::transformFeedbackVaryings(GLuint program,
5215 GLsizei count,
5216 const GLchar *const *varyings,
5217 GLenum bufferMode)
5218{
5219 Program *programObject = getProgram(program);
5220 ASSERT(programObject);
5221 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5222}
5223
5224void Context::getTransformFeedbackVarying(GLuint program,
5225 GLuint index,
5226 GLsizei bufSize,
5227 GLsizei *length,
5228 GLsizei *size,
5229 GLenum *type,
5230 GLchar *name)
5231{
5232 Program *programObject = getProgram(program);
5233 ASSERT(programObject);
5234 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5235}
5236
5237void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5238{
5239 for (int i = 0; i < n; i++)
5240 {
5241 GLuint transformFeedback = ids[i];
5242 if (transformFeedback == 0)
5243 {
5244 continue;
5245 }
5246
5247 TransformFeedback *transformFeedbackObject = nullptr;
5248 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5249 {
5250 if (transformFeedbackObject != nullptr)
5251 {
5252 detachTransformFeedback(transformFeedback);
5253 transformFeedbackObject->release(this);
5254 }
5255
5256 mTransformFeedbackHandleAllocator.release(transformFeedback);
5257 }
5258 }
5259}
5260
5261void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5262{
5263 for (int i = 0; i < n; i++)
5264 {
5265 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5266 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5267 ids[i] = transformFeedback;
5268 }
5269}
5270
5271bool Context::isTransformFeedback(GLuint id)
5272{
5273 if (id == 0)
5274 {
5275 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5276 // returns FALSE
5277 return GL_FALSE;
5278 }
5279
5280 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5281 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5282}
5283
5284void Context::pauseTransformFeedback()
5285{
5286 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5287 transformFeedback->pause();
5288}
5289
5290void Context::resumeTransformFeedback()
5291{
5292 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5293 transformFeedback->resume();
5294}
5295
Jamie Madill12e957f2017-08-26 21:42:26 -04005296void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5297{
5298 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005299 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005300}
5301
5302GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5303{
5304 const Program *programObject = getProgram(program);
5305 return programObject->getFragDataLocation(name);
5306}
5307
5308void Context::getUniformIndices(GLuint program,
5309 GLsizei uniformCount,
5310 const GLchar *const *uniformNames,
5311 GLuint *uniformIndices)
5312{
5313 const Program *programObject = getProgram(program);
5314 if (!programObject->isLinked())
5315 {
5316 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5317 {
5318 uniformIndices[uniformId] = GL_INVALID_INDEX;
5319 }
5320 }
5321 else
5322 {
5323 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5324 {
5325 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5326 }
5327 }
5328}
5329
5330void Context::getActiveUniformsiv(GLuint program,
5331 GLsizei uniformCount,
5332 const GLuint *uniformIndices,
5333 GLenum pname,
5334 GLint *params)
5335{
5336 const Program *programObject = getProgram(program);
5337 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5338 {
5339 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005340 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005341 }
5342}
5343
5344GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5345{
5346 const Program *programObject = getProgram(program);
5347 return programObject->getUniformBlockIndex(uniformBlockName);
5348}
5349
5350void Context::getActiveUniformBlockiv(GLuint program,
5351 GLuint uniformBlockIndex,
5352 GLenum pname,
5353 GLint *params)
5354{
5355 const Program *programObject = getProgram(program);
5356 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5357}
5358
5359void Context::getActiveUniformBlockName(GLuint program,
5360 GLuint uniformBlockIndex,
5361 GLsizei bufSize,
5362 GLsizei *length,
5363 GLchar *uniformBlockName)
5364{
5365 const Program *programObject = getProgram(program);
5366 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5367}
5368
5369void Context::uniformBlockBinding(GLuint program,
5370 GLuint uniformBlockIndex,
5371 GLuint uniformBlockBinding)
5372{
5373 Program *programObject = getProgram(program);
5374 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5375}
5376
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005377GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5378{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005379 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5380 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005381
Jamie Madill70b5bb02017-08-28 13:32:37 -04005382 Sync *syncObject = getSync(syncHandle);
5383 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005384 if (error.isError())
5385 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005386 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005387 handleError(error);
5388 return nullptr;
5389 }
5390
Jamie Madill70b5bb02017-08-28 13:32:37 -04005391 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005392}
5393
5394GLboolean Context::isSync(GLsync sync)
5395{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005396 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005397}
5398
5399GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5400{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005401 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005402
5403 GLenum result = GL_WAIT_FAILED;
5404 handleError(syncObject->clientWait(flags, timeout, &result));
5405 return result;
5406}
5407
5408void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5409{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005410 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005411 handleError(syncObject->serverWait(flags, timeout));
5412}
5413
5414void Context::getInteger64v(GLenum pname, GLint64 *params)
5415{
5416 GLenum nativeType = GL_NONE;
5417 unsigned int numParams = 0;
5418 getQueryParameterInfo(pname, &nativeType, &numParams);
5419
5420 if (nativeType == GL_INT_64_ANGLEX)
5421 {
5422 getInteger64vImpl(pname, params);
5423 }
5424 else
5425 {
5426 CastStateValues(this, nativeType, pname, numParams, params);
5427 }
5428}
5429
Corentin Wallez336129f2017-10-17 15:55:40 -04005430void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04005431{
5432 Buffer *buffer = mGLState.getTargetBuffer(target);
5433 QueryBufferParameteri64v(buffer, pname, params);
5434}
5435
5436void Context::genSamplers(GLsizei count, GLuint *samplers)
5437{
5438 for (int i = 0; i < count; i++)
5439 {
5440 samplers[i] = mState.mSamplers->createSampler();
5441 }
5442}
5443
5444void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5445{
5446 for (int i = 0; i < count; i++)
5447 {
5448 GLuint sampler = samplers[i];
5449
5450 if (mState.mSamplers->getSampler(sampler))
5451 {
5452 detachSampler(sampler);
5453 }
5454
5455 mState.mSamplers->deleteObject(this, sampler);
5456 }
5457}
5458
5459void Context::getInternalformativ(GLenum target,
5460 GLenum internalformat,
5461 GLenum pname,
5462 GLsizei bufSize,
5463 GLint *params)
5464{
5465 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5466 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5467}
5468
Jiajia Qin5451d532017-11-16 17:16:34 +08005469void Context::programUniform1i(GLuint program, GLint location, GLint v0)
5470{
5471 programUniform1iv(program, location, 1, &v0);
5472}
5473
5474void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
5475{
5476 GLint xy[2] = {v0, v1};
5477 programUniform2iv(program, location, 1, xy);
5478}
5479
5480void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
5481{
5482 GLint xyz[3] = {v0, v1, v2};
5483 programUniform3iv(program, location, 1, xyz);
5484}
5485
5486void Context::programUniform4i(GLuint program,
5487 GLint location,
5488 GLint v0,
5489 GLint v1,
5490 GLint v2,
5491 GLint v3)
5492{
5493 GLint xyzw[4] = {v0, v1, v2, v3};
5494 programUniform4iv(program, location, 1, xyzw);
5495}
5496
5497void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
5498{
5499 programUniform1uiv(program, location, 1, &v0);
5500}
5501
5502void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
5503{
5504 GLuint xy[2] = {v0, v1};
5505 programUniform2uiv(program, location, 1, xy);
5506}
5507
5508void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
5509{
5510 GLuint xyz[3] = {v0, v1, v2};
5511 programUniform3uiv(program, location, 1, xyz);
5512}
5513
5514void Context::programUniform4ui(GLuint program,
5515 GLint location,
5516 GLuint v0,
5517 GLuint v1,
5518 GLuint v2,
5519 GLuint v3)
5520{
5521 GLuint xyzw[4] = {v0, v1, v2, v3};
5522 programUniform4uiv(program, location, 1, xyzw);
5523}
5524
5525void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
5526{
5527 programUniform1fv(program, location, 1, &v0);
5528}
5529
5530void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
5531{
5532 GLfloat xy[2] = {v0, v1};
5533 programUniform2fv(program, location, 1, xy);
5534}
5535
5536void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
5537{
5538 GLfloat xyz[3] = {v0, v1, v2};
5539 programUniform3fv(program, location, 1, xyz);
5540}
5541
5542void Context::programUniform4f(GLuint program,
5543 GLint location,
5544 GLfloat v0,
5545 GLfloat v1,
5546 GLfloat v2,
5547 GLfloat v3)
5548{
5549 GLfloat xyzw[4] = {v0, v1, v2, v3};
5550 programUniform4fv(program, location, 1, xyzw);
5551}
5552
Jamie Madill81c2e252017-09-09 23:32:46 -04005553void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5554{
5555 Program *programObject = getProgram(program);
5556 ASSERT(programObject);
5557 if (programObject->setUniform1iv(location, count, value) ==
5558 Program::SetUniformResult::SamplerChanged)
5559 {
5560 mGLState.setObjectDirty(GL_PROGRAM);
5561 }
5562}
5563
Jiajia Qin5451d532017-11-16 17:16:34 +08005564void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5565{
5566 Program *programObject = getProgram(program);
5567 ASSERT(programObject);
5568 programObject->setUniform2iv(location, count, value);
5569}
5570
5571void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5572{
5573 Program *programObject = getProgram(program);
5574 ASSERT(programObject);
5575 programObject->setUniform3iv(location, count, value);
5576}
5577
5578void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5579{
5580 Program *programObject = getProgram(program);
5581 ASSERT(programObject);
5582 programObject->setUniform4iv(location, count, value);
5583}
5584
5585void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5586{
5587 Program *programObject = getProgram(program);
5588 ASSERT(programObject);
5589 programObject->setUniform1uiv(location, count, value);
5590}
5591
5592void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5593{
5594 Program *programObject = getProgram(program);
5595 ASSERT(programObject);
5596 programObject->setUniform2uiv(location, count, value);
5597}
5598
5599void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5600{
5601 Program *programObject = getProgram(program);
5602 ASSERT(programObject);
5603 programObject->setUniform3uiv(location, count, value);
5604}
5605
5606void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5607{
5608 Program *programObject = getProgram(program);
5609 ASSERT(programObject);
5610 programObject->setUniform4uiv(location, count, value);
5611}
5612
5613void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5614{
5615 Program *programObject = getProgram(program);
5616 ASSERT(programObject);
5617 programObject->setUniform1fv(location, count, value);
5618}
5619
5620void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5621{
5622 Program *programObject = getProgram(program);
5623 ASSERT(programObject);
5624 programObject->setUniform2fv(location, count, value);
5625}
5626
5627void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5628{
5629 Program *programObject = getProgram(program);
5630 ASSERT(programObject);
5631 programObject->setUniform3fv(location, count, value);
5632}
5633
5634void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5635{
5636 Program *programObject = getProgram(program);
5637 ASSERT(programObject);
5638 programObject->setUniform4fv(location, count, value);
5639}
5640
5641void Context::programUniformMatrix2fv(GLuint program,
5642 GLint location,
5643 GLsizei count,
5644 GLboolean transpose,
5645 const GLfloat *value)
5646{
5647 Program *programObject = getProgram(program);
5648 ASSERT(programObject);
5649 programObject->setUniformMatrix2fv(location, count, transpose, value);
5650}
5651
5652void Context::programUniformMatrix3fv(GLuint program,
5653 GLint location,
5654 GLsizei count,
5655 GLboolean transpose,
5656 const GLfloat *value)
5657{
5658 Program *programObject = getProgram(program);
5659 ASSERT(programObject);
5660 programObject->setUniformMatrix3fv(location, count, transpose, value);
5661}
5662
5663void Context::programUniformMatrix4fv(GLuint program,
5664 GLint location,
5665 GLsizei count,
5666 GLboolean transpose,
5667 const GLfloat *value)
5668{
5669 Program *programObject = getProgram(program);
5670 ASSERT(programObject);
5671 programObject->setUniformMatrix4fv(location, count, transpose, value);
5672}
5673
5674void Context::programUniformMatrix2x3fv(GLuint program,
5675 GLint location,
5676 GLsizei count,
5677 GLboolean transpose,
5678 const GLfloat *value)
5679{
5680 Program *programObject = getProgram(program);
5681 ASSERT(programObject);
5682 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
5683}
5684
5685void Context::programUniformMatrix3x2fv(GLuint program,
5686 GLint location,
5687 GLsizei count,
5688 GLboolean transpose,
5689 const GLfloat *value)
5690{
5691 Program *programObject = getProgram(program);
5692 ASSERT(programObject);
5693 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
5694}
5695
5696void Context::programUniformMatrix2x4fv(GLuint program,
5697 GLint location,
5698 GLsizei count,
5699 GLboolean transpose,
5700 const GLfloat *value)
5701{
5702 Program *programObject = getProgram(program);
5703 ASSERT(programObject);
5704 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
5705}
5706
5707void Context::programUniformMatrix4x2fv(GLuint program,
5708 GLint location,
5709 GLsizei count,
5710 GLboolean transpose,
5711 const GLfloat *value)
5712{
5713 Program *programObject = getProgram(program);
5714 ASSERT(programObject);
5715 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
5716}
5717
5718void Context::programUniformMatrix3x4fv(GLuint program,
5719 GLint location,
5720 GLsizei count,
5721 GLboolean transpose,
5722 const GLfloat *value)
5723{
5724 Program *programObject = getProgram(program);
5725 ASSERT(programObject);
5726 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
5727}
5728
5729void Context::programUniformMatrix4x3fv(GLuint program,
5730 GLint location,
5731 GLsizei count,
5732 GLboolean transpose,
5733 const GLfloat *value)
5734{
5735 Program *programObject = getProgram(program);
5736 ASSERT(programObject);
5737 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
5738}
5739
Jamie Madill81c2e252017-09-09 23:32:46 -04005740void Context::onTextureChange(const Texture *texture)
5741{
5742 // Conservatively assume all textures are dirty.
5743 // TODO(jmadill): More fine-grained update.
5744 mGLState.setObjectDirty(GL_TEXTURE);
5745}
5746
James Darpiniane8a93c62018-01-04 18:02:24 -08005747bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
5748{
5749 return mGLState.isCurrentTransformFeedback(tf);
5750}
5751bool Context::isCurrentVertexArray(const VertexArray *va) const
5752{
5753 return mGLState.isCurrentVertexArray(va);
5754}
5755
Yunchao Hea336b902017-08-02 16:05:21 +08005756void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5757{
5758 for (int i = 0; i < count; i++)
5759 {
5760 pipelines[i] = createProgramPipeline();
5761 }
5762}
5763
5764void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5765{
5766 for (int i = 0; i < count; i++)
5767 {
5768 if (pipelines[i] != 0)
5769 {
5770 deleteProgramPipeline(pipelines[i]);
5771 }
5772 }
5773}
5774
5775GLboolean Context::isProgramPipeline(GLuint pipeline)
5776{
5777 if (pipeline == 0)
5778 {
5779 return GL_FALSE;
5780 }
5781
5782 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5783}
5784
Jamie Madill2b7bbc22017-12-21 17:30:38 -05005785void Context::finishFenceNV(GLuint fence)
5786{
5787 FenceNV *fenceObject = getFenceNV(fence);
5788
5789 ASSERT(fenceObject && fenceObject->isSet());
5790 handleError(fenceObject->finish());
5791}
5792
5793void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
5794{
5795 FenceNV *fenceObject = getFenceNV(fence);
5796
5797 ASSERT(fenceObject && fenceObject->isSet());
5798
5799 switch (pname)
5800 {
5801 case GL_FENCE_STATUS_NV:
5802 {
5803 // GL_NV_fence spec:
5804 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
5805 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
5806 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
5807 GLboolean status = GL_TRUE;
5808 if (fenceObject->getStatus() != GL_TRUE)
5809 {
5810 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
5811 }
5812 *params = status;
5813 break;
5814 }
5815
5816 case GL_FENCE_CONDITION_NV:
5817 {
5818 *params = static_cast<GLint>(fenceObject->getCondition());
5819 break;
5820 }
5821
5822 default:
5823 UNREACHABLE();
5824 }
5825}
5826
5827void Context::getTranslatedShaderSource(GLuint shader,
5828 GLsizei bufsize,
5829 GLsizei *length,
5830 GLchar *source)
5831{
5832 Shader *shaderObject = getShader(shader);
5833 ASSERT(shaderObject);
5834 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
5835}
5836
5837void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
5838{
5839 Program *programObject = getProgram(program);
5840 ASSERT(programObject);
5841
5842 programObject->getUniformfv(this, location, params);
5843}
5844
5845void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
5846{
5847 Program *programObject = getProgram(program);
5848 ASSERT(programObject);
5849
5850 programObject->getUniformiv(this, location, params);
5851}
5852
5853GLboolean Context::isFenceNV(GLuint fence)
5854{
5855 FenceNV *fenceObject = getFenceNV(fence);
5856
5857 if (fenceObject == nullptr)
5858 {
5859 return GL_FALSE;
5860 }
5861
5862 // GL_NV_fence spec:
5863 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
5864 // existing fence.
5865 return fenceObject->isSet();
5866}
5867
5868void Context::readnPixels(GLint x,
5869 GLint y,
5870 GLsizei width,
5871 GLsizei height,
5872 GLenum format,
5873 GLenum type,
5874 GLsizei bufSize,
5875 void *data)
5876{
5877 return readPixels(x, y, width, height, format, type, data);
5878}
5879
Jamie Madill007530e2017-12-28 14:27:04 -05005880void Context::setFenceNV(GLuint fence, GLenum condition)
5881{
5882 ASSERT(condition == GL_ALL_COMPLETED_NV);
5883
5884 FenceNV *fenceObject = getFenceNV(fence);
5885 ASSERT(fenceObject != nullptr);
5886 handleError(fenceObject->set(condition));
5887}
5888
5889GLboolean Context::testFenceNV(GLuint fence)
5890{
5891 FenceNV *fenceObject = getFenceNV(fence);
5892
5893 ASSERT(fenceObject != nullptr);
5894 ASSERT(fenceObject->isSet() == GL_TRUE);
5895
5896 GLboolean result = GL_TRUE;
5897 Error error = fenceObject->test(&result);
5898 if (error.isError())
5899 {
5900 handleError(error);
5901 return GL_TRUE;
5902 }
5903
5904 return result;
5905}
5906
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005907void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005908{
5909 Texture *texture = getTargetTexture(target);
5910 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005911 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05005912}
5913
Jamie Madillfa920eb2018-01-04 11:45:50 -05005914void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005915{
5916 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
5917 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
5918 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
5919}
5920
Jamie Madillfa920eb2018-01-04 11:45:50 -05005921void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
5922{
5923 UNIMPLEMENTED();
5924}
5925
Geoff Lang2aaa7b42018-01-12 17:17:27 -05005926void Context::alphaFunc(GLenum func, GLfloat ref)
5927{
5928 UNIMPLEMENTED();
5929}
5930
5931void Context::alphaFuncx(GLenum func, GLfixed ref)
5932{
5933 UNIMPLEMENTED();
5934}
5935
5936void Context::clearColorx(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5937{
5938 UNIMPLEMENTED();
5939}
5940
5941void Context::clearDepthx(GLfixed depth)
5942{
5943 UNIMPLEMENTED();
5944}
5945
5946void Context::clientActiveTexture(GLenum texture)
5947{
5948 UNIMPLEMENTED();
5949}
5950
5951void Context::clipPlanef(GLenum p, const GLfloat *eqn)
5952{
5953 UNIMPLEMENTED();
5954}
5955
5956void Context::clipPlanex(GLenum plane, const GLfixed *equation)
5957{
5958 UNIMPLEMENTED();
5959}
5960
5961void Context::color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
5962{
5963 UNIMPLEMENTED();
5964}
5965
5966void Context::color4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
5967{
5968 UNIMPLEMENTED();
5969}
5970
5971void Context::color4x(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5972{
5973 UNIMPLEMENTED();
5974}
5975
5976void Context::colorPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
5977{
5978 UNIMPLEMENTED();
5979}
5980
5981void Context::cullFace(GLenum mode)
5982{
5983 UNIMPLEMENTED();
5984}
5985
5986void Context::depthRangex(GLfixed n, GLfixed f)
5987{
5988 UNIMPLEMENTED();
5989}
5990
5991void Context::disableClientState(GLenum array)
5992{
5993 UNIMPLEMENTED();
5994}
5995
5996void Context::enableClientState(GLenum array)
5997{
5998 UNIMPLEMENTED();
5999}
6000
6001void Context::fogf(GLenum pname, GLfloat param)
6002{
6003 UNIMPLEMENTED();
6004}
6005
6006void Context::fogfv(GLenum pname, const GLfloat *params)
6007{
6008 UNIMPLEMENTED();
6009}
6010
6011void Context::fogx(GLenum pname, GLfixed param)
6012{
6013 UNIMPLEMENTED();
6014}
6015
6016void Context::fogxv(GLenum pname, const GLfixed *param)
6017{
6018 UNIMPLEMENTED();
6019}
6020
6021void Context::frustumf(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
6022{
6023 UNIMPLEMENTED();
6024}
6025
6026void Context::frustumx(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
6027{
6028 UNIMPLEMENTED();
6029}
6030
6031void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
6032{
6033 UNIMPLEMENTED();
6034}
6035
6036void Context::getClipPlanef(GLenum plane, GLfloat *equation)
6037{
6038 UNIMPLEMENTED();
6039}
6040
6041void Context::getClipPlanex(GLenum plane, GLfixed *equation)
6042{
6043 UNIMPLEMENTED();
6044}
6045
6046void Context::getFixedv(GLenum pname, GLfixed *params)
6047{
6048 UNIMPLEMENTED();
6049}
6050
6051void Context::getLightfv(GLenum light, GLenum pname, GLfloat *params)
6052{
6053 UNIMPLEMENTED();
6054}
6055
6056void Context::getLightxv(GLenum light, GLenum pname, GLfixed *params)
6057{
6058 UNIMPLEMENTED();
6059}
6060
6061void Context::getMaterialfv(GLenum face, GLenum pname, GLfloat *params)
6062{
6063 UNIMPLEMENTED();
6064}
6065
6066void Context::getMaterialxv(GLenum face, GLenum pname, GLfixed *params)
6067{
6068 UNIMPLEMENTED();
6069}
6070
6071void Context::getTexEnvfv(GLenum target, GLenum pname, GLfloat *params)
6072{
6073 UNIMPLEMENTED();
6074}
6075
6076void Context::getTexEnviv(GLenum target, GLenum pname, GLint *params)
6077{
6078 UNIMPLEMENTED();
6079}
6080
6081void Context::getTexEnvxv(GLenum target, GLenum pname, GLfixed *params)
6082{
6083 UNIMPLEMENTED();
6084}
6085
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006086void Context::getTexParameterxv(TextureType target, GLenum pname, GLfixed *params)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006087{
6088 UNIMPLEMENTED();
6089}
6090
6091void Context::lightModelf(GLenum pname, GLfloat param)
6092{
6093 UNIMPLEMENTED();
6094}
6095
6096void Context::lightModelfv(GLenum pname, const GLfloat *params)
6097{
6098 UNIMPLEMENTED();
6099}
6100
6101void Context::lightModelx(GLenum pname, GLfixed param)
6102{
6103 UNIMPLEMENTED();
6104}
6105
6106void Context::lightModelxv(GLenum pname, const GLfixed *param)
6107{
6108 UNIMPLEMENTED();
6109}
6110
6111void Context::lightf(GLenum light, GLenum pname, GLfloat param)
6112{
6113 UNIMPLEMENTED();
6114}
6115
6116void Context::lightfv(GLenum light, GLenum pname, const GLfloat *params)
6117{
6118 UNIMPLEMENTED();
6119}
6120
6121void Context::lightx(GLenum light, GLenum pname, GLfixed param)
6122{
6123 UNIMPLEMENTED();
6124}
6125
6126void Context::lightxv(GLenum light, GLenum pname, const GLfixed *params)
6127{
6128 UNIMPLEMENTED();
6129}
6130
6131void Context::lineWidthx(GLfixed width)
6132{
6133 UNIMPLEMENTED();
6134}
6135
6136void Context::loadIdentity()
6137{
6138 UNIMPLEMENTED();
6139}
6140
6141void Context::loadMatrixf(const GLfloat *m)
6142{
6143 UNIMPLEMENTED();
6144}
6145
6146void Context::loadMatrixx(const GLfixed *m)
6147{
6148 UNIMPLEMENTED();
6149}
6150
6151void Context::logicOp(GLenum opcode)
6152{
6153 UNIMPLEMENTED();
6154}
6155
6156void Context::materialf(GLenum face, GLenum pname, GLfloat param)
6157{
6158 UNIMPLEMENTED();
6159}
6160
6161void Context::materialfv(GLenum face, GLenum pname, const GLfloat *params)
6162{
6163 UNIMPLEMENTED();
6164}
6165
6166void Context::materialx(GLenum face, GLenum pname, GLfixed param)
6167{
6168 UNIMPLEMENTED();
6169}
6170
6171void Context::materialxv(GLenum face, GLenum pname, const GLfixed *param)
6172{
6173 UNIMPLEMENTED();
6174}
6175
6176void Context::matrixMode(GLenum mode)
6177{
6178 UNIMPLEMENTED();
6179}
6180
6181void Context::multMatrixf(const GLfloat *m)
6182{
6183 UNIMPLEMENTED();
6184}
6185
6186void Context::multMatrixx(const GLfixed *m)
6187{
6188 UNIMPLEMENTED();
6189}
6190
6191void Context::multiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q)
6192{
6193 UNIMPLEMENTED();
6194}
6195
6196void Context::multiTexCoord4x(GLenum texture, GLfixed s, GLfixed t, GLfixed r, GLfixed q)
6197{
6198 UNIMPLEMENTED();
6199}
6200
6201void Context::normal3f(GLfloat nx, GLfloat ny, GLfloat nz)
6202{
6203 UNIMPLEMENTED();
6204}
6205
6206void Context::normal3x(GLfixed nx, GLfixed ny, GLfixed nz)
6207{
6208 UNIMPLEMENTED();
6209}
6210
6211void Context::normalPointer(GLenum type, GLsizei stride, const void *pointer)
6212{
6213 UNIMPLEMENTED();
6214}
6215
6216void Context::orthof(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
6217{
6218 UNIMPLEMENTED();
6219}
6220
6221void Context::orthox(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
6222{
6223 UNIMPLEMENTED();
6224}
6225
6226void Context::pointParameterf(GLenum pname, GLfloat param)
6227{
6228 UNIMPLEMENTED();
6229}
6230
6231void Context::pointParameterfv(GLenum pname, const GLfloat *params)
6232{
6233 UNIMPLEMENTED();
6234}
6235
6236void Context::pointParameterx(GLenum pname, GLfixed param)
6237{
6238 UNIMPLEMENTED();
6239}
6240
6241void Context::pointParameterxv(GLenum pname, const GLfixed *params)
6242{
6243 UNIMPLEMENTED();
6244}
6245
6246void Context::pointSize(GLfloat size)
6247{
6248 UNIMPLEMENTED();
6249}
6250
6251void Context::pointSizex(GLfixed size)
6252{
6253 UNIMPLEMENTED();
6254}
6255
6256void Context::polygonOffsetx(GLfixed factor, GLfixed units)
6257{
6258 UNIMPLEMENTED();
6259}
6260
6261void Context::popMatrix()
6262{
6263 UNIMPLEMENTED();
6264}
6265
6266void Context::pushMatrix()
6267{
6268 UNIMPLEMENTED();
6269}
6270
6271void Context::rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
6272{
6273 UNIMPLEMENTED();
6274}
6275
6276void Context::rotatex(GLfixed angle, GLfixed x, GLfixed y, GLfixed z)
6277{
6278 UNIMPLEMENTED();
6279}
6280
6281void Context::sampleCoveragex(GLclampx value, GLboolean invert)
6282{
6283 UNIMPLEMENTED();
6284}
6285
6286void Context::scalef(GLfloat x, GLfloat y, GLfloat z)
6287{
6288 UNIMPLEMENTED();
6289}
6290
6291void Context::scalex(GLfixed x, GLfixed y, GLfixed z)
6292{
6293 UNIMPLEMENTED();
6294}
6295
6296void Context::shadeModel(GLenum mode)
6297{
6298 UNIMPLEMENTED();
6299}
6300
6301void Context::texCoordPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6302{
6303 UNIMPLEMENTED();
6304}
6305
6306void Context::texEnvf(GLenum target, GLenum pname, GLfloat param)
6307{
6308 UNIMPLEMENTED();
6309}
6310
6311void Context::texEnvfv(GLenum target, GLenum pname, const GLfloat *params)
6312{
6313 UNIMPLEMENTED();
6314}
6315
6316void Context::texEnvi(GLenum target, GLenum pname, GLint param)
6317{
6318 UNIMPLEMENTED();
6319}
6320
6321void Context::texEnviv(GLenum target, GLenum pname, const GLint *params)
6322{
6323 UNIMPLEMENTED();
6324}
6325
6326void Context::texEnvx(GLenum target, GLenum pname, GLfixed param)
6327{
6328 UNIMPLEMENTED();
6329}
6330
6331void Context::texEnvxv(GLenum target, GLenum pname, const GLfixed *params)
6332{
6333 UNIMPLEMENTED();
6334}
6335
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006336void Context::texParameterx(TextureType target, GLenum pname, GLfixed param)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006337{
6338 UNIMPLEMENTED();
6339}
6340
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006341void Context::texParameterxv(TextureType target, GLenum pname, const GLfixed *params)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006342{
6343 UNIMPLEMENTED();
6344}
6345
6346void Context::translatef(GLfloat x, GLfloat y, GLfloat z)
6347{
6348 UNIMPLEMENTED();
6349}
6350
6351void Context::translatex(GLfixed x, GLfixed y, GLfixed z)
6352{
6353 UNIMPLEMENTED();
6354}
6355
6356void Context::vertexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6357{
6358 UNIMPLEMENTED();
6359}
6360
6361void Context::drawTexf(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height)
6362{
6363 UNIMPLEMENTED();
6364}
6365
6366void Context::drawTexfv(const GLfloat *coords)
6367{
6368 UNIMPLEMENTED();
6369}
6370
6371void Context::drawTexi(GLint x, GLint y, GLint z, GLint width, GLint height)
6372{
6373 UNIMPLEMENTED();
6374}
6375
6376void Context::drawTexiv(const GLint *coords)
6377{
6378 UNIMPLEMENTED();
6379}
6380
6381void Context::drawTexs(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height)
6382{
6383 UNIMPLEMENTED();
6384}
6385
6386void Context::drawTexsv(const GLshort *coords)
6387{
6388 UNIMPLEMENTED();
6389}
6390
6391void Context::drawTexx(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height)
6392{
6393 UNIMPLEMENTED();
6394}
6395
6396void Context::drawTexxv(const GLfixed *coords)
6397{
6398 UNIMPLEMENTED();
6399}
6400
6401void Context::currentPaletteMatrix(GLuint matrixpaletteindex)
6402{
6403 UNIMPLEMENTED();
6404}
6405
6406void Context::loadPaletteFromModelViewMatrix()
6407{
6408 UNIMPLEMENTED();
6409}
6410
6411void Context::matrixIndexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6412{
6413 UNIMPLEMENTED();
6414}
6415
6416void Context::weightPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6417{
6418 UNIMPLEMENTED();
6419}
6420
6421void Context::pointSizePointer(GLenum type, GLsizei stride, const void *pointer)
6422{
6423 UNIMPLEMENTED();
6424}
6425
6426GLbitfield Context::queryMatrixx(GLfixed *mantissa, GLint *exponent)
6427{
6428 UNIMPLEMENTED();
6429 return 0;
6430}
6431
Jamie Madill5b772312018-03-08 20:28:32 -05006432bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6433{
6434 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6435 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6436 // to the fact that it is stored internally as a float, and so would require conversion
6437 // if returned from Context::getIntegerv. Since this conversion is already implemented
6438 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6439 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6440 // application.
6441 switch (pname)
6442 {
6443 case GL_COMPRESSED_TEXTURE_FORMATS:
6444 {
6445 *type = GL_INT;
6446 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6447 return true;
6448 }
6449 case GL_SHADER_BINARY_FORMATS:
6450 {
6451 *type = GL_INT;
6452 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6453 return true;
6454 }
6455
6456 case GL_MAX_VERTEX_ATTRIBS:
6457 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6458 case GL_MAX_VARYING_VECTORS:
6459 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6460 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6461 case GL_MAX_TEXTURE_IMAGE_UNITS:
6462 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6463 case GL_MAX_RENDERBUFFER_SIZE:
6464 case GL_NUM_SHADER_BINARY_FORMATS:
6465 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6466 case GL_ARRAY_BUFFER_BINDING:
6467 case GL_FRAMEBUFFER_BINDING:
6468 case GL_RENDERBUFFER_BINDING:
6469 case GL_CURRENT_PROGRAM:
6470 case GL_PACK_ALIGNMENT:
6471 case GL_UNPACK_ALIGNMENT:
6472 case GL_GENERATE_MIPMAP_HINT:
6473 case GL_RED_BITS:
6474 case GL_GREEN_BITS:
6475 case GL_BLUE_BITS:
6476 case GL_ALPHA_BITS:
6477 case GL_DEPTH_BITS:
6478 case GL_STENCIL_BITS:
6479 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6480 case GL_CULL_FACE_MODE:
6481 case GL_FRONT_FACE:
6482 case GL_ACTIVE_TEXTURE:
6483 case GL_STENCIL_FUNC:
6484 case GL_STENCIL_VALUE_MASK:
6485 case GL_STENCIL_REF:
6486 case GL_STENCIL_FAIL:
6487 case GL_STENCIL_PASS_DEPTH_FAIL:
6488 case GL_STENCIL_PASS_DEPTH_PASS:
6489 case GL_STENCIL_BACK_FUNC:
6490 case GL_STENCIL_BACK_VALUE_MASK:
6491 case GL_STENCIL_BACK_REF:
6492 case GL_STENCIL_BACK_FAIL:
6493 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6494 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6495 case GL_DEPTH_FUNC:
6496 case GL_BLEND_SRC_RGB:
6497 case GL_BLEND_SRC_ALPHA:
6498 case GL_BLEND_DST_RGB:
6499 case GL_BLEND_DST_ALPHA:
6500 case GL_BLEND_EQUATION_RGB:
6501 case GL_BLEND_EQUATION_ALPHA:
6502 case GL_STENCIL_WRITEMASK:
6503 case GL_STENCIL_BACK_WRITEMASK:
6504 case GL_STENCIL_CLEAR_VALUE:
6505 case GL_SUBPIXEL_BITS:
6506 case GL_MAX_TEXTURE_SIZE:
6507 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6508 case GL_SAMPLE_BUFFERS:
6509 case GL_SAMPLES:
6510 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6511 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6512 case GL_TEXTURE_BINDING_2D:
6513 case GL_TEXTURE_BINDING_CUBE_MAP:
6514 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6515 {
6516 *type = GL_INT;
6517 *numParams = 1;
6518 return true;
6519 }
6520 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6521 {
6522 if (!getExtensions().packReverseRowOrder)
6523 {
6524 return false;
6525 }
6526 *type = GL_INT;
6527 *numParams = 1;
6528 return true;
6529 }
6530 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6531 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6532 {
6533 if (!getExtensions().textureRectangle)
6534 {
6535 return false;
6536 }
6537 *type = GL_INT;
6538 *numParams = 1;
6539 return true;
6540 }
6541 case GL_MAX_DRAW_BUFFERS_EXT:
6542 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6543 {
6544 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6545 {
6546 return false;
6547 }
6548 *type = GL_INT;
6549 *numParams = 1;
6550 return true;
6551 }
6552 case GL_MAX_VIEWPORT_DIMS:
6553 {
6554 *type = GL_INT;
6555 *numParams = 2;
6556 return true;
6557 }
6558 case GL_VIEWPORT:
6559 case GL_SCISSOR_BOX:
6560 {
6561 *type = GL_INT;
6562 *numParams = 4;
6563 return true;
6564 }
6565 case GL_SHADER_COMPILER:
6566 case GL_SAMPLE_COVERAGE_INVERT:
6567 case GL_DEPTH_WRITEMASK:
6568 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6569 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6570 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6571 // bool-natural
6572 case GL_SAMPLE_COVERAGE:
6573 case GL_SCISSOR_TEST:
6574 case GL_STENCIL_TEST:
6575 case GL_DEPTH_TEST:
6576 case GL_BLEND:
6577 case GL_DITHER:
6578 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6579 {
6580 *type = GL_BOOL;
6581 *numParams = 1;
6582 return true;
6583 }
6584 case GL_COLOR_WRITEMASK:
6585 {
6586 *type = GL_BOOL;
6587 *numParams = 4;
6588 return true;
6589 }
6590 case GL_POLYGON_OFFSET_FACTOR:
6591 case GL_POLYGON_OFFSET_UNITS:
6592 case GL_SAMPLE_COVERAGE_VALUE:
6593 case GL_DEPTH_CLEAR_VALUE:
6594 case GL_LINE_WIDTH:
6595 {
6596 *type = GL_FLOAT;
6597 *numParams = 1;
6598 return true;
6599 }
6600 case GL_ALIASED_LINE_WIDTH_RANGE:
6601 case GL_ALIASED_POINT_SIZE_RANGE:
6602 case GL_DEPTH_RANGE:
6603 {
6604 *type = GL_FLOAT;
6605 *numParams = 2;
6606 return true;
6607 }
6608 case GL_COLOR_CLEAR_VALUE:
6609 case GL_BLEND_COLOR:
6610 {
6611 *type = GL_FLOAT;
6612 *numParams = 4;
6613 return true;
6614 }
6615 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6616 if (!getExtensions().textureFilterAnisotropic)
6617 {
6618 return false;
6619 }
6620 *type = GL_FLOAT;
6621 *numParams = 1;
6622 return true;
6623 case GL_TIMESTAMP_EXT:
6624 if (!getExtensions().disjointTimerQuery)
6625 {
6626 return false;
6627 }
6628 *type = GL_INT_64_ANGLEX;
6629 *numParams = 1;
6630 return true;
6631 case GL_GPU_DISJOINT_EXT:
6632 if (!getExtensions().disjointTimerQuery)
6633 {
6634 return false;
6635 }
6636 *type = GL_INT;
6637 *numParams = 1;
6638 return true;
6639 case GL_COVERAGE_MODULATION_CHROMIUM:
6640 if (!getExtensions().framebufferMixedSamples)
6641 {
6642 return false;
6643 }
6644 *type = GL_INT;
6645 *numParams = 1;
6646 return true;
6647 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6648 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6649 {
6650 return false;
6651 }
6652 *type = GL_INT;
6653 *numParams = 1;
6654 return true;
6655 }
6656
6657 if (getExtensions().debug)
6658 {
6659 switch (pname)
6660 {
6661 case GL_DEBUG_LOGGED_MESSAGES:
6662 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6663 case GL_DEBUG_GROUP_STACK_DEPTH:
6664 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6665 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6666 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6667 case GL_MAX_LABEL_LENGTH:
6668 *type = GL_INT;
6669 *numParams = 1;
6670 return true;
6671
6672 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6673 case GL_DEBUG_OUTPUT:
6674 *type = GL_BOOL;
6675 *numParams = 1;
6676 return true;
6677 }
6678 }
6679
6680 if (getExtensions().multisampleCompatibility)
6681 {
6682 switch (pname)
6683 {
6684 case GL_MULTISAMPLE_EXT:
6685 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6686 *type = GL_BOOL;
6687 *numParams = 1;
6688 return true;
6689 }
6690 }
6691
6692 if (getExtensions().pathRendering)
6693 {
6694 switch (pname)
6695 {
6696 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6697 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6698 *type = GL_FLOAT;
6699 *numParams = 16;
6700 return true;
6701 }
6702 }
6703
6704 if (getExtensions().bindGeneratesResource)
6705 {
6706 switch (pname)
6707 {
6708 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6709 *type = GL_BOOL;
6710 *numParams = 1;
6711 return true;
6712 }
6713 }
6714
6715 if (getExtensions().clientArrays)
6716 {
6717 switch (pname)
6718 {
6719 case GL_CLIENT_ARRAYS_ANGLE:
6720 *type = GL_BOOL;
6721 *numParams = 1;
6722 return true;
6723 }
6724 }
6725
6726 if (getExtensions().sRGBWriteControl)
6727 {
6728 switch (pname)
6729 {
6730 case GL_FRAMEBUFFER_SRGB_EXT:
6731 *type = GL_BOOL;
6732 *numParams = 1;
6733 return true;
6734 }
6735 }
6736
6737 if (getExtensions().robustResourceInitialization &&
6738 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6739 {
6740 *type = GL_BOOL;
6741 *numParams = 1;
6742 return true;
6743 }
6744
6745 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6746 {
6747 *type = GL_BOOL;
6748 *numParams = 1;
6749 return true;
6750 }
6751
6752 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6753 switch (pname)
6754 {
6755 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6756 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6757 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6758 {
6759 return false;
6760 }
6761 *type = GL_INT;
6762 *numParams = 1;
6763 return true;
6764
6765 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6766 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6767 {
6768 return false;
6769 }
6770 *type = GL_INT;
6771 *numParams = 1;
6772 return true;
6773
6774 case GL_PROGRAM_BINARY_FORMATS_OES:
6775 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6776 {
6777 return false;
6778 }
6779 *type = GL_INT;
6780 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6781 return true;
6782
6783 case GL_PACK_ROW_LENGTH:
6784 case GL_PACK_SKIP_ROWS:
6785 case GL_PACK_SKIP_PIXELS:
6786 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
6787 {
6788 return false;
6789 }
6790 *type = GL_INT;
6791 *numParams = 1;
6792 return true;
6793 case GL_UNPACK_ROW_LENGTH:
6794 case GL_UNPACK_SKIP_ROWS:
6795 case GL_UNPACK_SKIP_PIXELS:
6796 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
6797 {
6798 return false;
6799 }
6800 *type = GL_INT;
6801 *numParams = 1;
6802 return true;
6803 case GL_VERTEX_ARRAY_BINDING:
6804 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
6805 {
6806 return false;
6807 }
6808 *type = GL_INT;
6809 *numParams = 1;
6810 return true;
6811 case GL_PIXEL_PACK_BUFFER_BINDING:
6812 case GL_PIXEL_UNPACK_BUFFER_BINDING:
6813 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
6814 {
6815 return false;
6816 }
6817 *type = GL_INT;
6818 *numParams = 1;
6819 return true;
6820 case GL_MAX_SAMPLES:
6821 {
6822 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
6823 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
6824 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
6825 {
6826 return false;
6827 }
6828 *type = GL_INT;
6829 *numParams = 1;
6830 return true;
6831
6832 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
6833 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
6834 {
6835 return false;
6836 }
6837 *type = GL_INT;
6838 *numParams = 1;
6839 return true;
6840 }
6841 }
6842
6843 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
6844 {
6845 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
6846 {
6847 return false;
6848 }
6849 *type = GL_INT;
6850 *numParams = 1;
6851 return true;
6852 }
6853
6854 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
6855 {
6856 *type = GL_INT;
6857 *numParams = 1;
6858 return true;
6859 }
6860
6861 if (getClientVersion() < Version(3, 0))
6862 {
6863 return false;
6864 }
6865
6866 // Check for ES3.0+ parameter names
6867 switch (pname)
6868 {
6869 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
6870 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
6871 case GL_UNIFORM_BUFFER_BINDING:
6872 case GL_TRANSFORM_FEEDBACK_BINDING:
6873 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
6874 case GL_COPY_READ_BUFFER_BINDING:
6875 case GL_COPY_WRITE_BUFFER_BINDING:
6876 case GL_SAMPLER_BINDING:
6877 case GL_READ_BUFFER:
6878 case GL_TEXTURE_BINDING_3D:
6879 case GL_TEXTURE_BINDING_2D_ARRAY:
6880 case GL_MAX_3D_TEXTURE_SIZE:
6881 case GL_MAX_ARRAY_TEXTURE_LAYERS:
6882 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
6883 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
6884 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
6885 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
6886 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
6887 case GL_MAX_VARYING_COMPONENTS:
6888 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
6889 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
6890 case GL_MIN_PROGRAM_TEXEL_OFFSET:
6891 case GL_MAX_PROGRAM_TEXEL_OFFSET:
6892 case GL_NUM_EXTENSIONS:
6893 case GL_MAJOR_VERSION:
6894 case GL_MINOR_VERSION:
6895 case GL_MAX_ELEMENTS_INDICES:
6896 case GL_MAX_ELEMENTS_VERTICES:
6897 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
6898 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
6899 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
6900 case GL_UNPACK_IMAGE_HEIGHT:
6901 case GL_UNPACK_SKIP_IMAGES:
6902 {
6903 *type = GL_INT;
6904 *numParams = 1;
6905 return true;
6906 }
6907
6908 case GL_MAX_ELEMENT_INDEX:
6909 case GL_MAX_UNIFORM_BLOCK_SIZE:
6910 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
6911 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
6912 case GL_MAX_SERVER_WAIT_TIMEOUT:
6913 {
6914 *type = GL_INT_64_ANGLEX;
6915 *numParams = 1;
6916 return true;
6917 }
6918
6919 case GL_TRANSFORM_FEEDBACK_ACTIVE:
6920 case GL_TRANSFORM_FEEDBACK_PAUSED:
6921 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
6922 case GL_RASTERIZER_DISCARD:
6923 {
6924 *type = GL_BOOL;
6925 *numParams = 1;
6926 return true;
6927 }
6928
6929 case GL_MAX_TEXTURE_LOD_BIAS:
6930 {
6931 *type = GL_FLOAT;
6932 *numParams = 1;
6933 return true;
6934 }
6935 }
6936
6937 if (getExtensions().requestExtension)
6938 {
6939 switch (pname)
6940 {
6941 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
6942 *type = GL_INT;
6943 *numParams = 1;
6944 return true;
6945 }
6946 }
6947
6948 if (getClientVersion() < Version(3, 1))
6949 {
6950 return false;
6951 }
6952
6953 switch (pname)
6954 {
6955 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
6956 case GL_DRAW_INDIRECT_BUFFER_BINDING:
6957 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
6958 case GL_MAX_FRAMEBUFFER_WIDTH:
6959 case GL_MAX_FRAMEBUFFER_HEIGHT:
6960 case GL_MAX_FRAMEBUFFER_SAMPLES:
6961 case GL_MAX_SAMPLE_MASK_WORDS:
6962 case GL_MAX_COLOR_TEXTURE_SAMPLES:
6963 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
6964 case GL_MAX_INTEGER_SAMPLES:
6965 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
6966 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
6967 case GL_MAX_VERTEX_ATTRIB_STRIDE:
6968 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
6969 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
6970 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
6971 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
6972 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
6973 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
6974 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
6975 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
6976 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
6977 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
6978 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
6979 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
6980 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
6981 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
6982 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
6983 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
6984 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
6985 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
6986 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
6987 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
6988 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
6989 case GL_MAX_UNIFORM_LOCATIONS:
6990 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
6991 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
6992 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
6993 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
6994 case GL_MAX_IMAGE_UNITS:
6995 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
6996 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
6997 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
6998 case GL_SHADER_STORAGE_BUFFER_BINDING:
6999 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7000 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7001 *type = GL_INT;
7002 *numParams = 1;
7003 return true;
7004 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7005 *type = GL_INT_64_ANGLEX;
7006 *numParams = 1;
7007 return true;
7008 case GL_SAMPLE_MASK:
7009 *type = GL_BOOL;
7010 *numParams = 1;
7011 return true;
7012 }
7013
7014 if (getExtensions().geometryShader)
7015 {
7016 switch (pname)
7017 {
7018 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7019 case GL_LAYER_PROVOKING_VERTEX_EXT:
7020 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7021 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7022 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7023 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7024 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7025 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7026 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7027 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7028 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7029 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7030 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7031 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7032 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7033 *type = GL_INT;
7034 *numParams = 1;
7035 return true;
7036 }
7037 }
7038
7039 return false;
7040}
7041
7042bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7043{
7044 if (getClientVersion() < Version(3, 0))
7045 {
7046 return false;
7047 }
7048
7049 switch (target)
7050 {
7051 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7052 case GL_UNIFORM_BUFFER_BINDING:
7053 {
7054 *type = GL_INT;
7055 *numParams = 1;
7056 return true;
7057 }
7058 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7059 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7060 case GL_UNIFORM_BUFFER_START:
7061 case GL_UNIFORM_BUFFER_SIZE:
7062 {
7063 *type = GL_INT_64_ANGLEX;
7064 *numParams = 1;
7065 return true;
7066 }
7067 }
7068
7069 if (getClientVersion() < Version(3, 1))
7070 {
7071 return false;
7072 }
7073
7074 switch (target)
7075 {
7076 case GL_IMAGE_BINDING_LAYERED:
7077 {
7078 *type = GL_BOOL;
7079 *numParams = 1;
7080 return true;
7081 }
7082 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7083 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7084 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7085 case GL_SHADER_STORAGE_BUFFER_BINDING:
7086 case GL_VERTEX_BINDING_BUFFER:
7087 case GL_VERTEX_BINDING_DIVISOR:
7088 case GL_VERTEX_BINDING_OFFSET:
7089 case GL_VERTEX_BINDING_STRIDE:
7090 case GL_SAMPLE_MASK_VALUE:
7091 case GL_IMAGE_BINDING_NAME:
7092 case GL_IMAGE_BINDING_LEVEL:
7093 case GL_IMAGE_BINDING_LAYER:
7094 case GL_IMAGE_BINDING_ACCESS:
7095 case GL_IMAGE_BINDING_FORMAT:
7096 {
7097 *type = GL_INT;
7098 *numParams = 1;
7099 return true;
7100 }
7101 case GL_ATOMIC_COUNTER_BUFFER_START:
7102 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7103 case GL_SHADER_STORAGE_BUFFER_START:
7104 case GL_SHADER_STORAGE_BUFFER_SIZE:
7105 {
7106 *type = GL_INT_64_ANGLEX;
7107 *numParams = 1;
7108 return true;
7109 }
7110 }
7111
7112 return false;
7113}
7114
7115Program *Context::getProgram(GLuint handle) const
7116{
7117 return mState.mShaderPrograms->getProgram(handle);
7118}
7119
7120Shader *Context::getShader(GLuint handle) const
7121{
7122 return mState.mShaderPrograms->getShader(handle);
7123}
7124
7125bool Context::isTextureGenerated(GLuint texture) const
7126{
7127 return mState.mTextures->isHandleGenerated(texture);
7128}
7129
7130bool Context::isBufferGenerated(GLuint buffer) const
7131{
7132 return mState.mBuffers->isHandleGenerated(buffer);
7133}
7134
7135bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7136{
7137 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7138}
7139
7140bool Context::isFramebufferGenerated(GLuint framebuffer) const
7141{
7142 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7143}
7144
7145bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7146{
7147 return mState.mPipelines->isHandleGenerated(pipeline);
7148}
7149
7150bool Context::usingDisplayTextureShareGroup() const
7151{
7152 return mDisplayTextureShareGroup;
7153}
7154
7155GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7156{
7157 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7158 internalformat == GL_DEPTH_STENCIL
7159 ? GL_DEPTH24_STENCIL8
7160 : internalformat;
7161}
7162
Jamie Madillc29968b2016-01-20 11:17:23 -05007163} // namespace gl