blob: 65252e834a85061496dcc73ec1f68ff33fe9c6ff [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{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400167 EGLAttrib attrib = attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT,
Jeff Gilbertc5de4d22017-10-31 15:07:53 -0700168 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
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400313 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400314 mZeroTextures[GL_TEXTURE_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500315
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400316 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, GL_TEXTURE_CUBE_MAP);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400317 mZeroTextures[GL_TEXTURE_CUBE_MAP].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
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400322 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, GL_TEXTURE_3D);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400323 mZeroTextures[GL_TEXTURE_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400324
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400325 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_ARRAY);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400326 mZeroTextures[GL_TEXTURE_2D_ARRAY].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 =
331 new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_MULTISAMPLE);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400332 mZeroTextures[GL_TEXTURE_2D_MULTISAMPLE].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 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400336 bindBufferRange(BufferBinding::AtomicCounter, 0, i, 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 =
349 new Texture(mImplementation.get(), 0, GL_TEXTURE_RECTANGLE_ANGLE);
350 mZeroTextures[GL_TEXTURE_RECTANGLE_ANGLE].set(this, zeroTextureRectangle);
351 }
352
Geoff Lang4751aab2017-10-30 15:14:52 -0400353 if (nativeExtensions.eglImageExternal || nativeExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400354 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400355 Texture *zeroTextureExternal =
356 new Texture(mImplementation.get(), 0, GL_TEXTURE_EXTERNAL_OES);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400357 mZeroTextures[GL_TEXTURE_EXTERNAL_OES].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400358 }
359
Jamie Madill4928b7c2017-06-20 12:57:39 -0400360 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500361
Jamie Madill57a89722013-07-02 11:57:03 -0400362 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000363
Geoff Langeb66a6e2016-10-31 13:06:12 -0400364 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400365 {
366 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
367 // In the initial state, a default transform feedback object is bound and treated as
368 // a transform feedback object with a name of zero. That object is bound any time
369 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400370 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400371 }
Geoff Langc8058452014-02-03 12:04:11 -0500372
Corentin Wallez336129f2017-10-17 15:55:40 -0400373 for (auto type : angle::AllEnums<BufferBinding>())
374 {
375 bindBuffer(type, 0);
376 }
377
378 bindRenderbuffer(GL_RENDERBUFFER, 0);
379
380 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
381 {
382 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
383 }
384
Jamie Madillad9f24e2016-02-12 09:27:24 -0500385 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400386 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500387 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500388 // No dirty objects.
389
390 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400391 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500392 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500393 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
394
395 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
396 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
397 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
398 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
399 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
400 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
401 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
402 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
403 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
404 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
405 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
406 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
407
408 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
409 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700410 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500411 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
412 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400413
Xinghua Cao10a4d432017-11-28 14:46:26 +0800414 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
415 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
416 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
417 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
418 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
419 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800420 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800421
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400422 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000423}
424
Jamie Madill4928b7c2017-06-20 12:57:39 -0400425egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000426{
Corentin Wallez80b24112015-08-25 16:41:57 -0400427 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000428 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400429 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000430 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400431 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000432
Corentin Wallez80b24112015-08-25 16:41:57 -0400433 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000434 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400435 if (query.second != nullptr)
436 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400437 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400438 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000439 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400440 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000441
Corentin Wallez80b24112015-08-25 16:41:57 -0400442 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400443 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400444 if (vertexArray.second)
445 {
446 vertexArray.second->onDestroy(this);
447 }
Jamie Madill57a89722013-07-02 11:57:03 -0400448 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400449 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400450
Corentin Wallez80b24112015-08-25 16:41:57 -0400451 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500452 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500453 if (transformFeedback.second != nullptr)
454 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500455 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500456 }
Geoff Langc8058452014-02-03 12:04:11 -0500457 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400458 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500459
Jamie Madilldedd7b92014-11-05 16:30:36 -0500460 for (auto &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400461 {
Jamie Madill71c88b32017-09-14 22:20:29 -0400462 ANGLE_TRY(zeroTexture.second->onDestroy(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400463 zeroTexture.second.set(this, nullptr);
Geoff Lang76b10c92014-09-05 16:28:14 -0400464 }
465 mZeroTextures.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000466
Corentin Wallezccab69d2017-01-27 16:57:15 -0500467 SafeDelete(mSurfacelessFramebuffer);
468
Jamie Madill4928b7c2017-06-20 12:57:39 -0400469 ANGLE_TRY(releaseSurface(display));
Jamie Madill2f348d22017-06-05 10:50:59 -0400470 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500471
Jamie Madill4928b7c2017-06-20 12:57:39 -0400472 mGLState.reset(this);
473
Jamie Madill6c1f6712017-02-14 19:08:04 -0500474 mState.mBuffers->release(this);
475 mState.mShaderPrograms->release(this);
476 mState.mTextures->release(this);
477 mState.mRenderbuffers->release(this);
478 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400479 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500480 mState.mPaths->release(this);
481 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800482 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400483
Jamie Madill76e471e2017-10-21 09:56:01 -0400484 mImplementation->onDestroy(this);
485
Jamie Madill4928b7c2017-06-20 12:57:39 -0400486 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000487}
488
Jamie Madill70ee0f62017-02-06 16:04:20 -0500489Context::~Context()
490{
491}
492
Jamie Madill4928b7c2017-06-20 12:57:39 -0400493egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000494{
Jamie Madill61e16b42017-06-19 11:13:23 -0400495 mCurrentDisplay = display;
496
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000497 if (!mHasBeenCurrent)
498 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000499 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500500 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400501 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000502
Corentin Wallezc295e512017-01-27 17:47:50 -0500503 int width = 0;
504 int height = 0;
505 if (surface != nullptr)
506 {
507 width = surface->getWidth();
508 height = surface->getHeight();
509 }
510
511 mGLState.setViewportParams(0, 0, width, height);
512 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000513
514 mHasBeenCurrent = true;
515 }
516
Jamie Madill1b94d432015-08-07 13:23:23 -0400517 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700518 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400519 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400520
Jamie Madill4928b7c2017-06-20 12:57:39 -0400521 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500522
523 Framebuffer *newDefault = nullptr;
524 if (surface != nullptr)
525 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400526 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500527 mCurrentSurface = surface;
528 newDefault = surface->getDefaultFramebuffer();
529 }
530 else
531 {
532 if (mSurfacelessFramebuffer == nullptr)
533 {
534 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
535 }
536
537 newDefault = mSurfacelessFramebuffer;
538 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000539
Corentin Wallez37c39792015-08-20 14:19:46 -0400540 // Update default framebuffer, the binding of the previous default
541 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400542 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700543 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400544 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700545 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400546 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700547 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400548 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700549 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400550 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500551 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400552 }
Ian Ewell292f0052016-02-04 10:37:32 -0500553
554 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400555 mImplementation->onMakeCurrent(this);
556 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000557}
558
Jamie Madill4928b7c2017-06-20 12:57:39 -0400559egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400560{
Corentin Wallez37c39792015-08-20 14:19:46 -0400561 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500562 Framebuffer *currentDefault = nullptr;
563 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400564 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500565 currentDefault = mCurrentSurface->getDefaultFramebuffer();
566 }
567 else if (mSurfacelessFramebuffer != nullptr)
568 {
569 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400570 }
571
Corentin Wallezc295e512017-01-27 17:47:50 -0500572 if (mGLState.getReadFramebuffer() == currentDefault)
573 {
574 mGLState.setReadFramebufferBinding(nullptr);
575 }
576 if (mGLState.getDrawFramebuffer() == currentDefault)
577 {
578 mGLState.setDrawFramebufferBinding(nullptr);
579 }
580 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
581
582 if (mCurrentSurface)
583 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400584 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500585 mCurrentSurface = nullptr;
586 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400587
588 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400589}
590
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000591GLuint Context::createBuffer()
592{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500593 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000594}
595
596GLuint Context::createProgram()
597{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500598 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000599}
600
601GLuint Context::createShader(GLenum type)
602{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500603 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000604}
605
606GLuint Context::createTexture()
607{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500608 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000609}
610
611GLuint Context::createRenderbuffer()
612{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500613 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000614}
615
Sami Väisänene45e53b2016-05-25 10:36:04 +0300616GLuint Context::createPaths(GLsizei range)
617{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500618 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300619 if (resultOrError.isError())
620 {
621 handleError(resultOrError.getError());
622 return 0;
623 }
624 return resultOrError.getResult();
625}
626
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000627// Returns an unused framebuffer name
628GLuint Context::createFramebuffer()
629{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500630 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000631}
632
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500633void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000634{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500635 for (int i = 0; i < n; i++)
636 {
637 GLuint handle = mFenceNVHandleAllocator.allocate();
638 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
639 fences[i] = handle;
640 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000641}
642
Yunchao Hea336b902017-08-02 16:05:21 +0800643GLuint Context::createProgramPipeline()
644{
645 return mState.mPipelines->createProgramPipeline();
646}
647
Jiajia Qin5451d532017-11-16 17:16:34 +0800648GLuint Context::createShaderProgramv(GLenum type, GLsizei count, const GLchar *const *strings)
649{
650 UNIMPLEMENTED();
651 return 0u;
652}
653
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000654void Context::deleteBuffer(GLuint buffer)
655{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500656 if (mState.mBuffers->getBuffer(buffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000657 {
658 detachBuffer(buffer);
659 }
Jamie Madill893ab082014-05-16 16:56:10 -0400660
Jamie Madill6c1f6712017-02-14 19:08:04 -0500661 mState.mBuffers->deleteObject(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000662}
663
664void Context::deleteShader(GLuint shader)
665{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500666 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000667}
668
669void Context::deleteProgram(GLuint program)
670{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500671 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000672}
673
674void Context::deleteTexture(GLuint texture)
675{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500676 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000677 {
678 detachTexture(texture);
679 }
680
Jamie Madill6c1f6712017-02-14 19:08:04 -0500681 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000682}
683
684void Context::deleteRenderbuffer(GLuint renderbuffer)
685{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500686 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000687 {
688 detachRenderbuffer(renderbuffer);
689 }
Jamie Madill893ab082014-05-16 16:56:10 -0400690
Jamie Madill6c1f6712017-02-14 19:08:04 -0500691 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000692}
693
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400694void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400695{
696 // The spec specifies the underlying Fence object is not deleted until all current
697 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
698 // and since our API is currently designed for being called from a single thread, we can delete
699 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400700 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400701}
702
Yunchao Hea336b902017-08-02 16:05:21 +0800703void Context::deleteProgramPipeline(GLuint pipeline)
704{
705 if (mState.mPipelines->getProgramPipeline(pipeline))
706 {
707 detachProgramPipeline(pipeline);
708 }
709
710 mState.mPipelines->deleteObject(this, pipeline);
711}
712
Sami Väisänene45e53b2016-05-25 10:36:04 +0300713void Context::deletePaths(GLuint first, GLsizei range)
714{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500715 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300716}
717
718bool Context::hasPathData(GLuint path) const
719{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500720 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300721 if (pathObj == nullptr)
722 return false;
723
724 return pathObj->hasPathData();
725}
726
727bool Context::hasPath(GLuint path) const
728{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500729 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300730}
731
732void Context::setPathCommands(GLuint path,
733 GLsizei numCommands,
734 const GLubyte *commands,
735 GLsizei numCoords,
736 GLenum coordType,
737 const void *coords)
738{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500739 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300740
741 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
742}
743
Jamie Madill007530e2017-12-28 14:27:04 -0500744void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300745{
Jamie Madill007530e2017-12-28 14:27:04 -0500746 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300747
748 switch (pname)
749 {
750 case GL_PATH_STROKE_WIDTH_CHROMIUM:
751 pathObj->setStrokeWidth(value);
752 break;
753 case GL_PATH_END_CAPS_CHROMIUM:
754 pathObj->setEndCaps(static_cast<GLenum>(value));
755 break;
756 case GL_PATH_JOIN_STYLE_CHROMIUM:
757 pathObj->setJoinStyle(static_cast<GLenum>(value));
758 break;
759 case GL_PATH_MITER_LIMIT_CHROMIUM:
760 pathObj->setMiterLimit(value);
761 break;
762 case GL_PATH_STROKE_BOUND_CHROMIUM:
763 pathObj->setStrokeBound(value);
764 break;
765 default:
766 UNREACHABLE();
767 break;
768 }
769}
770
Jamie Madill007530e2017-12-28 14:27:04 -0500771void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300772{
Jamie Madill007530e2017-12-28 14:27:04 -0500773 // TODO(jmadill): Should use proper clamping/casting.
774 pathParameterf(path, pname, static_cast<GLfloat>(value));
775}
776
777void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
778{
779 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300780
781 switch (pname)
782 {
783 case GL_PATH_STROKE_WIDTH_CHROMIUM:
784 *value = pathObj->getStrokeWidth();
785 break;
786 case GL_PATH_END_CAPS_CHROMIUM:
787 *value = static_cast<GLfloat>(pathObj->getEndCaps());
788 break;
789 case GL_PATH_JOIN_STYLE_CHROMIUM:
790 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
791 break;
792 case GL_PATH_MITER_LIMIT_CHROMIUM:
793 *value = pathObj->getMiterLimit();
794 break;
795 case GL_PATH_STROKE_BOUND_CHROMIUM:
796 *value = pathObj->getStrokeBound();
797 break;
798 default:
799 UNREACHABLE();
800 break;
801 }
802}
803
Jamie Madill007530e2017-12-28 14:27:04 -0500804void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
805{
806 GLfloat val = 0.0f;
807 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
808 if (value)
809 *value = static_cast<GLint>(val);
810}
811
Sami Väisänene45e53b2016-05-25 10:36:04 +0300812void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
813{
814 mGLState.setPathStencilFunc(func, ref, mask);
815}
816
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000817void Context::deleteFramebuffer(GLuint framebuffer)
818{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500819 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000820 {
821 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000822 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500823
Jamie Madill6c1f6712017-02-14 19:08:04 -0500824 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000825}
826
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500827void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000828{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500829 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000830 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500831 GLuint fence = fences[i];
832
833 FenceNV *fenceObject = nullptr;
834 if (mFenceNVMap.erase(fence, &fenceObject))
835 {
836 mFenceNVHandleAllocator.release(fence);
837 delete fenceObject;
838 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000839 }
840}
841
Geoff Lang70d0f492015-12-10 17:45:46 -0500842Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000843{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500844 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000845}
846
Jamie Madill570f7c82014-07-03 10:38:54 -0400847Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000848{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500849 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000850}
851
Geoff Lang70d0f492015-12-10 17:45:46 -0500852Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000853{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500854 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000855}
856
Jamie Madill70b5bb02017-08-28 13:32:37 -0400857Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400858{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400859 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400860}
861
Jamie Madill57a89722013-07-02 11:57:03 -0400862VertexArray *Context::getVertexArray(GLuint handle) const
863{
Jamie Madill96a483b2017-06-27 16:49:21 -0400864 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400865}
866
Jamie Madilldc356042013-07-19 16:36:57 -0400867Sampler *Context::getSampler(GLuint handle) const
868{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500869 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400870}
871
Geoff Langc8058452014-02-03 12:04:11 -0500872TransformFeedback *Context::getTransformFeedback(GLuint handle) const
873{
Jamie Madill96a483b2017-06-27 16:49:21 -0400874 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500875}
876
Yunchao Hea336b902017-08-02 16:05:21 +0800877ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
878{
879 return mState.mPipelines->getProgramPipeline(handle);
880}
881
Geoff Lang70d0f492015-12-10 17:45:46 -0500882LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
883{
884 switch (identifier)
885 {
886 case GL_BUFFER:
887 return getBuffer(name);
888 case GL_SHADER:
889 return getShader(name);
890 case GL_PROGRAM:
891 return getProgram(name);
892 case GL_VERTEX_ARRAY:
893 return getVertexArray(name);
894 case GL_QUERY:
895 return getQuery(name);
896 case GL_TRANSFORM_FEEDBACK:
897 return getTransformFeedback(name);
898 case GL_SAMPLER:
899 return getSampler(name);
900 case GL_TEXTURE:
901 return getTexture(name);
902 case GL_RENDERBUFFER:
903 return getRenderbuffer(name);
904 case GL_FRAMEBUFFER:
905 return getFramebuffer(name);
906 default:
907 UNREACHABLE();
908 return nullptr;
909 }
910}
911
912LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
913{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400914 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500915}
916
Martin Radev9d901792016-07-15 15:58:58 +0300917void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
918{
919 LabeledObject *object = getLabeledObject(identifier, name);
920 ASSERT(object != nullptr);
921
922 std::string labelName = GetObjectLabelFromPointer(length, label);
923 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400924
925 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
926 // specified object is active until we do this.
927 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300928}
929
930void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
931{
932 LabeledObject *object = getLabeledObjectFromPtr(ptr);
933 ASSERT(object != nullptr);
934
935 std::string labelName = GetObjectLabelFromPointer(length, label);
936 object->setLabel(labelName);
937}
938
939void Context::getObjectLabel(GLenum identifier,
940 GLuint name,
941 GLsizei bufSize,
942 GLsizei *length,
943 GLchar *label) const
944{
945 LabeledObject *object = getLabeledObject(identifier, name);
946 ASSERT(object != nullptr);
947
948 const std::string &objectLabel = object->getLabel();
949 GetObjectLabelBase(objectLabel, bufSize, length, label);
950}
951
952void Context::getObjectPtrLabel(const void *ptr,
953 GLsizei bufSize,
954 GLsizei *length,
955 GLchar *label) const
956{
957 LabeledObject *object = getLabeledObjectFromPtr(ptr);
958 ASSERT(object != nullptr);
959
960 const std::string &objectLabel = object->getLabel();
961 GetObjectLabelBase(objectLabel, bufSize, length, label);
962}
963
Jamie Madilldc356042013-07-19 16:36:57 -0400964bool Context::isSampler(GLuint samplerName) const
965{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500966 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400967}
968
Jamie Madilldedd7b92014-11-05 16:30:36 -0500969void Context::bindTexture(GLenum target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000970{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500971 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000972
Jamie Madilldedd7b92014-11-05 16:30:36 -0500973 if (handle == 0)
974 {
975 texture = mZeroTextures[target].get();
976 }
977 else
978 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500979 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500980 }
981
982 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400983 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000984}
985
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500986void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000987{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500988 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
989 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700990 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000991}
992
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500993void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000994{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500995 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
996 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700997 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000998}
999
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001000void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001001{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001002 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001003 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001004}
1005
Shao80957d92017-02-20 21:25:59 +08001006void Context::bindVertexBuffer(GLuint bindingIndex,
1007 GLuint bufferHandle,
1008 GLintptr offset,
1009 GLsizei stride)
1010{
1011 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001012 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001013}
1014
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001015void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001016{
Geoff Lang76b10c92014-09-05 16:28:14 -04001017 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001018 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001019 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001020 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001021}
1022
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001023void Context::bindImageTexture(GLuint unit,
1024 GLuint texture,
1025 GLint level,
1026 GLboolean layered,
1027 GLint layer,
1028 GLenum access,
1029 GLenum format)
1030{
1031 Texture *tex = mState.mTextures->getTexture(texture);
1032 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1033}
1034
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001035void Context::useProgram(GLuint program)
1036{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001037 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001038}
1039
Jiajia Qin5451d532017-11-16 17:16:34 +08001040void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1041{
1042 UNIMPLEMENTED();
1043}
1044
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001045void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001046{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001047 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001048 TransformFeedback *transformFeedback =
1049 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001050 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001051}
1052
Yunchao Hea336b902017-08-02 16:05:21 +08001053void Context::bindProgramPipeline(GLuint pipelineHandle)
1054{
1055 ProgramPipeline *pipeline =
1056 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1057 mGLState.setProgramPipelineBinding(this, pipeline);
1058}
1059
Jamie Madillf0e04492017-08-26 15:28:42 -04001060void Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001061{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001062 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001063 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001064
Geoff Lang5aad9672014-09-08 11:10:42 -04001065 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001066 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001067
1068 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001069 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001070}
1071
Jamie Madillf0e04492017-08-26 15:28:42 -04001072void Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001073{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001074 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001075 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001076
Jamie Madillf0e04492017-08-26 15:28:42 -04001077 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001078
Geoff Lang5aad9672014-09-08 11:10:42 -04001079 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001080 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001081}
1082
Jamie Madillf0e04492017-08-26 15:28:42 -04001083void Context::queryCounter(GLuint id, GLenum target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001084{
1085 ASSERT(target == GL_TIMESTAMP_EXT);
1086
1087 Query *queryObject = getQuery(id, true, target);
1088 ASSERT(queryObject);
1089
Jamie Madillf0e04492017-08-26 15:28:42 -04001090 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001091}
1092
1093void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1094{
1095 switch (pname)
1096 {
1097 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001098 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001099 break;
1100 case GL_QUERY_COUNTER_BITS_EXT:
1101 switch (target)
1102 {
1103 case GL_TIME_ELAPSED_EXT:
1104 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1105 break;
1106 case GL_TIMESTAMP_EXT:
1107 params[0] = getExtensions().queryCounterBitsTimestamp;
1108 break;
1109 default:
1110 UNREACHABLE();
1111 params[0] = 0;
1112 break;
1113 }
1114 break;
1115 default:
1116 UNREACHABLE();
1117 return;
1118 }
1119}
1120
Geoff Lang2186c382016-10-14 10:54:54 -04001121void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001122{
Geoff Lang2186c382016-10-14 10:54:54 -04001123 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001124}
1125
Geoff Lang2186c382016-10-14 10:54:54 -04001126void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001127{
Geoff Lang2186c382016-10-14 10:54:54 -04001128 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001129}
1130
Geoff Lang2186c382016-10-14 10:54:54 -04001131void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001132{
Geoff Lang2186c382016-10-14 10:54:54 -04001133 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001134}
1135
Geoff Lang2186c382016-10-14 10:54:54 -04001136void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001137{
Geoff Lang2186c382016-10-14 10:54:54 -04001138 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001139}
1140
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001141Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001142{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001143 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001144}
1145
Jamie Madill2f348d22017-06-05 10:50:59 -04001146FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001147{
Jamie Madill96a483b2017-06-27 16:49:21 -04001148 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001149}
1150
Jamie Madill2f348d22017-06-05 10:50:59 -04001151Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001152{
Jamie Madill96a483b2017-06-27 16:49:21 -04001153 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001154 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001155 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001156 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001157
1158 Query *query = mQueryMap.query(handle);
1159 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001160 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001161 query = new Query(mImplementation->createQuery(type), handle);
1162 query->addRef();
1163 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001164 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001165 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001166}
1167
Geoff Lang70d0f492015-12-10 17:45:46 -05001168Query *Context::getQuery(GLuint handle) const
1169{
Jamie Madill96a483b2017-06-27 16:49:21 -04001170 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001171}
1172
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001173Texture *Context::getTargetTexture(GLenum target) const
1174{
Ian Ewellbda75592016-04-18 17:25:54 -04001175 ASSERT(ValidTextureTarget(this, target) || ValidTextureExternalTarget(this, target));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001176 return mGLState.getTargetTexture(target);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001177}
1178
Geoff Lang76b10c92014-09-05 16:28:14 -04001179Texture *Context::getSamplerTexture(unsigned int sampler, GLenum type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001180{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001181 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001182}
1183
Geoff Lang492a7e42014-11-05 13:27:06 -05001184Compiler *Context::getCompiler() const
1185{
Jamie Madill2f348d22017-06-05 10:50:59 -04001186 if (mCompiler.get() == nullptr)
1187 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001188 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001189 }
1190 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001191}
1192
Jamie Madillc1d770e2017-04-13 17:31:24 -04001193void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001194{
1195 switch (pname)
1196 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001197 case GL_SHADER_COMPILER:
1198 *params = GL_TRUE;
1199 break;
1200 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1201 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1202 break;
1203 default:
1204 mGLState.getBooleanv(pname, params);
1205 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001206 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001207}
1208
Jamie Madillc1d770e2017-04-13 17:31:24 -04001209void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001210{
Shannon Woods53a94a82014-06-24 15:20:36 -04001211 // Queries about context capabilities and maximums are answered by Context.
1212 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001213 switch (pname)
1214 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001215 case GL_ALIASED_LINE_WIDTH_RANGE:
1216 params[0] = mCaps.minAliasedLineWidth;
1217 params[1] = mCaps.maxAliasedLineWidth;
1218 break;
1219 case GL_ALIASED_POINT_SIZE_RANGE:
1220 params[0] = mCaps.minAliasedPointSize;
1221 params[1] = mCaps.maxAliasedPointSize;
1222 break;
1223 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1224 ASSERT(mExtensions.textureFilterAnisotropic);
1225 *params = mExtensions.maxTextureAnisotropy;
1226 break;
1227 case GL_MAX_TEXTURE_LOD_BIAS:
1228 *params = mCaps.maxLODBias;
1229 break;
1230
1231 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1232 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1233 {
1234 ASSERT(mExtensions.pathRendering);
1235 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1236 memcpy(params, m, 16 * sizeof(GLfloat));
1237 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001238 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001239
Jamie Madill231c7f52017-04-26 13:45:37 -04001240 default:
1241 mGLState.getFloatv(pname, params);
1242 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001243 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001244}
1245
Jamie Madillc1d770e2017-04-13 17:31:24 -04001246void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001247{
Shannon Woods53a94a82014-06-24 15:20:36 -04001248 // Queries about context capabilities and maximums are answered by Context.
1249 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001250
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001251 switch (pname)
1252 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001253 case GL_MAX_VERTEX_ATTRIBS:
1254 *params = mCaps.maxVertexAttributes;
1255 break;
1256 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1257 *params = mCaps.maxVertexUniformVectors;
1258 break;
1259 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1260 *params = mCaps.maxVertexUniformComponents;
1261 break;
1262 case GL_MAX_VARYING_VECTORS:
1263 *params = mCaps.maxVaryingVectors;
1264 break;
1265 case GL_MAX_VARYING_COMPONENTS:
1266 *params = mCaps.maxVertexOutputComponents;
1267 break;
1268 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1269 *params = mCaps.maxCombinedTextureImageUnits;
1270 break;
1271 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1272 *params = mCaps.maxVertexTextureImageUnits;
1273 break;
1274 case GL_MAX_TEXTURE_IMAGE_UNITS:
1275 *params = mCaps.maxTextureImageUnits;
1276 break;
1277 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1278 *params = mCaps.maxFragmentUniformVectors;
1279 break;
1280 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1281 *params = mCaps.maxFragmentUniformComponents;
1282 break;
1283 case GL_MAX_RENDERBUFFER_SIZE:
1284 *params = mCaps.maxRenderbufferSize;
1285 break;
1286 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1287 *params = mCaps.maxColorAttachments;
1288 break;
1289 case GL_MAX_DRAW_BUFFERS_EXT:
1290 *params = mCaps.maxDrawBuffers;
1291 break;
1292 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1293 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1294 case GL_SUBPIXEL_BITS:
1295 *params = 4;
1296 break;
1297 case GL_MAX_TEXTURE_SIZE:
1298 *params = mCaps.max2DTextureSize;
1299 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001300 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1301 *params = mCaps.maxRectangleTextureSize;
1302 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001303 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1304 *params = mCaps.maxCubeMapTextureSize;
1305 break;
1306 case GL_MAX_3D_TEXTURE_SIZE:
1307 *params = mCaps.max3DTextureSize;
1308 break;
1309 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1310 *params = mCaps.maxArrayTextureLayers;
1311 break;
1312 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1313 *params = mCaps.uniformBufferOffsetAlignment;
1314 break;
1315 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1316 *params = mCaps.maxUniformBufferBindings;
1317 break;
1318 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1319 *params = mCaps.maxVertexUniformBlocks;
1320 break;
1321 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1322 *params = mCaps.maxFragmentUniformBlocks;
1323 break;
1324 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1325 *params = mCaps.maxCombinedTextureImageUnits;
1326 break;
1327 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1328 *params = mCaps.maxVertexOutputComponents;
1329 break;
1330 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1331 *params = mCaps.maxFragmentInputComponents;
1332 break;
1333 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1334 *params = mCaps.minProgramTexelOffset;
1335 break;
1336 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1337 *params = mCaps.maxProgramTexelOffset;
1338 break;
1339 case GL_MAJOR_VERSION:
1340 *params = getClientVersion().major;
1341 break;
1342 case GL_MINOR_VERSION:
1343 *params = getClientVersion().minor;
1344 break;
1345 case GL_MAX_ELEMENTS_INDICES:
1346 *params = mCaps.maxElementsIndices;
1347 break;
1348 case GL_MAX_ELEMENTS_VERTICES:
1349 *params = mCaps.maxElementsVertices;
1350 break;
1351 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1352 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1353 break;
1354 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1355 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1356 break;
1357 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1358 *params = mCaps.maxTransformFeedbackSeparateComponents;
1359 break;
1360 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1361 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1362 break;
1363 case GL_MAX_SAMPLES_ANGLE:
1364 *params = mCaps.maxSamples;
1365 break;
1366 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001367 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001368 params[0] = mCaps.maxViewportWidth;
1369 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001370 }
1371 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001372 case GL_COMPRESSED_TEXTURE_FORMATS:
1373 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1374 params);
1375 break;
1376 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1377 *params = mResetStrategy;
1378 break;
1379 case GL_NUM_SHADER_BINARY_FORMATS:
1380 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1381 break;
1382 case GL_SHADER_BINARY_FORMATS:
1383 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1384 break;
1385 case GL_NUM_PROGRAM_BINARY_FORMATS:
1386 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1387 break;
1388 case GL_PROGRAM_BINARY_FORMATS:
1389 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1390 break;
1391 case GL_NUM_EXTENSIONS:
1392 *params = static_cast<GLint>(mExtensionStrings.size());
1393 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001394
Jamie Madill231c7f52017-04-26 13:45:37 -04001395 // GL_KHR_debug
1396 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1397 *params = mExtensions.maxDebugMessageLength;
1398 break;
1399 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1400 *params = mExtensions.maxDebugLoggedMessages;
1401 break;
1402 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1403 *params = mExtensions.maxDebugGroupStackDepth;
1404 break;
1405 case GL_MAX_LABEL_LENGTH:
1406 *params = mExtensions.maxLabelLength;
1407 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001408
Martin Radeve5285d22017-07-14 16:23:53 +03001409 // GL_ANGLE_multiview
1410 case GL_MAX_VIEWS_ANGLE:
1411 *params = mExtensions.maxViews;
1412 break;
1413
Jamie Madill231c7f52017-04-26 13:45:37 -04001414 // GL_EXT_disjoint_timer_query
1415 case GL_GPU_DISJOINT_EXT:
1416 *params = mImplementation->getGPUDisjoint();
1417 break;
1418 case GL_MAX_FRAMEBUFFER_WIDTH:
1419 *params = mCaps.maxFramebufferWidth;
1420 break;
1421 case GL_MAX_FRAMEBUFFER_HEIGHT:
1422 *params = mCaps.maxFramebufferHeight;
1423 break;
1424 case GL_MAX_FRAMEBUFFER_SAMPLES:
1425 *params = mCaps.maxFramebufferSamples;
1426 break;
1427 case GL_MAX_SAMPLE_MASK_WORDS:
1428 *params = mCaps.maxSampleMaskWords;
1429 break;
1430 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1431 *params = mCaps.maxColorTextureSamples;
1432 break;
1433 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1434 *params = mCaps.maxDepthTextureSamples;
1435 break;
1436 case GL_MAX_INTEGER_SAMPLES:
1437 *params = mCaps.maxIntegerSamples;
1438 break;
1439 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1440 *params = mCaps.maxVertexAttribRelativeOffset;
1441 break;
1442 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1443 *params = mCaps.maxVertexAttribBindings;
1444 break;
1445 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1446 *params = mCaps.maxVertexAttribStride;
1447 break;
1448 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1449 *params = mCaps.maxVertexAtomicCounterBuffers;
1450 break;
1451 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1452 *params = mCaps.maxVertexAtomicCounters;
1453 break;
1454 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1455 *params = mCaps.maxVertexImageUniforms;
1456 break;
1457 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1458 *params = mCaps.maxVertexShaderStorageBlocks;
1459 break;
1460 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1461 *params = mCaps.maxFragmentAtomicCounterBuffers;
1462 break;
1463 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1464 *params = mCaps.maxFragmentAtomicCounters;
1465 break;
1466 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1467 *params = mCaps.maxFragmentImageUniforms;
1468 break;
1469 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1470 *params = mCaps.maxFragmentShaderStorageBlocks;
1471 break;
1472 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1473 *params = mCaps.minProgramTextureGatherOffset;
1474 break;
1475 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1476 *params = mCaps.maxProgramTextureGatherOffset;
1477 break;
1478 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1479 *params = mCaps.maxComputeWorkGroupInvocations;
1480 break;
1481 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1482 *params = mCaps.maxComputeUniformBlocks;
1483 break;
1484 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1485 *params = mCaps.maxComputeTextureImageUnits;
1486 break;
1487 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1488 *params = mCaps.maxComputeSharedMemorySize;
1489 break;
1490 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1491 *params = mCaps.maxComputeUniformComponents;
1492 break;
1493 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1494 *params = mCaps.maxComputeAtomicCounterBuffers;
1495 break;
1496 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1497 *params = mCaps.maxComputeAtomicCounters;
1498 break;
1499 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1500 *params = mCaps.maxComputeImageUniforms;
1501 break;
1502 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1503 *params = mCaps.maxCombinedComputeUniformComponents;
1504 break;
1505 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1506 *params = mCaps.maxComputeShaderStorageBlocks;
1507 break;
1508 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1509 *params = mCaps.maxCombinedShaderOutputResources;
1510 break;
1511 case GL_MAX_UNIFORM_LOCATIONS:
1512 *params = mCaps.maxUniformLocations;
1513 break;
1514 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1515 *params = mCaps.maxAtomicCounterBufferBindings;
1516 break;
1517 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1518 *params = mCaps.maxAtomicCounterBufferSize;
1519 break;
1520 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1521 *params = mCaps.maxCombinedAtomicCounterBuffers;
1522 break;
1523 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1524 *params = mCaps.maxCombinedAtomicCounters;
1525 break;
1526 case GL_MAX_IMAGE_UNITS:
1527 *params = mCaps.maxImageUnits;
1528 break;
1529 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1530 *params = mCaps.maxCombinedImageUniforms;
1531 break;
1532 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1533 *params = mCaps.maxShaderStorageBufferBindings;
1534 break;
1535 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1536 *params = mCaps.maxCombinedShaderStorageBlocks;
1537 break;
1538 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1539 *params = mCaps.shaderStorageBufferOffsetAlignment;
1540 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001541
1542 // GL_EXT_geometry_shader
1543 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1544 *params = mCaps.maxFramebufferLayers;
1545 break;
1546 case GL_LAYER_PROVOKING_VERTEX_EXT:
1547 *params = mCaps.layerProvokingVertex;
1548 break;
1549 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1550 *params = mCaps.maxGeometryUniformComponents;
1551 break;
1552 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
1553 *params = mCaps.maxGeometryUniformBlocks;
1554 break;
1555 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1556 *params = mCaps.maxCombinedGeometryUniformComponents;
1557 break;
1558 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1559 *params = mCaps.maxGeometryInputComponents;
1560 break;
1561 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1562 *params = mCaps.maxGeometryOutputComponents;
1563 break;
1564 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1565 *params = mCaps.maxGeometryOutputVertices;
1566 break;
1567 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1568 *params = mCaps.maxGeometryTotalOutputComponents;
1569 break;
1570 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1571 *params = mCaps.maxGeometryShaderInvocations;
1572 break;
1573 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
1574 *params = mCaps.maxGeometryTextureImageUnits;
1575 break;
1576 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
1577 *params = mCaps.maxGeometryAtomicCounterBuffers;
1578 break;
1579 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
1580 *params = mCaps.maxGeometryAtomicCounters;
1581 break;
1582 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
1583 *params = mCaps.maxGeometryImageUniforms;
1584 break;
1585 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
1586 *params = mCaps.maxGeometryShaderStorageBlocks;
1587 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001588 default:
1589 mGLState.getIntegerv(this, pname, params);
1590 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001591 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001592}
1593
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001594void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001595{
Shannon Woods53a94a82014-06-24 15:20:36 -04001596 // Queries about context capabilities and maximums are answered by Context.
1597 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001598 switch (pname)
1599 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001600 case GL_MAX_ELEMENT_INDEX:
1601 *params = mCaps.maxElementIndex;
1602 break;
1603 case GL_MAX_UNIFORM_BLOCK_SIZE:
1604 *params = mCaps.maxUniformBlockSize;
1605 break;
1606 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1607 *params = mCaps.maxCombinedVertexUniformComponents;
1608 break;
1609 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1610 *params = mCaps.maxCombinedFragmentUniformComponents;
1611 break;
1612 case GL_MAX_SERVER_WAIT_TIMEOUT:
1613 *params = mCaps.maxServerWaitTimeout;
1614 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001615
Jamie Madill231c7f52017-04-26 13:45:37 -04001616 // GL_EXT_disjoint_timer_query
1617 case GL_TIMESTAMP_EXT:
1618 *params = mImplementation->getTimestamp();
1619 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001620
Jamie Madill231c7f52017-04-26 13:45:37 -04001621 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1622 *params = mCaps.maxShaderStorageBlockSize;
1623 break;
1624 default:
1625 UNREACHABLE();
1626 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001627 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001628}
1629
Geoff Lang70d0f492015-12-10 17:45:46 -05001630void Context::getPointerv(GLenum pname, void **params) const
1631{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001632 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001633}
1634
Martin Radev66fb8202016-07-28 11:45:20 +03001635void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001636{
Shannon Woods53a94a82014-06-24 15:20:36 -04001637 // Queries about context capabilities and maximums are answered by Context.
1638 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001639
1640 GLenum nativeType;
1641 unsigned int numParams;
1642 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1643 ASSERT(queryStatus);
1644
1645 if (nativeType == GL_INT)
1646 {
1647 switch (target)
1648 {
1649 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1650 ASSERT(index < 3u);
1651 *data = mCaps.maxComputeWorkGroupCount[index];
1652 break;
1653 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1654 ASSERT(index < 3u);
1655 *data = mCaps.maxComputeWorkGroupSize[index];
1656 break;
1657 default:
1658 mGLState.getIntegeri_v(target, index, data);
1659 }
1660 }
1661 else
1662 {
1663 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1664 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001665}
1666
Martin Radev66fb8202016-07-28 11:45:20 +03001667void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001668{
Shannon Woods53a94a82014-06-24 15:20:36 -04001669 // Queries about context capabilities and maximums are answered by Context.
1670 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001671
1672 GLenum nativeType;
1673 unsigned int numParams;
1674 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1675 ASSERT(queryStatus);
1676
1677 if (nativeType == GL_INT_64_ANGLEX)
1678 {
1679 mGLState.getInteger64i_v(target, index, data);
1680 }
1681 else
1682 {
1683 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1684 }
1685}
1686
1687void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1688{
1689 // Queries about context capabilities and maximums are answered by Context.
1690 // Queries about current GL state values are answered by State.
1691
1692 GLenum nativeType;
1693 unsigned int numParams;
1694 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1695 ASSERT(queryStatus);
1696
1697 if (nativeType == GL_BOOL)
1698 {
1699 mGLState.getBooleani_v(target, index, data);
1700 }
1701 else
1702 {
1703 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1704 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001705}
1706
Corentin Wallez336129f2017-10-17 15:55:40 -04001707void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001708{
1709 Buffer *buffer = mGLState.getTargetBuffer(target);
1710 QueryBufferParameteriv(buffer, pname, params);
1711}
1712
1713void Context::getFramebufferAttachmentParameteriv(GLenum target,
1714 GLenum attachment,
1715 GLenum pname,
1716 GLint *params)
1717{
1718 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001719 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001720}
1721
1722void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1723{
1724 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1725 QueryRenderbufferiv(this, renderbuffer, pname, params);
1726}
1727
1728void Context::getTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
1729{
1730 Texture *texture = getTargetTexture(target);
1731 QueryTexParameterfv(texture, pname, params);
1732}
1733
1734void Context::getTexParameteriv(GLenum target, GLenum pname, GLint *params)
1735{
1736 Texture *texture = getTargetTexture(target);
1737 QueryTexParameteriv(texture, pname, params);
1738}
Jiajia Qin5451d532017-11-16 17:16:34 +08001739
1740void Context::getTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint *params)
1741{
1742 Texture *texture =
1743 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
1744 QueryTexLevelParameteriv(texture, target, level, pname, params);
1745}
1746
1747void Context::getTexLevelParameterfv(GLenum target, GLint level, GLenum pname, GLfloat *params)
1748{
1749 Texture *texture =
1750 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
1751 QueryTexLevelParameterfv(texture, target, level, pname, params);
1752}
1753
He Yunchao010e4db2017-03-03 14:22:06 +08001754void Context::texParameterf(GLenum target, GLenum pname, GLfloat param)
1755{
1756 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001757 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001758 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001759}
1760
1761void Context::texParameterfv(GLenum target, GLenum pname, const GLfloat *params)
1762{
1763 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001764 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001765 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001766}
1767
1768void Context::texParameteri(GLenum target, GLenum pname, GLint param)
1769{
1770 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001771 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001772 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001773}
1774
1775void Context::texParameteriv(GLenum target, GLenum pname, const GLint *params)
1776{
1777 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001778 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001779 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001780}
1781
Jamie Madill675fe712016-12-19 13:07:54 -05001782void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001783{
Jamie Madill05b35b22017-10-03 09:01:44 -04001784 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001785 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
1786 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001787}
1788
Jamie Madill675fe712016-12-19 13:07:54 -05001789void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001790{
Jamie Madill05b35b22017-10-03 09:01:44 -04001791 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001792 ANGLE_CONTEXT_TRY(
1793 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
1794 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
Geoff Langf6db0982015-08-25 13:04:00 -04001795}
1796
Jamie Madill876429b2017-04-20 15:46:24 -04001797void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001798{
Jamie Madill05b35b22017-10-03 09:01:44 -04001799 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001800 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001801}
1802
Jamie Madill675fe712016-12-19 13:07:54 -05001803void Context::drawElementsInstanced(GLenum mode,
1804 GLsizei count,
1805 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001806 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001807 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001808{
Jamie Madill05b35b22017-10-03 09:01:44 -04001809 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001810 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001811 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001812}
1813
Jamie Madill675fe712016-12-19 13:07:54 -05001814void Context::drawRangeElements(GLenum mode,
1815 GLuint start,
1816 GLuint end,
1817 GLsizei count,
1818 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001819 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001820{
Jamie Madill05b35b22017-10-03 09:01:44 -04001821 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001822 ANGLE_CONTEXT_TRY(
1823 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001824}
1825
Jamie Madill876429b2017-04-20 15:46:24 -04001826void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001827{
Jamie Madill05b35b22017-10-03 09:01:44 -04001828 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001829 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001830}
1831
Jamie Madill876429b2017-04-20 15:46:24 -04001832void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001833{
Jamie Madill05b35b22017-10-03 09:01:44 -04001834 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001835 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001836}
1837
Jamie Madill675fe712016-12-19 13:07:54 -05001838void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001839{
Jamie Madillafa02a22017-11-23 12:57:38 -05001840 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05001841}
1842
Jamie Madill675fe712016-12-19 13:07:54 -05001843void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001844{
Jamie Madillafa02a22017-11-23 12:57:38 -05001845 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001846}
1847
Austin Kinross6ee1e782015-05-29 17:05:37 -07001848void Context::insertEventMarker(GLsizei length, const char *marker)
1849{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001850 ASSERT(mImplementation);
1851 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001852}
1853
1854void Context::pushGroupMarker(GLsizei length, const char *marker)
1855{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001856 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05001857
1858 if (marker == nullptr)
1859 {
1860 // From the EXT_debug_marker spec,
1861 // "If <marker> is null then an empty string is pushed on the stack."
1862 mImplementation->pushGroupMarker(length, "");
1863 }
1864 else
1865 {
1866 mImplementation->pushGroupMarker(length, marker);
1867 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07001868}
1869
1870void Context::popGroupMarker()
1871{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001872 ASSERT(mImplementation);
1873 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001874}
1875
Geoff Langd8605522016-04-13 10:19:12 -04001876void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1877{
1878 Program *programObject = getProgram(program);
1879 ASSERT(programObject);
1880
1881 programObject->bindUniformLocation(location, name);
1882}
1883
Sami Väisänena797e062016-05-12 15:23:40 +03001884void Context::setCoverageModulation(GLenum components)
1885{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001886 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001887}
1888
Sami Väisänene45e53b2016-05-25 10:36:04 +03001889void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1890{
1891 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1892}
1893
1894void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1895{
1896 GLfloat I[16];
1897 angle::Matrix<GLfloat>::setToIdentity(I);
1898
1899 mGLState.loadPathRenderingMatrix(matrixMode, I);
1900}
1901
1902void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1903{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001904 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001905 if (!pathObj)
1906 return;
1907
1908 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1909 syncRendererState();
1910
1911 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1912}
1913
1914void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1915{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001916 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001917 if (!pathObj)
1918 return;
1919
1920 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1921 syncRendererState();
1922
1923 mImplementation->stencilStrokePath(pathObj, reference, mask);
1924}
1925
1926void Context::coverFillPath(GLuint path, GLenum coverMode)
1927{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001928 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001929 if (!pathObj)
1930 return;
1931
1932 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1933 syncRendererState();
1934
1935 mImplementation->coverFillPath(pathObj, coverMode);
1936}
1937
1938void Context::coverStrokePath(GLuint path, GLenum coverMode)
1939{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001940 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001941 if (!pathObj)
1942 return;
1943
1944 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1945 syncRendererState();
1946
1947 mImplementation->coverStrokePath(pathObj, coverMode);
1948}
1949
1950void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1951{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001952 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001953 if (!pathObj)
1954 return;
1955
1956 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1957 syncRendererState();
1958
1959 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
1960}
1961
1962void Context::stencilThenCoverStrokePath(GLuint path,
1963 GLint reference,
1964 GLuint mask,
1965 GLenum coverMode)
1966{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001967 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001968 if (!pathObj)
1969 return;
1970
1971 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1972 syncRendererState();
1973
1974 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
1975}
1976
Sami Väisänend59ca052016-06-21 16:10:00 +03001977void Context::coverFillPathInstanced(GLsizei numPaths,
1978 GLenum pathNameType,
1979 const void *paths,
1980 GLuint pathBase,
1981 GLenum coverMode,
1982 GLenum transformType,
1983 const GLfloat *transformValues)
1984{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001985 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03001986
1987 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1988 syncRendererState();
1989
1990 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
1991}
Sami Väisänen46eaa942016-06-29 10:26:37 +03001992
Sami Väisänend59ca052016-06-21 16:10:00 +03001993void Context::coverStrokePathInstanced(GLsizei numPaths,
1994 GLenum pathNameType,
1995 const void *paths,
1996 GLuint pathBase,
1997 GLenum coverMode,
1998 GLenum transformType,
1999 const GLfloat *transformValues)
2000{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002001 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002002
2003 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2004 syncRendererState();
2005
2006 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2007 transformValues);
2008}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002009
Sami Väisänend59ca052016-06-21 16:10:00 +03002010void Context::stencilFillPathInstanced(GLsizei numPaths,
2011 GLenum pathNameType,
2012 const void *paths,
2013 GLuint pathBase,
2014 GLenum fillMode,
2015 GLuint mask,
2016 GLenum transformType,
2017 const GLfloat *transformValues)
2018{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002019 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002020
2021 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2022 syncRendererState();
2023
2024 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2025 transformValues);
2026}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002027
Sami Väisänend59ca052016-06-21 16:10:00 +03002028void Context::stencilStrokePathInstanced(GLsizei numPaths,
2029 GLenum pathNameType,
2030 const void *paths,
2031 GLuint pathBase,
2032 GLint reference,
2033 GLuint mask,
2034 GLenum transformType,
2035 const GLfloat *transformValues)
2036{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002037 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002038
2039 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2040 syncRendererState();
2041
2042 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2043 transformValues);
2044}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002045
Sami Väisänend59ca052016-06-21 16:10:00 +03002046void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2047 GLenum pathNameType,
2048 const void *paths,
2049 GLuint pathBase,
2050 GLenum fillMode,
2051 GLuint mask,
2052 GLenum coverMode,
2053 GLenum transformType,
2054 const GLfloat *transformValues)
2055{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002056 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002057
2058 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2059 syncRendererState();
2060
2061 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2062 transformType, transformValues);
2063}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002064
Sami Väisänend59ca052016-06-21 16:10:00 +03002065void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2066 GLenum pathNameType,
2067 const void *paths,
2068 GLuint pathBase,
2069 GLint reference,
2070 GLuint mask,
2071 GLenum coverMode,
2072 GLenum transformType,
2073 const GLfloat *transformValues)
2074{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002075 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002076
2077 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2078 syncRendererState();
2079
2080 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2081 transformType, transformValues);
2082}
2083
Sami Väisänen46eaa942016-06-29 10:26:37 +03002084void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2085{
2086 auto *programObject = getProgram(program);
2087
2088 programObject->bindFragmentInputLocation(location, name);
2089}
2090
2091void Context::programPathFragmentInputGen(GLuint program,
2092 GLint location,
2093 GLenum genMode,
2094 GLint components,
2095 const GLfloat *coeffs)
2096{
2097 auto *programObject = getProgram(program);
2098
Jamie Madillbd044ed2017-06-05 12:59:21 -04002099 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002100}
2101
jchen1015015f72017-03-16 13:54:21 +08002102GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2103{
jchen10fd7c3b52017-03-21 15:36:03 +08002104 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002105 return QueryProgramResourceIndex(programObject, programInterface, name);
2106}
2107
jchen10fd7c3b52017-03-21 15:36:03 +08002108void Context::getProgramResourceName(GLuint program,
2109 GLenum programInterface,
2110 GLuint index,
2111 GLsizei bufSize,
2112 GLsizei *length,
2113 GLchar *name)
2114{
2115 const auto *programObject = getProgram(program);
2116 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2117}
2118
jchen10191381f2017-04-11 13:59:04 +08002119GLint Context::getProgramResourceLocation(GLuint program,
2120 GLenum programInterface,
2121 const GLchar *name)
2122{
2123 const auto *programObject = getProgram(program);
2124 return QueryProgramResourceLocation(programObject, programInterface, name);
2125}
2126
jchen10880683b2017-04-12 16:21:55 +08002127void Context::getProgramResourceiv(GLuint program,
2128 GLenum programInterface,
2129 GLuint index,
2130 GLsizei propCount,
2131 const GLenum *props,
2132 GLsizei bufSize,
2133 GLsizei *length,
2134 GLint *params)
2135{
2136 const auto *programObject = getProgram(program);
2137 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2138 length, params);
2139}
2140
jchen10d9cd7b72017-08-30 15:04:25 +08002141void Context::getProgramInterfaceiv(GLuint program,
2142 GLenum programInterface,
2143 GLenum pname,
2144 GLint *params)
2145{
2146 const auto *programObject = getProgram(program);
2147 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2148}
2149
Jamie Madill71c88b32017-09-14 22:20:29 -04002150void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002151{
Geoff Langda5777c2014-07-11 09:52:58 -04002152 if (error.isError())
2153 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002154 GLenum code = error.getCode();
2155 mErrors.insert(code);
2156 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2157 {
2158 markContextLost();
2159 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002160
Geoff Langee6884e2017-11-09 16:51:11 -05002161 ASSERT(!error.getMessage().empty());
2162 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2163 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002164 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002165}
2166
2167// Get one of the recorded errors and clear its flag, if any.
2168// [OpenGL ES 2.0.24] section 2.5 page 13.
2169GLenum Context::getError()
2170{
Geoff Langda5777c2014-07-11 09:52:58 -04002171 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002172 {
Geoff Langda5777c2014-07-11 09:52:58 -04002173 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002174 }
Geoff Langda5777c2014-07-11 09:52:58 -04002175 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002176 {
Geoff Langda5777c2014-07-11 09:52:58 -04002177 GLenum error = *mErrors.begin();
2178 mErrors.erase(mErrors.begin());
2179 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002180 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002181}
2182
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002183// NOTE: this function should not assume that this context is current!
2184void Context::markContextLost()
2185{
2186 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002187 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002188 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002189 mContextLostForced = true;
2190 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002191 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002192}
2193
2194bool Context::isContextLost()
2195{
2196 return mContextLost;
2197}
2198
Jamie Madillfa920eb2018-01-04 11:45:50 -05002199GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002200{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002201 // Even if the application doesn't want to know about resets, we want to know
2202 // as it will allow us to skip all the calls.
2203 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002204 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002205 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002206 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002207 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002208 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002209
2210 // EXT_robustness, section 2.6: If the reset notification behavior is
2211 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2212 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2213 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002214 }
2215
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002216 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2217 // status should be returned at least once, and GL_NO_ERROR should be returned
2218 // once the device has finished resetting.
2219 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002220 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002221 ASSERT(mResetStatus == GL_NO_ERROR);
2222 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002223
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002224 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002225 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002226 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002227 }
2228 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002229 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002230 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002231 // If markContextLost was used to mark the context lost then
2232 // assume that is not recoverable, and continue to report the
2233 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002234 mResetStatus = mImplementation->getResetStatus();
2235 }
Jamie Madill893ab082014-05-16 16:56:10 -04002236
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002237 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002238}
2239
2240bool Context::isResetNotificationEnabled()
2241{
2242 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2243}
2244
Corentin Walleze3b10e82015-05-20 11:06:25 -04002245const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002246{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002247 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002248}
2249
2250EGLenum Context::getClientType() const
2251{
2252 return mClientType;
2253}
2254
2255EGLenum Context::getRenderBuffer() const
2256{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002257 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2258 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002259 {
2260 return EGL_NONE;
2261 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002262
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002263 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002264 ASSERT(backAttachment != nullptr);
2265 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002266}
2267
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002268VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002269{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002270 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002271 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2272 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002273 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002274 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2275 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002276
Jamie Madill96a483b2017-06-27 16:49:21 -04002277 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002278 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002279
2280 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002281}
2282
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002283TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002284{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002285 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002286 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2287 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002288 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002289 transformFeedback =
2290 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002291 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002292 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002293 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002294
2295 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002296}
2297
2298bool Context::isVertexArrayGenerated(GLuint vertexArray)
2299{
Jamie Madill96a483b2017-06-27 16:49:21 -04002300 ASSERT(mVertexArrayMap.contains(0));
2301 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002302}
2303
2304bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2305{
Jamie Madill96a483b2017-06-27 16:49:21 -04002306 ASSERT(mTransformFeedbackMap.contains(0));
2307 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002308}
2309
Shannon Woods53a94a82014-06-24 15:20:36 -04002310void Context::detachTexture(GLuint texture)
2311{
2312 // Simple pass-through to State's detachTexture method, as textures do not require
2313 // allocation map management either here or in the resource manager at detach time.
2314 // Zero textures are held by the Context, and we don't attempt to request them from
2315 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002316 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002317}
2318
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002319void Context::detachBuffer(GLuint buffer)
2320{
Yuly Novikov5807a532015-12-03 13:01:22 -05002321 // Simple pass-through to State's detachBuffer method, since
2322 // only buffer attachments to container objects that are bound to the current context
2323 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002324
Yuly Novikov5807a532015-12-03 13:01:22 -05002325 // [OpenGL ES 3.2] section 5.1.2 page 45:
2326 // Attachments to unbound container objects, such as
2327 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2328 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002329 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002330}
2331
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002332void Context::detachFramebuffer(GLuint framebuffer)
2333{
Shannon Woods53a94a82014-06-24 15:20:36 -04002334 // Framebuffer detachment is handled by Context, because 0 is a valid
2335 // Framebuffer object, and a pointer to it must be passed from Context
2336 // to State at binding time.
2337
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002338 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002339 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2340 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2341 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002342
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002343 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002344 {
2345 bindReadFramebuffer(0);
2346 }
2347
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002348 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002349 {
2350 bindDrawFramebuffer(0);
2351 }
2352}
2353
2354void Context::detachRenderbuffer(GLuint renderbuffer)
2355{
Jamie Madilla02315b2017-02-23 14:14:47 -05002356 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002357}
2358
Jamie Madill57a89722013-07-02 11:57:03 -04002359void Context::detachVertexArray(GLuint vertexArray)
2360{
Jamie Madill77a72f62015-04-14 11:18:32 -04002361 // Vertex array detachment is handled by Context, because 0 is a valid
2362 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002363 // binding time.
2364
Jamie Madill57a89722013-07-02 11:57:03 -04002365 // [OpenGL ES 3.0.2] section 2.10 page 43:
2366 // If a vertex array object that is currently bound is deleted, the binding
2367 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002368 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002369 {
2370 bindVertexArray(0);
2371 }
2372}
2373
Geoff Langc8058452014-02-03 12:04:11 -05002374void Context::detachTransformFeedback(GLuint transformFeedback)
2375{
Corentin Walleza2257da2016-04-19 16:43:12 -04002376 // Transform feedback detachment is handled by Context, because 0 is a valid
2377 // transform feedback, and a pointer to it must be passed from Context to State at
2378 // binding time.
2379
2380 // The OpenGL specification doesn't mention what should happen when the currently bound
2381 // transform feedback object is deleted. Since it is a container object, we treat it like
2382 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002383 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002384 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002385 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002386 }
Geoff Langc8058452014-02-03 12:04:11 -05002387}
2388
Jamie Madilldc356042013-07-19 16:36:57 -04002389void Context::detachSampler(GLuint sampler)
2390{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002391 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002392}
2393
Yunchao Hea336b902017-08-02 16:05:21 +08002394void Context::detachProgramPipeline(GLuint pipeline)
2395{
2396 mGLState.detachProgramPipeline(this, pipeline);
2397}
2398
Jamie Madill3ef140a2017-08-26 23:11:21 -04002399void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002400{
Shaodde78e82017-05-22 14:13:27 +08002401 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002402}
2403
Jamie Madille29d1672013-07-19 16:36:57 -04002404void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2405{
Geoff Langc1984ed2016-10-07 12:41:00 -04002406 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002407 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002408 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002409 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002410}
Jamie Madille29d1672013-07-19 16:36:57 -04002411
Geoff Langc1984ed2016-10-07 12:41:00 -04002412void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2413{
2414 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002415 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002416 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002417 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002418}
2419
2420void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2421{
Geoff Langc1984ed2016-10-07 12:41:00 -04002422 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002423 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002424 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002425 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002426}
2427
Geoff Langc1984ed2016-10-07 12:41:00 -04002428void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002429{
Geoff Langc1984ed2016-10-07 12:41:00 -04002430 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002431 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002432 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002433 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002434}
2435
Geoff Langc1984ed2016-10-07 12:41:00 -04002436void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002437{
Geoff Langc1984ed2016-10-07 12:41:00 -04002438 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002439 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002440 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002441 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002442}
Jamie Madill9675b802013-07-19 16:36:59 -04002443
Geoff Langc1984ed2016-10-07 12:41:00 -04002444void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2445{
2446 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002447 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002448 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002449 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002450}
2451
Olli Etuahof0fee072016-03-30 15:11:58 +03002452void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2453{
2454 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002455 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002456}
2457
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002458void Context::initRendererString()
2459{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002460 std::ostringstream rendererString;
2461 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002462 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002463 rendererString << ")";
2464
Geoff Langcec35902014-04-16 10:52:36 -04002465 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002466}
2467
Geoff Langc339c4e2016-11-29 10:37:36 -05002468void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002469{
Geoff Langc339c4e2016-11-29 10:37:36 -05002470 const Version &clientVersion = getClientVersion();
2471
2472 std::ostringstream versionString;
2473 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2474 << ANGLE_VERSION_STRING << ")";
2475 mVersionString = MakeStaticString(versionString.str());
2476
2477 std::ostringstream shadingLanguageVersionString;
2478 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2479 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2480 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2481 << ")";
2482 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002483}
2484
Geoff Langcec35902014-04-16 10:52:36 -04002485void Context::initExtensionStrings()
2486{
Geoff Langc339c4e2016-11-29 10:37:36 -05002487 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2488 std::ostringstream combinedStringStream;
2489 std::copy(strings.begin(), strings.end(),
2490 std::ostream_iterator<const char *>(combinedStringStream, " "));
2491 return MakeStaticString(combinedStringStream.str());
2492 };
2493
2494 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002495 for (const auto &extensionString : mExtensions.getStrings())
2496 {
2497 mExtensionStrings.push_back(MakeStaticString(extensionString));
2498 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002499 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002500
Bryan Bernhart58806562017-01-05 13:09:31 -08002501 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2502
Geoff Langc339c4e2016-11-29 10:37:36 -05002503 mRequestableExtensionStrings.clear();
2504 for (const auto &extensionInfo : GetExtensionInfoMap())
2505 {
2506 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002507 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2508 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002509 {
2510 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2511 }
2512 }
2513 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002514}
2515
Geoff Langc339c4e2016-11-29 10:37:36 -05002516const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002517{
Geoff Langc339c4e2016-11-29 10:37:36 -05002518 switch (name)
2519 {
2520 case GL_VENDOR:
2521 return reinterpret_cast<const GLubyte *>("Google Inc.");
2522
2523 case GL_RENDERER:
2524 return reinterpret_cast<const GLubyte *>(mRendererString);
2525
2526 case GL_VERSION:
2527 return reinterpret_cast<const GLubyte *>(mVersionString);
2528
2529 case GL_SHADING_LANGUAGE_VERSION:
2530 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2531
2532 case GL_EXTENSIONS:
2533 return reinterpret_cast<const GLubyte *>(mExtensionString);
2534
2535 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2536 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2537
2538 default:
2539 UNREACHABLE();
2540 return nullptr;
2541 }
Geoff Langcec35902014-04-16 10:52:36 -04002542}
2543
Geoff Langc339c4e2016-11-29 10:37:36 -05002544const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002545{
Geoff Langc339c4e2016-11-29 10:37:36 -05002546 switch (name)
2547 {
2548 case GL_EXTENSIONS:
2549 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2550
2551 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2552 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2553
2554 default:
2555 UNREACHABLE();
2556 return nullptr;
2557 }
Geoff Langcec35902014-04-16 10:52:36 -04002558}
2559
2560size_t Context::getExtensionStringCount() const
2561{
2562 return mExtensionStrings.size();
2563}
2564
Geoff Lang111a99e2017-10-17 10:58:41 -04002565bool Context::isExtensionRequestable(const char *name)
2566{
2567 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2568 auto extension = extensionInfos.find(name);
2569
2570 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2571 return extension != extensionInfos.end() && extension->second.Requestable &&
2572 nativeExtensions.*(extension->second.ExtensionsMember);
2573}
2574
Geoff Langc339c4e2016-11-29 10:37:36 -05002575void Context::requestExtension(const char *name)
2576{
2577 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2578 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2579 const auto &extension = extensionInfos.at(name);
2580 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002581 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002582
2583 if (mExtensions.*(extension.ExtensionsMember))
2584 {
2585 // Extension already enabled
2586 return;
2587 }
2588
2589 mExtensions.*(extension.ExtensionsMember) = true;
2590 updateCaps();
2591 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002592
Jamie Madill2f348d22017-06-05 10:50:59 -04002593 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2594 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002595
Jamie Madill81c2e252017-09-09 23:32:46 -04002596 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2597 // sampleable.
2598 mState.mTextures->signalAllTexturesDirty();
Geoff Lang9aded172017-04-05 11:07:56 -04002599 for (auto &zeroTexture : mZeroTextures)
2600 {
Jamie Madill05b35b22017-10-03 09:01:44 -04002601 zeroTexture.second->signalDirty(InitState::Initialized);
Geoff Lang9aded172017-04-05 11:07:56 -04002602 }
2603
2604 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002605}
2606
2607size_t Context::getRequestableExtensionStringCount() const
2608{
2609 return mRequestableExtensionStrings.size();
2610}
2611
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002612void Context::beginTransformFeedback(GLenum primitiveMode)
2613{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002614 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002615 ASSERT(transformFeedback != nullptr);
2616 ASSERT(!transformFeedback->isPaused());
2617
Jamie Madill6c1f6712017-02-14 19:08:04 -05002618 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002619}
2620
2621bool Context::hasActiveTransformFeedback(GLuint program) const
2622{
2623 for (auto pair : mTransformFeedbackMap)
2624 {
2625 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2626 {
2627 return true;
2628 }
2629 }
2630 return false;
2631}
2632
Geoff Langb433e872017-10-05 14:01:47 -04002633void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002634{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002635 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002636
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002637 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002638
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002639 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002640
Geoff Langeb66a6e2016-10-31 13:06:12 -04002641 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002642 {
2643 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002644 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002645 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002646 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002647 mExtensions.multiview = false;
2648 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002649 }
2650
Jiawei Shao89be29a2017-11-06 14:36:45 +08002651 if (getClientVersion() < ES_3_1)
2652 {
2653 // Disable ES3.1+ extensions
2654 mExtensions.geometryShader = false;
2655 }
2656
Geoff Langeb66a6e2016-10-31 13:06:12 -04002657 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002658 {
2659 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002660 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002661 }
2662
Jamie Madill00ed7a12016-05-19 13:13:38 -04002663 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002664 mExtensions.bindUniformLocation = true;
2665 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002666 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002667 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002668 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002669
2670 // Enable the no error extension if the context was created with the flag.
2671 mExtensions.noError = mSkipValidation;
2672
Corentin Wallezccab69d2017-01-27 16:57:15 -05002673 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002674 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002675
Geoff Lang70d0f492015-12-10 17:45:46 -05002676 // Explicitly enable GL_KHR_debug
2677 mExtensions.debug = true;
2678 mExtensions.maxDebugMessageLength = 1024;
2679 mExtensions.maxDebugLoggedMessages = 1024;
2680 mExtensions.maxDebugGroupStackDepth = 1024;
2681 mExtensions.maxLabelLength = 1024;
2682
Geoff Langff5b2d52016-09-07 11:32:23 -04002683 // Explicitly enable GL_ANGLE_robust_client_memory
2684 mExtensions.robustClientMemory = true;
2685
Jamie Madille08a1d32017-03-07 17:24:06 -05002686 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002687 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002688
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002689 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2690 // supports it.
2691 mExtensions.robustBufferAccessBehavior =
2692 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2693
Jamie Madillc43be722017-07-13 16:22:14 -04002694 // Enable the cache control query unconditionally.
2695 mExtensions.programCacheControl = true;
2696
Geoff Lang301d1612014-07-09 10:34:37 -04002697 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002698 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002699
Jamie Madill0f80ed82017-09-19 00:24:56 -04002700 if (getClientVersion() < ES_3_1)
2701 {
2702 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2703 }
2704 else
2705 {
2706 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2707 }
Geoff Lang301d1612014-07-09 10:34:37 -04002708
Jamie Madill0f80ed82017-09-19 00:24:56 -04002709 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2710 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2711 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2712
2713 // Limit textures as well, so we can use fast bitsets with texture bindings.
2714 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2715 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2716 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002717
Jiawei Shaodb342272017-09-27 10:21:45 +08002718 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2719
Geoff Langc287ea62016-09-16 14:46:51 -04002720 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002721 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002722 for (const auto &extensionInfo : GetExtensionInfoMap())
2723 {
2724 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002725 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002726 {
2727 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2728 }
2729 }
2730
2731 // Generate texture caps
2732 updateCaps();
2733}
2734
2735void Context::updateCaps()
2736{
Geoff Lang900013c2014-07-07 11:32:19 -04002737 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002738 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002739
Jamie Madill7b62cf92017-11-02 15:20:49 -04002740 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04002741 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04002742 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04002743 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002744
Geoff Lang0d8b7242015-09-09 14:56:53 -04002745 // Update the format caps based on the client version and extensions.
2746 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2747 // ES3.
2748 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002749 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002750 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002751 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002752 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002753 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002754
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002755 // OpenGL ES does not support multisampling with non-rendererable formats
2756 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002757 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002758 (getClientVersion() < ES_3_1 &&
2759 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002760 {
Geoff Langd87878e2014-09-19 15:42:59 -04002761 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002762 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002763 else
2764 {
2765 // We may have limited the max samples for some required renderbuffer formats due to
2766 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2767 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2768
2769 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2770 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2771 // exception of signed and unsigned integer formats."
2772 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2773 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2774 {
2775 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2776 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2777 }
2778
2779 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2780 if (getClientVersion() >= ES_3_1)
2781 {
2782 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2783 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2784 // the exception that the signed and unsigned integer formats are required only to
2785 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2786 // multisamples, which must be at least one."
2787 if (formatInfo.componentType == GL_INT ||
2788 formatInfo.componentType == GL_UNSIGNED_INT)
2789 {
2790 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2791 }
2792
2793 // GLES 3.1 section 19.3.1.
2794 if (formatCaps.texturable)
2795 {
2796 if (formatInfo.depthBits > 0)
2797 {
2798 mCaps.maxDepthTextureSamples =
2799 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2800 }
2801 else if (formatInfo.redBits > 0)
2802 {
2803 mCaps.maxColorTextureSamples =
2804 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2805 }
2806 }
2807 }
2808 }
Geoff Langd87878e2014-09-19 15:42:59 -04002809
2810 if (formatCaps.texturable && formatInfo.compressed)
2811 {
Geoff Langca271392017-04-05 12:30:00 -04002812 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002813 }
2814
Geoff Langca271392017-04-05 12:30:00 -04002815 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002816 }
Jamie Madill32447362017-06-28 14:53:52 -04002817
2818 // If program binary is disabled, blank out the memory cache pointer.
2819 if (!mImplementation->getNativeExtensions().getProgramBinary)
2820 {
2821 mMemoryProgramCache = nullptr;
2822 }
Corentin Walleze4477002017-12-01 14:39:58 -05002823
2824 // Compute which buffer types are allowed
2825 mValidBufferBindings.reset();
2826 mValidBufferBindings.set(BufferBinding::ElementArray);
2827 mValidBufferBindings.set(BufferBinding::Array);
2828
2829 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
2830 {
2831 mValidBufferBindings.set(BufferBinding::PixelPack);
2832 mValidBufferBindings.set(BufferBinding::PixelUnpack);
2833 }
2834
2835 if (getClientVersion() >= ES_3_0)
2836 {
2837 mValidBufferBindings.set(BufferBinding::CopyRead);
2838 mValidBufferBindings.set(BufferBinding::CopyWrite);
2839 mValidBufferBindings.set(BufferBinding::TransformFeedback);
2840 mValidBufferBindings.set(BufferBinding::Uniform);
2841 }
2842
2843 if (getClientVersion() >= ES_3_1)
2844 {
2845 mValidBufferBindings.set(BufferBinding::AtomicCounter);
2846 mValidBufferBindings.set(BufferBinding::ShaderStorage);
2847 mValidBufferBindings.set(BufferBinding::DrawIndirect);
2848 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
2849 }
Geoff Lang493daf52014-07-03 13:38:44 -04002850}
2851
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002852void Context::initWorkarounds()
2853{
Jamie Madill761b02c2017-06-23 16:27:06 -04002854 // Apply back-end workarounds.
2855 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2856
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002857 // Lose the context upon out of memory error if the application is
2858 // expecting to watch for those events.
2859 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2860}
2861
Jamie Madill05b35b22017-10-03 09:01:44 -04002862Error Context::prepareForDraw()
2863{
2864 syncRendererState();
Jamie Madilla59fc192017-11-02 12:57:58 -04002865
2866 if (isRobustResourceInitEnabled())
2867 {
2868 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
2869 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
2870 }
2871
Jamie Madill05b35b22017-10-03 09:01:44 -04002872 return NoError();
2873}
2874
Jamie Madill1b94d432015-08-07 13:23:23 -04002875void Context::syncRendererState()
2876{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002877 mGLState.syncDirtyObjects(this);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002878 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madillfe548342017-06-19 11:13:24 -04002879 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002880 mGLState.clearDirtyBits();
Jamie Madill1b94d432015-08-07 13:23:23 -04002881}
2882
Jamie Madillad9f24e2016-02-12 09:27:24 -05002883void Context::syncRendererState(const State::DirtyBits &bitMask,
2884 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002885{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002886 mGLState.syncDirtyObjects(this, objectMask);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002887 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002888 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002889 mGLState.clearDirtyBits(dirtyBits);
Jamie Madill1b94d432015-08-07 13:23:23 -04002890}
Jamie Madillc29968b2016-01-20 11:17:23 -05002891
2892void Context::blitFramebuffer(GLint srcX0,
2893 GLint srcY0,
2894 GLint srcX1,
2895 GLint srcY1,
2896 GLint dstX0,
2897 GLint dstY0,
2898 GLint dstX1,
2899 GLint dstY1,
2900 GLbitfield mask,
2901 GLenum filter)
2902{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002903 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002904 ASSERT(drawFramebuffer);
2905
2906 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2907 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2908
Jamie Madillad9f24e2016-02-12 09:27:24 -05002909 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002910
Jamie Madillc564c072017-06-01 12:45:42 -04002911 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002912}
Jamie Madillc29968b2016-01-20 11:17:23 -05002913
2914void Context::clear(GLbitfield mask)
2915{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002916 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002917 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002918}
2919
2920void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2921{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002922 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002923 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002924}
2925
2926void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2927{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002928 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002929 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002930}
2931
2932void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2933{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002934 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002935 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002936}
2937
2938void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2939{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002940 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002941 ASSERT(framebufferObject);
2942
2943 // If a buffer is not present, the clear has no effect
2944 if (framebufferObject->getDepthbuffer() == nullptr &&
2945 framebufferObject->getStencilbuffer() == nullptr)
2946 {
2947 return;
2948 }
2949
Jamie Madillad9f24e2016-02-12 09:27:24 -05002950 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002951 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05002952}
2953
2954void Context::readPixels(GLint x,
2955 GLint y,
2956 GLsizei width,
2957 GLsizei height,
2958 GLenum format,
2959 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002960 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05002961{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002962 if (width == 0 || height == 0)
2963 {
2964 return;
2965 }
2966
Jamie Madillad9f24e2016-02-12 09:27:24 -05002967 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05002968
Jamie Madillb6664922017-07-25 12:55:04 -04002969 Framebuffer *readFBO = mGLState.getReadFramebuffer();
2970 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05002971
2972 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04002973 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05002974}
2975
2976void Context::copyTexImage2D(GLenum target,
2977 GLint level,
2978 GLenum internalformat,
2979 GLint x,
2980 GLint y,
2981 GLsizei width,
2982 GLsizei height,
2983 GLint border)
2984{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002985 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04002986 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05002987
Jamie Madillc29968b2016-01-20 11:17:23 -05002988 Rectangle sourceArea(x, y, width, height);
2989
Jamie Madill05b35b22017-10-03 09:01:44 -04002990 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002991 Texture *texture =
2992 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05002993 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05002994}
2995
2996void Context::copyTexSubImage2D(GLenum target,
2997 GLint level,
2998 GLint xoffset,
2999 GLint yoffset,
3000 GLint x,
3001 GLint y,
3002 GLsizei width,
3003 GLsizei height)
3004{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003005 if (width == 0 || height == 0)
3006 {
3007 return;
3008 }
3009
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003010 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003011 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003012
Jamie Madillc29968b2016-01-20 11:17:23 -05003013 Offset destOffset(xoffset, yoffset, 0);
3014 Rectangle sourceArea(x, y, width, height);
3015
Jamie Madill05b35b22017-10-03 09:01:44 -04003016 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003017 Texture *texture =
3018 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003019 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003020}
3021
3022void Context::copyTexSubImage3D(GLenum target,
3023 GLint level,
3024 GLint xoffset,
3025 GLint yoffset,
3026 GLint zoffset,
3027 GLint x,
3028 GLint y,
3029 GLsizei width,
3030 GLsizei height)
3031{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003032 if (width == 0 || height == 0)
3033 {
3034 return;
3035 }
3036
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003037 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003038 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003039
Jamie Madillc29968b2016-01-20 11:17:23 -05003040 Offset destOffset(xoffset, yoffset, zoffset);
3041 Rectangle sourceArea(x, y, width, height);
3042
Jamie Madill05b35b22017-10-03 09:01:44 -04003043 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3044 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003045 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003046}
3047
3048void Context::framebufferTexture2D(GLenum target,
3049 GLenum attachment,
3050 GLenum textarget,
3051 GLuint texture,
3052 GLint level)
3053{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003054 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003055 ASSERT(framebuffer);
3056
3057 if (texture != 0)
3058 {
3059 Texture *textureObj = getTexture(texture);
3060
3061 ImageIndex index = ImageIndex::MakeInvalid();
3062
3063 if (textarget == GL_TEXTURE_2D)
3064 {
3065 index = ImageIndex::Make2D(level);
3066 }
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003067 else if (textarget == GL_TEXTURE_RECTANGLE_ANGLE)
3068 {
3069 index = ImageIndex::MakeRectangle(level);
3070 }
JiangYizhoubddc46b2016-12-09 09:50:51 +08003071 else if (textarget == GL_TEXTURE_2D_MULTISAMPLE)
3072 {
3073 ASSERT(level == 0);
3074 index = ImageIndex::Make2DMultisample();
3075 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003076 else
3077 {
3078 ASSERT(IsCubeMapTextureTarget(textarget));
3079 index = ImageIndex::MakeCube(textarget, level);
3080 }
3081
Jamie Madilla02315b2017-02-23 14:14:47 -05003082 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003083 }
3084 else
3085 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003086 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003087 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003088
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003089 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003090}
3091
3092void Context::framebufferRenderbuffer(GLenum target,
3093 GLenum attachment,
3094 GLenum renderbuffertarget,
3095 GLuint renderbuffer)
3096{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003097 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003098 ASSERT(framebuffer);
3099
3100 if (renderbuffer != 0)
3101 {
3102 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003103
3104 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003105 renderbufferObject);
3106 }
3107 else
3108 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003109 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003110 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003111
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003112 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003113}
3114
3115void Context::framebufferTextureLayer(GLenum target,
3116 GLenum attachment,
3117 GLuint texture,
3118 GLint level,
3119 GLint layer)
3120{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003121 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003122 ASSERT(framebuffer);
3123
3124 if (texture != 0)
3125 {
3126 Texture *textureObject = getTexture(texture);
3127
3128 ImageIndex index = ImageIndex::MakeInvalid();
3129
3130 if (textureObject->getTarget() == GL_TEXTURE_3D)
3131 {
3132 index = ImageIndex::Make3D(level, layer);
3133 }
3134 else
3135 {
3136 ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY);
3137 index = ImageIndex::Make2DArray(level, layer);
3138 }
3139
Jamie Madilla02315b2017-02-23 14:14:47 -05003140 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003141 }
3142 else
3143 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003144 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003145 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003146
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003147 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003148}
3149
Martin Radev137032d2017-07-13 10:11:12 +03003150void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3151 GLenum attachment,
3152 GLuint texture,
3153 GLint level,
3154 GLint baseViewIndex,
3155 GLsizei numViews)
3156{
Martin Radev82ef7742017-08-08 17:44:58 +03003157 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3158 ASSERT(framebuffer);
3159
3160 if (texture != 0)
3161 {
3162 Texture *textureObj = getTexture(texture);
3163
Martin Radev18b75ba2017-08-15 15:50:40 +03003164 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003165 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3166 numViews, baseViewIndex);
3167 }
3168 else
3169 {
3170 framebuffer->resetAttachment(this, attachment);
3171 }
3172
3173 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003174}
3175
3176void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3177 GLenum attachment,
3178 GLuint texture,
3179 GLint level,
3180 GLsizei numViews,
3181 const GLint *viewportOffsets)
3182{
Martin Radev5dae57b2017-07-14 16:15:55 +03003183 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3184 ASSERT(framebuffer);
3185
3186 if (texture != 0)
3187 {
3188 Texture *textureObj = getTexture(texture);
3189
3190 ImageIndex index = ImageIndex::Make2D(level);
3191 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3192 textureObj, numViews, viewportOffsets);
3193 }
3194 else
3195 {
3196 framebuffer->resetAttachment(this, attachment);
3197 }
3198
3199 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003200}
3201
Jamie Madillc29968b2016-01-20 11:17:23 -05003202void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3203{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003204 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003205 ASSERT(framebuffer);
3206 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003207 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003208}
3209
3210void Context::readBuffer(GLenum mode)
3211{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003212 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003213 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003214 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003215}
3216
3217void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3218{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003219 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003220 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003221
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003222 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003223 ASSERT(framebuffer);
3224
3225 // The specification isn't clear what should be done when the framebuffer isn't complete.
3226 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003227 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003228}
3229
3230void Context::invalidateFramebuffer(GLenum target,
3231 GLsizei numAttachments,
3232 const GLenum *attachments)
3233{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003234 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003235 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003236
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003237 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003238 ASSERT(framebuffer);
3239
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003240 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003241 {
Jamie Madill437fa652016-05-03 15:13:24 -04003242 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003243 }
Jamie Madill437fa652016-05-03 15:13:24 -04003244
Jamie Madill4928b7c2017-06-20 12:57:39 -04003245 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003246}
3247
3248void Context::invalidateSubFramebuffer(GLenum target,
3249 GLsizei numAttachments,
3250 const GLenum *attachments,
3251 GLint x,
3252 GLint y,
3253 GLsizei width,
3254 GLsizei height)
3255{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003256 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003257 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003258
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003259 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003260 ASSERT(framebuffer);
3261
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003262 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003263 {
Jamie Madill437fa652016-05-03 15:13:24 -04003264 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003265 }
Jamie Madill437fa652016-05-03 15:13:24 -04003266
3267 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003268 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003269}
3270
Jamie Madill73a84962016-02-12 09:27:23 -05003271void Context::texImage2D(GLenum target,
3272 GLint level,
3273 GLint internalformat,
3274 GLsizei width,
3275 GLsizei height,
3276 GLint border,
3277 GLenum format,
3278 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003279 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003280{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003281 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003282
3283 Extents size(width, height, 1);
3284 Texture *texture =
3285 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003286 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3287 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003288}
3289
3290void Context::texImage3D(GLenum target,
3291 GLint level,
3292 GLint internalformat,
3293 GLsizei width,
3294 GLsizei height,
3295 GLsizei depth,
3296 GLint border,
3297 GLenum format,
3298 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003299 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003300{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003301 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003302
3303 Extents size(width, height, depth);
3304 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003305 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3306 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003307}
3308
3309void Context::texSubImage2D(GLenum target,
3310 GLint level,
3311 GLint xoffset,
3312 GLint yoffset,
3313 GLsizei width,
3314 GLsizei height,
3315 GLenum format,
3316 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003317 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003318{
3319 // Zero sized uploads are valid but no-ops
3320 if (width == 0 || height == 0)
3321 {
3322 return;
3323 }
3324
Jamie Madillad9f24e2016-02-12 09:27:24 -05003325 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003326
3327 Box area(xoffset, yoffset, 0, width, height, 1);
3328 Texture *texture =
3329 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003330 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3331 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003332}
3333
3334void Context::texSubImage3D(GLenum target,
3335 GLint level,
3336 GLint xoffset,
3337 GLint yoffset,
3338 GLint zoffset,
3339 GLsizei width,
3340 GLsizei height,
3341 GLsizei depth,
3342 GLenum format,
3343 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003344 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003345{
3346 // Zero sized uploads are valid but no-ops
3347 if (width == 0 || height == 0 || depth == 0)
3348 {
3349 return;
3350 }
3351
Jamie Madillad9f24e2016-02-12 09:27:24 -05003352 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003353
3354 Box area(xoffset, yoffset, zoffset, width, height, depth);
3355 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003356 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3357 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003358}
3359
3360void Context::compressedTexImage2D(GLenum target,
3361 GLint level,
3362 GLenum internalformat,
3363 GLsizei width,
3364 GLsizei height,
3365 GLint border,
3366 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003367 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003368{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003369 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003370
3371 Extents size(width, height, 1);
3372 Texture *texture =
3373 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003374 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003375 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003376 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003377}
3378
3379void Context::compressedTexImage3D(GLenum target,
3380 GLint level,
3381 GLenum internalformat,
3382 GLsizei width,
3383 GLsizei height,
3384 GLsizei depth,
3385 GLint border,
3386 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003387 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003388{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003389 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003390
3391 Extents size(width, height, depth);
3392 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003393 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003394 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003395 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003396}
3397
3398void Context::compressedTexSubImage2D(GLenum target,
3399 GLint level,
3400 GLint xoffset,
3401 GLint yoffset,
3402 GLsizei width,
3403 GLsizei height,
3404 GLenum format,
3405 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003406 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003407{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003408 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003409
3410 Box area(xoffset, yoffset, 0, width, height, 1);
3411 Texture *texture =
3412 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003413 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003414 format, imageSize,
3415 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003416}
3417
3418void Context::compressedTexSubImage3D(GLenum target,
3419 GLint level,
3420 GLint xoffset,
3421 GLint yoffset,
3422 GLint zoffset,
3423 GLsizei width,
3424 GLsizei height,
3425 GLsizei depth,
3426 GLenum format,
3427 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003428 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003429{
3430 // Zero sized uploads are valid but no-ops
3431 if (width == 0 || height == 0)
3432 {
3433 return;
3434 }
3435
Jamie Madillad9f24e2016-02-12 09:27:24 -05003436 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003437
3438 Box area(xoffset, yoffset, zoffset, width, height, depth);
3439 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003440 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003441 format, imageSize,
3442 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003443}
3444
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003445void Context::generateMipmap(GLenum target)
3446{
3447 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003448 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003449}
3450
Jamie Madill007530e2017-12-28 14:27:04 -05003451void Context::copyTexture(GLuint sourceId,
3452 GLint sourceLevel,
3453 GLenum destTarget,
3454 GLuint destId,
3455 GLint destLevel,
3456 GLint internalFormat,
3457 GLenum destType,
3458 GLboolean unpackFlipY,
3459 GLboolean unpackPremultiplyAlpha,
3460 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003461{
3462 syncStateForTexImage();
3463
3464 gl::Texture *sourceTexture = getTexture(sourceId);
3465 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05003466 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
3467 sourceLevel, ConvertToBool(unpackFlipY),
3468 ConvertToBool(unpackPremultiplyAlpha),
3469 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003470}
3471
Jamie Madill007530e2017-12-28 14:27:04 -05003472void Context::copySubTexture(GLuint sourceId,
3473 GLint sourceLevel,
3474 GLenum destTarget,
3475 GLuint destId,
3476 GLint destLevel,
3477 GLint xoffset,
3478 GLint yoffset,
3479 GLint x,
3480 GLint y,
3481 GLsizei width,
3482 GLsizei height,
3483 GLboolean unpackFlipY,
3484 GLboolean unpackPremultiplyAlpha,
3485 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003486{
3487 // Zero sized copies are valid but no-ops
3488 if (width == 0 || height == 0)
3489 {
3490 return;
3491 }
3492
3493 syncStateForTexImage();
3494
3495 gl::Texture *sourceTexture = getTexture(sourceId);
3496 gl::Texture *destTexture = getTexture(destId);
3497 Offset offset(xoffset, yoffset, 0);
3498 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05003499 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
3500 ConvertToBool(unpackFlipY),
3501 ConvertToBool(unpackPremultiplyAlpha),
3502 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003503}
3504
Jamie Madill007530e2017-12-28 14:27:04 -05003505void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07003506{
3507 syncStateForTexImage();
3508
3509 gl::Texture *sourceTexture = getTexture(sourceId);
3510 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003511 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003512}
3513
Corentin Wallez336129f2017-10-17 15:55:40 -04003514void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003515{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003516 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003517 ASSERT(buffer);
3518
Geoff Lang496c02d2016-10-20 11:38:11 -07003519 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003520}
3521
Corentin Wallez336129f2017-10-17 15:55:40 -04003522void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003523{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003524 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003525 ASSERT(buffer);
3526
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003527 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003528 if (error.isError())
3529 {
Jamie Madill437fa652016-05-03 15:13:24 -04003530 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003531 return nullptr;
3532 }
3533
3534 return buffer->getMapPointer();
3535}
3536
Corentin Wallez336129f2017-10-17 15:55:40 -04003537GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003538{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003539 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003540 ASSERT(buffer);
3541
3542 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003543 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003544 if (error.isError())
3545 {
Jamie Madill437fa652016-05-03 15:13:24 -04003546 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003547 return GL_FALSE;
3548 }
3549
3550 return result;
3551}
3552
Corentin Wallez336129f2017-10-17 15:55:40 -04003553void *Context::mapBufferRange(BufferBinding target,
3554 GLintptr offset,
3555 GLsizeiptr length,
3556 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003557{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003558 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003559 ASSERT(buffer);
3560
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003561 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003562 if (error.isError())
3563 {
Jamie Madill437fa652016-05-03 15:13:24 -04003564 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003565 return nullptr;
3566 }
3567
3568 return buffer->getMapPointer();
3569}
3570
Corentin Wallez336129f2017-10-17 15:55:40 -04003571void Context::flushMappedBufferRange(BufferBinding /*target*/,
3572 GLintptr /*offset*/,
3573 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03003574{
3575 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3576}
3577
Jamie Madillad9f24e2016-02-12 09:27:24 -05003578void Context::syncStateForReadPixels()
3579{
3580 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3581}
3582
3583void Context::syncStateForTexImage()
3584{
3585 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3586}
3587
3588void Context::syncStateForClear()
3589{
3590 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3591}
3592
3593void Context::syncStateForBlit()
3594{
3595 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3596}
3597
Jiajia Qin5451d532017-11-16 17:16:34 +08003598void Context::activeShaderProgram(GLuint pipeline, GLuint program)
3599{
3600 UNIMPLEMENTED();
3601}
3602
Jamie Madillc20ab272016-06-09 07:20:46 -07003603void Context::activeTexture(GLenum texture)
3604{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003605 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003606}
3607
Jamie Madill876429b2017-04-20 15:46:24 -04003608void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003609{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003610 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003611}
3612
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003613void Context::blendEquation(GLenum mode)
3614{
3615 mGLState.setBlendEquation(mode, mode);
3616}
3617
Jamie Madillc20ab272016-06-09 07:20:46 -07003618void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3619{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003620 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003621}
3622
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003623void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3624{
3625 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3626}
3627
Jamie Madillc20ab272016-06-09 07:20:46 -07003628void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3629{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003630 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003631}
3632
Jamie Madill876429b2017-04-20 15:46:24 -04003633void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003634{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003635 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003636}
3637
Jamie Madill876429b2017-04-20 15:46:24 -04003638void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003639{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003640 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003641}
3642
3643void Context::clearStencil(GLint s)
3644{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003645 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003646}
3647
3648void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3649{
Geoff Lang92019432017-11-20 13:09:34 -05003650 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
3651 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003652}
3653
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003654void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003655{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003656 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003657}
3658
3659void Context::depthFunc(GLenum func)
3660{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003661 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003662}
3663
3664void Context::depthMask(GLboolean flag)
3665{
Geoff Lang92019432017-11-20 13:09:34 -05003666 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07003667}
3668
Jamie Madill876429b2017-04-20 15:46:24 -04003669void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003670{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003671 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003672}
3673
3674void Context::disable(GLenum cap)
3675{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003676 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003677}
3678
3679void Context::disableVertexAttribArray(GLuint index)
3680{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003681 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003682}
3683
3684void Context::enable(GLenum cap)
3685{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003686 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003687}
3688
3689void Context::enableVertexAttribArray(GLuint index)
3690{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003691 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003692}
3693
3694void Context::frontFace(GLenum mode)
3695{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003696 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003697}
3698
3699void Context::hint(GLenum target, GLenum mode)
3700{
3701 switch (target)
3702 {
3703 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003704 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003705 break;
3706
3707 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003708 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003709 break;
3710
3711 default:
3712 UNREACHABLE();
3713 return;
3714 }
3715}
3716
3717void Context::lineWidth(GLfloat width)
3718{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003719 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003720}
3721
3722void Context::pixelStorei(GLenum pname, GLint param)
3723{
3724 switch (pname)
3725 {
3726 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003727 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003728 break;
3729
3730 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003731 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003732 break;
3733
3734 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003735 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003736 break;
3737
3738 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003739 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003740 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003741 break;
3742
3743 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003744 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003745 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003746 break;
3747
3748 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003749 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003750 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003751 break;
3752
3753 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003754 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003755 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003756 break;
3757
3758 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003759 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003760 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003761 break;
3762
3763 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003764 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003765 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003766 break;
3767
3768 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003769 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003770 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003771 break;
3772
3773 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003774 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003775 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003776 break;
3777
3778 default:
3779 UNREACHABLE();
3780 return;
3781 }
3782}
3783
3784void Context::polygonOffset(GLfloat factor, GLfloat units)
3785{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003786 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003787}
3788
Jamie Madill876429b2017-04-20 15:46:24 -04003789void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003790{
Geoff Lang92019432017-11-20 13:09:34 -05003791 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07003792}
3793
Jiawei Shaodb342272017-09-27 10:21:45 +08003794void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3795{
3796 mGLState.setSampleMaskParams(maskNumber, mask);
3797}
3798
Jamie Madillc20ab272016-06-09 07:20:46 -07003799void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3800{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003801 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003802}
3803
3804void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3805{
3806 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3807 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003808 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003809 }
3810
3811 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3812 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003813 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003814 }
3815}
3816
3817void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3818{
3819 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3820 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003821 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003822 }
3823
3824 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3825 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003826 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003827 }
3828}
3829
3830void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3831{
3832 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3833 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003834 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003835 }
3836
3837 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3838 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003839 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003840 }
3841}
3842
3843void Context::vertexAttrib1f(GLuint index, GLfloat x)
3844{
3845 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003846 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003847}
3848
3849void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3850{
3851 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003852 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003853}
3854
3855void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3856{
3857 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003858 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003859}
3860
3861void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3862{
3863 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003864 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003865}
3866
3867void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3868{
3869 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003870 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003871}
3872
3873void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3874{
3875 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003876 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003877}
3878
3879void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3880{
3881 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003882 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003883}
3884
3885void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3886{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003887 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003888}
3889
3890void Context::vertexAttribPointer(GLuint index,
3891 GLint size,
3892 GLenum type,
3893 GLboolean normalized,
3894 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003895 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003896{
Corentin Wallez336129f2017-10-17 15:55:40 -04003897 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05003898 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003899}
3900
Shao80957d92017-02-20 21:25:59 +08003901void Context::vertexAttribFormat(GLuint attribIndex,
3902 GLint size,
3903 GLenum type,
3904 GLboolean normalized,
3905 GLuint relativeOffset)
3906{
Geoff Lang92019432017-11-20 13:09:34 -05003907 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08003908 relativeOffset);
3909}
3910
3911void Context::vertexAttribIFormat(GLuint attribIndex,
3912 GLint size,
3913 GLenum type,
3914 GLuint relativeOffset)
3915{
3916 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3917}
3918
3919void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3920{
Shaodde78e82017-05-22 14:13:27 +08003921 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08003922}
3923
Jiajia Qin5451d532017-11-16 17:16:34 +08003924void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08003925{
3926 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3927}
3928
Jamie Madillc20ab272016-06-09 07:20:46 -07003929void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3930{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003931 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003932}
3933
3934void Context::vertexAttribIPointer(GLuint index,
3935 GLint size,
3936 GLenum type,
3937 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003938 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003939{
Corentin Wallez336129f2017-10-17 15:55:40 -04003940 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
3941 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003942}
3943
3944void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3945{
3946 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003947 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003948}
3949
3950void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
3951{
3952 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003953 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003954}
3955
3956void Context::vertexAttribI4iv(GLuint index, const GLint *v)
3957{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003958 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003959}
3960
3961void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
3962{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003963 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003964}
3965
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003966void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
3967{
3968 const VertexAttribCurrentValueData &currentValues =
3969 getGLState().getVertexAttribCurrentValue(index);
3970 const VertexArray *vao = getGLState().getVertexArray();
3971 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3972 currentValues, pname, params);
3973}
3974
3975void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
3976{
3977 const VertexAttribCurrentValueData &currentValues =
3978 getGLState().getVertexAttribCurrentValue(index);
3979 const VertexArray *vao = getGLState().getVertexArray();
3980 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3981 currentValues, pname, params);
3982}
3983
3984void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
3985{
3986 const VertexAttribCurrentValueData &currentValues =
3987 getGLState().getVertexAttribCurrentValue(index);
3988 const VertexArray *vao = getGLState().getVertexArray();
3989 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3990 currentValues, pname, params);
3991}
3992
3993void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
3994{
3995 const VertexAttribCurrentValueData &currentValues =
3996 getGLState().getVertexAttribCurrentValue(index);
3997 const VertexArray *vao = getGLState().getVertexArray();
3998 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
3999 currentValues, pname, params);
4000}
4001
Jamie Madill876429b2017-04-20 15:46:24 -04004002void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004003{
4004 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4005 QueryVertexAttribPointerv(attrib, pname, pointer);
4006}
4007
Jamie Madillc20ab272016-06-09 07:20:46 -07004008void Context::debugMessageControl(GLenum source,
4009 GLenum type,
4010 GLenum severity,
4011 GLsizei count,
4012 const GLuint *ids,
4013 GLboolean enabled)
4014{
4015 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004016 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004017 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004018}
4019
4020void Context::debugMessageInsert(GLenum source,
4021 GLenum type,
4022 GLuint id,
4023 GLenum severity,
4024 GLsizei length,
4025 const GLchar *buf)
4026{
4027 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004028 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004029}
4030
4031void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4032{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004033 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004034}
4035
4036GLuint Context::getDebugMessageLog(GLuint count,
4037 GLsizei bufSize,
4038 GLenum *sources,
4039 GLenum *types,
4040 GLuint *ids,
4041 GLenum *severities,
4042 GLsizei *lengths,
4043 GLchar *messageLog)
4044{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004045 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4046 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004047}
4048
4049void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4050{
4051 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004052 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004053 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004054}
4055
4056void Context::popDebugGroup()
4057{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004058 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004059 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004060}
4061
Corentin Wallez336129f2017-10-17 15:55:40 -04004062void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004063{
4064 Buffer *buffer = mGLState.getTargetBuffer(target);
4065 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004066 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004067}
4068
Corentin Wallez336129f2017-10-17 15:55:40 -04004069void Context::bufferSubData(BufferBinding target,
4070 GLintptr offset,
4071 GLsizeiptr size,
4072 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004073{
4074 if (data == nullptr)
4075 {
4076 return;
4077 }
4078
4079 Buffer *buffer = mGLState.getTargetBuffer(target);
4080 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004081 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004082}
4083
Jamie Madillef300b12016-10-07 15:12:09 -04004084void Context::attachShader(GLuint program, GLuint shader)
4085{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004086 Program *programObject = mState.mShaderPrograms->getProgram(program);
4087 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004088 ASSERT(programObject && shaderObject);
4089 programObject->attachShader(shaderObject);
4090}
4091
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004092const Workarounds &Context::getWorkarounds() const
4093{
4094 return mWorkarounds;
4095}
4096
Corentin Wallez336129f2017-10-17 15:55:40 -04004097void Context::copyBufferSubData(BufferBinding readTarget,
4098 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004099 GLintptr readOffset,
4100 GLintptr writeOffset,
4101 GLsizeiptr size)
4102{
4103 // if size is zero, the copy is a successful no-op
4104 if (size == 0)
4105 {
4106 return;
4107 }
4108
4109 // TODO(jmadill): cache these.
4110 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4111 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4112
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004113 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004114}
4115
Jamie Madill01a80ee2016-11-07 12:06:18 -05004116void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4117{
4118 Program *programObject = getProgram(program);
4119 // TODO(jmadill): Re-use this from the validation if possible.
4120 ASSERT(programObject);
4121 programObject->bindAttributeLocation(index, name);
4122}
4123
Corentin Wallez336129f2017-10-17 15:55:40 -04004124void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004125{
Corentin Wallez336129f2017-10-17 15:55:40 -04004126 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4127 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004128}
4129
Corentin Wallez336129f2017-10-17 15:55:40 -04004130void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004131{
4132 bindBufferRange(target, index, buffer, 0, 0);
4133}
4134
Corentin Wallez336129f2017-10-17 15:55:40 -04004135void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004136 GLuint index,
4137 GLuint buffer,
4138 GLintptr offset,
4139 GLsizeiptr size)
4140{
Corentin Wallez336129f2017-10-17 15:55:40 -04004141 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4142 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004143}
4144
Jamie Madill01a80ee2016-11-07 12:06:18 -05004145void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4146{
4147 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4148 {
4149 bindReadFramebuffer(framebuffer);
4150 }
4151
4152 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4153 {
4154 bindDrawFramebuffer(framebuffer);
4155 }
4156}
4157
4158void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4159{
4160 ASSERT(target == GL_RENDERBUFFER);
4161 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004162 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004163 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004164}
4165
JiangYizhoubddc46b2016-12-09 09:50:51 +08004166void Context::texStorage2DMultisample(GLenum target,
4167 GLsizei samples,
4168 GLenum internalformat,
4169 GLsizei width,
4170 GLsizei height,
4171 GLboolean fixedsamplelocations)
4172{
4173 Extents size(width, height, 1);
4174 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004175 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
Geoff Lang92019432017-11-20 13:09:34 -05004176 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004177}
4178
4179void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4180{
JiangYizhou5b03f472017-01-09 10:22:53 +08004181 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4182 // the sample position should be queried by DRAW_FRAMEBUFFER.
4183 mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER);
4184 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004185
4186 switch (pname)
4187 {
4188 case GL_SAMPLE_POSITION:
4189 handleError(framebuffer->getSamplePosition(index, val));
4190 break;
4191 default:
4192 UNREACHABLE();
4193 }
4194}
4195
Jamie Madille8fb6402017-02-14 17:56:40 -05004196void Context::renderbufferStorage(GLenum target,
4197 GLenum internalformat,
4198 GLsizei width,
4199 GLsizei height)
4200{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004201 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4202 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4203
Jamie Madille8fb6402017-02-14 17:56:40 -05004204 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004205 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004206}
4207
4208void Context::renderbufferStorageMultisample(GLenum target,
4209 GLsizei samples,
4210 GLenum internalformat,
4211 GLsizei width,
4212 GLsizei height)
4213{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004214 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4215 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004216
4217 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004218 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004219 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004220}
4221
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004222void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4223{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004224 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004225 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004226}
4227
JiangYizhoue18e6392017-02-20 10:32:23 +08004228void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4229{
4230 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4231 QueryFramebufferParameteriv(framebuffer, pname, params);
4232}
4233
Jiajia Qin5451d532017-11-16 17:16:34 +08004234void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004235{
4236 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4237 SetFramebufferParameteri(framebuffer, pname, param);
4238}
4239
Jamie Madillb3f26b92017-07-19 15:07:41 -04004240Error Context::getScratchBuffer(size_t requstedSizeBytes,
4241 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004242{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004243 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4244 {
4245 return OutOfMemory() << "Failed to allocate internal buffer.";
4246 }
4247 return NoError();
4248}
4249
4250Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4251 angle::MemoryBuffer **zeroBufferOut) const
4252{
4253 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004254 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004255 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004256 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004257 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004258}
4259
Xinghua Cao10a4d432017-11-28 14:46:26 +08004260Error Context::prepareForDispatch()
4261{
4262 syncRendererState(mComputeDirtyBits, mComputeDirtyObjects);
4263
4264 if (isRobustResourceInitEnabled())
4265 {
4266 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4267 }
4268
4269 return NoError();
4270}
4271
Xinghua Cao2b396592017-03-29 15:36:04 +08004272void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4273{
4274 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4275 {
4276 return;
4277 }
4278
Xinghua Cao10a4d432017-11-28 14:46:26 +08004279 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004280 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004281}
4282
Jiajia Qin5451d532017-11-16 17:16:34 +08004283void Context::dispatchComputeIndirect(GLintptr indirect)
4284{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004285 ANGLE_CONTEXT_TRY(prepareForDispatch());
4286 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004287}
4288
JiangYizhou165361c2017-06-07 14:56:57 +08004289void Context::texStorage2D(GLenum target,
4290 GLsizei levels,
4291 GLenum internalFormat,
4292 GLsizei width,
4293 GLsizei height)
4294{
4295 Extents size(width, height, 1);
4296 Texture *texture = getTargetTexture(target);
4297 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4298}
4299
4300void Context::texStorage3D(GLenum target,
4301 GLsizei levels,
4302 GLenum internalFormat,
4303 GLsizei width,
4304 GLsizei height,
4305 GLsizei depth)
4306{
4307 Extents size(width, height, depth);
4308 Texture *texture = getTargetTexture(target);
4309 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4310}
4311
Jiajia Qin5451d532017-11-16 17:16:34 +08004312void Context::memoryBarrier(GLbitfield barriers)
4313{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004314 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004315}
4316
4317void Context::memoryBarrierByRegion(GLbitfield barriers)
4318{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004319 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004320}
4321
Jamie Madillc1d770e2017-04-13 17:31:24 -04004322GLenum Context::checkFramebufferStatus(GLenum target)
4323{
4324 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4325 ASSERT(framebuffer);
4326
4327 return framebuffer->checkStatus(this);
4328}
4329
4330void Context::compileShader(GLuint shader)
4331{
4332 Shader *shaderObject = GetValidShader(this, shader);
4333 if (!shaderObject)
4334 {
4335 return;
4336 }
4337 shaderObject->compile(this);
4338}
4339
4340void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4341{
4342 for (int i = 0; i < n; i++)
4343 {
4344 deleteBuffer(buffers[i]);
4345 }
4346}
4347
4348void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4349{
4350 for (int i = 0; i < n; i++)
4351 {
4352 if (framebuffers[i] != 0)
4353 {
4354 deleteFramebuffer(framebuffers[i]);
4355 }
4356 }
4357}
4358
4359void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4360{
4361 for (int i = 0; i < n; i++)
4362 {
4363 deleteRenderbuffer(renderbuffers[i]);
4364 }
4365}
4366
4367void Context::deleteTextures(GLsizei n, const GLuint *textures)
4368{
4369 for (int i = 0; i < n; i++)
4370 {
4371 if (textures[i] != 0)
4372 {
4373 deleteTexture(textures[i]);
4374 }
4375 }
4376}
4377
4378void Context::detachShader(GLuint program, GLuint shader)
4379{
4380 Program *programObject = getProgram(program);
4381 ASSERT(programObject);
4382
4383 Shader *shaderObject = getShader(shader);
4384 ASSERT(shaderObject);
4385
4386 programObject->detachShader(this, shaderObject);
4387}
4388
4389void Context::genBuffers(GLsizei n, GLuint *buffers)
4390{
4391 for (int i = 0; i < n; i++)
4392 {
4393 buffers[i] = createBuffer();
4394 }
4395}
4396
4397void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4398{
4399 for (int i = 0; i < n; i++)
4400 {
4401 framebuffers[i] = createFramebuffer();
4402 }
4403}
4404
4405void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4406{
4407 for (int i = 0; i < n; i++)
4408 {
4409 renderbuffers[i] = createRenderbuffer();
4410 }
4411}
4412
4413void Context::genTextures(GLsizei n, GLuint *textures)
4414{
4415 for (int i = 0; i < n; i++)
4416 {
4417 textures[i] = createTexture();
4418 }
4419}
4420
4421void Context::getActiveAttrib(GLuint program,
4422 GLuint index,
4423 GLsizei bufsize,
4424 GLsizei *length,
4425 GLint *size,
4426 GLenum *type,
4427 GLchar *name)
4428{
4429 Program *programObject = getProgram(program);
4430 ASSERT(programObject);
4431 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4432}
4433
4434void Context::getActiveUniform(GLuint program,
4435 GLuint index,
4436 GLsizei bufsize,
4437 GLsizei *length,
4438 GLint *size,
4439 GLenum *type,
4440 GLchar *name)
4441{
4442 Program *programObject = getProgram(program);
4443 ASSERT(programObject);
4444 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4445}
4446
4447void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4448{
4449 Program *programObject = getProgram(program);
4450 ASSERT(programObject);
4451 programObject->getAttachedShaders(maxcount, count, shaders);
4452}
4453
4454GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4455{
4456 Program *programObject = getProgram(program);
4457 ASSERT(programObject);
4458 return programObject->getAttributeLocation(name);
4459}
4460
4461void Context::getBooleanv(GLenum pname, GLboolean *params)
4462{
4463 GLenum nativeType;
4464 unsigned int numParams = 0;
4465 getQueryParameterInfo(pname, &nativeType, &numParams);
4466
4467 if (nativeType == GL_BOOL)
4468 {
4469 getBooleanvImpl(pname, params);
4470 }
4471 else
4472 {
4473 CastStateValues(this, nativeType, pname, numParams, params);
4474 }
4475}
4476
4477void Context::getFloatv(GLenum pname, GLfloat *params)
4478{
4479 GLenum nativeType;
4480 unsigned int numParams = 0;
4481 getQueryParameterInfo(pname, &nativeType, &numParams);
4482
4483 if (nativeType == GL_FLOAT)
4484 {
4485 getFloatvImpl(pname, params);
4486 }
4487 else
4488 {
4489 CastStateValues(this, nativeType, pname, numParams, params);
4490 }
4491}
4492
4493void Context::getIntegerv(GLenum pname, GLint *params)
4494{
4495 GLenum nativeType;
4496 unsigned int numParams = 0;
4497 getQueryParameterInfo(pname, &nativeType, &numParams);
4498
4499 if (nativeType == GL_INT)
4500 {
4501 getIntegervImpl(pname, params);
4502 }
4503 else
4504 {
4505 CastStateValues(this, nativeType, pname, numParams, params);
4506 }
4507}
4508
4509void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4510{
4511 Program *programObject = getProgram(program);
4512 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004513 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004514}
4515
Jiajia Qin5451d532017-11-16 17:16:34 +08004516void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
4517{
4518 UNIMPLEMENTED();
4519}
4520
Jamie Madillbe849e42017-05-02 15:49:00 -04004521void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004522{
4523 Program *programObject = getProgram(program);
4524 ASSERT(programObject);
4525 programObject->getInfoLog(bufsize, length, infolog);
4526}
4527
Jiajia Qin5451d532017-11-16 17:16:34 +08004528void Context::getProgramPipelineInfoLog(GLuint pipeline,
4529 GLsizei bufSize,
4530 GLsizei *length,
4531 GLchar *infoLog)
4532{
4533 UNIMPLEMENTED();
4534}
4535
Jamie Madillc1d770e2017-04-13 17:31:24 -04004536void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4537{
4538 Shader *shaderObject = getShader(shader);
4539 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004540 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004541}
4542
4543void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4544{
4545 Shader *shaderObject = getShader(shader);
4546 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004547 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004548}
4549
4550void Context::getShaderPrecisionFormat(GLenum shadertype,
4551 GLenum precisiontype,
4552 GLint *range,
4553 GLint *precision)
4554{
4555 // TODO(jmadill): Compute shaders.
4556
4557 switch (shadertype)
4558 {
4559 case GL_VERTEX_SHADER:
4560 switch (precisiontype)
4561 {
4562 case GL_LOW_FLOAT:
4563 mCaps.vertexLowpFloat.get(range, precision);
4564 break;
4565 case GL_MEDIUM_FLOAT:
4566 mCaps.vertexMediumpFloat.get(range, precision);
4567 break;
4568 case GL_HIGH_FLOAT:
4569 mCaps.vertexHighpFloat.get(range, precision);
4570 break;
4571
4572 case GL_LOW_INT:
4573 mCaps.vertexLowpInt.get(range, precision);
4574 break;
4575 case GL_MEDIUM_INT:
4576 mCaps.vertexMediumpInt.get(range, precision);
4577 break;
4578 case GL_HIGH_INT:
4579 mCaps.vertexHighpInt.get(range, precision);
4580 break;
4581
4582 default:
4583 UNREACHABLE();
4584 return;
4585 }
4586 break;
4587
4588 case GL_FRAGMENT_SHADER:
4589 switch (precisiontype)
4590 {
4591 case GL_LOW_FLOAT:
4592 mCaps.fragmentLowpFloat.get(range, precision);
4593 break;
4594 case GL_MEDIUM_FLOAT:
4595 mCaps.fragmentMediumpFloat.get(range, precision);
4596 break;
4597 case GL_HIGH_FLOAT:
4598 mCaps.fragmentHighpFloat.get(range, precision);
4599 break;
4600
4601 case GL_LOW_INT:
4602 mCaps.fragmentLowpInt.get(range, precision);
4603 break;
4604 case GL_MEDIUM_INT:
4605 mCaps.fragmentMediumpInt.get(range, precision);
4606 break;
4607 case GL_HIGH_INT:
4608 mCaps.fragmentHighpInt.get(range, precision);
4609 break;
4610
4611 default:
4612 UNREACHABLE();
4613 return;
4614 }
4615 break;
4616
4617 default:
4618 UNREACHABLE();
4619 return;
4620 }
4621}
4622
4623void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4624{
4625 Shader *shaderObject = getShader(shader);
4626 ASSERT(shaderObject);
4627 shaderObject->getSource(bufsize, length, source);
4628}
4629
4630void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4631{
4632 Program *programObject = getProgram(program);
4633 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004634 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004635}
4636
4637void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4638{
4639 Program *programObject = getProgram(program);
4640 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004641 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004642}
4643
4644GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4645{
4646 Program *programObject = getProgram(program);
4647 ASSERT(programObject);
4648 return programObject->getUniformLocation(name);
4649}
4650
4651GLboolean Context::isBuffer(GLuint buffer)
4652{
4653 if (buffer == 0)
4654 {
4655 return GL_FALSE;
4656 }
4657
4658 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4659}
4660
4661GLboolean Context::isEnabled(GLenum cap)
4662{
4663 return mGLState.getEnableFeature(cap);
4664}
4665
4666GLboolean Context::isFramebuffer(GLuint framebuffer)
4667{
4668 if (framebuffer == 0)
4669 {
4670 return GL_FALSE;
4671 }
4672
4673 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4674}
4675
4676GLboolean Context::isProgram(GLuint program)
4677{
4678 if (program == 0)
4679 {
4680 return GL_FALSE;
4681 }
4682
4683 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4684}
4685
4686GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4687{
4688 if (renderbuffer == 0)
4689 {
4690 return GL_FALSE;
4691 }
4692
4693 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4694}
4695
4696GLboolean Context::isShader(GLuint shader)
4697{
4698 if (shader == 0)
4699 {
4700 return GL_FALSE;
4701 }
4702
4703 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4704}
4705
4706GLboolean Context::isTexture(GLuint texture)
4707{
4708 if (texture == 0)
4709 {
4710 return GL_FALSE;
4711 }
4712
4713 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4714}
4715
4716void Context::linkProgram(GLuint program)
4717{
4718 Program *programObject = getProgram(program);
4719 ASSERT(programObject);
4720 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004721 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004722}
4723
4724void Context::releaseShaderCompiler()
4725{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004726 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004727}
4728
4729void Context::shaderBinary(GLsizei n,
4730 const GLuint *shaders,
4731 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004732 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004733 GLsizei length)
4734{
4735 // No binary shader formats are supported.
4736 UNIMPLEMENTED();
4737}
4738
4739void Context::shaderSource(GLuint shader,
4740 GLsizei count,
4741 const GLchar *const *string,
4742 const GLint *length)
4743{
4744 Shader *shaderObject = getShader(shader);
4745 ASSERT(shaderObject);
4746 shaderObject->setSource(count, string, length);
4747}
4748
4749void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4750{
4751 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4752}
4753
4754void Context::stencilMask(GLuint mask)
4755{
4756 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4757}
4758
4759void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4760{
4761 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4762}
4763
4764void Context::uniform1f(GLint location, GLfloat x)
4765{
4766 Program *program = mGLState.getProgram();
4767 program->setUniform1fv(location, 1, &x);
4768}
4769
4770void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4771{
4772 Program *program = mGLState.getProgram();
4773 program->setUniform1fv(location, count, v);
4774}
4775
4776void Context::uniform1i(GLint location, GLint x)
4777{
4778 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004779 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4780 {
4781 mGLState.setObjectDirty(GL_PROGRAM);
4782 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004783}
4784
4785void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4786{
4787 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004788 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4789 {
4790 mGLState.setObjectDirty(GL_PROGRAM);
4791 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004792}
4793
4794void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4795{
4796 GLfloat xy[2] = {x, y};
4797 Program *program = mGLState.getProgram();
4798 program->setUniform2fv(location, 1, xy);
4799}
4800
4801void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4802{
4803 Program *program = mGLState.getProgram();
4804 program->setUniform2fv(location, count, v);
4805}
4806
4807void Context::uniform2i(GLint location, GLint x, GLint y)
4808{
4809 GLint xy[2] = {x, y};
4810 Program *program = mGLState.getProgram();
4811 program->setUniform2iv(location, 1, xy);
4812}
4813
4814void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4815{
4816 Program *program = mGLState.getProgram();
4817 program->setUniform2iv(location, count, v);
4818}
4819
4820void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4821{
4822 GLfloat xyz[3] = {x, y, z};
4823 Program *program = mGLState.getProgram();
4824 program->setUniform3fv(location, 1, xyz);
4825}
4826
4827void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4828{
4829 Program *program = mGLState.getProgram();
4830 program->setUniform3fv(location, count, v);
4831}
4832
4833void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4834{
4835 GLint xyz[3] = {x, y, z};
4836 Program *program = mGLState.getProgram();
4837 program->setUniform3iv(location, 1, xyz);
4838}
4839
4840void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4841{
4842 Program *program = mGLState.getProgram();
4843 program->setUniform3iv(location, count, v);
4844}
4845
4846void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4847{
4848 GLfloat xyzw[4] = {x, y, z, w};
4849 Program *program = mGLState.getProgram();
4850 program->setUniform4fv(location, 1, xyzw);
4851}
4852
4853void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4854{
4855 Program *program = mGLState.getProgram();
4856 program->setUniform4fv(location, count, v);
4857}
4858
4859void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4860{
4861 GLint xyzw[4] = {x, y, z, w};
4862 Program *program = mGLState.getProgram();
4863 program->setUniform4iv(location, 1, xyzw);
4864}
4865
4866void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4867{
4868 Program *program = mGLState.getProgram();
4869 program->setUniform4iv(location, count, v);
4870}
4871
4872void Context::uniformMatrix2fv(GLint location,
4873 GLsizei count,
4874 GLboolean transpose,
4875 const GLfloat *value)
4876{
4877 Program *program = mGLState.getProgram();
4878 program->setUniformMatrix2fv(location, count, transpose, value);
4879}
4880
4881void Context::uniformMatrix3fv(GLint location,
4882 GLsizei count,
4883 GLboolean transpose,
4884 const GLfloat *value)
4885{
4886 Program *program = mGLState.getProgram();
4887 program->setUniformMatrix3fv(location, count, transpose, value);
4888}
4889
4890void Context::uniformMatrix4fv(GLint location,
4891 GLsizei count,
4892 GLboolean transpose,
4893 const GLfloat *value)
4894{
4895 Program *program = mGLState.getProgram();
4896 program->setUniformMatrix4fv(location, count, transpose, value);
4897}
4898
4899void Context::validateProgram(GLuint program)
4900{
4901 Program *programObject = getProgram(program);
4902 ASSERT(programObject);
4903 programObject->validate(mCaps);
4904}
4905
Jiajia Qin5451d532017-11-16 17:16:34 +08004906void Context::validateProgramPipeline(GLuint pipeline)
4907{
4908 UNIMPLEMENTED();
4909}
4910
Jamie Madilld04908b2017-06-09 14:15:35 -04004911void Context::getProgramBinary(GLuint program,
4912 GLsizei bufSize,
4913 GLsizei *length,
4914 GLenum *binaryFormat,
4915 void *binary)
4916{
4917 Program *programObject = getProgram(program);
4918 ASSERT(programObject != nullptr);
4919
4920 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4921}
4922
4923void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4924{
4925 Program *programObject = getProgram(program);
4926 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04004927
Jamie Madilld04908b2017-06-09 14:15:35 -04004928 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
4929}
4930
Jamie Madillff325f12017-08-26 15:06:05 -04004931void Context::uniform1ui(GLint location, GLuint v0)
4932{
4933 Program *program = mGLState.getProgram();
4934 program->setUniform1uiv(location, 1, &v0);
4935}
4936
4937void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
4938{
4939 Program *program = mGLState.getProgram();
4940 const GLuint xy[] = {v0, v1};
4941 program->setUniform2uiv(location, 1, xy);
4942}
4943
4944void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
4945{
4946 Program *program = mGLState.getProgram();
4947 const GLuint xyz[] = {v0, v1, v2};
4948 program->setUniform3uiv(location, 1, xyz);
4949}
4950
4951void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
4952{
4953 Program *program = mGLState.getProgram();
4954 const GLuint xyzw[] = {v0, v1, v2, v3};
4955 program->setUniform4uiv(location, 1, xyzw);
4956}
4957
4958void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
4959{
4960 Program *program = mGLState.getProgram();
4961 program->setUniform1uiv(location, count, value);
4962}
4963void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
4964{
4965 Program *program = mGLState.getProgram();
4966 program->setUniform2uiv(location, count, value);
4967}
4968
4969void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
4970{
4971 Program *program = mGLState.getProgram();
4972 program->setUniform3uiv(location, count, value);
4973}
4974
4975void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
4976{
4977 Program *program = mGLState.getProgram();
4978 program->setUniform4uiv(location, count, value);
4979}
4980
Jamie Madillf0e04492017-08-26 15:28:42 -04004981void Context::genQueries(GLsizei n, GLuint *ids)
4982{
4983 for (GLsizei i = 0; i < n; i++)
4984 {
4985 GLuint handle = mQueryHandleAllocator.allocate();
4986 mQueryMap.assign(handle, nullptr);
4987 ids[i] = handle;
4988 }
4989}
4990
4991void Context::deleteQueries(GLsizei n, const GLuint *ids)
4992{
4993 for (int i = 0; i < n; i++)
4994 {
4995 GLuint query = ids[i];
4996
4997 Query *queryObject = nullptr;
4998 if (mQueryMap.erase(query, &queryObject))
4999 {
5000 mQueryHandleAllocator.release(query);
5001 if (queryObject)
5002 {
5003 queryObject->release(this);
5004 }
5005 }
5006 }
5007}
5008
5009GLboolean Context::isQuery(GLuint id)
5010{
5011 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
5012}
5013
Jamie Madillc8c95812017-08-26 18:40:09 -04005014void Context::uniformMatrix2x3fv(GLint location,
5015 GLsizei count,
5016 GLboolean transpose,
5017 const GLfloat *value)
5018{
5019 Program *program = mGLState.getProgram();
5020 program->setUniformMatrix2x3fv(location, count, transpose, value);
5021}
5022
5023void Context::uniformMatrix3x2fv(GLint location,
5024 GLsizei count,
5025 GLboolean transpose,
5026 const GLfloat *value)
5027{
5028 Program *program = mGLState.getProgram();
5029 program->setUniformMatrix3x2fv(location, count, transpose, value);
5030}
5031
5032void Context::uniformMatrix2x4fv(GLint location,
5033 GLsizei count,
5034 GLboolean transpose,
5035 const GLfloat *value)
5036{
5037 Program *program = mGLState.getProgram();
5038 program->setUniformMatrix2x4fv(location, count, transpose, value);
5039}
5040
5041void Context::uniformMatrix4x2fv(GLint location,
5042 GLsizei count,
5043 GLboolean transpose,
5044 const GLfloat *value)
5045{
5046 Program *program = mGLState.getProgram();
5047 program->setUniformMatrix4x2fv(location, count, transpose, value);
5048}
5049
5050void Context::uniformMatrix3x4fv(GLint location,
5051 GLsizei count,
5052 GLboolean transpose,
5053 const GLfloat *value)
5054{
5055 Program *program = mGLState.getProgram();
5056 program->setUniformMatrix3x4fv(location, count, transpose, value);
5057}
5058
5059void Context::uniformMatrix4x3fv(GLint location,
5060 GLsizei count,
5061 GLboolean transpose,
5062 const GLfloat *value)
5063{
5064 Program *program = mGLState.getProgram();
5065 program->setUniformMatrix4x3fv(location, count, transpose, value);
5066}
5067
Jamie Madilld7576732017-08-26 18:49:50 -04005068void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5069{
5070 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5071 {
5072 GLuint vertexArray = arrays[arrayIndex];
5073
5074 if (arrays[arrayIndex] != 0)
5075 {
5076 VertexArray *vertexArrayObject = nullptr;
5077 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5078 {
5079 if (vertexArrayObject != nullptr)
5080 {
5081 detachVertexArray(vertexArray);
5082 vertexArrayObject->onDestroy(this);
5083 }
5084
5085 mVertexArrayHandleAllocator.release(vertexArray);
5086 }
5087 }
5088 }
5089}
5090
5091void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5092{
5093 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5094 {
5095 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5096 mVertexArrayMap.assign(vertexArray, nullptr);
5097 arrays[arrayIndex] = vertexArray;
5098 }
5099}
5100
5101bool Context::isVertexArray(GLuint array)
5102{
5103 if (array == 0)
5104 {
5105 return GL_FALSE;
5106 }
5107
5108 VertexArray *vao = getVertexArray(array);
5109 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5110}
5111
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005112void Context::endTransformFeedback()
5113{
5114 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5115 transformFeedback->end(this);
5116}
5117
5118void Context::transformFeedbackVaryings(GLuint program,
5119 GLsizei count,
5120 const GLchar *const *varyings,
5121 GLenum bufferMode)
5122{
5123 Program *programObject = getProgram(program);
5124 ASSERT(programObject);
5125 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5126}
5127
5128void Context::getTransformFeedbackVarying(GLuint program,
5129 GLuint index,
5130 GLsizei bufSize,
5131 GLsizei *length,
5132 GLsizei *size,
5133 GLenum *type,
5134 GLchar *name)
5135{
5136 Program *programObject = getProgram(program);
5137 ASSERT(programObject);
5138 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5139}
5140
5141void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5142{
5143 for (int i = 0; i < n; i++)
5144 {
5145 GLuint transformFeedback = ids[i];
5146 if (transformFeedback == 0)
5147 {
5148 continue;
5149 }
5150
5151 TransformFeedback *transformFeedbackObject = nullptr;
5152 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5153 {
5154 if (transformFeedbackObject != nullptr)
5155 {
5156 detachTransformFeedback(transformFeedback);
5157 transformFeedbackObject->release(this);
5158 }
5159
5160 mTransformFeedbackHandleAllocator.release(transformFeedback);
5161 }
5162 }
5163}
5164
5165void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5166{
5167 for (int i = 0; i < n; i++)
5168 {
5169 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5170 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5171 ids[i] = transformFeedback;
5172 }
5173}
5174
5175bool Context::isTransformFeedback(GLuint id)
5176{
5177 if (id == 0)
5178 {
5179 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5180 // returns FALSE
5181 return GL_FALSE;
5182 }
5183
5184 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5185 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5186}
5187
5188void Context::pauseTransformFeedback()
5189{
5190 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5191 transformFeedback->pause();
5192}
5193
5194void Context::resumeTransformFeedback()
5195{
5196 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5197 transformFeedback->resume();
5198}
5199
Jamie Madill12e957f2017-08-26 21:42:26 -04005200void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5201{
5202 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005203 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005204}
5205
5206GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5207{
5208 const Program *programObject = getProgram(program);
5209 return programObject->getFragDataLocation(name);
5210}
5211
5212void Context::getUniformIndices(GLuint program,
5213 GLsizei uniformCount,
5214 const GLchar *const *uniformNames,
5215 GLuint *uniformIndices)
5216{
5217 const Program *programObject = getProgram(program);
5218 if (!programObject->isLinked())
5219 {
5220 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5221 {
5222 uniformIndices[uniformId] = GL_INVALID_INDEX;
5223 }
5224 }
5225 else
5226 {
5227 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5228 {
5229 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5230 }
5231 }
5232}
5233
5234void Context::getActiveUniformsiv(GLuint program,
5235 GLsizei uniformCount,
5236 const GLuint *uniformIndices,
5237 GLenum pname,
5238 GLint *params)
5239{
5240 const Program *programObject = getProgram(program);
5241 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5242 {
5243 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005244 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005245 }
5246}
5247
5248GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5249{
5250 const Program *programObject = getProgram(program);
5251 return programObject->getUniformBlockIndex(uniformBlockName);
5252}
5253
5254void Context::getActiveUniformBlockiv(GLuint program,
5255 GLuint uniformBlockIndex,
5256 GLenum pname,
5257 GLint *params)
5258{
5259 const Program *programObject = getProgram(program);
5260 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5261}
5262
5263void Context::getActiveUniformBlockName(GLuint program,
5264 GLuint uniformBlockIndex,
5265 GLsizei bufSize,
5266 GLsizei *length,
5267 GLchar *uniformBlockName)
5268{
5269 const Program *programObject = getProgram(program);
5270 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5271}
5272
5273void Context::uniformBlockBinding(GLuint program,
5274 GLuint uniformBlockIndex,
5275 GLuint uniformBlockBinding)
5276{
5277 Program *programObject = getProgram(program);
5278 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5279}
5280
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005281GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5282{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005283 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5284 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005285
Jamie Madill70b5bb02017-08-28 13:32:37 -04005286 Sync *syncObject = getSync(syncHandle);
5287 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005288 if (error.isError())
5289 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005290 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005291 handleError(error);
5292 return nullptr;
5293 }
5294
Jamie Madill70b5bb02017-08-28 13:32:37 -04005295 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005296}
5297
5298GLboolean Context::isSync(GLsync sync)
5299{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005300 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005301}
5302
5303GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5304{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005305 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005306
5307 GLenum result = GL_WAIT_FAILED;
5308 handleError(syncObject->clientWait(flags, timeout, &result));
5309 return result;
5310}
5311
5312void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5313{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005314 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005315 handleError(syncObject->serverWait(flags, timeout));
5316}
5317
5318void Context::getInteger64v(GLenum pname, GLint64 *params)
5319{
5320 GLenum nativeType = GL_NONE;
5321 unsigned int numParams = 0;
5322 getQueryParameterInfo(pname, &nativeType, &numParams);
5323
5324 if (nativeType == GL_INT_64_ANGLEX)
5325 {
5326 getInteger64vImpl(pname, params);
5327 }
5328 else
5329 {
5330 CastStateValues(this, nativeType, pname, numParams, params);
5331 }
5332}
5333
Corentin Wallez336129f2017-10-17 15:55:40 -04005334void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04005335{
5336 Buffer *buffer = mGLState.getTargetBuffer(target);
5337 QueryBufferParameteri64v(buffer, pname, params);
5338}
5339
5340void Context::genSamplers(GLsizei count, GLuint *samplers)
5341{
5342 for (int i = 0; i < count; i++)
5343 {
5344 samplers[i] = mState.mSamplers->createSampler();
5345 }
5346}
5347
5348void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5349{
5350 for (int i = 0; i < count; i++)
5351 {
5352 GLuint sampler = samplers[i];
5353
5354 if (mState.mSamplers->getSampler(sampler))
5355 {
5356 detachSampler(sampler);
5357 }
5358
5359 mState.mSamplers->deleteObject(this, sampler);
5360 }
5361}
5362
5363void Context::getInternalformativ(GLenum target,
5364 GLenum internalformat,
5365 GLenum pname,
5366 GLsizei bufSize,
5367 GLint *params)
5368{
5369 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5370 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5371}
5372
Jiajia Qin5451d532017-11-16 17:16:34 +08005373void Context::programUniform1i(GLuint program, GLint location, GLint v0)
5374{
5375 programUniform1iv(program, location, 1, &v0);
5376}
5377
5378void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
5379{
5380 GLint xy[2] = {v0, v1};
5381 programUniform2iv(program, location, 1, xy);
5382}
5383
5384void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
5385{
5386 GLint xyz[3] = {v0, v1, v2};
5387 programUniform3iv(program, location, 1, xyz);
5388}
5389
5390void Context::programUniform4i(GLuint program,
5391 GLint location,
5392 GLint v0,
5393 GLint v1,
5394 GLint v2,
5395 GLint v3)
5396{
5397 GLint xyzw[4] = {v0, v1, v2, v3};
5398 programUniform4iv(program, location, 1, xyzw);
5399}
5400
5401void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
5402{
5403 programUniform1uiv(program, location, 1, &v0);
5404}
5405
5406void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
5407{
5408 GLuint xy[2] = {v0, v1};
5409 programUniform2uiv(program, location, 1, xy);
5410}
5411
5412void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
5413{
5414 GLuint xyz[3] = {v0, v1, v2};
5415 programUniform3uiv(program, location, 1, xyz);
5416}
5417
5418void Context::programUniform4ui(GLuint program,
5419 GLint location,
5420 GLuint v0,
5421 GLuint v1,
5422 GLuint v2,
5423 GLuint v3)
5424{
5425 GLuint xyzw[4] = {v0, v1, v2, v3};
5426 programUniform4uiv(program, location, 1, xyzw);
5427}
5428
5429void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
5430{
5431 programUniform1fv(program, location, 1, &v0);
5432}
5433
5434void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
5435{
5436 GLfloat xy[2] = {v0, v1};
5437 programUniform2fv(program, location, 1, xy);
5438}
5439
5440void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
5441{
5442 GLfloat xyz[3] = {v0, v1, v2};
5443 programUniform3fv(program, location, 1, xyz);
5444}
5445
5446void Context::programUniform4f(GLuint program,
5447 GLint location,
5448 GLfloat v0,
5449 GLfloat v1,
5450 GLfloat v2,
5451 GLfloat v3)
5452{
5453 GLfloat xyzw[4] = {v0, v1, v2, v3};
5454 programUniform4fv(program, location, 1, xyzw);
5455}
5456
Jamie Madill81c2e252017-09-09 23:32:46 -04005457void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5458{
5459 Program *programObject = getProgram(program);
5460 ASSERT(programObject);
5461 if (programObject->setUniform1iv(location, count, value) ==
5462 Program::SetUniformResult::SamplerChanged)
5463 {
5464 mGLState.setObjectDirty(GL_PROGRAM);
5465 }
5466}
5467
Jiajia Qin5451d532017-11-16 17:16:34 +08005468void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5469{
5470 Program *programObject = getProgram(program);
5471 ASSERT(programObject);
5472 programObject->setUniform2iv(location, count, value);
5473}
5474
5475void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5476{
5477 Program *programObject = getProgram(program);
5478 ASSERT(programObject);
5479 programObject->setUniform3iv(location, count, value);
5480}
5481
5482void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5483{
5484 Program *programObject = getProgram(program);
5485 ASSERT(programObject);
5486 programObject->setUniform4iv(location, count, value);
5487}
5488
5489void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5490{
5491 Program *programObject = getProgram(program);
5492 ASSERT(programObject);
5493 programObject->setUniform1uiv(location, count, value);
5494}
5495
5496void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5497{
5498 Program *programObject = getProgram(program);
5499 ASSERT(programObject);
5500 programObject->setUniform2uiv(location, count, value);
5501}
5502
5503void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5504{
5505 Program *programObject = getProgram(program);
5506 ASSERT(programObject);
5507 programObject->setUniform3uiv(location, count, value);
5508}
5509
5510void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5511{
5512 Program *programObject = getProgram(program);
5513 ASSERT(programObject);
5514 programObject->setUniform4uiv(location, count, value);
5515}
5516
5517void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5518{
5519 Program *programObject = getProgram(program);
5520 ASSERT(programObject);
5521 programObject->setUniform1fv(location, count, value);
5522}
5523
5524void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5525{
5526 Program *programObject = getProgram(program);
5527 ASSERT(programObject);
5528 programObject->setUniform2fv(location, count, value);
5529}
5530
5531void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5532{
5533 Program *programObject = getProgram(program);
5534 ASSERT(programObject);
5535 programObject->setUniform3fv(location, count, value);
5536}
5537
5538void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5539{
5540 Program *programObject = getProgram(program);
5541 ASSERT(programObject);
5542 programObject->setUniform4fv(location, count, value);
5543}
5544
5545void Context::programUniformMatrix2fv(GLuint program,
5546 GLint location,
5547 GLsizei count,
5548 GLboolean transpose,
5549 const GLfloat *value)
5550{
5551 Program *programObject = getProgram(program);
5552 ASSERT(programObject);
5553 programObject->setUniformMatrix2fv(location, count, transpose, value);
5554}
5555
5556void Context::programUniformMatrix3fv(GLuint program,
5557 GLint location,
5558 GLsizei count,
5559 GLboolean transpose,
5560 const GLfloat *value)
5561{
5562 Program *programObject = getProgram(program);
5563 ASSERT(programObject);
5564 programObject->setUniformMatrix3fv(location, count, transpose, value);
5565}
5566
5567void Context::programUniformMatrix4fv(GLuint program,
5568 GLint location,
5569 GLsizei count,
5570 GLboolean transpose,
5571 const GLfloat *value)
5572{
5573 Program *programObject = getProgram(program);
5574 ASSERT(programObject);
5575 programObject->setUniformMatrix4fv(location, count, transpose, value);
5576}
5577
5578void Context::programUniformMatrix2x3fv(GLuint program,
5579 GLint location,
5580 GLsizei count,
5581 GLboolean transpose,
5582 const GLfloat *value)
5583{
5584 Program *programObject = getProgram(program);
5585 ASSERT(programObject);
5586 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
5587}
5588
5589void Context::programUniformMatrix3x2fv(GLuint program,
5590 GLint location,
5591 GLsizei count,
5592 GLboolean transpose,
5593 const GLfloat *value)
5594{
5595 Program *programObject = getProgram(program);
5596 ASSERT(programObject);
5597 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
5598}
5599
5600void Context::programUniformMatrix2x4fv(GLuint program,
5601 GLint location,
5602 GLsizei count,
5603 GLboolean transpose,
5604 const GLfloat *value)
5605{
5606 Program *programObject = getProgram(program);
5607 ASSERT(programObject);
5608 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
5609}
5610
5611void Context::programUniformMatrix4x2fv(GLuint program,
5612 GLint location,
5613 GLsizei count,
5614 GLboolean transpose,
5615 const GLfloat *value)
5616{
5617 Program *programObject = getProgram(program);
5618 ASSERT(programObject);
5619 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
5620}
5621
5622void Context::programUniformMatrix3x4fv(GLuint program,
5623 GLint location,
5624 GLsizei count,
5625 GLboolean transpose,
5626 const GLfloat *value)
5627{
5628 Program *programObject = getProgram(program);
5629 ASSERT(programObject);
5630 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
5631}
5632
5633void Context::programUniformMatrix4x3fv(GLuint program,
5634 GLint location,
5635 GLsizei count,
5636 GLboolean transpose,
5637 const GLfloat *value)
5638{
5639 Program *programObject = getProgram(program);
5640 ASSERT(programObject);
5641 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
5642}
5643
Jamie Madill81c2e252017-09-09 23:32:46 -04005644void Context::onTextureChange(const Texture *texture)
5645{
5646 // Conservatively assume all textures are dirty.
5647 // TODO(jmadill): More fine-grained update.
5648 mGLState.setObjectDirty(GL_TEXTURE);
5649}
5650
Yunchao Hea336b902017-08-02 16:05:21 +08005651void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5652{
5653 for (int i = 0; i < count; i++)
5654 {
5655 pipelines[i] = createProgramPipeline();
5656 }
5657}
5658
5659void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5660{
5661 for (int i = 0; i < count; i++)
5662 {
5663 if (pipelines[i] != 0)
5664 {
5665 deleteProgramPipeline(pipelines[i]);
5666 }
5667 }
5668}
5669
5670GLboolean Context::isProgramPipeline(GLuint pipeline)
5671{
5672 if (pipeline == 0)
5673 {
5674 return GL_FALSE;
5675 }
5676
5677 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5678}
5679
Jamie Madill2b7bbc22017-12-21 17:30:38 -05005680void Context::finishFenceNV(GLuint fence)
5681{
5682 FenceNV *fenceObject = getFenceNV(fence);
5683
5684 ASSERT(fenceObject && fenceObject->isSet());
5685 handleError(fenceObject->finish());
5686}
5687
5688void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
5689{
5690 FenceNV *fenceObject = getFenceNV(fence);
5691
5692 ASSERT(fenceObject && fenceObject->isSet());
5693
5694 switch (pname)
5695 {
5696 case GL_FENCE_STATUS_NV:
5697 {
5698 // GL_NV_fence spec:
5699 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
5700 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
5701 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
5702 GLboolean status = GL_TRUE;
5703 if (fenceObject->getStatus() != GL_TRUE)
5704 {
5705 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
5706 }
5707 *params = status;
5708 break;
5709 }
5710
5711 case GL_FENCE_CONDITION_NV:
5712 {
5713 *params = static_cast<GLint>(fenceObject->getCondition());
5714 break;
5715 }
5716
5717 default:
5718 UNREACHABLE();
5719 }
5720}
5721
5722void Context::getTranslatedShaderSource(GLuint shader,
5723 GLsizei bufsize,
5724 GLsizei *length,
5725 GLchar *source)
5726{
5727 Shader *shaderObject = getShader(shader);
5728 ASSERT(shaderObject);
5729 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
5730}
5731
5732void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
5733{
5734 Program *programObject = getProgram(program);
5735 ASSERT(programObject);
5736
5737 programObject->getUniformfv(this, location, params);
5738}
5739
5740void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
5741{
5742 Program *programObject = getProgram(program);
5743 ASSERT(programObject);
5744
5745 programObject->getUniformiv(this, location, params);
5746}
5747
5748GLboolean Context::isFenceNV(GLuint fence)
5749{
5750 FenceNV *fenceObject = getFenceNV(fence);
5751
5752 if (fenceObject == nullptr)
5753 {
5754 return GL_FALSE;
5755 }
5756
5757 // GL_NV_fence spec:
5758 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
5759 // existing fence.
5760 return fenceObject->isSet();
5761}
5762
5763void Context::readnPixels(GLint x,
5764 GLint y,
5765 GLsizei width,
5766 GLsizei height,
5767 GLenum format,
5768 GLenum type,
5769 GLsizei bufSize,
5770 void *data)
5771{
5772 return readPixels(x, y, width, height, format, type, data);
5773}
5774
Jamie Madill007530e2017-12-28 14:27:04 -05005775void Context::setFenceNV(GLuint fence, GLenum condition)
5776{
5777 ASSERT(condition == GL_ALL_COMPLETED_NV);
5778
5779 FenceNV *fenceObject = getFenceNV(fence);
5780 ASSERT(fenceObject != nullptr);
5781 handleError(fenceObject->set(condition));
5782}
5783
5784GLboolean Context::testFenceNV(GLuint fence)
5785{
5786 FenceNV *fenceObject = getFenceNV(fence);
5787
5788 ASSERT(fenceObject != nullptr);
5789 ASSERT(fenceObject->isSet() == GL_TRUE);
5790
5791 GLboolean result = GL_TRUE;
5792 Error error = fenceObject->test(&result);
5793 if (error.isError())
5794 {
5795 handleError(error);
5796 return GL_TRUE;
5797 }
5798
5799 return result;
5800}
5801
Jamie Madillfa920eb2018-01-04 11:45:50 -05005802void Context::eGLImageTargetTexture2D(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005803{
5804 Texture *texture = getTargetTexture(target);
5805 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
5806 handleError(texture->setEGLImageTarget(this, target, imageObject));
5807}
5808
Jamie Madillfa920eb2018-01-04 11:45:50 -05005809void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005810{
5811 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
5812 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
5813 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
5814}
5815
Jamie Madillfa920eb2018-01-04 11:45:50 -05005816void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
5817{
5818 UNIMPLEMENTED();
5819}
5820
Geoff Lang2aaa7b42018-01-12 17:17:27 -05005821void Context::alphaFunc(GLenum func, GLfloat ref)
5822{
5823 UNIMPLEMENTED();
5824}
5825
5826void Context::alphaFuncx(GLenum func, GLfixed ref)
5827{
5828 UNIMPLEMENTED();
5829}
5830
5831void Context::clearColorx(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5832{
5833 UNIMPLEMENTED();
5834}
5835
5836void Context::clearDepthx(GLfixed depth)
5837{
5838 UNIMPLEMENTED();
5839}
5840
5841void Context::clientActiveTexture(GLenum texture)
5842{
5843 UNIMPLEMENTED();
5844}
5845
5846void Context::clipPlanef(GLenum p, const GLfloat *eqn)
5847{
5848 UNIMPLEMENTED();
5849}
5850
5851void Context::clipPlanex(GLenum plane, const GLfixed *equation)
5852{
5853 UNIMPLEMENTED();
5854}
5855
5856void Context::color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
5857{
5858 UNIMPLEMENTED();
5859}
5860
5861void Context::color4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
5862{
5863 UNIMPLEMENTED();
5864}
5865
5866void Context::color4x(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5867{
5868 UNIMPLEMENTED();
5869}
5870
5871void Context::colorPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
5872{
5873 UNIMPLEMENTED();
5874}
5875
5876void Context::cullFace(GLenum mode)
5877{
5878 UNIMPLEMENTED();
5879}
5880
5881void Context::depthRangex(GLfixed n, GLfixed f)
5882{
5883 UNIMPLEMENTED();
5884}
5885
5886void Context::disableClientState(GLenum array)
5887{
5888 UNIMPLEMENTED();
5889}
5890
5891void Context::enableClientState(GLenum array)
5892{
5893 UNIMPLEMENTED();
5894}
5895
5896void Context::fogf(GLenum pname, GLfloat param)
5897{
5898 UNIMPLEMENTED();
5899}
5900
5901void Context::fogfv(GLenum pname, const GLfloat *params)
5902{
5903 UNIMPLEMENTED();
5904}
5905
5906void Context::fogx(GLenum pname, GLfixed param)
5907{
5908 UNIMPLEMENTED();
5909}
5910
5911void Context::fogxv(GLenum pname, const GLfixed *param)
5912{
5913 UNIMPLEMENTED();
5914}
5915
5916void Context::frustumf(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
5917{
5918 UNIMPLEMENTED();
5919}
5920
5921void Context::frustumx(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
5922{
5923 UNIMPLEMENTED();
5924}
5925
5926void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
5927{
5928 UNIMPLEMENTED();
5929}
5930
5931void Context::getClipPlanef(GLenum plane, GLfloat *equation)
5932{
5933 UNIMPLEMENTED();
5934}
5935
5936void Context::getClipPlanex(GLenum plane, GLfixed *equation)
5937{
5938 UNIMPLEMENTED();
5939}
5940
5941void Context::getFixedv(GLenum pname, GLfixed *params)
5942{
5943 UNIMPLEMENTED();
5944}
5945
5946void Context::getLightfv(GLenum light, GLenum pname, GLfloat *params)
5947{
5948 UNIMPLEMENTED();
5949}
5950
5951void Context::getLightxv(GLenum light, GLenum pname, GLfixed *params)
5952{
5953 UNIMPLEMENTED();
5954}
5955
5956void Context::getMaterialfv(GLenum face, GLenum pname, GLfloat *params)
5957{
5958 UNIMPLEMENTED();
5959}
5960
5961void Context::getMaterialxv(GLenum face, GLenum pname, GLfixed *params)
5962{
5963 UNIMPLEMENTED();
5964}
5965
5966void Context::getTexEnvfv(GLenum target, GLenum pname, GLfloat *params)
5967{
5968 UNIMPLEMENTED();
5969}
5970
5971void Context::getTexEnviv(GLenum target, GLenum pname, GLint *params)
5972{
5973 UNIMPLEMENTED();
5974}
5975
5976void Context::getTexEnvxv(GLenum target, GLenum pname, GLfixed *params)
5977{
5978 UNIMPLEMENTED();
5979}
5980
5981void Context::getTexParameterxv(GLenum target, GLenum pname, GLfixed *params)
5982{
5983 UNIMPLEMENTED();
5984}
5985
5986void Context::lightModelf(GLenum pname, GLfloat param)
5987{
5988 UNIMPLEMENTED();
5989}
5990
5991void Context::lightModelfv(GLenum pname, const GLfloat *params)
5992{
5993 UNIMPLEMENTED();
5994}
5995
5996void Context::lightModelx(GLenum pname, GLfixed param)
5997{
5998 UNIMPLEMENTED();
5999}
6000
6001void Context::lightModelxv(GLenum pname, const GLfixed *param)
6002{
6003 UNIMPLEMENTED();
6004}
6005
6006void Context::lightf(GLenum light, GLenum pname, GLfloat param)
6007{
6008 UNIMPLEMENTED();
6009}
6010
6011void Context::lightfv(GLenum light, GLenum pname, const GLfloat *params)
6012{
6013 UNIMPLEMENTED();
6014}
6015
6016void Context::lightx(GLenum light, GLenum pname, GLfixed param)
6017{
6018 UNIMPLEMENTED();
6019}
6020
6021void Context::lightxv(GLenum light, GLenum pname, const GLfixed *params)
6022{
6023 UNIMPLEMENTED();
6024}
6025
6026void Context::lineWidthx(GLfixed width)
6027{
6028 UNIMPLEMENTED();
6029}
6030
6031void Context::loadIdentity()
6032{
6033 UNIMPLEMENTED();
6034}
6035
6036void Context::loadMatrixf(const GLfloat *m)
6037{
6038 UNIMPLEMENTED();
6039}
6040
6041void Context::loadMatrixx(const GLfixed *m)
6042{
6043 UNIMPLEMENTED();
6044}
6045
6046void Context::logicOp(GLenum opcode)
6047{
6048 UNIMPLEMENTED();
6049}
6050
6051void Context::materialf(GLenum face, GLenum pname, GLfloat param)
6052{
6053 UNIMPLEMENTED();
6054}
6055
6056void Context::materialfv(GLenum face, GLenum pname, const GLfloat *params)
6057{
6058 UNIMPLEMENTED();
6059}
6060
6061void Context::materialx(GLenum face, GLenum pname, GLfixed param)
6062{
6063 UNIMPLEMENTED();
6064}
6065
6066void Context::materialxv(GLenum face, GLenum pname, const GLfixed *param)
6067{
6068 UNIMPLEMENTED();
6069}
6070
6071void Context::matrixMode(GLenum mode)
6072{
6073 UNIMPLEMENTED();
6074}
6075
6076void Context::multMatrixf(const GLfloat *m)
6077{
6078 UNIMPLEMENTED();
6079}
6080
6081void Context::multMatrixx(const GLfixed *m)
6082{
6083 UNIMPLEMENTED();
6084}
6085
6086void Context::multiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q)
6087{
6088 UNIMPLEMENTED();
6089}
6090
6091void Context::multiTexCoord4x(GLenum texture, GLfixed s, GLfixed t, GLfixed r, GLfixed q)
6092{
6093 UNIMPLEMENTED();
6094}
6095
6096void Context::normal3f(GLfloat nx, GLfloat ny, GLfloat nz)
6097{
6098 UNIMPLEMENTED();
6099}
6100
6101void Context::normal3x(GLfixed nx, GLfixed ny, GLfixed nz)
6102{
6103 UNIMPLEMENTED();
6104}
6105
6106void Context::normalPointer(GLenum type, GLsizei stride, const void *pointer)
6107{
6108 UNIMPLEMENTED();
6109}
6110
6111void Context::orthof(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
6112{
6113 UNIMPLEMENTED();
6114}
6115
6116void Context::orthox(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
6117{
6118 UNIMPLEMENTED();
6119}
6120
6121void Context::pointParameterf(GLenum pname, GLfloat param)
6122{
6123 UNIMPLEMENTED();
6124}
6125
6126void Context::pointParameterfv(GLenum pname, const GLfloat *params)
6127{
6128 UNIMPLEMENTED();
6129}
6130
6131void Context::pointParameterx(GLenum pname, GLfixed param)
6132{
6133 UNIMPLEMENTED();
6134}
6135
6136void Context::pointParameterxv(GLenum pname, const GLfixed *params)
6137{
6138 UNIMPLEMENTED();
6139}
6140
6141void Context::pointSize(GLfloat size)
6142{
6143 UNIMPLEMENTED();
6144}
6145
6146void Context::pointSizex(GLfixed size)
6147{
6148 UNIMPLEMENTED();
6149}
6150
6151void Context::polygonOffsetx(GLfixed factor, GLfixed units)
6152{
6153 UNIMPLEMENTED();
6154}
6155
6156void Context::popMatrix()
6157{
6158 UNIMPLEMENTED();
6159}
6160
6161void Context::pushMatrix()
6162{
6163 UNIMPLEMENTED();
6164}
6165
6166void Context::rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
6167{
6168 UNIMPLEMENTED();
6169}
6170
6171void Context::rotatex(GLfixed angle, GLfixed x, GLfixed y, GLfixed z)
6172{
6173 UNIMPLEMENTED();
6174}
6175
6176void Context::sampleCoveragex(GLclampx value, GLboolean invert)
6177{
6178 UNIMPLEMENTED();
6179}
6180
6181void Context::scalef(GLfloat x, GLfloat y, GLfloat z)
6182{
6183 UNIMPLEMENTED();
6184}
6185
6186void Context::scalex(GLfixed x, GLfixed y, GLfixed z)
6187{
6188 UNIMPLEMENTED();
6189}
6190
6191void Context::shadeModel(GLenum mode)
6192{
6193 UNIMPLEMENTED();
6194}
6195
6196void Context::texCoordPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6197{
6198 UNIMPLEMENTED();
6199}
6200
6201void Context::texEnvf(GLenum target, GLenum pname, GLfloat param)
6202{
6203 UNIMPLEMENTED();
6204}
6205
6206void Context::texEnvfv(GLenum target, GLenum pname, const GLfloat *params)
6207{
6208 UNIMPLEMENTED();
6209}
6210
6211void Context::texEnvi(GLenum target, GLenum pname, GLint param)
6212{
6213 UNIMPLEMENTED();
6214}
6215
6216void Context::texEnviv(GLenum target, GLenum pname, const GLint *params)
6217{
6218 UNIMPLEMENTED();
6219}
6220
6221void Context::texEnvx(GLenum target, GLenum pname, GLfixed param)
6222{
6223 UNIMPLEMENTED();
6224}
6225
6226void Context::texEnvxv(GLenum target, GLenum pname, const GLfixed *params)
6227{
6228 UNIMPLEMENTED();
6229}
6230
6231void Context::texParameterx(GLenum target, GLenum pname, GLfixed param)
6232{
6233 UNIMPLEMENTED();
6234}
6235
6236void Context::texParameterxv(GLenum target, GLenum pname, const GLfixed *params)
6237{
6238 UNIMPLEMENTED();
6239}
6240
6241void Context::translatef(GLfloat x, GLfloat y, GLfloat z)
6242{
6243 UNIMPLEMENTED();
6244}
6245
6246void Context::translatex(GLfixed x, GLfixed y, GLfixed z)
6247{
6248 UNIMPLEMENTED();
6249}
6250
6251void Context::vertexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6252{
6253 UNIMPLEMENTED();
6254}
6255
6256void Context::drawTexf(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height)
6257{
6258 UNIMPLEMENTED();
6259}
6260
6261void Context::drawTexfv(const GLfloat *coords)
6262{
6263 UNIMPLEMENTED();
6264}
6265
6266void Context::drawTexi(GLint x, GLint y, GLint z, GLint width, GLint height)
6267{
6268 UNIMPLEMENTED();
6269}
6270
6271void Context::drawTexiv(const GLint *coords)
6272{
6273 UNIMPLEMENTED();
6274}
6275
6276void Context::drawTexs(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height)
6277{
6278 UNIMPLEMENTED();
6279}
6280
6281void Context::drawTexsv(const GLshort *coords)
6282{
6283 UNIMPLEMENTED();
6284}
6285
6286void Context::drawTexx(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height)
6287{
6288 UNIMPLEMENTED();
6289}
6290
6291void Context::drawTexxv(const GLfixed *coords)
6292{
6293 UNIMPLEMENTED();
6294}
6295
6296void Context::currentPaletteMatrix(GLuint matrixpaletteindex)
6297{
6298 UNIMPLEMENTED();
6299}
6300
6301void Context::loadPaletteFromModelViewMatrix()
6302{
6303 UNIMPLEMENTED();
6304}
6305
6306void Context::matrixIndexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6307{
6308 UNIMPLEMENTED();
6309}
6310
6311void Context::weightPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6312{
6313 UNIMPLEMENTED();
6314}
6315
6316void Context::pointSizePointer(GLenum type, GLsizei stride, const void *pointer)
6317{
6318 UNIMPLEMENTED();
6319}
6320
6321GLbitfield Context::queryMatrixx(GLfixed *mantissa, GLint *exponent)
6322{
6323 UNIMPLEMENTED();
6324 return 0;
6325}
6326
Jamie Madillc29968b2016-01-20 11:17:23 -05006327} // namespace gl