blob: 5aeb75cf7b757c420dcbf9759605d8a8680791b4 [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 Madill9fdaa492018-02-16 10:52:11 -05001784 // No-op if zero count
1785 if (count == 0)
1786 {
1787 return;
1788 }
1789
Jamie Madill05b35b22017-10-03 09:01:44 -04001790 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001791 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
1792 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001793}
1794
Jamie Madill675fe712016-12-19 13:07:54 -05001795void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001796{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001797 // No-op if zero count
1798 if (count == 0 || instanceCount == 0)
1799 {
1800 return;
1801 }
1802
Jamie Madill05b35b22017-10-03 09:01:44 -04001803 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001804 ANGLE_CONTEXT_TRY(
1805 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
1806 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
Geoff Langf6db0982015-08-25 13:04:00 -04001807}
1808
Jamie Madill876429b2017-04-20 15:46:24 -04001809void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001810{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001811 // No-op if zero count
1812 if (count == 0)
1813 {
1814 return;
1815 }
1816
Jamie Madill05b35b22017-10-03 09:01:44 -04001817 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001818 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001819}
1820
Jamie Madill675fe712016-12-19 13:07:54 -05001821void Context::drawElementsInstanced(GLenum mode,
1822 GLsizei count,
1823 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001824 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001825 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001826{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001827 // No-op if zero count
1828 if (count == 0 || instances == 0)
1829 {
1830 return;
1831 }
1832
Jamie Madill05b35b22017-10-03 09:01:44 -04001833 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001834 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001835 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001836}
1837
Jamie Madill675fe712016-12-19 13:07:54 -05001838void Context::drawRangeElements(GLenum mode,
1839 GLuint start,
1840 GLuint end,
1841 GLsizei count,
1842 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001843 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001844{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001845 // No-op if zero count
1846 if (count == 0)
1847 {
1848 return;
1849 }
1850
Jamie Madill05b35b22017-10-03 09:01:44 -04001851 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001852 ANGLE_CONTEXT_TRY(
1853 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001854}
1855
Jamie Madill876429b2017-04-20 15:46:24 -04001856void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001857{
Jamie Madill05b35b22017-10-03 09:01:44 -04001858 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001859 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001860}
1861
Jamie Madill876429b2017-04-20 15:46:24 -04001862void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001863{
Jamie Madill05b35b22017-10-03 09:01:44 -04001864 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001865 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001866}
1867
Jamie Madill675fe712016-12-19 13:07:54 -05001868void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001869{
Jamie Madillafa02a22017-11-23 12:57:38 -05001870 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05001871}
1872
Jamie Madill675fe712016-12-19 13:07:54 -05001873void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001874{
Jamie Madillafa02a22017-11-23 12:57:38 -05001875 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001876}
1877
Austin Kinross6ee1e782015-05-29 17:05:37 -07001878void Context::insertEventMarker(GLsizei length, const char *marker)
1879{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001880 ASSERT(mImplementation);
1881 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001882}
1883
1884void Context::pushGroupMarker(GLsizei length, const char *marker)
1885{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001886 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05001887
1888 if (marker == nullptr)
1889 {
1890 // From the EXT_debug_marker spec,
1891 // "If <marker> is null then an empty string is pushed on the stack."
1892 mImplementation->pushGroupMarker(length, "");
1893 }
1894 else
1895 {
1896 mImplementation->pushGroupMarker(length, marker);
1897 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07001898}
1899
1900void Context::popGroupMarker()
1901{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001902 ASSERT(mImplementation);
1903 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001904}
1905
Geoff Langd8605522016-04-13 10:19:12 -04001906void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1907{
1908 Program *programObject = getProgram(program);
1909 ASSERT(programObject);
1910
1911 programObject->bindUniformLocation(location, name);
1912}
1913
Sami Väisänena797e062016-05-12 15:23:40 +03001914void Context::setCoverageModulation(GLenum components)
1915{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001916 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001917}
1918
Sami Väisänene45e53b2016-05-25 10:36:04 +03001919void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1920{
1921 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1922}
1923
1924void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1925{
1926 GLfloat I[16];
1927 angle::Matrix<GLfloat>::setToIdentity(I);
1928
1929 mGLState.loadPathRenderingMatrix(matrixMode, I);
1930}
1931
1932void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1933{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001934 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001935 if (!pathObj)
1936 return;
1937
1938 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1939 syncRendererState();
1940
1941 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1942}
1943
1944void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1945{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001946 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001947 if (!pathObj)
1948 return;
1949
1950 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1951 syncRendererState();
1952
1953 mImplementation->stencilStrokePath(pathObj, reference, mask);
1954}
1955
1956void Context::coverFillPath(GLuint path, GLenum coverMode)
1957{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001958 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001959 if (!pathObj)
1960 return;
1961
1962 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1963 syncRendererState();
1964
1965 mImplementation->coverFillPath(pathObj, coverMode);
1966}
1967
1968void Context::coverStrokePath(GLuint path, GLenum coverMode)
1969{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001970 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001971 if (!pathObj)
1972 return;
1973
1974 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1975 syncRendererState();
1976
1977 mImplementation->coverStrokePath(pathObj, coverMode);
1978}
1979
1980void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1981{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001982 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001983 if (!pathObj)
1984 return;
1985
1986 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1987 syncRendererState();
1988
1989 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
1990}
1991
1992void Context::stencilThenCoverStrokePath(GLuint path,
1993 GLint reference,
1994 GLuint mask,
1995 GLenum coverMode)
1996{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001997 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001998 if (!pathObj)
1999 return;
2000
2001 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2002 syncRendererState();
2003
2004 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2005}
2006
Sami Väisänend59ca052016-06-21 16:10:00 +03002007void Context::coverFillPathInstanced(GLsizei numPaths,
2008 GLenum pathNameType,
2009 const void *paths,
2010 GLuint pathBase,
2011 GLenum coverMode,
2012 GLenum transformType,
2013 const GLfloat *transformValues)
2014{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002015 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002016
2017 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2018 syncRendererState();
2019
2020 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2021}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002022
Sami Väisänend59ca052016-06-21 16:10:00 +03002023void Context::coverStrokePathInstanced(GLsizei numPaths,
2024 GLenum pathNameType,
2025 const void *paths,
2026 GLuint pathBase,
2027 GLenum coverMode,
2028 GLenum transformType,
2029 const GLfloat *transformValues)
2030{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002031 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002032
2033 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2034 syncRendererState();
2035
2036 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2037 transformValues);
2038}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002039
Sami Väisänend59ca052016-06-21 16:10:00 +03002040void Context::stencilFillPathInstanced(GLsizei numPaths,
2041 GLenum pathNameType,
2042 const void *paths,
2043 GLuint pathBase,
2044 GLenum fillMode,
2045 GLuint mask,
2046 GLenum transformType,
2047 const GLfloat *transformValues)
2048{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002049 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002050
2051 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2052 syncRendererState();
2053
2054 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2055 transformValues);
2056}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002057
Sami Väisänend59ca052016-06-21 16:10:00 +03002058void Context::stencilStrokePathInstanced(GLsizei numPaths,
2059 GLenum pathNameType,
2060 const void *paths,
2061 GLuint pathBase,
2062 GLint reference,
2063 GLuint mask,
2064 GLenum transformType,
2065 const GLfloat *transformValues)
2066{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002067 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002068
2069 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2070 syncRendererState();
2071
2072 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2073 transformValues);
2074}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002075
Sami Väisänend59ca052016-06-21 16:10:00 +03002076void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2077 GLenum pathNameType,
2078 const void *paths,
2079 GLuint pathBase,
2080 GLenum fillMode,
2081 GLuint mask,
2082 GLenum coverMode,
2083 GLenum transformType,
2084 const GLfloat *transformValues)
2085{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002086 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002087
2088 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2089 syncRendererState();
2090
2091 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2092 transformType, transformValues);
2093}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002094
Sami Väisänend59ca052016-06-21 16:10:00 +03002095void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2096 GLenum pathNameType,
2097 const void *paths,
2098 GLuint pathBase,
2099 GLint reference,
2100 GLuint mask,
2101 GLenum coverMode,
2102 GLenum transformType,
2103 const GLfloat *transformValues)
2104{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002105 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002106
2107 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2108 syncRendererState();
2109
2110 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2111 transformType, transformValues);
2112}
2113
Sami Väisänen46eaa942016-06-29 10:26:37 +03002114void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2115{
2116 auto *programObject = getProgram(program);
2117
2118 programObject->bindFragmentInputLocation(location, name);
2119}
2120
2121void Context::programPathFragmentInputGen(GLuint program,
2122 GLint location,
2123 GLenum genMode,
2124 GLint components,
2125 const GLfloat *coeffs)
2126{
2127 auto *programObject = getProgram(program);
2128
Jamie Madillbd044ed2017-06-05 12:59:21 -04002129 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002130}
2131
jchen1015015f72017-03-16 13:54:21 +08002132GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2133{
jchen10fd7c3b52017-03-21 15:36:03 +08002134 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002135 return QueryProgramResourceIndex(programObject, programInterface, name);
2136}
2137
jchen10fd7c3b52017-03-21 15:36:03 +08002138void Context::getProgramResourceName(GLuint program,
2139 GLenum programInterface,
2140 GLuint index,
2141 GLsizei bufSize,
2142 GLsizei *length,
2143 GLchar *name)
2144{
2145 const auto *programObject = getProgram(program);
2146 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2147}
2148
jchen10191381f2017-04-11 13:59:04 +08002149GLint Context::getProgramResourceLocation(GLuint program,
2150 GLenum programInterface,
2151 const GLchar *name)
2152{
2153 const auto *programObject = getProgram(program);
2154 return QueryProgramResourceLocation(programObject, programInterface, name);
2155}
2156
jchen10880683b2017-04-12 16:21:55 +08002157void Context::getProgramResourceiv(GLuint program,
2158 GLenum programInterface,
2159 GLuint index,
2160 GLsizei propCount,
2161 const GLenum *props,
2162 GLsizei bufSize,
2163 GLsizei *length,
2164 GLint *params)
2165{
2166 const auto *programObject = getProgram(program);
2167 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2168 length, params);
2169}
2170
jchen10d9cd7b72017-08-30 15:04:25 +08002171void Context::getProgramInterfaceiv(GLuint program,
2172 GLenum programInterface,
2173 GLenum pname,
2174 GLint *params)
2175{
2176 const auto *programObject = getProgram(program);
2177 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2178}
2179
Jamie Madill71c88b32017-09-14 22:20:29 -04002180void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002181{
Geoff Langda5777c2014-07-11 09:52:58 -04002182 if (error.isError())
2183 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002184 GLenum code = error.getCode();
2185 mErrors.insert(code);
2186 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2187 {
2188 markContextLost();
2189 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002190
Geoff Langee6884e2017-11-09 16:51:11 -05002191 ASSERT(!error.getMessage().empty());
2192 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2193 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002194 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002195}
2196
2197// Get one of the recorded errors and clear its flag, if any.
2198// [OpenGL ES 2.0.24] section 2.5 page 13.
2199GLenum Context::getError()
2200{
Geoff Langda5777c2014-07-11 09:52:58 -04002201 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002202 {
Geoff Langda5777c2014-07-11 09:52:58 -04002203 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002204 }
Geoff Langda5777c2014-07-11 09:52:58 -04002205 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002206 {
Geoff Langda5777c2014-07-11 09:52:58 -04002207 GLenum error = *mErrors.begin();
2208 mErrors.erase(mErrors.begin());
2209 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002210 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002211}
2212
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002213// NOTE: this function should not assume that this context is current!
2214void Context::markContextLost()
2215{
2216 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002217 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002218 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002219 mContextLostForced = true;
2220 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002221 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002222}
2223
2224bool Context::isContextLost()
2225{
2226 return mContextLost;
2227}
2228
Jamie Madillfa920eb2018-01-04 11:45:50 -05002229GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002230{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002231 // Even if the application doesn't want to know about resets, we want to know
2232 // as it will allow us to skip all the calls.
2233 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002234 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002235 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002236 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002237 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002238 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002239
2240 // EXT_robustness, section 2.6: If the reset notification behavior is
2241 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2242 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2243 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002244 }
2245
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002246 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2247 // status should be returned at least once, and GL_NO_ERROR should be returned
2248 // once the device has finished resetting.
2249 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002250 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002251 ASSERT(mResetStatus == GL_NO_ERROR);
2252 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002253
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002254 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002255 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002256 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002257 }
2258 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002259 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002260 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002261 // If markContextLost was used to mark the context lost then
2262 // assume that is not recoverable, and continue to report the
2263 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002264 mResetStatus = mImplementation->getResetStatus();
2265 }
Jamie Madill893ab082014-05-16 16:56:10 -04002266
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002267 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002268}
2269
2270bool Context::isResetNotificationEnabled()
2271{
2272 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2273}
2274
Corentin Walleze3b10e82015-05-20 11:06:25 -04002275const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002276{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002277 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002278}
2279
2280EGLenum Context::getClientType() const
2281{
2282 return mClientType;
2283}
2284
2285EGLenum Context::getRenderBuffer() const
2286{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002287 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2288 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002289 {
2290 return EGL_NONE;
2291 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002292
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002293 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002294 ASSERT(backAttachment != nullptr);
2295 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002296}
2297
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002298VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002299{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002300 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002301 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2302 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002303 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002304 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2305 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002306
Jamie Madill96a483b2017-06-27 16:49:21 -04002307 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002308 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002309
2310 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002311}
2312
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002313TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002314{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002315 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002316 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2317 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002318 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002319 transformFeedback =
2320 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002321 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002322 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002323 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002324
2325 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002326}
2327
2328bool Context::isVertexArrayGenerated(GLuint vertexArray)
2329{
Jamie Madill96a483b2017-06-27 16:49:21 -04002330 ASSERT(mVertexArrayMap.contains(0));
2331 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002332}
2333
2334bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2335{
Jamie Madill96a483b2017-06-27 16:49:21 -04002336 ASSERT(mTransformFeedbackMap.contains(0));
2337 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002338}
2339
Shannon Woods53a94a82014-06-24 15:20:36 -04002340void Context::detachTexture(GLuint texture)
2341{
2342 // Simple pass-through to State's detachTexture method, as textures do not require
2343 // allocation map management either here or in the resource manager at detach time.
2344 // Zero textures are held by the Context, and we don't attempt to request them from
2345 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002346 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002347}
2348
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002349void Context::detachBuffer(GLuint buffer)
2350{
Yuly Novikov5807a532015-12-03 13:01:22 -05002351 // Simple pass-through to State's detachBuffer method, since
2352 // only buffer attachments to container objects that are bound to the current context
2353 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002354
Yuly Novikov5807a532015-12-03 13:01:22 -05002355 // [OpenGL ES 3.2] section 5.1.2 page 45:
2356 // Attachments to unbound container objects, such as
2357 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2358 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002359 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002360}
2361
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002362void Context::detachFramebuffer(GLuint framebuffer)
2363{
Shannon Woods53a94a82014-06-24 15:20:36 -04002364 // Framebuffer detachment is handled by Context, because 0 is a valid
2365 // Framebuffer object, and a pointer to it must be passed from Context
2366 // to State at binding time.
2367
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002368 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002369 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2370 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2371 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002372
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002373 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002374 {
2375 bindReadFramebuffer(0);
2376 }
2377
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002378 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002379 {
2380 bindDrawFramebuffer(0);
2381 }
2382}
2383
2384void Context::detachRenderbuffer(GLuint renderbuffer)
2385{
Jamie Madilla02315b2017-02-23 14:14:47 -05002386 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002387}
2388
Jamie Madill57a89722013-07-02 11:57:03 -04002389void Context::detachVertexArray(GLuint vertexArray)
2390{
Jamie Madill77a72f62015-04-14 11:18:32 -04002391 // Vertex array detachment is handled by Context, because 0 is a valid
2392 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002393 // binding time.
2394
Jamie Madill57a89722013-07-02 11:57:03 -04002395 // [OpenGL ES 3.0.2] section 2.10 page 43:
2396 // If a vertex array object that is currently bound is deleted, the binding
2397 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002398 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002399 {
2400 bindVertexArray(0);
2401 }
2402}
2403
Geoff Langc8058452014-02-03 12:04:11 -05002404void Context::detachTransformFeedback(GLuint transformFeedback)
2405{
Corentin Walleza2257da2016-04-19 16:43:12 -04002406 // Transform feedback detachment is handled by Context, because 0 is a valid
2407 // transform feedback, and a pointer to it must be passed from Context to State at
2408 // binding time.
2409
2410 // The OpenGL specification doesn't mention what should happen when the currently bound
2411 // transform feedback object is deleted. Since it is a container object, we treat it like
2412 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002413 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002414 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002415 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002416 }
Geoff Langc8058452014-02-03 12:04:11 -05002417}
2418
Jamie Madilldc356042013-07-19 16:36:57 -04002419void Context::detachSampler(GLuint sampler)
2420{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002421 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002422}
2423
Yunchao Hea336b902017-08-02 16:05:21 +08002424void Context::detachProgramPipeline(GLuint pipeline)
2425{
2426 mGLState.detachProgramPipeline(this, pipeline);
2427}
2428
Jamie Madill3ef140a2017-08-26 23:11:21 -04002429void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002430{
Shaodde78e82017-05-22 14:13:27 +08002431 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002432}
2433
Jamie Madille29d1672013-07-19 16:36:57 -04002434void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2435{
Geoff Langc1984ed2016-10-07 12:41:00 -04002436 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002437 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002438 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002439 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002440}
Jamie Madille29d1672013-07-19 16:36:57 -04002441
Geoff Langc1984ed2016-10-07 12:41:00 -04002442void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2443{
2444 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002445 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002446 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002447 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002448}
2449
2450void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2451{
Geoff Langc1984ed2016-10-07 12:41:00 -04002452 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002453 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002454 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002455 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002456}
2457
Geoff Langc1984ed2016-10-07 12:41:00 -04002458void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002459{
Geoff Langc1984ed2016-10-07 12:41:00 -04002460 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002461 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002462 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002463 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002464}
2465
Geoff Langc1984ed2016-10-07 12:41:00 -04002466void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002467{
Geoff Langc1984ed2016-10-07 12:41:00 -04002468 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002469 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002470 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002471 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002472}
Jamie Madill9675b802013-07-19 16:36:59 -04002473
Geoff Langc1984ed2016-10-07 12:41:00 -04002474void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2475{
2476 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002477 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002478 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002479 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002480}
2481
Olli Etuahof0fee072016-03-30 15:11:58 +03002482void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2483{
2484 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002485 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002486}
2487
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002488void Context::initRendererString()
2489{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002490 std::ostringstream rendererString;
2491 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002492 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002493 rendererString << ")";
2494
Geoff Langcec35902014-04-16 10:52:36 -04002495 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002496}
2497
Geoff Langc339c4e2016-11-29 10:37:36 -05002498void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002499{
Geoff Langc339c4e2016-11-29 10:37:36 -05002500 const Version &clientVersion = getClientVersion();
2501
2502 std::ostringstream versionString;
2503 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2504 << ANGLE_VERSION_STRING << ")";
2505 mVersionString = MakeStaticString(versionString.str());
2506
2507 std::ostringstream shadingLanguageVersionString;
2508 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2509 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2510 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2511 << ")";
2512 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002513}
2514
Geoff Langcec35902014-04-16 10:52:36 -04002515void Context::initExtensionStrings()
2516{
Geoff Langc339c4e2016-11-29 10:37:36 -05002517 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2518 std::ostringstream combinedStringStream;
2519 std::copy(strings.begin(), strings.end(),
2520 std::ostream_iterator<const char *>(combinedStringStream, " "));
2521 return MakeStaticString(combinedStringStream.str());
2522 };
2523
2524 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002525 for (const auto &extensionString : mExtensions.getStrings())
2526 {
2527 mExtensionStrings.push_back(MakeStaticString(extensionString));
2528 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002529 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002530
Bryan Bernhart58806562017-01-05 13:09:31 -08002531 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2532
Geoff Langc339c4e2016-11-29 10:37:36 -05002533 mRequestableExtensionStrings.clear();
2534 for (const auto &extensionInfo : GetExtensionInfoMap())
2535 {
2536 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002537 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2538 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002539 {
2540 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2541 }
2542 }
2543 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002544}
2545
Geoff Langc339c4e2016-11-29 10:37:36 -05002546const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002547{
Geoff Langc339c4e2016-11-29 10:37:36 -05002548 switch (name)
2549 {
2550 case GL_VENDOR:
2551 return reinterpret_cast<const GLubyte *>("Google Inc.");
2552
2553 case GL_RENDERER:
2554 return reinterpret_cast<const GLubyte *>(mRendererString);
2555
2556 case GL_VERSION:
2557 return reinterpret_cast<const GLubyte *>(mVersionString);
2558
2559 case GL_SHADING_LANGUAGE_VERSION:
2560 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2561
2562 case GL_EXTENSIONS:
2563 return reinterpret_cast<const GLubyte *>(mExtensionString);
2564
2565 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2566 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2567
2568 default:
2569 UNREACHABLE();
2570 return nullptr;
2571 }
Geoff Langcec35902014-04-16 10:52:36 -04002572}
2573
Geoff Langc339c4e2016-11-29 10:37:36 -05002574const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002575{
Geoff Langc339c4e2016-11-29 10:37:36 -05002576 switch (name)
2577 {
2578 case GL_EXTENSIONS:
2579 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2580
2581 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2582 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2583
2584 default:
2585 UNREACHABLE();
2586 return nullptr;
2587 }
Geoff Langcec35902014-04-16 10:52:36 -04002588}
2589
2590size_t Context::getExtensionStringCount() const
2591{
2592 return mExtensionStrings.size();
2593}
2594
Geoff Lang111a99e2017-10-17 10:58:41 -04002595bool Context::isExtensionRequestable(const char *name)
2596{
2597 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2598 auto extension = extensionInfos.find(name);
2599
2600 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2601 return extension != extensionInfos.end() && extension->second.Requestable &&
2602 nativeExtensions.*(extension->second.ExtensionsMember);
2603}
2604
Geoff Langc339c4e2016-11-29 10:37:36 -05002605void Context::requestExtension(const char *name)
2606{
2607 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2608 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2609 const auto &extension = extensionInfos.at(name);
2610 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002611 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002612
2613 if (mExtensions.*(extension.ExtensionsMember))
2614 {
2615 // Extension already enabled
2616 return;
2617 }
2618
2619 mExtensions.*(extension.ExtensionsMember) = true;
2620 updateCaps();
2621 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002622
Jamie Madill2f348d22017-06-05 10:50:59 -04002623 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2624 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002625
Jamie Madill81c2e252017-09-09 23:32:46 -04002626 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2627 // sampleable.
2628 mState.mTextures->signalAllTexturesDirty();
Geoff Lang9aded172017-04-05 11:07:56 -04002629 for (auto &zeroTexture : mZeroTextures)
2630 {
Jamie Madill05b35b22017-10-03 09:01:44 -04002631 zeroTexture.second->signalDirty(InitState::Initialized);
Geoff Lang9aded172017-04-05 11:07:56 -04002632 }
2633
2634 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002635}
2636
2637size_t Context::getRequestableExtensionStringCount() const
2638{
2639 return mRequestableExtensionStrings.size();
2640}
2641
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002642void Context::beginTransformFeedback(GLenum primitiveMode)
2643{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002644 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002645 ASSERT(transformFeedback != nullptr);
2646 ASSERT(!transformFeedback->isPaused());
2647
Jamie Madill6c1f6712017-02-14 19:08:04 -05002648 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002649}
2650
2651bool Context::hasActiveTransformFeedback(GLuint program) const
2652{
2653 for (auto pair : mTransformFeedbackMap)
2654 {
2655 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2656 {
2657 return true;
2658 }
2659 }
2660 return false;
2661}
2662
Geoff Langb433e872017-10-05 14:01:47 -04002663void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002664{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002665 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002666
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002667 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002668
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002669 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002670
Geoff Langeb66a6e2016-10-31 13:06:12 -04002671 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002672 {
2673 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002674 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002675 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002676 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002677 mExtensions.multiview = false;
2678 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002679 }
2680
Jiawei Shao89be29a2017-11-06 14:36:45 +08002681 if (getClientVersion() < ES_3_1)
2682 {
2683 // Disable ES3.1+ extensions
2684 mExtensions.geometryShader = false;
2685 }
2686
Geoff Langeb66a6e2016-10-31 13:06:12 -04002687 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002688 {
2689 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002690 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002691 }
2692
Jamie Madill00ed7a12016-05-19 13:13:38 -04002693 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002694 mExtensions.bindUniformLocation = true;
2695 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002696 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002697 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002698 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002699
2700 // Enable the no error extension if the context was created with the flag.
2701 mExtensions.noError = mSkipValidation;
2702
Corentin Wallezccab69d2017-01-27 16:57:15 -05002703 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002704 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002705
Geoff Lang70d0f492015-12-10 17:45:46 -05002706 // Explicitly enable GL_KHR_debug
2707 mExtensions.debug = true;
2708 mExtensions.maxDebugMessageLength = 1024;
2709 mExtensions.maxDebugLoggedMessages = 1024;
2710 mExtensions.maxDebugGroupStackDepth = 1024;
2711 mExtensions.maxLabelLength = 1024;
2712
Geoff Langff5b2d52016-09-07 11:32:23 -04002713 // Explicitly enable GL_ANGLE_robust_client_memory
2714 mExtensions.robustClientMemory = true;
2715
Jamie Madille08a1d32017-03-07 17:24:06 -05002716 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002717 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002718
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002719 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2720 // supports it.
2721 mExtensions.robustBufferAccessBehavior =
2722 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2723
Jamie Madillc43be722017-07-13 16:22:14 -04002724 // Enable the cache control query unconditionally.
2725 mExtensions.programCacheControl = true;
2726
Geoff Lang301d1612014-07-09 10:34:37 -04002727 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002728 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002729
Jamie Madill0f80ed82017-09-19 00:24:56 -04002730 if (getClientVersion() < ES_3_1)
2731 {
2732 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2733 }
2734 else
2735 {
2736 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2737 }
Geoff Lang301d1612014-07-09 10:34:37 -04002738
Jamie Madill0f80ed82017-09-19 00:24:56 -04002739 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2740 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2741 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2742
2743 // Limit textures as well, so we can use fast bitsets with texture bindings.
2744 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2745 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2746 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002747
Jiawei Shaodb342272017-09-27 10:21:45 +08002748 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2749
Geoff Langc287ea62016-09-16 14:46:51 -04002750 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002751 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002752 for (const auto &extensionInfo : GetExtensionInfoMap())
2753 {
2754 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002755 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002756 {
2757 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2758 }
2759 }
2760
2761 // Generate texture caps
2762 updateCaps();
2763}
2764
2765void Context::updateCaps()
2766{
Geoff Lang900013c2014-07-07 11:32:19 -04002767 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002768 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002769
Jamie Madill7b62cf92017-11-02 15:20:49 -04002770 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04002771 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04002772 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04002773 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002774
Geoff Lang0d8b7242015-09-09 14:56:53 -04002775 // Update the format caps based on the client version and extensions.
2776 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2777 // ES3.
2778 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002779 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002780 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002781 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002782 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002783 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002784
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002785 // OpenGL ES does not support multisampling with non-rendererable formats
2786 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002787 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002788 (getClientVersion() < ES_3_1 &&
2789 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002790 {
Geoff Langd87878e2014-09-19 15:42:59 -04002791 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002792 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002793 else
2794 {
2795 // We may have limited the max samples for some required renderbuffer formats due to
2796 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2797 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2798
2799 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2800 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2801 // exception of signed and unsigned integer formats."
2802 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2803 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2804 {
2805 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2806 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2807 }
2808
2809 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2810 if (getClientVersion() >= ES_3_1)
2811 {
2812 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2813 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2814 // the exception that the signed and unsigned integer formats are required only to
2815 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2816 // multisamples, which must be at least one."
2817 if (formatInfo.componentType == GL_INT ||
2818 formatInfo.componentType == GL_UNSIGNED_INT)
2819 {
2820 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2821 }
2822
2823 // GLES 3.1 section 19.3.1.
2824 if (formatCaps.texturable)
2825 {
2826 if (formatInfo.depthBits > 0)
2827 {
2828 mCaps.maxDepthTextureSamples =
2829 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2830 }
2831 else if (formatInfo.redBits > 0)
2832 {
2833 mCaps.maxColorTextureSamples =
2834 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2835 }
2836 }
2837 }
2838 }
Geoff Langd87878e2014-09-19 15:42:59 -04002839
2840 if (formatCaps.texturable && formatInfo.compressed)
2841 {
Geoff Langca271392017-04-05 12:30:00 -04002842 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002843 }
2844
Geoff Langca271392017-04-05 12:30:00 -04002845 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002846 }
Jamie Madill32447362017-06-28 14:53:52 -04002847
2848 // If program binary is disabled, blank out the memory cache pointer.
2849 if (!mImplementation->getNativeExtensions().getProgramBinary)
2850 {
2851 mMemoryProgramCache = nullptr;
2852 }
Corentin Walleze4477002017-12-01 14:39:58 -05002853
2854 // Compute which buffer types are allowed
2855 mValidBufferBindings.reset();
2856 mValidBufferBindings.set(BufferBinding::ElementArray);
2857 mValidBufferBindings.set(BufferBinding::Array);
2858
2859 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
2860 {
2861 mValidBufferBindings.set(BufferBinding::PixelPack);
2862 mValidBufferBindings.set(BufferBinding::PixelUnpack);
2863 }
2864
2865 if (getClientVersion() >= ES_3_0)
2866 {
2867 mValidBufferBindings.set(BufferBinding::CopyRead);
2868 mValidBufferBindings.set(BufferBinding::CopyWrite);
2869 mValidBufferBindings.set(BufferBinding::TransformFeedback);
2870 mValidBufferBindings.set(BufferBinding::Uniform);
2871 }
2872
2873 if (getClientVersion() >= ES_3_1)
2874 {
2875 mValidBufferBindings.set(BufferBinding::AtomicCounter);
2876 mValidBufferBindings.set(BufferBinding::ShaderStorage);
2877 mValidBufferBindings.set(BufferBinding::DrawIndirect);
2878 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
2879 }
Geoff Lang493daf52014-07-03 13:38:44 -04002880}
2881
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002882void Context::initWorkarounds()
2883{
Jamie Madill761b02c2017-06-23 16:27:06 -04002884 // Apply back-end workarounds.
2885 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2886
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002887 // Lose the context upon out of memory error if the application is
2888 // expecting to watch for those events.
2889 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2890}
2891
Jamie Madill05b35b22017-10-03 09:01:44 -04002892Error Context::prepareForDraw()
2893{
2894 syncRendererState();
Jamie Madilla59fc192017-11-02 12:57:58 -04002895
2896 if (isRobustResourceInitEnabled())
2897 {
2898 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
2899 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
2900 }
2901
Jamie Madill05b35b22017-10-03 09:01:44 -04002902 return NoError();
2903}
2904
Jamie Madill1b94d432015-08-07 13:23:23 -04002905void Context::syncRendererState()
2906{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002907 mGLState.syncDirtyObjects(this);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002908 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madillfe548342017-06-19 11:13:24 -04002909 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002910 mGLState.clearDirtyBits();
Jamie Madill1b94d432015-08-07 13:23:23 -04002911}
2912
Jamie Madillad9f24e2016-02-12 09:27:24 -05002913void Context::syncRendererState(const State::DirtyBits &bitMask,
2914 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002915{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002916 mGLState.syncDirtyObjects(this, objectMask);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002917 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002918 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002919 mGLState.clearDirtyBits(dirtyBits);
Jamie Madill1b94d432015-08-07 13:23:23 -04002920}
Jamie Madillc29968b2016-01-20 11:17:23 -05002921
2922void Context::blitFramebuffer(GLint srcX0,
2923 GLint srcY0,
2924 GLint srcX1,
2925 GLint srcY1,
2926 GLint dstX0,
2927 GLint dstY0,
2928 GLint dstX1,
2929 GLint dstY1,
2930 GLbitfield mask,
2931 GLenum filter)
2932{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002933 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002934 ASSERT(drawFramebuffer);
2935
2936 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2937 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2938
Jamie Madillad9f24e2016-02-12 09:27:24 -05002939 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002940
Jamie Madillc564c072017-06-01 12:45:42 -04002941 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002942}
Jamie Madillc29968b2016-01-20 11:17:23 -05002943
2944void Context::clear(GLbitfield mask)
2945{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002946 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002947 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002948}
2949
2950void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2951{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002952 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002953 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002954}
2955
2956void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2957{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002958 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002959 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002960}
2961
2962void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2963{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002964 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002965 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002966}
2967
2968void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2969{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002970 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002971 ASSERT(framebufferObject);
2972
2973 // If a buffer is not present, the clear has no effect
2974 if (framebufferObject->getDepthbuffer() == nullptr &&
2975 framebufferObject->getStencilbuffer() == nullptr)
2976 {
2977 return;
2978 }
2979
Jamie Madillad9f24e2016-02-12 09:27:24 -05002980 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002981 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05002982}
2983
2984void Context::readPixels(GLint x,
2985 GLint y,
2986 GLsizei width,
2987 GLsizei height,
2988 GLenum format,
2989 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002990 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05002991{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002992 if (width == 0 || height == 0)
2993 {
2994 return;
2995 }
2996
Jamie Madillad9f24e2016-02-12 09:27:24 -05002997 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05002998
Jamie Madillb6664922017-07-25 12:55:04 -04002999 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3000 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003001
3002 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003003 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003004}
3005
3006void Context::copyTexImage2D(GLenum target,
3007 GLint level,
3008 GLenum internalformat,
3009 GLint x,
3010 GLint y,
3011 GLsizei width,
3012 GLsizei height,
3013 GLint border)
3014{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003015 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003016 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003017
Jamie Madillc29968b2016-01-20 11:17:23 -05003018 Rectangle sourceArea(x, y, width, height);
3019
Jamie Madill05b35b22017-10-03 09:01:44 -04003020 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003021 Texture *texture =
3022 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003023 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003024}
3025
3026void Context::copyTexSubImage2D(GLenum target,
3027 GLint level,
3028 GLint xoffset,
3029 GLint yoffset,
3030 GLint x,
3031 GLint y,
3032 GLsizei width,
3033 GLsizei height)
3034{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003035 if (width == 0 || height == 0)
3036 {
3037 return;
3038 }
3039
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003040 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003041 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003042
Jamie Madillc29968b2016-01-20 11:17:23 -05003043 Offset destOffset(xoffset, yoffset, 0);
3044 Rectangle sourceArea(x, y, width, height);
3045
Jamie Madill05b35b22017-10-03 09:01:44 -04003046 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003047 Texture *texture =
3048 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003049 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003050}
3051
3052void Context::copyTexSubImage3D(GLenum target,
3053 GLint level,
3054 GLint xoffset,
3055 GLint yoffset,
3056 GLint zoffset,
3057 GLint x,
3058 GLint y,
3059 GLsizei width,
3060 GLsizei height)
3061{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003062 if (width == 0 || height == 0)
3063 {
3064 return;
3065 }
3066
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003067 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003068 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003069
Jamie Madillc29968b2016-01-20 11:17:23 -05003070 Offset destOffset(xoffset, yoffset, zoffset);
3071 Rectangle sourceArea(x, y, width, height);
3072
Jamie Madill05b35b22017-10-03 09:01:44 -04003073 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3074 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003075 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003076}
3077
3078void Context::framebufferTexture2D(GLenum target,
3079 GLenum attachment,
3080 GLenum textarget,
3081 GLuint texture,
3082 GLint level)
3083{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003084 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003085 ASSERT(framebuffer);
3086
3087 if (texture != 0)
3088 {
3089 Texture *textureObj = getTexture(texture);
3090
3091 ImageIndex index = ImageIndex::MakeInvalid();
3092
3093 if (textarget == GL_TEXTURE_2D)
3094 {
3095 index = ImageIndex::Make2D(level);
3096 }
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003097 else if (textarget == GL_TEXTURE_RECTANGLE_ANGLE)
3098 {
3099 index = ImageIndex::MakeRectangle(level);
3100 }
JiangYizhoubddc46b2016-12-09 09:50:51 +08003101 else if (textarget == GL_TEXTURE_2D_MULTISAMPLE)
3102 {
3103 ASSERT(level == 0);
3104 index = ImageIndex::Make2DMultisample();
3105 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003106 else
3107 {
3108 ASSERT(IsCubeMapTextureTarget(textarget));
3109 index = ImageIndex::MakeCube(textarget, level);
3110 }
3111
Jamie Madilla02315b2017-02-23 14:14:47 -05003112 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003113 }
3114 else
3115 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003116 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003117 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003118
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003119 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003120}
3121
3122void Context::framebufferRenderbuffer(GLenum target,
3123 GLenum attachment,
3124 GLenum renderbuffertarget,
3125 GLuint renderbuffer)
3126{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003127 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003128 ASSERT(framebuffer);
3129
3130 if (renderbuffer != 0)
3131 {
3132 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003133
3134 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003135 renderbufferObject);
3136 }
3137 else
3138 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003139 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003140 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003141
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003142 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003143}
3144
3145void Context::framebufferTextureLayer(GLenum target,
3146 GLenum attachment,
3147 GLuint texture,
3148 GLint level,
3149 GLint layer)
3150{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003151 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003152 ASSERT(framebuffer);
3153
3154 if (texture != 0)
3155 {
3156 Texture *textureObject = getTexture(texture);
3157
3158 ImageIndex index = ImageIndex::MakeInvalid();
3159
3160 if (textureObject->getTarget() == GL_TEXTURE_3D)
3161 {
3162 index = ImageIndex::Make3D(level, layer);
3163 }
3164 else
3165 {
3166 ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY);
3167 index = ImageIndex::Make2DArray(level, layer);
3168 }
3169
Jamie Madilla02315b2017-02-23 14:14:47 -05003170 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003171 }
3172 else
3173 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003174 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003175 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003176
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003177 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003178}
3179
Martin Radev137032d2017-07-13 10:11:12 +03003180void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3181 GLenum attachment,
3182 GLuint texture,
3183 GLint level,
3184 GLint baseViewIndex,
3185 GLsizei numViews)
3186{
Martin Radev82ef7742017-08-08 17:44:58 +03003187 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3188 ASSERT(framebuffer);
3189
3190 if (texture != 0)
3191 {
3192 Texture *textureObj = getTexture(texture);
3193
Martin Radev18b75ba2017-08-15 15:50:40 +03003194 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003195 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3196 numViews, baseViewIndex);
3197 }
3198 else
3199 {
3200 framebuffer->resetAttachment(this, attachment);
3201 }
3202
3203 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003204}
3205
3206void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3207 GLenum attachment,
3208 GLuint texture,
3209 GLint level,
3210 GLsizei numViews,
3211 const GLint *viewportOffsets)
3212{
Martin Radev5dae57b2017-07-14 16:15:55 +03003213 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3214 ASSERT(framebuffer);
3215
3216 if (texture != 0)
3217 {
3218 Texture *textureObj = getTexture(texture);
3219
3220 ImageIndex index = ImageIndex::Make2D(level);
3221 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3222 textureObj, numViews, viewportOffsets);
3223 }
3224 else
3225 {
3226 framebuffer->resetAttachment(this, attachment);
3227 }
3228
3229 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003230}
3231
Jamie Madillc29968b2016-01-20 11:17:23 -05003232void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3233{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003234 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003235 ASSERT(framebuffer);
3236 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003237 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003238}
3239
3240void Context::readBuffer(GLenum mode)
3241{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003242 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003243 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003244 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003245}
3246
3247void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3248{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003249 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003250 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003251
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003252 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003253 ASSERT(framebuffer);
3254
3255 // The specification isn't clear what should be done when the framebuffer isn't complete.
3256 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003257 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003258}
3259
3260void Context::invalidateFramebuffer(GLenum target,
3261 GLsizei numAttachments,
3262 const GLenum *attachments)
3263{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003264 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003265 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003266
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003267 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003268 ASSERT(framebuffer);
3269
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003270 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003271 {
Jamie Madill437fa652016-05-03 15:13:24 -04003272 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003273 }
Jamie Madill437fa652016-05-03 15:13:24 -04003274
Jamie Madill4928b7c2017-06-20 12:57:39 -04003275 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003276}
3277
3278void Context::invalidateSubFramebuffer(GLenum target,
3279 GLsizei numAttachments,
3280 const GLenum *attachments,
3281 GLint x,
3282 GLint y,
3283 GLsizei width,
3284 GLsizei height)
3285{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003286 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003287 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003288
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003289 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003290 ASSERT(framebuffer);
3291
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003292 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003293 {
Jamie Madill437fa652016-05-03 15:13:24 -04003294 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003295 }
Jamie Madill437fa652016-05-03 15:13:24 -04003296
3297 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003298 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003299}
3300
Jamie Madill73a84962016-02-12 09:27:23 -05003301void Context::texImage2D(GLenum target,
3302 GLint level,
3303 GLint internalformat,
3304 GLsizei width,
3305 GLsizei height,
3306 GLint border,
3307 GLenum format,
3308 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003309 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003310{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003311 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003312
3313 Extents size(width, height, 1);
3314 Texture *texture =
3315 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003316 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3317 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003318}
3319
3320void Context::texImage3D(GLenum target,
3321 GLint level,
3322 GLint internalformat,
3323 GLsizei width,
3324 GLsizei height,
3325 GLsizei depth,
3326 GLint border,
3327 GLenum format,
3328 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003329 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003330{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003331 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003332
3333 Extents size(width, height, depth);
3334 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003335 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3336 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003337}
3338
3339void Context::texSubImage2D(GLenum target,
3340 GLint level,
3341 GLint xoffset,
3342 GLint yoffset,
3343 GLsizei width,
3344 GLsizei height,
3345 GLenum format,
3346 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003347 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003348{
3349 // Zero sized uploads are valid but no-ops
3350 if (width == 0 || height == 0)
3351 {
3352 return;
3353 }
3354
Jamie Madillad9f24e2016-02-12 09:27:24 -05003355 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003356
3357 Box area(xoffset, yoffset, 0, width, height, 1);
3358 Texture *texture =
3359 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003360 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3361 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003362}
3363
3364void Context::texSubImage3D(GLenum target,
3365 GLint level,
3366 GLint xoffset,
3367 GLint yoffset,
3368 GLint zoffset,
3369 GLsizei width,
3370 GLsizei height,
3371 GLsizei depth,
3372 GLenum format,
3373 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003374 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003375{
3376 // Zero sized uploads are valid but no-ops
3377 if (width == 0 || height == 0 || depth == 0)
3378 {
3379 return;
3380 }
3381
Jamie Madillad9f24e2016-02-12 09:27:24 -05003382 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003383
3384 Box area(xoffset, yoffset, zoffset, width, height, depth);
3385 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003386 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3387 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003388}
3389
3390void Context::compressedTexImage2D(GLenum target,
3391 GLint level,
3392 GLenum internalformat,
3393 GLsizei width,
3394 GLsizei height,
3395 GLint border,
3396 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003397 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003398{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003399 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003400
3401 Extents size(width, height, 1);
3402 Texture *texture =
3403 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003404 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003405 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003406 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003407}
3408
3409void Context::compressedTexImage3D(GLenum target,
3410 GLint level,
3411 GLenum internalformat,
3412 GLsizei width,
3413 GLsizei height,
3414 GLsizei depth,
3415 GLint border,
3416 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003417 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003418{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003419 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003420
3421 Extents size(width, height, depth);
3422 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003423 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003424 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003425 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003426}
3427
3428void Context::compressedTexSubImage2D(GLenum target,
3429 GLint level,
3430 GLint xoffset,
3431 GLint yoffset,
3432 GLsizei width,
3433 GLsizei height,
3434 GLenum format,
3435 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003436 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003437{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003438 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003439
3440 Box area(xoffset, yoffset, 0, width, height, 1);
3441 Texture *texture =
3442 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003443 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003444 format, imageSize,
3445 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003446}
3447
3448void Context::compressedTexSubImage3D(GLenum target,
3449 GLint level,
3450 GLint xoffset,
3451 GLint yoffset,
3452 GLint zoffset,
3453 GLsizei width,
3454 GLsizei height,
3455 GLsizei depth,
3456 GLenum format,
3457 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003458 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003459{
3460 // Zero sized uploads are valid but no-ops
3461 if (width == 0 || height == 0)
3462 {
3463 return;
3464 }
3465
Jamie Madillad9f24e2016-02-12 09:27:24 -05003466 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003467
3468 Box area(xoffset, yoffset, zoffset, width, height, depth);
3469 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003470 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003471 format, imageSize,
3472 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003473}
3474
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003475void Context::generateMipmap(GLenum target)
3476{
3477 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003478 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003479}
3480
Jamie Madill007530e2017-12-28 14:27:04 -05003481void Context::copyTexture(GLuint sourceId,
3482 GLint sourceLevel,
3483 GLenum destTarget,
3484 GLuint destId,
3485 GLint destLevel,
3486 GLint internalFormat,
3487 GLenum destType,
3488 GLboolean unpackFlipY,
3489 GLboolean unpackPremultiplyAlpha,
3490 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003491{
3492 syncStateForTexImage();
3493
3494 gl::Texture *sourceTexture = getTexture(sourceId);
3495 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05003496 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
3497 sourceLevel, ConvertToBool(unpackFlipY),
3498 ConvertToBool(unpackPremultiplyAlpha),
3499 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003500}
3501
Jamie Madill007530e2017-12-28 14:27:04 -05003502void Context::copySubTexture(GLuint sourceId,
3503 GLint sourceLevel,
3504 GLenum destTarget,
3505 GLuint destId,
3506 GLint destLevel,
3507 GLint xoffset,
3508 GLint yoffset,
3509 GLint x,
3510 GLint y,
3511 GLsizei width,
3512 GLsizei height,
3513 GLboolean unpackFlipY,
3514 GLboolean unpackPremultiplyAlpha,
3515 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003516{
3517 // Zero sized copies are valid but no-ops
3518 if (width == 0 || height == 0)
3519 {
3520 return;
3521 }
3522
3523 syncStateForTexImage();
3524
3525 gl::Texture *sourceTexture = getTexture(sourceId);
3526 gl::Texture *destTexture = getTexture(destId);
3527 Offset offset(xoffset, yoffset, 0);
3528 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05003529 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
3530 ConvertToBool(unpackFlipY),
3531 ConvertToBool(unpackPremultiplyAlpha),
3532 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003533}
3534
Jamie Madill007530e2017-12-28 14:27:04 -05003535void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07003536{
3537 syncStateForTexImage();
3538
3539 gl::Texture *sourceTexture = getTexture(sourceId);
3540 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003541 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003542}
3543
Corentin Wallez336129f2017-10-17 15:55:40 -04003544void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003545{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003546 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003547 ASSERT(buffer);
3548
Geoff Lang496c02d2016-10-20 11:38:11 -07003549 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003550}
3551
Corentin Wallez336129f2017-10-17 15:55:40 -04003552void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003553{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003554 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003555 ASSERT(buffer);
3556
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003557 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003558 if (error.isError())
3559 {
Jamie Madill437fa652016-05-03 15:13:24 -04003560 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003561 return nullptr;
3562 }
3563
3564 return buffer->getMapPointer();
3565}
3566
Corentin Wallez336129f2017-10-17 15:55:40 -04003567GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003568{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003569 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003570 ASSERT(buffer);
3571
3572 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003573 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003574 if (error.isError())
3575 {
Jamie Madill437fa652016-05-03 15:13:24 -04003576 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003577 return GL_FALSE;
3578 }
3579
3580 return result;
3581}
3582
Corentin Wallez336129f2017-10-17 15:55:40 -04003583void *Context::mapBufferRange(BufferBinding target,
3584 GLintptr offset,
3585 GLsizeiptr length,
3586 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003587{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003588 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003589 ASSERT(buffer);
3590
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003591 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003592 if (error.isError())
3593 {
Jamie Madill437fa652016-05-03 15:13:24 -04003594 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003595 return nullptr;
3596 }
3597
3598 return buffer->getMapPointer();
3599}
3600
Corentin Wallez336129f2017-10-17 15:55:40 -04003601void Context::flushMappedBufferRange(BufferBinding /*target*/,
3602 GLintptr /*offset*/,
3603 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03003604{
3605 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3606}
3607
Jamie Madillad9f24e2016-02-12 09:27:24 -05003608void Context::syncStateForReadPixels()
3609{
3610 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3611}
3612
3613void Context::syncStateForTexImage()
3614{
3615 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3616}
3617
3618void Context::syncStateForClear()
3619{
3620 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3621}
3622
3623void Context::syncStateForBlit()
3624{
3625 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3626}
3627
Jiajia Qin5451d532017-11-16 17:16:34 +08003628void Context::activeShaderProgram(GLuint pipeline, GLuint program)
3629{
3630 UNIMPLEMENTED();
3631}
3632
Jamie Madillc20ab272016-06-09 07:20:46 -07003633void Context::activeTexture(GLenum texture)
3634{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003635 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003636}
3637
Jamie Madill876429b2017-04-20 15:46:24 -04003638void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003639{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003640 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003641}
3642
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003643void Context::blendEquation(GLenum mode)
3644{
3645 mGLState.setBlendEquation(mode, mode);
3646}
3647
Jamie Madillc20ab272016-06-09 07:20:46 -07003648void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3649{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003650 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003651}
3652
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003653void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3654{
3655 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3656}
3657
Jamie Madillc20ab272016-06-09 07:20:46 -07003658void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3659{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003660 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003661}
3662
Jamie Madill876429b2017-04-20 15:46:24 -04003663void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003664{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003665 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003666}
3667
Jamie Madill876429b2017-04-20 15:46:24 -04003668void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003669{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003670 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003671}
3672
3673void Context::clearStencil(GLint s)
3674{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003675 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003676}
3677
3678void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3679{
Geoff Lang92019432017-11-20 13:09:34 -05003680 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
3681 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003682}
3683
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003684void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003685{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003686 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003687}
3688
3689void Context::depthFunc(GLenum func)
3690{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003691 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003692}
3693
3694void Context::depthMask(GLboolean flag)
3695{
Geoff Lang92019432017-11-20 13:09:34 -05003696 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07003697}
3698
Jamie Madill876429b2017-04-20 15:46:24 -04003699void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003700{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003701 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003702}
3703
3704void Context::disable(GLenum cap)
3705{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003706 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003707}
3708
3709void Context::disableVertexAttribArray(GLuint index)
3710{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003711 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003712}
3713
3714void Context::enable(GLenum cap)
3715{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003716 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003717}
3718
3719void Context::enableVertexAttribArray(GLuint index)
3720{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003721 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003722}
3723
3724void Context::frontFace(GLenum mode)
3725{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003726 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003727}
3728
3729void Context::hint(GLenum target, GLenum mode)
3730{
3731 switch (target)
3732 {
3733 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003734 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003735 break;
3736
3737 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003738 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003739 break;
3740
3741 default:
3742 UNREACHABLE();
3743 return;
3744 }
3745}
3746
3747void Context::lineWidth(GLfloat width)
3748{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003749 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003750}
3751
3752void Context::pixelStorei(GLenum pname, GLint param)
3753{
3754 switch (pname)
3755 {
3756 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003757 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003758 break;
3759
3760 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003761 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003762 break;
3763
3764 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003765 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003766 break;
3767
3768 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003769 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003770 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003771 break;
3772
3773 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003774 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003775 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003776 break;
3777
3778 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003779 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003780 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003781 break;
3782
3783 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003784 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003785 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003786 break;
3787
3788 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003789 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003790 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003791 break;
3792
3793 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003794 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003795 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003796 break;
3797
3798 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003799 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003800 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003801 break;
3802
3803 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003804 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003805 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003806 break;
3807
3808 default:
3809 UNREACHABLE();
3810 return;
3811 }
3812}
3813
3814void Context::polygonOffset(GLfloat factor, GLfloat units)
3815{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003816 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003817}
3818
Jamie Madill876429b2017-04-20 15:46:24 -04003819void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003820{
Geoff Lang92019432017-11-20 13:09:34 -05003821 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07003822}
3823
Jiawei Shaodb342272017-09-27 10:21:45 +08003824void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3825{
3826 mGLState.setSampleMaskParams(maskNumber, mask);
3827}
3828
Jamie Madillc20ab272016-06-09 07:20:46 -07003829void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3830{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003831 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003832}
3833
3834void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3835{
3836 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3837 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003838 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003839 }
3840
3841 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3842 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003843 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003844 }
3845}
3846
3847void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3848{
3849 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3850 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003851 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003852 }
3853
3854 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3855 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003856 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003857 }
3858}
3859
3860void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3861{
3862 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3863 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003864 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003865 }
3866
3867 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3868 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003869 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003870 }
3871}
3872
3873void Context::vertexAttrib1f(GLuint index, GLfloat x)
3874{
3875 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003876 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003877}
3878
3879void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3880{
3881 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003882 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003883}
3884
3885void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3886{
3887 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003888 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003889}
3890
3891void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3892{
3893 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003894 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003895}
3896
3897void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3898{
3899 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003900 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003901}
3902
3903void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3904{
3905 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003906 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003907}
3908
3909void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3910{
3911 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003912 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003913}
3914
3915void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3916{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003917 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003918}
3919
3920void Context::vertexAttribPointer(GLuint index,
3921 GLint size,
3922 GLenum type,
3923 GLboolean normalized,
3924 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003925 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003926{
Corentin Wallez336129f2017-10-17 15:55:40 -04003927 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05003928 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003929}
3930
Shao80957d92017-02-20 21:25:59 +08003931void Context::vertexAttribFormat(GLuint attribIndex,
3932 GLint size,
3933 GLenum type,
3934 GLboolean normalized,
3935 GLuint relativeOffset)
3936{
Geoff Lang92019432017-11-20 13:09:34 -05003937 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08003938 relativeOffset);
3939}
3940
3941void Context::vertexAttribIFormat(GLuint attribIndex,
3942 GLint size,
3943 GLenum type,
3944 GLuint relativeOffset)
3945{
3946 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3947}
3948
3949void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3950{
Shaodde78e82017-05-22 14:13:27 +08003951 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08003952}
3953
Jiajia Qin5451d532017-11-16 17:16:34 +08003954void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08003955{
3956 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3957}
3958
Jamie Madillc20ab272016-06-09 07:20:46 -07003959void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3960{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003961 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003962}
3963
3964void Context::vertexAttribIPointer(GLuint index,
3965 GLint size,
3966 GLenum type,
3967 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003968 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003969{
Corentin Wallez336129f2017-10-17 15:55:40 -04003970 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
3971 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003972}
3973
3974void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3975{
3976 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003977 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003978}
3979
3980void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
3981{
3982 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003983 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003984}
3985
3986void Context::vertexAttribI4iv(GLuint index, const GLint *v)
3987{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003988 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003989}
3990
3991void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
3992{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003993 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003994}
3995
Jiawei-Shao2597fb62016-12-09 16:38:02 +08003996void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
3997{
3998 const VertexAttribCurrentValueData &currentValues =
3999 getGLState().getVertexAttribCurrentValue(index);
4000 const VertexArray *vao = getGLState().getVertexArray();
4001 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4002 currentValues, pname, params);
4003}
4004
4005void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4006{
4007 const VertexAttribCurrentValueData &currentValues =
4008 getGLState().getVertexAttribCurrentValue(index);
4009 const VertexArray *vao = getGLState().getVertexArray();
4010 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4011 currentValues, pname, params);
4012}
4013
4014void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4015{
4016 const VertexAttribCurrentValueData &currentValues =
4017 getGLState().getVertexAttribCurrentValue(index);
4018 const VertexArray *vao = getGLState().getVertexArray();
4019 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4020 currentValues, pname, params);
4021}
4022
4023void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4024{
4025 const VertexAttribCurrentValueData &currentValues =
4026 getGLState().getVertexAttribCurrentValue(index);
4027 const VertexArray *vao = getGLState().getVertexArray();
4028 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4029 currentValues, pname, params);
4030}
4031
Jamie Madill876429b2017-04-20 15:46:24 -04004032void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004033{
4034 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4035 QueryVertexAttribPointerv(attrib, pname, pointer);
4036}
4037
Jamie Madillc20ab272016-06-09 07:20:46 -07004038void Context::debugMessageControl(GLenum source,
4039 GLenum type,
4040 GLenum severity,
4041 GLsizei count,
4042 const GLuint *ids,
4043 GLboolean enabled)
4044{
4045 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004046 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004047 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004048}
4049
4050void Context::debugMessageInsert(GLenum source,
4051 GLenum type,
4052 GLuint id,
4053 GLenum severity,
4054 GLsizei length,
4055 const GLchar *buf)
4056{
4057 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004058 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004059}
4060
4061void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4062{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004063 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004064}
4065
4066GLuint Context::getDebugMessageLog(GLuint count,
4067 GLsizei bufSize,
4068 GLenum *sources,
4069 GLenum *types,
4070 GLuint *ids,
4071 GLenum *severities,
4072 GLsizei *lengths,
4073 GLchar *messageLog)
4074{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004075 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4076 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004077}
4078
4079void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4080{
4081 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004082 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004083 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004084}
4085
4086void Context::popDebugGroup()
4087{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004088 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004089 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004090}
4091
Corentin Wallez336129f2017-10-17 15:55:40 -04004092void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004093{
4094 Buffer *buffer = mGLState.getTargetBuffer(target);
4095 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004096 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004097}
4098
Corentin Wallez336129f2017-10-17 15:55:40 -04004099void Context::bufferSubData(BufferBinding target,
4100 GLintptr offset,
4101 GLsizeiptr size,
4102 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004103{
4104 if (data == nullptr)
4105 {
4106 return;
4107 }
4108
4109 Buffer *buffer = mGLState.getTargetBuffer(target);
4110 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004111 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004112}
4113
Jamie Madillef300b12016-10-07 15:12:09 -04004114void Context::attachShader(GLuint program, GLuint shader)
4115{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004116 Program *programObject = mState.mShaderPrograms->getProgram(program);
4117 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004118 ASSERT(programObject && shaderObject);
4119 programObject->attachShader(shaderObject);
4120}
4121
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004122const Workarounds &Context::getWorkarounds() const
4123{
4124 return mWorkarounds;
4125}
4126
Corentin Wallez336129f2017-10-17 15:55:40 -04004127void Context::copyBufferSubData(BufferBinding readTarget,
4128 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004129 GLintptr readOffset,
4130 GLintptr writeOffset,
4131 GLsizeiptr size)
4132{
4133 // if size is zero, the copy is a successful no-op
4134 if (size == 0)
4135 {
4136 return;
4137 }
4138
4139 // TODO(jmadill): cache these.
4140 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4141 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4142
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004143 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004144}
4145
Jamie Madill01a80ee2016-11-07 12:06:18 -05004146void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4147{
4148 Program *programObject = getProgram(program);
4149 // TODO(jmadill): Re-use this from the validation if possible.
4150 ASSERT(programObject);
4151 programObject->bindAttributeLocation(index, name);
4152}
4153
Corentin Wallez336129f2017-10-17 15:55:40 -04004154void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004155{
Corentin Wallez336129f2017-10-17 15:55:40 -04004156 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4157 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004158}
4159
Corentin Wallez336129f2017-10-17 15:55:40 -04004160void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004161{
4162 bindBufferRange(target, index, buffer, 0, 0);
4163}
4164
Corentin Wallez336129f2017-10-17 15:55:40 -04004165void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004166 GLuint index,
4167 GLuint buffer,
4168 GLintptr offset,
4169 GLsizeiptr size)
4170{
Corentin Wallez336129f2017-10-17 15:55:40 -04004171 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4172 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004173}
4174
Jamie Madill01a80ee2016-11-07 12:06:18 -05004175void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4176{
4177 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4178 {
4179 bindReadFramebuffer(framebuffer);
4180 }
4181
4182 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4183 {
4184 bindDrawFramebuffer(framebuffer);
4185 }
4186}
4187
4188void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4189{
4190 ASSERT(target == GL_RENDERBUFFER);
4191 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004192 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004193 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004194}
4195
JiangYizhoubddc46b2016-12-09 09:50:51 +08004196void Context::texStorage2DMultisample(GLenum target,
4197 GLsizei samples,
4198 GLenum internalformat,
4199 GLsizei width,
4200 GLsizei height,
4201 GLboolean fixedsamplelocations)
4202{
4203 Extents size(width, height, 1);
4204 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004205 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
Geoff Lang92019432017-11-20 13:09:34 -05004206 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004207}
4208
4209void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4210{
JiangYizhou5b03f472017-01-09 10:22:53 +08004211 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4212 // the sample position should be queried by DRAW_FRAMEBUFFER.
4213 mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER);
4214 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004215
4216 switch (pname)
4217 {
4218 case GL_SAMPLE_POSITION:
4219 handleError(framebuffer->getSamplePosition(index, val));
4220 break;
4221 default:
4222 UNREACHABLE();
4223 }
4224}
4225
Jamie Madille8fb6402017-02-14 17:56:40 -05004226void Context::renderbufferStorage(GLenum target,
4227 GLenum internalformat,
4228 GLsizei width,
4229 GLsizei height)
4230{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004231 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4232 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4233
Jamie Madille8fb6402017-02-14 17:56:40 -05004234 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004235 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004236}
4237
4238void Context::renderbufferStorageMultisample(GLenum target,
4239 GLsizei samples,
4240 GLenum internalformat,
4241 GLsizei width,
4242 GLsizei height)
4243{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004244 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4245 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004246
4247 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004248 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004249 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004250}
4251
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004252void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4253{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004254 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004255 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004256}
4257
JiangYizhoue18e6392017-02-20 10:32:23 +08004258void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4259{
4260 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4261 QueryFramebufferParameteriv(framebuffer, pname, params);
4262}
4263
Jiajia Qin5451d532017-11-16 17:16:34 +08004264void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004265{
4266 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4267 SetFramebufferParameteri(framebuffer, pname, param);
4268}
4269
Jamie Madillb3f26b92017-07-19 15:07:41 -04004270Error Context::getScratchBuffer(size_t requstedSizeBytes,
4271 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004272{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004273 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4274 {
4275 return OutOfMemory() << "Failed to allocate internal buffer.";
4276 }
4277 return NoError();
4278}
4279
4280Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4281 angle::MemoryBuffer **zeroBufferOut) const
4282{
4283 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004284 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004285 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004286 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004287 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004288}
4289
Xinghua Cao10a4d432017-11-28 14:46:26 +08004290Error Context::prepareForDispatch()
4291{
4292 syncRendererState(mComputeDirtyBits, mComputeDirtyObjects);
4293
4294 if (isRobustResourceInitEnabled())
4295 {
4296 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4297 }
4298
4299 return NoError();
4300}
4301
Xinghua Cao2b396592017-03-29 15:36:04 +08004302void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4303{
4304 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4305 {
4306 return;
4307 }
4308
Xinghua Cao10a4d432017-11-28 14:46:26 +08004309 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004310 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004311}
4312
Jiajia Qin5451d532017-11-16 17:16:34 +08004313void Context::dispatchComputeIndirect(GLintptr indirect)
4314{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004315 ANGLE_CONTEXT_TRY(prepareForDispatch());
4316 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004317}
4318
JiangYizhou165361c2017-06-07 14:56:57 +08004319void Context::texStorage2D(GLenum target,
4320 GLsizei levels,
4321 GLenum internalFormat,
4322 GLsizei width,
4323 GLsizei height)
4324{
4325 Extents size(width, height, 1);
4326 Texture *texture = getTargetTexture(target);
4327 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4328}
4329
4330void Context::texStorage3D(GLenum target,
4331 GLsizei levels,
4332 GLenum internalFormat,
4333 GLsizei width,
4334 GLsizei height,
4335 GLsizei depth)
4336{
4337 Extents size(width, height, depth);
4338 Texture *texture = getTargetTexture(target);
4339 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4340}
4341
Jiajia Qin5451d532017-11-16 17:16:34 +08004342void Context::memoryBarrier(GLbitfield barriers)
4343{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004344 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004345}
4346
4347void Context::memoryBarrierByRegion(GLbitfield barriers)
4348{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004349 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004350}
4351
Jamie Madillc1d770e2017-04-13 17:31:24 -04004352GLenum Context::checkFramebufferStatus(GLenum target)
4353{
4354 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4355 ASSERT(framebuffer);
4356
4357 return framebuffer->checkStatus(this);
4358}
4359
4360void Context::compileShader(GLuint shader)
4361{
4362 Shader *shaderObject = GetValidShader(this, shader);
4363 if (!shaderObject)
4364 {
4365 return;
4366 }
4367 shaderObject->compile(this);
4368}
4369
4370void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4371{
4372 for (int i = 0; i < n; i++)
4373 {
4374 deleteBuffer(buffers[i]);
4375 }
4376}
4377
4378void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4379{
4380 for (int i = 0; i < n; i++)
4381 {
4382 if (framebuffers[i] != 0)
4383 {
4384 deleteFramebuffer(framebuffers[i]);
4385 }
4386 }
4387}
4388
4389void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4390{
4391 for (int i = 0; i < n; i++)
4392 {
4393 deleteRenderbuffer(renderbuffers[i]);
4394 }
4395}
4396
4397void Context::deleteTextures(GLsizei n, const GLuint *textures)
4398{
4399 for (int i = 0; i < n; i++)
4400 {
4401 if (textures[i] != 0)
4402 {
4403 deleteTexture(textures[i]);
4404 }
4405 }
4406}
4407
4408void Context::detachShader(GLuint program, GLuint shader)
4409{
4410 Program *programObject = getProgram(program);
4411 ASSERT(programObject);
4412
4413 Shader *shaderObject = getShader(shader);
4414 ASSERT(shaderObject);
4415
4416 programObject->detachShader(this, shaderObject);
4417}
4418
4419void Context::genBuffers(GLsizei n, GLuint *buffers)
4420{
4421 for (int i = 0; i < n; i++)
4422 {
4423 buffers[i] = createBuffer();
4424 }
4425}
4426
4427void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4428{
4429 for (int i = 0; i < n; i++)
4430 {
4431 framebuffers[i] = createFramebuffer();
4432 }
4433}
4434
4435void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4436{
4437 for (int i = 0; i < n; i++)
4438 {
4439 renderbuffers[i] = createRenderbuffer();
4440 }
4441}
4442
4443void Context::genTextures(GLsizei n, GLuint *textures)
4444{
4445 for (int i = 0; i < n; i++)
4446 {
4447 textures[i] = createTexture();
4448 }
4449}
4450
4451void Context::getActiveAttrib(GLuint program,
4452 GLuint index,
4453 GLsizei bufsize,
4454 GLsizei *length,
4455 GLint *size,
4456 GLenum *type,
4457 GLchar *name)
4458{
4459 Program *programObject = getProgram(program);
4460 ASSERT(programObject);
4461 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4462}
4463
4464void Context::getActiveUniform(GLuint program,
4465 GLuint index,
4466 GLsizei bufsize,
4467 GLsizei *length,
4468 GLint *size,
4469 GLenum *type,
4470 GLchar *name)
4471{
4472 Program *programObject = getProgram(program);
4473 ASSERT(programObject);
4474 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4475}
4476
4477void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4478{
4479 Program *programObject = getProgram(program);
4480 ASSERT(programObject);
4481 programObject->getAttachedShaders(maxcount, count, shaders);
4482}
4483
4484GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4485{
4486 Program *programObject = getProgram(program);
4487 ASSERT(programObject);
4488 return programObject->getAttributeLocation(name);
4489}
4490
4491void Context::getBooleanv(GLenum pname, GLboolean *params)
4492{
4493 GLenum nativeType;
4494 unsigned int numParams = 0;
4495 getQueryParameterInfo(pname, &nativeType, &numParams);
4496
4497 if (nativeType == GL_BOOL)
4498 {
4499 getBooleanvImpl(pname, params);
4500 }
4501 else
4502 {
4503 CastStateValues(this, nativeType, pname, numParams, params);
4504 }
4505}
4506
4507void Context::getFloatv(GLenum pname, GLfloat *params)
4508{
4509 GLenum nativeType;
4510 unsigned int numParams = 0;
4511 getQueryParameterInfo(pname, &nativeType, &numParams);
4512
4513 if (nativeType == GL_FLOAT)
4514 {
4515 getFloatvImpl(pname, params);
4516 }
4517 else
4518 {
4519 CastStateValues(this, nativeType, pname, numParams, params);
4520 }
4521}
4522
4523void Context::getIntegerv(GLenum pname, GLint *params)
4524{
4525 GLenum nativeType;
4526 unsigned int numParams = 0;
4527 getQueryParameterInfo(pname, &nativeType, &numParams);
4528
4529 if (nativeType == GL_INT)
4530 {
4531 getIntegervImpl(pname, params);
4532 }
4533 else
4534 {
4535 CastStateValues(this, nativeType, pname, numParams, params);
4536 }
4537}
4538
4539void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4540{
4541 Program *programObject = getProgram(program);
4542 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004543 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004544}
4545
Jiajia Qin5451d532017-11-16 17:16:34 +08004546void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
4547{
4548 UNIMPLEMENTED();
4549}
4550
Jamie Madillbe849e42017-05-02 15:49:00 -04004551void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004552{
4553 Program *programObject = getProgram(program);
4554 ASSERT(programObject);
4555 programObject->getInfoLog(bufsize, length, infolog);
4556}
4557
Jiajia Qin5451d532017-11-16 17:16:34 +08004558void Context::getProgramPipelineInfoLog(GLuint pipeline,
4559 GLsizei bufSize,
4560 GLsizei *length,
4561 GLchar *infoLog)
4562{
4563 UNIMPLEMENTED();
4564}
4565
Jamie Madillc1d770e2017-04-13 17:31:24 -04004566void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4567{
4568 Shader *shaderObject = getShader(shader);
4569 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004570 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004571}
4572
4573void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4574{
4575 Shader *shaderObject = getShader(shader);
4576 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004577 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004578}
4579
4580void Context::getShaderPrecisionFormat(GLenum shadertype,
4581 GLenum precisiontype,
4582 GLint *range,
4583 GLint *precision)
4584{
4585 // TODO(jmadill): Compute shaders.
4586
4587 switch (shadertype)
4588 {
4589 case GL_VERTEX_SHADER:
4590 switch (precisiontype)
4591 {
4592 case GL_LOW_FLOAT:
4593 mCaps.vertexLowpFloat.get(range, precision);
4594 break;
4595 case GL_MEDIUM_FLOAT:
4596 mCaps.vertexMediumpFloat.get(range, precision);
4597 break;
4598 case GL_HIGH_FLOAT:
4599 mCaps.vertexHighpFloat.get(range, precision);
4600 break;
4601
4602 case GL_LOW_INT:
4603 mCaps.vertexLowpInt.get(range, precision);
4604 break;
4605 case GL_MEDIUM_INT:
4606 mCaps.vertexMediumpInt.get(range, precision);
4607 break;
4608 case GL_HIGH_INT:
4609 mCaps.vertexHighpInt.get(range, precision);
4610 break;
4611
4612 default:
4613 UNREACHABLE();
4614 return;
4615 }
4616 break;
4617
4618 case GL_FRAGMENT_SHADER:
4619 switch (precisiontype)
4620 {
4621 case GL_LOW_FLOAT:
4622 mCaps.fragmentLowpFloat.get(range, precision);
4623 break;
4624 case GL_MEDIUM_FLOAT:
4625 mCaps.fragmentMediumpFloat.get(range, precision);
4626 break;
4627 case GL_HIGH_FLOAT:
4628 mCaps.fragmentHighpFloat.get(range, precision);
4629 break;
4630
4631 case GL_LOW_INT:
4632 mCaps.fragmentLowpInt.get(range, precision);
4633 break;
4634 case GL_MEDIUM_INT:
4635 mCaps.fragmentMediumpInt.get(range, precision);
4636 break;
4637 case GL_HIGH_INT:
4638 mCaps.fragmentHighpInt.get(range, precision);
4639 break;
4640
4641 default:
4642 UNREACHABLE();
4643 return;
4644 }
4645 break;
4646
4647 default:
4648 UNREACHABLE();
4649 return;
4650 }
4651}
4652
4653void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4654{
4655 Shader *shaderObject = getShader(shader);
4656 ASSERT(shaderObject);
4657 shaderObject->getSource(bufsize, length, source);
4658}
4659
4660void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4661{
4662 Program *programObject = getProgram(program);
4663 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004664 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004665}
4666
4667void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4668{
4669 Program *programObject = getProgram(program);
4670 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004671 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004672}
4673
4674GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4675{
4676 Program *programObject = getProgram(program);
4677 ASSERT(programObject);
4678 return programObject->getUniformLocation(name);
4679}
4680
4681GLboolean Context::isBuffer(GLuint buffer)
4682{
4683 if (buffer == 0)
4684 {
4685 return GL_FALSE;
4686 }
4687
4688 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4689}
4690
4691GLboolean Context::isEnabled(GLenum cap)
4692{
4693 return mGLState.getEnableFeature(cap);
4694}
4695
4696GLboolean Context::isFramebuffer(GLuint framebuffer)
4697{
4698 if (framebuffer == 0)
4699 {
4700 return GL_FALSE;
4701 }
4702
4703 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4704}
4705
4706GLboolean Context::isProgram(GLuint program)
4707{
4708 if (program == 0)
4709 {
4710 return GL_FALSE;
4711 }
4712
4713 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4714}
4715
4716GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4717{
4718 if (renderbuffer == 0)
4719 {
4720 return GL_FALSE;
4721 }
4722
4723 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4724}
4725
4726GLboolean Context::isShader(GLuint shader)
4727{
4728 if (shader == 0)
4729 {
4730 return GL_FALSE;
4731 }
4732
4733 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4734}
4735
4736GLboolean Context::isTexture(GLuint texture)
4737{
4738 if (texture == 0)
4739 {
4740 return GL_FALSE;
4741 }
4742
4743 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4744}
4745
4746void Context::linkProgram(GLuint program)
4747{
4748 Program *programObject = getProgram(program);
4749 ASSERT(programObject);
4750 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004751 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004752}
4753
4754void Context::releaseShaderCompiler()
4755{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004756 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004757}
4758
4759void Context::shaderBinary(GLsizei n,
4760 const GLuint *shaders,
4761 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004762 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004763 GLsizei length)
4764{
4765 // No binary shader formats are supported.
4766 UNIMPLEMENTED();
4767}
4768
4769void Context::shaderSource(GLuint shader,
4770 GLsizei count,
4771 const GLchar *const *string,
4772 const GLint *length)
4773{
4774 Shader *shaderObject = getShader(shader);
4775 ASSERT(shaderObject);
4776 shaderObject->setSource(count, string, length);
4777}
4778
4779void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4780{
4781 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4782}
4783
4784void Context::stencilMask(GLuint mask)
4785{
4786 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4787}
4788
4789void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4790{
4791 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4792}
4793
4794void Context::uniform1f(GLint location, GLfloat x)
4795{
4796 Program *program = mGLState.getProgram();
4797 program->setUniform1fv(location, 1, &x);
4798}
4799
4800void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4801{
4802 Program *program = mGLState.getProgram();
4803 program->setUniform1fv(location, count, v);
4804}
4805
4806void Context::uniform1i(GLint location, GLint x)
4807{
4808 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004809 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4810 {
4811 mGLState.setObjectDirty(GL_PROGRAM);
4812 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004813}
4814
4815void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4816{
4817 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004818 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4819 {
4820 mGLState.setObjectDirty(GL_PROGRAM);
4821 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004822}
4823
4824void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4825{
4826 GLfloat xy[2] = {x, y};
4827 Program *program = mGLState.getProgram();
4828 program->setUniform2fv(location, 1, xy);
4829}
4830
4831void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4832{
4833 Program *program = mGLState.getProgram();
4834 program->setUniform2fv(location, count, v);
4835}
4836
4837void Context::uniform2i(GLint location, GLint x, GLint y)
4838{
4839 GLint xy[2] = {x, y};
4840 Program *program = mGLState.getProgram();
4841 program->setUniform2iv(location, 1, xy);
4842}
4843
4844void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4845{
4846 Program *program = mGLState.getProgram();
4847 program->setUniform2iv(location, count, v);
4848}
4849
4850void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4851{
4852 GLfloat xyz[3] = {x, y, z};
4853 Program *program = mGLState.getProgram();
4854 program->setUniform3fv(location, 1, xyz);
4855}
4856
4857void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4858{
4859 Program *program = mGLState.getProgram();
4860 program->setUniform3fv(location, count, v);
4861}
4862
4863void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4864{
4865 GLint xyz[3] = {x, y, z};
4866 Program *program = mGLState.getProgram();
4867 program->setUniform3iv(location, 1, xyz);
4868}
4869
4870void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4871{
4872 Program *program = mGLState.getProgram();
4873 program->setUniform3iv(location, count, v);
4874}
4875
4876void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4877{
4878 GLfloat xyzw[4] = {x, y, z, w};
4879 Program *program = mGLState.getProgram();
4880 program->setUniform4fv(location, 1, xyzw);
4881}
4882
4883void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4884{
4885 Program *program = mGLState.getProgram();
4886 program->setUniform4fv(location, count, v);
4887}
4888
4889void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4890{
4891 GLint xyzw[4] = {x, y, z, w};
4892 Program *program = mGLState.getProgram();
4893 program->setUniform4iv(location, 1, xyzw);
4894}
4895
4896void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4897{
4898 Program *program = mGLState.getProgram();
4899 program->setUniform4iv(location, count, v);
4900}
4901
4902void Context::uniformMatrix2fv(GLint location,
4903 GLsizei count,
4904 GLboolean transpose,
4905 const GLfloat *value)
4906{
4907 Program *program = mGLState.getProgram();
4908 program->setUniformMatrix2fv(location, count, transpose, value);
4909}
4910
4911void Context::uniformMatrix3fv(GLint location,
4912 GLsizei count,
4913 GLboolean transpose,
4914 const GLfloat *value)
4915{
4916 Program *program = mGLState.getProgram();
4917 program->setUniformMatrix3fv(location, count, transpose, value);
4918}
4919
4920void Context::uniformMatrix4fv(GLint location,
4921 GLsizei count,
4922 GLboolean transpose,
4923 const GLfloat *value)
4924{
4925 Program *program = mGLState.getProgram();
4926 program->setUniformMatrix4fv(location, count, transpose, value);
4927}
4928
4929void Context::validateProgram(GLuint program)
4930{
4931 Program *programObject = getProgram(program);
4932 ASSERT(programObject);
4933 programObject->validate(mCaps);
4934}
4935
Jiajia Qin5451d532017-11-16 17:16:34 +08004936void Context::validateProgramPipeline(GLuint pipeline)
4937{
4938 UNIMPLEMENTED();
4939}
4940
Jamie Madilld04908b2017-06-09 14:15:35 -04004941void Context::getProgramBinary(GLuint program,
4942 GLsizei bufSize,
4943 GLsizei *length,
4944 GLenum *binaryFormat,
4945 void *binary)
4946{
4947 Program *programObject = getProgram(program);
4948 ASSERT(programObject != nullptr);
4949
4950 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4951}
4952
4953void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4954{
4955 Program *programObject = getProgram(program);
4956 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04004957
Jamie Madilld04908b2017-06-09 14:15:35 -04004958 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
4959}
4960
Jamie Madillff325f12017-08-26 15:06:05 -04004961void Context::uniform1ui(GLint location, GLuint v0)
4962{
4963 Program *program = mGLState.getProgram();
4964 program->setUniform1uiv(location, 1, &v0);
4965}
4966
4967void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
4968{
4969 Program *program = mGLState.getProgram();
4970 const GLuint xy[] = {v0, v1};
4971 program->setUniform2uiv(location, 1, xy);
4972}
4973
4974void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
4975{
4976 Program *program = mGLState.getProgram();
4977 const GLuint xyz[] = {v0, v1, v2};
4978 program->setUniform3uiv(location, 1, xyz);
4979}
4980
4981void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
4982{
4983 Program *program = mGLState.getProgram();
4984 const GLuint xyzw[] = {v0, v1, v2, v3};
4985 program->setUniform4uiv(location, 1, xyzw);
4986}
4987
4988void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
4989{
4990 Program *program = mGLState.getProgram();
4991 program->setUniform1uiv(location, count, value);
4992}
4993void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
4994{
4995 Program *program = mGLState.getProgram();
4996 program->setUniform2uiv(location, count, value);
4997}
4998
4999void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5000{
5001 Program *program = mGLState.getProgram();
5002 program->setUniform3uiv(location, count, value);
5003}
5004
5005void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5006{
5007 Program *program = mGLState.getProgram();
5008 program->setUniform4uiv(location, count, value);
5009}
5010
Jamie Madillf0e04492017-08-26 15:28:42 -04005011void Context::genQueries(GLsizei n, GLuint *ids)
5012{
5013 for (GLsizei i = 0; i < n; i++)
5014 {
5015 GLuint handle = mQueryHandleAllocator.allocate();
5016 mQueryMap.assign(handle, nullptr);
5017 ids[i] = handle;
5018 }
5019}
5020
5021void Context::deleteQueries(GLsizei n, const GLuint *ids)
5022{
5023 for (int i = 0; i < n; i++)
5024 {
5025 GLuint query = ids[i];
5026
5027 Query *queryObject = nullptr;
5028 if (mQueryMap.erase(query, &queryObject))
5029 {
5030 mQueryHandleAllocator.release(query);
5031 if (queryObject)
5032 {
5033 queryObject->release(this);
5034 }
5035 }
5036 }
5037}
5038
5039GLboolean Context::isQuery(GLuint id)
5040{
5041 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
5042}
5043
Jamie Madillc8c95812017-08-26 18:40:09 -04005044void Context::uniformMatrix2x3fv(GLint location,
5045 GLsizei count,
5046 GLboolean transpose,
5047 const GLfloat *value)
5048{
5049 Program *program = mGLState.getProgram();
5050 program->setUniformMatrix2x3fv(location, count, transpose, value);
5051}
5052
5053void Context::uniformMatrix3x2fv(GLint location,
5054 GLsizei count,
5055 GLboolean transpose,
5056 const GLfloat *value)
5057{
5058 Program *program = mGLState.getProgram();
5059 program->setUniformMatrix3x2fv(location, count, transpose, value);
5060}
5061
5062void Context::uniformMatrix2x4fv(GLint location,
5063 GLsizei count,
5064 GLboolean transpose,
5065 const GLfloat *value)
5066{
5067 Program *program = mGLState.getProgram();
5068 program->setUniformMatrix2x4fv(location, count, transpose, value);
5069}
5070
5071void Context::uniformMatrix4x2fv(GLint location,
5072 GLsizei count,
5073 GLboolean transpose,
5074 const GLfloat *value)
5075{
5076 Program *program = mGLState.getProgram();
5077 program->setUniformMatrix4x2fv(location, count, transpose, value);
5078}
5079
5080void Context::uniformMatrix3x4fv(GLint location,
5081 GLsizei count,
5082 GLboolean transpose,
5083 const GLfloat *value)
5084{
5085 Program *program = mGLState.getProgram();
5086 program->setUniformMatrix3x4fv(location, count, transpose, value);
5087}
5088
5089void Context::uniformMatrix4x3fv(GLint location,
5090 GLsizei count,
5091 GLboolean transpose,
5092 const GLfloat *value)
5093{
5094 Program *program = mGLState.getProgram();
5095 program->setUniformMatrix4x3fv(location, count, transpose, value);
5096}
5097
Jamie Madilld7576732017-08-26 18:49:50 -04005098void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5099{
5100 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5101 {
5102 GLuint vertexArray = arrays[arrayIndex];
5103
5104 if (arrays[arrayIndex] != 0)
5105 {
5106 VertexArray *vertexArrayObject = nullptr;
5107 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5108 {
5109 if (vertexArrayObject != nullptr)
5110 {
5111 detachVertexArray(vertexArray);
5112 vertexArrayObject->onDestroy(this);
5113 }
5114
5115 mVertexArrayHandleAllocator.release(vertexArray);
5116 }
5117 }
5118 }
5119}
5120
5121void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5122{
5123 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5124 {
5125 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5126 mVertexArrayMap.assign(vertexArray, nullptr);
5127 arrays[arrayIndex] = vertexArray;
5128 }
5129}
5130
5131bool Context::isVertexArray(GLuint array)
5132{
5133 if (array == 0)
5134 {
5135 return GL_FALSE;
5136 }
5137
5138 VertexArray *vao = getVertexArray(array);
5139 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5140}
5141
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005142void Context::endTransformFeedback()
5143{
5144 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5145 transformFeedback->end(this);
5146}
5147
5148void Context::transformFeedbackVaryings(GLuint program,
5149 GLsizei count,
5150 const GLchar *const *varyings,
5151 GLenum bufferMode)
5152{
5153 Program *programObject = getProgram(program);
5154 ASSERT(programObject);
5155 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5156}
5157
5158void Context::getTransformFeedbackVarying(GLuint program,
5159 GLuint index,
5160 GLsizei bufSize,
5161 GLsizei *length,
5162 GLsizei *size,
5163 GLenum *type,
5164 GLchar *name)
5165{
5166 Program *programObject = getProgram(program);
5167 ASSERT(programObject);
5168 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5169}
5170
5171void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5172{
5173 for (int i = 0; i < n; i++)
5174 {
5175 GLuint transformFeedback = ids[i];
5176 if (transformFeedback == 0)
5177 {
5178 continue;
5179 }
5180
5181 TransformFeedback *transformFeedbackObject = nullptr;
5182 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5183 {
5184 if (transformFeedbackObject != nullptr)
5185 {
5186 detachTransformFeedback(transformFeedback);
5187 transformFeedbackObject->release(this);
5188 }
5189
5190 mTransformFeedbackHandleAllocator.release(transformFeedback);
5191 }
5192 }
5193}
5194
5195void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5196{
5197 for (int i = 0; i < n; i++)
5198 {
5199 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5200 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5201 ids[i] = transformFeedback;
5202 }
5203}
5204
5205bool Context::isTransformFeedback(GLuint id)
5206{
5207 if (id == 0)
5208 {
5209 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5210 // returns FALSE
5211 return GL_FALSE;
5212 }
5213
5214 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5215 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5216}
5217
5218void Context::pauseTransformFeedback()
5219{
5220 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5221 transformFeedback->pause();
5222}
5223
5224void Context::resumeTransformFeedback()
5225{
5226 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5227 transformFeedback->resume();
5228}
5229
Jamie Madill12e957f2017-08-26 21:42:26 -04005230void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5231{
5232 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005233 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005234}
5235
5236GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5237{
5238 const Program *programObject = getProgram(program);
5239 return programObject->getFragDataLocation(name);
5240}
5241
5242void Context::getUniformIndices(GLuint program,
5243 GLsizei uniformCount,
5244 const GLchar *const *uniformNames,
5245 GLuint *uniformIndices)
5246{
5247 const Program *programObject = getProgram(program);
5248 if (!programObject->isLinked())
5249 {
5250 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5251 {
5252 uniformIndices[uniformId] = GL_INVALID_INDEX;
5253 }
5254 }
5255 else
5256 {
5257 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5258 {
5259 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5260 }
5261 }
5262}
5263
5264void Context::getActiveUniformsiv(GLuint program,
5265 GLsizei uniformCount,
5266 const GLuint *uniformIndices,
5267 GLenum pname,
5268 GLint *params)
5269{
5270 const Program *programObject = getProgram(program);
5271 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5272 {
5273 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005274 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005275 }
5276}
5277
5278GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5279{
5280 const Program *programObject = getProgram(program);
5281 return programObject->getUniformBlockIndex(uniformBlockName);
5282}
5283
5284void Context::getActiveUniformBlockiv(GLuint program,
5285 GLuint uniformBlockIndex,
5286 GLenum pname,
5287 GLint *params)
5288{
5289 const Program *programObject = getProgram(program);
5290 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5291}
5292
5293void Context::getActiveUniformBlockName(GLuint program,
5294 GLuint uniformBlockIndex,
5295 GLsizei bufSize,
5296 GLsizei *length,
5297 GLchar *uniformBlockName)
5298{
5299 const Program *programObject = getProgram(program);
5300 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5301}
5302
5303void Context::uniformBlockBinding(GLuint program,
5304 GLuint uniformBlockIndex,
5305 GLuint uniformBlockBinding)
5306{
5307 Program *programObject = getProgram(program);
5308 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5309}
5310
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005311GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5312{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005313 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5314 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005315
Jamie Madill70b5bb02017-08-28 13:32:37 -04005316 Sync *syncObject = getSync(syncHandle);
5317 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005318 if (error.isError())
5319 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005320 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005321 handleError(error);
5322 return nullptr;
5323 }
5324
Jamie Madill70b5bb02017-08-28 13:32:37 -04005325 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005326}
5327
5328GLboolean Context::isSync(GLsync sync)
5329{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005330 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005331}
5332
5333GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5334{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005335 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005336
5337 GLenum result = GL_WAIT_FAILED;
5338 handleError(syncObject->clientWait(flags, timeout, &result));
5339 return result;
5340}
5341
5342void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5343{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005344 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005345 handleError(syncObject->serverWait(flags, timeout));
5346}
5347
5348void Context::getInteger64v(GLenum pname, GLint64 *params)
5349{
5350 GLenum nativeType = GL_NONE;
5351 unsigned int numParams = 0;
5352 getQueryParameterInfo(pname, &nativeType, &numParams);
5353
5354 if (nativeType == GL_INT_64_ANGLEX)
5355 {
5356 getInteger64vImpl(pname, params);
5357 }
5358 else
5359 {
5360 CastStateValues(this, nativeType, pname, numParams, params);
5361 }
5362}
5363
Corentin Wallez336129f2017-10-17 15:55:40 -04005364void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04005365{
5366 Buffer *buffer = mGLState.getTargetBuffer(target);
5367 QueryBufferParameteri64v(buffer, pname, params);
5368}
5369
5370void Context::genSamplers(GLsizei count, GLuint *samplers)
5371{
5372 for (int i = 0; i < count; i++)
5373 {
5374 samplers[i] = mState.mSamplers->createSampler();
5375 }
5376}
5377
5378void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5379{
5380 for (int i = 0; i < count; i++)
5381 {
5382 GLuint sampler = samplers[i];
5383
5384 if (mState.mSamplers->getSampler(sampler))
5385 {
5386 detachSampler(sampler);
5387 }
5388
5389 mState.mSamplers->deleteObject(this, sampler);
5390 }
5391}
5392
5393void Context::getInternalformativ(GLenum target,
5394 GLenum internalformat,
5395 GLenum pname,
5396 GLsizei bufSize,
5397 GLint *params)
5398{
5399 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5400 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5401}
5402
Jiajia Qin5451d532017-11-16 17:16:34 +08005403void Context::programUniform1i(GLuint program, GLint location, GLint v0)
5404{
5405 programUniform1iv(program, location, 1, &v0);
5406}
5407
5408void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
5409{
5410 GLint xy[2] = {v0, v1};
5411 programUniform2iv(program, location, 1, xy);
5412}
5413
5414void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
5415{
5416 GLint xyz[3] = {v0, v1, v2};
5417 programUniform3iv(program, location, 1, xyz);
5418}
5419
5420void Context::programUniform4i(GLuint program,
5421 GLint location,
5422 GLint v0,
5423 GLint v1,
5424 GLint v2,
5425 GLint v3)
5426{
5427 GLint xyzw[4] = {v0, v1, v2, v3};
5428 programUniform4iv(program, location, 1, xyzw);
5429}
5430
5431void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
5432{
5433 programUniform1uiv(program, location, 1, &v0);
5434}
5435
5436void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
5437{
5438 GLuint xy[2] = {v0, v1};
5439 programUniform2uiv(program, location, 1, xy);
5440}
5441
5442void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
5443{
5444 GLuint xyz[3] = {v0, v1, v2};
5445 programUniform3uiv(program, location, 1, xyz);
5446}
5447
5448void Context::programUniform4ui(GLuint program,
5449 GLint location,
5450 GLuint v0,
5451 GLuint v1,
5452 GLuint v2,
5453 GLuint v3)
5454{
5455 GLuint xyzw[4] = {v0, v1, v2, v3};
5456 programUniform4uiv(program, location, 1, xyzw);
5457}
5458
5459void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
5460{
5461 programUniform1fv(program, location, 1, &v0);
5462}
5463
5464void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
5465{
5466 GLfloat xy[2] = {v0, v1};
5467 programUniform2fv(program, location, 1, xy);
5468}
5469
5470void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
5471{
5472 GLfloat xyz[3] = {v0, v1, v2};
5473 programUniform3fv(program, location, 1, xyz);
5474}
5475
5476void Context::programUniform4f(GLuint program,
5477 GLint location,
5478 GLfloat v0,
5479 GLfloat v1,
5480 GLfloat v2,
5481 GLfloat v3)
5482{
5483 GLfloat xyzw[4] = {v0, v1, v2, v3};
5484 programUniform4fv(program, location, 1, xyzw);
5485}
5486
Jamie Madill81c2e252017-09-09 23:32:46 -04005487void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5488{
5489 Program *programObject = getProgram(program);
5490 ASSERT(programObject);
5491 if (programObject->setUniform1iv(location, count, value) ==
5492 Program::SetUniformResult::SamplerChanged)
5493 {
5494 mGLState.setObjectDirty(GL_PROGRAM);
5495 }
5496}
5497
Jiajia Qin5451d532017-11-16 17:16:34 +08005498void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5499{
5500 Program *programObject = getProgram(program);
5501 ASSERT(programObject);
5502 programObject->setUniform2iv(location, count, value);
5503}
5504
5505void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5506{
5507 Program *programObject = getProgram(program);
5508 ASSERT(programObject);
5509 programObject->setUniform3iv(location, count, value);
5510}
5511
5512void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5513{
5514 Program *programObject = getProgram(program);
5515 ASSERT(programObject);
5516 programObject->setUniform4iv(location, count, value);
5517}
5518
5519void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5520{
5521 Program *programObject = getProgram(program);
5522 ASSERT(programObject);
5523 programObject->setUniform1uiv(location, count, value);
5524}
5525
5526void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5527{
5528 Program *programObject = getProgram(program);
5529 ASSERT(programObject);
5530 programObject->setUniform2uiv(location, count, value);
5531}
5532
5533void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5534{
5535 Program *programObject = getProgram(program);
5536 ASSERT(programObject);
5537 programObject->setUniform3uiv(location, count, value);
5538}
5539
5540void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5541{
5542 Program *programObject = getProgram(program);
5543 ASSERT(programObject);
5544 programObject->setUniform4uiv(location, count, value);
5545}
5546
5547void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5548{
5549 Program *programObject = getProgram(program);
5550 ASSERT(programObject);
5551 programObject->setUniform1fv(location, count, value);
5552}
5553
5554void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5555{
5556 Program *programObject = getProgram(program);
5557 ASSERT(programObject);
5558 programObject->setUniform2fv(location, count, value);
5559}
5560
5561void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5562{
5563 Program *programObject = getProgram(program);
5564 ASSERT(programObject);
5565 programObject->setUniform3fv(location, count, value);
5566}
5567
5568void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5569{
5570 Program *programObject = getProgram(program);
5571 ASSERT(programObject);
5572 programObject->setUniform4fv(location, count, value);
5573}
5574
5575void Context::programUniformMatrix2fv(GLuint program,
5576 GLint location,
5577 GLsizei count,
5578 GLboolean transpose,
5579 const GLfloat *value)
5580{
5581 Program *programObject = getProgram(program);
5582 ASSERT(programObject);
5583 programObject->setUniformMatrix2fv(location, count, transpose, value);
5584}
5585
5586void Context::programUniformMatrix3fv(GLuint program,
5587 GLint location,
5588 GLsizei count,
5589 GLboolean transpose,
5590 const GLfloat *value)
5591{
5592 Program *programObject = getProgram(program);
5593 ASSERT(programObject);
5594 programObject->setUniformMatrix3fv(location, count, transpose, value);
5595}
5596
5597void Context::programUniformMatrix4fv(GLuint program,
5598 GLint location,
5599 GLsizei count,
5600 GLboolean transpose,
5601 const GLfloat *value)
5602{
5603 Program *programObject = getProgram(program);
5604 ASSERT(programObject);
5605 programObject->setUniformMatrix4fv(location, count, transpose, value);
5606}
5607
5608void Context::programUniformMatrix2x3fv(GLuint program,
5609 GLint location,
5610 GLsizei count,
5611 GLboolean transpose,
5612 const GLfloat *value)
5613{
5614 Program *programObject = getProgram(program);
5615 ASSERT(programObject);
5616 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
5617}
5618
5619void Context::programUniformMatrix3x2fv(GLuint program,
5620 GLint location,
5621 GLsizei count,
5622 GLboolean transpose,
5623 const GLfloat *value)
5624{
5625 Program *programObject = getProgram(program);
5626 ASSERT(programObject);
5627 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
5628}
5629
5630void Context::programUniformMatrix2x4fv(GLuint program,
5631 GLint location,
5632 GLsizei count,
5633 GLboolean transpose,
5634 const GLfloat *value)
5635{
5636 Program *programObject = getProgram(program);
5637 ASSERT(programObject);
5638 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
5639}
5640
5641void Context::programUniformMatrix4x2fv(GLuint program,
5642 GLint location,
5643 GLsizei count,
5644 GLboolean transpose,
5645 const GLfloat *value)
5646{
5647 Program *programObject = getProgram(program);
5648 ASSERT(programObject);
5649 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
5650}
5651
5652void Context::programUniformMatrix3x4fv(GLuint program,
5653 GLint location,
5654 GLsizei count,
5655 GLboolean transpose,
5656 const GLfloat *value)
5657{
5658 Program *programObject = getProgram(program);
5659 ASSERT(programObject);
5660 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
5661}
5662
5663void Context::programUniformMatrix4x3fv(GLuint program,
5664 GLint location,
5665 GLsizei count,
5666 GLboolean transpose,
5667 const GLfloat *value)
5668{
5669 Program *programObject = getProgram(program);
5670 ASSERT(programObject);
5671 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
5672}
5673
Jamie Madill81c2e252017-09-09 23:32:46 -04005674void Context::onTextureChange(const Texture *texture)
5675{
5676 // Conservatively assume all textures are dirty.
5677 // TODO(jmadill): More fine-grained update.
5678 mGLState.setObjectDirty(GL_TEXTURE);
5679}
5680
Yunchao Hea336b902017-08-02 16:05:21 +08005681void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5682{
5683 for (int i = 0; i < count; i++)
5684 {
5685 pipelines[i] = createProgramPipeline();
5686 }
5687}
5688
5689void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5690{
5691 for (int i = 0; i < count; i++)
5692 {
5693 if (pipelines[i] != 0)
5694 {
5695 deleteProgramPipeline(pipelines[i]);
5696 }
5697 }
5698}
5699
5700GLboolean Context::isProgramPipeline(GLuint pipeline)
5701{
5702 if (pipeline == 0)
5703 {
5704 return GL_FALSE;
5705 }
5706
5707 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5708}
5709
Jamie Madill2b7bbc22017-12-21 17:30:38 -05005710void Context::finishFenceNV(GLuint fence)
5711{
5712 FenceNV *fenceObject = getFenceNV(fence);
5713
5714 ASSERT(fenceObject && fenceObject->isSet());
5715 handleError(fenceObject->finish());
5716}
5717
5718void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
5719{
5720 FenceNV *fenceObject = getFenceNV(fence);
5721
5722 ASSERT(fenceObject && fenceObject->isSet());
5723
5724 switch (pname)
5725 {
5726 case GL_FENCE_STATUS_NV:
5727 {
5728 // GL_NV_fence spec:
5729 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
5730 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
5731 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
5732 GLboolean status = GL_TRUE;
5733 if (fenceObject->getStatus() != GL_TRUE)
5734 {
5735 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
5736 }
5737 *params = status;
5738 break;
5739 }
5740
5741 case GL_FENCE_CONDITION_NV:
5742 {
5743 *params = static_cast<GLint>(fenceObject->getCondition());
5744 break;
5745 }
5746
5747 default:
5748 UNREACHABLE();
5749 }
5750}
5751
5752void Context::getTranslatedShaderSource(GLuint shader,
5753 GLsizei bufsize,
5754 GLsizei *length,
5755 GLchar *source)
5756{
5757 Shader *shaderObject = getShader(shader);
5758 ASSERT(shaderObject);
5759 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
5760}
5761
5762void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
5763{
5764 Program *programObject = getProgram(program);
5765 ASSERT(programObject);
5766
5767 programObject->getUniformfv(this, location, params);
5768}
5769
5770void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
5771{
5772 Program *programObject = getProgram(program);
5773 ASSERT(programObject);
5774
5775 programObject->getUniformiv(this, location, params);
5776}
5777
5778GLboolean Context::isFenceNV(GLuint fence)
5779{
5780 FenceNV *fenceObject = getFenceNV(fence);
5781
5782 if (fenceObject == nullptr)
5783 {
5784 return GL_FALSE;
5785 }
5786
5787 // GL_NV_fence spec:
5788 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
5789 // existing fence.
5790 return fenceObject->isSet();
5791}
5792
5793void Context::readnPixels(GLint x,
5794 GLint y,
5795 GLsizei width,
5796 GLsizei height,
5797 GLenum format,
5798 GLenum type,
5799 GLsizei bufSize,
5800 void *data)
5801{
5802 return readPixels(x, y, width, height, format, type, data);
5803}
5804
Jamie Madill007530e2017-12-28 14:27:04 -05005805void Context::setFenceNV(GLuint fence, GLenum condition)
5806{
5807 ASSERT(condition == GL_ALL_COMPLETED_NV);
5808
5809 FenceNV *fenceObject = getFenceNV(fence);
5810 ASSERT(fenceObject != nullptr);
5811 handleError(fenceObject->set(condition));
5812}
5813
5814GLboolean Context::testFenceNV(GLuint fence)
5815{
5816 FenceNV *fenceObject = getFenceNV(fence);
5817
5818 ASSERT(fenceObject != nullptr);
5819 ASSERT(fenceObject->isSet() == GL_TRUE);
5820
5821 GLboolean result = GL_TRUE;
5822 Error error = fenceObject->test(&result);
5823 if (error.isError())
5824 {
5825 handleError(error);
5826 return GL_TRUE;
5827 }
5828
5829 return result;
5830}
5831
Jamie Madillfa920eb2018-01-04 11:45:50 -05005832void Context::eGLImageTargetTexture2D(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005833{
5834 Texture *texture = getTargetTexture(target);
5835 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
5836 handleError(texture->setEGLImageTarget(this, target, imageObject));
5837}
5838
Jamie Madillfa920eb2018-01-04 11:45:50 -05005839void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005840{
5841 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
5842 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
5843 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
5844}
5845
Jamie Madillfa920eb2018-01-04 11:45:50 -05005846void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
5847{
5848 UNIMPLEMENTED();
5849}
5850
Geoff Lang2aaa7b42018-01-12 17:17:27 -05005851void Context::alphaFunc(GLenum func, GLfloat ref)
5852{
5853 UNIMPLEMENTED();
5854}
5855
5856void Context::alphaFuncx(GLenum func, GLfixed ref)
5857{
5858 UNIMPLEMENTED();
5859}
5860
5861void Context::clearColorx(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5862{
5863 UNIMPLEMENTED();
5864}
5865
5866void Context::clearDepthx(GLfixed depth)
5867{
5868 UNIMPLEMENTED();
5869}
5870
5871void Context::clientActiveTexture(GLenum texture)
5872{
5873 UNIMPLEMENTED();
5874}
5875
5876void Context::clipPlanef(GLenum p, const GLfloat *eqn)
5877{
5878 UNIMPLEMENTED();
5879}
5880
5881void Context::clipPlanex(GLenum plane, const GLfixed *equation)
5882{
5883 UNIMPLEMENTED();
5884}
5885
5886void Context::color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
5887{
5888 UNIMPLEMENTED();
5889}
5890
5891void Context::color4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
5892{
5893 UNIMPLEMENTED();
5894}
5895
5896void Context::color4x(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5897{
5898 UNIMPLEMENTED();
5899}
5900
5901void Context::colorPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
5902{
5903 UNIMPLEMENTED();
5904}
5905
5906void Context::cullFace(GLenum mode)
5907{
5908 UNIMPLEMENTED();
5909}
5910
5911void Context::depthRangex(GLfixed n, GLfixed f)
5912{
5913 UNIMPLEMENTED();
5914}
5915
5916void Context::disableClientState(GLenum array)
5917{
5918 UNIMPLEMENTED();
5919}
5920
5921void Context::enableClientState(GLenum array)
5922{
5923 UNIMPLEMENTED();
5924}
5925
5926void Context::fogf(GLenum pname, GLfloat param)
5927{
5928 UNIMPLEMENTED();
5929}
5930
5931void Context::fogfv(GLenum pname, const GLfloat *params)
5932{
5933 UNIMPLEMENTED();
5934}
5935
5936void Context::fogx(GLenum pname, GLfixed param)
5937{
5938 UNIMPLEMENTED();
5939}
5940
5941void Context::fogxv(GLenum pname, const GLfixed *param)
5942{
5943 UNIMPLEMENTED();
5944}
5945
5946void Context::frustumf(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
5947{
5948 UNIMPLEMENTED();
5949}
5950
5951void Context::frustumx(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
5952{
5953 UNIMPLEMENTED();
5954}
5955
5956void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
5957{
5958 UNIMPLEMENTED();
5959}
5960
5961void Context::getClipPlanef(GLenum plane, GLfloat *equation)
5962{
5963 UNIMPLEMENTED();
5964}
5965
5966void Context::getClipPlanex(GLenum plane, GLfixed *equation)
5967{
5968 UNIMPLEMENTED();
5969}
5970
5971void Context::getFixedv(GLenum pname, GLfixed *params)
5972{
5973 UNIMPLEMENTED();
5974}
5975
5976void Context::getLightfv(GLenum light, GLenum pname, GLfloat *params)
5977{
5978 UNIMPLEMENTED();
5979}
5980
5981void Context::getLightxv(GLenum light, GLenum pname, GLfixed *params)
5982{
5983 UNIMPLEMENTED();
5984}
5985
5986void Context::getMaterialfv(GLenum face, GLenum pname, GLfloat *params)
5987{
5988 UNIMPLEMENTED();
5989}
5990
5991void Context::getMaterialxv(GLenum face, GLenum pname, GLfixed *params)
5992{
5993 UNIMPLEMENTED();
5994}
5995
5996void Context::getTexEnvfv(GLenum target, GLenum pname, GLfloat *params)
5997{
5998 UNIMPLEMENTED();
5999}
6000
6001void Context::getTexEnviv(GLenum target, GLenum pname, GLint *params)
6002{
6003 UNIMPLEMENTED();
6004}
6005
6006void Context::getTexEnvxv(GLenum target, GLenum pname, GLfixed *params)
6007{
6008 UNIMPLEMENTED();
6009}
6010
6011void Context::getTexParameterxv(GLenum target, GLenum pname, GLfixed *params)
6012{
6013 UNIMPLEMENTED();
6014}
6015
6016void Context::lightModelf(GLenum pname, GLfloat param)
6017{
6018 UNIMPLEMENTED();
6019}
6020
6021void Context::lightModelfv(GLenum pname, const GLfloat *params)
6022{
6023 UNIMPLEMENTED();
6024}
6025
6026void Context::lightModelx(GLenum pname, GLfixed param)
6027{
6028 UNIMPLEMENTED();
6029}
6030
6031void Context::lightModelxv(GLenum pname, const GLfixed *param)
6032{
6033 UNIMPLEMENTED();
6034}
6035
6036void Context::lightf(GLenum light, GLenum pname, GLfloat param)
6037{
6038 UNIMPLEMENTED();
6039}
6040
6041void Context::lightfv(GLenum light, GLenum pname, const GLfloat *params)
6042{
6043 UNIMPLEMENTED();
6044}
6045
6046void Context::lightx(GLenum light, GLenum pname, GLfixed param)
6047{
6048 UNIMPLEMENTED();
6049}
6050
6051void Context::lightxv(GLenum light, GLenum pname, const GLfixed *params)
6052{
6053 UNIMPLEMENTED();
6054}
6055
6056void Context::lineWidthx(GLfixed width)
6057{
6058 UNIMPLEMENTED();
6059}
6060
6061void Context::loadIdentity()
6062{
6063 UNIMPLEMENTED();
6064}
6065
6066void Context::loadMatrixf(const GLfloat *m)
6067{
6068 UNIMPLEMENTED();
6069}
6070
6071void Context::loadMatrixx(const GLfixed *m)
6072{
6073 UNIMPLEMENTED();
6074}
6075
6076void Context::logicOp(GLenum opcode)
6077{
6078 UNIMPLEMENTED();
6079}
6080
6081void Context::materialf(GLenum face, GLenum pname, GLfloat param)
6082{
6083 UNIMPLEMENTED();
6084}
6085
6086void Context::materialfv(GLenum face, GLenum pname, const GLfloat *params)
6087{
6088 UNIMPLEMENTED();
6089}
6090
6091void Context::materialx(GLenum face, GLenum pname, GLfixed param)
6092{
6093 UNIMPLEMENTED();
6094}
6095
6096void Context::materialxv(GLenum face, GLenum pname, const GLfixed *param)
6097{
6098 UNIMPLEMENTED();
6099}
6100
6101void Context::matrixMode(GLenum mode)
6102{
6103 UNIMPLEMENTED();
6104}
6105
6106void Context::multMatrixf(const GLfloat *m)
6107{
6108 UNIMPLEMENTED();
6109}
6110
6111void Context::multMatrixx(const GLfixed *m)
6112{
6113 UNIMPLEMENTED();
6114}
6115
6116void Context::multiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q)
6117{
6118 UNIMPLEMENTED();
6119}
6120
6121void Context::multiTexCoord4x(GLenum texture, GLfixed s, GLfixed t, GLfixed r, GLfixed q)
6122{
6123 UNIMPLEMENTED();
6124}
6125
6126void Context::normal3f(GLfloat nx, GLfloat ny, GLfloat nz)
6127{
6128 UNIMPLEMENTED();
6129}
6130
6131void Context::normal3x(GLfixed nx, GLfixed ny, GLfixed nz)
6132{
6133 UNIMPLEMENTED();
6134}
6135
6136void Context::normalPointer(GLenum type, GLsizei stride, const void *pointer)
6137{
6138 UNIMPLEMENTED();
6139}
6140
6141void Context::orthof(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
6142{
6143 UNIMPLEMENTED();
6144}
6145
6146void Context::orthox(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
6147{
6148 UNIMPLEMENTED();
6149}
6150
6151void Context::pointParameterf(GLenum pname, GLfloat param)
6152{
6153 UNIMPLEMENTED();
6154}
6155
6156void Context::pointParameterfv(GLenum pname, const GLfloat *params)
6157{
6158 UNIMPLEMENTED();
6159}
6160
6161void Context::pointParameterx(GLenum pname, GLfixed param)
6162{
6163 UNIMPLEMENTED();
6164}
6165
6166void Context::pointParameterxv(GLenum pname, const GLfixed *params)
6167{
6168 UNIMPLEMENTED();
6169}
6170
6171void Context::pointSize(GLfloat size)
6172{
6173 UNIMPLEMENTED();
6174}
6175
6176void Context::pointSizex(GLfixed size)
6177{
6178 UNIMPLEMENTED();
6179}
6180
6181void Context::polygonOffsetx(GLfixed factor, GLfixed units)
6182{
6183 UNIMPLEMENTED();
6184}
6185
6186void Context::popMatrix()
6187{
6188 UNIMPLEMENTED();
6189}
6190
6191void Context::pushMatrix()
6192{
6193 UNIMPLEMENTED();
6194}
6195
6196void Context::rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
6197{
6198 UNIMPLEMENTED();
6199}
6200
6201void Context::rotatex(GLfixed angle, GLfixed x, GLfixed y, GLfixed z)
6202{
6203 UNIMPLEMENTED();
6204}
6205
6206void Context::sampleCoveragex(GLclampx value, GLboolean invert)
6207{
6208 UNIMPLEMENTED();
6209}
6210
6211void Context::scalef(GLfloat x, GLfloat y, GLfloat z)
6212{
6213 UNIMPLEMENTED();
6214}
6215
6216void Context::scalex(GLfixed x, GLfixed y, GLfixed z)
6217{
6218 UNIMPLEMENTED();
6219}
6220
6221void Context::shadeModel(GLenum mode)
6222{
6223 UNIMPLEMENTED();
6224}
6225
6226void Context::texCoordPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6227{
6228 UNIMPLEMENTED();
6229}
6230
6231void Context::texEnvf(GLenum target, GLenum pname, GLfloat param)
6232{
6233 UNIMPLEMENTED();
6234}
6235
6236void Context::texEnvfv(GLenum target, GLenum pname, const GLfloat *params)
6237{
6238 UNIMPLEMENTED();
6239}
6240
6241void Context::texEnvi(GLenum target, GLenum pname, GLint param)
6242{
6243 UNIMPLEMENTED();
6244}
6245
6246void Context::texEnviv(GLenum target, GLenum pname, const GLint *params)
6247{
6248 UNIMPLEMENTED();
6249}
6250
6251void Context::texEnvx(GLenum target, GLenum pname, GLfixed param)
6252{
6253 UNIMPLEMENTED();
6254}
6255
6256void Context::texEnvxv(GLenum target, GLenum pname, const GLfixed *params)
6257{
6258 UNIMPLEMENTED();
6259}
6260
6261void Context::texParameterx(GLenum target, GLenum pname, GLfixed param)
6262{
6263 UNIMPLEMENTED();
6264}
6265
6266void Context::texParameterxv(GLenum target, GLenum pname, const GLfixed *params)
6267{
6268 UNIMPLEMENTED();
6269}
6270
6271void Context::translatef(GLfloat x, GLfloat y, GLfloat z)
6272{
6273 UNIMPLEMENTED();
6274}
6275
6276void Context::translatex(GLfixed x, GLfixed y, GLfixed z)
6277{
6278 UNIMPLEMENTED();
6279}
6280
6281void Context::vertexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6282{
6283 UNIMPLEMENTED();
6284}
6285
6286void Context::drawTexf(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height)
6287{
6288 UNIMPLEMENTED();
6289}
6290
6291void Context::drawTexfv(const GLfloat *coords)
6292{
6293 UNIMPLEMENTED();
6294}
6295
6296void Context::drawTexi(GLint x, GLint y, GLint z, GLint width, GLint height)
6297{
6298 UNIMPLEMENTED();
6299}
6300
6301void Context::drawTexiv(const GLint *coords)
6302{
6303 UNIMPLEMENTED();
6304}
6305
6306void Context::drawTexs(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height)
6307{
6308 UNIMPLEMENTED();
6309}
6310
6311void Context::drawTexsv(const GLshort *coords)
6312{
6313 UNIMPLEMENTED();
6314}
6315
6316void Context::drawTexx(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height)
6317{
6318 UNIMPLEMENTED();
6319}
6320
6321void Context::drawTexxv(const GLfixed *coords)
6322{
6323 UNIMPLEMENTED();
6324}
6325
6326void Context::currentPaletteMatrix(GLuint matrixpaletteindex)
6327{
6328 UNIMPLEMENTED();
6329}
6330
6331void Context::loadPaletteFromModelViewMatrix()
6332{
6333 UNIMPLEMENTED();
6334}
6335
6336void Context::matrixIndexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6337{
6338 UNIMPLEMENTED();
6339}
6340
6341void Context::weightPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6342{
6343 UNIMPLEMENTED();
6344}
6345
6346void Context::pointSizePointer(GLenum type, GLsizei stride, const void *pointer)
6347{
6348 UNIMPLEMENTED();
6349}
6350
6351GLbitfield Context::queryMatrixx(GLfixed *mantissa, GLint *exponent)
6352{
6353 UNIMPLEMENTED();
6354 return 0;
6355}
6356
Jamie Madillc29968b2016-01-20 11:17:23 -05006357} // namespace gl