blob: 01e58f68414ae2fb7d0147fc97cbfd14ce0cb910 [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
James Darpinian4d9d4832018-03-13 12:43:28 -0700661void Context::deleteBuffer(GLuint bufferName)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000662{
James Darpinian4d9d4832018-03-13 12:43:28 -0700663 Buffer *buffer = mState.mBuffers->getBuffer(bufferName);
664 if (buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000665 {
666 detachBuffer(buffer);
667 }
Jamie Madill893ab082014-05-16 16:56:10 -0400668
James Darpinian4d9d4832018-03-13 12:43:28 -0700669 mState.mBuffers->deleteObject(this, bufferName);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000670}
671
672void Context::deleteShader(GLuint shader)
673{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500674 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000675}
676
677void Context::deleteProgram(GLuint program)
678{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500679 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000680}
681
682void Context::deleteTexture(GLuint texture)
683{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500684 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000685 {
686 detachTexture(texture);
687 }
688
Jamie Madill6c1f6712017-02-14 19:08:04 -0500689 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000690}
691
692void Context::deleteRenderbuffer(GLuint renderbuffer)
693{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500694 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000695 {
696 detachRenderbuffer(renderbuffer);
697 }
Jamie Madill893ab082014-05-16 16:56:10 -0400698
Jamie Madill6c1f6712017-02-14 19:08:04 -0500699 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000700}
701
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400702void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400703{
704 // The spec specifies the underlying Fence object is not deleted until all current
705 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
706 // and since our API is currently designed for being called from a single thread, we can delete
707 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400708 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400709}
710
Yunchao Hea336b902017-08-02 16:05:21 +0800711void Context::deleteProgramPipeline(GLuint pipeline)
712{
713 if (mState.mPipelines->getProgramPipeline(pipeline))
714 {
715 detachProgramPipeline(pipeline);
716 }
717
718 mState.mPipelines->deleteObject(this, pipeline);
719}
720
Sami Väisänene45e53b2016-05-25 10:36:04 +0300721void Context::deletePaths(GLuint first, GLsizei range)
722{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500723 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300724}
725
726bool Context::hasPathData(GLuint path) const
727{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500728 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300729 if (pathObj == nullptr)
730 return false;
731
732 return pathObj->hasPathData();
733}
734
735bool Context::hasPath(GLuint path) const
736{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500737 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300738}
739
740void Context::setPathCommands(GLuint path,
741 GLsizei numCommands,
742 const GLubyte *commands,
743 GLsizei numCoords,
744 GLenum coordType,
745 const void *coords)
746{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500747 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300748
749 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
750}
751
Jamie Madill007530e2017-12-28 14:27:04 -0500752void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300753{
Jamie Madill007530e2017-12-28 14:27:04 -0500754 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300755
756 switch (pname)
757 {
758 case GL_PATH_STROKE_WIDTH_CHROMIUM:
759 pathObj->setStrokeWidth(value);
760 break;
761 case GL_PATH_END_CAPS_CHROMIUM:
762 pathObj->setEndCaps(static_cast<GLenum>(value));
763 break;
764 case GL_PATH_JOIN_STYLE_CHROMIUM:
765 pathObj->setJoinStyle(static_cast<GLenum>(value));
766 break;
767 case GL_PATH_MITER_LIMIT_CHROMIUM:
768 pathObj->setMiterLimit(value);
769 break;
770 case GL_PATH_STROKE_BOUND_CHROMIUM:
771 pathObj->setStrokeBound(value);
772 break;
773 default:
774 UNREACHABLE();
775 break;
776 }
777}
778
Jamie Madill007530e2017-12-28 14:27:04 -0500779void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300780{
Jamie Madill007530e2017-12-28 14:27:04 -0500781 // TODO(jmadill): Should use proper clamping/casting.
782 pathParameterf(path, pname, static_cast<GLfloat>(value));
783}
784
785void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
786{
787 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300788
789 switch (pname)
790 {
791 case GL_PATH_STROKE_WIDTH_CHROMIUM:
792 *value = pathObj->getStrokeWidth();
793 break;
794 case GL_PATH_END_CAPS_CHROMIUM:
795 *value = static_cast<GLfloat>(pathObj->getEndCaps());
796 break;
797 case GL_PATH_JOIN_STYLE_CHROMIUM:
798 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
799 break;
800 case GL_PATH_MITER_LIMIT_CHROMIUM:
801 *value = pathObj->getMiterLimit();
802 break;
803 case GL_PATH_STROKE_BOUND_CHROMIUM:
804 *value = pathObj->getStrokeBound();
805 break;
806 default:
807 UNREACHABLE();
808 break;
809 }
810}
811
Jamie Madill007530e2017-12-28 14:27:04 -0500812void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
813{
814 GLfloat val = 0.0f;
815 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
816 if (value)
817 *value = static_cast<GLint>(val);
818}
819
Sami Väisänene45e53b2016-05-25 10:36:04 +0300820void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
821{
822 mGLState.setPathStencilFunc(func, ref, mask);
823}
824
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000825void Context::deleteFramebuffer(GLuint framebuffer)
826{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500827 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000828 {
829 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000830 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500831
Jamie Madill6c1f6712017-02-14 19:08:04 -0500832 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000833}
834
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500835void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000836{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500837 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000838 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500839 GLuint fence = fences[i];
840
841 FenceNV *fenceObject = nullptr;
842 if (mFenceNVMap.erase(fence, &fenceObject))
843 {
844 mFenceNVHandleAllocator.release(fence);
845 delete fenceObject;
846 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000847 }
848}
849
Geoff Lang70d0f492015-12-10 17:45:46 -0500850Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000851{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500852 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000853}
854
Jamie Madill570f7c82014-07-03 10:38:54 -0400855Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000856{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500857 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000858}
859
Geoff Lang70d0f492015-12-10 17:45:46 -0500860Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000861{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500862 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000863}
864
Jamie Madill70b5bb02017-08-28 13:32:37 -0400865Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400866{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400867 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400868}
869
Jamie Madill57a89722013-07-02 11:57:03 -0400870VertexArray *Context::getVertexArray(GLuint handle) const
871{
Jamie Madill96a483b2017-06-27 16:49:21 -0400872 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400873}
874
Jamie Madilldc356042013-07-19 16:36:57 -0400875Sampler *Context::getSampler(GLuint handle) const
876{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500877 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400878}
879
Geoff Langc8058452014-02-03 12:04:11 -0500880TransformFeedback *Context::getTransformFeedback(GLuint handle) const
881{
Jamie Madill96a483b2017-06-27 16:49:21 -0400882 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500883}
884
Yunchao Hea336b902017-08-02 16:05:21 +0800885ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
886{
887 return mState.mPipelines->getProgramPipeline(handle);
888}
889
Geoff Lang70d0f492015-12-10 17:45:46 -0500890LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
891{
892 switch (identifier)
893 {
894 case GL_BUFFER:
895 return getBuffer(name);
896 case GL_SHADER:
897 return getShader(name);
898 case GL_PROGRAM:
899 return getProgram(name);
900 case GL_VERTEX_ARRAY:
901 return getVertexArray(name);
902 case GL_QUERY:
903 return getQuery(name);
904 case GL_TRANSFORM_FEEDBACK:
905 return getTransformFeedback(name);
906 case GL_SAMPLER:
907 return getSampler(name);
908 case GL_TEXTURE:
909 return getTexture(name);
910 case GL_RENDERBUFFER:
911 return getRenderbuffer(name);
912 case GL_FRAMEBUFFER:
913 return getFramebuffer(name);
914 default:
915 UNREACHABLE();
916 return nullptr;
917 }
918}
919
920LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
921{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400922 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500923}
924
Martin Radev9d901792016-07-15 15:58:58 +0300925void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
926{
927 LabeledObject *object = getLabeledObject(identifier, name);
928 ASSERT(object != nullptr);
929
930 std::string labelName = GetObjectLabelFromPointer(length, label);
931 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400932
933 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
934 // specified object is active until we do this.
935 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300936}
937
938void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
939{
940 LabeledObject *object = getLabeledObjectFromPtr(ptr);
941 ASSERT(object != nullptr);
942
943 std::string labelName = GetObjectLabelFromPointer(length, label);
944 object->setLabel(labelName);
945}
946
947void Context::getObjectLabel(GLenum identifier,
948 GLuint name,
949 GLsizei bufSize,
950 GLsizei *length,
951 GLchar *label) const
952{
953 LabeledObject *object = getLabeledObject(identifier, name);
954 ASSERT(object != nullptr);
955
956 const std::string &objectLabel = object->getLabel();
957 GetObjectLabelBase(objectLabel, bufSize, length, label);
958}
959
960void Context::getObjectPtrLabel(const void *ptr,
961 GLsizei bufSize,
962 GLsizei *length,
963 GLchar *label) const
964{
965 LabeledObject *object = getLabeledObjectFromPtr(ptr);
966 ASSERT(object != nullptr);
967
968 const std::string &objectLabel = object->getLabel();
969 GetObjectLabelBase(objectLabel, bufSize, length, label);
970}
971
Jamie Madilldc356042013-07-19 16:36:57 -0400972bool Context::isSampler(GLuint samplerName) const
973{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500974 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400975}
976
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800977void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000978{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500979 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000980
Jamie Madilldedd7b92014-11-05 16:30:36 -0500981 if (handle == 0)
982 {
983 texture = mZeroTextures[target].get();
984 }
985 else
986 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500987 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500988 }
989
990 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400991 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000992}
993
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500994void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000995{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500996 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
997 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700998 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000999}
1000
Jamie Madill5bf9ff42016-02-01 11:13:03 -05001001void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001002{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001003 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
1004 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001005 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001006}
1007
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001008void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001009{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001010 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001011 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001012}
1013
Shao80957d92017-02-20 21:25:59 +08001014void Context::bindVertexBuffer(GLuint bindingIndex,
1015 GLuint bufferHandle,
1016 GLintptr offset,
1017 GLsizei stride)
1018{
1019 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001020 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001021}
1022
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001023void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001024{
Geoff Lang76b10c92014-09-05 16:28:14 -04001025 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001026 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001027 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001028 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001029}
1030
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001031void Context::bindImageTexture(GLuint unit,
1032 GLuint texture,
1033 GLint level,
1034 GLboolean layered,
1035 GLint layer,
1036 GLenum access,
1037 GLenum format)
1038{
1039 Texture *tex = mState.mTextures->getTexture(texture);
1040 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1041}
1042
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001043void Context::useProgram(GLuint program)
1044{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001045 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001046}
1047
Jiajia Qin5451d532017-11-16 17:16:34 +08001048void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1049{
1050 UNIMPLEMENTED();
1051}
1052
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001053void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001054{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001055 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001056 TransformFeedback *transformFeedback =
1057 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001058 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001059}
1060
Yunchao Hea336b902017-08-02 16:05:21 +08001061void Context::bindProgramPipeline(GLuint pipelineHandle)
1062{
1063 ProgramPipeline *pipeline =
1064 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1065 mGLState.setProgramPipelineBinding(this, pipeline);
1066}
1067
Jamie Madillf0e04492017-08-26 15:28:42 -04001068void Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001069{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001070 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001071 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001072
Geoff Lang5aad9672014-09-08 11:10:42 -04001073 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001074 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001075
1076 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001077 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001078}
1079
Jamie Madillf0e04492017-08-26 15:28:42 -04001080void Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001081{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001082 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001083 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001084
Jamie Madillf0e04492017-08-26 15:28:42 -04001085 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001086
Geoff Lang5aad9672014-09-08 11:10:42 -04001087 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001088 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001089}
1090
Jamie Madillf0e04492017-08-26 15:28:42 -04001091void Context::queryCounter(GLuint id, GLenum target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001092{
1093 ASSERT(target == GL_TIMESTAMP_EXT);
1094
1095 Query *queryObject = getQuery(id, true, target);
1096 ASSERT(queryObject);
1097
Jamie Madillf0e04492017-08-26 15:28:42 -04001098 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001099}
1100
1101void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1102{
1103 switch (pname)
1104 {
1105 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001106 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001107 break;
1108 case GL_QUERY_COUNTER_BITS_EXT:
1109 switch (target)
1110 {
1111 case GL_TIME_ELAPSED_EXT:
1112 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1113 break;
1114 case GL_TIMESTAMP_EXT:
1115 params[0] = getExtensions().queryCounterBitsTimestamp;
1116 break;
1117 default:
1118 UNREACHABLE();
1119 params[0] = 0;
1120 break;
1121 }
1122 break;
1123 default:
1124 UNREACHABLE();
1125 return;
1126 }
1127}
1128
Geoff Lang2186c382016-10-14 10:54:54 -04001129void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001130{
Geoff Lang2186c382016-10-14 10:54:54 -04001131 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001132}
1133
Geoff Lang2186c382016-10-14 10:54:54 -04001134void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001135{
Geoff Lang2186c382016-10-14 10:54:54 -04001136 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001137}
1138
Geoff Lang2186c382016-10-14 10:54:54 -04001139void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001140{
Geoff Lang2186c382016-10-14 10:54:54 -04001141 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001142}
1143
Geoff Lang2186c382016-10-14 10:54:54 -04001144void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001145{
Geoff Lang2186c382016-10-14 10:54:54 -04001146 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001147}
1148
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001149Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001150{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001151 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001152}
1153
Jamie Madill2f348d22017-06-05 10:50:59 -04001154FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001155{
Jamie Madill96a483b2017-06-27 16:49:21 -04001156 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001157}
1158
Jamie Madill2f348d22017-06-05 10:50:59 -04001159Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001160{
Jamie Madill96a483b2017-06-27 16:49:21 -04001161 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001162 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001163 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001164 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001165
1166 Query *query = mQueryMap.query(handle);
1167 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001168 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001169 query = new Query(mImplementation->createQuery(type), handle);
1170 query->addRef();
1171 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001172 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001173 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001174}
1175
Geoff Lang70d0f492015-12-10 17:45:46 -05001176Query *Context::getQuery(GLuint handle) const
1177{
Jamie Madill96a483b2017-06-27 16:49:21 -04001178 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001179}
1180
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001181Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001182{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001183 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1184 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001185}
1186
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001187Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001188{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001189 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001190}
1191
Geoff Lang492a7e42014-11-05 13:27:06 -05001192Compiler *Context::getCompiler() const
1193{
Jamie Madill2f348d22017-06-05 10:50:59 -04001194 if (mCompiler.get() == nullptr)
1195 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001196 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001197 }
1198 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001199}
1200
Jamie Madillc1d770e2017-04-13 17:31:24 -04001201void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001202{
1203 switch (pname)
1204 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001205 case GL_SHADER_COMPILER:
1206 *params = GL_TRUE;
1207 break;
1208 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1209 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1210 break;
1211 default:
1212 mGLState.getBooleanv(pname, params);
1213 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001214 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001215}
1216
Jamie Madillc1d770e2017-04-13 17:31:24 -04001217void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001218{
Shannon Woods53a94a82014-06-24 15:20:36 -04001219 // Queries about context capabilities and maximums are answered by Context.
1220 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001221 switch (pname)
1222 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001223 case GL_ALIASED_LINE_WIDTH_RANGE:
1224 params[0] = mCaps.minAliasedLineWidth;
1225 params[1] = mCaps.maxAliasedLineWidth;
1226 break;
1227 case GL_ALIASED_POINT_SIZE_RANGE:
1228 params[0] = mCaps.minAliasedPointSize;
1229 params[1] = mCaps.maxAliasedPointSize;
1230 break;
1231 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1232 ASSERT(mExtensions.textureFilterAnisotropic);
1233 *params = mExtensions.maxTextureAnisotropy;
1234 break;
1235 case GL_MAX_TEXTURE_LOD_BIAS:
1236 *params = mCaps.maxLODBias;
1237 break;
1238
1239 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1240 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1241 {
1242 ASSERT(mExtensions.pathRendering);
1243 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1244 memcpy(params, m, 16 * sizeof(GLfloat));
1245 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001246 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001247
Jamie Madill231c7f52017-04-26 13:45:37 -04001248 default:
1249 mGLState.getFloatv(pname, params);
1250 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001251 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001252}
1253
Jamie Madillc1d770e2017-04-13 17:31:24 -04001254void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001255{
Shannon Woods53a94a82014-06-24 15:20:36 -04001256 // Queries about context capabilities and maximums are answered by Context.
1257 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001258
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001259 switch (pname)
1260 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001261 case GL_MAX_VERTEX_ATTRIBS:
1262 *params = mCaps.maxVertexAttributes;
1263 break;
1264 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1265 *params = mCaps.maxVertexUniformVectors;
1266 break;
1267 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1268 *params = mCaps.maxVertexUniformComponents;
1269 break;
1270 case GL_MAX_VARYING_VECTORS:
1271 *params = mCaps.maxVaryingVectors;
1272 break;
1273 case GL_MAX_VARYING_COMPONENTS:
1274 *params = mCaps.maxVertexOutputComponents;
1275 break;
1276 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1277 *params = mCaps.maxCombinedTextureImageUnits;
1278 break;
1279 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1280 *params = mCaps.maxVertexTextureImageUnits;
1281 break;
1282 case GL_MAX_TEXTURE_IMAGE_UNITS:
1283 *params = mCaps.maxTextureImageUnits;
1284 break;
1285 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1286 *params = mCaps.maxFragmentUniformVectors;
1287 break;
1288 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1289 *params = mCaps.maxFragmentUniformComponents;
1290 break;
1291 case GL_MAX_RENDERBUFFER_SIZE:
1292 *params = mCaps.maxRenderbufferSize;
1293 break;
1294 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1295 *params = mCaps.maxColorAttachments;
1296 break;
1297 case GL_MAX_DRAW_BUFFERS_EXT:
1298 *params = mCaps.maxDrawBuffers;
1299 break;
1300 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1301 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1302 case GL_SUBPIXEL_BITS:
1303 *params = 4;
1304 break;
1305 case GL_MAX_TEXTURE_SIZE:
1306 *params = mCaps.max2DTextureSize;
1307 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001308 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1309 *params = mCaps.maxRectangleTextureSize;
1310 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001311 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1312 *params = mCaps.maxCubeMapTextureSize;
1313 break;
1314 case GL_MAX_3D_TEXTURE_SIZE:
1315 *params = mCaps.max3DTextureSize;
1316 break;
1317 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1318 *params = mCaps.maxArrayTextureLayers;
1319 break;
1320 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1321 *params = mCaps.uniformBufferOffsetAlignment;
1322 break;
1323 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1324 *params = mCaps.maxUniformBufferBindings;
1325 break;
1326 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1327 *params = mCaps.maxVertexUniformBlocks;
1328 break;
1329 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1330 *params = mCaps.maxFragmentUniformBlocks;
1331 break;
1332 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1333 *params = mCaps.maxCombinedTextureImageUnits;
1334 break;
1335 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1336 *params = mCaps.maxVertexOutputComponents;
1337 break;
1338 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1339 *params = mCaps.maxFragmentInputComponents;
1340 break;
1341 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1342 *params = mCaps.minProgramTexelOffset;
1343 break;
1344 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1345 *params = mCaps.maxProgramTexelOffset;
1346 break;
1347 case GL_MAJOR_VERSION:
1348 *params = getClientVersion().major;
1349 break;
1350 case GL_MINOR_VERSION:
1351 *params = getClientVersion().minor;
1352 break;
1353 case GL_MAX_ELEMENTS_INDICES:
1354 *params = mCaps.maxElementsIndices;
1355 break;
1356 case GL_MAX_ELEMENTS_VERTICES:
1357 *params = mCaps.maxElementsVertices;
1358 break;
1359 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1360 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1361 break;
1362 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1363 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1364 break;
1365 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1366 *params = mCaps.maxTransformFeedbackSeparateComponents;
1367 break;
1368 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1369 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1370 break;
1371 case GL_MAX_SAMPLES_ANGLE:
1372 *params = mCaps.maxSamples;
1373 break;
1374 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001375 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001376 params[0] = mCaps.maxViewportWidth;
1377 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001378 }
1379 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001380 case GL_COMPRESSED_TEXTURE_FORMATS:
1381 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1382 params);
1383 break;
1384 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1385 *params = mResetStrategy;
1386 break;
1387 case GL_NUM_SHADER_BINARY_FORMATS:
1388 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1389 break;
1390 case GL_SHADER_BINARY_FORMATS:
1391 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1392 break;
1393 case GL_NUM_PROGRAM_BINARY_FORMATS:
1394 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1395 break;
1396 case GL_PROGRAM_BINARY_FORMATS:
1397 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1398 break;
1399 case GL_NUM_EXTENSIONS:
1400 *params = static_cast<GLint>(mExtensionStrings.size());
1401 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001402
Jamie Madill231c7f52017-04-26 13:45:37 -04001403 // GL_KHR_debug
1404 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1405 *params = mExtensions.maxDebugMessageLength;
1406 break;
1407 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1408 *params = mExtensions.maxDebugLoggedMessages;
1409 break;
1410 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1411 *params = mExtensions.maxDebugGroupStackDepth;
1412 break;
1413 case GL_MAX_LABEL_LENGTH:
1414 *params = mExtensions.maxLabelLength;
1415 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001416
Martin Radeve5285d22017-07-14 16:23:53 +03001417 // GL_ANGLE_multiview
1418 case GL_MAX_VIEWS_ANGLE:
1419 *params = mExtensions.maxViews;
1420 break;
1421
Jamie Madill231c7f52017-04-26 13:45:37 -04001422 // GL_EXT_disjoint_timer_query
1423 case GL_GPU_DISJOINT_EXT:
1424 *params = mImplementation->getGPUDisjoint();
1425 break;
1426 case GL_MAX_FRAMEBUFFER_WIDTH:
1427 *params = mCaps.maxFramebufferWidth;
1428 break;
1429 case GL_MAX_FRAMEBUFFER_HEIGHT:
1430 *params = mCaps.maxFramebufferHeight;
1431 break;
1432 case GL_MAX_FRAMEBUFFER_SAMPLES:
1433 *params = mCaps.maxFramebufferSamples;
1434 break;
1435 case GL_MAX_SAMPLE_MASK_WORDS:
1436 *params = mCaps.maxSampleMaskWords;
1437 break;
1438 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1439 *params = mCaps.maxColorTextureSamples;
1440 break;
1441 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1442 *params = mCaps.maxDepthTextureSamples;
1443 break;
1444 case GL_MAX_INTEGER_SAMPLES:
1445 *params = mCaps.maxIntegerSamples;
1446 break;
1447 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1448 *params = mCaps.maxVertexAttribRelativeOffset;
1449 break;
1450 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1451 *params = mCaps.maxVertexAttribBindings;
1452 break;
1453 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1454 *params = mCaps.maxVertexAttribStride;
1455 break;
1456 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1457 *params = mCaps.maxVertexAtomicCounterBuffers;
1458 break;
1459 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1460 *params = mCaps.maxVertexAtomicCounters;
1461 break;
1462 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1463 *params = mCaps.maxVertexImageUniforms;
1464 break;
1465 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1466 *params = mCaps.maxVertexShaderStorageBlocks;
1467 break;
1468 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1469 *params = mCaps.maxFragmentAtomicCounterBuffers;
1470 break;
1471 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1472 *params = mCaps.maxFragmentAtomicCounters;
1473 break;
1474 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1475 *params = mCaps.maxFragmentImageUniforms;
1476 break;
1477 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1478 *params = mCaps.maxFragmentShaderStorageBlocks;
1479 break;
1480 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1481 *params = mCaps.minProgramTextureGatherOffset;
1482 break;
1483 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1484 *params = mCaps.maxProgramTextureGatherOffset;
1485 break;
1486 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1487 *params = mCaps.maxComputeWorkGroupInvocations;
1488 break;
1489 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1490 *params = mCaps.maxComputeUniformBlocks;
1491 break;
1492 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1493 *params = mCaps.maxComputeTextureImageUnits;
1494 break;
1495 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1496 *params = mCaps.maxComputeSharedMemorySize;
1497 break;
1498 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1499 *params = mCaps.maxComputeUniformComponents;
1500 break;
1501 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1502 *params = mCaps.maxComputeAtomicCounterBuffers;
1503 break;
1504 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1505 *params = mCaps.maxComputeAtomicCounters;
1506 break;
1507 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1508 *params = mCaps.maxComputeImageUniforms;
1509 break;
1510 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1511 *params = mCaps.maxCombinedComputeUniformComponents;
1512 break;
1513 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1514 *params = mCaps.maxComputeShaderStorageBlocks;
1515 break;
1516 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1517 *params = mCaps.maxCombinedShaderOutputResources;
1518 break;
1519 case GL_MAX_UNIFORM_LOCATIONS:
1520 *params = mCaps.maxUniformLocations;
1521 break;
1522 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1523 *params = mCaps.maxAtomicCounterBufferBindings;
1524 break;
1525 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1526 *params = mCaps.maxAtomicCounterBufferSize;
1527 break;
1528 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1529 *params = mCaps.maxCombinedAtomicCounterBuffers;
1530 break;
1531 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1532 *params = mCaps.maxCombinedAtomicCounters;
1533 break;
1534 case GL_MAX_IMAGE_UNITS:
1535 *params = mCaps.maxImageUnits;
1536 break;
1537 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1538 *params = mCaps.maxCombinedImageUniforms;
1539 break;
1540 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1541 *params = mCaps.maxShaderStorageBufferBindings;
1542 break;
1543 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1544 *params = mCaps.maxCombinedShaderStorageBlocks;
1545 break;
1546 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1547 *params = mCaps.shaderStorageBufferOffsetAlignment;
1548 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001549
1550 // GL_EXT_geometry_shader
1551 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1552 *params = mCaps.maxFramebufferLayers;
1553 break;
1554 case GL_LAYER_PROVOKING_VERTEX_EXT:
1555 *params = mCaps.layerProvokingVertex;
1556 break;
1557 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1558 *params = mCaps.maxGeometryUniformComponents;
1559 break;
1560 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
1561 *params = mCaps.maxGeometryUniformBlocks;
1562 break;
1563 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1564 *params = mCaps.maxCombinedGeometryUniformComponents;
1565 break;
1566 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1567 *params = mCaps.maxGeometryInputComponents;
1568 break;
1569 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1570 *params = mCaps.maxGeometryOutputComponents;
1571 break;
1572 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1573 *params = mCaps.maxGeometryOutputVertices;
1574 break;
1575 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1576 *params = mCaps.maxGeometryTotalOutputComponents;
1577 break;
1578 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1579 *params = mCaps.maxGeometryShaderInvocations;
1580 break;
1581 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
1582 *params = mCaps.maxGeometryTextureImageUnits;
1583 break;
1584 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
1585 *params = mCaps.maxGeometryAtomicCounterBuffers;
1586 break;
1587 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
1588 *params = mCaps.maxGeometryAtomicCounters;
1589 break;
1590 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
1591 *params = mCaps.maxGeometryImageUniforms;
1592 break;
1593 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
1594 *params = mCaps.maxGeometryShaderStorageBlocks;
1595 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001596 default:
Jamie Madille98b1b52018-03-08 09:47:23 -05001597 handleError(mGLState.getIntegerv(this, pname, params));
Jamie Madill231c7f52017-04-26 13:45:37 -04001598 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001599 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001600}
1601
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001602void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001603{
Shannon Woods53a94a82014-06-24 15:20:36 -04001604 // Queries about context capabilities and maximums are answered by Context.
1605 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001606 switch (pname)
1607 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001608 case GL_MAX_ELEMENT_INDEX:
1609 *params = mCaps.maxElementIndex;
1610 break;
1611 case GL_MAX_UNIFORM_BLOCK_SIZE:
1612 *params = mCaps.maxUniformBlockSize;
1613 break;
1614 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1615 *params = mCaps.maxCombinedVertexUniformComponents;
1616 break;
1617 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1618 *params = mCaps.maxCombinedFragmentUniformComponents;
1619 break;
1620 case GL_MAX_SERVER_WAIT_TIMEOUT:
1621 *params = mCaps.maxServerWaitTimeout;
1622 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001623
Jamie Madill231c7f52017-04-26 13:45:37 -04001624 // GL_EXT_disjoint_timer_query
1625 case GL_TIMESTAMP_EXT:
1626 *params = mImplementation->getTimestamp();
1627 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001628
Jamie Madill231c7f52017-04-26 13:45:37 -04001629 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1630 *params = mCaps.maxShaderStorageBlockSize;
1631 break;
1632 default:
1633 UNREACHABLE();
1634 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001635 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001636}
1637
Geoff Lang70d0f492015-12-10 17:45:46 -05001638void Context::getPointerv(GLenum pname, void **params) const
1639{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001640 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001641}
1642
Martin Radev66fb8202016-07-28 11:45:20 +03001643void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001644{
Shannon Woods53a94a82014-06-24 15:20:36 -04001645 // Queries about context capabilities and maximums are answered by Context.
1646 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001647
1648 GLenum nativeType;
1649 unsigned int numParams;
1650 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1651 ASSERT(queryStatus);
1652
1653 if (nativeType == GL_INT)
1654 {
1655 switch (target)
1656 {
1657 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1658 ASSERT(index < 3u);
1659 *data = mCaps.maxComputeWorkGroupCount[index];
1660 break;
1661 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1662 ASSERT(index < 3u);
1663 *data = mCaps.maxComputeWorkGroupSize[index];
1664 break;
1665 default:
1666 mGLState.getIntegeri_v(target, index, data);
1667 }
1668 }
1669 else
1670 {
1671 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1672 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001673}
1674
Martin Radev66fb8202016-07-28 11:45:20 +03001675void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001676{
Shannon Woods53a94a82014-06-24 15:20:36 -04001677 // Queries about context capabilities and maximums are answered by Context.
1678 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001679
1680 GLenum nativeType;
1681 unsigned int numParams;
1682 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1683 ASSERT(queryStatus);
1684
1685 if (nativeType == GL_INT_64_ANGLEX)
1686 {
1687 mGLState.getInteger64i_v(target, index, data);
1688 }
1689 else
1690 {
1691 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1692 }
1693}
1694
1695void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1696{
1697 // Queries about context capabilities and maximums are answered by Context.
1698 // Queries about current GL state values are answered by State.
1699
1700 GLenum nativeType;
1701 unsigned int numParams;
1702 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1703 ASSERT(queryStatus);
1704
1705 if (nativeType == GL_BOOL)
1706 {
1707 mGLState.getBooleani_v(target, index, data);
1708 }
1709 else
1710 {
1711 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1712 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001713}
1714
Corentin Wallez336129f2017-10-17 15:55:40 -04001715void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001716{
1717 Buffer *buffer = mGLState.getTargetBuffer(target);
1718 QueryBufferParameteriv(buffer, pname, params);
1719}
1720
1721void Context::getFramebufferAttachmentParameteriv(GLenum target,
1722 GLenum attachment,
1723 GLenum pname,
1724 GLint *params)
1725{
1726 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001727 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001728}
1729
1730void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1731{
1732 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1733 QueryRenderbufferiv(this, renderbuffer, pname, params);
1734}
1735
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001736void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001737{
1738 Texture *texture = getTargetTexture(target);
1739 QueryTexParameterfv(texture, pname, params);
1740}
1741
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001742void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001743{
1744 Texture *texture = getTargetTexture(target);
1745 QueryTexParameteriv(texture, pname, params);
1746}
Jiajia Qin5451d532017-11-16 17:16:34 +08001747
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001748void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001749{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001750 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001751 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001752}
1753
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001754void Context::getTexLevelParameterfv(TextureTarget target,
1755 GLint level,
1756 GLenum pname,
1757 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001758{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001759 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001760 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001761}
1762
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001763void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08001764{
1765 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001766 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001767 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001768}
1769
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001770void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001771{
1772 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001773 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001774 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001775}
1776
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001777void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08001778{
1779 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001780 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001781 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001782}
1783
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001784void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001785{
1786 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001787 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001788 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001789}
1790
Jamie Madill675fe712016-12-19 13:07:54 -05001791void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001792{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001793 // No-op if zero count
1794 if (count == 0)
1795 {
1796 return;
1797 }
1798
Jamie Madill05b35b22017-10-03 09:01:44 -04001799 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001800 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
1801 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001802}
1803
Jamie Madill675fe712016-12-19 13:07:54 -05001804void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001805{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001806 // No-op if zero count
1807 if (count == 0 || instanceCount == 0)
1808 {
1809 return;
1810 }
1811
Jamie Madill05b35b22017-10-03 09:01:44 -04001812 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001813 ANGLE_CONTEXT_TRY(
1814 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
1815 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
Geoff Langf6db0982015-08-25 13:04:00 -04001816}
1817
Jamie Madill876429b2017-04-20 15:46:24 -04001818void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001819{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001820 // No-op if zero count
1821 if (count == 0)
1822 {
1823 return;
1824 }
1825
Jamie Madill05b35b22017-10-03 09:01:44 -04001826 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001827 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001828}
1829
Jamie Madill675fe712016-12-19 13:07:54 -05001830void Context::drawElementsInstanced(GLenum mode,
1831 GLsizei count,
1832 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001833 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001834 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001835{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001836 // No-op if zero count
1837 if (count == 0 || instances == 0)
1838 {
1839 return;
1840 }
1841
Jamie Madill05b35b22017-10-03 09:01:44 -04001842 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001843 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001844 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001845}
1846
Jamie Madill675fe712016-12-19 13:07:54 -05001847void Context::drawRangeElements(GLenum mode,
1848 GLuint start,
1849 GLuint end,
1850 GLsizei count,
1851 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001852 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001853{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001854 // No-op if zero count
1855 if (count == 0)
1856 {
1857 return;
1858 }
1859
Jamie Madill05b35b22017-10-03 09:01:44 -04001860 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001861 ANGLE_CONTEXT_TRY(
1862 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001863}
1864
Jamie Madill876429b2017-04-20 15:46:24 -04001865void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001866{
Jamie Madill05b35b22017-10-03 09:01:44 -04001867 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001868 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001869}
1870
Jamie Madill876429b2017-04-20 15:46:24 -04001871void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001872{
Jamie Madill05b35b22017-10-03 09:01:44 -04001873 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001874 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001875}
1876
Jamie Madill675fe712016-12-19 13:07:54 -05001877void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001878{
Jamie Madillafa02a22017-11-23 12:57:38 -05001879 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05001880}
1881
Jamie Madill675fe712016-12-19 13:07:54 -05001882void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001883{
Jamie Madillafa02a22017-11-23 12:57:38 -05001884 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001885}
1886
Austin Kinross6ee1e782015-05-29 17:05:37 -07001887void Context::insertEventMarker(GLsizei length, const char *marker)
1888{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001889 ASSERT(mImplementation);
1890 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001891}
1892
1893void Context::pushGroupMarker(GLsizei length, const char *marker)
1894{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001895 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05001896
1897 if (marker == nullptr)
1898 {
1899 // From the EXT_debug_marker spec,
1900 // "If <marker> is null then an empty string is pushed on the stack."
1901 mImplementation->pushGroupMarker(length, "");
1902 }
1903 else
1904 {
1905 mImplementation->pushGroupMarker(length, marker);
1906 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07001907}
1908
1909void Context::popGroupMarker()
1910{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001911 ASSERT(mImplementation);
1912 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001913}
1914
Geoff Langd8605522016-04-13 10:19:12 -04001915void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1916{
1917 Program *programObject = getProgram(program);
1918 ASSERT(programObject);
1919
1920 programObject->bindUniformLocation(location, name);
1921}
1922
Sami Väisänena797e062016-05-12 15:23:40 +03001923void Context::setCoverageModulation(GLenum components)
1924{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001925 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001926}
1927
Sami Väisänene45e53b2016-05-25 10:36:04 +03001928void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1929{
1930 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1931}
1932
1933void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1934{
1935 GLfloat I[16];
1936 angle::Matrix<GLfloat>::setToIdentity(I);
1937
1938 mGLState.loadPathRenderingMatrix(matrixMode, I);
1939}
1940
1941void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1942{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001943 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001944 if (!pathObj)
1945 return;
1946
1947 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05001948 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001949
1950 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1951}
1952
1953void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1954{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001955 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001956 if (!pathObj)
1957 return;
1958
1959 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05001960 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001961
1962 mImplementation->stencilStrokePath(pathObj, reference, mask);
1963}
1964
1965void Context::coverFillPath(GLuint path, GLenum coverMode)
1966{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001967 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001968 if (!pathObj)
1969 return;
1970
1971 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05001972 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001973
1974 mImplementation->coverFillPath(pathObj, coverMode);
1975}
1976
1977void Context::coverStrokePath(GLuint path, GLenum coverMode)
1978{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001979 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001980 if (!pathObj)
1981 return;
1982
1983 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05001984 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001985
1986 mImplementation->coverStrokePath(pathObj, coverMode);
1987}
1988
1989void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1990{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001991 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001992 if (!pathObj)
1993 return;
1994
1995 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05001996 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03001997
1998 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
1999}
2000
2001void Context::stencilThenCoverStrokePath(GLuint path,
2002 GLint reference,
2003 GLuint mask,
2004 GLenum coverMode)
2005{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002006 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002007 if (!pathObj)
2008 return;
2009
2010 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002011 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänene45e53b2016-05-25 10:36:04 +03002012
2013 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2014}
2015
Sami Väisänend59ca052016-06-21 16:10:00 +03002016void Context::coverFillPathInstanced(GLsizei numPaths,
2017 GLenum pathNameType,
2018 const void *paths,
2019 GLuint pathBase,
2020 GLenum coverMode,
2021 GLenum transformType,
2022 const GLfloat *transformValues)
2023{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002024 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002025
2026 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002027 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002028
2029 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2030}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002031
Sami Väisänend59ca052016-06-21 16:10:00 +03002032void Context::coverStrokePathInstanced(GLsizei numPaths,
2033 GLenum pathNameType,
2034 const void *paths,
2035 GLuint pathBase,
2036 GLenum coverMode,
2037 GLenum transformType,
2038 const GLfloat *transformValues)
2039{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002040 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002041
2042 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002043 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002044
2045 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2046 transformValues);
2047}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002048
Sami Väisänend59ca052016-06-21 16:10:00 +03002049void Context::stencilFillPathInstanced(GLsizei numPaths,
2050 GLenum pathNameType,
2051 const void *paths,
2052 GLuint pathBase,
2053 GLenum fillMode,
2054 GLuint mask,
2055 GLenum transformType,
2056 const GLfloat *transformValues)
2057{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002058 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002059
2060 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002061 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002062
2063 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2064 transformValues);
2065}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002066
Sami Väisänend59ca052016-06-21 16:10:00 +03002067void Context::stencilStrokePathInstanced(GLsizei numPaths,
2068 GLenum pathNameType,
2069 const void *paths,
2070 GLuint pathBase,
2071 GLint reference,
2072 GLuint mask,
2073 GLenum transformType,
2074 const GLfloat *transformValues)
2075{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002076 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002077
2078 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002079 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002080
2081 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2082 transformValues);
2083}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002084
Sami Väisänend59ca052016-06-21 16:10:00 +03002085void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2086 GLenum pathNameType,
2087 const void *paths,
2088 GLuint pathBase,
2089 GLenum fillMode,
2090 GLuint mask,
2091 GLenum coverMode,
2092 GLenum transformType,
2093 const GLfloat *transformValues)
2094{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002095 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002096
2097 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002098 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002099
2100 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2101 transformType, transformValues);
2102}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002103
Sami Väisänend59ca052016-06-21 16:10:00 +03002104void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2105 GLenum pathNameType,
2106 const void *paths,
2107 GLuint pathBase,
2108 GLint reference,
2109 GLuint mask,
2110 GLenum coverMode,
2111 GLenum transformType,
2112 const GLfloat *transformValues)
2113{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002114 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002115
2116 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
Geoff Langa8cb2872018-03-09 16:09:40 -05002117 ANGLE_CONTEXT_TRY(syncState());
Sami Väisänend59ca052016-06-21 16:10:00 +03002118
2119 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2120 transformType, transformValues);
2121}
2122
Sami Väisänen46eaa942016-06-29 10:26:37 +03002123void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2124{
2125 auto *programObject = getProgram(program);
2126
2127 programObject->bindFragmentInputLocation(location, name);
2128}
2129
2130void Context::programPathFragmentInputGen(GLuint program,
2131 GLint location,
2132 GLenum genMode,
2133 GLint components,
2134 const GLfloat *coeffs)
2135{
2136 auto *programObject = getProgram(program);
2137
Jamie Madillbd044ed2017-06-05 12:59:21 -04002138 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002139}
2140
jchen1015015f72017-03-16 13:54:21 +08002141GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2142{
jchen10fd7c3b52017-03-21 15:36:03 +08002143 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002144 return QueryProgramResourceIndex(programObject, programInterface, name);
2145}
2146
jchen10fd7c3b52017-03-21 15:36:03 +08002147void Context::getProgramResourceName(GLuint program,
2148 GLenum programInterface,
2149 GLuint index,
2150 GLsizei bufSize,
2151 GLsizei *length,
2152 GLchar *name)
2153{
2154 const auto *programObject = getProgram(program);
2155 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2156}
2157
jchen10191381f2017-04-11 13:59:04 +08002158GLint Context::getProgramResourceLocation(GLuint program,
2159 GLenum programInterface,
2160 const GLchar *name)
2161{
2162 const auto *programObject = getProgram(program);
2163 return QueryProgramResourceLocation(programObject, programInterface, name);
2164}
2165
jchen10880683b2017-04-12 16:21:55 +08002166void Context::getProgramResourceiv(GLuint program,
2167 GLenum programInterface,
2168 GLuint index,
2169 GLsizei propCount,
2170 const GLenum *props,
2171 GLsizei bufSize,
2172 GLsizei *length,
2173 GLint *params)
2174{
2175 const auto *programObject = getProgram(program);
2176 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2177 length, params);
2178}
2179
jchen10d9cd7b72017-08-30 15:04:25 +08002180void Context::getProgramInterfaceiv(GLuint program,
2181 GLenum programInterface,
2182 GLenum pname,
2183 GLint *params)
2184{
2185 const auto *programObject = getProgram(program);
2186 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2187}
2188
Jamie Madill71c88b32017-09-14 22:20:29 -04002189void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002190{
Geoff Langda5777c2014-07-11 09:52:58 -04002191 if (error.isError())
2192 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002193 GLenum code = error.getCode();
2194 mErrors.insert(code);
2195 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2196 {
2197 markContextLost();
2198 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002199
Geoff Langee6884e2017-11-09 16:51:11 -05002200 ASSERT(!error.getMessage().empty());
2201 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2202 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002203 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002204}
2205
2206// Get one of the recorded errors and clear its flag, if any.
2207// [OpenGL ES 2.0.24] section 2.5 page 13.
2208GLenum Context::getError()
2209{
Geoff Langda5777c2014-07-11 09:52:58 -04002210 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002211 {
Geoff Langda5777c2014-07-11 09:52:58 -04002212 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002213 }
Geoff Langda5777c2014-07-11 09:52:58 -04002214 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002215 {
Geoff Langda5777c2014-07-11 09:52:58 -04002216 GLenum error = *mErrors.begin();
2217 mErrors.erase(mErrors.begin());
2218 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002219 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002220}
2221
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002222// NOTE: this function should not assume that this context is current!
2223void Context::markContextLost()
2224{
2225 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002226 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002227 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002228 mContextLostForced = true;
2229 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002230 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002231}
2232
2233bool Context::isContextLost()
2234{
2235 return mContextLost;
2236}
2237
Jamie Madillfa920eb2018-01-04 11:45:50 -05002238GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002239{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002240 // Even if the application doesn't want to know about resets, we want to know
2241 // as it will allow us to skip all the calls.
2242 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002243 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002244 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002245 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002246 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002247 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002248
2249 // EXT_robustness, section 2.6: If the reset notification behavior is
2250 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2251 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2252 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002253 }
2254
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002255 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2256 // status should be returned at least once, and GL_NO_ERROR should be returned
2257 // once the device has finished resetting.
2258 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002259 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002260 ASSERT(mResetStatus == GL_NO_ERROR);
2261 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002262
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002263 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002264 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002265 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002266 }
2267 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002268 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002269 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002270 // If markContextLost was used to mark the context lost then
2271 // assume that is not recoverable, and continue to report the
2272 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002273 mResetStatus = mImplementation->getResetStatus();
2274 }
Jamie Madill893ab082014-05-16 16:56:10 -04002275
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002276 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002277}
2278
2279bool Context::isResetNotificationEnabled()
2280{
2281 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2282}
2283
Corentin Walleze3b10e82015-05-20 11:06:25 -04002284const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002285{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002286 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002287}
2288
2289EGLenum Context::getClientType() const
2290{
2291 return mClientType;
2292}
2293
2294EGLenum Context::getRenderBuffer() const
2295{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002296 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2297 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002298 {
2299 return EGL_NONE;
2300 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002301
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002302 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002303 ASSERT(backAttachment != nullptr);
2304 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002305}
2306
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002307VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002308{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002309 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002310 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2311 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002312 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002313 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2314 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002315
Jamie Madill96a483b2017-06-27 16:49:21 -04002316 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002317 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002318
2319 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002320}
2321
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002322TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002323{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002324 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002325 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2326 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002327 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002328 transformFeedback =
2329 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002330 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002331 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002332 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002333
2334 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002335}
2336
2337bool Context::isVertexArrayGenerated(GLuint vertexArray)
2338{
Jamie Madill96a483b2017-06-27 16:49:21 -04002339 ASSERT(mVertexArrayMap.contains(0));
2340 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002341}
2342
2343bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2344{
Jamie Madill96a483b2017-06-27 16:49:21 -04002345 ASSERT(mTransformFeedbackMap.contains(0));
2346 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002347}
2348
Shannon Woods53a94a82014-06-24 15:20:36 -04002349void Context::detachTexture(GLuint texture)
2350{
2351 // Simple pass-through to State's detachTexture method, as textures do not require
2352 // allocation map management either here or in the resource manager at detach time.
2353 // Zero textures are held by the Context, and we don't attempt to request them from
2354 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002355 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002356}
2357
James Darpinian4d9d4832018-03-13 12:43:28 -07002358void Context::detachBuffer(Buffer *buffer)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002359{
Yuly Novikov5807a532015-12-03 13:01:22 -05002360 // Simple pass-through to State's detachBuffer method, since
2361 // only buffer attachments to container objects that are bound to the current context
2362 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002363
Yuly Novikov5807a532015-12-03 13:01:22 -05002364 // [OpenGL ES 3.2] section 5.1.2 page 45:
2365 // Attachments to unbound container objects, such as
2366 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2367 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002368 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002369}
2370
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002371void Context::detachFramebuffer(GLuint framebuffer)
2372{
Shannon Woods53a94a82014-06-24 15:20:36 -04002373 // Framebuffer detachment is handled by Context, because 0 is a valid
2374 // Framebuffer object, and a pointer to it must be passed from Context
2375 // to State at binding time.
2376
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002377 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002378 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2379 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2380 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002381
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002382 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002383 {
2384 bindReadFramebuffer(0);
2385 }
2386
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002387 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002388 {
2389 bindDrawFramebuffer(0);
2390 }
2391}
2392
2393void Context::detachRenderbuffer(GLuint renderbuffer)
2394{
Jamie Madilla02315b2017-02-23 14:14:47 -05002395 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002396}
2397
Jamie Madill57a89722013-07-02 11:57:03 -04002398void Context::detachVertexArray(GLuint vertexArray)
2399{
Jamie Madill77a72f62015-04-14 11:18:32 -04002400 // Vertex array detachment is handled by Context, because 0 is a valid
2401 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002402 // binding time.
2403
Jamie Madill57a89722013-07-02 11:57:03 -04002404 // [OpenGL ES 3.0.2] section 2.10 page 43:
2405 // If a vertex array object that is currently bound is deleted, the binding
2406 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002407 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002408 {
2409 bindVertexArray(0);
2410 }
2411}
2412
Geoff Langc8058452014-02-03 12:04:11 -05002413void Context::detachTransformFeedback(GLuint transformFeedback)
2414{
Corentin Walleza2257da2016-04-19 16:43:12 -04002415 // Transform feedback detachment is handled by Context, because 0 is a valid
2416 // transform feedback, and a pointer to it must be passed from Context to State at
2417 // binding time.
2418
2419 // The OpenGL specification doesn't mention what should happen when the currently bound
2420 // transform feedback object is deleted. Since it is a container object, we treat it like
2421 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002422 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002423 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002424 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002425 }
Geoff Langc8058452014-02-03 12:04:11 -05002426}
2427
Jamie Madilldc356042013-07-19 16:36:57 -04002428void Context::detachSampler(GLuint sampler)
2429{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002430 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002431}
2432
Yunchao Hea336b902017-08-02 16:05:21 +08002433void Context::detachProgramPipeline(GLuint pipeline)
2434{
2435 mGLState.detachProgramPipeline(this, pipeline);
2436}
2437
Jamie Madill3ef140a2017-08-26 23:11:21 -04002438void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002439{
Shaodde78e82017-05-22 14:13:27 +08002440 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002441}
2442
Jamie Madille29d1672013-07-19 16:36:57 -04002443void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2444{
Geoff Langc1984ed2016-10-07 12:41:00 -04002445 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002446 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002447 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002448 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002449}
Jamie Madille29d1672013-07-19 16:36:57 -04002450
Geoff Langc1984ed2016-10-07 12:41:00 -04002451void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2452{
2453 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002454 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002455 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002456 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002457}
2458
2459void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2460{
Geoff Langc1984ed2016-10-07 12:41:00 -04002461 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002462 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002463 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002464 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002465}
2466
Geoff Langc1984ed2016-10-07 12:41:00 -04002467void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002468{
Geoff Langc1984ed2016-10-07 12:41:00 -04002469 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002470 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002471 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002472 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002473}
2474
Geoff Langc1984ed2016-10-07 12:41:00 -04002475void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002476{
Geoff Langc1984ed2016-10-07 12:41:00 -04002477 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002478 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002479 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002480 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002481}
Jamie Madill9675b802013-07-19 16:36:59 -04002482
Geoff Langc1984ed2016-10-07 12:41:00 -04002483void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2484{
2485 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002486 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002487 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002488 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002489}
2490
Olli Etuahof0fee072016-03-30 15:11:58 +03002491void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2492{
2493 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002494 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002495}
2496
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002497void Context::initRendererString()
2498{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002499 std::ostringstream rendererString;
2500 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002501 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002502 rendererString << ")";
2503
Geoff Langcec35902014-04-16 10:52:36 -04002504 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002505}
2506
Geoff Langc339c4e2016-11-29 10:37:36 -05002507void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002508{
Geoff Langc339c4e2016-11-29 10:37:36 -05002509 const Version &clientVersion = getClientVersion();
2510
2511 std::ostringstream versionString;
2512 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2513 << ANGLE_VERSION_STRING << ")";
2514 mVersionString = MakeStaticString(versionString.str());
2515
2516 std::ostringstream shadingLanguageVersionString;
2517 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2518 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2519 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2520 << ")";
2521 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002522}
2523
Geoff Langcec35902014-04-16 10:52:36 -04002524void Context::initExtensionStrings()
2525{
Geoff Langc339c4e2016-11-29 10:37:36 -05002526 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2527 std::ostringstream combinedStringStream;
2528 std::copy(strings.begin(), strings.end(),
2529 std::ostream_iterator<const char *>(combinedStringStream, " "));
2530 return MakeStaticString(combinedStringStream.str());
2531 };
2532
2533 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002534 for (const auto &extensionString : mExtensions.getStrings())
2535 {
2536 mExtensionStrings.push_back(MakeStaticString(extensionString));
2537 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002538 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002539
Bryan Bernhart58806562017-01-05 13:09:31 -08002540 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2541
Geoff Langc339c4e2016-11-29 10:37:36 -05002542 mRequestableExtensionStrings.clear();
2543 for (const auto &extensionInfo : GetExtensionInfoMap())
2544 {
2545 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002546 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2547 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002548 {
2549 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2550 }
2551 }
2552 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002553}
2554
Geoff Langc339c4e2016-11-29 10:37:36 -05002555const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002556{
Geoff Langc339c4e2016-11-29 10:37:36 -05002557 switch (name)
2558 {
2559 case GL_VENDOR:
2560 return reinterpret_cast<const GLubyte *>("Google Inc.");
2561
2562 case GL_RENDERER:
2563 return reinterpret_cast<const GLubyte *>(mRendererString);
2564
2565 case GL_VERSION:
2566 return reinterpret_cast<const GLubyte *>(mVersionString);
2567
2568 case GL_SHADING_LANGUAGE_VERSION:
2569 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2570
2571 case GL_EXTENSIONS:
2572 return reinterpret_cast<const GLubyte *>(mExtensionString);
2573
2574 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2575 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2576
2577 default:
2578 UNREACHABLE();
2579 return nullptr;
2580 }
Geoff Langcec35902014-04-16 10:52:36 -04002581}
2582
Geoff Langc339c4e2016-11-29 10:37:36 -05002583const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002584{
Geoff Langc339c4e2016-11-29 10:37:36 -05002585 switch (name)
2586 {
2587 case GL_EXTENSIONS:
2588 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2589
2590 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2591 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2592
2593 default:
2594 UNREACHABLE();
2595 return nullptr;
2596 }
Geoff Langcec35902014-04-16 10:52:36 -04002597}
2598
2599size_t Context::getExtensionStringCount() const
2600{
2601 return mExtensionStrings.size();
2602}
2603
Geoff Lang111a99e2017-10-17 10:58:41 -04002604bool Context::isExtensionRequestable(const char *name)
2605{
2606 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2607 auto extension = extensionInfos.find(name);
2608
2609 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2610 return extension != extensionInfos.end() && extension->second.Requestable &&
2611 nativeExtensions.*(extension->second.ExtensionsMember);
2612}
2613
Geoff Langc339c4e2016-11-29 10:37:36 -05002614void Context::requestExtension(const char *name)
2615{
2616 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2617 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2618 const auto &extension = extensionInfos.at(name);
2619 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002620 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002621
2622 if (mExtensions.*(extension.ExtensionsMember))
2623 {
2624 // Extension already enabled
2625 return;
2626 }
2627
2628 mExtensions.*(extension.ExtensionsMember) = true;
2629 updateCaps();
2630 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002631
Jamie Madill2f348d22017-06-05 10:50:59 -04002632 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2633 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002634
Jamie Madill81c2e252017-09-09 23:32:46 -04002635 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2636 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002637 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002638 for (auto &zeroTexture : mZeroTextures)
2639 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002640 if (zeroTexture.get() != nullptr)
2641 {
2642 zeroTexture->signalDirty(this, InitState::Initialized);
2643 }
Geoff Lang9aded172017-04-05 11:07:56 -04002644 }
2645
2646 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002647}
2648
2649size_t Context::getRequestableExtensionStringCount() const
2650{
2651 return mRequestableExtensionStrings.size();
2652}
2653
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002654void Context::beginTransformFeedback(GLenum primitiveMode)
2655{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002656 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002657 ASSERT(transformFeedback != nullptr);
2658 ASSERT(!transformFeedback->isPaused());
2659
Jamie Madill6c1f6712017-02-14 19:08:04 -05002660 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002661}
2662
2663bool Context::hasActiveTransformFeedback(GLuint program) const
2664{
2665 for (auto pair : mTransformFeedbackMap)
2666 {
2667 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2668 {
2669 return true;
2670 }
2671 }
2672 return false;
2673}
2674
Geoff Langb433e872017-10-05 14:01:47 -04002675void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002676{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002677 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002678
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08002679 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
2680 if (getClientVersion() < Version(2, 0))
2681 {
2682 mCaps.maxMultitextureUnits = 4;
2683 mCaps.maxClipPlanes = 6;
2684 mCaps.maxLights = 8;
2685 mCaps.maxModelviewMatrixStackDepth = 16;
2686 mCaps.maxProjectionMatrixStackDepth = 16;
2687 mCaps.maxTextureMatrixStackDepth = 16;
2688 }
2689
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002690 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002691
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002692 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002693
Geoff Langeb66a6e2016-10-31 13:06:12 -04002694 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002695 {
2696 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002697 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002698 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002699 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002700 mExtensions.multiview = false;
2701 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002702 }
2703
Jiawei Shao89be29a2017-11-06 14:36:45 +08002704 if (getClientVersion() < ES_3_1)
2705 {
2706 // Disable ES3.1+ extensions
2707 mExtensions.geometryShader = false;
2708 }
2709
Geoff Langeb66a6e2016-10-31 13:06:12 -04002710 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002711 {
2712 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002713 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002714 }
2715
Jamie Madill00ed7a12016-05-19 13:13:38 -04002716 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002717 mExtensions.bindUniformLocation = true;
2718 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002719 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002720 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002721 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002722
2723 // Enable the no error extension if the context was created with the flag.
2724 mExtensions.noError = mSkipValidation;
2725
Corentin Wallezccab69d2017-01-27 16:57:15 -05002726 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002727 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002728
Geoff Lang70d0f492015-12-10 17:45:46 -05002729 // Explicitly enable GL_KHR_debug
2730 mExtensions.debug = true;
2731 mExtensions.maxDebugMessageLength = 1024;
2732 mExtensions.maxDebugLoggedMessages = 1024;
2733 mExtensions.maxDebugGroupStackDepth = 1024;
2734 mExtensions.maxLabelLength = 1024;
2735
Geoff Langff5b2d52016-09-07 11:32:23 -04002736 // Explicitly enable GL_ANGLE_robust_client_memory
2737 mExtensions.robustClientMemory = true;
2738
Jamie Madille08a1d32017-03-07 17:24:06 -05002739 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002740 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002741
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002742 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2743 // supports it.
2744 mExtensions.robustBufferAccessBehavior =
2745 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2746
Jamie Madillc43be722017-07-13 16:22:14 -04002747 // Enable the cache control query unconditionally.
2748 mExtensions.programCacheControl = true;
2749
Geoff Lang301d1612014-07-09 10:34:37 -04002750 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002751 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002752
Jamie Madill0f80ed82017-09-19 00:24:56 -04002753 if (getClientVersion() < ES_3_1)
2754 {
2755 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2756 }
2757 else
2758 {
2759 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2760 }
Geoff Lang301d1612014-07-09 10:34:37 -04002761
Jamie Madill0f80ed82017-09-19 00:24:56 -04002762 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2763 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2764 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2765
2766 // Limit textures as well, so we can use fast bitsets with texture bindings.
2767 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2768 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2769 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002770
Jiawei Shaodb342272017-09-27 10:21:45 +08002771 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2772
Geoff Langc287ea62016-09-16 14:46:51 -04002773 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002774 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002775 for (const auto &extensionInfo : GetExtensionInfoMap())
2776 {
2777 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002778 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002779 {
2780 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2781 }
2782 }
2783
2784 // Generate texture caps
2785 updateCaps();
2786}
2787
2788void Context::updateCaps()
2789{
Geoff Lang900013c2014-07-07 11:32:19 -04002790 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002791 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002792
Jamie Madill7b62cf92017-11-02 15:20:49 -04002793 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04002794 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04002795 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04002796 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002797
Geoff Lang0d8b7242015-09-09 14:56:53 -04002798 // Update the format caps based on the client version and extensions.
2799 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2800 // ES3.
2801 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002802 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002803 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002804 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002805 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002806 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002807
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002808 // OpenGL ES does not support multisampling with non-rendererable formats
2809 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002810 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002811 (getClientVersion() < ES_3_1 &&
2812 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002813 {
Geoff Langd87878e2014-09-19 15:42:59 -04002814 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002815 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002816 else
2817 {
2818 // We may have limited the max samples for some required renderbuffer formats due to
2819 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2820 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2821
2822 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2823 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2824 // exception of signed and unsigned integer formats."
2825 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2826 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2827 {
2828 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2829 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2830 }
2831
2832 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2833 if (getClientVersion() >= ES_3_1)
2834 {
2835 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2836 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2837 // the exception that the signed and unsigned integer formats are required only to
2838 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2839 // multisamples, which must be at least one."
2840 if (formatInfo.componentType == GL_INT ||
2841 formatInfo.componentType == GL_UNSIGNED_INT)
2842 {
2843 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2844 }
2845
2846 // GLES 3.1 section 19.3.1.
2847 if (formatCaps.texturable)
2848 {
2849 if (formatInfo.depthBits > 0)
2850 {
2851 mCaps.maxDepthTextureSamples =
2852 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2853 }
2854 else if (formatInfo.redBits > 0)
2855 {
2856 mCaps.maxColorTextureSamples =
2857 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2858 }
2859 }
2860 }
2861 }
Geoff Langd87878e2014-09-19 15:42:59 -04002862
2863 if (formatCaps.texturable && formatInfo.compressed)
2864 {
Geoff Langca271392017-04-05 12:30:00 -04002865 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002866 }
2867
Geoff Langca271392017-04-05 12:30:00 -04002868 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002869 }
Jamie Madill32447362017-06-28 14:53:52 -04002870
2871 // If program binary is disabled, blank out the memory cache pointer.
2872 if (!mImplementation->getNativeExtensions().getProgramBinary)
2873 {
2874 mMemoryProgramCache = nullptr;
2875 }
Corentin Walleze4477002017-12-01 14:39:58 -05002876
2877 // Compute which buffer types are allowed
2878 mValidBufferBindings.reset();
2879 mValidBufferBindings.set(BufferBinding::ElementArray);
2880 mValidBufferBindings.set(BufferBinding::Array);
2881
2882 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
2883 {
2884 mValidBufferBindings.set(BufferBinding::PixelPack);
2885 mValidBufferBindings.set(BufferBinding::PixelUnpack);
2886 }
2887
2888 if (getClientVersion() >= ES_3_0)
2889 {
2890 mValidBufferBindings.set(BufferBinding::CopyRead);
2891 mValidBufferBindings.set(BufferBinding::CopyWrite);
2892 mValidBufferBindings.set(BufferBinding::TransformFeedback);
2893 mValidBufferBindings.set(BufferBinding::Uniform);
2894 }
2895
2896 if (getClientVersion() >= ES_3_1)
2897 {
2898 mValidBufferBindings.set(BufferBinding::AtomicCounter);
2899 mValidBufferBindings.set(BufferBinding::ShaderStorage);
2900 mValidBufferBindings.set(BufferBinding::DrawIndirect);
2901 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
2902 }
Geoff Lang493daf52014-07-03 13:38:44 -04002903}
2904
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002905void Context::initWorkarounds()
2906{
Jamie Madill761b02c2017-06-23 16:27:06 -04002907 // Apply back-end workarounds.
2908 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2909
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002910 // Lose the context upon out of memory error if the application is
2911 // expecting to watch for those events.
2912 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2913}
2914
Jamie Madill05b35b22017-10-03 09:01:44 -04002915Error Context::prepareForDraw()
2916{
Geoff Langa8cb2872018-03-09 16:09:40 -05002917 ANGLE_TRY(syncDirtyObjects());
Jamie Madilla59fc192017-11-02 12:57:58 -04002918
2919 if (isRobustResourceInitEnabled())
2920 {
2921 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
2922 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
2923 }
2924
Geoff Langa8cb2872018-03-09 16:09:40 -05002925 ANGLE_TRY(syncDirtyBits());
Geoff Langd4fff502017-09-22 11:28:28 -04002926 return NoError();
2927}
2928
2929Error Context::prepareForClear(GLbitfield mask)
2930{
Geoff Langa8cb2872018-03-09 16:09:40 -05002931 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04002932 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearAttachmentsInitialized(this, mask));
Geoff Langa8cb2872018-03-09 16:09:40 -05002933 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Geoff Langd4fff502017-09-22 11:28:28 -04002934 return NoError();
2935}
2936
2937Error Context::prepareForClearBuffer(GLenum buffer, GLint drawbuffer)
2938{
Geoff Langa8cb2872018-03-09 16:09:40 -05002939 ANGLE_TRY(syncDirtyObjects(mClearDirtyObjects));
Geoff Langd4fff502017-09-22 11:28:28 -04002940 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureClearBufferAttachmentsInitialized(this, buffer,
2941 drawbuffer));
Geoff Langa8cb2872018-03-09 16:09:40 -05002942 ANGLE_TRY(syncDirtyBits(mClearDirtyBits));
Jamie Madill05b35b22017-10-03 09:01:44 -04002943 return NoError();
2944}
2945
Geoff Langa8cb2872018-03-09 16:09:40 -05002946Error Context::syncState()
Jamie Madill1b94d432015-08-07 13:23:23 -04002947{
Geoff Langa8cb2872018-03-09 16:09:40 -05002948 ANGLE_TRY(syncDirtyObjects());
2949 ANGLE_TRY(syncDirtyBits());
Jamie Madillbc918e72018-03-08 09:47:21 -05002950 return NoError();
Jamie Madill1b94d432015-08-07 13:23:23 -04002951}
2952
Geoff Langa8cb2872018-03-09 16:09:40 -05002953Error Context::syncState(const State::DirtyBits &bitMask, const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002954{
Geoff Langa8cb2872018-03-09 16:09:40 -05002955 ANGLE_TRY(syncDirtyObjects(objectMask));
2956 ANGLE_TRY(syncDirtyBits(bitMask));
Geoff Langd4fff502017-09-22 11:28:28 -04002957 return NoError();
2958}
2959
Geoff Langa8cb2872018-03-09 16:09:40 -05002960Error Context::syncDirtyBits()
Geoff Langd4fff502017-09-22 11:28:28 -04002961{
2962 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
2963 mImplementation->syncState(this, dirtyBits);
2964 mGLState.clearDirtyBits();
2965 return NoError();
2966}
2967
Geoff Langa8cb2872018-03-09 16:09:40 -05002968Error Context::syncDirtyBits(const State::DirtyBits &bitMask)
Geoff Langd4fff502017-09-22 11:28:28 -04002969{
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 Langa8cb2872018-03-09 16:09:40 -05002976Error Context::syncDirtyObjects()
Geoff Langd4fff502017-09-22 11:28:28 -04002977{
2978 return mGLState.syncDirtyObjects(this);
2979}
2980
Geoff Langa8cb2872018-03-09 16:09:40 -05002981Error Context::syncDirtyObjects(const State::DirtyObjects &objectMask)
Geoff Langd4fff502017-09-22 11:28:28 -04002982{
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 Madille98b1b52018-03-08 09:47:23 -05003343 bool complete = false;
3344 ANGLE_CONTEXT_TRY(framebuffer->isComplete(this, &complete));
3345 if (!complete)
Jamie Madillc29968b2016-01-20 11:17:23 -05003346 {
Jamie Madill437fa652016-05-03 15:13:24 -04003347 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003348 }
Jamie Madill437fa652016-05-03 15:13:24 -04003349
Jamie Madill4928b7c2017-06-20 12:57:39 -04003350 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003351}
3352
3353void Context::invalidateSubFramebuffer(GLenum target,
3354 GLsizei numAttachments,
3355 const GLenum *attachments,
3356 GLint x,
3357 GLint y,
3358 GLsizei width,
3359 GLsizei height)
3360{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003361 // Only sync the FBO
Jamie Madillbc918e72018-03-08 09:47:21 -05003362 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, target));
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003363
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003364 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003365 ASSERT(framebuffer);
3366
Jamie Madille98b1b52018-03-08 09:47:23 -05003367 bool complete = false;
3368 ANGLE_CONTEXT_TRY(framebuffer->isComplete(this, &complete));
3369 if (!complete)
Jamie Madillc29968b2016-01-20 11:17:23 -05003370 {
Jamie Madill437fa652016-05-03 15:13:24 -04003371 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003372 }
Jamie Madill437fa652016-05-03 15:13:24 -04003373
3374 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003375 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003376}
3377
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003378void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003379 GLint level,
3380 GLint internalformat,
3381 GLsizei width,
3382 GLsizei height,
3383 GLint border,
3384 GLenum format,
3385 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003386 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003387{
Jamie Madillbc918e72018-03-08 09:47:21 -05003388 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003389
3390 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003391 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003392 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3393 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003394}
3395
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003396void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003397 GLint level,
3398 GLint internalformat,
3399 GLsizei width,
3400 GLsizei height,
3401 GLsizei depth,
3402 GLint border,
3403 GLenum format,
3404 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003405 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003406{
Jamie Madillbc918e72018-03-08 09:47:21 -05003407 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003408
3409 Extents size(width, height, depth);
3410 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003411 handleError(texture->setImage(this, mGLState.getUnpackState(),
3412 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3413 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003414}
3415
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003416void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003417 GLint level,
3418 GLint xoffset,
3419 GLint yoffset,
3420 GLsizei width,
3421 GLsizei height,
3422 GLenum format,
3423 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003424 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003425{
3426 // Zero sized uploads are valid but no-ops
3427 if (width == 0 || height == 0)
3428 {
3429 return;
3430 }
3431
Jamie Madillbc918e72018-03-08 09:47:21 -05003432 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003433
3434 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003435 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003436 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3437 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003438}
3439
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003440void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003441 GLint level,
3442 GLint xoffset,
3443 GLint yoffset,
3444 GLint zoffset,
3445 GLsizei width,
3446 GLsizei height,
3447 GLsizei depth,
3448 GLenum format,
3449 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003450 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003451{
3452 // Zero sized uploads are valid but no-ops
3453 if (width == 0 || height == 0 || depth == 0)
3454 {
3455 return;
3456 }
3457
Jamie Madillbc918e72018-03-08 09:47:21 -05003458 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003459
3460 Box area(xoffset, yoffset, zoffset, width, height, depth);
3461 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003462 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3463 NonCubeTextureTypeToTarget(target), level, area, format, type,
3464 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003465}
3466
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003467void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003468 GLint level,
3469 GLenum internalformat,
3470 GLsizei width,
3471 GLsizei height,
3472 GLint border,
3473 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003474 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003475{
Jamie Madillbc918e72018-03-08 09:47:21 -05003476 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003477
3478 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003479 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003480 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3481 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003482 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003483}
3484
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003485void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003486 GLint level,
3487 GLenum internalformat,
3488 GLsizei width,
3489 GLsizei height,
3490 GLsizei depth,
3491 GLint border,
3492 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003493 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003494{
Jamie Madillbc918e72018-03-08 09:47:21 -05003495 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003496
3497 Extents size(width, height, depth);
3498 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003499 handleError(texture->setCompressedImage(
3500 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3501 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003502}
3503
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003504void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003505 GLint level,
3506 GLint xoffset,
3507 GLint yoffset,
3508 GLsizei width,
3509 GLsizei height,
3510 GLenum format,
3511 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003512 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003513{
Jamie Madillbc918e72018-03-08 09:47:21 -05003514 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003515
3516 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003517 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003518 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3519 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003520 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003521}
3522
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003523void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003524 GLint level,
3525 GLint xoffset,
3526 GLint yoffset,
3527 GLint zoffset,
3528 GLsizei width,
3529 GLsizei height,
3530 GLsizei depth,
3531 GLenum format,
3532 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003533 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003534{
3535 // Zero sized uploads are valid but no-ops
3536 if (width == 0 || height == 0)
3537 {
3538 return;
3539 }
3540
Jamie Madillbc918e72018-03-08 09:47:21 -05003541 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Jamie Madill73a84962016-02-12 09:27:23 -05003542
3543 Box area(xoffset, yoffset, zoffset, width, height, depth);
3544 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003545 handleError(texture->setCompressedSubImage(
3546 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
3547 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003548}
3549
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003550void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003551{
3552 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003553 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003554}
3555
Jamie Madill007530e2017-12-28 14:27:04 -05003556void Context::copyTexture(GLuint sourceId,
3557 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003558 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05003559 GLuint destId,
3560 GLint destLevel,
3561 GLint internalFormat,
3562 GLenum destType,
3563 GLboolean unpackFlipY,
3564 GLboolean unpackPremultiplyAlpha,
3565 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003566{
Jamie Madillbc918e72018-03-08 09:47:21 -05003567 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07003568
3569 gl::Texture *sourceTexture = getTexture(sourceId);
3570 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05003571 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
3572 sourceLevel, ConvertToBool(unpackFlipY),
3573 ConvertToBool(unpackPremultiplyAlpha),
3574 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003575}
3576
Jamie Madill007530e2017-12-28 14:27:04 -05003577void Context::copySubTexture(GLuint sourceId,
3578 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003579 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05003580 GLuint destId,
3581 GLint destLevel,
3582 GLint xoffset,
3583 GLint yoffset,
3584 GLint x,
3585 GLint y,
3586 GLsizei width,
3587 GLsizei height,
3588 GLboolean unpackFlipY,
3589 GLboolean unpackPremultiplyAlpha,
3590 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003591{
3592 // Zero sized copies are valid but no-ops
3593 if (width == 0 || height == 0)
3594 {
3595 return;
3596 }
3597
Jamie Madillbc918e72018-03-08 09:47:21 -05003598 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang97073d12016-04-20 10:42:34 -07003599
3600 gl::Texture *sourceTexture = getTexture(sourceId);
3601 gl::Texture *destTexture = getTexture(destId);
3602 Offset offset(xoffset, yoffset, 0);
3603 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05003604 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
3605 ConvertToBool(unpackFlipY),
3606 ConvertToBool(unpackPremultiplyAlpha),
3607 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003608}
3609
Jamie Madill007530e2017-12-28 14:27:04 -05003610void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07003611{
Jamie Madillbc918e72018-03-08 09:47:21 -05003612 ANGLE_CONTEXT_TRY(syncStateForTexImage());
Geoff Lang47110bf2016-04-20 11:13:22 -07003613
3614 gl::Texture *sourceTexture = getTexture(sourceId);
3615 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003616 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003617}
3618
Corentin Wallez336129f2017-10-17 15:55:40 -04003619void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003620{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003621 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003622 ASSERT(buffer);
3623
Geoff Lang496c02d2016-10-20 11:38:11 -07003624 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003625}
3626
Corentin Wallez336129f2017-10-17 15:55:40 -04003627void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003628{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003629 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003630 ASSERT(buffer);
3631
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003632 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003633 if (error.isError())
3634 {
Jamie Madill437fa652016-05-03 15:13:24 -04003635 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003636 return nullptr;
3637 }
3638
3639 return buffer->getMapPointer();
3640}
3641
Corentin Wallez336129f2017-10-17 15:55:40 -04003642GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003643{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003644 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003645 ASSERT(buffer);
3646
3647 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003648 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003649 if (error.isError())
3650 {
Jamie Madill437fa652016-05-03 15:13:24 -04003651 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003652 return GL_FALSE;
3653 }
3654
3655 return result;
3656}
3657
Corentin Wallez336129f2017-10-17 15:55:40 -04003658void *Context::mapBufferRange(BufferBinding target,
3659 GLintptr offset,
3660 GLsizeiptr length,
3661 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003662{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003663 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003664 ASSERT(buffer);
3665
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003666 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003667 if (error.isError())
3668 {
Jamie Madill437fa652016-05-03 15:13:24 -04003669 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003670 return nullptr;
3671 }
3672
3673 return buffer->getMapPointer();
3674}
3675
Corentin Wallez336129f2017-10-17 15:55:40 -04003676void Context::flushMappedBufferRange(BufferBinding /*target*/,
3677 GLintptr /*offset*/,
3678 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03003679{
3680 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3681}
3682
Jamie Madillbc918e72018-03-08 09:47:21 -05003683Error Context::syncStateForReadPixels()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003684{
Geoff Langa8cb2872018-03-09 16:09:40 -05003685 return syncState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003686}
3687
Jamie Madillbc918e72018-03-08 09:47:21 -05003688Error Context::syncStateForTexImage()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003689{
Geoff Langa8cb2872018-03-09 16:09:40 -05003690 return syncState(mTexImageDirtyBits, mTexImageDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003691}
3692
Jamie Madillbc918e72018-03-08 09:47:21 -05003693Error Context::syncStateForBlit()
Jamie Madillad9f24e2016-02-12 09:27:24 -05003694{
Geoff Langa8cb2872018-03-09 16:09:40 -05003695 return syncState(mBlitDirtyBits, mBlitDirtyObjects);
Jamie Madillad9f24e2016-02-12 09:27:24 -05003696}
3697
Jiajia Qin5451d532017-11-16 17:16:34 +08003698void Context::activeShaderProgram(GLuint pipeline, GLuint program)
3699{
3700 UNIMPLEMENTED();
3701}
3702
Jamie Madillc20ab272016-06-09 07:20:46 -07003703void Context::activeTexture(GLenum texture)
3704{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003705 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003706}
3707
Jamie Madill876429b2017-04-20 15:46:24 -04003708void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003709{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003710 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003711}
3712
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003713void Context::blendEquation(GLenum mode)
3714{
3715 mGLState.setBlendEquation(mode, mode);
3716}
3717
Jamie Madillc20ab272016-06-09 07:20:46 -07003718void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3719{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003720 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003721}
3722
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003723void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3724{
3725 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3726}
3727
Jamie Madillc20ab272016-06-09 07:20:46 -07003728void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3729{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003730 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003731}
3732
Jamie Madill876429b2017-04-20 15:46:24 -04003733void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003734{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003735 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003736}
3737
Jamie Madill876429b2017-04-20 15:46:24 -04003738void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003739{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003740 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003741}
3742
3743void Context::clearStencil(GLint s)
3744{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003745 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003746}
3747
3748void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3749{
Geoff Lang92019432017-11-20 13:09:34 -05003750 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
3751 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003752}
3753
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003754void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003755{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003756 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003757}
3758
3759void Context::depthFunc(GLenum func)
3760{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003761 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003762}
3763
3764void Context::depthMask(GLboolean flag)
3765{
Geoff Lang92019432017-11-20 13:09:34 -05003766 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07003767}
3768
Jamie Madill876429b2017-04-20 15:46:24 -04003769void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003770{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003771 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003772}
3773
3774void Context::disable(GLenum cap)
3775{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003776 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003777}
3778
3779void Context::disableVertexAttribArray(GLuint index)
3780{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003781 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003782}
3783
3784void Context::enable(GLenum cap)
3785{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003786 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003787}
3788
3789void Context::enableVertexAttribArray(GLuint index)
3790{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003791 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003792}
3793
3794void Context::frontFace(GLenum mode)
3795{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003796 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003797}
3798
3799void Context::hint(GLenum target, GLenum mode)
3800{
3801 switch (target)
3802 {
3803 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003804 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003805 break;
3806
3807 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003808 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003809 break;
3810
3811 default:
3812 UNREACHABLE();
3813 return;
3814 }
3815}
3816
3817void Context::lineWidth(GLfloat width)
3818{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003819 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003820}
3821
3822void Context::pixelStorei(GLenum pname, GLint param)
3823{
3824 switch (pname)
3825 {
3826 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003827 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003828 break;
3829
3830 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003831 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003832 break;
3833
3834 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003835 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003836 break;
3837
3838 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003839 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003840 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003841 break;
3842
3843 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003844 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003845 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003846 break;
3847
3848 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003849 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003850 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003851 break;
3852
3853 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003854 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003855 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003856 break;
3857
3858 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003859 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003860 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003861 break;
3862
3863 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003864 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003865 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003866 break;
3867
3868 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003869 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003870 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003871 break;
3872
3873 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003874 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003875 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003876 break;
3877
3878 default:
3879 UNREACHABLE();
3880 return;
3881 }
3882}
3883
3884void Context::polygonOffset(GLfloat factor, GLfloat units)
3885{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003886 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003887}
3888
Jamie Madill876429b2017-04-20 15:46:24 -04003889void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003890{
Geoff Lang92019432017-11-20 13:09:34 -05003891 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07003892}
3893
Jiawei Shaodb342272017-09-27 10:21:45 +08003894void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3895{
3896 mGLState.setSampleMaskParams(maskNumber, mask);
3897}
3898
Jamie Madillc20ab272016-06-09 07:20:46 -07003899void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3900{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003901 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003902}
3903
3904void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3905{
3906 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3907 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003908 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003909 }
3910
3911 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3912 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003913 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003914 }
3915}
3916
3917void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3918{
3919 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3920 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003921 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003922 }
3923
3924 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3925 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003926 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003927 }
3928}
3929
3930void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3931{
3932 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3933 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003934 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003935 }
3936
3937 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3938 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003939 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003940 }
3941}
3942
3943void Context::vertexAttrib1f(GLuint index, GLfloat x)
3944{
3945 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003946 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003947}
3948
3949void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3950{
3951 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003952 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003953}
3954
3955void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3956{
3957 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003958 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003959}
3960
3961void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3962{
3963 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003964 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003965}
3966
3967void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3968{
3969 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003970 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003971}
3972
3973void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3974{
3975 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003976 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003977}
3978
3979void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3980{
3981 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003982 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003983}
3984
3985void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3986{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003987 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003988}
3989
3990void Context::vertexAttribPointer(GLuint index,
3991 GLint size,
3992 GLenum type,
3993 GLboolean normalized,
3994 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003995 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003996{
Corentin Wallez336129f2017-10-17 15:55:40 -04003997 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05003998 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003999}
4000
Shao80957d92017-02-20 21:25:59 +08004001void Context::vertexAttribFormat(GLuint attribIndex,
4002 GLint size,
4003 GLenum type,
4004 GLboolean normalized,
4005 GLuint relativeOffset)
4006{
Geoff Lang92019432017-11-20 13:09:34 -05004007 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08004008 relativeOffset);
4009}
4010
4011void Context::vertexAttribIFormat(GLuint attribIndex,
4012 GLint size,
4013 GLenum type,
4014 GLuint relativeOffset)
4015{
4016 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
4017}
4018
4019void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
4020{
Shaodde78e82017-05-22 14:13:27 +08004021 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08004022}
4023
Jiajia Qin5451d532017-11-16 17:16:34 +08004024void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08004025{
4026 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
4027}
4028
Jamie Madillc20ab272016-06-09 07:20:46 -07004029void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
4030{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004031 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07004032}
4033
4034void Context::vertexAttribIPointer(GLuint index,
4035 GLint size,
4036 GLenum type,
4037 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04004038 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07004039{
Corentin Wallez336129f2017-10-17 15:55:40 -04004040 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
4041 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07004042}
4043
4044void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
4045{
4046 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004047 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004048}
4049
4050void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4051{
4052 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004053 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004054}
4055
4056void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4057{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004058 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004059}
4060
4061void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4062{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004063 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004064}
4065
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004066void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4067{
4068 const VertexAttribCurrentValueData &currentValues =
4069 getGLState().getVertexAttribCurrentValue(index);
4070 const VertexArray *vao = getGLState().getVertexArray();
4071 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4072 currentValues, pname, params);
4073}
4074
4075void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4076{
4077 const VertexAttribCurrentValueData &currentValues =
4078 getGLState().getVertexAttribCurrentValue(index);
4079 const VertexArray *vao = getGLState().getVertexArray();
4080 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4081 currentValues, pname, params);
4082}
4083
4084void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4085{
4086 const VertexAttribCurrentValueData &currentValues =
4087 getGLState().getVertexAttribCurrentValue(index);
4088 const VertexArray *vao = getGLState().getVertexArray();
4089 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4090 currentValues, pname, params);
4091}
4092
4093void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4094{
4095 const VertexAttribCurrentValueData &currentValues =
4096 getGLState().getVertexAttribCurrentValue(index);
4097 const VertexArray *vao = getGLState().getVertexArray();
4098 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4099 currentValues, pname, params);
4100}
4101
Jamie Madill876429b2017-04-20 15:46:24 -04004102void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004103{
4104 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4105 QueryVertexAttribPointerv(attrib, pname, pointer);
4106}
4107
Jamie Madillc20ab272016-06-09 07:20:46 -07004108void Context::debugMessageControl(GLenum source,
4109 GLenum type,
4110 GLenum severity,
4111 GLsizei count,
4112 const GLuint *ids,
4113 GLboolean enabled)
4114{
4115 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004116 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004117 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004118}
4119
4120void Context::debugMessageInsert(GLenum source,
4121 GLenum type,
4122 GLuint id,
4123 GLenum severity,
4124 GLsizei length,
4125 const GLchar *buf)
4126{
4127 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004128 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004129}
4130
4131void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4132{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004133 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004134}
4135
4136GLuint Context::getDebugMessageLog(GLuint count,
4137 GLsizei bufSize,
4138 GLenum *sources,
4139 GLenum *types,
4140 GLuint *ids,
4141 GLenum *severities,
4142 GLsizei *lengths,
4143 GLchar *messageLog)
4144{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004145 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4146 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004147}
4148
4149void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4150{
4151 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004152 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004153 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004154}
4155
4156void Context::popDebugGroup()
4157{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004158 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004159 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004160}
4161
Corentin Wallez336129f2017-10-17 15:55:40 -04004162void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004163{
4164 Buffer *buffer = mGLState.getTargetBuffer(target);
4165 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004166 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004167}
4168
Corentin Wallez336129f2017-10-17 15:55:40 -04004169void Context::bufferSubData(BufferBinding target,
4170 GLintptr offset,
4171 GLsizeiptr size,
4172 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004173{
4174 if (data == nullptr)
4175 {
4176 return;
4177 }
4178
4179 Buffer *buffer = mGLState.getTargetBuffer(target);
4180 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004181 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004182}
4183
Jamie Madillef300b12016-10-07 15:12:09 -04004184void Context::attachShader(GLuint program, GLuint shader)
4185{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004186 Program *programObject = mState.mShaderPrograms->getProgram(program);
4187 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004188 ASSERT(programObject && shaderObject);
4189 programObject->attachShader(shaderObject);
4190}
4191
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004192const Workarounds &Context::getWorkarounds() const
4193{
4194 return mWorkarounds;
4195}
4196
Corentin Wallez336129f2017-10-17 15:55:40 -04004197void Context::copyBufferSubData(BufferBinding readTarget,
4198 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004199 GLintptr readOffset,
4200 GLintptr writeOffset,
4201 GLsizeiptr size)
4202{
4203 // if size is zero, the copy is a successful no-op
4204 if (size == 0)
4205 {
4206 return;
4207 }
4208
4209 // TODO(jmadill): cache these.
4210 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4211 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4212
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004213 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004214}
4215
Jamie Madill01a80ee2016-11-07 12:06:18 -05004216void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4217{
4218 Program *programObject = getProgram(program);
4219 // TODO(jmadill): Re-use this from the validation if possible.
4220 ASSERT(programObject);
4221 programObject->bindAttributeLocation(index, name);
4222}
4223
Corentin Wallez336129f2017-10-17 15:55:40 -04004224void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004225{
Corentin Wallez336129f2017-10-17 15:55:40 -04004226 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4227 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004228}
4229
Corentin Wallez336129f2017-10-17 15:55:40 -04004230void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004231{
4232 bindBufferRange(target, index, buffer, 0, 0);
4233}
4234
Corentin Wallez336129f2017-10-17 15:55:40 -04004235void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004236 GLuint index,
4237 GLuint buffer,
4238 GLintptr offset,
4239 GLsizeiptr size)
4240{
Corentin Wallez336129f2017-10-17 15:55:40 -04004241 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4242 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004243}
4244
Jamie Madill01a80ee2016-11-07 12:06:18 -05004245void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4246{
4247 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4248 {
4249 bindReadFramebuffer(framebuffer);
4250 }
4251
4252 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4253 {
4254 bindDrawFramebuffer(framebuffer);
4255 }
4256}
4257
4258void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4259{
4260 ASSERT(target == GL_RENDERBUFFER);
4261 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004262 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004263 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004264}
4265
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004266void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004267 GLsizei samples,
4268 GLenum internalformat,
4269 GLsizei width,
4270 GLsizei height,
4271 GLboolean fixedsamplelocations)
4272{
4273 Extents size(width, height, 1);
4274 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004275 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4276 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004277}
4278
4279void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4280{
JiangYizhou5b03f472017-01-09 10:22:53 +08004281 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4282 // the sample position should be queried by DRAW_FRAMEBUFFER.
Jamie Madillbc918e72018-03-08 09:47:21 -05004283 ANGLE_CONTEXT_TRY(mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER));
JiangYizhou5b03f472017-01-09 10:22:53 +08004284 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004285
4286 switch (pname)
4287 {
4288 case GL_SAMPLE_POSITION:
4289 handleError(framebuffer->getSamplePosition(index, val));
4290 break;
4291 default:
4292 UNREACHABLE();
4293 }
4294}
4295
Jamie Madille8fb6402017-02-14 17:56:40 -05004296void Context::renderbufferStorage(GLenum target,
4297 GLenum internalformat,
4298 GLsizei width,
4299 GLsizei height)
4300{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004301 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4302 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4303
Jamie Madille8fb6402017-02-14 17:56:40 -05004304 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004305 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004306}
4307
4308void Context::renderbufferStorageMultisample(GLenum target,
4309 GLsizei samples,
4310 GLenum internalformat,
4311 GLsizei width,
4312 GLsizei height)
4313{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004314 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4315 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004316
4317 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004318 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004319 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004320}
4321
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004322void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4323{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004324 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004325 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004326}
4327
JiangYizhoue18e6392017-02-20 10:32:23 +08004328void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4329{
4330 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4331 QueryFramebufferParameteriv(framebuffer, pname, params);
4332}
4333
Jiajia Qin5451d532017-11-16 17:16:34 +08004334void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004335{
4336 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4337 SetFramebufferParameteri(framebuffer, pname, param);
4338}
4339
Jamie Madillb3f26b92017-07-19 15:07:41 -04004340Error Context::getScratchBuffer(size_t requstedSizeBytes,
4341 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004342{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004343 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4344 {
4345 return OutOfMemory() << "Failed to allocate internal buffer.";
4346 }
4347 return NoError();
4348}
4349
4350Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4351 angle::MemoryBuffer **zeroBufferOut) const
4352{
4353 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004354 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004355 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004356 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004357 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004358}
4359
Xinghua Cao10a4d432017-11-28 14:46:26 +08004360Error Context::prepareForDispatch()
4361{
Geoff Langa8cb2872018-03-09 16:09:40 -05004362 ANGLE_TRY(syncState(mComputeDirtyBits, mComputeDirtyObjects));
Xinghua Cao10a4d432017-11-28 14:46:26 +08004363
4364 if (isRobustResourceInitEnabled())
4365 {
4366 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4367 }
4368
4369 return NoError();
4370}
4371
Xinghua Cao2b396592017-03-29 15:36:04 +08004372void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4373{
4374 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4375 {
4376 return;
4377 }
4378
Xinghua Cao10a4d432017-11-28 14:46:26 +08004379 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004380 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004381}
4382
Jiajia Qin5451d532017-11-16 17:16:34 +08004383void Context::dispatchComputeIndirect(GLintptr indirect)
4384{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004385 ANGLE_CONTEXT_TRY(prepareForDispatch());
4386 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004387}
4388
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004389void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004390 GLsizei levels,
4391 GLenum internalFormat,
4392 GLsizei width,
4393 GLsizei height)
4394{
4395 Extents size(width, height, 1);
4396 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004397 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004398}
4399
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004400void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004401 GLsizei levels,
4402 GLenum internalFormat,
4403 GLsizei width,
4404 GLsizei height,
4405 GLsizei depth)
4406{
4407 Extents size(width, height, depth);
4408 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004409 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004410}
4411
Jiajia Qin5451d532017-11-16 17:16:34 +08004412void Context::memoryBarrier(GLbitfield barriers)
4413{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004414 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004415}
4416
4417void Context::memoryBarrierByRegion(GLbitfield barriers)
4418{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004419 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004420}
4421
Jamie Madillc1d770e2017-04-13 17:31:24 -04004422GLenum Context::checkFramebufferStatus(GLenum target)
4423{
4424 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4425 ASSERT(framebuffer);
4426
Jamie Madille98b1b52018-03-08 09:47:23 -05004427 GLenum status = GL_NONE;
4428 Error err = framebuffer->checkStatus(this, &status);
4429 if (err.isError())
4430 {
4431 handleError(err);
4432 return 0;
4433 }
4434 return status;
Jamie Madillc1d770e2017-04-13 17:31:24 -04004435}
4436
4437void Context::compileShader(GLuint shader)
4438{
4439 Shader *shaderObject = GetValidShader(this, shader);
4440 if (!shaderObject)
4441 {
4442 return;
4443 }
4444 shaderObject->compile(this);
4445}
4446
4447void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4448{
4449 for (int i = 0; i < n; i++)
4450 {
4451 deleteBuffer(buffers[i]);
4452 }
4453}
4454
4455void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4456{
4457 for (int i = 0; i < n; i++)
4458 {
4459 if (framebuffers[i] != 0)
4460 {
4461 deleteFramebuffer(framebuffers[i]);
4462 }
4463 }
4464}
4465
4466void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4467{
4468 for (int i = 0; i < n; i++)
4469 {
4470 deleteRenderbuffer(renderbuffers[i]);
4471 }
4472}
4473
4474void Context::deleteTextures(GLsizei n, const GLuint *textures)
4475{
4476 for (int i = 0; i < n; i++)
4477 {
4478 if (textures[i] != 0)
4479 {
4480 deleteTexture(textures[i]);
4481 }
4482 }
4483}
4484
4485void Context::detachShader(GLuint program, GLuint shader)
4486{
4487 Program *programObject = getProgram(program);
4488 ASSERT(programObject);
4489
4490 Shader *shaderObject = getShader(shader);
4491 ASSERT(shaderObject);
4492
4493 programObject->detachShader(this, shaderObject);
4494}
4495
4496void Context::genBuffers(GLsizei n, GLuint *buffers)
4497{
4498 for (int i = 0; i < n; i++)
4499 {
4500 buffers[i] = createBuffer();
4501 }
4502}
4503
4504void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4505{
4506 for (int i = 0; i < n; i++)
4507 {
4508 framebuffers[i] = createFramebuffer();
4509 }
4510}
4511
4512void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4513{
4514 for (int i = 0; i < n; i++)
4515 {
4516 renderbuffers[i] = createRenderbuffer();
4517 }
4518}
4519
4520void Context::genTextures(GLsizei n, GLuint *textures)
4521{
4522 for (int i = 0; i < n; i++)
4523 {
4524 textures[i] = createTexture();
4525 }
4526}
4527
4528void Context::getActiveAttrib(GLuint program,
4529 GLuint index,
4530 GLsizei bufsize,
4531 GLsizei *length,
4532 GLint *size,
4533 GLenum *type,
4534 GLchar *name)
4535{
4536 Program *programObject = getProgram(program);
4537 ASSERT(programObject);
4538 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4539}
4540
4541void Context::getActiveUniform(GLuint program,
4542 GLuint index,
4543 GLsizei bufsize,
4544 GLsizei *length,
4545 GLint *size,
4546 GLenum *type,
4547 GLchar *name)
4548{
4549 Program *programObject = getProgram(program);
4550 ASSERT(programObject);
4551 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4552}
4553
4554void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4555{
4556 Program *programObject = getProgram(program);
4557 ASSERT(programObject);
4558 programObject->getAttachedShaders(maxcount, count, shaders);
4559}
4560
4561GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4562{
4563 Program *programObject = getProgram(program);
4564 ASSERT(programObject);
4565 return programObject->getAttributeLocation(name);
4566}
4567
4568void Context::getBooleanv(GLenum pname, GLboolean *params)
4569{
4570 GLenum nativeType;
4571 unsigned int numParams = 0;
4572 getQueryParameterInfo(pname, &nativeType, &numParams);
4573
4574 if (nativeType == GL_BOOL)
4575 {
4576 getBooleanvImpl(pname, params);
4577 }
4578 else
4579 {
4580 CastStateValues(this, nativeType, pname, numParams, params);
4581 }
4582}
4583
4584void Context::getFloatv(GLenum pname, GLfloat *params)
4585{
4586 GLenum nativeType;
4587 unsigned int numParams = 0;
4588 getQueryParameterInfo(pname, &nativeType, &numParams);
4589
4590 if (nativeType == GL_FLOAT)
4591 {
4592 getFloatvImpl(pname, params);
4593 }
4594 else
4595 {
4596 CastStateValues(this, nativeType, pname, numParams, params);
4597 }
4598}
4599
4600void Context::getIntegerv(GLenum pname, GLint *params)
4601{
4602 GLenum nativeType;
4603 unsigned int numParams = 0;
4604 getQueryParameterInfo(pname, &nativeType, &numParams);
4605
4606 if (nativeType == GL_INT)
4607 {
4608 getIntegervImpl(pname, params);
4609 }
4610 else
4611 {
4612 CastStateValues(this, nativeType, pname, numParams, params);
4613 }
4614}
4615
4616void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4617{
4618 Program *programObject = getProgram(program);
4619 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004620 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004621}
4622
Jiajia Qin5451d532017-11-16 17:16:34 +08004623void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
4624{
4625 UNIMPLEMENTED();
4626}
4627
Jamie Madillbe849e42017-05-02 15:49:00 -04004628void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004629{
4630 Program *programObject = getProgram(program);
4631 ASSERT(programObject);
4632 programObject->getInfoLog(bufsize, length, infolog);
4633}
4634
Jiajia Qin5451d532017-11-16 17:16:34 +08004635void Context::getProgramPipelineInfoLog(GLuint pipeline,
4636 GLsizei bufSize,
4637 GLsizei *length,
4638 GLchar *infoLog)
4639{
4640 UNIMPLEMENTED();
4641}
4642
Jamie Madillc1d770e2017-04-13 17:31:24 -04004643void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4644{
4645 Shader *shaderObject = getShader(shader);
4646 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004647 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004648}
4649
4650void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4651{
4652 Shader *shaderObject = getShader(shader);
4653 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004654 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004655}
4656
4657void Context::getShaderPrecisionFormat(GLenum shadertype,
4658 GLenum precisiontype,
4659 GLint *range,
4660 GLint *precision)
4661{
4662 // TODO(jmadill): Compute shaders.
4663
4664 switch (shadertype)
4665 {
4666 case GL_VERTEX_SHADER:
4667 switch (precisiontype)
4668 {
4669 case GL_LOW_FLOAT:
4670 mCaps.vertexLowpFloat.get(range, precision);
4671 break;
4672 case GL_MEDIUM_FLOAT:
4673 mCaps.vertexMediumpFloat.get(range, precision);
4674 break;
4675 case GL_HIGH_FLOAT:
4676 mCaps.vertexHighpFloat.get(range, precision);
4677 break;
4678
4679 case GL_LOW_INT:
4680 mCaps.vertexLowpInt.get(range, precision);
4681 break;
4682 case GL_MEDIUM_INT:
4683 mCaps.vertexMediumpInt.get(range, precision);
4684 break;
4685 case GL_HIGH_INT:
4686 mCaps.vertexHighpInt.get(range, precision);
4687 break;
4688
4689 default:
4690 UNREACHABLE();
4691 return;
4692 }
4693 break;
4694
4695 case GL_FRAGMENT_SHADER:
4696 switch (precisiontype)
4697 {
4698 case GL_LOW_FLOAT:
4699 mCaps.fragmentLowpFloat.get(range, precision);
4700 break;
4701 case GL_MEDIUM_FLOAT:
4702 mCaps.fragmentMediumpFloat.get(range, precision);
4703 break;
4704 case GL_HIGH_FLOAT:
4705 mCaps.fragmentHighpFloat.get(range, precision);
4706 break;
4707
4708 case GL_LOW_INT:
4709 mCaps.fragmentLowpInt.get(range, precision);
4710 break;
4711 case GL_MEDIUM_INT:
4712 mCaps.fragmentMediumpInt.get(range, precision);
4713 break;
4714 case GL_HIGH_INT:
4715 mCaps.fragmentHighpInt.get(range, precision);
4716 break;
4717
4718 default:
4719 UNREACHABLE();
4720 return;
4721 }
4722 break;
4723
4724 default:
4725 UNREACHABLE();
4726 return;
4727 }
4728}
4729
4730void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4731{
4732 Shader *shaderObject = getShader(shader);
4733 ASSERT(shaderObject);
4734 shaderObject->getSource(bufsize, length, source);
4735}
4736
4737void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4738{
4739 Program *programObject = getProgram(program);
4740 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004741 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004742}
4743
4744void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4745{
4746 Program *programObject = getProgram(program);
4747 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004748 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004749}
4750
4751GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4752{
4753 Program *programObject = getProgram(program);
4754 ASSERT(programObject);
4755 return programObject->getUniformLocation(name);
4756}
4757
4758GLboolean Context::isBuffer(GLuint buffer)
4759{
4760 if (buffer == 0)
4761 {
4762 return GL_FALSE;
4763 }
4764
4765 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4766}
4767
4768GLboolean Context::isEnabled(GLenum cap)
4769{
4770 return mGLState.getEnableFeature(cap);
4771}
4772
4773GLboolean Context::isFramebuffer(GLuint framebuffer)
4774{
4775 if (framebuffer == 0)
4776 {
4777 return GL_FALSE;
4778 }
4779
4780 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4781}
4782
4783GLboolean Context::isProgram(GLuint program)
4784{
4785 if (program == 0)
4786 {
4787 return GL_FALSE;
4788 }
4789
4790 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4791}
4792
4793GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4794{
4795 if (renderbuffer == 0)
4796 {
4797 return GL_FALSE;
4798 }
4799
4800 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4801}
4802
4803GLboolean Context::isShader(GLuint shader)
4804{
4805 if (shader == 0)
4806 {
4807 return GL_FALSE;
4808 }
4809
4810 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4811}
4812
4813GLboolean Context::isTexture(GLuint texture)
4814{
4815 if (texture == 0)
4816 {
4817 return GL_FALSE;
4818 }
4819
4820 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4821}
4822
4823void Context::linkProgram(GLuint program)
4824{
4825 Program *programObject = getProgram(program);
4826 ASSERT(programObject);
4827 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004828 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004829}
4830
4831void Context::releaseShaderCompiler()
4832{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004833 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004834}
4835
4836void Context::shaderBinary(GLsizei n,
4837 const GLuint *shaders,
4838 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004839 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004840 GLsizei length)
4841{
4842 // No binary shader formats are supported.
4843 UNIMPLEMENTED();
4844}
4845
4846void Context::shaderSource(GLuint shader,
4847 GLsizei count,
4848 const GLchar *const *string,
4849 const GLint *length)
4850{
4851 Shader *shaderObject = getShader(shader);
4852 ASSERT(shaderObject);
4853 shaderObject->setSource(count, string, length);
4854}
4855
4856void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4857{
4858 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4859}
4860
4861void Context::stencilMask(GLuint mask)
4862{
4863 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4864}
4865
4866void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4867{
4868 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4869}
4870
4871void Context::uniform1f(GLint location, GLfloat x)
4872{
4873 Program *program = mGLState.getProgram();
4874 program->setUniform1fv(location, 1, &x);
4875}
4876
4877void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4878{
4879 Program *program = mGLState.getProgram();
4880 program->setUniform1fv(location, count, v);
4881}
4882
4883void Context::uniform1i(GLint location, GLint x)
4884{
4885 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004886 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4887 {
4888 mGLState.setObjectDirty(GL_PROGRAM);
4889 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004890}
4891
4892void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4893{
4894 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004895 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4896 {
4897 mGLState.setObjectDirty(GL_PROGRAM);
4898 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004899}
4900
4901void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4902{
4903 GLfloat xy[2] = {x, y};
4904 Program *program = mGLState.getProgram();
4905 program->setUniform2fv(location, 1, xy);
4906}
4907
4908void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4909{
4910 Program *program = mGLState.getProgram();
4911 program->setUniform2fv(location, count, v);
4912}
4913
4914void Context::uniform2i(GLint location, GLint x, GLint y)
4915{
4916 GLint xy[2] = {x, y};
4917 Program *program = mGLState.getProgram();
4918 program->setUniform2iv(location, 1, xy);
4919}
4920
4921void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4922{
4923 Program *program = mGLState.getProgram();
4924 program->setUniform2iv(location, count, v);
4925}
4926
4927void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4928{
4929 GLfloat xyz[3] = {x, y, z};
4930 Program *program = mGLState.getProgram();
4931 program->setUniform3fv(location, 1, xyz);
4932}
4933
4934void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4935{
4936 Program *program = mGLState.getProgram();
4937 program->setUniform3fv(location, count, v);
4938}
4939
4940void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4941{
4942 GLint xyz[3] = {x, y, z};
4943 Program *program = mGLState.getProgram();
4944 program->setUniform3iv(location, 1, xyz);
4945}
4946
4947void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4948{
4949 Program *program = mGLState.getProgram();
4950 program->setUniform3iv(location, count, v);
4951}
4952
4953void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4954{
4955 GLfloat xyzw[4] = {x, y, z, w};
4956 Program *program = mGLState.getProgram();
4957 program->setUniform4fv(location, 1, xyzw);
4958}
4959
4960void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4961{
4962 Program *program = mGLState.getProgram();
4963 program->setUniform4fv(location, count, v);
4964}
4965
4966void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4967{
4968 GLint xyzw[4] = {x, y, z, w};
4969 Program *program = mGLState.getProgram();
4970 program->setUniform4iv(location, 1, xyzw);
4971}
4972
4973void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4974{
4975 Program *program = mGLState.getProgram();
4976 program->setUniform4iv(location, count, v);
4977}
4978
4979void Context::uniformMatrix2fv(GLint location,
4980 GLsizei count,
4981 GLboolean transpose,
4982 const GLfloat *value)
4983{
4984 Program *program = mGLState.getProgram();
4985 program->setUniformMatrix2fv(location, count, transpose, value);
4986}
4987
4988void Context::uniformMatrix3fv(GLint location,
4989 GLsizei count,
4990 GLboolean transpose,
4991 const GLfloat *value)
4992{
4993 Program *program = mGLState.getProgram();
4994 program->setUniformMatrix3fv(location, count, transpose, value);
4995}
4996
4997void Context::uniformMatrix4fv(GLint location,
4998 GLsizei count,
4999 GLboolean transpose,
5000 const GLfloat *value)
5001{
5002 Program *program = mGLState.getProgram();
5003 program->setUniformMatrix4fv(location, count, transpose, value);
5004}
5005
5006void Context::validateProgram(GLuint program)
5007{
5008 Program *programObject = getProgram(program);
5009 ASSERT(programObject);
5010 programObject->validate(mCaps);
5011}
5012
Jiajia Qin5451d532017-11-16 17:16:34 +08005013void Context::validateProgramPipeline(GLuint pipeline)
5014{
5015 UNIMPLEMENTED();
5016}
5017
Jamie Madilld04908b2017-06-09 14:15:35 -04005018void Context::getProgramBinary(GLuint program,
5019 GLsizei bufSize,
5020 GLsizei *length,
5021 GLenum *binaryFormat,
5022 void *binary)
5023{
5024 Program *programObject = getProgram(program);
5025 ASSERT(programObject != nullptr);
5026
5027 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
5028}
5029
5030void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
5031{
5032 Program *programObject = getProgram(program);
5033 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04005034
Jamie Madilld04908b2017-06-09 14:15:35 -04005035 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
5036}
5037
Jamie Madillff325f12017-08-26 15:06:05 -04005038void Context::uniform1ui(GLint location, GLuint v0)
5039{
5040 Program *program = mGLState.getProgram();
5041 program->setUniform1uiv(location, 1, &v0);
5042}
5043
5044void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
5045{
5046 Program *program = mGLState.getProgram();
5047 const GLuint xy[] = {v0, v1};
5048 program->setUniform2uiv(location, 1, xy);
5049}
5050
5051void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
5052{
5053 Program *program = mGLState.getProgram();
5054 const GLuint xyz[] = {v0, v1, v2};
5055 program->setUniform3uiv(location, 1, xyz);
5056}
5057
5058void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5059{
5060 Program *program = mGLState.getProgram();
5061 const GLuint xyzw[] = {v0, v1, v2, v3};
5062 program->setUniform4uiv(location, 1, xyzw);
5063}
5064
5065void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5066{
5067 Program *program = mGLState.getProgram();
5068 program->setUniform1uiv(location, count, value);
5069}
5070void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5071{
5072 Program *program = mGLState.getProgram();
5073 program->setUniform2uiv(location, count, value);
5074}
5075
5076void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5077{
5078 Program *program = mGLState.getProgram();
5079 program->setUniform3uiv(location, count, value);
5080}
5081
5082void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5083{
5084 Program *program = mGLState.getProgram();
5085 program->setUniform4uiv(location, count, value);
5086}
5087
Jamie Madillf0e04492017-08-26 15:28:42 -04005088void Context::genQueries(GLsizei n, GLuint *ids)
5089{
5090 for (GLsizei i = 0; i < n; i++)
5091 {
5092 GLuint handle = mQueryHandleAllocator.allocate();
5093 mQueryMap.assign(handle, nullptr);
5094 ids[i] = handle;
5095 }
5096}
5097
5098void Context::deleteQueries(GLsizei n, const GLuint *ids)
5099{
5100 for (int i = 0; i < n; i++)
5101 {
5102 GLuint query = ids[i];
5103
5104 Query *queryObject = nullptr;
5105 if (mQueryMap.erase(query, &queryObject))
5106 {
5107 mQueryHandleAllocator.release(query);
5108 if (queryObject)
5109 {
5110 queryObject->release(this);
5111 }
5112 }
5113 }
5114}
5115
5116GLboolean Context::isQuery(GLuint id)
5117{
5118 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
5119}
5120
Jamie Madillc8c95812017-08-26 18:40:09 -04005121void Context::uniformMatrix2x3fv(GLint location,
5122 GLsizei count,
5123 GLboolean transpose,
5124 const GLfloat *value)
5125{
5126 Program *program = mGLState.getProgram();
5127 program->setUniformMatrix2x3fv(location, count, transpose, value);
5128}
5129
5130void Context::uniformMatrix3x2fv(GLint location,
5131 GLsizei count,
5132 GLboolean transpose,
5133 const GLfloat *value)
5134{
5135 Program *program = mGLState.getProgram();
5136 program->setUniformMatrix3x2fv(location, count, transpose, value);
5137}
5138
5139void Context::uniformMatrix2x4fv(GLint location,
5140 GLsizei count,
5141 GLboolean transpose,
5142 const GLfloat *value)
5143{
5144 Program *program = mGLState.getProgram();
5145 program->setUniformMatrix2x4fv(location, count, transpose, value);
5146}
5147
5148void Context::uniformMatrix4x2fv(GLint location,
5149 GLsizei count,
5150 GLboolean transpose,
5151 const GLfloat *value)
5152{
5153 Program *program = mGLState.getProgram();
5154 program->setUniformMatrix4x2fv(location, count, transpose, value);
5155}
5156
5157void Context::uniformMatrix3x4fv(GLint location,
5158 GLsizei count,
5159 GLboolean transpose,
5160 const GLfloat *value)
5161{
5162 Program *program = mGLState.getProgram();
5163 program->setUniformMatrix3x4fv(location, count, transpose, value);
5164}
5165
5166void Context::uniformMatrix4x3fv(GLint location,
5167 GLsizei count,
5168 GLboolean transpose,
5169 const GLfloat *value)
5170{
5171 Program *program = mGLState.getProgram();
5172 program->setUniformMatrix4x3fv(location, count, transpose, value);
5173}
5174
Jamie Madilld7576732017-08-26 18:49:50 -04005175void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5176{
5177 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5178 {
5179 GLuint vertexArray = arrays[arrayIndex];
5180
5181 if (arrays[arrayIndex] != 0)
5182 {
5183 VertexArray *vertexArrayObject = nullptr;
5184 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5185 {
5186 if (vertexArrayObject != nullptr)
5187 {
5188 detachVertexArray(vertexArray);
5189 vertexArrayObject->onDestroy(this);
5190 }
5191
5192 mVertexArrayHandleAllocator.release(vertexArray);
5193 }
5194 }
5195 }
5196}
5197
5198void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5199{
5200 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5201 {
5202 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5203 mVertexArrayMap.assign(vertexArray, nullptr);
5204 arrays[arrayIndex] = vertexArray;
5205 }
5206}
5207
5208bool Context::isVertexArray(GLuint array)
5209{
5210 if (array == 0)
5211 {
5212 return GL_FALSE;
5213 }
5214
5215 VertexArray *vao = getVertexArray(array);
5216 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5217}
5218
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005219void Context::endTransformFeedback()
5220{
5221 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5222 transformFeedback->end(this);
5223}
5224
5225void Context::transformFeedbackVaryings(GLuint program,
5226 GLsizei count,
5227 const GLchar *const *varyings,
5228 GLenum bufferMode)
5229{
5230 Program *programObject = getProgram(program);
5231 ASSERT(programObject);
5232 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5233}
5234
5235void Context::getTransformFeedbackVarying(GLuint program,
5236 GLuint index,
5237 GLsizei bufSize,
5238 GLsizei *length,
5239 GLsizei *size,
5240 GLenum *type,
5241 GLchar *name)
5242{
5243 Program *programObject = getProgram(program);
5244 ASSERT(programObject);
5245 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5246}
5247
5248void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5249{
5250 for (int i = 0; i < n; i++)
5251 {
5252 GLuint transformFeedback = ids[i];
5253 if (transformFeedback == 0)
5254 {
5255 continue;
5256 }
5257
5258 TransformFeedback *transformFeedbackObject = nullptr;
5259 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5260 {
5261 if (transformFeedbackObject != nullptr)
5262 {
5263 detachTransformFeedback(transformFeedback);
5264 transformFeedbackObject->release(this);
5265 }
5266
5267 mTransformFeedbackHandleAllocator.release(transformFeedback);
5268 }
5269 }
5270}
5271
5272void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5273{
5274 for (int i = 0; i < n; i++)
5275 {
5276 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5277 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5278 ids[i] = transformFeedback;
5279 }
5280}
5281
5282bool Context::isTransformFeedback(GLuint id)
5283{
5284 if (id == 0)
5285 {
5286 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5287 // returns FALSE
5288 return GL_FALSE;
5289 }
5290
5291 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5292 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5293}
5294
5295void Context::pauseTransformFeedback()
5296{
5297 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5298 transformFeedback->pause();
5299}
5300
5301void Context::resumeTransformFeedback()
5302{
5303 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5304 transformFeedback->resume();
5305}
5306
Jamie Madill12e957f2017-08-26 21:42:26 -04005307void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5308{
5309 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005310 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005311}
5312
5313GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5314{
5315 const Program *programObject = getProgram(program);
5316 return programObject->getFragDataLocation(name);
5317}
5318
5319void Context::getUniformIndices(GLuint program,
5320 GLsizei uniformCount,
5321 const GLchar *const *uniformNames,
5322 GLuint *uniformIndices)
5323{
5324 const Program *programObject = getProgram(program);
5325 if (!programObject->isLinked())
5326 {
5327 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5328 {
5329 uniformIndices[uniformId] = GL_INVALID_INDEX;
5330 }
5331 }
5332 else
5333 {
5334 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5335 {
5336 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5337 }
5338 }
5339}
5340
5341void Context::getActiveUniformsiv(GLuint program,
5342 GLsizei uniformCount,
5343 const GLuint *uniformIndices,
5344 GLenum pname,
5345 GLint *params)
5346{
5347 const Program *programObject = getProgram(program);
5348 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5349 {
5350 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005351 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005352 }
5353}
5354
5355GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5356{
5357 const Program *programObject = getProgram(program);
5358 return programObject->getUniformBlockIndex(uniformBlockName);
5359}
5360
5361void Context::getActiveUniformBlockiv(GLuint program,
5362 GLuint uniformBlockIndex,
5363 GLenum pname,
5364 GLint *params)
5365{
5366 const Program *programObject = getProgram(program);
5367 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5368}
5369
5370void Context::getActiveUniformBlockName(GLuint program,
5371 GLuint uniformBlockIndex,
5372 GLsizei bufSize,
5373 GLsizei *length,
5374 GLchar *uniformBlockName)
5375{
5376 const Program *programObject = getProgram(program);
5377 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5378}
5379
5380void Context::uniformBlockBinding(GLuint program,
5381 GLuint uniformBlockIndex,
5382 GLuint uniformBlockBinding)
5383{
5384 Program *programObject = getProgram(program);
5385 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5386}
5387
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005388GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5389{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005390 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5391 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005392
Jamie Madill70b5bb02017-08-28 13:32:37 -04005393 Sync *syncObject = getSync(syncHandle);
5394 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005395 if (error.isError())
5396 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005397 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005398 handleError(error);
5399 return nullptr;
5400 }
5401
Jamie Madill70b5bb02017-08-28 13:32:37 -04005402 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005403}
5404
5405GLboolean Context::isSync(GLsync sync)
5406{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005407 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005408}
5409
5410GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5411{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005412 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005413
5414 GLenum result = GL_WAIT_FAILED;
5415 handleError(syncObject->clientWait(flags, timeout, &result));
5416 return result;
5417}
5418
5419void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5420{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005421 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005422 handleError(syncObject->serverWait(flags, timeout));
5423}
5424
5425void Context::getInteger64v(GLenum pname, GLint64 *params)
5426{
5427 GLenum nativeType = GL_NONE;
5428 unsigned int numParams = 0;
5429 getQueryParameterInfo(pname, &nativeType, &numParams);
5430
5431 if (nativeType == GL_INT_64_ANGLEX)
5432 {
5433 getInteger64vImpl(pname, params);
5434 }
5435 else
5436 {
5437 CastStateValues(this, nativeType, pname, numParams, params);
5438 }
5439}
5440
Corentin Wallez336129f2017-10-17 15:55:40 -04005441void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04005442{
5443 Buffer *buffer = mGLState.getTargetBuffer(target);
5444 QueryBufferParameteri64v(buffer, pname, params);
5445}
5446
5447void Context::genSamplers(GLsizei count, GLuint *samplers)
5448{
5449 for (int i = 0; i < count; i++)
5450 {
5451 samplers[i] = mState.mSamplers->createSampler();
5452 }
5453}
5454
5455void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5456{
5457 for (int i = 0; i < count; i++)
5458 {
5459 GLuint sampler = samplers[i];
5460
5461 if (mState.mSamplers->getSampler(sampler))
5462 {
5463 detachSampler(sampler);
5464 }
5465
5466 mState.mSamplers->deleteObject(this, sampler);
5467 }
5468}
5469
5470void Context::getInternalformativ(GLenum target,
5471 GLenum internalformat,
5472 GLenum pname,
5473 GLsizei bufSize,
5474 GLint *params)
5475{
5476 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5477 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5478}
5479
Jiajia Qin5451d532017-11-16 17:16:34 +08005480void Context::programUniform1i(GLuint program, GLint location, GLint v0)
5481{
5482 programUniform1iv(program, location, 1, &v0);
5483}
5484
5485void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
5486{
5487 GLint xy[2] = {v0, v1};
5488 programUniform2iv(program, location, 1, xy);
5489}
5490
5491void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
5492{
5493 GLint xyz[3] = {v0, v1, v2};
5494 programUniform3iv(program, location, 1, xyz);
5495}
5496
5497void Context::programUniform4i(GLuint program,
5498 GLint location,
5499 GLint v0,
5500 GLint v1,
5501 GLint v2,
5502 GLint v3)
5503{
5504 GLint xyzw[4] = {v0, v1, v2, v3};
5505 programUniform4iv(program, location, 1, xyzw);
5506}
5507
5508void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
5509{
5510 programUniform1uiv(program, location, 1, &v0);
5511}
5512
5513void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
5514{
5515 GLuint xy[2] = {v0, v1};
5516 programUniform2uiv(program, location, 1, xy);
5517}
5518
5519void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
5520{
5521 GLuint xyz[3] = {v0, v1, v2};
5522 programUniform3uiv(program, location, 1, xyz);
5523}
5524
5525void Context::programUniform4ui(GLuint program,
5526 GLint location,
5527 GLuint v0,
5528 GLuint v1,
5529 GLuint v2,
5530 GLuint v3)
5531{
5532 GLuint xyzw[4] = {v0, v1, v2, v3};
5533 programUniform4uiv(program, location, 1, xyzw);
5534}
5535
5536void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
5537{
5538 programUniform1fv(program, location, 1, &v0);
5539}
5540
5541void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
5542{
5543 GLfloat xy[2] = {v0, v1};
5544 programUniform2fv(program, location, 1, xy);
5545}
5546
5547void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
5548{
5549 GLfloat xyz[3] = {v0, v1, v2};
5550 programUniform3fv(program, location, 1, xyz);
5551}
5552
5553void Context::programUniform4f(GLuint program,
5554 GLint location,
5555 GLfloat v0,
5556 GLfloat v1,
5557 GLfloat v2,
5558 GLfloat v3)
5559{
5560 GLfloat xyzw[4] = {v0, v1, v2, v3};
5561 programUniform4fv(program, location, 1, xyzw);
5562}
5563
Jamie Madill81c2e252017-09-09 23:32:46 -04005564void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5565{
5566 Program *programObject = getProgram(program);
5567 ASSERT(programObject);
5568 if (programObject->setUniform1iv(location, count, value) ==
5569 Program::SetUniformResult::SamplerChanged)
5570 {
5571 mGLState.setObjectDirty(GL_PROGRAM);
5572 }
5573}
5574
Jiajia Qin5451d532017-11-16 17:16:34 +08005575void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5576{
5577 Program *programObject = getProgram(program);
5578 ASSERT(programObject);
5579 programObject->setUniform2iv(location, count, value);
5580}
5581
5582void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5583{
5584 Program *programObject = getProgram(program);
5585 ASSERT(programObject);
5586 programObject->setUniform3iv(location, count, value);
5587}
5588
5589void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5590{
5591 Program *programObject = getProgram(program);
5592 ASSERT(programObject);
5593 programObject->setUniform4iv(location, count, value);
5594}
5595
5596void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5597{
5598 Program *programObject = getProgram(program);
5599 ASSERT(programObject);
5600 programObject->setUniform1uiv(location, count, value);
5601}
5602
5603void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5604{
5605 Program *programObject = getProgram(program);
5606 ASSERT(programObject);
5607 programObject->setUniform2uiv(location, count, value);
5608}
5609
5610void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5611{
5612 Program *programObject = getProgram(program);
5613 ASSERT(programObject);
5614 programObject->setUniform3uiv(location, count, value);
5615}
5616
5617void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5618{
5619 Program *programObject = getProgram(program);
5620 ASSERT(programObject);
5621 programObject->setUniform4uiv(location, count, value);
5622}
5623
5624void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5625{
5626 Program *programObject = getProgram(program);
5627 ASSERT(programObject);
5628 programObject->setUniform1fv(location, count, value);
5629}
5630
5631void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5632{
5633 Program *programObject = getProgram(program);
5634 ASSERT(programObject);
5635 programObject->setUniform2fv(location, count, value);
5636}
5637
5638void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5639{
5640 Program *programObject = getProgram(program);
5641 ASSERT(programObject);
5642 programObject->setUniform3fv(location, count, value);
5643}
5644
5645void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5646{
5647 Program *programObject = getProgram(program);
5648 ASSERT(programObject);
5649 programObject->setUniform4fv(location, count, value);
5650}
5651
5652void Context::programUniformMatrix2fv(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->setUniformMatrix2fv(location, count, transpose, value);
5661}
5662
5663void Context::programUniformMatrix3fv(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->setUniformMatrix3fv(location, count, transpose, value);
5672}
5673
5674void Context::programUniformMatrix4fv(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->setUniformMatrix4fv(location, count, transpose, value);
5683}
5684
5685void Context::programUniformMatrix2x3fv(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->setUniformMatrix2x3fv(location, count, transpose, value);
5694}
5695
5696void Context::programUniformMatrix3x2fv(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->setUniformMatrix3x2fv(location, count, transpose, value);
5705}
5706
5707void Context::programUniformMatrix2x4fv(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->setUniformMatrix2x4fv(location, count, transpose, value);
5716}
5717
5718void Context::programUniformMatrix4x2fv(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->setUniformMatrix4x2fv(location, count, transpose, value);
5727}
5728
5729void Context::programUniformMatrix3x4fv(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->setUniformMatrix3x4fv(location, count, transpose, value);
5738}
5739
5740void Context::programUniformMatrix4x3fv(GLuint program,
5741 GLint location,
5742 GLsizei count,
5743 GLboolean transpose,
5744 const GLfloat *value)
5745{
5746 Program *programObject = getProgram(program);
5747 ASSERT(programObject);
5748 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
5749}
5750
Jamie Madill81c2e252017-09-09 23:32:46 -04005751void Context::onTextureChange(const Texture *texture)
5752{
5753 // Conservatively assume all textures are dirty.
5754 // TODO(jmadill): More fine-grained update.
5755 mGLState.setObjectDirty(GL_TEXTURE);
5756}
5757
James Darpiniane8a93c62018-01-04 18:02:24 -08005758bool Context::isCurrentTransformFeedback(const TransformFeedback *tf) const
5759{
5760 return mGLState.isCurrentTransformFeedback(tf);
5761}
5762bool Context::isCurrentVertexArray(const VertexArray *va) const
5763{
5764 return mGLState.isCurrentVertexArray(va);
5765}
5766
Yunchao Hea336b902017-08-02 16:05:21 +08005767void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5768{
5769 for (int i = 0; i < count; i++)
5770 {
5771 pipelines[i] = createProgramPipeline();
5772 }
5773}
5774
5775void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5776{
5777 for (int i = 0; i < count; i++)
5778 {
5779 if (pipelines[i] != 0)
5780 {
5781 deleteProgramPipeline(pipelines[i]);
5782 }
5783 }
5784}
5785
5786GLboolean Context::isProgramPipeline(GLuint pipeline)
5787{
5788 if (pipeline == 0)
5789 {
5790 return GL_FALSE;
5791 }
5792
5793 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5794}
5795
Jamie Madill2b7bbc22017-12-21 17:30:38 -05005796void Context::finishFenceNV(GLuint fence)
5797{
5798 FenceNV *fenceObject = getFenceNV(fence);
5799
5800 ASSERT(fenceObject && fenceObject->isSet());
5801 handleError(fenceObject->finish());
5802}
5803
5804void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
5805{
5806 FenceNV *fenceObject = getFenceNV(fence);
5807
5808 ASSERT(fenceObject && fenceObject->isSet());
5809
5810 switch (pname)
5811 {
5812 case GL_FENCE_STATUS_NV:
5813 {
5814 // GL_NV_fence spec:
5815 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
5816 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
5817 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
5818 GLboolean status = GL_TRUE;
5819 if (fenceObject->getStatus() != GL_TRUE)
5820 {
5821 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
5822 }
5823 *params = status;
5824 break;
5825 }
5826
5827 case GL_FENCE_CONDITION_NV:
5828 {
5829 *params = static_cast<GLint>(fenceObject->getCondition());
5830 break;
5831 }
5832
5833 default:
5834 UNREACHABLE();
5835 }
5836}
5837
5838void Context::getTranslatedShaderSource(GLuint shader,
5839 GLsizei bufsize,
5840 GLsizei *length,
5841 GLchar *source)
5842{
5843 Shader *shaderObject = getShader(shader);
5844 ASSERT(shaderObject);
5845 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
5846}
5847
5848void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
5849{
5850 Program *programObject = getProgram(program);
5851 ASSERT(programObject);
5852
5853 programObject->getUniformfv(this, location, params);
5854}
5855
5856void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
5857{
5858 Program *programObject = getProgram(program);
5859 ASSERT(programObject);
5860
5861 programObject->getUniformiv(this, location, params);
5862}
5863
5864GLboolean Context::isFenceNV(GLuint fence)
5865{
5866 FenceNV *fenceObject = getFenceNV(fence);
5867
5868 if (fenceObject == nullptr)
5869 {
5870 return GL_FALSE;
5871 }
5872
5873 // GL_NV_fence spec:
5874 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
5875 // existing fence.
5876 return fenceObject->isSet();
5877}
5878
5879void Context::readnPixels(GLint x,
5880 GLint y,
5881 GLsizei width,
5882 GLsizei height,
5883 GLenum format,
5884 GLenum type,
5885 GLsizei bufSize,
5886 void *data)
5887{
5888 return readPixels(x, y, width, height, format, type, data);
5889}
5890
Jamie Madill007530e2017-12-28 14:27:04 -05005891void Context::setFenceNV(GLuint fence, GLenum condition)
5892{
5893 ASSERT(condition == GL_ALL_COMPLETED_NV);
5894
5895 FenceNV *fenceObject = getFenceNV(fence);
5896 ASSERT(fenceObject != nullptr);
5897 handleError(fenceObject->set(condition));
5898}
5899
5900GLboolean Context::testFenceNV(GLuint fence)
5901{
5902 FenceNV *fenceObject = getFenceNV(fence);
5903
5904 ASSERT(fenceObject != nullptr);
5905 ASSERT(fenceObject->isSet() == GL_TRUE);
5906
5907 GLboolean result = GL_TRUE;
5908 Error error = fenceObject->test(&result);
5909 if (error.isError())
5910 {
5911 handleError(error);
5912 return GL_TRUE;
5913 }
5914
5915 return result;
5916}
5917
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005918void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005919{
5920 Texture *texture = getTargetTexture(target);
5921 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005922 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05005923}
5924
Jamie Madillfa920eb2018-01-04 11:45:50 -05005925void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005926{
5927 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
5928 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
5929 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
5930}
5931
Jamie Madillfa920eb2018-01-04 11:45:50 -05005932void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
5933{
5934 UNIMPLEMENTED();
5935}
5936
Geoff Lang2aaa7b42018-01-12 17:17:27 -05005937void Context::alphaFunc(GLenum func, GLfloat ref)
5938{
5939 UNIMPLEMENTED();
5940}
5941
5942void Context::alphaFuncx(GLenum func, GLfixed ref)
5943{
5944 UNIMPLEMENTED();
5945}
5946
5947void Context::clearColorx(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5948{
5949 UNIMPLEMENTED();
5950}
5951
5952void Context::clearDepthx(GLfixed depth)
5953{
5954 UNIMPLEMENTED();
5955}
5956
5957void Context::clientActiveTexture(GLenum texture)
5958{
5959 UNIMPLEMENTED();
5960}
5961
5962void Context::clipPlanef(GLenum p, const GLfloat *eqn)
5963{
5964 UNIMPLEMENTED();
5965}
5966
5967void Context::clipPlanex(GLenum plane, const GLfixed *equation)
5968{
5969 UNIMPLEMENTED();
5970}
5971
5972void Context::color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
5973{
5974 UNIMPLEMENTED();
5975}
5976
5977void Context::color4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
5978{
5979 UNIMPLEMENTED();
5980}
5981
5982void Context::color4x(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5983{
5984 UNIMPLEMENTED();
5985}
5986
5987void Context::colorPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
5988{
5989 UNIMPLEMENTED();
5990}
5991
5992void Context::cullFace(GLenum mode)
5993{
5994 UNIMPLEMENTED();
5995}
5996
5997void Context::depthRangex(GLfixed n, GLfixed f)
5998{
5999 UNIMPLEMENTED();
6000}
6001
6002void Context::disableClientState(GLenum array)
6003{
6004 UNIMPLEMENTED();
6005}
6006
6007void Context::enableClientState(GLenum array)
6008{
6009 UNIMPLEMENTED();
6010}
6011
6012void Context::fogf(GLenum pname, GLfloat param)
6013{
6014 UNIMPLEMENTED();
6015}
6016
6017void Context::fogfv(GLenum pname, const GLfloat *params)
6018{
6019 UNIMPLEMENTED();
6020}
6021
6022void Context::fogx(GLenum pname, GLfixed param)
6023{
6024 UNIMPLEMENTED();
6025}
6026
6027void Context::fogxv(GLenum pname, const GLfixed *param)
6028{
6029 UNIMPLEMENTED();
6030}
6031
6032void Context::frustumf(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
6033{
6034 UNIMPLEMENTED();
6035}
6036
6037void Context::frustumx(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
6038{
6039 UNIMPLEMENTED();
6040}
6041
6042void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
6043{
6044 UNIMPLEMENTED();
6045}
6046
6047void Context::getClipPlanef(GLenum plane, GLfloat *equation)
6048{
6049 UNIMPLEMENTED();
6050}
6051
6052void Context::getClipPlanex(GLenum plane, GLfixed *equation)
6053{
6054 UNIMPLEMENTED();
6055}
6056
6057void Context::getFixedv(GLenum pname, GLfixed *params)
6058{
6059 UNIMPLEMENTED();
6060}
6061
6062void Context::getLightfv(GLenum light, GLenum pname, GLfloat *params)
6063{
6064 UNIMPLEMENTED();
6065}
6066
6067void Context::getLightxv(GLenum light, GLenum pname, GLfixed *params)
6068{
6069 UNIMPLEMENTED();
6070}
6071
6072void Context::getMaterialfv(GLenum face, GLenum pname, GLfloat *params)
6073{
6074 UNIMPLEMENTED();
6075}
6076
6077void Context::getMaterialxv(GLenum face, GLenum pname, GLfixed *params)
6078{
6079 UNIMPLEMENTED();
6080}
6081
6082void Context::getTexEnvfv(GLenum target, GLenum pname, GLfloat *params)
6083{
6084 UNIMPLEMENTED();
6085}
6086
6087void Context::getTexEnviv(GLenum target, GLenum pname, GLint *params)
6088{
6089 UNIMPLEMENTED();
6090}
6091
6092void Context::getTexEnvxv(GLenum target, GLenum pname, GLfixed *params)
6093{
6094 UNIMPLEMENTED();
6095}
6096
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006097void Context::getTexParameterxv(TextureType target, GLenum pname, GLfixed *params)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006098{
6099 UNIMPLEMENTED();
6100}
6101
6102void Context::lightModelf(GLenum pname, GLfloat param)
6103{
6104 UNIMPLEMENTED();
6105}
6106
6107void Context::lightModelfv(GLenum pname, const GLfloat *params)
6108{
6109 UNIMPLEMENTED();
6110}
6111
6112void Context::lightModelx(GLenum pname, GLfixed param)
6113{
6114 UNIMPLEMENTED();
6115}
6116
6117void Context::lightModelxv(GLenum pname, const GLfixed *param)
6118{
6119 UNIMPLEMENTED();
6120}
6121
6122void Context::lightf(GLenum light, GLenum pname, GLfloat param)
6123{
6124 UNIMPLEMENTED();
6125}
6126
6127void Context::lightfv(GLenum light, GLenum pname, const GLfloat *params)
6128{
6129 UNIMPLEMENTED();
6130}
6131
6132void Context::lightx(GLenum light, GLenum pname, GLfixed param)
6133{
6134 UNIMPLEMENTED();
6135}
6136
6137void Context::lightxv(GLenum light, GLenum pname, const GLfixed *params)
6138{
6139 UNIMPLEMENTED();
6140}
6141
6142void Context::lineWidthx(GLfixed width)
6143{
6144 UNIMPLEMENTED();
6145}
6146
6147void Context::loadIdentity()
6148{
6149 UNIMPLEMENTED();
6150}
6151
6152void Context::loadMatrixf(const GLfloat *m)
6153{
6154 UNIMPLEMENTED();
6155}
6156
6157void Context::loadMatrixx(const GLfixed *m)
6158{
6159 UNIMPLEMENTED();
6160}
6161
6162void Context::logicOp(GLenum opcode)
6163{
6164 UNIMPLEMENTED();
6165}
6166
6167void Context::materialf(GLenum face, GLenum pname, GLfloat param)
6168{
6169 UNIMPLEMENTED();
6170}
6171
6172void Context::materialfv(GLenum face, GLenum pname, const GLfloat *params)
6173{
6174 UNIMPLEMENTED();
6175}
6176
6177void Context::materialx(GLenum face, GLenum pname, GLfixed param)
6178{
6179 UNIMPLEMENTED();
6180}
6181
6182void Context::materialxv(GLenum face, GLenum pname, const GLfixed *param)
6183{
6184 UNIMPLEMENTED();
6185}
6186
6187void Context::matrixMode(GLenum mode)
6188{
6189 UNIMPLEMENTED();
6190}
6191
6192void Context::multMatrixf(const GLfloat *m)
6193{
6194 UNIMPLEMENTED();
6195}
6196
6197void Context::multMatrixx(const GLfixed *m)
6198{
6199 UNIMPLEMENTED();
6200}
6201
6202void Context::multiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q)
6203{
6204 UNIMPLEMENTED();
6205}
6206
6207void Context::multiTexCoord4x(GLenum texture, GLfixed s, GLfixed t, GLfixed r, GLfixed q)
6208{
6209 UNIMPLEMENTED();
6210}
6211
6212void Context::normal3f(GLfloat nx, GLfloat ny, GLfloat nz)
6213{
6214 UNIMPLEMENTED();
6215}
6216
6217void Context::normal3x(GLfixed nx, GLfixed ny, GLfixed nz)
6218{
6219 UNIMPLEMENTED();
6220}
6221
6222void Context::normalPointer(GLenum type, GLsizei stride, const void *pointer)
6223{
6224 UNIMPLEMENTED();
6225}
6226
6227void Context::orthof(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
6228{
6229 UNIMPLEMENTED();
6230}
6231
6232void Context::orthox(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
6233{
6234 UNIMPLEMENTED();
6235}
6236
6237void Context::pointParameterf(GLenum pname, GLfloat param)
6238{
6239 UNIMPLEMENTED();
6240}
6241
6242void Context::pointParameterfv(GLenum pname, const GLfloat *params)
6243{
6244 UNIMPLEMENTED();
6245}
6246
6247void Context::pointParameterx(GLenum pname, GLfixed param)
6248{
6249 UNIMPLEMENTED();
6250}
6251
6252void Context::pointParameterxv(GLenum pname, const GLfixed *params)
6253{
6254 UNIMPLEMENTED();
6255}
6256
6257void Context::pointSize(GLfloat size)
6258{
6259 UNIMPLEMENTED();
6260}
6261
6262void Context::pointSizex(GLfixed size)
6263{
6264 UNIMPLEMENTED();
6265}
6266
6267void Context::polygonOffsetx(GLfixed factor, GLfixed units)
6268{
6269 UNIMPLEMENTED();
6270}
6271
6272void Context::popMatrix()
6273{
6274 UNIMPLEMENTED();
6275}
6276
6277void Context::pushMatrix()
6278{
6279 UNIMPLEMENTED();
6280}
6281
6282void Context::rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
6283{
6284 UNIMPLEMENTED();
6285}
6286
6287void Context::rotatex(GLfixed angle, GLfixed x, GLfixed y, GLfixed z)
6288{
6289 UNIMPLEMENTED();
6290}
6291
6292void Context::sampleCoveragex(GLclampx value, GLboolean invert)
6293{
6294 UNIMPLEMENTED();
6295}
6296
6297void Context::scalef(GLfloat x, GLfloat y, GLfloat z)
6298{
6299 UNIMPLEMENTED();
6300}
6301
6302void Context::scalex(GLfixed x, GLfixed y, GLfixed z)
6303{
6304 UNIMPLEMENTED();
6305}
6306
6307void Context::shadeModel(GLenum mode)
6308{
6309 UNIMPLEMENTED();
6310}
6311
6312void Context::texCoordPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6313{
6314 UNIMPLEMENTED();
6315}
6316
6317void Context::texEnvf(GLenum target, GLenum pname, GLfloat param)
6318{
6319 UNIMPLEMENTED();
6320}
6321
6322void Context::texEnvfv(GLenum target, GLenum pname, const GLfloat *params)
6323{
6324 UNIMPLEMENTED();
6325}
6326
6327void Context::texEnvi(GLenum target, GLenum pname, GLint param)
6328{
6329 UNIMPLEMENTED();
6330}
6331
6332void Context::texEnviv(GLenum target, GLenum pname, const GLint *params)
6333{
6334 UNIMPLEMENTED();
6335}
6336
6337void Context::texEnvx(GLenum target, GLenum pname, GLfixed param)
6338{
6339 UNIMPLEMENTED();
6340}
6341
6342void Context::texEnvxv(GLenum target, GLenum pname, const GLfixed *params)
6343{
6344 UNIMPLEMENTED();
6345}
6346
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006347void Context::texParameterx(TextureType target, GLenum pname, GLfixed param)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006348{
6349 UNIMPLEMENTED();
6350}
6351
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006352void Context::texParameterxv(TextureType target, GLenum pname, const GLfixed *params)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006353{
6354 UNIMPLEMENTED();
6355}
6356
6357void Context::translatef(GLfloat x, GLfloat y, GLfloat z)
6358{
6359 UNIMPLEMENTED();
6360}
6361
6362void Context::translatex(GLfixed x, GLfixed y, GLfixed z)
6363{
6364 UNIMPLEMENTED();
6365}
6366
6367void Context::vertexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6368{
6369 UNIMPLEMENTED();
6370}
6371
6372void Context::drawTexf(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height)
6373{
6374 UNIMPLEMENTED();
6375}
6376
6377void Context::drawTexfv(const GLfloat *coords)
6378{
6379 UNIMPLEMENTED();
6380}
6381
6382void Context::drawTexi(GLint x, GLint y, GLint z, GLint width, GLint height)
6383{
6384 UNIMPLEMENTED();
6385}
6386
6387void Context::drawTexiv(const GLint *coords)
6388{
6389 UNIMPLEMENTED();
6390}
6391
6392void Context::drawTexs(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height)
6393{
6394 UNIMPLEMENTED();
6395}
6396
6397void Context::drawTexsv(const GLshort *coords)
6398{
6399 UNIMPLEMENTED();
6400}
6401
6402void Context::drawTexx(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height)
6403{
6404 UNIMPLEMENTED();
6405}
6406
6407void Context::drawTexxv(const GLfixed *coords)
6408{
6409 UNIMPLEMENTED();
6410}
6411
6412void Context::currentPaletteMatrix(GLuint matrixpaletteindex)
6413{
6414 UNIMPLEMENTED();
6415}
6416
6417void Context::loadPaletteFromModelViewMatrix()
6418{
6419 UNIMPLEMENTED();
6420}
6421
6422void Context::matrixIndexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6423{
6424 UNIMPLEMENTED();
6425}
6426
6427void Context::weightPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6428{
6429 UNIMPLEMENTED();
6430}
6431
6432void Context::pointSizePointer(GLenum type, GLsizei stride, const void *pointer)
6433{
6434 UNIMPLEMENTED();
6435}
6436
6437GLbitfield Context::queryMatrixx(GLfixed *mantissa, GLint *exponent)
6438{
6439 UNIMPLEMENTED();
6440 return 0;
6441}
6442
Jamie Madill5b772312018-03-08 20:28:32 -05006443bool Context::getQueryParameterInfo(GLenum pname, GLenum *type, unsigned int *numParams)
6444{
6445 // Please note: the query type returned for DEPTH_CLEAR_VALUE in this implementation
6446 // is FLOAT rather than INT, as would be suggested by the GL ES 2.0 spec. This is due
6447 // to the fact that it is stored internally as a float, and so would require conversion
6448 // if returned from Context::getIntegerv. Since this conversion is already implemented
6449 // in the case that one calls glGetIntegerv to retrieve a float-typed state variable, we
6450 // place DEPTH_CLEAR_VALUE with the floats. This should make no difference to the calling
6451 // application.
6452 switch (pname)
6453 {
6454 case GL_COMPRESSED_TEXTURE_FORMATS:
6455 {
6456 *type = GL_INT;
6457 *numParams = static_cast<unsigned int>(getCaps().compressedTextureFormats.size());
6458 return true;
6459 }
6460 case GL_SHADER_BINARY_FORMATS:
6461 {
6462 *type = GL_INT;
6463 *numParams = static_cast<unsigned int>(getCaps().shaderBinaryFormats.size());
6464 return true;
6465 }
6466
6467 case GL_MAX_VERTEX_ATTRIBS:
6468 case GL_MAX_VERTEX_UNIFORM_VECTORS:
6469 case GL_MAX_VARYING_VECTORS:
6470 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
6471 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
6472 case GL_MAX_TEXTURE_IMAGE_UNITS:
6473 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
6474 case GL_MAX_RENDERBUFFER_SIZE:
6475 case GL_NUM_SHADER_BINARY_FORMATS:
6476 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
6477 case GL_ARRAY_BUFFER_BINDING:
6478 case GL_FRAMEBUFFER_BINDING:
6479 case GL_RENDERBUFFER_BINDING:
6480 case GL_CURRENT_PROGRAM:
6481 case GL_PACK_ALIGNMENT:
6482 case GL_UNPACK_ALIGNMENT:
6483 case GL_GENERATE_MIPMAP_HINT:
6484 case GL_RED_BITS:
6485 case GL_GREEN_BITS:
6486 case GL_BLUE_BITS:
6487 case GL_ALPHA_BITS:
6488 case GL_DEPTH_BITS:
6489 case GL_STENCIL_BITS:
6490 case GL_ELEMENT_ARRAY_BUFFER_BINDING:
6491 case GL_CULL_FACE_MODE:
6492 case GL_FRONT_FACE:
6493 case GL_ACTIVE_TEXTURE:
6494 case GL_STENCIL_FUNC:
6495 case GL_STENCIL_VALUE_MASK:
6496 case GL_STENCIL_REF:
6497 case GL_STENCIL_FAIL:
6498 case GL_STENCIL_PASS_DEPTH_FAIL:
6499 case GL_STENCIL_PASS_DEPTH_PASS:
6500 case GL_STENCIL_BACK_FUNC:
6501 case GL_STENCIL_BACK_VALUE_MASK:
6502 case GL_STENCIL_BACK_REF:
6503 case GL_STENCIL_BACK_FAIL:
6504 case GL_STENCIL_BACK_PASS_DEPTH_FAIL:
6505 case GL_STENCIL_BACK_PASS_DEPTH_PASS:
6506 case GL_DEPTH_FUNC:
6507 case GL_BLEND_SRC_RGB:
6508 case GL_BLEND_SRC_ALPHA:
6509 case GL_BLEND_DST_RGB:
6510 case GL_BLEND_DST_ALPHA:
6511 case GL_BLEND_EQUATION_RGB:
6512 case GL_BLEND_EQUATION_ALPHA:
6513 case GL_STENCIL_WRITEMASK:
6514 case GL_STENCIL_BACK_WRITEMASK:
6515 case GL_STENCIL_CLEAR_VALUE:
6516 case GL_SUBPIXEL_BITS:
6517 case GL_MAX_TEXTURE_SIZE:
6518 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
6519 case GL_SAMPLE_BUFFERS:
6520 case GL_SAMPLES:
6521 case GL_IMPLEMENTATION_COLOR_READ_TYPE:
6522 case GL_IMPLEMENTATION_COLOR_READ_FORMAT:
6523 case GL_TEXTURE_BINDING_2D:
6524 case GL_TEXTURE_BINDING_CUBE_MAP:
6525 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
6526 {
6527 *type = GL_INT;
6528 *numParams = 1;
6529 return true;
6530 }
6531 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
6532 {
6533 if (!getExtensions().packReverseRowOrder)
6534 {
6535 return false;
6536 }
6537 *type = GL_INT;
6538 *numParams = 1;
6539 return true;
6540 }
6541 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
6542 case GL_TEXTURE_BINDING_RECTANGLE_ANGLE:
6543 {
6544 if (!getExtensions().textureRectangle)
6545 {
6546 return false;
6547 }
6548 *type = GL_INT;
6549 *numParams = 1;
6550 return true;
6551 }
6552 case GL_MAX_DRAW_BUFFERS_EXT:
6553 case GL_MAX_COLOR_ATTACHMENTS_EXT:
6554 {
6555 if ((getClientMajorVersion() < 3) && !getExtensions().drawBuffers)
6556 {
6557 return false;
6558 }
6559 *type = GL_INT;
6560 *numParams = 1;
6561 return true;
6562 }
6563 case GL_MAX_VIEWPORT_DIMS:
6564 {
6565 *type = GL_INT;
6566 *numParams = 2;
6567 return true;
6568 }
6569 case GL_VIEWPORT:
6570 case GL_SCISSOR_BOX:
6571 {
6572 *type = GL_INT;
6573 *numParams = 4;
6574 return true;
6575 }
6576 case GL_SHADER_COMPILER:
6577 case GL_SAMPLE_COVERAGE_INVERT:
6578 case GL_DEPTH_WRITEMASK:
6579 case GL_CULL_FACE: // CULL_FACE through DITHER are natural to IsEnabled,
6580 case GL_POLYGON_OFFSET_FILL: // but can be retrieved through the Get{Type}v queries.
6581 case GL_SAMPLE_ALPHA_TO_COVERAGE: // For this purpose, they are treated here as
6582 // bool-natural
6583 case GL_SAMPLE_COVERAGE:
6584 case GL_SCISSOR_TEST:
6585 case GL_STENCIL_TEST:
6586 case GL_DEPTH_TEST:
6587 case GL_BLEND:
6588 case GL_DITHER:
6589 case GL_CONTEXT_ROBUST_ACCESS_EXT:
6590 {
6591 *type = GL_BOOL;
6592 *numParams = 1;
6593 return true;
6594 }
6595 case GL_COLOR_WRITEMASK:
6596 {
6597 *type = GL_BOOL;
6598 *numParams = 4;
6599 return true;
6600 }
6601 case GL_POLYGON_OFFSET_FACTOR:
6602 case GL_POLYGON_OFFSET_UNITS:
6603 case GL_SAMPLE_COVERAGE_VALUE:
6604 case GL_DEPTH_CLEAR_VALUE:
6605 case GL_LINE_WIDTH:
6606 {
6607 *type = GL_FLOAT;
6608 *numParams = 1;
6609 return true;
6610 }
6611 case GL_ALIASED_LINE_WIDTH_RANGE:
6612 case GL_ALIASED_POINT_SIZE_RANGE:
6613 case GL_DEPTH_RANGE:
6614 {
6615 *type = GL_FLOAT;
6616 *numParams = 2;
6617 return true;
6618 }
6619 case GL_COLOR_CLEAR_VALUE:
6620 case GL_BLEND_COLOR:
6621 {
6622 *type = GL_FLOAT;
6623 *numParams = 4;
6624 return true;
6625 }
6626 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
6627 if (!getExtensions().textureFilterAnisotropic)
6628 {
6629 return false;
6630 }
6631 *type = GL_FLOAT;
6632 *numParams = 1;
6633 return true;
6634 case GL_TIMESTAMP_EXT:
6635 if (!getExtensions().disjointTimerQuery)
6636 {
6637 return false;
6638 }
6639 *type = GL_INT_64_ANGLEX;
6640 *numParams = 1;
6641 return true;
6642 case GL_GPU_DISJOINT_EXT:
6643 if (!getExtensions().disjointTimerQuery)
6644 {
6645 return false;
6646 }
6647 *type = GL_INT;
6648 *numParams = 1;
6649 return true;
6650 case GL_COVERAGE_MODULATION_CHROMIUM:
6651 if (!getExtensions().framebufferMixedSamples)
6652 {
6653 return false;
6654 }
6655 *type = GL_INT;
6656 *numParams = 1;
6657 return true;
6658 case GL_TEXTURE_BINDING_EXTERNAL_OES:
6659 if (!getExtensions().eglStreamConsumerExternal && !getExtensions().eglImageExternal)
6660 {
6661 return false;
6662 }
6663 *type = GL_INT;
6664 *numParams = 1;
6665 return true;
6666 }
6667
6668 if (getExtensions().debug)
6669 {
6670 switch (pname)
6671 {
6672 case GL_DEBUG_LOGGED_MESSAGES:
6673 case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH:
6674 case GL_DEBUG_GROUP_STACK_DEPTH:
6675 case GL_MAX_DEBUG_MESSAGE_LENGTH:
6676 case GL_MAX_DEBUG_LOGGED_MESSAGES:
6677 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
6678 case GL_MAX_LABEL_LENGTH:
6679 *type = GL_INT;
6680 *numParams = 1;
6681 return true;
6682
6683 case GL_DEBUG_OUTPUT_SYNCHRONOUS:
6684 case GL_DEBUG_OUTPUT:
6685 *type = GL_BOOL;
6686 *numParams = 1;
6687 return true;
6688 }
6689 }
6690
6691 if (getExtensions().multisampleCompatibility)
6692 {
6693 switch (pname)
6694 {
6695 case GL_MULTISAMPLE_EXT:
6696 case GL_SAMPLE_ALPHA_TO_ONE_EXT:
6697 *type = GL_BOOL;
6698 *numParams = 1;
6699 return true;
6700 }
6701 }
6702
6703 if (getExtensions().pathRendering)
6704 {
6705 switch (pname)
6706 {
6707 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
6708 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
6709 *type = GL_FLOAT;
6710 *numParams = 16;
6711 return true;
6712 }
6713 }
6714
6715 if (getExtensions().bindGeneratesResource)
6716 {
6717 switch (pname)
6718 {
6719 case GL_BIND_GENERATES_RESOURCE_CHROMIUM:
6720 *type = GL_BOOL;
6721 *numParams = 1;
6722 return true;
6723 }
6724 }
6725
6726 if (getExtensions().clientArrays)
6727 {
6728 switch (pname)
6729 {
6730 case GL_CLIENT_ARRAYS_ANGLE:
6731 *type = GL_BOOL;
6732 *numParams = 1;
6733 return true;
6734 }
6735 }
6736
6737 if (getExtensions().sRGBWriteControl)
6738 {
6739 switch (pname)
6740 {
6741 case GL_FRAMEBUFFER_SRGB_EXT:
6742 *type = GL_BOOL;
6743 *numParams = 1;
6744 return true;
6745 }
6746 }
6747
6748 if (getExtensions().robustResourceInitialization &&
6749 pname == GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE)
6750 {
6751 *type = GL_BOOL;
6752 *numParams = 1;
6753 return true;
6754 }
6755
6756 if (getExtensions().programCacheControl && pname == GL_PROGRAM_CACHE_ENABLED_ANGLE)
6757 {
6758 *type = GL_BOOL;
6759 *numParams = 1;
6760 return true;
6761 }
6762
6763 // Check for ES3.0+ parameter names which are also exposed as ES2 extensions
6764 switch (pname)
6765 {
6766 // case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE // equivalent to FRAMEBUFFER_BINDING
6767 case GL_READ_FRAMEBUFFER_BINDING_ANGLE:
6768 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferBlit)
6769 {
6770 return false;
6771 }
6772 *type = GL_INT;
6773 *numParams = 1;
6774 return true;
6775
6776 case GL_NUM_PROGRAM_BINARY_FORMATS_OES:
6777 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6778 {
6779 return false;
6780 }
6781 *type = GL_INT;
6782 *numParams = 1;
6783 return true;
6784
6785 case GL_PROGRAM_BINARY_FORMATS_OES:
6786 if ((getClientMajorVersion() < 3) && !getExtensions().getProgramBinary)
6787 {
6788 return false;
6789 }
6790 *type = GL_INT;
6791 *numParams = static_cast<unsigned int>(getCaps().programBinaryFormats.size());
6792 return true;
6793
6794 case GL_PACK_ROW_LENGTH:
6795 case GL_PACK_SKIP_ROWS:
6796 case GL_PACK_SKIP_PIXELS:
6797 if ((getClientMajorVersion() < 3) && !getExtensions().packSubimage)
6798 {
6799 return false;
6800 }
6801 *type = GL_INT;
6802 *numParams = 1;
6803 return true;
6804 case GL_UNPACK_ROW_LENGTH:
6805 case GL_UNPACK_SKIP_ROWS:
6806 case GL_UNPACK_SKIP_PIXELS:
6807 if ((getClientMajorVersion() < 3) && !getExtensions().unpackSubimage)
6808 {
6809 return false;
6810 }
6811 *type = GL_INT;
6812 *numParams = 1;
6813 return true;
6814 case GL_VERTEX_ARRAY_BINDING:
6815 if ((getClientMajorVersion() < 3) && !getExtensions().vertexArrayObject)
6816 {
6817 return false;
6818 }
6819 *type = GL_INT;
6820 *numParams = 1;
6821 return true;
6822 case GL_PIXEL_PACK_BUFFER_BINDING:
6823 case GL_PIXEL_UNPACK_BUFFER_BINDING:
6824 if ((getClientMajorVersion() < 3) && !getExtensions().pixelBufferObject)
6825 {
6826 return false;
6827 }
6828 *type = GL_INT;
6829 *numParams = 1;
6830 return true;
6831 case GL_MAX_SAMPLES:
6832 {
6833 static_assert(GL_MAX_SAMPLES_ANGLE == GL_MAX_SAMPLES,
6834 "GL_MAX_SAMPLES_ANGLE not equal to GL_MAX_SAMPLES");
6835 if ((getClientMajorVersion() < 3) && !getExtensions().framebufferMultisample)
6836 {
6837 return false;
6838 }
6839 *type = GL_INT;
6840 *numParams = 1;
6841 return true;
6842
6843 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT:
6844 if ((getClientMajorVersion() < 3) && !getExtensions().standardDerivatives)
6845 {
6846 return false;
6847 }
6848 *type = GL_INT;
6849 *numParams = 1;
6850 return true;
6851 }
6852 }
6853
6854 if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT)
6855 {
6856 if ((getClientVersion() < Version(3, 0)) && !getExtensions().drawBuffers)
6857 {
6858 return false;
6859 }
6860 *type = GL_INT;
6861 *numParams = 1;
6862 return true;
6863 }
6864
6865 if (getExtensions().multiview && pname == GL_MAX_VIEWS_ANGLE)
6866 {
6867 *type = GL_INT;
6868 *numParams = 1;
6869 return true;
6870 }
6871
6872 if (getClientVersion() < Version(3, 0))
6873 {
6874 return false;
6875 }
6876
6877 // Check for ES3.0+ parameter names
6878 switch (pname)
6879 {
6880 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
6881 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
6882 case GL_UNIFORM_BUFFER_BINDING:
6883 case GL_TRANSFORM_FEEDBACK_BINDING:
6884 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
6885 case GL_COPY_READ_BUFFER_BINDING:
6886 case GL_COPY_WRITE_BUFFER_BINDING:
6887 case GL_SAMPLER_BINDING:
6888 case GL_READ_BUFFER:
6889 case GL_TEXTURE_BINDING_3D:
6890 case GL_TEXTURE_BINDING_2D_ARRAY:
6891 case GL_MAX_3D_TEXTURE_SIZE:
6892 case GL_MAX_ARRAY_TEXTURE_LAYERS:
6893 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
6894 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
6895 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
6896 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
6897 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
6898 case GL_MAX_VARYING_COMPONENTS:
6899 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
6900 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
6901 case GL_MIN_PROGRAM_TEXEL_OFFSET:
6902 case GL_MAX_PROGRAM_TEXEL_OFFSET:
6903 case GL_NUM_EXTENSIONS:
6904 case GL_MAJOR_VERSION:
6905 case GL_MINOR_VERSION:
6906 case GL_MAX_ELEMENTS_INDICES:
6907 case GL_MAX_ELEMENTS_VERTICES:
6908 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
6909 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
6910 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
6911 case GL_UNPACK_IMAGE_HEIGHT:
6912 case GL_UNPACK_SKIP_IMAGES:
6913 {
6914 *type = GL_INT;
6915 *numParams = 1;
6916 return true;
6917 }
6918
6919 case GL_MAX_ELEMENT_INDEX:
6920 case GL_MAX_UNIFORM_BLOCK_SIZE:
6921 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
6922 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
6923 case GL_MAX_SERVER_WAIT_TIMEOUT:
6924 {
6925 *type = GL_INT_64_ANGLEX;
6926 *numParams = 1;
6927 return true;
6928 }
6929
6930 case GL_TRANSFORM_FEEDBACK_ACTIVE:
6931 case GL_TRANSFORM_FEEDBACK_PAUSED:
6932 case GL_PRIMITIVE_RESTART_FIXED_INDEX:
6933 case GL_RASTERIZER_DISCARD:
6934 {
6935 *type = GL_BOOL;
6936 *numParams = 1;
6937 return true;
6938 }
6939
6940 case GL_MAX_TEXTURE_LOD_BIAS:
6941 {
6942 *type = GL_FLOAT;
6943 *numParams = 1;
6944 return true;
6945 }
6946 }
6947
6948 if (getExtensions().requestExtension)
6949 {
6950 switch (pname)
6951 {
6952 case GL_NUM_REQUESTABLE_EXTENSIONS_ANGLE:
6953 *type = GL_INT;
6954 *numParams = 1;
6955 return true;
6956 }
6957 }
6958
6959 if (getClientVersion() < Version(3, 1))
6960 {
6961 return false;
6962 }
6963
6964 switch (pname)
6965 {
6966 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
6967 case GL_DRAW_INDIRECT_BUFFER_BINDING:
6968 case GL_DISPATCH_INDIRECT_BUFFER_BINDING:
6969 case GL_MAX_FRAMEBUFFER_WIDTH:
6970 case GL_MAX_FRAMEBUFFER_HEIGHT:
6971 case GL_MAX_FRAMEBUFFER_SAMPLES:
6972 case GL_MAX_SAMPLE_MASK_WORDS:
6973 case GL_MAX_COLOR_TEXTURE_SAMPLES:
6974 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
6975 case GL_MAX_INTEGER_SAMPLES:
6976 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
6977 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
6978 case GL_MAX_VERTEX_ATTRIB_STRIDE:
6979 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
6980 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
6981 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
6982 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
6983 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
6984 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
6985 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
6986 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
6987 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
6988 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
6989 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
6990 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
6991 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
6992 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
6993 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
6994 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
6995 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
6996 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
6997 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
6998 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
6999 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
7000 case GL_MAX_UNIFORM_LOCATIONS:
7001 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
7002 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
7003 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
7004 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
7005 case GL_MAX_IMAGE_UNITS:
7006 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
7007 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
7008 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
7009 case GL_SHADER_STORAGE_BUFFER_BINDING:
7010 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
7011 case GL_TEXTURE_BINDING_2D_MULTISAMPLE:
7012 *type = GL_INT;
7013 *numParams = 1;
7014 return true;
7015 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
7016 *type = GL_INT_64_ANGLEX;
7017 *numParams = 1;
7018 return true;
7019 case GL_SAMPLE_MASK:
7020 *type = GL_BOOL;
7021 *numParams = 1;
7022 return true;
7023 }
7024
7025 if (getExtensions().geometryShader)
7026 {
7027 switch (pname)
7028 {
7029 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
7030 case GL_LAYER_PROVOKING_VERTEX_EXT:
7031 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7032 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
7033 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
7034 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
7035 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
7036 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
7037 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
7038 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
7039 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
7040 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
7041 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
7042 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
7043 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
7044 *type = GL_INT;
7045 *numParams = 1;
7046 return true;
7047 }
7048 }
7049
7050 return false;
7051}
7052
7053bool Context::getIndexedQueryParameterInfo(GLenum target, GLenum *type, unsigned int *numParams)
7054{
7055 if (getClientVersion() < Version(3, 0))
7056 {
7057 return false;
7058 }
7059
7060 switch (target)
7061 {
7062 case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING:
7063 case GL_UNIFORM_BUFFER_BINDING:
7064 {
7065 *type = GL_INT;
7066 *numParams = 1;
7067 return true;
7068 }
7069 case GL_TRANSFORM_FEEDBACK_BUFFER_START:
7070 case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE:
7071 case GL_UNIFORM_BUFFER_START:
7072 case GL_UNIFORM_BUFFER_SIZE:
7073 {
7074 *type = GL_INT_64_ANGLEX;
7075 *numParams = 1;
7076 return true;
7077 }
7078 }
7079
7080 if (getClientVersion() < Version(3, 1))
7081 {
7082 return false;
7083 }
7084
7085 switch (target)
7086 {
7087 case GL_IMAGE_BINDING_LAYERED:
7088 {
7089 *type = GL_BOOL;
7090 *numParams = 1;
7091 return true;
7092 }
7093 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
7094 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
7095 case GL_ATOMIC_COUNTER_BUFFER_BINDING:
7096 case GL_SHADER_STORAGE_BUFFER_BINDING:
7097 case GL_VERTEX_BINDING_BUFFER:
7098 case GL_VERTEX_BINDING_DIVISOR:
7099 case GL_VERTEX_BINDING_OFFSET:
7100 case GL_VERTEX_BINDING_STRIDE:
7101 case GL_SAMPLE_MASK_VALUE:
7102 case GL_IMAGE_BINDING_NAME:
7103 case GL_IMAGE_BINDING_LEVEL:
7104 case GL_IMAGE_BINDING_LAYER:
7105 case GL_IMAGE_BINDING_ACCESS:
7106 case GL_IMAGE_BINDING_FORMAT:
7107 {
7108 *type = GL_INT;
7109 *numParams = 1;
7110 return true;
7111 }
7112 case GL_ATOMIC_COUNTER_BUFFER_START:
7113 case GL_ATOMIC_COUNTER_BUFFER_SIZE:
7114 case GL_SHADER_STORAGE_BUFFER_START:
7115 case GL_SHADER_STORAGE_BUFFER_SIZE:
7116 {
7117 *type = GL_INT_64_ANGLEX;
7118 *numParams = 1;
7119 return true;
7120 }
7121 }
7122
7123 return false;
7124}
7125
7126Program *Context::getProgram(GLuint handle) const
7127{
7128 return mState.mShaderPrograms->getProgram(handle);
7129}
7130
7131Shader *Context::getShader(GLuint handle) const
7132{
7133 return mState.mShaderPrograms->getShader(handle);
7134}
7135
7136bool Context::isTextureGenerated(GLuint texture) const
7137{
7138 return mState.mTextures->isHandleGenerated(texture);
7139}
7140
7141bool Context::isBufferGenerated(GLuint buffer) const
7142{
7143 return mState.mBuffers->isHandleGenerated(buffer);
7144}
7145
7146bool Context::isRenderbufferGenerated(GLuint renderbuffer) const
7147{
7148 return mState.mRenderbuffers->isHandleGenerated(renderbuffer);
7149}
7150
7151bool Context::isFramebufferGenerated(GLuint framebuffer) const
7152{
7153 return mState.mFramebuffers->isHandleGenerated(framebuffer);
7154}
7155
7156bool Context::isProgramPipelineGenerated(GLuint pipeline) const
7157{
7158 return mState.mPipelines->isHandleGenerated(pipeline);
7159}
7160
7161bool Context::usingDisplayTextureShareGroup() const
7162{
7163 return mDisplayTextureShareGroup;
7164}
7165
7166GLenum Context::getConvertedRenderbufferFormat(GLenum internalformat) const
7167{
7168 return mState.mExtensions.webglCompatibility && mState.mClientVersion.major == 2 &&
7169 internalformat == GL_DEPTH_STENCIL
7170 ? GL_DEPTH24_STENCIL8
7171 : internalformat;
7172}
7173
Jamie Madillc29968b2016-01-20 11:17:23 -05007174} // namespace gl