blob: f4c0291d46c735b3e5e8f6fab0e1efd23f3e46c4 [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)
Martin Radev1be913c2016-07-11 17:59:16 +0300267
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500268 : ValidationContext(shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500269 shareTextures,
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500270 GetClientVersion(attribs),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700271 &mGLState,
Jamie Madillf25855c2015-11-03 11:06:18 -0500272 mCaps,
273 mTextureCaps,
274 mExtensions,
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500275 mLimitations,
276 GetNoError(attribs)),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700277 mImplementation(implFactory->createContext(mState)),
Jamie Madill2f348d22017-06-05 10:50:59 -0400278 mCompiler(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400279 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500280 mClientType(EGL_OPENGL_ES_API),
281 mHasBeenCurrent(false),
282 mContextLost(false),
283 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700284 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500285 mResetStrategy(GetResetStrategy(attribs)),
286 mRobustAccess(GetRobustAccess(attribs)),
Jamie Madill61e16b42017-06-19 11:13:23 -0400287 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
288 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500289 mSurfacelessFramebuffer(nullptr),
Jamie Madille14951e2017-03-09 18:55:16 -0500290 mWebGLContext(GetWebGLContext(attribs)),
Jamie Madill32447362017-06-28 14:53:52 -0400291 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400292 mScratchBuffer(1000u),
293 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000294{
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400295 mImplementation->setMemoryProgramCache(memoryProgramCache);
296
Geoff Langb433e872017-10-05 14:01:47 -0400297 bool robustResourceInit = GetRobustResourceInit(attribs);
298 initCaps(displayExtensions, robustResourceInit);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700299 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400300
Jamie Madill4928b7c2017-06-20 12:57:39 -0400301 mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs),
Jamie Madillc43be722017-07-13 16:22:14 -0400302 GetClientArraysEnabled(attribs), robustResourceInit,
303 mMemoryProgramCache != nullptr);
Régis Fénéon83107972015-02-05 12:57:44 +0100304
Shannon Woods53a94a82014-06-24 15:20:36 -0400305 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400306
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000307 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400308 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000309 // and cube map texture state vectors respectively associated with them.
310 // In order that access to these initial textures not be lost, they are treated as texture
311 // objects all of whose names are 0.
312
Corentin Wallez99d492c2018-02-27 15:17:10 -0500313 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, TextureType::_2D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800314 mZeroTextures[TextureType::_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500315
Corentin Wallez99d492c2018-02-27 15:17:10 -0500316 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, TextureType::CubeMap);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800317 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400318
Geoff Langeb66a6e2016-10-31 13:06:12 -0400319 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400320 {
321 // TODO: These could also be enabled via extension
Corentin Wallez99d492c2018-02-27 15:17:10 -0500322 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, TextureType::_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800323 mZeroTextures[TextureType::_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400324
Corentin Wallez99d492c2018-02-27 15:17:10 -0500325 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, TextureType::_2DArray);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800326 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400327 }
Geoff Lang3b573612016-10-31 14:08:10 -0400328 if (getClientVersion() >= Version(3, 1))
329 {
330 Texture *zeroTexture2DMultisample =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500331 new Texture(mImplementation.get(), 0, TextureType::_2DMultisample);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800332 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800333
Jiajia Qin6eafb042016-12-27 17:04:07 +0800334 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
335 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800336 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800337 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800338
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800339 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
340 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400341 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800342 }
Geoff Lang3b573612016-10-31 14:08:10 -0400343 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000344
Geoff Lang4751aab2017-10-30 15:14:52 -0400345 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
346 if (nativeExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400347 {
348 Texture *zeroTextureRectangle =
Corentin Wallez99d492c2018-02-27 15:17:10 -0500349 new Texture(mImplementation.get(), 0, TextureType::Rectangle);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800350 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400351 }
352
Geoff Lang4751aab2017-10-30 15:14:52 -0400353 if (nativeExtensions.eglImageExternal || nativeExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400354 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500355 Texture *zeroTextureExternal = new Texture(mImplementation.get(), 0, TextureType::External);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800356 mZeroTextures[TextureType::External].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400357 }
358
Jamie Madill4928b7c2017-06-20 12:57:39 -0400359 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500360
Jamie Madill57a89722013-07-02 11:57:03 -0400361 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000362
Geoff Langeb66a6e2016-10-31 13:06:12 -0400363 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400364 {
365 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
366 // In the initial state, a default transform feedback object is bound and treated as
367 // a transform feedback object with a name of zero. That object is bound any time
368 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400369 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400370 }
Geoff Langc8058452014-02-03 12:04:11 -0500371
Corentin Wallez336129f2017-10-17 15:55:40 -0400372 for (auto type : angle::AllEnums<BufferBinding>())
373 {
374 bindBuffer(type, 0);
375 }
376
377 bindRenderbuffer(GL_RENDERBUFFER, 0);
378
379 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
380 {
381 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
382 }
383
Jamie Madillad9f24e2016-02-12 09:27:24 -0500384 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400385 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500386 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500387 // No dirty objects.
388
389 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400390 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500391 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500392 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
393
394 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
395 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
396 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
397 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
398 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
399 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
400 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
401 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
402 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
403 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
404 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
405 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
406
407 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
408 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700409 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500410 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
411 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400412
Xinghua Cao10a4d432017-11-28 14:46:26 +0800413 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
414 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
415 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
416 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
417 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
418 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800419 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800420
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400421 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000422}
423
Jamie Madill4928b7c2017-06-20 12:57:39 -0400424egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000425{
Corentin Wallez80b24112015-08-25 16:41:57 -0400426 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000427 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400428 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000429 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400430 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000431
Corentin Wallez80b24112015-08-25 16:41:57 -0400432 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000433 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400434 if (query.second != nullptr)
435 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400436 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400437 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000438 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400439 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000440
Corentin Wallez80b24112015-08-25 16:41:57 -0400441 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400442 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400443 if (vertexArray.second)
444 {
445 vertexArray.second->onDestroy(this);
446 }
Jamie Madill57a89722013-07-02 11:57:03 -0400447 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400448 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400449
Corentin Wallez80b24112015-08-25 16:41:57 -0400450 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500451 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500452 if (transformFeedback.second != nullptr)
453 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500454 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500455 }
Geoff Langc8058452014-02-03 12:04:11 -0500456 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400457 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500458
Jamie Madilldedd7b92014-11-05 16:30:36 -0500459 for (auto &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400460 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800461 if (zeroTexture.get() != nullptr)
462 {
463 ANGLE_TRY(zeroTexture->onDestroy(this));
464 zeroTexture.set(this, nullptr);
465 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400466 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000467
Corentin Wallezccab69d2017-01-27 16:57:15 -0500468 SafeDelete(mSurfacelessFramebuffer);
469
Jamie Madill4928b7c2017-06-20 12:57:39 -0400470 ANGLE_TRY(releaseSurface(display));
Jamie Madill2f348d22017-06-05 10:50:59 -0400471 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500472
Jamie Madill4928b7c2017-06-20 12:57:39 -0400473 mGLState.reset(this);
474
Jamie Madill6c1f6712017-02-14 19:08:04 -0500475 mState.mBuffers->release(this);
476 mState.mShaderPrograms->release(this);
477 mState.mTextures->release(this);
478 mState.mRenderbuffers->release(this);
479 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400480 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500481 mState.mPaths->release(this);
482 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800483 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400484
Jamie Madill76e471e2017-10-21 09:56:01 -0400485 mImplementation->onDestroy(this);
486
Jamie Madill4928b7c2017-06-20 12:57:39 -0400487 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000488}
489
Jamie Madill70ee0f62017-02-06 16:04:20 -0500490Context::~Context()
491{
492}
493
Jamie Madill4928b7c2017-06-20 12:57:39 -0400494egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000495{
Jamie Madill61e16b42017-06-19 11:13:23 -0400496 mCurrentDisplay = display;
497
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000498 if (!mHasBeenCurrent)
499 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000500 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500501 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400502 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000503
Corentin Wallezc295e512017-01-27 17:47:50 -0500504 int width = 0;
505 int height = 0;
506 if (surface != nullptr)
507 {
508 width = surface->getWidth();
509 height = surface->getHeight();
510 }
511
512 mGLState.setViewportParams(0, 0, width, height);
513 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000514
515 mHasBeenCurrent = true;
516 }
517
Jamie Madill1b94d432015-08-07 13:23:23 -0400518 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700519 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400520 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400521
Jamie Madill4928b7c2017-06-20 12:57:39 -0400522 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500523
524 Framebuffer *newDefault = nullptr;
525 if (surface != nullptr)
526 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400527 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500528 mCurrentSurface = surface;
529 newDefault = surface->getDefaultFramebuffer();
530 }
531 else
532 {
533 if (mSurfacelessFramebuffer == nullptr)
534 {
535 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
536 }
537
538 newDefault = mSurfacelessFramebuffer;
539 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000540
Corentin Wallez37c39792015-08-20 14:19:46 -0400541 // Update default framebuffer, the binding of the previous default
542 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400543 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700544 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400545 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700546 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400547 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700548 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400549 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700550 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400551 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500552 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400553 }
Ian Ewell292f0052016-02-04 10:37:32 -0500554
555 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400556 mImplementation->onMakeCurrent(this);
557 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000558}
559
Jamie Madill4928b7c2017-06-20 12:57:39 -0400560egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400561{
Corentin Wallez37c39792015-08-20 14:19:46 -0400562 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500563 Framebuffer *currentDefault = nullptr;
564 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400565 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500566 currentDefault = mCurrentSurface->getDefaultFramebuffer();
567 }
568 else if (mSurfacelessFramebuffer != nullptr)
569 {
570 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400571 }
572
Corentin Wallezc295e512017-01-27 17:47:50 -0500573 if (mGLState.getReadFramebuffer() == currentDefault)
574 {
575 mGLState.setReadFramebufferBinding(nullptr);
576 }
577 if (mGLState.getDrawFramebuffer() == currentDefault)
578 {
579 mGLState.setDrawFramebufferBinding(nullptr);
580 }
581 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
582
583 if (mCurrentSurface)
584 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400585 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500586 mCurrentSurface = nullptr;
587 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400588
589 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400590}
591
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000592GLuint Context::createBuffer()
593{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500594 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000595}
596
597GLuint Context::createProgram()
598{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500599 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000600}
601
602GLuint Context::createShader(GLenum type)
603{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500604 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000605}
606
607GLuint Context::createTexture()
608{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500609 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000610}
611
612GLuint Context::createRenderbuffer()
613{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500614 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000615}
616
Sami Väisänene45e53b2016-05-25 10:36:04 +0300617GLuint Context::createPaths(GLsizei range)
618{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500619 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300620 if (resultOrError.isError())
621 {
622 handleError(resultOrError.getError());
623 return 0;
624 }
625 return resultOrError.getResult();
626}
627
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000628// Returns an unused framebuffer name
629GLuint Context::createFramebuffer()
630{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500631 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000632}
633
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500634void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000635{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500636 for (int i = 0; i < n; i++)
637 {
638 GLuint handle = mFenceNVHandleAllocator.allocate();
639 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
640 fences[i] = handle;
641 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000642}
643
Yunchao Hea336b902017-08-02 16:05:21 +0800644GLuint Context::createProgramPipeline()
645{
646 return mState.mPipelines->createProgramPipeline();
647}
648
Jiajia Qin5451d532017-11-16 17:16:34 +0800649GLuint Context::createShaderProgramv(GLenum type, GLsizei count, const GLchar *const *strings)
650{
651 UNIMPLEMENTED();
652 return 0u;
653}
654
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000655void Context::deleteBuffer(GLuint buffer)
656{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500657 if (mState.mBuffers->getBuffer(buffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000658 {
659 detachBuffer(buffer);
660 }
Jamie Madill893ab082014-05-16 16:56:10 -0400661
Jamie Madill6c1f6712017-02-14 19:08:04 -0500662 mState.mBuffers->deleteObject(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000663}
664
665void Context::deleteShader(GLuint shader)
666{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500667 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000668}
669
670void Context::deleteProgram(GLuint program)
671{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500672 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000673}
674
675void Context::deleteTexture(GLuint texture)
676{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500677 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000678 {
679 detachTexture(texture);
680 }
681
Jamie Madill6c1f6712017-02-14 19:08:04 -0500682 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000683}
684
685void Context::deleteRenderbuffer(GLuint renderbuffer)
686{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500687 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000688 {
689 detachRenderbuffer(renderbuffer);
690 }
Jamie Madill893ab082014-05-16 16:56:10 -0400691
Jamie Madill6c1f6712017-02-14 19:08:04 -0500692 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000693}
694
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400695void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400696{
697 // The spec specifies the underlying Fence object is not deleted until all current
698 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
699 // and since our API is currently designed for being called from a single thread, we can delete
700 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400701 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400702}
703
Yunchao Hea336b902017-08-02 16:05:21 +0800704void Context::deleteProgramPipeline(GLuint pipeline)
705{
706 if (mState.mPipelines->getProgramPipeline(pipeline))
707 {
708 detachProgramPipeline(pipeline);
709 }
710
711 mState.mPipelines->deleteObject(this, pipeline);
712}
713
Sami Väisänene45e53b2016-05-25 10:36:04 +0300714void Context::deletePaths(GLuint first, GLsizei range)
715{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500716 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300717}
718
719bool Context::hasPathData(GLuint path) const
720{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500721 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300722 if (pathObj == nullptr)
723 return false;
724
725 return pathObj->hasPathData();
726}
727
728bool Context::hasPath(GLuint path) const
729{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500730 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300731}
732
733void Context::setPathCommands(GLuint path,
734 GLsizei numCommands,
735 const GLubyte *commands,
736 GLsizei numCoords,
737 GLenum coordType,
738 const void *coords)
739{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500740 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300741
742 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
743}
744
Jamie Madill007530e2017-12-28 14:27:04 -0500745void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300746{
Jamie Madill007530e2017-12-28 14:27:04 -0500747 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300748
749 switch (pname)
750 {
751 case GL_PATH_STROKE_WIDTH_CHROMIUM:
752 pathObj->setStrokeWidth(value);
753 break;
754 case GL_PATH_END_CAPS_CHROMIUM:
755 pathObj->setEndCaps(static_cast<GLenum>(value));
756 break;
757 case GL_PATH_JOIN_STYLE_CHROMIUM:
758 pathObj->setJoinStyle(static_cast<GLenum>(value));
759 break;
760 case GL_PATH_MITER_LIMIT_CHROMIUM:
761 pathObj->setMiterLimit(value);
762 break;
763 case GL_PATH_STROKE_BOUND_CHROMIUM:
764 pathObj->setStrokeBound(value);
765 break;
766 default:
767 UNREACHABLE();
768 break;
769 }
770}
771
Jamie Madill007530e2017-12-28 14:27:04 -0500772void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300773{
Jamie Madill007530e2017-12-28 14:27:04 -0500774 // TODO(jmadill): Should use proper clamping/casting.
775 pathParameterf(path, pname, static_cast<GLfloat>(value));
776}
777
778void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
779{
780 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300781
782 switch (pname)
783 {
784 case GL_PATH_STROKE_WIDTH_CHROMIUM:
785 *value = pathObj->getStrokeWidth();
786 break;
787 case GL_PATH_END_CAPS_CHROMIUM:
788 *value = static_cast<GLfloat>(pathObj->getEndCaps());
789 break;
790 case GL_PATH_JOIN_STYLE_CHROMIUM:
791 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
792 break;
793 case GL_PATH_MITER_LIMIT_CHROMIUM:
794 *value = pathObj->getMiterLimit();
795 break;
796 case GL_PATH_STROKE_BOUND_CHROMIUM:
797 *value = pathObj->getStrokeBound();
798 break;
799 default:
800 UNREACHABLE();
801 break;
802 }
803}
804
Jamie Madill007530e2017-12-28 14:27:04 -0500805void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
806{
807 GLfloat val = 0.0f;
808 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
809 if (value)
810 *value = static_cast<GLint>(val);
811}
812
Sami Väisänene45e53b2016-05-25 10:36:04 +0300813void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
814{
815 mGLState.setPathStencilFunc(func, ref, mask);
816}
817
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000818void Context::deleteFramebuffer(GLuint framebuffer)
819{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500820 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000821 {
822 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000823 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500824
Jamie Madill6c1f6712017-02-14 19:08:04 -0500825 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000826}
827
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500828void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000829{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500830 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000831 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500832 GLuint fence = fences[i];
833
834 FenceNV *fenceObject = nullptr;
835 if (mFenceNVMap.erase(fence, &fenceObject))
836 {
837 mFenceNVHandleAllocator.release(fence);
838 delete fenceObject;
839 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000840 }
841}
842
Geoff Lang70d0f492015-12-10 17:45:46 -0500843Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000844{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500845 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000846}
847
Jamie Madill570f7c82014-07-03 10:38:54 -0400848Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000849{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500850 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000851}
852
Geoff Lang70d0f492015-12-10 17:45:46 -0500853Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000854{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500855 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000856}
857
Jamie Madill70b5bb02017-08-28 13:32:37 -0400858Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400859{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400860 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400861}
862
Jamie Madill57a89722013-07-02 11:57:03 -0400863VertexArray *Context::getVertexArray(GLuint handle) const
864{
Jamie Madill96a483b2017-06-27 16:49:21 -0400865 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400866}
867
Jamie Madilldc356042013-07-19 16:36:57 -0400868Sampler *Context::getSampler(GLuint handle) const
869{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500870 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400871}
872
Geoff Langc8058452014-02-03 12:04:11 -0500873TransformFeedback *Context::getTransformFeedback(GLuint handle) const
874{
Jamie Madill96a483b2017-06-27 16:49:21 -0400875 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500876}
877
Yunchao Hea336b902017-08-02 16:05:21 +0800878ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
879{
880 return mState.mPipelines->getProgramPipeline(handle);
881}
882
Geoff Lang70d0f492015-12-10 17:45:46 -0500883LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
884{
885 switch (identifier)
886 {
887 case GL_BUFFER:
888 return getBuffer(name);
889 case GL_SHADER:
890 return getShader(name);
891 case GL_PROGRAM:
892 return getProgram(name);
893 case GL_VERTEX_ARRAY:
894 return getVertexArray(name);
895 case GL_QUERY:
896 return getQuery(name);
897 case GL_TRANSFORM_FEEDBACK:
898 return getTransformFeedback(name);
899 case GL_SAMPLER:
900 return getSampler(name);
901 case GL_TEXTURE:
902 return getTexture(name);
903 case GL_RENDERBUFFER:
904 return getRenderbuffer(name);
905 case GL_FRAMEBUFFER:
906 return getFramebuffer(name);
907 default:
908 UNREACHABLE();
909 return nullptr;
910 }
911}
912
913LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
914{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400915 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500916}
917
Martin Radev9d901792016-07-15 15:58:58 +0300918void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
919{
920 LabeledObject *object = getLabeledObject(identifier, name);
921 ASSERT(object != nullptr);
922
923 std::string labelName = GetObjectLabelFromPointer(length, label);
924 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400925
926 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
927 // specified object is active until we do this.
928 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300929}
930
931void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
932{
933 LabeledObject *object = getLabeledObjectFromPtr(ptr);
934 ASSERT(object != nullptr);
935
936 std::string labelName = GetObjectLabelFromPointer(length, label);
937 object->setLabel(labelName);
938}
939
940void Context::getObjectLabel(GLenum identifier,
941 GLuint name,
942 GLsizei bufSize,
943 GLsizei *length,
944 GLchar *label) const
945{
946 LabeledObject *object = getLabeledObject(identifier, name);
947 ASSERT(object != nullptr);
948
949 const std::string &objectLabel = object->getLabel();
950 GetObjectLabelBase(objectLabel, bufSize, length, label);
951}
952
953void Context::getObjectPtrLabel(const void *ptr,
954 GLsizei bufSize,
955 GLsizei *length,
956 GLchar *label) const
957{
958 LabeledObject *object = getLabeledObjectFromPtr(ptr);
959 ASSERT(object != nullptr);
960
961 const std::string &objectLabel = object->getLabel();
962 GetObjectLabelBase(objectLabel, bufSize, length, label);
963}
964
Jamie Madilldc356042013-07-19 16:36:57 -0400965bool Context::isSampler(GLuint samplerName) const
966{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500967 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400968}
969
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800970void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000971{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500972 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000973
Jamie Madilldedd7b92014-11-05 16:30:36 -0500974 if (handle == 0)
975 {
976 texture = mZeroTextures[target].get();
977 }
978 else
979 {
Corentin Wallez99d492c2018-02-27 15:17:10 -0500980 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500981 }
982
983 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400984 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000985}
986
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500987void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000988{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500989 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
990 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700991 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000992}
993
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500994void Context::bindDrawFramebuffer(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.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000999}
1000
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001001void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001002{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001003 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001004 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001005}
1006
Shao80957d92017-02-20 21:25:59 +08001007void Context::bindVertexBuffer(GLuint bindingIndex,
1008 GLuint bufferHandle,
1009 GLintptr offset,
1010 GLsizei stride)
1011{
1012 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001013 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001014}
1015
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001016void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001017{
Geoff Lang76b10c92014-09-05 16:28:14 -04001018 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001019 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001020 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001021 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001022}
1023
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001024void Context::bindImageTexture(GLuint unit,
1025 GLuint texture,
1026 GLint level,
1027 GLboolean layered,
1028 GLint layer,
1029 GLenum access,
1030 GLenum format)
1031{
1032 Texture *tex = mState.mTextures->getTexture(texture);
1033 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1034}
1035
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001036void Context::useProgram(GLuint program)
1037{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001038 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001039}
1040
Jiajia Qin5451d532017-11-16 17:16:34 +08001041void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1042{
1043 UNIMPLEMENTED();
1044}
1045
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001046void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001047{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001048 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001049 TransformFeedback *transformFeedback =
1050 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001051 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001052}
1053
Yunchao Hea336b902017-08-02 16:05:21 +08001054void Context::bindProgramPipeline(GLuint pipelineHandle)
1055{
1056 ProgramPipeline *pipeline =
1057 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1058 mGLState.setProgramPipelineBinding(this, pipeline);
1059}
1060
Jamie Madillf0e04492017-08-26 15:28:42 -04001061void Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001062{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001063 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001064 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001065
Geoff Lang5aad9672014-09-08 11:10:42 -04001066 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001067 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001068
1069 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001070 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001071}
1072
Jamie Madillf0e04492017-08-26 15:28:42 -04001073void Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001074{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001075 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001076 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001077
Jamie Madillf0e04492017-08-26 15:28:42 -04001078 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001079
Geoff Lang5aad9672014-09-08 11:10:42 -04001080 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001081 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001082}
1083
Jamie Madillf0e04492017-08-26 15:28:42 -04001084void Context::queryCounter(GLuint id, GLenum target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001085{
1086 ASSERT(target == GL_TIMESTAMP_EXT);
1087
1088 Query *queryObject = getQuery(id, true, target);
1089 ASSERT(queryObject);
1090
Jamie Madillf0e04492017-08-26 15:28:42 -04001091 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001092}
1093
1094void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1095{
1096 switch (pname)
1097 {
1098 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001099 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001100 break;
1101 case GL_QUERY_COUNTER_BITS_EXT:
1102 switch (target)
1103 {
1104 case GL_TIME_ELAPSED_EXT:
1105 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1106 break;
1107 case GL_TIMESTAMP_EXT:
1108 params[0] = getExtensions().queryCounterBitsTimestamp;
1109 break;
1110 default:
1111 UNREACHABLE();
1112 params[0] = 0;
1113 break;
1114 }
1115 break;
1116 default:
1117 UNREACHABLE();
1118 return;
1119 }
1120}
1121
Geoff Lang2186c382016-10-14 10:54:54 -04001122void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001123{
Geoff Lang2186c382016-10-14 10:54:54 -04001124 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001125}
1126
Geoff Lang2186c382016-10-14 10:54:54 -04001127void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001128{
Geoff Lang2186c382016-10-14 10:54:54 -04001129 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001130}
1131
Geoff Lang2186c382016-10-14 10:54:54 -04001132void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001133{
Geoff Lang2186c382016-10-14 10:54:54 -04001134 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001135}
1136
Geoff Lang2186c382016-10-14 10:54:54 -04001137void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001138{
Geoff Lang2186c382016-10-14 10:54:54 -04001139 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001140}
1141
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001142Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001143{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001144 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001145}
1146
Jamie Madill2f348d22017-06-05 10:50:59 -04001147FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001148{
Jamie Madill96a483b2017-06-27 16:49:21 -04001149 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001150}
1151
Jamie Madill2f348d22017-06-05 10:50:59 -04001152Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001153{
Jamie Madill96a483b2017-06-27 16:49:21 -04001154 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001155 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001156 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001157 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001158
1159 Query *query = mQueryMap.query(handle);
1160 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001161 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001162 query = new Query(mImplementation->createQuery(type), handle);
1163 query->addRef();
1164 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001165 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001166 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001167}
1168
Geoff Lang70d0f492015-12-10 17:45:46 -05001169Query *Context::getQuery(GLuint handle) const
1170{
Jamie Madill96a483b2017-06-27 16:49:21 -04001171 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001172}
1173
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001174Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001175{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001176 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1177 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001178}
1179
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001180Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001181{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001182 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001183}
1184
Geoff Lang492a7e42014-11-05 13:27:06 -05001185Compiler *Context::getCompiler() const
1186{
Jamie Madill2f348d22017-06-05 10:50:59 -04001187 if (mCompiler.get() == nullptr)
1188 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001189 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001190 }
1191 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001192}
1193
Jamie Madillc1d770e2017-04-13 17:31:24 -04001194void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001195{
1196 switch (pname)
1197 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001198 case GL_SHADER_COMPILER:
1199 *params = GL_TRUE;
1200 break;
1201 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1202 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1203 break;
1204 default:
1205 mGLState.getBooleanv(pname, params);
1206 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001207 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001208}
1209
Jamie Madillc1d770e2017-04-13 17:31:24 -04001210void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001211{
Shannon Woods53a94a82014-06-24 15:20:36 -04001212 // Queries about context capabilities and maximums are answered by Context.
1213 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001214 switch (pname)
1215 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001216 case GL_ALIASED_LINE_WIDTH_RANGE:
1217 params[0] = mCaps.minAliasedLineWidth;
1218 params[1] = mCaps.maxAliasedLineWidth;
1219 break;
1220 case GL_ALIASED_POINT_SIZE_RANGE:
1221 params[0] = mCaps.minAliasedPointSize;
1222 params[1] = mCaps.maxAliasedPointSize;
1223 break;
1224 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1225 ASSERT(mExtensions.textureFilterAnisotropic);
1226 *params = mExtensions.maxTextureAnisotropy;
1227 break;
1228 case GL_MAX_TEXTURE_LOD_BIAS:
1229 *params = mCaps.maxLODBias;
1230 break;
1231
1232 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1233 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1234 {
1235 ASSERT(mExtensions.pathRendering);
1236 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1237 memcpy(params, m, 16 * sizeof(GLfloat));
1238 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001239 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001240
Jamie Madill231c7f52017-04-26 13:45:37 -04001241 default:
1242 mGLState.getFloatv(pname, params);
1243 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001244 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001245}
1246
Jamie Madillc1d770e2017-04-13 17:31:24 -04001247void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001248{
Shannon Woods53a94a82014-06-24 15:20:36 -04001249 // Queries about context capabilities and maximums are answered by Context.
1250 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001251
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001252 switch (pname)
1253 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001254 case GL_MAX_VERTEX_ATTRIBS:
1255 *params = mCaps.maxVertexAttributes;
1256 break;
1257 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1258 *params = mCaps.maxVertexUniformVectors;
1259 break;
1260 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1261 *params = mCaps.maxVertexUniformComponents;
1262 break;
1263 case GL_MAX_VARYING_VECTORS:
1264 *params = mCaps.maxVaryingVectors;
1265 break;
1266 case GL_MAX_VARYING_COMPONENTS:
1267 *params = mCaps.maxVertexOutputComponents;
1268 break;
1269 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1270 *params = mCaps.maxCombinedTextureImageUnits;
1271 break;
1272 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1273 *params = mCaps.maxVertexTextureImageUnits;
1274 break;
1275 case GL_MAX_TEXTURE_IMAGE_UNITS:
1276 *params = mCaps.maxTextureImageUnits;
1277 break;
1278 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1279 *params = mCaps.maxFragmentUniformVectors;
1280 break;
1281 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1282 *params = mCaps.maxFragmentUniformComponents;
1283 break;
1284 case GL_MAX_RENDERBUFFER_SIZE:
1285 *params = mCaps.maxRenderbufferSize;
1286 break;
1287 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1288 *params = mCaps.maxColorAttachments;
1289 break;
1290 case GL_MAX_DRAW_BUFFERS_EXT:
1291 *params = mCaps.maxDrawBuffers;
1292 break;
1293 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1294 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1295 case GL_SUBPIXEL_BITS:
1296 *params = 4;
1297 break;
1298 case GL_MAX_TEXTURE_SIZE:
1299 *params = mCaps.max2DTextureSize;
1300 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001301 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1302 *params = mCaps.maxRectangleTextureSize;
1303 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001304 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1305 *params = mCaps.maxCubeMapTextureSize;
1306 break;
1307 case GL_MAX_3D_TEXTURE_SIZE:
1308 *params = mCaps.max3DTextureSize;
1309 break;
1310 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1311 *params = mCaps.maxArrayTextureLayers;
1312 break;
1313 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1314 *params = mCaps.uniformBufferOffsetAlignment;
1315 break;
1316 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1317 *params = mCaps.maxUniformBufferBindings;
1318 break;
1319 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1320 *params = mCaps.maxVertexUniformBlocks;
1321 break;
1322 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1323 *params = mCaps.maxFragmentUniformBlocks;
1324 break;
1325 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1326 *params = mCaps.maxCombinedTextureImageUnits;
1327 break;
1328 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1329 *params = mCaps.maxVertexOutputComponents;
1330 break;
1331 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1332 *params = mCaps.maxFragmentInputComponents;
1333 break;
1334 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1335 *params = mCaps.minProgramTexelOffset;
1336 break;
1337 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1338 *params = mCaps.maxProgramTexelOffset;
1339 break;
1340 case GL_MAJOR_VERSION:
1341 *params = getClientVersion().major;
1342 break;
1343 case GL_MINOR_VERSION:
1344 *params = getClientVersion().minor;
1345 break;
1346 case GL_MAX_ELEMENTS_INDICES:
1347 *params = mCaps.maxElementsIndices;
1348 break;
1349 case GL_MAX_ELEMENTS_VERTICES:
1350 *params = mCaps.maxElementsVertices;
1351 break;
1352 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1353 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1354 break;
1355 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1356 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1357 break;
1358 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1359 *params = mCaps.maxTransformFeedbackSeparateComponents;
1360 break;
1361 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1362 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1363 break;
1364 case GL_MAX_SAMPLES_ANGLE:
1365 *params = mCaps.maxSamples;
1366 break;
1367 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001368 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001369 params[0] = mCaps.maxViewportWidth;
1370 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001371 }
1372 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001373 case GL_COMPRESSED_TEXTURE_FORMATS:
1374 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1375 params);
1376 break;
1377 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1378 *params = mResetStrategy;
1379 break;
1380 case GL_NUM_SHADER_BINARY_FORMATS:
1381 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1382 break;
1383 case GL_SHADER_BINARY_FORMATS:
1384 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1385 break;
1386 case GL_NUM_PROGRAM_BINARY_FORMATS:
1387 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1388 break;
1389 case GL_PROGRAM_BINARY_FORMATS:
1390 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1391 break;
1392 case GL_NUM_EXTENSIONS:
1393 *params = static_cast<GLint>(mExtensionStrings.size());
1394 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001395
Jamie Madill231c7f52017-04-26 13:45:37 -04001396 // GL_KHR_debug
1397 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1398 *params = mExtensions.maxDebugMessageLength;
1399 break;
1400 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1401 *params = mExtensions.maxDebugLoggedMessages;
1402 break;
1403 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1404 *params = mExtensions.maxDebugGroupStackDepth;
1405 break;
1406 case GL_MAX_LABEL_LENGTH:
1407 *params = mExtensions.maxLabelLength;
1408 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001409
Martin Radeve5285d22017-07-14 16:23:53 +03001410 // GL_ANGLE_multiview
1411 case GL_MAX_VIEWS_ANGLE:
1412 *params = mExtensions.maxViews;
1413 break;
1414
Jamie Madill231c7f52017-04-26 13:45:37 -04001415 // GL_EXT_disjoint_timer_query
1416 case GL_GPU_DISJOINT_EXT:
1417 *params = mImplementation->getGPUDisjoint();
1418 break;
1419 case GL_MAX_FRAMEBUFFER_WIDTH:
1420 *params = mCaps.maxFramebufferWidth;
1421 break;
1422 case GL_MAX_FRAMEBUFFER_HEIGHT:
1423 *params = mCaps.maxFramebufferHeight;
1424 break;
1425 case GL_MAX_FRAMEBUFFER_SAMPLES:
1426 *params = mCaps.maxFramebufferSamples;
1427 break;
1428 case GL_MAX_SAMPLE_MASK_WORDS:
1429 *params = mCaps.maxSampleMaskWords;
1430 break;
1431 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1432 *params = mCaps.maxColorTextureSamples;
1433 break;
1434 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1435 *params = mCaps.maxDepthTextureSamples;
1436 break;
1437 case GL_MAX_INTEGER_SAMPLES:
1438 *params = mCaps.maxIntegerSamples;
1439 break;
1440 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1441 *params = mCaps.maxVertexAttribRelativeOffset;
1442 break;
1443 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1444 *params = mCaps.maxVertexAttribBindings;
1445 break;
1446 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1447 *params = mCaps.maxVertexAttribStride;
1448 break;
1449 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1450 *params = mCaps.maxVertexAtomicCounterBuffers;
1451 break;
1452 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1453 *params = mCaps.maxVertexAtomicCounters;
1454 break;
1455 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1456 *params = mCaps.maxVertexImageUniforms;
1457 break;
1458 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1459 *params = mCaps.maxVertexShaderStorageBlocks;
1460 break;
1461 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1462 *params = mCaps.maxFragmentAtomicCounterBuffers;
1463 break;
1464 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1465 *params = mCaps.maxFragmentAtomicCounters;
1466 break;
1467 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1468 *params = mCaps.maxFragmentImageUniforms;
1469 break;
1470 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1471 *params = mCaps.maxFragmentShaderStorageBlocks;
1472 break;
1473 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1474 *params = mCaps.minProgramTextureGatherOffset;
1475 break;
1476 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1477 *params = mCaps.maxProgramTextureGatherOffset;
1478 break;
1479 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1480 *params = mCaps.maxComputeWorkGroupInvocations;
1481 break;
1482 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1483 *params = mCaps.maxComputeUniformBlocks;
1484 break;
1485 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1486 *params = mCaps.maxComputeTextureImageUnits;
1487 break;
1488 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1489 *params = mCaps.maxComputeSharedMemorySize;
1490 break;
1491 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1492 *params = mCaps.maxComputeUniformComponents;
1493 break;
1494 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1495 *params = mCaps.maxComputeAtomicCounterBuffers;
1496 break;
1497 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1498 *params = mCaps.maxComputeAtomicCounters;
1499 break;
1500 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1501 *params = mCaps.maxComputeImageUniforms;
1502 break;
1503 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1504 *params = mCaps.maxCombinedComputeUniformComponents;
1505 break;
1506 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1507 *params = mCaps.maxComputeShaderStorageBlocks;
1508 break;
1509 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1510 *params = mCaps.maxCombinedShaderOutputResources;
1511 break;
1512 case GL_MAX_UNIFORM_LOCATIONS:
1513 *params = mCaps.maxUniformLocations;
1514 break;
1515 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1516 *params = mCaps.maxAtomicCounterBufferBindings;
1517 break;
1518 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1519 *params = mCaps.maxAtomicCounterBufferSize;
1520 break;
1521 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1522 *params = mCaps.maxCombinedAtomicCounterBuffers;
1523 break;
1524 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1525 *params = mCaps.maxCombinedAtomicCounters;
1526 break;
1527 case GL_MAX_IMAGE_UNITS:
1528 *params = mCaps.maxImageUnits;
1529 break;
1530 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1531 *params = mCaps.maxCombinedImageUniforms;
1532 break;
1533 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1534 *params = mCaps.maxShaderStorageBufferBindings;
1535 break;
1536 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1537 *params = mCaps.maxCombinedShaderStorageBlocks;
1538 break;
1539 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1540 *params = mCaps.shaderStorageBufferOffsetAlignment;
1541 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001542
1543 // GL_EXT_geometry_shader
1544 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1545 *params = mCaps.maxFramebufferLayers;
1546 break;
1547 case GL_LAYER_PROVOKING_VERTEX_EXT:
1548 *params = mCaps.layerProvokingVertex;
1549 break;
1550 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1551 *params = mCaps.maxGeometryUniformComponents;
1552 break;
1553 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
1554 *params = mCaps.maxGeometryUniformBlocks;
1555 break;
1556 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1557 *params = mCaps.maxCombinedGeometryUniformComponents;
1558 break;
1559 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1560 *params = mCaps.maxGeometryInputComponents;
1561 break;
1562 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1563 *params = mCaps.maxGeometryOutputComponents;
1564 break;
1565 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1566 *params = mCaps.maxGeometryOutputVertices;
1567 break;
1568 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1569 *params = mCaps.maxGeometryTotalOutputComponents;
1570 break;
1571 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1572 *params = mCaps.maxGeometryShaderInvocations;
1573 break;
1574 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
1575 *params = mCaps.maxGeometryTextureImageUnits;
1576 break;
1577 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
1578 *params = mCaps.maxGeometryAtomicCounterBuffers;
1579 break;
1580 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
1581 *params = mCaps.maxGeometryAtomicCounters;
1582 break;
1583 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
1584 *params = mCaps.maxGeometryImageUniforms;
1585 break;
1586 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
1587 *params = mCaps.maxGeometryShaderStorageBlocks;
1588 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001589 default:
1590 mGLState.getIntegerv(this, pname, params);
1591 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001592 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001593}
1594
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001595void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001596{
Shannon Woods53a94a82014-06-24 15:20:36 -04001597 // Queries about context capabilities and maximums are answered by Context.
1598 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001599 switch (pname)
1600 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001601 case GL_MAX_ELEMENT_INDEX:
1602 *params = mCaps.maxElementIndex;
1603 break;
1604 case GL_MAX_UNIFORM_BLOCK_SIZE:
1605 *params = mCaps.maxUniformBlockSize;
1606 break;
1607 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1608 *params = mCaps.maxCombinedVertexUniformComponents;
1609 break;
1610 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1611 *params = mCaps.maxCombinedFragmentUniformComponents;
1612 break;
1613 case GL_MAX_SERVER_WAIT_TIMEOUT:
1614 *params = mCaps.maxServerWaitTimeout;
1615 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001616
Jamie Madill231c7f52017-04-26 13:45:37 -04001617 // GL_EXT_disjoint_timer_query
1618 case GL_TIMESTAMP_EXT:
1619 *params = mImplementation->getTimestamp();
1620 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001621
Jamie Madill231c7f52017-04-26 13:45:37 -04001622 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1623 *params = mCaps.maxShaderStorageBlockSize;
1624 break;
1625 default:
1626 UNREACHABLE();
1627 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001628 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001629}
1630
Geoff Lang70d0f492015-12-10 17:45:46 -05001631void Context::getPointerv(GLenum pname, void **params) const
1632{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001633 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001634}
1635
Martin Radev66fb8202016-07-28 11:45:20 +03001636void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001637{
Shannon Woods53a94a82014-06-24 15:20:36 -04001638 // Queries about context capabilities and maximums are answered by Context.
1639 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001640
1641 GLenum nativeType;
1642 unsigned int numParams;
1643 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1644 ASSERT(queryStatus);
1645
1646 if (nativeType == GL_INT)
1647 {
1648 switch (target)
1649 {
1650 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1651 ASSERT(index < 3u);
1652 *data = mCaps.maxComputeWorkGroupCount[index];
1653 break;
1654 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1655 ASSERT(index < 3u);
1656 *data = mCaps.maxComputeWorkGroupSize[index];
1657 break;
1658 default:
1659 mGLState.getIntegeri_v(target, index, data);
1660 }
1661 }
1662 else
1663 {
1664 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1665 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001666}
1667
Martin Radev66fb8202016-07-28 11:45:20 +03001668void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001669{
Shannon Woods53a94a82014-06-24 15:20:36 -04001670 // Queries about context capabilities and maximums are answered by Context.
1671 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001672
1673 GLenum nativeType;
1674 unsigned int numParams;
1675 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1676 ASSERT(queryStatus);
1677
1678 if (nativeType == GL_INT_64_ANGLEX)
1679 {
1680 mGLState.getInteger64i_v(target, index, data);
1681 }
1682 else
1683 {
1684 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1685 }
1686}
1687
1688void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1689{
1690 // Queries about context capabilities and maximums are answered by Context.
1691 // Queries about current GL state values are answered by State.
1692
1693 GLenum nativeType;
1694 unsigned int numParams;
1695 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1696 ASSERT(queryStatus);
1697
1698 if (nativeType == GL_BOOL)
1699 {
1700 mGLState.getBooleani_v(target, index, data);
1701 }
1702 else
1703 {
1704 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1705 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001706}
1707
Corentin Wallez336129f2017-10-17 15:55:40 -04001708void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001709{
1710 Buffer *buffer = mGLState.getTargetBuffer(target);
1711 QueryBufferParameteriv(buffer, pname, params);
1712}
1713
1714void Context::getFramebufferAttachmentParameteriv(GLenum target,
1715 GLenum attachment,
1716 GLenum pname,
1717 GLint *params)
1718{
1719 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001720 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001721}
1722
1723void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1724{
1725 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1726 QueryRenderbufferiv(this, renderbuffer, pname, params);
1727}
1728
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001729void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001730{
1731 Texture *texture = getTargetTexture(target);
1732 QueryTexParameterfv(texture, pname, params);
1733}
1734
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001735void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001736{
1737 Texture *texture = getTargetTexture(target);
1738 QueryTexParameteriv(texture, pname, params);
1739}
Jiajia Qin5451d532017-11-16 17:16:34 +08001740
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001741void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001742{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001743 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001744 QueryTexLevelParameteriv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001745}
1746
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001747void Context::getTexLevelParameterfv(TextureTarget target,
1748 GLint level,
1749 GLenum pname,
1750 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001751{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001752 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05001753 QueryTexLevelParameterfv(texture, target, level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001754}
1755
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001756void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08001757{
1758 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001759 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001760 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001761}
1762
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001763void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001764{
1765 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001766 SetTexParameterfv(this, texture, pname, params);
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::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08001771{
1772 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001773 SetTexParameteri(this, texture, pname, param);
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::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001778{
1779 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001780 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001781 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001782}
1783
Jamie Madill675fe712016-12-19 13:07:54 -05001784void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001785{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001786 // No-op if zero count
1787 if (count == 0)
1788 {
1789 return;
1790 }
1791
Jamie Madill05b35b22017-10-03 09:01:44 -04001792 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001793 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
1794 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001795}
1796
Jamie Madill675fe712016-12-19 13:07:54 -05001797void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001798{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001799 // No-op if zero count
1800 if (count == 0 || instanceCount == 0)
1801 {
1802 return;
1803 }
1804
Jamie Madill05b35b22017-10-03 09:01:44 -04001805 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001806 ANGLE_CONTEXT_TRY(
1807 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
1808 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
Geoff Langf6db0982015-08-25 13:04:00 -04001809}
1810
Jamie Madill876429b2017-04-20 15:46:24 -04001811void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001812{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001813 // No-op if zero count
1814 if (count == 0)
1815 {
1816 return;
1817 }
1818
Jamie Madill05b35b22017-10-03 09:01:44 -04001819 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001820 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001821}
1822
Jamie Madill675fe712016-12-19 13:07:54 -05001823void Context::drawElementsInstanced(GLenum mode,
1824 GLsizei count,
1825 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001826 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001827 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001828{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001829 // No-op if zero count
1830 if (count == 0 || instances == 0)
1831 {
1832 return;
1833 }
1834
Jamie Madill05b35b22017-10-03 09:01:44 -04001835 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001836 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001837 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001838}
1839
Jamie Madill675fe712016-12-19 13:07:54 -05001840void Context::drawRangeElements(GLenum mode,
1841 GLuint start,
1842 GLuint end,
1843 GLsizei count,
1844 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001845 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001846{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001847 // No-op if zero count
1848 if (count == 0)
1849 {
1850 return;
1851 }
1852
Jamie Madill05b35b22017-10-03 09:01:44 -04001853 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001854 ANGLE_CONTEXT_TRY(
1855 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001856}
1857
Jamie Madill876429b2017-04-20 15:46:24 -04001858void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001859{
Jamie Madill05b35b22017-10-03 09:01:44 -04001860 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001861 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001862}
1863
Jamie Madill876429b2017-04-20 15:46:24 -04001864void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001865{
Jamie Madill05b35b22017-10-03 09:01:44 -04001866 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001867 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001868}
1869
Jamie Madill675fe712016-12-19 13:07:54 -05001870void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001871{
Jamie Madillafa02a22017-11-23 12:57:38 -05001872 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05001873}
1874
Jamie Madill675fe712016-12-19 13:07:54 -05001875void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001876{
Jamie Madillafa02a22017-11-23 12:57:38 -05001877 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001878}
1879
Austin Kinross6ee1e782015-05-29 17:05:37 -07001880void Context::insertEventMarker(GLsizei length, const char *marker)
1881{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001882 ASSERT(mImplementation);
1883 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001884}
1885
1886void Context::pushGroupMarker(GLsizei length, const char *marker)
1887{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001888 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05001889
1890 if (marker == nullptr)
1891 {
1892 // From the EXT_debug_marker spec,
1893 // "If <marker> is null then an empty string is pushed on the stack."
1894 mImplementation->pushGroupMarker(length, "");
1895 }
1896 else
1897 {
1898 mImplementation->pushGroupMarker(length, marker);
1899 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07001900}
1901
1902void Context::popGroupMarker()
1903{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001904 ASSERT(mImplementation);
1905 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001906}
1907
Geoff Langd8605522016-04-13 10:19:12 -04001908void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1909{
1910 Program *programObject = getProgram(program);
1911 ASSERT(programObject);
1912
1913 programObject->bindUniformLocation(location, name);
1914}
1915
Sami Väisänena797e062016-05-12 15:23:40 +03001916void Context::setCoverageModulation(GLenum components)
1917{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001918 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001919}
1920
Sami Väisänene45e53b2016-05-25 10:36:04 +03001921void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1922{
1923 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1924}
1925
1926void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1927{
1928 GLfloat I[16];
1929 angle::Matrix<GLfloat>::setToIdentity(I);
1930
1931 mGLState.loadPathRenderingMatrix(matrixMode, I);
1932}
1933
1934void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1935{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001936 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001937 if (!pathObj)
1938 return;
1939
1940 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1941 syncRendererState();
1942
1943 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1944}
1945
1946void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1947{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001948 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001949 if (!pathObj)
1950 return;
1951
1952 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1953 syncRendererState();
1954
1955 mImplementation->stencilStrokePath(pathObj, reference, mask);
1956}
1957
1958void Context::coverFillPath(GLuint path, GLenum coverMode)
1959{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001960 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001961 if (!pathObj)
1962 return;
1963
1964 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1965 syncRendererState();
1966
1967 mImplementation->coverFillPath(pathObj, coverMode);
1968}
1969
1970void Context::coverStrokePath(GLuint path, GLenum coverMode)
1971{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001972 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001973 if (!pathObj)
1974 return;
1975
1976 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1977 syncRendererState();
1978
1979 mImplementation->coverStrokePath(pathObj, coverMode);
1980}
1981
1982void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1983{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001984 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001985 if (!pathObj)
1986 return;
1987
1988 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1989 syncRendererState();
1990
1991 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
1992}
1993
1994void Context::stencilThenCoverStrokePath(GLuint path,
1995 GLint reference,
1996 GLuint mask,
1997 GLenum coverMode)
1998{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001999 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002000 if (!pathObj)
2001 return;
2002
2003 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2004 syncRendererState();
2005
2006 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2007}
2008
Sami Väisänend59ca052016-06-21 16:10:00 +03002009void Context::coverFillPathInstanced(GLsizei numPaths,
2010 GLenum pathNameType,
2011 const void *paths,
2012 GLuint pathBase,
2013 GLenum coverMode,
2014 GLenum transformType,
2015 const GLfloat *transformValues)
2016{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002017 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002018
2019 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2020 syncRendererState();
2021
2022 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2023}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002024
Sami Väisänend59ca052016-06-21 16:10:00 +03002025void Context::coverStrokePathInstanced(GLsizei numPaths,
2026 GLenum pathNameType,
2027 const void *paths,
2028 GLuint pathBase,
2029 GLenum coverMode,
2030 GLenum transformType,
2031 const GLfloat *transformValues)
2032{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002033 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002034
2035 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2036 syncRendererState();
2037
2038 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2039 transformValues);
2040}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002041
Sami Väisänend59ca052016-06-21 16:10:00 +03002042void Context::stencilFillPathInstanced(GLsizei numPaths,
2043 GLenum pathNameType,
2044 const void *paths,
2045 GLuint pathBase,
2046 GLenum fillMode,
2047 GLuint mask,
2048 GLenum transformType,
2049 const GLfloat *transformValues)
2050{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002051 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002052
2053 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2054 syncRendererState();
2055
2056 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2057 transformValues);
2058}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002059
Sami Väisänend59ca052016-06-21 16:10:00 +03002060void Context::stencilStrokePathInstanced(GLsizei numPaths,
2061 GLenum pathNameType,
2062 const void *paths,
2063 GLuint pathBase,
2064 GLint reference,
2065 GLuint mask,
2066 GLenum transformType,
2067 const GLfloat *transformValues)
2068{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002069 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002070
2071 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2072 syncRendererState();
2073
2074 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2075 transformValues);
2076}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002077
Sami Väisänend59ca052016-06-21 16:10:00 +03002078void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2079 GLenum pathNameType,
2080 const void *paths,
2081 GLuint pathBase,
2082 GLenum fillMode,
2083 GLuint mask,
2084 GLenum coverMode,
2085 GLenum transformType,
2086 const GLfloat *transformValues)
2087{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002088 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002089
2090 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2091 syncRendererState();
2092
2093 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2094 transformType, transformValues);
2095}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002096
Sami Väisänend59ca052016-06-21 16:10:00 +03002097void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2098 GLenum pathNameType,
2099 const void *paths,
2100 GLuint pathBase,
2101 GLint reference,
2102 GLuint mask,
2103 GLenum coverMode,
2104 GLenum transformType,
2105 const GLfloat *transformValues)
2106{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002107 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002108
2109 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2110 syncRendererState();
2111
2112 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2113 transformType, transformValues);
2114}
2115
Sami Väisänen46eaa942016-06-29 10:26:37 +03002116void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2117{
2118 auto *programObject = getProgram(program);
2119
2120 programObject->bindFragmentInputLocation(location, name);
2121}
2122
2123void Context::programPathFragmentInputGen(GLuint program,
2124 GLint location,
2125 GLenum genMode,
2126 GLint components,
2127 const GLfloat *coeffs)
2128{
2129 auto *programObject = getProgram(program);
2130
Jamie Madillbd044ed2017-06-05 12:59:21 -04002131 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002132}
2133
jchen1015015f72017-03-16 13:54:21 +08002134GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2135{
jchen10fd7c3b52017-03-21 15:36:03 +08002136 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002137 return QueryProgramResourceIndex(programObject, programInterface, name);
2138}
2139
jchen10fd7c3b52017-03-21 15:36:03 +08002140void Context::getProgramResourceName(GLuint program,
2141 GLenum programInterface,
2142 GLuint index,
2143 GLsizei bufSize,
2144 GLsizei *length,
2145 GLchar *name)
2146{
2147 const auto *programObject = getProgram(program);
2148 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2149}
2150
jchen10191381f2017-04-11 13:59:04 +08002151GLint Context::getProgramResourceLocation(GLuint program,
2152 GLenum programInterface,
2153 const GLchar *name)
2154{
2155 const auto *programObject = getProgram(program);
2156 return QueryProgramResourceLocation(programObject, programInterface, name);
2157}
2158
jchen10880683b2017-04-12 16:21:55 +08002159void Context::getProgramResourceiv(GLuint program,
2160 GLenum programInterface,
2161 GLuint index,
2162 GLsizei propCount,
2163 const GLenum *props,
2164 GLsizei bufSize,
2165 GLsizei *length,
2166 GLint *params)
2167{
2168 const auto *programObject = getProgram(program);
2169 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2170 length, params);
2171}
2172
jchen10d9cd7b72017-08-30 15:04:25 +08002173void Context::getProgramInterfaceiv(GLuint program,
2174 GLenum programInterface,
2175 GLenum pname,
2176 GLint *params)
2177{
2178 const auto *programObject = getProgram(program);
2179 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2180}
2181
Jamie Madill71c88b32017-09-14 22:20:29 -04002182void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002183{
Geoff Langda5777c2014-07-11 09:52:58 -04002184 if (error.isError())
2185 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002186 GLenum code = error.getCode();
2187 mErrors.insert(code);
2188 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2189 {
2190 markContextLost();
2191 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002192
Geoff Langee6884e2017-11-09 16:51:11 -05002193 ASSERT(!error.getMessage().empty());
2194 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2195 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002196 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002197}
2198
2199// Get one of the recorded errors and clear its flag, if any.
2200// [OpenGL ES 2.0.24] section 2.5 page 13.
2201GLenum Context::getError()
2202{
Geoff Langda5777c2014-07-11 09:52:58 -04002203 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002204 {
Geoff Langda5777c2014-07-11 09:52:58 -04002205 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002206 }
Geoff Langda5777c2014-07-11 09:52:58 -04002207 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002208 {
Geoff Langda5777c2014-07-11 09:52:58 -04002209 GLenum error = *mErrors.begin();
2210 mErrors.erase(mErrors.begin());
2211 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002212 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002213}
2214
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002215// NOTE: this function should not assume that this context is current!
2216void Context::markContextLost()
2217{
2218 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002219 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002220 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002221 mContextLostForced = true;
2222 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002223 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002224}
2225
2226bool Context::isContextLost()
2227{
2228 return mContextLost;
2229}
2230
Jamie Madillfa920eb2018-01-04 11:45:50 -05002231GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002232{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002233 // Even if the application doesn't want to know about resets, we want to know
2234 // as it will allow us to skip all the calls.
2235 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002236 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002237 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002238 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002239 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002240 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002241
2242 // EXT_robustness, section 2.6: If the reset notification behavior is
2243 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2244 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2245 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002246 }
2247
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002248 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2249 // status should be returned at least once, and GL_NO_ERROR should be returned
2250 // once the device has finished resetting.
2251 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002252 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002253 ASSERT(mResetStatus == GL_NO_ERROR);
2254 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002255
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002256 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002257 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002258 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002259 }
2260 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002261 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002262 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002263 // If markContextLost was used to mark the context lost then
2264 // assume that is not recoverable, and continue to report the
2265 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002266 mResetStatus = mImplementation->getResetStatus();
2267 }
Jamie Madill893ab082014-05-16 16:56:10 -04002268
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002269 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002270}
2271
2272bool Context::isResetNotificationEnabled()
2273{
2274 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2275}
2276
Corentin Walleze3b10e82015-05-20 11:06:25 -04002277const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002278{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002279 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002280}
2281
2282EGLenum Context::getClientType() const
2283{
2284 return mClientType;
2285}
2286
2287EGLenum Context::getRenderBuffer() const
2288{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002289 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2290 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002291 {
2292 return EGL_NONE;
2293 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002294
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002295 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002296 ASSERT(backAttachment != nullptr);
2297 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002298}
2299
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002300VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002301{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002302 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002303 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2304 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002305 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002306 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2307 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002308
Jamie Madill96a483b2017-06-27 16:49:21 -04002309 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002310 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002311
2312 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002313}
2314
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002315TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002316{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002317 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002318 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2319 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002320 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002321 transformFeedback =
2322 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002323 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002324 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002325 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002326
2327 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002328}
2329
2330bool Context::isVertexArrayGenerated(GLuint vertexArray)
2331{
Jamie Madill96a483b2017-06-27 16:49:21 -04002332 ASSERT(mVertexArrayMap.contains(0));
2333 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002334}
2335
2336bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2337{
Jamie Madill96a483b2017-06-27 16:49:21 -04002338 ASSERT(mTransformFeedbackMap.contains(0));
2339 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002340}
2341
Shannon Woods53a94a82014-06-24 15:20:36 -04002342void Context::detachTexture(GLuint texture)
2343{
2344 // Simple pass-through to State's detachTexture method, as textures do not require
2345 // allocation map management either here or in the resource manager at detach time.
2346 // Zero textures are held by the Context, and we don't attempt to request them from
2347 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002348 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002349}
2350
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002351void Context::detachBuffer(GLuint buffer)
2352{
Yuly Novikov5807a532015-12-03 13:01:22 -05002353 // Simple pass-through to State's detachBuffer method, since
2354 // only buffer attachments to container objects that are bound to the current context
2355 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002356
Yuly Novikov5807a532015-12-03 13:01:22 -05002357 // [OpenGL ES 3.2] section 5.1.2 page 45:
2358 // Attachments to unbound container objects, such as
2359 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2360 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002361 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002362}
2363
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002364void Context::detachFramebuffer(GLuint framebuffer)
2365{
Shannon Woods53a94a82014-06-24 15:20:36 -04002366 // Framebuffer detachment is handled by Context, because 0 is a valid
2367 // Framebuffer object, and a pointer to it must be passed from Context
2368 // to State at binding time.
2369
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002370 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002371 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2372 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2373 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002374
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002375 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002376 {
2377 bindReadFramebuffer(0);
2378 }
2379
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002380 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002381 {
2382 bindDrawFramebuffer(0);
2383 }
2384}
2385
2386void Context::detachRenderbuffer(GLuint renderbuffer)
2387{
Jamie Madilla02315b2017-02-23 14:14:47 -05002388 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002389}
2390
Jamie Madill57a89722013-07-02 11:57:03 -04002391void Context::detachVertexArray(GLuint vertexArray)
2392{
Jamie Madill77a72f62015-04-14 11:18:32 -04002393 // Vertex array detachment is handled by Context, because 0 is a valid
2394 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002395 // binding time.
2396
Jamie Madill57a89722013-07-02 11:57:03 -04002397 // [OpenGL ES 3.0.2] section 2.10 page 43:
2398 // If a vertex array object that is currently bound is deleted, the binding
2399 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002400 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002401 {
2402 bindVertexArray(0);
2403 }
2404}
2405
Geoff Langc8058452014-02-03 12:04:11 -05002406void Context::detachTransformFeedback(GLuint transformFeedback)
2407{
Corentin Walleza2257da2016-04-19 16:43:12 -04002408 // Transform feedback detachment is handled by Context, because 0 is a valid
2409 // transform feedback, and a pointer to it must be passed from Context to State at
2410 // binding time.
2411
2412 // The OpenGL specification doesn't mention what should happen when the currently bound
2413 // transform feedback object is deleted. Since it is a container object, we treat it like
2414 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002415 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002416 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002417 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002418 }
Geoff Langc8058452014-02-03 12:04:11 -05002419}
2420
Jamie Madilldc356042013-07-19 16:36:57 -04002421void Context::detachSampler(GLuint sampler)
2422{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002423 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002424}
2425
Yunchao Hea336b902017-08-02 16:05:21 +08002426void Context::detachProgramPipeline(GLuint pipeline)
2427{
2428 mGLState.detachProgramPipeline(this, pipeline);
2429}
2430
Jamie Madill3ef140a2017-08-26 23:11:21 -04002431void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002432{
Shaodde78e82017-05-22 14:13:27 +08002433 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002434}
2435
Jamie Madille29d1672013-07-19 16:36:57 -04002436void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2437{
Geoff Langc1984ed2016-10-07 12:41:00 -04002438 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002439 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002440 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002441 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002442}
Jamie Madille29d1672013-07-19 16:36:57 -04002443
Geoff Langc1984ed2016-10-07 12:41:00 -04002444void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2445{
2446 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002447 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002448 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002449 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002450}
2451
2452void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2453{
Geoff Langc1984ed2016-10-07 12:41:00 -04002454 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002455 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002456 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002457 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002458}
2459
Geoff Langc1984ed2016-10-07 12:41:00 -04002460void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002461{
Geoff Langc1984ed2016-10-07 12:41:00 -04002462 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002463 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002464 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002465 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002466}
2467
Geoff Langc1984ed2016-10-07 12:41:00 -04002468void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002469{
Geoff Langc1984ed2016-10-07 12:41:00 -04002470 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002471 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002472 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002473 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002474}
Jamie Madill9675b802013-07-19 16:36:59 -04002475
Geoff Langc1984ed2016-10-07 12:41:00 -04002476void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2477{
2478 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002479 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002480 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002481 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002482}
2483
Olli Etuahof0fee072016-03-30 15:11:58 +03002484void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2485{
2486 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002487 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002488}
2489
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002490void Context::initRendererString()
2491{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002492 std::ostringstream rendererString;
2493 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002494 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002495 rendererString << ")";
2496
Geoff Langcec35902014-04-16 10:52:36 -04002497 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002498}
2499
Geoff Langc339c4e2016-11-29 10:37:36 -05002500void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002501{
Geoff Langc339c4e2016-11-29 10:37:36 -05002502 const Version &clientVersion = getClientVersion();
2503
2504 std::ostringstream versionString;
2505 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2506 << ANGLE_VERSION_STRING << ")";
2507 mVersionString = MakeStaticString(versionString.str());
2508
2509 std::ostringstream shadingLanguageVersionString;
2510 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2511 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2512 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2513 << ")";
2514 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002515}
2516
Geoff Langcec35902014-04-16 10:52:36 -04002517void Context::initExtensionStrings()
2518{
Geoff Langc339c4e2016-11-29 10:37:36 -05002519 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2520 std::ostringstream combinedStringStream;
2521 std::copy(strings.begin(), strings.end(),
2522 std::ostream_iterator<const char *>(combinedStringStream, " "));
2523 return MakeStaticString(combinedStringStream.str());
2524 };
2525
2526 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002527 for (const auto &extensionString : mExtensions.getStrings())
2528 {
2529 mExtensionStrings.push_back(MakeStaticString(extensionString));
2530 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002531 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002532
Bryan Bernhart58806562017-01-05 13:09:31 -08002533 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2534
Geoff Langc339c4e2016-11-29 10:37:36 -05002535 mRequestableExtensionStrings.clear();
2536 for (const auto &extensionInfo : GetExtensionInfoMap())
2537 {
2538 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002539 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2540 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002541 {
2542 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2543 }
2544 }
2545 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002546}
2547
Geoff Langc339c4e2016-11-29 10:37:36 -05002548const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002549{
Geoff Langc339c4e2016-11-29 10:37:36 -05002550 switch (name)
2551 {
2552 case GL_VENDOR:
2553 return reinterpret_cast<const GLubyte *>("Google Inc.");
2554
2555 case GL_RENDERER:
2556 return reinterpret_cast<const GLubyte *>(mRendererString);
2557
2558 case GL_VERSION:
2559 return reinterpret_cast<const GLubyte *>(mVersionString);
2560
2561 case GL_SHADING_LANGUAGE_VERSION:
2562 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2563
2564 case GL_EXTENSIONS:
2565 return reinterpret_cast<const GLubyte *>(mExtensionString);
2566
2567 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2568 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2569
2570 default:
2571 UNREACHABLE();
2572 return nullptr;
2573 }
Geoff Langcec35902014-04-16 10:52:36 -04002574}
2575
Geoff Langc339c4e2016-11-29 10:37:36 -05002576const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002577{
Geoff Langc339c4e2016-11-29 10:37:36 -05002578 switch (name)
2579 {
2580 case GL_EXTENSIONS:
2581 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2582
2583 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2584 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2585
2586 default:
2587 UNREACHABLE();
2588 return nullptr;
2589 }
Geoff Langcec35902014-04-16 10:52:36 -04002590}
2591
2592size_t Context::getExtensionStringCount() const
2593{
2594 return mExtensionStrings.size();
2595}
2596
Geoff Lang111a99e2017-10-17 10:58:41 -04002597bool Context::isExtensionRequestable(const char *name)
2598{
2599 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2600 auto extension = extensionInfos.find(name);
2601
2602 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2603 return extension != extensionInfos.end() && extension->second.Requestable &&
2604 nativeExtensions.*(extension->second.ExtensionsMember);
2605}
2606
Geoff Langc339c4e2016-11-29 10:37:36 -05002607void Context::requestExtension(const char *name)
2608{
2609 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2610 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2611 const auto &extension = extensionInfos.at(name);
2612 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002613 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002614
2615 if (mExtensions.*(extension.ExtensionsMember))
2616 {
2617 // Extension already enabled
2618 return;
2619 }
2620
2621 mExtensions.*(extension.ExtensionsMember) = true;
2622 updateCaps();
2623 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002624
Jamie Madill2f348d22017-06-05 10:50:59 -04002625 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2626 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002627
Jamie Madill81c2e252017-09-09 23:32:46 -04002628 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2629 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002630 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002631 for (auto &zeroTexture : mZeroTextures)
2632 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002633 if (zeroTexture.get() != nullptr)
2634 {
2635 zeroTexture->signalDirty(this, InitState::Initialized);
2636 }
Geoff Lang9aded172017-04-05 11:07:56 -04002637 }
2638
2639 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002640}
2641
2642size_t Context::getRequestableExtensionStringCount() const
2643{
2644 return mRequestableExtensionStrings.size();
2645}
2646
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002647void Context::beginTransformFeedback(GLenum primitiveMode)
2648{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002649 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002650 ASSERT(transformFeedback != nullptr);
2651 ASSERT(!transformFeedback->isPaused());
2652
Jamie Madill6c1f6712017-02-14 19:08:04 -05002653 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002654}
2655
2656bool Context::hasActiveTransformFeedback(GLuint program) const
2657{
2658 for (auto pair : mTransformFeedbackMap)
2659 {
2660 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2661 {
2662 return true;
2663 }
2664 }
2665 return false;
2666}
2667
Geoff Langb433e872017-10-05 14:01:47 -04002668void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002669{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002670 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002671
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08002672 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
2673 if (getClientVersion() < Version(2, 0))
2674 {
2675 mCaps.maxMultitextureUnits = 4;
2676 mCaps.maxClipPlanes = 6;
2677 mCaps.maxLights = 8;
2678 mCaps.maxModelviewMatrixStackDepth = 16;
2679 mCaps.maxProjectionMatrixStackDepth = 16;
2680 mCaps.maxTextureMatrixStackDepth = 16;
2681 }
2682
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002683 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002684
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002685 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002686
Geoff Langeb66a6e2016-10-31 13:06:12 -04002687 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002688 {
2689 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002690 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002691 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002692 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002693 mExtensions.multiview = false;
2694 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002695 }
2696
Jiawei Shao89be29a2017-11-06 14:36:45 +08002697 if (getClientVersion() < ES_3_1)
2698 {
2699 // Disable ES3.1+ extensions
2700 mExtensions.geometryShader = false;
2701 }
2702
Geoff Langeb66a6e2016-10-31 13:06:12 -04002703 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002704 {
2705 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002706 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002707 }
2708
Jamie Madill00ed7a12016-05-19 13:13:38 -04002709 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002710 mExtensions.bindUniformLocation = true;
2711 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002712 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002713 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002714 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002715
2716 // Enable the no error extension if the context was created with the flag.
2717 mExtensions.noError = mSkipValidation;
2718
Corentin Wallezccab69d2017-01-27 16:57:15 -05002719 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002720 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002721
Geoff Lang70d0f492015-12-10 17:45:46 -05002722 // Explicitly enable GL_KHR_debug
2723 mExtensions.debug = true;
2724 mExtensions.maxDebugMessageLength = 1024;
2725 mExtensions.maxDebugLoggedMessages = 1024;
2726 mExtensions.maxDebugGroupStackDepth = 1024;
2727 mExtensions.maxLabelLength = 1024;
2728
Geoff Langff5b2d52016-09-07 11:32:23 -04002729 // Explicitly enable GL_ANGLE_robust_client_memory
2730 mExtensions.robustClientMemory = true;
2731
Jamie Madille08a1d32017-03-07 17:24:06 -05002732 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002733 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002734
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002735 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2736 // supports it.
2737 mExtensions.robustBufferAccessBehavior =
2738 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2739
Jamie Madillc43be722017-07-13 16:22:14 -04002740 // Enable the cache control query unconditionally.
2741 mExtensions.programCacheControl = true;
2742
Geoff Lang301d1612014-07-09 10:34:37 -04002743 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002744 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002745
Jamie Madill0f80ed82017-09-19 00:24:56 -04002746 if (getClientVersion() < ES_3_1)
2747 {
2748 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2749 }
2750 else
2751 {
2752 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2753 }
Geoff Lang301d1612014-07-09 10:34:37 -04002754
Jamie Madill0f80ed82017-09-19 00:24:56 -04002755 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2756 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2757 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2758
2759 // Limit textures as well, so we can use fast bitsets with texture bindings.
2760 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2761 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2762 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002763
Jiawei Shaodb342272017-09-27 10:21:45 +08002764 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2765
Geoff Langc287ea62016-09-16 14:46:51 -04002766 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002767 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002768 for (const auto &extensionInfo : GetExtensionInfoMap())
2769 {
2770 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002771 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002772 {
2773 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2774 }
2775 }
2776
2777 // Generate texture caps
2778 updateCaps();
2779}
2780
2781void Context::updateCaps()
2782{
Geoff Lang900013c2014-07-07 11:32:19 -04002783 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002784 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002785
Jamie Madill7b62cf92017-11-02 15:20:49 -04002786 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04002787 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04002788 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04002789 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002790
Geoff Lang0d8b7242015-09-09 14:56:53 -04002791 // Update the format caps based on the client version and extensions.
2792 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2793 // ES3.
2794 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002795 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002796 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002797 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002798 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002799 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002800
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002801 // OpenGL ES does not support multisampling with non-rendererable formats
2802 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002803 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002804 (getClientVersion() < ES_3_1 &&
2805 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002806 {
Geoff Langd87878e2014-09-19 15:42:59 -04002807 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002808 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002809 else
2810 {
2811 // We may have limited the max samples for some required renderbuffer formats due to
2812 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2813 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2814
2815 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2816 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2817 // exception of signed and unsigned integer formats."
2818 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2819 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2820 {
2821 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2822 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2823 }
2824
2825 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2826 if (getClientVersion() >= ES_3_1)
2827 {
2828 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2829 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2830 // the exception that the signed and unsigned integer formats are required only to
2831 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2832 // multisamples, which must be at least one."
2833 if (formatInfo.componentType == GL_INT ||
2834 formatInfo.componentType == GL_UNSIGNED_INT)
2835 {
2836 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2837 }
2838
2839 // GLES 3.1 section 19.3.1.
2840 if (formatCaps.texturable)
2841 {
2842 if (formatInfo.depthBits > 0)
2843 {
2844 mCaps.maxDepthTextureSamples =
2845 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2846 }
2847 else if (formatInfo.redBits > 0)
2848 {
2849 mCaps.maxColorTextureSamples =
2850 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2851 }
2852 }
2853 }
2854 }
Geoff Langd87878e2014-09-19 15:42:59 -04002855
2856 if (formatCaps.texturable && formatInfo.compressed)
2857 {
Geoff Langca271392017-04-05 12:30:00 -04002858 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002859 }
2860
Geoff Langca271392017-04-05 12:30:00 -04002861 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002862 }
Jamie Madill32447362017-06-28 14:53:52 -04002863
2864 // If program binary is disabled, blank out the memory cache pointer.
2865 if (!mImplementation->getNativeExtensions().getProgramBinary)
2866 {
2867 mMemoryProgramCache = nullptr;
2868 }
Corentin Walleze4477002017-12-01 14:39:58 -05002869
2870 // Compute which buffer types are allowed
2871 mValidBufferBindings.reset();
2872 mValidBufferBindings.set(BufferBinding::ElementArray);
2873 mValidBufferBindings.set(BufferBinding::Array);
2874
2875 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
2876 {
2877 mValidBufferBindings.set(BufferBinding::PixelPack);
2878 mValidBufferBindings.set(BufferBinding::PixelUnpack);
2879 }
2880
2881 if (getClientVersion() >= ES_3_0)
2882 {
2883 mValidBufferBindings.set(BufferBinding::CopyRead);
2884 mValidBufferBindings.set(BufferBinding::CopyWrite);
2885 mValidBufferBindings.set(BufferBinding::TransformFeedback);
2886 mValidBufferBindings.set(BufferBinding::Uniform);
2887 }
2888
2889 if (getClientVersion() >= ES_3_1)
2890 {
2891 mValidBufferBindings.set(BufferBinding::AtomicCounter);
2892 mValidBufferBindings.set(BufferBinding::ShaderStorage);
2893 mValidBufferBindings.set(BufferBinding::DrawIndirect);
2894 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
2895 }
Geoff Lang493daf52014-07-03 13:38:44 -04002896}
2897
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002898void Context::initWorkarounds()
2899{
Jamie Madill761b02c2017-06-23 16:27:06 -04002900 // Apply back-end workarounds.
2901 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2902
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002903 // Lose the context upon out of memory error if the application is
2904 // expecting to watch for those events.
2905 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2906}
2907
Jamie Madill05b35b22017-10-03 09:01:44 -04002908Error Context::prepareForDraw()
2909{
2910 syncRendererState();
Jamie Madilla59fc192017-11-02 12:57:58 -04002911
2912 if (isRobustResourceInitEnabled())
2913 {
2914 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
2915 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
2916 }
2917
Jamie Madill05b35b22017-10-03 09:01:44 -04002918 return NoError();
2919}
2920
Jamie Madill1b94d432015-08-07 13:23:23 -04002921void Context::syncRendererState()
2922{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002923 mGLState.syncDirtyObjects(this);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002924 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madillfe548342017-06-19 11:13:24 -04002925 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002926 mGLState.clearDirtyBits();
Jamie Madill1b94d432015-08-07 13:23:23 -04002927}
2928
Jamie Madillad9f24e2016-02-12 09:27:24 -05002929void Context::syncRendererState(const State::DirtyBits &bitMask,
2930 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002931{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002932 mGLState.syncDirtyObjects(this, objectMask);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002933 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002934 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002935 mGLState.clearDirtyBits(dirtyBits);
Jamie Madill1b94d432015-08-07 13:23:23 -04002936}
Jamie Madillc29968b2016-01-20 11:17:23 -05002937
2938void Context::blitFramebuffer(GLint srcX0,
2939 GLint srcY0,
2940 GLint srcX1,
2941 GLint srcY1,
2942 GLint dstX0,
2943 GLint dstY0,
2944 GLint dstX1,
2945 GLint dstY1,
2946 GLbitfield mask,
2947 GLenum filter)
2948{
Qin Jiajiaaef92162018-02-27 13:51:44 +08002949 if (mask == 0)
2950 {
2951 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
2952 // buffers are copied.
2953 return;
2954 }
2955
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002956 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002957 ASSERT(drawFramebuffer);
2958
2959 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2960 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2961
Jamie Madillad9f24e2016-02-12 09:27:24 -05002962 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002963
Jamie Madillc564c072017-06-01 12:45:42 -04002964 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002965}
Jamie Madillc29968b2016-01-20 11:17:23 -05002966
2967void Context::clear(GLbitfield mask)
2968{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002969 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002970 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002971}
2972
2973void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2974{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002975 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002976 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002977}
2978
2979void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2980{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002981 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002982 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002983}
2984
2985void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2986{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002987 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002988 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002989}
2990
2991void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2992{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002993 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002994 ASSERT(framebufferObject);
2995
2996 // If a buffer is not present, the clear has no effect
2997 if (framebufferObject->getDepthbuffer() == nullptr &&
2998 framebufferObject->getStencilbuffer() == nullptr)
2999 {
3000 return;
3001 }
3002
Jamie Madillad9f24e2016-02-12 09:27:24 -05003003 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04003004 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003005}
3006
3007void Context::readPixels(GLint x,
3008 GLint y,
3009 GLsizei width,
3010 GLsizei height,
3011 GLenum format,
3012 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003013 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003014{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003015 if (width == 0 || height == 0)
3016 {
3017 return;
3018 }
3019
Jamie Madillad9f24e2016-02-12 09:27:24 -05003020 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05003021
Jamie Madillb6664922017-07-25 12:55:04 -04003022 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3023 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003024
3025 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003026 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003027}
3028
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003029void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003030 GLint level,
3031 GLenum internalformat,
3032 GLint x,
3033 GLint y,
3034 GLsizei width,
3035 GLsizei height,
3036 GLint border)
3037{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003038 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003039 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003040
Jamie Madillc29968b2016-01-20 11:17:23 -05003041 Rectangle sourceArea(x, y, width, height);
3042
Jamie Madill05b35b22017-10-03 09:01:44 -04003043 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003044 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003045 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003046}
3047
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003048void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003049 GLint level,
3050 GLint xoffset,
3051 GLint yoffset,
3052 GLint x,
3053 GLint y,
3054 GLsizei width,
3055 GLsizei height)
3056{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003057 if (width == 0 || height == 0)
3058 {
3059 return;
3060 }
3061
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003062 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003063 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003064
Jamie Madillc29968b2016-01-20 11:17:23 -05003065 Offset destOffset(xoffset, yoffset, 0);
3066 Rectangle sourceArea(x, y, width, height);
3067
Jamie Madill05b35b22017-10-03 09:01:44 -04003068 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003069 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003070 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003071}
3072
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003073void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003074 GLint level,
3075 GLint xoffset,
3076 GLint yoffset,
3077 GLint zoffset,
3078 GLint x,
3079 GLint y,
3080 GLsizei width,
3081 GLsizei height)
3082{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003083 if (width == 0 || height == 0)
3084 {
3085 return;
3086 }
3087
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003088 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003089 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003090
Jamie Madillc29968b2016-01-20 11:17:23 -05003091 Offset destOffset(xoffset, yoffset, zoffset);
3092 Rectangle sourceArea(x, y, width, height);
3093
Jamie Madill05b35b22017-10-03 09:01:44 -04003094 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3095 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003096 handleError(texture->copySubImage(this, NonCubeTextureTypeToTarget(target), level, destOffset,
3097 sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003098}
3099
3100void Context::framebufferTexture2D(GLenum target,
3101 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003102 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003103 GLuint texture,
3104 GLint level)
3105{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003106 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003107 ASSERT(framebuffer);
3108
3109 if (texture != 0)
3110 {
3111 Texture *textureObj = getTexture(texture);
3112
3113 ImageIndex index = ImageIndex::MakeInvalid();
3114
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003115 if (textarget == TextureTarget::_2D)
Jamie Madillc29968b2016-01-20 11:17:23 -05003116 {
3117 index = ImageIndex::Make2D(level);
3118 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003119 else if (textarget == TextureTarget::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003120 {
3121 index = ImageIndex::MakeRectangle(level);
3122 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003123 else if (textarget == TextureTarget::_2DMultisample)
JiangYizhoubddc46b2016-12-09 09:50:51 +08003124 {
3125 ASSERT(level == 0);
3126 index = ImageIndex::Make2DMultisample();
3127 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003128 else
3129 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003130 ASSERT(TextureTargetToType(textarget) == TextureType::CubeMap);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003131 index = ImageIndex::MakeCube(textarget, level);
Jamie Madillc29968b2016-01-20 11:17:23 -05003132 }
3133
Jamie Madilla02315b2017-02-23 14:14:47 -05003134 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003135 }
3136 else
3137 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003138 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003139 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003140
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003141 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003142}
3143
3144void Context::framebufferRenderbuffer(GLenum target,
3145 GLenum attachment,
3146 GLenum renderbuffertarget,
3147 GLuint renderbuffer)
3148{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003149 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003150 ASSERT(framebuffer);
3151
3152 if (renderbuffer != 0)
3153 {
3154 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003155
3156 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003157 renderbufferObject);
3158 }
3159 else
3160 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003161 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003162 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003163
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003164 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003165}
3166
3167void Context::framebufferTextureLayer(GLenum target,
3168 GLenum attachment,
3169 GLuint texture,
3170 GLint level,
3171 GLint layer)
3172{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003173 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003174 ASSERT(framebuffer);
3175
3176 if (texture != 0)
3177 {
3178 Texture *textureObject = getTexture(texture);
3179
3180 ImageIndex index = ImageIndex::MakeInvalid();
3181
Corentin Wallez99d492c2018-02-27 15:17:10 -05003182 if (textureObject->getType() == TextureType::_3D)
Jamie Madillc29968b2016-01-20 11:17:23 -05003183 {
3184 index = ImageIndex::Make3D(level, layer);
3185 }
3186 else
3187 {
Corentin Wallez99d492c2018-02-27 15:17:10 -05003188 ASSERT(textureObject->getType() == TextureType::_2DArray);
Jamie Madillc29968b2016-01-20 11:17:23 -05003189 index = ImageIndex::Make2DArray(level, layer);
3190 }
3191
Jamie Madilla02315b2017-02-23 14:14:47 -05003192 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003193 }
3194 else
3195 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003196 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003197 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003198
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003199 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003200}
3201
Martin Radev137032d2017-07-13 10:11:12 +03003202void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3203 GLenum attachment,
3204 GLuint texture,
3205 GLint level,
3206 GLint baseViewIndex,
3207 GLsizei numViews)
3208{
Martin Radev82ef7742017-08-08 17:44:58 +03003209 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3210 ASSERT(framebuffer);
3211
3212 if (texture != 0)
3213 {
3214 Texture *textureObj = getTexture(texture);
3215
Martin Radev18b75ba2017-08-15 15:50:40 +03003216 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003217 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3218 numViews, baseViewIndex);
3219 }
3220 else
3221 {
3222 framebuffer->resetAttachment(this, attachment);
3223 }
3224
3225 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003226}
3227
3228void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3229 GLenum attachment,
3230 GLuint texture,
3231 GLint level,
3232 GLsizei numViews,
3233 const GLint *viewportOffsets)
3234{
Martin Radev5dae57b2017-07-14 16:15:55 +03003235 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3236 ASSERT(framebuffer);
3237
3238 if (texture != 0)
3239 {
3240 Texture *textureObj = getTexture(texture);
3241
3242 ImageIndex index = ImageIndex::Make2D(level);
3243 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3244 textureObj, numViews, viewportOffsets);
3245 }
3246 else
3247 {
3248 framebuffer->resetAttachment(this, attachment);
3249 }
3250
3251 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003252}
3253
Jamie Madillc29968b2016-01-20 11:17:23 -05003254void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3255{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003256 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003257 ASSERT(framebuffer);
3258 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003259 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003260}
3261
3262void Context::readBuffer(GLenum mode)
3263{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003264 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003265 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003266 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003267}
3268
3269void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3270{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003271 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003272 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003273
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003274 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003275 ASSERT(framebuffer);
3276
3277 // The specification isn't clear what should be done when the framebuffer isn't complete.
3278 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003279 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003280}
3281
3282void Context::invalidateFramebuffer(GLenum target,
3283 GLsizei numAttachments,
3284 const GLenum *attachments)
3285{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003286 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003287 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003288
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003289 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003290 ASSERT(framebuffer);
3291
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003292 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003293 {
Jamie Madill437fa652016-05-03 15:13:24 -04003294 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003295 }
Jamie Madill437fa652016-05-03 15:13:24 -04003296
Jamie Madill4928b7c2017-06-20 12:57:39 -04003297 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003298}
3299
3300void Context::invalidateSubFramebuffer(GLenum target,
3301 GLsizei numAttachments,
3302 const GLenum *attachments,
3303 GLint x,
3304 GLint y,
3305 GLsizei width,
3306 GLsizei height)
3307{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003308 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003309 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003310
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003311 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003312 ASSERT(framebuffer);
3313
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003314 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003315 {
Jamie Madill437fa652016-05-03 15:13:24 -04003316 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003317 }
Jamie Madill437fa652016-05-03 15:13:24 -04003318
3319 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003320 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003321}
3322
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003323void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003324 GLint level,
3325 GLint internalformat,
3326 GLsizei width,
3327 GLsizei height,
3328 GLint border,
3329 GLenum format,
3330 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003331 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003332{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003333 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003334
3335 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003336 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003337 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3338 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003339}
3340
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003341void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003342 GLint level,
3343 GLint internalformat,
3344 GLsizei width,
3345 GLsizei height,
3346 GLsizei depth,
3347 GLint border,
3348 GLenum format,
3349 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003350 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003351{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003352 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003353
3354 Extents size(width, height, depth);
3355 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003356 handleError(texture->setImage(this, mGLState.getUnpackState(),
3357 NonCubeTextureTypeToTarget(target), level, internalformat, size,
3358 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003359}
3360
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003361void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003362 GLint level,
3363 GLint xoffset,
3364 GLint yoffset,
3365 GLsizei width,
3366 GLsizei height,
3367 GLenum format,
3368 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003369 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003370{
3371 // Zero sized uploads are valid but no-ops
3372 if (width == 0 || height == 0)
3373 {
3374 return;
3375 }
3376
Jamie Madillad9f24e2016-02-12 09:27:24 -05003377 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003378
3379 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003380 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003381 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3382 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003383}
3384
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003385void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003386 GLint level,
3387 GLint xoffset,
3388 GLint yoffset,
3389 GLint zoffset,
3390 GLsizei width,
3391 GLsizei height,
3392 GLsizei depth,
3393 GLenum format,
3394 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003395 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003396{
3397 // Zero sized uploads are valid but no-ops
3398 if (width == 0 || height == 0 || depth == 0)
3399 {
3400 return;
3401 }
3402
Jamie Madillad9f24e2016-02-12 09:27:24 -05003403 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003404
3405 Box area(xoffset, yoffset, zoffset, width, height, depth);
3406 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003407 handleError(texture->setSubImage(this, mGLState.getUnpackState(),
3408 NonCubeTextureTypeToTarget(target), level, area, format, type,
3409 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003410}
3411
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003412void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003413 GLint level,
3414 GLenum internalformat,
3415 GLsizei width,
3416 GLsizei height,
3417 GLint border,
3418 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003419 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003420{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003421 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003422
3423 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003424 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003425 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
3426 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003427 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003428}
3429
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003430void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003431 GLint level,
3432 GLenum internalformat,
3433 GLsizei width,
3434 GLsizei height,
3435 GLsizei depth,
3436 GLint border,
3437 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003438 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003439{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003440 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003441
3442 Extents size(width, height, depth);
3443 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003444 handleError(texture->setCompressedImage(
3445 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, internalformat,
3446 size, imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003447}
3448
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003449void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003450 GLint level,
3451 GLint xoffset,
3452 GLint yoffset,
3453 GLsizei width,
3454 GLsizei height,
3455 GLenum format,
3456 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003457 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003458{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003459 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003460
3461 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003462 Texture *texture = getTargetTexture(TextureTargetToType(target));
Corentin Wallez99d492c2018-02-27 15:17:10 -05003463 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
3464 format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003465 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003466}
3467
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003468void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003469 GLint level,
3470 GLint xoffset,
3471 GLint yoffset,
3472 GLint zoffset,
3473 GLsizei width,
3474 GLsizei height,
3475 GLsizei depth,
3476 GLenum format,
3477 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003478 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003479{
3480 // Zero sized uploads are valid but no-ops
3481 if (width == 0 || height == 0)
3482 {
3483 return;
3484 }
3485
Jamie Madillad9f24e2016-02-12 09:27:24 -05003486 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003487
3488 Box area(xoffset, yoffset, zoffset, width, height, depth);
3489 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05003490 handleError(texture->setCompressedSubImage(
3491 this, mGLState.getUnpackState(), NonCubeTextureTypeToTarget(target), level, area, format,
3492 imageSize, reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003493}
3494
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003495void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003496{
3497 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003498 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003499}
3500
Jamie Madill007530e2017-12-28 14:27:04 -05003501void Context::copyTexture(GLuint sourceId,
3502 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003503 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05003504 GLuint destId,
3505 GLint destLevel,
3506 GLint internalFormat,
3507 GLenum destType,
3508 GLboolean unpackFlipY,
3509 GLboolean unpackPremultiplyAlpha,
3510 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003511{
3512 syncStateForTexImage();
3513
3514 gl::Texture *sourceTexture = getTexture(sourceId);
3515 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05003516 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
3517 sourceLevel, ConvertToBool(unpackFlipY),
3518 ConvertToBool(unpackPremultiplyAlpha),
3519 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003520}
3521
Jamie Madill007530e2017-12-28 14:27:04 -05003522void Context::copySubTexture(GLuint sourceId,
3523 GLint sourceLevel,
Corentin Wallez99d492c2018-02-27 15:17:10 -05003524 TextureTarget destTarget,
Jamie Madill007530e2017-12-28 14:27:04 -05003525 GLuint destId,
3526 GLint destLevel,
3527 GLint xoffset,
3528 GLint yoffset,
3529 GLint x,
3530 GLint y,
3531 GLsizei width,
3532 GLsizei height,
3533 GLboolean unpackFlipY,
3534 GLboolean unpackPremultiplyAlpha,
3535 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003536{
3537 // Zero sized copies are valid but no-ops
3538 if (width == 0 || height == 0)
3539 {
3540 return;
3541 }
3542
3543 syncStateForTexImage();
3544
3545 gl::Texture *sourceTexture = getTexture(sourceId);
3546 gl::Texture *destTexture = getTexture(destId);
3547 Offset offset(xoffset, yoffset, 0);
3548 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05003549 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
3550 ConvertToBool(unpackFlipY),
3551 ConvertToBool(unpackPremultiplyAlpha),
3552 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003553}
3554
Jamie Madill007530e2017-12-28 14:27:04 -05003555void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07003556{
3557 syncStateForTexImage();
3558
3559 gl::Texture *sourceTexture = getTexture(sourceId);
3560 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003561 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003562}
3563
Corentin Wallez336129f2017-10-17 15:55:40 -04003564void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003565{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003566 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003567 ASSERT(buffer);
3568
Geoff Lang496c02d2016-10-20 11:38:11 -07003569 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003570}
3571
Corentin Wallez336129f2017-10-17 15:55:40 -04003572void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003573{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003574 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003575 ASSERT(buffer);
3576
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003577 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003578 if (error.isError())
3579 {
Jamie Madill437fa652016-05-03 15:13:24 -04003580 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003581 return nullptr;
3582 }
3583
3584 return buffer->getMapPointer();
3585}
3586
Corentin Wallez336129f2017-10-17 15:55:40 -04003587GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003588{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003589 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003590 ASSERT(buffer);
3591
3592 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003593 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003594 if (error.isError())
3595 {
Jamie Madill437fa652016-05-03 15:13:24 -04003596 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003597 return GL_FALSE;
3598 }
3599
3600 return result;
3601}
3602
Corentin Wallez336129f2017-10-17 15:55:40 -04003603void *Context::mapBufferRange(BufferBinding target,
3604 GLintptr offset,
3605 GLsizeiptr length,
3606 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003607{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003608 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003609 ASSERT(buffer);
3610
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003611 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003612 if (error.isError())
3613 {
Jamie Madill437fa652016-05-03 15:13:24 -04003614 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003615 return nullptr;
3616 }
3617
3618 return buffer->getMapPointer();
3619}
3620
Corentin Wallez336129f2017-10-17 15:55:40 -04003621void Context::flushMappedBufferRange(BufferBinding /*target*/,
3622 GLintptr /*offset*/,
3623 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03003624{
3625 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3626}
3627
Jamie Madillad9f24e2016-02-12 09:27:24 -05003628void Context::syncStateForReadPixels()
3629{
3630 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3631}
3632
3633void Context::syncStateForTexImage()
3634{
3635 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3636}
3637
3638void Context::syncStateForClear()
3639{
3640 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3641}
3642
3643void Context::syncStateForBlit()
3644{
3645 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3646}
3647
Jiajia Qin5451d532017-11-16 17:16:34 +08003648void Context::activeShaderProgram(GLuint pipeline, GLuint program)
3649{
3650 UNIMPLEMENTED();
3651}
3652
Jamie Madillc20ab272016-06-09 07:20:46 -07003653void Context::activeTexture(GLenum texture)
3654{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003655 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003656}
3657
Jamie Madill876429b2017-04-20 15:46:24 -04003658void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003659{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003660 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003661}
3662
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003663void Context::blendEquation(GLenum mode)
3664{
3665 mGLState.setBlendEquation(mode, mode);
3666}
3667
Jamie Madillc20ab272016-06-09 07:20:46 -07003668void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3669{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003670 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003671}
3672
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003673void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3674{
3675 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3676}
3677
Jamie Madillc20ab272016-06-09 07:20:46 -07003678void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3679{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003680 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003681}
3682
Jamie Madill876429b2017-04-20 15:46:24 -04003683void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003684{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003685 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003686}
3687
Jamie Madill876429b2017-04-20 15:46:24 -04003688void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003689{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003690 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003691}
3692
3693void Context::clearStencil(GLint s)
3694{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003695 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003696}
3697
3698void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3699{
Geoff Lang92019432017-11-20 13:09:34 -05003700 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
3701 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003702}
3703
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003704void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003705{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003706 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003707}
3708
3709void Context::depthFunc(GLenum func)
3710{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003711 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003712}
3713
3714void Context::depthMask(GLboolean flag)
3715{
Geoff Lang92019432017-11-20 13:09:34 -05003716 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07003717}
3718
Jamie Madill876429b2017-04-20 15:46:24 -04003719void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003720{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003721 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003722}
3723
3724void Context::disable(GLenum cap)
3725{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003726 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003727}
3728
3729void Context::disableVertexAttribArray(GLuint index)
3730{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003731 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003732}
3733
3734void Context::enable(GLenum cap)
3735{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003736 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003737}
3738
3739void Context::enableVertexAttribArray(GLuint index)
3740{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003741 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003742}
3743
3744void Context::frontFace(GLenum mode)
3745{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003746 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003747}
3748
3749void Context::hint(GLenum target, GLenum mode)
3750{
3751 switch (target)
3752 {
3753 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003754 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003755 break;
3756
3757 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003758 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003759 break;
3760
3761 default:
3762 UNREACHABLE();
3763 return;
3764 }
3765}
3766
3767void Context::lineWidth(GLfloat width)
3768{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003769 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003770}
3771
3772void Context::pixelStorei(GLenum pname, GLint param)
3773{
3774 switch (pname)
3775 {
3776 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003777 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003778 break;
3779
3780 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003781 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003782 break;
3783
3784 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003785 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003786 break;
3787
3788 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003789 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003790 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003791 break;
3792
3793 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003794 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003795 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003796 break;
3797
3798 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003799 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003800 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003801 break;
3802
3803 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003804 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003805 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003806 break;
3807
3808 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003809 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003810 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003811 break;
3812
3813 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003814 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003815 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003816 break;
3817
3818 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003819 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003820 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003821 break;
3822
3823 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003824 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003825 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003826 break;
3827
3828 default:
3829 UNREACHABLE();
3830 return;
3831 }
3832}
3833
3834void Context::polygonOffset(GLfloat factor, GLfloat units)
3835{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003836 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003837}
3838
Jamie Madill876429b2017-04-20 15:46:24 -04003839void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003840{
Geoff Lang92019432017-11-20 13:09:34 -05003841 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07003842}
3843
Jiawei Shaodb342272017-09-27 10:21:45 +08003844void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3845{
3846 mGLState.setSampleMaskParams(maskNumber, mask);
3847}
3848
Jamie Madillc20ab272016-06-09 07:20:46 -07003849void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3850{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003851 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003852}
3853
3854void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3855{
3856 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3857 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003858 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003859 }
3860
3861 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3862 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003863 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003864 }
3865}
3866
3867void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3868{
3869 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3870 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003871 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003872 }
3873
3874 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3875 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003876 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003877 }
3878}
3879
3880void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3881{
3882 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3883 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003884 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003885 }
3886
3887 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3888 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003889 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003890 }
3891}
3892
3893void Context::vertexAttrib1f(GLuint index, GLfloat x)
3894{
3895 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003896 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003897}
3898
3899void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3900{
3901 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003902 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003903}
3904
3905void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3906{
3907 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003908 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003909}
3910
3911void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3912{
3913 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003914 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003915}
3916
3917void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3918{
3919 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003920 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003921}
3922
3923void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3924{
3925 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003926 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003927}
3928
3929void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3930{
3931 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003932 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003933}
3934
3935void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3936{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003937 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003938}
3939
3940void Context::vertexAttribPointer(GLuint index,
3941 GLint size,
3942 GLenum type,
3943 GLboolean normalized,
3944 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003945 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003946{
Corentin Wallez336129f2017-10-17 15:55:40 -04003947 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05003948 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003949}
3950
Shao80957d92017-02-20 21:25:59 +08003951void Context::vertexAttribFormat(GLuint attribIndex,
3952 GLint size,
3953 GLenum type,
3954 GLboolean normalized,
3955 GLuint relativeOffset)
3956{
Geoff Lang92019432017-11-20 13:09:34 -05003957 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08003958 relativeOffset);
3959}
3960
3961void Context::vertexAttribIFormat(GLuint attribIndex,
3962 GLint size,
3963 GLenum type,
3964 GLuint relativeOffset)
3965{
3966 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3967}
3968
3969void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3970{
Shaodde78e82017-05-22 14:13:27 +08003971 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08003972}
3973
Jiajia Qin5451d532017-11-16 17:16:34 +08003974void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08003975{
3976 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3977}
3978
Jamie Madillc20ab272016-06-09 07:20:46 -07003979void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3980{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003981 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003982}
3983
3984void Context::vertexAttribIPointer(GLuint index,
3985 GLint size,
3986 GLenum type,
3987 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003988 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003989{
Corentin Wallez336129f2017-10-17 15:55:40 -04003990 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
3991 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003992}
3993
3994void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3995{
3996 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003997 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003998}
3999
4000void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4001{
4002 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004003 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004004}
4005
4006void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4007{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004008 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004009}
4010
4011void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4012{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004013 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004014}
4015
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004016void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4017{
4018 const VertexAttribCurrentValueData &currentValues =
4019 getGLState().getVertexAttribCurrentValue(index);
4020 const VertexArray *vao = getGLState().getVertexArray();
4021 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4022 currentValues, pname, params);
4023}
4024
4025void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4026{
4027 const VertexAttribCurrentValueData &currentValues =
4028 getGLState().getVertexAttribCurrentValue(index);
4029 const VertexArray *vao = getGLState().getVertexArray();
4030 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4031 currentValues, pname, params);
4032}
4033
4034void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4035{
4036 const VertexAttribCurrentValueData &currentValues =
4037 getGLState().getVertexAttribCurrentValue(index);
4038 const VertexArray *vao = getGLState().getVertexArray();
4039 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4040 currentValues, pname, params);
4041}
4042
4043void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4044{
4045 const VertexAttribCurrentValueData &currentValues =
4046 getGLState().getVertexAttribCurrentValue(index);
4047 const VertexArray *vao = getGLState().getVertexArray();
4048 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4049 currentValues, pname, params);
4050}
4051
Jamie Madill876429b2017-04-20 15:46:24 -04004052void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004053{
4054 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4055 QueryVertexAttribPointerv(attrib, pname, pointer);
4056}
4057
Jamie Madillc20ab272016-06-09 07:20:46 -07004058void Context::debugMessageControl(GLenum source,
4059 GLenum type,
4060 GLenum severity,
4061 GLsizei count,
4062 const GLuint *ids,
4063 GLboolean enabled)
4064{
4065 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004066 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004067 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004068}
4069
4070void Context::debugMessageInsert(GLenum source,
4071 GLenum type,
4072 GLuint id,
4073 GLenum severity,
4074 GLsizei length,
4075 const GLchar *buf)
4076{
4077 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004078 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004079}
4080
4081void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4082{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004083 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004084}
4085
4086GLuint Context::getDebugMessageLog(GLuint count,
4087 GLsizei bufSize,
4088 GLenum *sources,
4089 GLenum *types,
4090 GLuint *ids,
4091 GLenum *severities,
4092 GLsizei *lengths,
4093 GLchar *messageLog)
4094{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004095 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4096 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004097}
4098
4099void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4100{
4101 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004102 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004103 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004104}
4105
4106void Context::popDebugGroup()
4107{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004108 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004109 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004110}
4111
Corentin Wallez336129f2017-10-17 15:55:40 -04004112void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004113{
4114 Buffer *buffer = mGLState.getTargetBuffer(target);
4115 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004116 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004117}
4118
Corentin Wallez336129f2017-10-17 15:55:40 -04004119void Context::bufferSubData(BufferBinding target,
4120 GLintptr offset,
4121 GLsizeiptr size,
4122 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004123{
4124 if (data == nullptr)
4125 {
4126 return;
4127 }
4128
4129 Buffer *buffer = mGLState.getTargetBuffer(target);
4130 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004131 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004132}
4133
Jamie Madillef300b12016-10-07 15:12:09 -04004134void Context::attachShader(GLuint program, GLuint shader)
4135{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004136 Program *programObject = mState.mShaderPrograms->getProgram(program);
4137 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004138 ASSERT(programObject && shaderObject);
4139 programObject->attachShader(shaderObject);
4140}
4141
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004142const Workarounds &Context::getWorkarounds() const
4143{
4144 return mWorkarounds;
4145}
4146
Corentin Wallez336129f2017-10-17 15:55:40 -04004147void Context::copyBufferSubData(BufferBinding readTarget,
4148 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004149 GLintptr readOffset,
4150 GLintptr writeOffset,
4151 GLsizeiptr size)
4152{
4153 // if size is zero, the copy is a successful no-op
4154 if (size == 0)
4155 {
4156 return;
4157 }
4158
4159 // TODO(jmadill): cache these.
4160 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4161 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4162
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004163 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004164}
4165
Jamie Madill01a80ee2016-11-07 12:06:18 -05004166void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4167{
4168 Program *programObject = getProgram(program);
4169 // TODO(jmadill): Re-use this from the validation if possible.
4170 ASSERT(programObject);
4171 programObject->bindAttributeLocation(index, name);
4172}
4173
Corentin Wallez336129f2017-10-17 15:55:40 -04004174void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004175{
Corentin Wallez336129f2017-10-17 15:55:40 -04004176 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4177 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004178}
4179
Corentin Wallez336129f2017-10-17 15:55:40 -04004180void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004181{
4182 bindBufferRange(target, index, buffer, 0, 0);
4183}
4184
Corentin Wallez336129f2017-10-17 15:55:40 -04004185void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004186 GLuint index,
4187 GLuint buffer,
4188 GLintptr offset,
4189 GLsizeiptr size)
4190{
Corentin Wallez336129f2017-10-17 15:55:40 -04004191 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4192 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004193}
4194
Jamie Madill01a80ee2016-11-07 12:06:18 -05004195void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4196{
4197 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4198 {
4199 bindReadFramebuffer(framebuffer);
4200 }
4201
4202 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4203 {
4204 bindDrawFramebuffer(framebuffer);
4205 }
4206}
4207
4208void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4209{
4210 ASSERT(target == GL_RENDERBUFFER);
4211 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004212 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004213 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004214}
4215
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004216void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004217 GLsizei samples,
4218 GLenum internalformat,
4219 GLsizei width,
4220 GLsizei height,
4221 GLboolean fixedsamplelocations)
4222{
4223 Extents size(width, height, 1);
4224 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004225 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
4226 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004227}
4228
4229void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4230{
JiangYizhou5b03f472017-01-09 10:22:53 +08004231 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4232 // the sample position should be queried by DRAW_FRAMEBUFFER.
4233 mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER);
4234 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004235
4236 switch (pname)
4237 {
4238 case GL_SAMPLE_POSITION:
4239 handleError(framebuffer->getSamplePosition(index, val));
4240 break;
4241 default:
4242 UNREACHABLE();
4243 }
4244}
4245
Jamie Madille8fb6402017-02-14 17:56:40 -05004246void Context::renderbufferStorage(GLenum target,
4247 GLenum internalformat,
4248 GLsizei width,
4249 GLsizei height)
4250{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004251 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4252 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4253
Jamie Madille8fb6402017-02-14 17:56:40 -05004254 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004255 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004256}
4257
4258void Context::renderbufferStorageMultisample(GLenum target,
4259 GLsizei samples,
4260 GLenum internalformat,
4261 GLsizei width,
4262 GLsizei height)
4263{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004264 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4265 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004266
4267 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004268 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004269 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004270}
4271
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004272void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4273{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004274 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004275 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004276}
4277
JiangYizhoue18e6392017-02-20 10:32:23 +08004278void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4279{
4280 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4281 QueryFramebufferParameteriv(framebuffer, pname, params);
4282}
4283
Jiajia Qin5451d532017-11-16 17:16:34 +08004284void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004285{
4286 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4287 SetFramebufferParameteri(framebuffer, pname, param);
4288}
4289
Jamie Madillb3f26b92017-07-19 15:07:41 -04004290Error Context::getScratchBuffer(size_t requstedSizeBytes,
4291 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004292{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004293 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4294 {
4295 return OutOfMemory() << "Failed to allocate internal buffer.";
4296 }
4297 return NoError();
4298}
4299
4300Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4301 angle::MemoryBuffer **zeroBufferOut) const
4302{
4303 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004304 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004305 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004306 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004307 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004308}
4309
Xinghua Cao10a4d432017-11-28 14:46:26 +08004310Error Context::prepareForDispatch()
4311{
4312 syncRendererState(mComputeDirtyBits, mComputeDirtyObjects);
4313
4314 if (isRobustResourceInitEnabled())
4315 {
4316 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4317 }
4318
4319 return NoError();
4320}
4321
Xinghua Cao2b396592017-03-29 15:36:04 +08004322void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4323{
4324 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4325 {
4326 return;
4327 }
4328
Xinghua Cao10a4d432017-11-28 14:46:26 +08004329 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004330 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004331}
4332
Jiajia Qin5451d532017-11-16 17:16:34 +08004333void Context::dispatchComputeIndirect(GLintptr indirect)
4334{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004335 ANGLE_CONTEXT_TRY(prepareForDispatch());
4336 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004337}
4338
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004339void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004340 GLsizei levels,
4341 GLenum internalFormat,
4342 GLsizei width,
4343 GLsizei height)
4344{
4345 Extents size(width, height, 1);
4346 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004347 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004348}
4349
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004350void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004351 GLsizei levels,
4352 GLenum internalFormat,
4353 GLsizei width,
4354 GLsizei height,
4355 GLsizei depth)
4356{
4357 Extents size(width, height, depth);
4358 Texture *texture = getTargetTexture(target);
Corentin Wallez99d492c2018-02-27 15:17:10 -05004359 handleError(texture->setStorage(this, target, levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004360}
4361
Jiajia Qin5451d532017-11-16 17:16:34 +08004362void Context::memoryBarrier(GLbitfield barriers)
4363{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004364 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004365}
4366
4367void Context::memoryBarrierByRegion(GLbitfield barriers)
4368{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004369 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004370}
4371
Jamie Madillc1d770e2017-04-13 17:31:24 -04004372GLenum Context::checkFramebufferStatus(GLenum target)
4373{
4374 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4375 ASSERT(framebuffer);
4376
4377 return framebuffer->checkStatus(this);
4378}
4379
4380void Context::compileShader(GLuint shader)
4381{
4382 Shader *shaderObject = GetValidShader(this, shader);
4383 if (!shaderObject)
4384 {
4385 return;
4386 }
4387 shaderObject->compile(this);
4388}
4389
4390void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4391{
4392 for (int i = 0; i < n; i++)
4393 {
4394 deleteBuffer(buffers[i]);
4395 }
4396}
4397
4398void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4399{
4400 for (int i = 0; i < n; i++)
4401 {
4402 if (framebuffers[i] != 0)
4403 {
4404 deleteFramebuffer(framebuffers[i]);
4405 }
4406 }
4407}
4408
4409void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4410{
4411 for (int i = 0; i < n; i++)
4412 {
4413 deleteRenderbuffer(renderbuffers[i]);
4414 }
4415}
4416
4417void Context::deleteTextures(GLsizei n, const GLuint *textures)
4418{
4419 for (int i = 0; i < n; i++)
4420 {
4421 if (textures[i] != 0)
4422 {
4423 deleteTexture(textures[i]);
4424 }
4425 }
4426}
4427
4428void Context::detachShader(GLuint program, GLuint shader)
4429{
4430 Program *programObject = getProgram(program);
4431 ASSERT(programObject);
4432
4433 Shader *shaderObject = getShader(shader);
4434 ASSERT(shaderObject);
4435
4436 programObject->detachShader(this, shaderObject);
4437}
4438
4439void Context::genBuffers(GLsizei n, GLuint *buffers)
4440{
4441 for (int i = 0; i < n; i++)
4442 {
4443 buffers[i] = createBuffer();
4444 }
4445}
4446
4447void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4448{
4449 for (int i = 0; i < n; i++)
4450 {
4451 framebuffers[i] = createFramebuffer();
4452 }
4453}
4454
4455void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4456{
4457 for (int i = 0; i < n; i++)
4458 {
4459 renderbuffers[i] = createRenderbuffer();
4460 }
4461}
4462
4463void Context::genTextures(GLsizei n, GLuint *textures)
4464{
4465 for (int i = 0; i < n; i++)
4466 {
4467 textures[i] = createTexture();
4468 }
4469}
4470
4471void Context::getActiveAttrib(GLuint program,
4472 GLuint index,
4473 GLsizei bufsize,
4474 GLsizei *length,
4475 GLint *size,
4476 GLenum *type,
4477 GLchar *name)
4478{
4479 Program *programObject = getProgram(program);
4480 ASSERT(programObject);
4481 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4482}
4483
4484void Context::getActiveUniform(GLuint program,
4485 GLuint index,
4486 GLsizei bufsize,
4487 GLsizei *length,
4488 GLint *size,
4489 GLenum *type,
4490 GLchar *name)
4491{
4492 Program *programObject = getProgram(program);
4493 ASSERT(programObject);
4494 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4495}
4496
4497void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4498{
4499 Program *programObject = getProgram(program);
4500 ASSERT(programObject);
4501 programObject->getAttachedShaders(maxcount, count, shaders);
4502}
4503
4504GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4505{
4506 Program *programObject = getProgram(program);
4507 ASSERT(programObject);
4508 return programObject->getAttributeLocation(name);
4509}
4510
4511void Context::getBooleanv(GLenum pname, GLboolean *params)
4512{
4513 GLenum nativeType;
4514 unsigned int numParams = 0;
4515 getQueryParameterInfo(pname, &nativeType, &numParams);
4516
4517 if (nativeType == GL_BOOL)
4518 {
4519 getBooleanvImpl(pname, params);
4520 }
4521 else
4522 {
4523 CastStateValues(this, nativeType, pname, numParams, params);
4524 }
4525}
4526
4527void Context::getFloatv(GLenum pname, GLfloat *params)
4528{
4529 GLenum nativeType;
4530 unsigned int numParams = 0;
4531 getQueryParameterInfo(pname, &nativeType, &numParams);
4532
4533 if (nativeType == GL_FLOAT)
4534 {
4535 getFloatvImpl(pname, params);
4536 }
4537 else
4538 {
4539 CastStateValues(this, nativeType, pname, numParams, params);
4540 }
4541}
4542
4543void Context::getIntegerv(GLenum pname, GLint *params)
4544{
4545 GLenum nativeType;
4546 unsigned int numParams = 0;
4547 getQueryParameterInfo(pname, &nativeType, &numParams);
4548
4549 if (nativeType == GL_INT)
4550 {
4551 getIntegervImpl(pname, params);
4552 }
4553 else
4554 {
4555 CastStateValues(this, nativeType, pname, numParams, params);
4556 }
4557}
4558
4559void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4560{
4561 Program *programObject = getProgram(program);
4562 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004563 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004564}
4565
Jiajia Qin5451d532017-11-16 17:16:34 +08004566void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
4567{
4568 UNIMPLEMENTED();
4569}
4570
Jamie Madillbe849e42017-05-02 15:49:00 -04004571void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004572{
4573 Program *programObject = getProgram(program);
4574 ASSERT(programObject);
4575 programObject->getInfoLog(bufsize, length, infolog);
4576}
4577
Jiajia Qin5451d532017-11-16 17:16:34 +08004578void Context::getProgramPipelineInfoLog(GLuint pipeline,
4579 GLsizei bufSize,
4580 GLsizei *length,
4581 GLchar *infoLog)
4582{
4583 UNIMPLEMENTED();
4584}
4585
Jamie Madillc1d770e2017-04-13 17:31:24 -04004586void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4587{
4588 Shader *shaderObject = getShader(shader);
4589 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004590 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004591}
4592
4593void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4594{
4595 Shader *shaderObject = getShader(shader);
4596 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004597 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004598}
4599
4600void Context::getShaderPrecisionFormat(GLenum shadertype,
4601 GLenum precisiontype,
4602 GLint *range,
4603 GLint *precision)
4604{
4605 // TODO(jmadill): Compute shaders.
4606
4607 switch (shadertype)
4608 {
4609 case GL_VERTEX_SHADER:
4610 switch (precisiontype)
4611 {
4612 case GL_LOW_FLOAT:
4613 mCaps.vertexLowpFloat.get(range, precision);
4614 break;
4615 case GL_MEDIUM_FLOAT:
4616 mCaps.vertexMediumpFloat.get(range, precision);
4617 break;
4618 case GL_HIGH_FLOAT:
4619 mCaps.vertexHighpFloat.get(range, precision);
4620 break;
4621
4622 case GL_LOW_INT:
4623 mCaps.vertexLowpInt.get(range, precision);
4624 break;
4625 case GL_MEDIUM_INT:
4626 mCaps.vertexMediumpInt.get(range, precision);
4627 break;
4628 case GL_HIGH_INT:
4629 mCaps.vertexHighpInt.get(range, precision);
4630 break;
4631
4632 default:
4633 UNREACHABLE();
4634 return;
4635 }
4636 break;
4637
4638 case GL_FRAGMENT_SHADER:
4639 switch (precisiontype)
4640 {
4641 case GL_LOW_FLOAT:
4642 mCaps.fragmentLowpFloat.get(range, precision);
4643 break;
4644 case GL_MEDIUM_FLOAT:
4645 mCaps.fragmentMediumpFloat.get(range, precision);
4646 break;
4647 case GL_HIGH_FLOAT:
4648 mCaps.fragmentHighpFloat.get(range, precision);
4649 break;
4650
4651 case GL_LOW_INT:
4652 mCaps.fragmentLowpInt.get(range, precision);
4653 break;
4654 case GL_MEDIUM_INT:
4655 mCaps.fragmentMediumpInt.get(range, precision);
4656 break;
4657 case GL_HIGH_INT:
4658 mCaps.fragmentHighpInt.get(range, precision);
4659 break;
4660
4661 default:
4662 UNREACHABLE();
4663 return;
4664 }
4665 break;
4666
4667 default:
4668 UNREACHABLE();
4669 return;
4670 }
4671}
4672
4673void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4674{
4675 Shader *shaderObject = getShader(shader);
4676 ASSERT(shaderObject);
4677 shaderObject->getSource(bufsize, length, source);
4678}
4679
4680void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4681{
4682 Program *programObject = getProgram(program);
4683 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004684 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004685}
4686
4687void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4688{
4689 Program *programObject = getProgram(program);
4690 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004691 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004692}
4693
4694GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4695{
4696 Program *programObject = getProgram(program);
4697 ASSERT(programObject);
4698 return programObject->getUniformLocation(name);
4699}
4700
4701GLboolean Context::isBuffer(GLuint buffer)
4702{
4703 if (buffer == 0)
4704 {
4705 return GL_FALSE;
4706 }
4707
4708 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4709}
4710
4711GLboolean Context::isEnabled(GLenum cap)
4712{
4713 return mGLState.getEnableFeature(cap);
4714}
4715
4716GLboolean Context::isFramebuffer(GLuint framebuffer)
4717{
4718 if (framebuffer == 0)
4719 {
4720 return GL_FALSE;
4721 }
4722
4723 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4724}
4725
4726GLboolean Context::isProgram(GLuint program)
4727{
4728 if (program == 0)
4729 {
4730 return GL_FALSE;
4731 }
4732
4733 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4734}
4735
4736GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4737{
4738 if (renderbuffer == 0)
4739 {
4740 return GL_FALSE;
4741 }
4742
4743 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4744}
4745
4746GLboolean Context::isShader(GLuint shader)
4747{
4748 if (shader == 0)
4749 {
4750 return GL_FALSE;
4751 }
4752
4753 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4754}
4755
4756GLboolean Context::isTexture(GLuint texture)
4757{
4758 if (texture == 0)
4759 {
4760 return GL_FALSE;
4761 }
4762
4763 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4764}
4765
4766void Context::linkProgram(GLuint program)
4767{
4768 Program *programObject = getProgram(program);
4769 ASSERT(programObject);
4770 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004771 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004772}
4773
4774void Context::releaseShaderCompiler()
4775{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004776 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004777}
4778
4779void Context::shaderBinary(GLsizei n,
4780 const GLuint *shaders,
4781 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004782 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004783 GLsizei length)
4784{
4785 // No binary shader formats are supported.
4786 UNIMPLEMENTED();
4787}
4788
4789void Context::shaderSource(GLuint shader,
4790 GLsizei count,
4791 const GLchar *const *string,
4792 const GLint *length)
4793{
4794 Shader *shaderObject = getShader(shader);
4795 ASSERT(shaderObject);
4796 shaderObject->setSource(count, string, length);
4797}
4798
4799void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4800{
4801 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4802}
4803
4804void Context::stencilMask(GLuint mask)
4805{
4806 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4807}
4808
4809void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4810{
4811 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4812}
4813
4814void Context::uniform1f(GLint location, GLfloat x)
4815{
4816 Program *program = mGLState.getProgram();
4817 program->setUniform1fv(location, 1, &x);
4818}
4819
4820void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4821{
4822 Program *program = mGLState.getProgram();
4823 program->setUniform1fv(location, count, v);
4824}
4825
4826void Context::uniform1i(GLint location, GLint x)
4827{
4828 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004829 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4830 {
4831 mGLState.setObjectDirty(GL_PROGRAM);
4832 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004833}
4834
4835void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4836{
4837 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004838 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4839 {
4840 mGLState.setObjectDirty(GL_PROGRAM);
4841 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004842}
4843
4844void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4845{
4846 GLfloat xy[2] = {x, y};
4847 Program *program = mGLState.getProgram();
4848 program->setUniform2fv(location, 1, xy);
4849}
4850
4851void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4852{
4853 Program *program = mGLState.getProgram();
4854 program->setUniform2fv(location, count, v);
4855}
4856
4857void Context::uniform2i(GLint location, GLint x, GLint y)
4858{
4859 GLint xy[2] = {x, y};
4860 Program *program = mGLState.getProgram();
4861 program->setUniform2iv(location, 1, xy);
4862}
4863
4864void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4865{
4866 Program *program = mGLState.getProgram();
4867 program->setUniform2iv(location, count, v);
4868}
4869
4870void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4871{
4872 GLfloat xyz[3] = {x, y, z};
4873 Program *program = mGLState.getProgram();
4874 program->setUniform3fv(location, 1, xyz);
4875}
4876
4877void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4878{
4879 Program *program = mGLState.getProgram();
4880 program->setUniform3fv(location, count, v);
4881}
4882
4883void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4884{
4885 GLint xyz[3] = {x, y, z};
4886 Program *program = mGLState.getProgram();
4887 program->setUniform3iv(location, 1, xyz);
4888}
4889
4890void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4891{
4892 Program *program = mGLState.getProgram();
4893 program->setUniform3iv(location, count, v);
4894}
4895
4896void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4897{
4898 GLfloat xyzw[4] = {x, y, z, w};
4899 Program *program = mGLState.getProgram();
4900 program->setUniform4fv(location, 1, xyzw);
4901}
4902
4903void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4904{
4905 Program *program = mGLState.getProgram();
4906 program->setUniform4fv(location, count, v);
4907}
4908
4909void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4910{
4911 GLint xyzw[4] = {x, y, z, w};
4912 Program *program = mGLState.getProgram();
4913 program->setUniform4iv(location, 1, xyzw);
4914}
4915
4916void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4917{
4918 Program *program = mGLState.getProgram();
4919 program->setUniform4iv(location, count, v);
4920}
4921
4922void Context::uniformMatrix2fv(GLint location,
4923 GLsizei count,
4924 GLboolean transpose,
4925 const GLfloat *value)
4926{
4927 Program *program = mGLState.getProgram();
4928 program->setUniformMatrix2fv(location, count, transpose, value);
4929}
4930
4931void Context::uniformMatrix3fv(GLint location,
4932 GLsizei count,
4933 GLboolean transpose,
4934 const GLfloat *value)
4935{
4936 Program *program = mGLState.getProgram();
4937 program->setUniformMatrix3fv(location, count, transpose, value);
4938}
4939
4940void Context::uniformMatrix4fv(GLint location,
4941 GLsizei count,
4942 GLboolean transpose,
4943 const GLfloat *value)
4944{
4945 Program *program = mGLState.getProgram();
4946 program->setUniformMatrix4fv(location, count, transpose, value);
4947}
4948
4949void Context::validateProgram(GLuint program)
4950{
4951 Program *programObject = getProgram(program);
4952 ASSERT(programObject);
4953 programObject->validate(mCaps);
4954}
4955
Jiajia Qin5451d532017-11-16 17:16:34 +08004956void Context::validateProgramPipeline(GLuint pipeline)
4957{
4958 UNIMPLEMENTED();
4959}
4960
Jamie Madilld04908b2017-06-09 14:15:35 -04004961void Context::getProgramBinary(GLuint program,
4962 GLsizei bufSize,
4963 GLsizei *length,
4964 GLenum *binaryFormat,
4965 void *binary)
4966{
4967 Program *programObject = getProgram(program);
4968 ASSERT(programObject != nullptr);
4969
4970 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4971}
4972
4973void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4974{
4975 Program *programObject = getProgram(program);
4976 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04004977
Jamie Madilld04908b2017-06-09 14:15:35 -04004978 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
4979}
4980
Jamie Madillff325f12017-08-26 15:06:05 -04004981void Context::uniform1ui(GLint location, GLuint v0)
4982{
4983 Program *program = mGLState.getProgram();
4984 program->setUniform1uiv(location, 1, &v0);
4985}
4986
4987void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
4988{
4989 Program *program = mGLState.getProgram();
4990 const GLuint xy[] = {v0, v1};
4991 program->setUniform2uiv(location, 1, xy);
4992}
4993
4994void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
4995{
4996 Program *program = mGLState.getProgram();
4997 const GLuint xyz[] = {v0, v1, v2};
4998 program->setUniform3uiv(location, 1, xyz);
4999}
5000
5001void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5002{
5003 Program *program = mGLState.getProgram();
5004 const GLuint xyzw[] = {v0, v1, v2, v3};
5005 program->setUniform4uiv(location, 1, xyzw);
5006}
5007
5008void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5009{
5010 Program *program = mGLState.getProgram();
5011 program->setUniform1uiv(location, count, value);
5012}
5013void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5014{
5015 Program *program = mGLState.getProgram();
5016 program->setUniform2uiv(location, count, value);
5017}
5018
5019void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5020{
5021 Program *program = mGLState.getProgram();
5022 program->setUniform3uiv(location, count, value);
5023}
5024
5025void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5026{
5027 Program *program = mGLState.getProgram();
5028 program->setUniform4uiv(location, count, value);
5029}
5030
Jamie Madillf0e04492017-08-26 15:28:42 -04005031void Context::genQueries(GLsizei n, GLuint *ids)
5032{
5033 for (GLsizei i = 0; i < n; i++)
5034 {
5035 GLuint handle = mQueryHandleAllocator.allocate();
5036 mQueryMap.assign(handle, nullptr);
5037 ids[i] = handle;
5038 }
5039}
5040
5041void Context::deleteQueries(GLsizei n, const GLuint *ids)
5042{
5043 for (int i = 0; i < n; i++)
5044 {
5045 GLuint query = ids[i];
5046
5047 Query *queryObject = nullptr;
5048 if (mQueryMap.erase(query, &queryObject))
5049 {
5050 mQueryHandleAllocator.release(query);
5051 if (queryObject)
5052 {
5053 queryObject->release(this);
5054 }
5055 }
5056 }
5057}
5058
5059GLboolean Context::isQuery(GLuint id)
5060{
5061 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
5062}
5063
Jamie Madillc8c95812017-08-26 18:40:09 -04005064void Context::uniformMatrix2x3fv(GLint location,
5065 GLsizei count,
5066 GLboolean transpose,
5067 const GLfloat *value)
5068{
5069 Program *program = mGLState.getProgram();
5070 program->setUniformMatrix2x3fv(location, count, transpose, value);
5071}
5072
5073void Context::uniformMatrix3x2fv(GLint location,
5074 GLsizei count,
5075 GLboolean transpose,
5076 const GLfloat *value)
5077{
5078 Program *program = mGLState.getProgram();
5079 program->setUniformMatrix3x2fv(location, count, transpose, value);
5080}
5081
5082void Context::uniformMatrix2x4fv(GLint location,
5083 GLsizei count,
5084 GLboolean transpose,
5085 const GLfloat *value)
5086{
5087 Program *program = mGLState.getProgram();
5088 program->setUniformMatrix2x4fv(location, count, transpose, value);
5089}
5090
5091void Context::uniformMatrix4x2fv(GLint location,
5092 GLsizei count,
5093 GLboolean transpose,
5094 const GLfloat *value)
5095{
5096 Program *program = mGLState.getProgram();
5097 program->setUniformMatrix4x2fv(location, count, transpose, value);
5098}
5099
5100void Context::uniformMatrix3x4fv(GLint location,
5101 GLsizei count,
5102 GLboolean transpose,
5103 const GLfloat *value)
5104{
5105 Program *program = mGLState.getProgram();
5106 program->setUniformMatrix3x4fv(location, count, transpose, value);
5107}
5108
5109void Context::uniformMatrix4x3fv(GLint location,
5110 GLsizei count,
5111 GLboolean transpose,
5112 const GLfloat *value)
5113{
5114 Program *program = mGLState.getProgram();
5115 program->setUniformMatrix4x3fv(location, count, transpose, value);
5116}
5117
Jamie Madilld7576732017-08-26 18:49:50 -04005118void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5119{
5120 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5121 {
5122 GLuint vertexArray = arrays[arrayIndex];
5123
5124 if (arrays[arrayIndex] != 0)
5125 {
5126 VertexArray *vertexArrayObject = nullptr;
5127 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5128 {
5129 if (vertexArrayObject != nullptr)
5130 {
5131 detachVertexArray(vertexArray);
5132 vertexArrayObject->onDestroy(this);
5133 }
5134
5135 mVertexArrayHandleAllocator.release(vertexArray);
5136 }
5137 }
5138 }
5139}
5140
5141void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5142{
5143 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5144 {
5145 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5146 mVertexArrayMap.assign(vertexArray, nullptr);
5147 arrays[arrayIndex] = vertexArray;
5148 }
5149}
5150
5151bool Context::isVertexArray(GLuint array)
5152{
5153 if (array == 0)
5154 {
5155 return GL_FALSE;
5156 }
5157
5158 VertexArray *vao = getVertexArray(array);
5159 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5160}
5161
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005162void Context::endTransformFeedback()
5163{
5164 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5165 transformFeedback->end(this);
5166}
5167
5168void Context::transformFeedbackVaryings(GLuint program,
5169 GLsizei count,
5170 const GLchar *const *varyings,
5171 GLenum bufferMode)
5172{
5173 Program *programObject = getProgram(program);
5174 ASSERT(programObject);
5175 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5176}
5177
5178void Context::getTransformFeedbackVarying(GLuint program,
5179 GLuint index,
5180 GLsizei bufSize,
5181 GLsizei *length,
5182 GLsizei *size,
5183 GLenum *type,
5184 GLchar *name)
5185{
5186 Program *programObject = getProgram(program);
5187 ASSERT(programObject);
5188 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5189}
5190
5191void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5192{
5193 for (int i = 0; i < n; i++)
5194 {
5195 GLuint transformFeedback = ids[i];
5196 if (transformFeedback == 0)
5197 {
5198 continue;
5199 }
5200
5201 TransformFeedback *transformFeedbackObject = nullptr;
5202 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5203 {
5204 if (transformFeedbackObject != nullptr)
5205 {
5206 detachTransformFeedback(transformFeedback);
5207 transformFeedbackObject->release(this);
5208 }
5209
5210 mTransformFeedbackHandleAllocator.release(transformFeedback);
5211 }
5212 }
5213}
5214
5215void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5216{
5217 for (int i = 0; i < n; i++)
5218 {
5219 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5220 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5221 ids[i] = transformFeedback;
5222 }
5223}
5224
5225bool Context::isTransformFeedback(GLuint id)
5226{
5227 if (id == 0)
5228 {
5229 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5230 // returns FALSE
5231 return GL_FALSE;
5232 }
5233
5234 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5235 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5236}
5237
5238void Context::pauseTransformFeedback()
5239{
5240 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5241 transformFeedback->pause();
5242}
5243
5244void Context::resumeTransformFeedback()
5245{
5246 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5247 transformFeedback->resume();
5248}
5249
Jamie Madill12e957f2017-08-26 21:42:26 -04005250void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5251{
5252 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005253 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005254}
5255
5256GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5257{
5258 const Program *programObject = getProgram(program);
5259 return programObject->getFragDataLocation(name);
5260}
5261
5262void Context::getUniformIndices(GLuint program,
5263 GLsizei uniformCount,
5264 const GLchar *const *uniformNames,
5265 GLuint *uniformIndices)
5266{
5267 const Program *programObject = getProgram(program);
5268 if (!programObject->isLinked())
5269 {
5270 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5271 {
5272 uniformIndices[uniformId] = GL_INVALID_INDEX;
5273 }
5274 }
5275 else
5276 {
5277 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5278 {
5279 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5280 }
5281 }
5282}
5283
5284void Context::getActiveUniformsiv(GLuint program,
5285 GLsizei uniformCount,
5286 const GLuint *uniformIndices,
5287 GLenum pname,
5288 GLint *params)
5289{
5290 const Program *programObject = getProgram(program);
5291 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5292 {
5293 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005294 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005295 }
5296}
5297
5298GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5299{
5300 const Program *programObject = getProgram(program);
5301 return programObject->getUniformBlockIndex(uniformBlockName);
5302}
5303
5304void Context::getActiveUniformBlockiv(GLuint program,
5305 GLuint uniformBlockIndex,
5306 GLenum pname,
5307 GLint *params)
5308{
5309 const Program *programObject = getProgram(program);
5310 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5311}
5312
5313void Context::getActiveUniformBlockName(GLuint program,
5314 GLuint uniformBlockIndex,
5315 GLsizei bufSize,
5316 GLsizei *length,
5317 GLchar *uniformBlockName)
5318{
5319 const Program *programObject = getProgram(program);
5320 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5321}
5322
5323void Context::uniformBlockBinding(GLuint program,
5324 GLuint uniformBlockIndex,
5325 GLuint uniformBlockBinding)
5326{
5327 Program *programObject = getProgram(program);
5328 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5329}
5330
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005331GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5332{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005333 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5334 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005335
Jamie Madill70b5bb02017-08-28 13:32:37 -04005336 Sync *syncObject = getSync(syncHandle);
5337 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005338 if (error.isError())
5339 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005340 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005341 handleError(error);
5342 return nullptr;
5343 }
5344
Jamie Madill70b5bb02017-08-28 13:32:37 -04005345 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005346}
5347
5348GLboolean Context::isSync(GLsync sync)
5349{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005350 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005351}
5352
5353GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5354{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005355 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005356
5357 GLenum result = GL_WAIT_FAILED;
5358 handleError(syncObject->clientWait(flags, timeout, &result));
5359 return result;
5360}
5361
5362void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5363{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005364 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005365 handleError(syncObject->serverWait(flags, timeout));
5366}
5367
5368void Context::getInteger64v(GLenum pname, GLint64 *params)
5369{
5370 GLenum nativeType = GL_NONE;
5371 unsigned int numParams = 0;
5372 getQueryParameterInfo(pname, &nativeType, &numParams);
5373
5374 if (nativeType == GL_INT_64_ANGLEX)
5375 {
5376 getInteger64vImpl(pname, params);
5377 }
5378 else
5379 {
5380 CastStateValues(this, nativeType, pname, numParams, params);
5381 }
5382}
5383
Corentin Wallez336129f2017-10-17 15:55:40 -04005384void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04005385{
5386 Buffer *buffer = mGLState.getTargetBuffer(target);
5387 QueryBufferParameteri64v(buffer, pname, params);
5388}
5389
5390void Context::genSamplers(GLsizei count, GLuint *samplers)
5391{
5392 for (int i = 0; i < count; i++)
5393 {
5394 samplers[i] = mState.mSamplers->createSampler();
5395 }
5396}
5397
5398void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5399{
5400 for (int i = 0; i < count; i++)
5401 {
5402 GLuint sampler = samplers[i];
5403
5404 if (mState.mSamplers->getSampler(sampler))
5405 {
5406 detachSampler(sampler);
5407 }
5408
5409 mState.mSamplers->deleteObject(this, sampler);
5410 }
5411}
5412
5413void Context::getInternalformativ(GLenum target,
5414 GLenum internalformat,
5415 GLenum pname,
5416 GLsizei bufSize,
5417 GLint *params)
5418{
5419 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5420 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5421}
5422
Jiajia Qin5451d532017-11-16 17:16:34 +08005423void Context::programUniform1i(GLuint program, GLint location, GLint v0)
5424{
5425 programUniform1iv(program, location, 1, &v0);
5426}
5427
5428void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
5429{
5430 GLint xy[2] = {v0, v1};
5431 programUniform2iv(program, location, 1, xy);
5432}
5433
5434void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
5435{
5436 GLint xyz[3] = {v0, v1, v2};
5437 programUniform3iv(program, location, 1, xyz);
5438}
5439
5440void Context::programUniform4i(GLuint program,
5441 GLint location,
5442 GLint v0,
5443 GLint v1,
5444 GLint v2,
5445 GLint v3)
5446{
5447 GLint xyzw[4] = {v0, v1, v2, v3};
5448 programUniform4iv(program, location, 1, xyzw);
5449}
5450
5451void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
5452{
5453 programUniform1uiv(program, location, 1, &v0);
5454}
5455
5456void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
5457{
5458 GLuint xy[2] = {v0, v1};
5459 programUniform2uiv(program, location, 1, xy);
5460}
5461
5462void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
5463{
5464 GLuint xyz[3] = {v0, v1, v2};
5465 programUniform3uiv(program, location, 1, xyz);
5466}
5467
5468void Context::programUniform4ui(GLuint program,
5469 GLint location,
5470 GLuint v0,
5471 GLuint v1,
5472 GLuint v2,
5473 GLuint v3)
5474{
5475 GLuint xyzw[4] = {v0, v1, v2, v3};
5476 programUniform4uiv(program, location, 1, xyzw);
5477}
5478
5479void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
5480{
5481 programUniform1fv(program, location, 1, &v0);
5482}
5483
5484void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
5485{
5486 GLfloat xy[2] = {v0, v1};
5487 programUniform2fv(program, location, 1, xy);
5488}
5489
5490void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
5491{
5492 GLfloat xyz[3] = {v0, v1, v2};
5493 programUniform3fv(program, location, 1, xyz);
5494}
5495
5496void Context::programUniform4f(GLuint program,
5497 GLint location,
5498 GLfloat v0,
5499 GLfloat v1,
5500 GLfloat v2,
5501 GLfloat v3)
5502{
5503 GLfloat xyzw[4] = {v0, v1, v2, v3};
5504 programUniform4fv(program, location, 1, xyzw);
5505}
5506
Jamie Madill81c2e252017-09-09 23:32:46 -04005507void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5508{
5509 Program *programObject = getProgram(program);
5510 ASSERT(programObject);
5511 if (programObject->setUniform1iv(location, count, value) ==
5512 Program::SetUniformResult::SamplerChanged)
5513 {
5514 mGLState.setObjectDirty(GL_PROGRAM);
5515 }
5516}
5517
Jiajia Qin5451d532017-11-16 17:16:34 +08005518void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5519{
5520 Program *programObject = getProgram(program);
5521 ASSERT(programObject);
5522 programObject->setUniform2iv(location, count, value);
5523}
5524
5525void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5526{
5527 Program *programObject = getProgram(program);
5528 ASSERT(programObject);
5529 programObject->setUniform3iv(location, count, value);
5530}
5531
5532void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5533{
5534 Program *programObject = getProgram(program);
5535 ASSERT(programObject);
5536 programObject->setUniform4iv(location, count, value);
5537}
5538
5539void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5540{
5541 Program *programObject = getProgram(program);
5542 ASSERT(programObject);
5543 programObject->setUniform1uiv(location, count, value);
5544}
5545
5546void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5547{
5548 Program *programObject = getProgram(program);
5549 ASSERT(programObject);
5550 programObject->setUniform2uiv(location, count, value);
5551}
5552
5553void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5554{
5555 Program *programObject = getProgram(program);
5556 ASSERT(programObject);
5557 programObject->setUniform3uiv(location, count, value);
5558}
5559
5560void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5561{
5562 Program *programObject = getProgram(program);
5563 ASSERT(programObject);
5564 programObject->setUniform4uiv(location, count, value);
5565}
5566
5567void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5568{
5569 Program *programObject = getProgram(program);
5570 ASSERT(programObject);
5571 programObject->setUniform1fv(location, count, value);
5572}
5573
5574void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5575{
5576 Program *programObject = getProgram(program);
5577 ASSERT(programObject);
5578 programObject->setUniform2fv(location, count, value);
5579}
5580
5581void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5582{
5583 Program *programObject = getProgram(program);
5584 ASSERT(programObject);
5585 programObject->setUniform3fv(location, count, value);
5586}
5587
5588void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5589{
5590 Program *programObject = getProgram(program);
5591 ASSERT(programObject);
5592 programObject->setUniform4fv(location, count, value);
5593}
5594
5595void Context::programUniformMatrix2fv(GLuint program,
5596 GLint location,
5597 GLsizei count,
5598 GLboolean transpose,
5599 const GLfloat *value)
5600{
5601 Program *programObject = getProgram(program);
5602 ASSERT(programObject);
5603 programObject->setUniformMatrix2fv(location, count, transpose, value);
5604}
5605
5606void Context::programUniformMatrix3fv(GLuint program,
5607 GLint location,
5608 GLsizei count,
5609 GLboolean transpose,
5610 const GLfloat *value)
5611{
5612 Program *programObject = getProgram(program);
5613 ASSERT(programObject);
5614 programObject->setUniformMatrix3fv(location, count, transpose, value);
5615}
5616
5617void Context::programUniformMatrix4fv(GLuint program,
5618 GLint location,
5619 GLsizei count,
5620 GLboolean transpose,
5621 const GLfloat *value)
5622{
5623 Program *programObject = getProgram(program);
5624 ASSERT(programObject);
5625 programObject->setUniformMatrix4fv(location, count, transpose, value);
5626}
5627
5628void Context::programUniformMatrix2x3fv(GLuint program,
5629 GLint location,
5630 GLsizei count,
5631 GLboolean transpose,
5632 const GLfloat *value)
5633{
5634 Program *programObject = getProgram(program);
5635 ASSERT(programObject);
5636 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
5637}
5638
5639void Context::programUniformMatrix3x2fv(GLuint program,
5640 GLint location,
5641 GLsizei count,
5642 GLboolean transpose,
5643 const GLfloat *value)
5644{
5645 Program *programObject = getProgram(program);
5646 ASSERT(programObject);
5647 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
5648}
5649
5650void Context::programUniformMatrix2x4fv(GLuint program,
5651 GLint location,
5652 GLsizei count,
5653 GLboolean transpose,
5654 const GLfloat *value)
5655{
5656 Program *programObject = getProgram(program);
5657 ASSERT(programObject);
5658 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
5659}
5660
5661void Context::programUniformMatrix4x2fv(GLuint program,
5662 GLint location,
5663 GLsizei count,
5664 GLboolean transpose,
5665 const GLfloat *value)
5666{
5667 Program *programObject = getProgram(program);
5668 ASSERT(programObject);
5669 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
5670}
5671
5672void Context::programUniformMatrix3x4fv(GLuint program,
5673 GLint location,
5674 GLsizei count,
5675 GLboolean transpose,
5676 const GLfloat *value)
5677{
5678 Program *programObject = getProgram(program);
5679 ASSERT(programObject);
5680 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
5681}
5682
5683void Context::programUniformMatrix4x3fv(GLuint program,
5684 GLint location,
5685 GLsizei count,
5686 GLboolean transpose,
5687 const GLfloat *value)
5688{
5689 Program *programObject = getProgram(program);
5690 ASSERT(programObject);
5691 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
5692}
5693
Jamie Madill81c2e252017-09-09 23:32:46 -04005694void Context::onTextureChange(const Texture *texture)
5695{
5696 // Conservatively assume all textures are dirty.
5697 // TODO(jmadill): More fine-grained update.
5698 mGLState.setObjectDirty(GL_TEXTURE);
5699}
5700
Yunchao Hea336b902017-08-02 16:05:21 +08005701void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5702{
5703 for (int i = 0; i < count; i++)
5704 {
5705 pipelines[i] = createProgramPipeline();
5706 }
5707}
5708
5709void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5710{
5711 for (int i = 0; i < count; i++)
5712 {
5713 if (pipelines[i] != 0)
5714 {
5715 deleteProgramPipeline(pipelines[i]);
5716 }
5717 }
5718}
5719
5720GLboolean Context::isProgramPipeline(GLuint pipeline)
5721{
5722 if (pipeline == 0)
5723 {
5724 return GL_FALSE;
5725 }
5726
5727 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5728}
5729
Jamie Madill2b7bbc22017-12-21 17:30:38 -05005730void Context::finishFenceNV(GLuint fence)
5731{
5732 FenceNV *fenceObject = getFenceNV(fence);
5733
5734 ASSERT(fenceObject && fenceObject->isSet());
5735 handleError(fenceObject->finish());
5736}
5737
5738void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
5739{
5740 FenceNV *fenceObject = getFenceNV(fence);
5741
5742 ASSERT(fenceObject && fenceObject->isSet());
5743
5744 switch (pname)
5745 {
5746 case GL_FENCE_STATUS_NV:
5747 {
5748 // GL_NV_fence spec:
5749 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
5750 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
5751 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
5752 GLboolean status = GL_TRUE;
5753 if (fenceObject->getStatus() != GL_TRUE)
5754 {
5755 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
5756 }
5757 *params = status;
5758 break;
5759 }
5760
5761 case GL_FENCE_CONDITION_NV:
5762 {
5763 *params = static_cast<GLint>(fenceObject->getCondition());
5764 break;
5765 }
5766
5767 default:
5768 UNREACHABLE();
5769 }
5770}
5771
5772void Context::getTranslatedShaderSource(GLuint shader,
5773 GLsizei bufsize,
5774 GLsizei *length,
5775 GLchar *source)
5776{
5777 Shader *shaderObject = getShader(shader);
5778 ASSERT(shaderObject);
5779 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
5780}
5781
5782void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
5783{
5784 Program *programObject = getProgram(program);
5785 ASSERT(programObject);
5786
5787 programObject->getUniformfv(this, location, params);
5788}
5789
5790void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
5791{
5792 Program *programObject = getProgram(program);
5793 ASSERT(programObject);
5794
5795 programObject->getUniformiv(this, location, params);
5796}
5797
5798GLboolean Context::isFenceNV(GLuint fence)
5799{
5800 FenceNV *fenceObject = getFenceNV(fence);
5801
5802 if (fenceObject == nullptr)
5803 {
5804 return GL_FALSE;
5805 }
5806
5807 // GL_NV_fence spec:
5808 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
5809 // existing fence.
5810 return fenceObject->isSet();
5811}
5812
5813void Context::readnPixels(GLint x,
5814 GLint y,
5815 GLsizei width,
5816 GLsizei height,
5817 GLenum format,
5818 GLenum type,
5819 GLsizei bufSize,
5820 void *data)
5821{
5822 return readPixels(x, y, width, height, format, type, data);
5823}
5824
Jamie Madill007530e2017-12-28 14:27:04 -05005825void Context::setFenceNV(GLuint fence, GLenum condition)
5826{
5827 ASSERT(condition == GL_ALL_COMPLETED_NV);
5828
5829 FenceNV *fenceObject = getFenceNV(fence);
5830 ASSERT(fenceObject != nullptr);
5831 handleError(fenceObject->set(condition));
5832}
5833
5834GLboolean Context::testFenceNV(GLuint fence)
5835{
5836 FenceNV *fenceObject = getFenceNV(fence);
5837
5838 ASSERT(fenceObject != nullptr);
5839 ASSERT(fenceObject->isSet() == GL_TRUE);
5840
5841 GLboolean result = GL_TRUE;
5842 Error error = fenceObject->test(&result);
5843 if (error.isError())
5844 {
5845 handleError(error);
5846 return GL_TRUE;
5847 }
5848
5849 return result;
5850}
5851
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005852void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005853{
5854 Texture *texture = getTargetTexture(target);
5855 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallez99d492c2018-02-27 15:17:10 -05005856 handleError(texture->setEGLImageTarget(this, target, imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05005857}
5858
Jamie Madillfa920eb2018-01-04 11:45:50 -05005859void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005860{
5861 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
5862 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
5863 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
5864}
5865
Jamie Madillfa920eb2018-01-04 11:45:50 -05005866void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
5867{
5868 UNIMPLEMENTED();
5869}
5870
Geoff Lang2aaa7b42018-01-12 17:17:27 -05005871void Context::alphaFunc(GLenum func, GLfloat ref)
5872{
5873 UNIMPLEMENTED();
5874}
5875
5876void Context::alphaFuncx(GLenum func, GLfixed ref)
5877{
5878 UNIMPLEMENTED();
5879}
5880
5881void Context::clearColorx(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5882{
5883 UNIMPLEMENTED();
5884}
5885
5886void Context::clearDepthx(GLfixed depth)
5887{
5888 UNIMPLEMENTED();
5889}
5890
5891void Context::clientActiveTexture(GLenum texture)
5892{
5893 UNIMPLEMENTED();
5894}
5895
5896void Context::clipPlanef(GLenum p, const GLfloat *eqn)
5897{
5898 UNIMPLEMENTED();
5899}
5900
5901void Context::clipPlanex(GLenum plane, const GLfixed *equation)
5902{
5903 UNIMPLEMENTED();
5904}
5905
5906void Context::color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
5907{
5908 UNIMPLEMENTED();
5909}
5910
5911void Context::color4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
5912{
5913 UNIMPLEMENTED();
5914}
5915
5916void Context::color4x(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5917{
5918 UNIMPLEMENTED();
5919}
5920
5921void Context::colorPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
5922{
5923 UNIMPLEMENTED();
5924}
5925
5926void Context::cullFace(GLenum mode)
5927{
5928 UNIMPLEMENTED();
5929}
5930
5931void Context::depthRangex(GLfixed n, GLfixed f)
5932{
5933 UNIMPLEMENTED();
5934}
5935
5936void Context::disableClientState(GLenum array)
5937{
5938 UNIMPLEMENTED();
5939}
5940
5941void Context::enableClientState(GLenum array)
5942{
5943 UNIMPLEMENTED();
5944}
5945
5946void Context::fogf(GLenum pname, GLfloat param)
5947{
5948 UNIMPLEMENTED();
5949}
5950
5951void Context::fogfv(GLenum pname, const GLfloat *params)
5952{
5953 UNIMPLEMENTED();
5954}
5955
5956void Context::fogx(GLenum pname, GLfixed param)
5957{
5958 UNIMPLEMENTED();
5959}
5960
5961void Context::fogxv(GLenum pname, const GLfixed *param)
5962{
5963 UNIMPLEMENTED();
5964}
5965
5966void Context::frustumf(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
5967{
5968 UNIMPLEMENTED();
5969}
5970
5971void Context::frustumx(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
5972{
5973 UNIMPLEMENTED();
5974}
5975
5976void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
5977{
5978 UNIMPLEMENTED();
5979}
5980
5981void Context::getClipPlanef(GLenum plane, GLfloat *equation)
5982{
5983 UNIMPLEMENTED();
5984}
5985
5986void Context::getClipPlanex(GLenum plane, GLfixed *equation)
5987{
5988 UNIMPLEMENTED();
5989}
5990
5991void Context::getFixedv(GLenum pname, GLfixed *params)
5992{
5993 UNIMPLEMENTED();
5994}
5995
5996void Context::getLightfv(GLenum light, GLenum pname, GLfloat *params)
5997{
5998 UNIMPLEMENTED();
5999}
6000
6001void Context::getLightxv(GLenum light, GLenum pname, GLfixed *params)
6002{
6003 UNIMPLEMENTED();
6004}
6005
6006void Context::getMaterialfv(GLenum face, GLenum pname, GLfloat *params)
6007{
6008 UNIMPLEMENTED();
6009}
6010
6011void Context::getMaterialxv(GLenum face, GLenum pname, GLfixed *params)
6012{
6013 UNIMPLEMENTED();
6014}
6015
6016void Context::getTexEnvfv(GLenum target, GLenum pname, GLfloat *params)
6017{
6018 UNIMPLEMENTED();
6019}
6020
6021void Context::getTexEnviv(GLenum target, GLenum pname, GLint *params)
6022{
6023 UNIMPLEMENTED();
6024}
6025
6026void Context::getTexEnvxv(GLenum target, GLenum pname, GLfixed *params)
6027{
6028 UNIMPLEMENTED();
6029}
6030
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006031void Context::getTexParameterxv(TextureType target, GLenum pname, GLfixed *params)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006032{
6033 UNIMPLEMENTED();
6034}
6035
6036void Context::lightModelf(GLenum pname, GLfloat param)
6037{
6038 UNIMPLEMENTED();
6039}
6040
6041void Context::lightModelfv(GLenum pname, const GLfloat *params)
6042{
6043 UNIMPLEMENTED();
6044}
6045
6046void Context::lightModelx(GLenum pname, GLfixed param)
6047{
6048 UNIMPLEMENTED();
6049}
6050
6051void Context::lightModelxv(GLenum pname, const GLfixed *param)
6052{
6053 UNIMPLEMENTED();
6054}
6055
6056void Context::lightf(GLenum light, GLenum pname, GLfloat param)
6057{
6058 UNIMPLEMENTED();
6059}
6060
6061void Context::lightfv(GLenum light, GLenum pname, const GLfloat *params)
6062{
6063 UNIMPLEMENTED();
6064}
6065
6066void Context::lightx(GLenum light, GLenum pname, GLfixed param)
6067{
6068 UNIMPLEMENTED();
6069}
6070
6071void Context::lightxv(GLenum light, GLenum pname, const GLfixed *params)
6072{
6073 UNIMPLEMENTED();
6074}
6075
6076void Context::lineWidthx(GLfixed width)
6077{
6078 UNIMPLEMENTED();
6079}
6080
6081void Context::loadIdentity()
6082{
6083 UNIMPLEMENTED();
6084}
6085
6086void Context::loadMatrixf(const GLfloat *m)
6087{
6088 UNIMPLEMENTED();
6089}
6090
6091void Context::loadMatrixx(const GLfixed *m)
6092{
6093 UNIMPLEMENTED();
6094}
6095
6096void Context::logicOp(GLenum opcode)
6097{
6098 UNIMPLEMENTED();
6099}
6100
6101void Context::materialf(GLenum face, GLenum pname, GLfloat param)
6102{
6103 UNIMPLEMENTED();
6104}
6105
6106void Context::materialfv(GLenum face, GLenum pname, const GLfloat *params)
6107{
6108 UNIMPLEMENTED();
6109}
6110
6111void Context::materialx(GLenum face, GLenum pname, GLfixed param)
6112{
6113 UNIMPLEMENTED();
6114}
6115
6116void Context::materialxv(GLenum face, GLenum pname, const GLfixed *param)
6117{
6118 UNIMPLEMENTED();
6119}
6120
6121void Context::matrixMode(GLenum mode)
6122{
6123 UNIMPLEMENTED();
6124}
6125
6126void Context::multMatrixf(const GLfloat *m)
6127{
6128 UNIMPLEMENTED();
6129}
6130
6131void Context::multMatrixx(const GLfixed *m)
6132{
6133 UNIMPLEMENTED();
6134}
6135
6136void Context::multiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q)
6137{
6138 UNIMPLEMENTED();
6139}
6140
6141void Context::multiTexCoord4x(GLenum texture, GLfixed s, GLfixed t, GLfixed r, GLfixed q)
6142{
6143 UNIMPLEMENTED();
6144}
6145
6146void Context::normal3f(GLfloat nx, GLfloat ny, GLfloat nz)
6147{
6148 UNIMPLEMENTED();
6149}
6150
6151void Context::normal3x(GLfixed nx, GLfixed ny, GLfixed nz)
6152{
6153 UNIMPLEMENTED();
6154}
6155
6156void Context::normalPointer(GLenum type, GLsizei stride, const void *pointer)
6157{
6158 UNIMPLEMENTED();
6159}
6160
6161void Context::orthof(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
6162{
6163 UNIMPLEMENTED();
6164}
6165
6166void Context::orthox(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
6167{
6168 UNIMPLEMENTED();
6169}
6170
6171void Context::pointParameterf(GLenum pname, GLfloat param)
6172{
6173 UNIMPLEMENTED();
6174}
6175
6176void Context::pointParameterfv(GLenum pname, const GLfloat *params)
6177{
6178 UNIMPLEMENTED();
6179}
6180
6181void Context::pointParameterx(GLenum pname, GLfixed param)
6182{
6183 UNIMPLEMENTED();
6184}
6185
6186void Context::pointParameterxv(GLenum pname, const GLfixed *params)
6187{
6188 UNIMPLEMENTED();
6189}
6190
6191void Context::pointSize(GLfloat size)
6192{
6193 UNIMPLEMENTED();
6194}
6195
6196void Context::pointSizex(GLfixed size)
6197{
6198 UNIMPLEMENTED();
6199}
6200
6201void Context::polygonOffsetx(GLfixed factor, GLfixed units)
6202{
6203 UNIMPLEMENTED();
6204}
6205
6206void Context::popMatrix()
6207{
6208 UNIMPLEMENTED();
6209}
6210
6211void Context::pushMatrix()
6212{
6213 UNIMPLEMENTED();
6214}
6215
6216void Context::rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
6217{
6218 UNIMPLEMENTED();
6219}
6220
6221void Context::rotatex(GLfixed angle, GLfixed x, GLfixed y, GLfixed z)
6222{
6223 UNIMPLEMENTED();
6224}
6225
6226void Context::sampleCoveragex(GLclampx value, GLboolean invert)
6227{
6228 UNIMPLEMENTED();
6229}
6230
6231void Context::scalef(GLfloat x, GLfloat y, GLfloat z)
6232{
6233 UNIMPLEMENTED();
6234}
6235
6236void Context::scalex(GLfixed x, GLfixed y, GLfixed z)
6237{
6238 UNIMPLEMENTED();
6239}
6240
6241void Context::shadeModel(GLenum mode)
6242{
6243 UNIMPLEMENTED();
6244}
6245
6246void Context::texCoordPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6247{
6248 UNIMPLEMENTED();
6249}
6250
6251void Context::texEnvf(GLenum target, GLenum pname, GLfloat param)
6252{
6253 UNIMPLEMENTED();
6254}
6255
6256void Context::texEnvfv(GLenum target, GLenum pname, const GLfloat *params)
6257{
6258 UNIMPLEMENTED();
6259}
6260
6261void Context::texEnvi(GLenum target, GLenum pname, GLint param)
6262{
6263 UNIMPLEMENTED();
6264}
6265
6266void Context::texEnviv(GLenum target, GLenum pname, const GLint *params)
6267{
6268 UNIMPLEMENTED();
6269}
6270
6271void Context::texEnvx(GLenum target, GLenum pname, GLfixed param)
6272{
6273 UNIMPLEMENTED();
6274}
6275
6276void Context::texEnvxv(GLenum target, GLenum pname, const GLfixed *params)
6277{
6278 UNIMPLEMENTED();
6279}
6280
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006281void Context::texParameterx(TextureType target, GLenum pname, GLfixed param)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006282{
6283 UNIMPLEMENTED();
6284}
6285
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006286void Context::texParameterxv(TextureType target, GLenum pname, const GLfixed *params)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006287{
6288 UNIMPLEMENTED();
6289}
6290
6291void Context::translatef(GLfloat x, GLfloat y, GLfloat z)
6292{
6293 UNIMPLEMENTED();
6294}
6295
6296void Context::translatex(GLfixed x, GLfixed y, GLfixed z)
6297{
6298 UNIMPLEMENTED();
6299}
6300
6301void Context::vertexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6302{
6303 UNIMPLEMENTED();
6304}
6305
6306void Context::drawTexf(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height)
6307{
6308 UNIMPLEMENTED();
6309}
6310
6311void Context::drawTexfv(const GLfloat *coords)
6312{
6313 UNIMPLEMENTED();
6314}
6315
6316void Context::drawTexi(GLint x, GLint y, GLint z, GLint width, GLint height)
6317{
6318 UNIMPLEMENTED();
6319}
6320
6321void Context::drawTexiv(const GLint *coords)
6322{
6323 UNIMPLEMENTED();
6324}
6325
6326void Context::drawTexs(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height)
6327{
6328 UNIMPLEMENTED();
6329}
6330
6331void Context::drawTexsv(const GLshort *coords)
6332{
6333 UNIMPLEMENTED();
6334}
6335
6336void Context::drawTexx(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height)
6337{
6338 UNIMPLEMENTED();
6339}
6340
6341void Context::drawTexxv(const GLfixed *coords)
6342{
6343 UNIMPLEMENTED();
6344}
6345
6346void Context::currentPaletteMatrix(GLuint matrixpaletteindex)
6347{
6348 UNIMPLEMENTED();
6349}
6350
6351void Context::loadPaletteFromModelViewMatrix()
6352{
6353 UNIMPLEMENTED();
6354}
6355
6356void Context::matrixIndexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6357{
6358 UNIMPLEMENTED();
6359}
6360
6361void Context::weightPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6362{
6363 UNIMPLEMENTED();
6364}
6365
6366void Context::pointSizePointer(GLenum type, GLsizei stride, const void *pointer)
6367{
6368 UNIMPLEMENTED();
6369}
6370
6371GLbitfield Context::queryMatrixx(GLfixed *mantissa, GLint *exponent)
6372{
6373 UNIMPLEMENTED();
6374 return 0;
6375}
6376
Jamie Madillc29968b2016-01-20 11:17:23 -05006377} // namespace gl