blob: 7a104671ae2d3ca19c586acfa2f74b4e10699783 [file] [log] [blame]
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001//
Geoff Langeeba6e12014-02-03 13:12:30 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Context.cpp: Implements the gl::Context class, managing all GL state and performing
8// rendering operations. It is the GLES2 specific implementation of EGLContext.
9
Geoff Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/Context.h"
apatrick@chromium.org144f2802012-07-12 01:42:34 +000011
Jamie Madill231c7f52017-04-26 13:45:37 -040012#include <string.h>
Jamie Madillb9293972015-02-19 11:07:54 -050013#include <iterator>
14#include <sstream>
Sami Väisänend59ca052016-06-21 16:10:00 +030015#include <vector>
Jamie Madillb9293972015-02-19 11:07:54 -050016
Sami Väisänene45e53b2016-05-25 10:36:04 +030017#include "common/matrix_utils.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040018#include "common/platform.h"
Jamie Madillb9293972015-02-19 11:07:54 -050019#include "common/utilities.h"
Geoff Langc339c4e2016-11-29 10:37:36 -050020#include "common/version.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050021#include "libANGLE/Buffer.h"
Jamie Madillb9293972015-02-19 11:07:54 -050022#include "libANGLE/Compiler.h"
Jamie Madill948bbe52017-06-01 13:10:42 -040023#include "libANGLE/Display.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050024#include "libANGLE/Fence.h"
25#include "libANGLE/Framebuffer.h"
26#include "libANGLE/FramebufferAttachment.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030027#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050028#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080029#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050030#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050031#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050032#include "libANGLE/ResourceManager.h"
33#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050034#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050035#include "libANGLE/Texture.h"
36#include "libANGLE/TransformFeedback.h"
37#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070038#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040039#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030040#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040041#include "libANGLE/queryutils.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040042#include "libANGLE/renderer/ContextImpl.h"
43#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040044#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040045#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000046
Geoff Langf6db0982015-08-25 13:04:00 -040047namespace
48{
49
Jamie Madillb6664922017-07-25 12:55:04 -040050#define ANGLE_HANDLE_ERR(X) \
51 handleError(X); \
52 return;
53#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
54
Ian Ewell3ffd78b2016-01-22 16:09:42 -050055template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050056std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030057 GLsizei numPaths,
58 const void *paths,
59 GLuint pathBase)
60{
61 std::vector<gl::Path *> ret;
62 ret.reserve(numPaths);
63
64 const auto *nameArray = static_cast<const T *>(paths);
65
66 for (GLsizei i = 0; i < numPaths; ++i)
67 {
68 const GLuint pathName = nameArray[i] + pathBase;
69
70 ret.push_back(resourceManager.getPath(pathName));
71 }
72
73 return ret;
74}
75
Geoff Lang4ddf5af2016-12-01 14:30:44 -050076std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030077 GLsizei numPaths,
78 GLenum pathNameType,
79 const void *paths,
80 GLuint pathBase)
81{
82 switch (pathNameType)
83 {
84 case GL_UNSIGNED_BYTE:
85 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
86
87 case GL_BYTE:
88 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
89
90 case GL_UNSIGNED_SHORT:
91 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
92
93 case GL_SHORT:
94 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
95
96 case GL_UNSIGNED_INT:
97 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
98
99 case GL_INT:
100 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
101 }
102
103 UNREACHABLE();
104 return std::vector<gl::Path *>();
105}
106
107template <typename T>
Geoff Lang2186c382016-10-14 10:54:54 -0400108gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500109{
Geoff Lang2186c382016-10-14 10:54:54 -0400110 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500111
112 switch (pname)
113 {
114 case GL_QUERY_RESULT_EXT:
Geoff Lang2186c382016-10-14 10:54:54 -0400115 return query->getResult(params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500116 case GL_QUERY_RESULT_AVAILABLE_EXT:
117 {
118 bool available;
Geoff Lang2186c382016-10-14 10:54:54 -0400119 gl::Error error = query->isResultAvailable(&available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500120 if (!error.isError())
121 {
jchen10a99ed552017-09-22 08:10:32 +0800122 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500123 }
124 return error;
125 }
126 default:
127 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500128 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500129 }
130}
131
Geoff Langf6db0982015-08-25 13:04:00 -0400132void MarkTransformFeedbackBufferUsage(gl::TransformFeedback *transformFeedback)
133{
Geoff Lang1a683462015-09-29 15:09:59 -0400134 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400135 {
136 for (size_t tfBufferIndex = 0; tfBufferIndex < transformFeedback->getIndexedBufferCount();
137 tfBufferIndex++)
138 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400139 const gl::OffsetBindingPointer<gl::Buffer> &buffer =
Geoff Langf6db0982015-08-25 13:04:00 -0400140 transformFeedback->getIndexedBuffer(tfBufferIndex);
141 if (buffer.get() != nullptr)
142 {
143 buffer->onTransformFeedback();
144 }
145 }
146 }
147}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500148
149// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300150EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500151{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400152 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500153}
154
Martin Radev1be913c2016-07-11 17:59:16 +0300155EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
156{
157 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
158}
159
Geoff Langeb66a6e2016-10-31 13:06:12 -0400160gl::Version GetClientVersion(const egl::AttributeMap &attribs)
161{
162 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
163}
164
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500165GLenum GetResetStrategy(const egl::AttributeMap &attribs)
166{
Lingfeng Yangb27b03a2018-02-19 13:38:48 -0800167 EGLAttrib attrib =
168 attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500169 switch (attrib)
170 {
171 case EGL_NO_RESET_NOTIFICATION:
172 return GL_NO_RESET_NOTIFICATION_EXT;
173 case EGL_LOSE_CONTEXT_ON_RESET:
174 return GL_LOSE_CONTEXT_ON_RESET_EXT;
175 default:
176 UNREACHABLE();
177 return GL_NONE;
178 }
179}
180
181bool GetRobustAccess(const egl::AttributeMap &attribs)
182{
Geoff Lang077f20a2016-11-01 10:08:02 -0400183 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
184 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
185 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500186}
187
188bool GetDebug(const egl::AttributeMap &attribs)
189{
Geoff Lang077f20a2016-11-01 10:08:02 -0400190 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
191 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500192}
193
194bool GetNoError(const egl::AttributeMap &attribs)
195{
196 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
197}
198
Geoff Langc287ea62016-09-16 14:46:51 -0400199bool GetWebGLContext(const egl::AttributeMap &attribs)
200{
201 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
202}
203
Geoff Langf41a7152016-09-19 15:11:17 -0400204bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
205{
206 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
207}
208
Geoff Langfeb8c682017-02-13 16:07:35 -0500209bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
210{
211 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
212}
213
Geoff Langb433e872017-10-05 14:01:47 -0400214bool GetRobustResourceInit(const egl::AttributeMap &attribs)
215{
216 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
217}
218
Martin Radev9d901792016-07-15 15:58:58 +0300219std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
220{
221 std::string labelName;
222 if (label != nullptr)
223 {
224 size_t labelLength = length < 0 ? strlen(label) : length;
225 labelName = std::string(label, labelLength);
226 }
227 return labelName;
228}
229
230void GetObjectLabelBase(const std::string &objectLabel,
231 GLsizei bufSize,
232 GLsizei *length,
233 GLchar *label)
234{
235 size_t writeLength = objectLabel.length();
236 if (label != nullptr && bufSize > 0)
237 {
238 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
239 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
240 label[writeLength] = '\0';
241 }
242
243 if (length != nullptr)
244 {
245 *length = static_cast<GLsizei>(writeLength);
246 }
247}
248
Jamie Madill0f80ed82017-09-19 00:24:56 -0400249template <typename CapT, typename MaxT>
250void LimitCap(CapT *cap, MaxT maximum)
251{
252 *cap = std::min(*cap, static_cast<CapT>(maximum));
253}
254
Geoff Langf6db0982015-08-25 13:04:00 -0400255} // anonymous namespace
256
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000257namespace gl
258{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000259
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400260Context::Context(rx::EGLImplFactory *implFactory,
261 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400262 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500263 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400264 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500265 const egl::AttributeMap &attribs,
Geoff Langb433e872017-10-05 14:01:47 -0400266 const egl::DisplayExtensions &displayExtensions)
Martin Radev1be913c2016-07-11 17:59:16 +0300267
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500268 : ValidationContext(shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500269 shareTextures,
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500270 GetClientVersion(attribs),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700271 &mGLState,
Jamie Madillf25855c2015-11-03 11:06:18 -0500272 mCaps,
273 mTextureCaps,
274 mExtensions,
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500275 mLimitations,
276 GetNoError(attribs)),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700277 mImplementation(implFactory->createContext(mState)),
Jamie Madill2f348d22017-06-05 10:50:59 -0400278 mCompiler(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400279 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500280 mClientType(EGL_OPENGL_ES_API),
281 mHasBeenCurrent(false),
282 mContextLost(false),
283 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700284 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500285 mResetStrategy(GetResetStrategy(attribs)),
286 mRobustAccess(GetRobustAccess(attribs)),
Jamie Madill61e16b42017-06-19 11:13:23 -0400287 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
288 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500289 mSurfacelessFramebuffer(nullptr),
Jamie Madille14951e2017-03-09 18:55:16 -0500290 mWebGLContext(GetWebGLContext(attribs)),
Jamie Madill32447362017-06-28 14:53:52 -0400291 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400292 mScratchBuffer(1000u),
293 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000294{
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400295 mImplementation->setMemoryProgramCache(memoryProgramCache);
296
Geoff Langb433e872017-10-05 14:01:47 -0400297 bool robustResourceInit = GetRobustResourceInit(attribs);
298 initCaps(displayExtensions, robustResourceInit);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700299 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400300
Jamie Madill4928b7c2017-06-20 12:57:39 -0400301 mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs),
Jamie Madillc43be722017-07-13 16:22:14 -0400302 GetClientArraysEnabled(attribs), robustResourceInit,
303 mMemoryProgramCache != nullptr);
Régis Fénéon83107972015-02-05 12:57:44 +0100304
Shannon Woods53a94a82014-06-24 15:20:36 -0400305 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400306
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000307 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400308 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000309 // and cube map texture state vectors respectively associated with them.
310 // In order that access to these initial textures not be lost, they are treated as texture
311 // objects all of whose names are 0.
312
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 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800336 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800337 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800338
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800339 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
340 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400341 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800342 }
Geoff Lang3b573612016-10-31 14:08:10 -0400343 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000344
Geoff Lang4751aab2017-10-30 15:14:52 -0400345 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
346 if (nativeExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400347 {
348 Texture *zeroTextureRectangle =
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.
Jamie Madilld4442552018-02-27 22:03:47 -05002628 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002629 for (auto &zeroTexture : mZeroTextures)
2630 {
Jamie Madilld4442552018-02-27 22:03:47 -05002631 zeroTexture.second->signalDirty(this, 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
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08002667 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
2668 if (getClientVersion() < Version(2, 0))
2669 {
2670 mCaps.maxMultitextureUnits = 4;
2671 mCaps.maxClipPlanes = 6;
2672 mCaps.maxLights = 8;
2673 mCaps.maxModelviewMatrixStackDepth = 16;
2674 mCaps.maxProjectionMatrixStackDepth = 16;
2675 mCaps.maxTextureMatrixStackDepth = 16;
2676 }
2677
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002678 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002679
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002680 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002681
Geoff Langeb66a6e2016-10-31 13:06:12 -04002682 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002683 {
2684 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002685 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002686 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002687 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002688 mExtensions.multiview = false;
2689 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002690 }
2691
Jiawei Shao89be29a2017-11-06 14:36:45 +08002692 if (getClientVersion() < ES_3_1)
2693 {
2694 // Disable ES3.1+ extensions
2695 mExtensions.geometryShader = false;
2696 }
2697
Geoff Langeb66a6e2016-10-31 13:06:12 -04002698 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002699 {
2700 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002701 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002702 }
2703
Jamie Madill00ed7a12016-05-19 13:13:38 -04002704 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002705 mExtensions.bindUniformLocation = true;
2706 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002707 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002708 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002709 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002710
2711 // Enable the no error extension if the context was created with the flag.
2712 mExtensions.noError = mSkipValidation;
2713
Corentin Wallezccab69d2017-01-27 16:57:15 -05002714 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002715 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002716
Geoff Lang70d0f492015-12-10 17:45:46 -05002717 // Explicitly enable GL_KHR_debug
2718 mExtensions.debug = true;
2719 mExtensions.maxDebugMessageLength = 1024;
2720 mExtensions.maxDebugLoggedMessages = 1024;
2721 mExtensions.maxDebugGroupStackDepth = 1024;
2722 mExtensions.maxLabelLength = 1024;
2723
Geoff Langff5b2d52016-09-07 11:32:23 -04002724 // Explicitly enable GL_ANGLE_robust_client_memory
2725 mExtensions.robustClientMemory = true;
2726
Jamie Madille08a1d32017-03-07 17:24:06 -05002727 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002728 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002729
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002730 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2731 // supports it.
2732 mExtensions.robustBufferAccessBehavior =
2733 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2734
Jamie Madillc43be722017-07-13 16:22:14 -04002735 // Enable the cache control query unconditionally.
2736 mExtensions.programCacheControl = true;
2737
Geoff Lang301d1612014-07-09 10:34:37 -04002738 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002739 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002740
Jamie Madill0f80ed82017-09-19 00:24:56 -04002741 if (getClientVersion() < ES_3_1)
2742 {
2743 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2744 }
2745 else
2746 {
2747 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2748 }
Geoff Lang301d1612014-07-09 10:34:37 -04002749
Jamie Madill0f80ed82017-09-19 00:24:56 -04002750 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2751 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2752 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2753
2754 // Limit textures as well, so we can use fast bitsets with texture bindings.
2755 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2756 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2757 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002758
Jiawei Shaodb342272017-09-27 10:21:45 +08002759 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2760
Geoff Langc287ea62016-09-16 14:46:51 -04002761 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002762 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002763 for (const auto &extensionInfo : GetExtensionInfoMap())
2764 {
2765 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002766 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002767 {
2768 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2769 }
2770 }
2771
2772 // Generate texture caps
2773 updateCaps();
2774}
2775
2776void Context::updateCaps()
2777{
Geoff Lang900013c2014-07-07 11:32:19 -04002778 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002779 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002780
Jamie Madill7b62cf92017-11-02 15:20:49 -04002781 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04002782 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04002783 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04002784 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002785
Geoff Lang0d8b7242015-09-09 14:56:53 -04002786 // Update the format caps based on the client version and extensions.
2787 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2788 // ES3.
2789 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002790 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002791 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002792 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002793 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002794 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002795
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002796 // OpenGL ES does not support multisampling with non-rendererable formats
2797 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002798 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002799 (getClientVersion() < ES_3_1 &&
2800 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002801 {
Geoff Langd87878e2014-09-19 15:42:59 -04002802 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002803 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002804 else
2805 {
2806 // We may have limited the max samples for some required renderbuffer formats due to
2807 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2808 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2809
2810 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2811 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2812 // exception of signed and unsigned integer formats."
2813 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2814 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2815 {
2816 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2817 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2818 }
2819
2820 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2821 if (getClientVersion() >= ES_3_1)
2822 {
2823 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2824 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2825 // the exception that the signed and unsigned integer formats are required only to
2826 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2827 // multisamples, which must be at least one."
2828 if (formatInfo.componentType == GL_INT ||
2829 formatInfo.componentType == GL_UNSIGNED_INT)
2830 {
2831 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2832 }
2833
2834 // GLES 3.1 section 19.3.1.
2835 if (formatCaps.texturable)
2836 {
2837 if (formatInfo.depthBits > 0)
2838 {
2839 mCaps.maxDepthTextureSamples =
2840 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2841 }
2842 else if (formatInfo.redBits > 0)
2843 {
2844 mCaps.maxColorTextureSamples =
2845 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2846 }
2847 }
2848 }
2849 }
Geoff Langd87878e2014-09-19 15:42:59 -04002850
2851 if (formatCaps.texturable && formatInfo.compressed)
2852 {
Geoff Langca271392017-04-05 12:30:00 -04002853 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002854 }
2855
Geoff Langca271392017-04-05 12:30:00 -04002856 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002857 }
Jamie Madill32447362017-06-28 14:53:52 -04002858
2859 // If program binary is disabled, blank out the memory cache pointer.
2860 if (!mImplementation->getNativeExtensions().getProgramBinary)
2861 {
2862 mMemoryProgramCache = nullptr;
2863 }
Corentin Walleze4477002017-12-01 14:39:58 -05002864
2865 // Compute which buffer types are allowed
2866 mValidBufferBindings.reset();
2867 mValidBufferBindings.set(BufferBinding::ElementArray);
2868 mValidBufferBindings.set(BufferBinding::Array);
2869
2870 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
2871 {
2872 mValidBufferBindings.set(BufferBinding::PixelPack);
2873 mValidBufferBindings.set(BufferBinding::PixelUnpack);
2874 }
2875
2876 if (getClientVersion() >= ES_3_0)
2877 {
2878 mValidBufferBindings.set(BufferBinding::CopyRead);
2879 mValidBufferBindings.set(BufferBinding::CopyWrite);
2880 mValidBufferBindings.set(BufferBinding::TransformFeedback);
2881 mValidBufferBindings.set(BufferBinding::Uniform);
2882 }
2883
2884 if (getClientVersion() >= ES_3_1)
2885 {
2886 mValidBufferBindings.set(BufferBinding::AtomicCounter);
2887 mValidBufferBindings.set(BufferBinding::ShaderStorage);
2888 mValidBufferBindings.set(BufferBinding::DrawIndirect);
2889 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
2890 }
Geoff Lang493daf52014-07-03 13:38:44 -04002891}
2892
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002893void Context::initWorkarounds()
2894{
Jamie Madill761b02c2017-06-23 16:27:06 -04002895 // Apply back-end workarounds.
2896 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2897
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002898 // Lose the context upon out of memory error if the application is
2899 // expecting to watch for those events.
2900 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2901}
2902
Jamie Madill05b35b22017-10-03 09:01:44 -04002903Error Context::prepareForDraw()
2904{
2905 syncRendererState();
Jamie Madilla59fc192017-11-02 12:57:58 -04002906
2907 if (isRobustResourceInitEnabled())
2908 {
2909 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
2910 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
2911 }
2912
Jamie Madill05b35b22017-10-03 09:01:44 -04002913 return NoError();
2914}
2915
Jamie Madill1b94d432015-08-07 13:23:23 -04002916void Context::syncRendererState()
2917{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002918 mGLState.syncDirtyObjects(this);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002919 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madillfe548342017-06-19 11:13:24 -04002920 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002921 mGLState.clearDirtyBits();
Jamie Madill1b94d432015-08-07 13:23:23 -04002922}
2923
Jamie Madillad9f24e2016-02-12 09:27:24 -05002924void Context::syncRendererState(const State::DirtyBits &bitMask,
2925 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002926{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002927 mGLState.syncDirtyObjects(this, objectMask);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002928 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002929 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002930 mGLState.clearDirtyBits(dirtyBits);
Jamie Madill1b94d432015-08-07 13:23:23 -04002931}
Jamie Madillc29968b2016-01-20 11:17:23 -05002932
2933void Context::blitFramebuffer(GLint srcX0,
2934 GLint srcY0,
2935 GLint srcX1,
2936 GLint srcY1,
2937 GLint dstX0,
2938 GLint dstY0,
2939 GLint dstX1,
2940 GLint dstY1,
2941 GLbitfield mask,
2942 GLenum filter)
2943{
Qin Jiajiaaef92162018-02-27 13:51:44 +08002944 if (mask == 0)
2945 {
2946 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
2947 // buffers are copied.
2948 return;
2949 }
2950
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002951 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002952 ASSERT(drawFramebuffer);
2953
2954 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2955 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2956
Jamie Madillad9f24e2016-02-12 09:27:24 -05002957 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002958
Jamie Madillc564c072017-06-01 12:45:42 -04002959 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002960}
Jamie Madillc29968b2016-01-20 11:17:23 -05002961
2962void Context::clear(GLbitfield mask)
2963{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002964 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002965 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002966}
2967
2968void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2969{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002970 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002971 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002972}
2973
2974void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2975{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002976 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002977 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002978}
2979
2980void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2981{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002982 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002983 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002984}
2985
2986void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2987{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002988 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002989 ASSERT(framebufferObject);
2990
2991 // If a buffer is not present, the clear has no effect
2992 if (framebufferObject->getDepthbuffer() == nullptr &&
2993 framebufferObject->getStencilbuffer() == nullptr)
2994 {
2995 return;
2996 }
2997
Jamie Madillad9f24e2016-02-12 09:27:24 -05002998 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002999 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003000}
3001
3002void Context::readPixels(GLint x,
3003 GLint y,
3004 GLsizei width,
3005 GLsizei height,
3006 GLenum format,
3007 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003008 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003009{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003010 if (width == 0 || height == 0)
3011 {
3012 return;
3013 }
3014
Jamie Madillad9f24e2016-02-12 09:27:24 -05003015 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05003016
Jamie Madillb6664922017-07-25 12:55:04 -04003017 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3018 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003019
3020 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003021 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003022}
3023
3024void Context::copyTexImage2D(GLenum target,
3025 GLint level,
3026 GLenum internalformat,
3027 GLint x,
3028 GLint y,
3029 GLsizei width,
3030 GLsizei height,
3031 GLint border)
3032{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003033 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003034 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003035
Jamie Madillc29968b2016-01-20 11:17:23 -05003036 Rectangle sourceArea(x, y, width, height);
3037
Jamie Madill05b35b22017-10-03 09:01:44 -04003038 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003039 Texture *texture =
3040 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003041 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003042}
3043
3044void Context::copyTexSubImage2D(GLenum target,
3045 GLint level,
3046 GLint xoffset,
3047 GLint yoffset,
3048 GLint x,
3049 GLint y,
3050 GLsizei width,
3051 GLsizei height)
3052{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003053 if (width == 0 || height == 0)
3054 {
3055 return;
3056 }
3057
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003058 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003059 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003060
Jamie Madillc29968b2016-01-20 11:17:23 -05003061 Offset destOffset(xoffset, yoffset, 0);
3062 Rectangle sourceArea(x, y, width, height);
3063
Jamie Madill05b35b22017-10-03 09:01:44 -04003064 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003065 Texture *texture =
3066 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003067 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003068}
3069
3070void Context::copyTexSubImage3D(GLenum target,
3071 GLint level,
3072 GLint xoffset,
3073 GLint yoffset,
3074 GLint zoffset,
3075 GLint x,
3076 GLint y,
3077 GLsizei width,
3078 GLsizei height)
3079{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003080 if (width == 0 || height == 0)
3081 {
3082 return;
3083 }
3084
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003085 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003086 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003087
Jamie Madillc29968b2016-01-20 11:17:23 -05003088 Offset destOffset(xoffset, yoffset, zoffset);
3089 Rectangle sourceArea(x, y, width, height);
3090
Jamie Madill05b35b22017-10-03 09:01:44 -04003091 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3092 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003093 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003094}
3095
3096void Context::framebufferTexture2D(GLenum target,
3097 GLenum attachment,
3098 GLenum textarget,
3099 GLuint texture,
3100 GLint level)
3101{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003102 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003103 ASSERT(framebuffer);
3104
3105 if (texture != 0)
3106 {
3107 Texture *textureObj = getTexture(texture);
3108
3109 ImageIndex index = ImageIndex::MakeInvalid();
3110
3111 if (textarget == GL_TEXTURE_2D)
3112 {
3113 index = ImageIndex::Make2D(level);
3114 }
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003115 else if (textarget == GL_TEXTURE_RECTANGLE_ANGLE)
3116 {
3117 index = ImageIndex::MakeRectangle(level);
3118 }
JiangYizhoubddc46b2016-12-09 09:50:51 +08003119 else if (textarget == GL_TEXTURE_2D_MULTISAMPLE)
3120 {
3121 ASSERT(level == 0);
3122 index = ImageIndex::Make2DMultisample();
3123 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003124 else
3125 {
3126 ASSERT(IsCubeMapTextureTarget(textarget));
3127 index = ImageIndex::MakeCube(textarget, level);
3128 }
3129
Jamie Madilla02315b2017-02-23 14:14:47 -05003130 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003131 }
3132 else
3133 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003134 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003135 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003136
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003137 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003138}
3139
3140void Context::framebufferRenderbuffer(GLenum target,
3141 GLenum attachment,
3142 GLenum renderbuffertarget,
3143 GLuint renderbuffer)
3144{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003145 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003146 ASSERT(framebuffer);
3147
3148 if (renderbuffer != 0)
3149 {
3150 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003151
3152 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003153 renderbufferObject);
3154 }
3155 else
3156 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003157 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003158 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003159
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003160 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003161}
3162
3163void Context::framebufferTextureLayer(GLenum target,
3164 GLenum attachment,
3165 GLuint texture,
3166 GLint level,
3167 GLint layer)
3168{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003169 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003170 ASSERT(framebuffer);
3171
3172 if (texture != 0)
3173 {
3174 Texture *textureObject = getTexture(texture);
3175
3176 ImageIndex index = ImageIndex::MakeInvalid();
3177
3178 if (textureObject->getTarget() == GL_TEXTURE_3D)
3179 {
3180 index = ImageIndex::Make3D(level, layer);
3181 }
3182 else
3183 {
3184 ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY);
3185 index = ImageIndex::Make2DArray(level, layer);
3186 }
3187
Jamie Madilla02315b2017-02-23 14:14:47 -05003188 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003189 }
3190 else
3191 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003192 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003193 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003194
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003195 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003196}
3197
Martin Radev137032d2017-07-13 10:11:12 +03003198void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3199 GLenum attachment,
3200 GLuint texture,
3201 GLint level,
3202 GLint baseViewIndex,
3203 GLsizei numViews)
3204{
Martin Radev82ef7742017-08-08 17:44:58 +03003205 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3206 ASSERT(framebuffer);
3207
3208 if (texture != 0)
3209 {
3210 Texture *textureObj = getTexture(texture);
3211
Martin Radev18b75ba2017-08-15 15:50:40 +03003212 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003213 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3214 numViews, baseViewIndex);
3215 }
3216 else
3217 {
3218 framebuffer->resetAttachment(this, attachment);
3219 }
3220
3221 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003222}
3223
3224void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3225 GLenum attachment,
3226 GLuint texture,
3227 GLint level,
3228 GLsizei numViews,
3229 const GLint *viewportOffsets)
3230{
Martin Radev5dae57b2017-07-14 16:15:55 +03003231 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3232 ASSERT(framebuffer);
3233
3234 if (texture != 0)
3235 {
3236 Texture *textureObj = getTexture(texture);
3237
3238 ImageIndex index = ImageIndex::Make2D(level);
3239 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3240 textureObj, numViews, viewportOffsets);
3241 }
3242 else
3243 {
3244 framebuffer->resetAttachment(this, attachment);
3245 }
3246
3247 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003248}
3249
Jamie Madillc29968b2016-01-20 11:17:23 -05003250void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3251{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003252 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003253 ASSERT(framebuffer);
3254 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003255 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003256}
3257
3258void Context::readBuffer(GLenum mode)
3259{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003260 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003261 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003262 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003263}
3264
3265void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3266{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003267 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003268 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003269
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003270 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003271 ASSERT(framebuffer);
3272
3273 // The specification isn't clear what should be done when the framebuffer isn't complete.
3274 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003275 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003276}
3277
3278void Context::invalidateFramebuffer(GLenum target,
3279 GLsizei numAttachments,
3280 const GLenum *attachments)
3281{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003282 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003283 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003284
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003285 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003286 ASSERT(framebuffer);
3287
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003288 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003289 {
Jamie Madill437fa652016-05-03 15:13:24 -04003290 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003291 }
Jamie Madill437fa652016-05-03 15:13:24 -04003292
Jamie Madill4928b7c2017-06-20 12:57:39 -04003293 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003294}
3295
3296void Context::invalidateSubFramebuffer(GLenum target,
3297 GLsizei numAttachments,
3298 const GLenum *attachments,
3299 GLint x,
3300 GLint y,
3301 GLsizei width,
3302 GLsizei height)
3303{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003304 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003305 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003306
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003307 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003308 ASSERT(framebuffer);
3309
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003310 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003311 {
Jamie Madill437fa652016-05-03 15:13:24 -04003312 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003313 }
Jamie Madill437fa652016-05-03 15:13:24 -04003314
3315 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003316 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003317}
3318
Jamie Madill73a84962016-02-12 09:27:23 -05003319void Context::texImage2D(GLenum target,
3320 GLint level,
3321 GLint internalformat,
3322 GLsizei width,
3323 GLsizei height,
3324 GLint border,
3325 GLenum format,
3326 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003327 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003328{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003329 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003330
3331 Extents size(width, height, 1);
3332 Texture *texture =
3333 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003334 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3335 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003336}
3337
3338void Context::texImage3D(GLenum target,
3339 GLint level,
3340 GLint internalformat,
3341 GLsizei width,
3342 GLsizei height,
3343 GLsizei depth,
3344 GLint border,
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{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003349 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003350
3351 Extents size(width, height, depth);
3352 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003353 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3354 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003355}
3356
3357void Context::texSubImage2D(GLenum target,
3358 GLint level,
3359 GLint xoffset,
3360 GLint yoffset,
3361 GLsizei width,
3362 GLsizei height,
3363 GLenum format,
3364 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003365 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003366{
3367 // Zero sized uploads are valid but no-ops
3368 if (width == 0 || height == 0)
3369 {
3370 return;
3371 }
3372
Jamie Madillad9f24e2016-02-12 09:27:24 -05003373 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003374
3375 Box area(xoffset, yoffset, 0, width, height, 1);
3376 Texture *texture =
3377 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003378 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3379 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003380}
3381
3382void Context::texSubImage3D(GLenum target,
3383 GLint level,
3384 GLint xoffset,
3385 GLint yoffset,
3386 GLint zoffset,
3387 GLsizei width,
3388 GLsizei height,
3389 GLsizei depth,
3390 GLenum format,
3391 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003392 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003393{
3394 // Zero sized uploads are valid but no-ops
3395 if (width == 0 || height == 0 || depth == 0)
3396 {
3397 return;
3398 }
3399
Jamie Madillad9f24e2016-02-12 09:27:24 -05003400 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003401
3402 Box area(xoffset, yoffset, zoffset, width, height, depth);
3403 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003404 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3405 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003406}
3407
3408void Context::compressedTexImage2D(GLenum target,
3409 GLint level,
3410 GLenum internalformat,
3411 GLsizei width,
3412 GLsizei height,
3413 GLint border,
3414 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003415 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003416{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003417 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003418
3419 Extents size(width, height, 1);
3420 Texture *texture =
3421 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003422 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003423 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003424 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003425}
3426
3427void Context::compressedTexImage3D(GLenum target,
3428 GLint level,
3429 GLenum internalformat,
3430 GLsizei width,
3431 GLsizei height,
3432 GLsizei depth,
3433 GLint border,
3434 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003435 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003436{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003437 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003438
3439 Extents size(width, height, depth);
3440 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003441 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003442 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003443 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003444}
3445
3446void Context::compressedTexSubImage2D(GLenum target,
3447 GLint level,
3448 GLint xoffset,
3449 GLint yoffset,
3450 GLsizei width,
3451 GLsizei height,
3452 GLenum format,
3453 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003454 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003455{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003456 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003457
3458 Box area(xoffset, yoffset, 0, width, height, 1);
3459 Texture *texture =
3460 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003461 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003462 format, imageSize,
3463 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003464}
3465
3466void Context::compressedTexSubImage3D(GLenum target,
3467 GLint level,
3468 GLint xoffset,
3469 GLint yoffset,
3470 GLint zoffset,
3471 GLsizei width,
3472 GLsizei height,
3473 GLsizei depth,
3474 GLenum format,
3475 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003476 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003477{
3478 // Zero sized uploads are valid but no-ops
3479 if (width == 0 || height == 0)
3480 {
3481 return;
3482 }
3483
Jamie Madillad9f24e2016-02-12 09:27:24 -05003484 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003485
3486 Box area(xoffset, yoffset, zoffset, width, height, depth);
3487 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003488 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003489 format, imageSize,
3490 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003491}
3492
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003493void Context::generateMipmap(GLenum target)
3494{
3495 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003496 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003497}
3498
Jamie Madill007530e2017-12-28 14:27:04 -05003499void Context::copyTexture(GLuint sourceId,
3500 GLint sourceLevel,
3501 GLenum destTarget,
3502 GLuint destId,
3503 GLint destLevel,
3504 GLint internalFormat,
3505 GLenum destType,
3506 GLboolean unpackFlipY,
3507 GLboolean unpackPremultiplyAlpha,
3508 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003509{
3510 syncStateForTexImage();
3511
3512 gl::Texture *sourceTexture = getTexture(sourceId);
3513 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05003514 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
3515 sourceLevel, ConvertToBool(unpackFlipY),
3516 ConvertToBool(unpackPremultiplyAlpha),
3517 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003518}
3519
Jamie Madill007530e2017-12-28 14:27:04 -05003520void Context::copySubTexture(GLuint sourceId,
3521 GLint sourceLevel,
3522 GLenum destTarget,
3523 GLuint destId,
3524 GLint destLevel,
3525 GLint xoffset,
3526 GLint yoffset,
3527 GLint x,
3528 GLint y,
3529 GLsizei width,
3530 GLsizei height,
3531 GLboolean unpackFlipY,
3532 GLboolean unpackPremultiplyAlpha,
3533 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003534{
3535 // Zero sized copies are valid but no-ops
3536 if (width == 0 || height == 0)
3537 {
3538 return;
3539 }
3540
3541 syncStateForTexImage();
3542
3543 gl::Texture *sourceTexture = getTexture(sourceId);
3544 gl::Texture *destTexture = getTexture(destId);
3545 Offset offset(xoffset, yoffset, 0);
3546 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05003547 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
3548 ConvertToBool(unpackFlipY),
3549 ConvertToBool(unpackPremultiplyAlpha),
3550 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003551}
3552
Jamie Madill007530e2017-12-28 14:27:04 -05003553void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07003554{
3555 syncStateForTexImage();
3556
3557 gl::Texture *sourceTexture = getTexture(sourceId);
3558 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003559 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003560}
3561
Corentin Wallez336129f2017-10-17 15:55:40 -04003562void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003563{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003564 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003565 ASSERT(buffer);
3566
Geoff Lang496c02d2016-10-20 11:38:11 -07003567 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003568}
3569
Corentin Wallez336129f2017-10-17 15:55:40 -04003570void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003571{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003572 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003573 ASSERT(buffer);
3574
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003575 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003576 if (error.isError())
3577 {
Jamie Madill437fa652016-05-03 15:13:24 -04003578 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003579 return nullptr;
3580 }
3581
3582 return buffer->getMapPointer();
3583}
3584
Corentin Wallez336129f2017-10-17 15:55:40 -04003585GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003586{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003587 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003588 ASSERT(buffer);
3589
3590 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003591 Error error = buffer->unmap(this, &result);
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 GL_FALSE;
3596 }
3597
3598 return result;
3599}
3600
Corentin Wallez336129f2017-10-17 15:55:40 -04003601void *Context::mapBufferRange(BufferBinding target,
3602 GLintptr offset,
3603 GLsizeiptr length,
3604 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003605{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003606 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003607 ASSERT(buffer);
3608
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003609 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003610 if (error.isError())
3611 {
Jamie Madill437fa652016-05-03 15:13:24 -04003612 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003613 return nullptr;
3614 }
3615
3616 return buffer->getMapPointer();
3617}
3618
Corentin Wallez336129f2017-10-17 15:55:40 -04003619void Context::flushMappedBufferRange(BufferBinding /*target*/,
3620 GLintptr /*offset*/,
3621 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03003622{
3623 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3624}
3625
Jamie Madillad9f24e2016-02-12 09:27:24 -05003626void Context::syncStateForReadPixels()
3627{
3628 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3629}
3630
3631void Context::syncStateForTexImage()
3632{
3633 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3634}
3635
3636void Context::syncStateForClear()
3637{
3638 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3639}
3640
3641void Context::syncStateForBlit()
3642{
3643 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3644}
3645
Jiajia Qin5451d532017-11-16 17:16:34 +08003646void Context::activeShaderProgram(GLuint pipeline, GLuint program)
3647{
3648 UNIMPLEMENTED();
3649}
3650
Jamie Madillc20ab272016-06-09 07:20:46 -07003651void Context::activeTexture(GLenum texture)
3652{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003653 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003654}
3655
Jamie Madill876429b2017-04-20 15:46:24 -04003656void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003657{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003658 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003659}
3660
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003661void Context::blendEquation(GLenum mode)
3662{
3663 mGLState.setBlendEquation(mode, mode);
3664}
3665
Jamie Madillc20ab272016-06-09 07:20:46 -07003666void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3667{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003668 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003669}
3670
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003671void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3672{
3673 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3674}
3675
Jamie Madillc20ab272016-06-09 07:20:46 -07003676void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3677{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003678 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003679}
3680
Jamie Madill876429b2017-04-20 15:46:24 -04003681void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003682{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003683 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003684}
3685
Jamie Madill876429b2017-04-20 15:46:24 -04003686void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003687{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003688 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003689}
3690
3691void Context::clearStencil(GLint s)
3692{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003693 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003694}
3695
3696void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3697{
Geoff Lang92019432017-11-20 13:09:34 -05003698 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
3699 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003700}
3701
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003702void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003703{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003704 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003705}
3706
3707void Context::depthFunc(GLenum func)
3708{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003709 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003710}
3711
3712void Context::depthMask(GLboolean flag)
3713{
Geoff Lang92019432017-11-20 13:09:34 -05003714 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07003715}
3716
Jamie Madill876429b2017-04-20 15:46:24 -04003717void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003718{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003719 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003720}
3721
3722void Context::disable(GLenum cap)
3723{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003724 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003725}
3726
3727void Context::disableVertexAttribArray(GLuint index)
3728{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003729 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003730}
3731
3732void Context::enable(GLenum cap)
3733{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003734 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003735}
3736
3737void Context::enableVertexAttribArray(GLuint index)
3738{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003739 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003740}
3741
3742void Context::frontFace(GLenum mode)
3743{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003744 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003745}
3746
3747void Context::hint(GLenum target, GLenum mode)
3748{
3749 switch (target)
3750 {
3751 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003752 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003753 break;
3754
3755 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003756 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003757 break;
3758
3759 default:
3760 UNREACHABLE();
3761 return;
3762 }
3763}
3764
3765void Context::lineWidth(GLfloat width)
3766{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003767 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003768}
3769
3770void Context::pixelStorei(GLenum pname, GLint param)
3771{
3772 switch (pname)
3773 {
3774 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003775 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003776 break;
3777
3778 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003779 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003780 break;
3781
3782 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003783 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003784 break;
3785
3786 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003787 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003788 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003789 break;
3790
3791 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003792 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003793 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003794 break;
3795
3796 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003797 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003798 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003799 break;
3800
3801 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003802 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003803 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003804 break;
3805
3806 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003807 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003808 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003809 break;
3810
3811 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003812 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003813 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003814 break;
3815
3816 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003817 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003818 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003819 break;
3820
3821 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003822 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003823 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003824 break;
3825
3826 default:
3827 UNREACHABLE();
3828 return;
3829 }
3830}
3831
3832void Context::polygonOffset(GLfloat factor, GLfloat units)
3833{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003834 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003835}
3836
Jamie Madill876429b2017-04-20 15:46:24 -04003837void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003838{
Geoff Lang92019432017-11-20 13:09:34 -05003839 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07003840}
3841
Jiawei Shaodb342272017-09-27 10:21:45 +08003842void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3843{
3844 mGLState.setSampleMaskParams(maskNumber, mask);
3845}
3846
Jamie Madillc20ab272016-06-09 07:20:46 -07003847void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3848{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003849 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003850}
3851
3852void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3853{
3854 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3855 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003856 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003857 }
3858
3859 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3860 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003861 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003862 }
3863}
3864
3865void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3866{
3867 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3868 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003869 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003870 }
3871
3872 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3873 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003874 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003875 }
3876}
3877
3878void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3879{
3880 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3881 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003882 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003883 }
3884
3885 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3886 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003887 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003888 }
3889}
3890
3891void Context::vertexAttrib1f(GLuint index, GLfloat x)
3892{
3893 GLfloat vals[4] = {x, 0, 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::vertexAttrib1fv(GLuint index, const GLfloat *values)
3898{
3899 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003900 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003901}
3902
3903void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3904{
3905 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003906 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003907}
3908
3909void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3910{
3911 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003912 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003913}
3914
3915void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3916{
3917 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003918 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003919}
3920
3921void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3922{
3923 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003924 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003925}
3926
3927void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3928{
3929 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003930 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003931}
3932
3933void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3934{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003935 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003936}
3937
3938void Context::vertexAttribPointer(GLuint index,
3939 GLint size,
3940 GLenum type,
3941 GLboolean normalized,
3942 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003943 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003944{
Corentin Wallez336129f2017-10-17 15:55:40 -04003945 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05003946 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003947}
3948
Shao80957d92017-02-20 21:25:59 +08003949void Context::vertexAttribFormat(GLuint attribIndex,
3950 GLint size,
3951 GLenum type,
3952 GLboolean normalized,
3953 GLuint relativeOffset)
3954{
Geoff Lang92019432017-11-20 13:09:34 -05003955 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08003956 relativeOffset);
3957}
3958
3959void Context::vertexAttribIFormat(GLuint attribIndex,
3960 GLint size,
3961 GLenum type,
3962 GLuint relativeOffset)
3963{
3964 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3965}
3966
3967void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3968{
Shaodde78e82017-05-22 14:13:27 +08003969 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08003970}
3971
Jiajia Qin5451d532017-11-16 17:16:34 +08003972void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08003973{
3974 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3975}
3976
Jamie Madillc20ab272016-06-09 07:20:46 -07003977void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3978{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003979 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003980}
3981
3982void Context::vertexAttribIPointer(GLuint index,
3983 GLint size,
3984 GLenum type,
3985 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003986 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003987{
Corentin Wallez336129f2017-10-17 15:55:40 -04003988 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
3989 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003990}
3991
3992void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3993{
3994 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003995 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003996}
3997
3998void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
3999{
4000 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004001 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004002}
4003
4004void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4005{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004006 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004007}
4008
4009void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4010{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004011 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004012}
4013
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004014void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4015{
4016 const VertexAttribCurrentValueData &currentValues =
4017 getGLState().getVertexAttribCurrentValue(index);
4018 const VertexArray *vao = getGLState().getVertexArray();
4019 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4020 currentValues, pname, params);
4021}
4022
4023void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4024{
4025 const VertexAttribCurrentValueData &currentValues =
4026 getGLState().getVertexAttribCurrentValue(index);
4027 const VertexArray *vao = getGLState().getVertexArray();
4028 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4029 currentValues, pname, params);
4030}
4031
4032void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4033{
4034 const VertexAttribCurrentValueData &currentValues =
4035 getGLState().getVertexAttribCurrentValue(index);
4036 const VertexArray *vao = getGLState().getVertexArray();
4037 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4038 currentValues, pname, params);
4039}
4040
4041void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4042{
4043 const VertexAttribCurrentValueData &currentValues =
4044 getGLState().getVertexAttribCurrentValue(index);
4045 const VertexArray *vao = getGLState().getVertexArray();
4046 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4047 currentValues, pname, params);
4048}
4049
Jamie Madill876429b2017-04-20 15:46:24 -04004050void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004051{
4052 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4053 QueryVertexAttribPointerv(attrib, pname, pointer);
4054}
4055
Jamie Madillc20ab272016-06-09 07:20:46 -07004056void Context::debugMessageControl(GLenum source,
4057 GLenum type,
4058 GLenum severity,
4059 GLsizei count,
4060 const GLuint *ids,
4061 GLboolean enabled)
4062{
4063 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004064 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004065 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004066}
4067
4068void Context::debugMessageInsert(GLenum source,
4069 GLenum type,
4070 GLuint id,
4071 GLenum severity,
4072 GLsizei length,
4073 const GLchar *buf)
4074{
4075 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004076 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004077}
4078
4079void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4080{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004081 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004082}
4083
4084GLuint Context::getDebugMessageLog(GLuint count,
4085 GLsizei bufSize,
4086 GLenum *sources,
4087 GLenum *types,
4088 GLuint *ids,
4089 GLenum *severities,
4090 GLsizei *lengths,
4091 GLchar *messageLog)
4092{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004093 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4094 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004095}
4096
4097void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4098{
4099 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004100 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004101 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004102}
4103
4104void Context::popDebugGroup()
4105{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004106 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004107 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004108}
4109
Corentin Wallez336129f2017-10-17 15:55:40 -04004110void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004111{
4112 Buffer *buffer = mGLState.getTargetBuffer(target);
4113 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004114 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004115}
4116
Corentin Wallez336129f2017-10-17 15:55:40 -04004117void Context::bufferSubData(BufferBinding target,
4118 GLintptr offset,
4119 GLsizeiptr size,
4120 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004121{
4122 if (data == nullptr)
4123 {
4124 return;
4125 }
4126
4127 Buffer *buffer = mGLState.getTargetBuffer(target);
4128 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004129 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004130}
4131
Jamie Madillef300b12016-10-07 15:12:09 -04004132void Context::attachShader(GLuint program, GLuint shader)
4133{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004134 Program *programObject = mState.mShaderPrograms->getProgram(program);
4135 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004136 ASSERT(programObject && shaderObject);
4137 programObject->attachShader(shaderObject);
4138}
4139
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004140const Workarounds &Context::getWorkarounds() const
4141{
4142 return mWorkarounds;
4143}
4144
Corentin Wallez336129f2017-10-17 15:55:40 -04004145void Context::copyBufferSubData(BufferBinding readTarget,
4146 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004147 GLintptr readOffset,
4148 GLintptr writeOffset,
4149 GLsizeiptr size)
4150{
4151 // if size is zero, the copy is a successful no-op
4152 if (size == 0)
4153 {
4154 return;
4155 }
4156
4157 // TODO(jmadill): cache these.
4158 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4159 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4160
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004161 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004162}
4163
Jamie Madill01a80ee2016-11-07 12:06:18 -05004164void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4165{
4166 Program *programObject = getProgram(program);
4167 // TODO(jmadill): Re-use this from the validation if possible.
4168 ASSERT(programObject);
4169 programObject->bindAttributeLocation(index, name);
4170}
4171
Corentin Wallez336129f2017-10-17 15:55:40 -04004172void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004173{
Corentin Wallez336129f2017-10-17 15:55:40 -04004174 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4175 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004176}
4177
Corentin Wallez336129f2017-10-17 15:55:40 -04004178void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004179{
4180 bindBufferRange(target, index, buffer, 0, 0);
4181}
4182
Corentin Wallez336129f2017-10-17 15:55:40 -04004183void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004184 GLuint index,
4185 GLuint buffer,
4186 GLintptr offset,
4187 GLsizeiptr size)
4188{
Corentin Wallez336129f2017-10-17 15:55:40 -04004189 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4190 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004191}
4192
Jamie Madill01a80ee2016-11-07 12:06:18 -05004193void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4194{
4195 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4196 {
4197 bindReadFramebuffer(framebuffer);
4198 }
4199
4200 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4201 {
4202 bindDrawFramebuffer(framebuffer);
4203 }
4204}
4205
4206void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4207{
4208 ASSERT(target == GL_RENDERBUFFER);
4209 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004210 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004211 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004212}
4213
JiangYizhoubddc46b2016-12-09 09:50:51 +08004214void Context::texStorage2DMultisample(GLenum target,
4215 GLsizei samples,
4216 GLenum internalformat,
4217 GLsizei width,
4218 GLsizei height,
4219 GLboolean fixedsamplelocations)
4220{
4221 Extents size(width, height, 1);
4222 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004223 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
Geoff Lang92019432017-11-20 13:09:34 -05004224 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004225}
4226
4227void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4228{
JiangYizhou5b03f472017-01-09 10:22:53 +08004229 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4230 // the sample position should be queried by DRAW_FRAMEBUFFER.
4231 mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER);
4232 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004233
4234 switch (pname)
4235 {
4236 case GL_SAMPLE_POSITION:
4237 handleError(framebuffer->getSamplePosition(index, val));
4238 break;
4239 default:
4240 UNREACHABLE();
4241 }
4242}
4243
Jamie Madille8fb6402017-02-14 17:56:40 -05004244void Context::renderbufferStorage(GLenum target,
4245 GLenum internalformat,
4246 GLsizei width,
4247 GLsizei height)
4248{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004249 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4250 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4251
Jamie Madille8fb6402017-02-14 17:56:40 -05004252 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004253 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004254}
4255
4256void Context::renderbufferStorageMultisample(GLenum target,
4257 GLsizei samples,
4258 GLenum internalformat,
4259 GLsizei width,
4260 GLsizei height)
4261{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004262 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4263 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004264
4265 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004266 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004267 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004268}
4269
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004270void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4271{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004272 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004273 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004274}
4275
JiangYizhoue18e6392017-02-20 10:32:23 +08004276void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4277{
4278 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4279 QueryFramebufferParameteriv(framebuffer, pname, params);
4280}
4281
Jiajia Qin5451d532017-11-16 17:16:34 +08004282void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004283{
4284 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4285 SetFramebufferParameteri(framebuffer, pname, param);
4286}
4287
Jamie Madillb3f26b92017-07-19 15:07:41 -04004288Error Context::getScratchBuffer(size_t requstedSizeBytes,
4289 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004290{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004291 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4292 {
4293 return OutOfMemory() << "Failed to allocate internal buffer.";
4294 }
4295 return NoError();
4296}
4297
4298Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4299 angle::MemoryBuffer **zeroBufferOut) const
4300{
4301 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004302 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004303 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004304 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004305 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004306}
4307
Xinghua Cao10a4d432017-11-28 14:46:26 +08004308Error Context::prepareForDispatch()
4309{
4310 syncRendererState(mComputeDirtyBits, mComputeDirtyObjects);
4311
4312 if (isRobustResourceInitEnabled())
4313 {
4314 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4315 }
4316
4317 return NoError();
4318}
4319
Xinghua Cao2b396592017-03-29 15:36:04 +08004320void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4321{
4322 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4323 {
4324 return;
4325 }
4326
Xinghua Cao10a4d432017-11-28 14:46:26 +08004327 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004328 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004329}
4330
Jiajia Qin5451d532017-11-16 17:16:34 +08004331void Context::dispatchComputeIndirect(GLintptr indirect)
4332{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004333 ANGLE_CONTEXT_TRY(prepareForDispatch());
4334 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004335}
4336
JiangYizhou165361c2017-06-07 14:56:57 +08004337void Context::texStorage2D(GLenum target,
4338 GLsizei levels,
4339 GLenum internalFormat,
4340 GLsizei width,
4341 GLsizei height)
4342{
4343 Extents size(width, height, 1);
4344 Texture *texture = getTargetTexture(target);
4345 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4346}
4347
4348void Context::texStorage3D(GLenum target,
4349 GLsizei levels,
4350 GLenum internalFormat,
4351 GLsizei width,
4352 GLsizei height,
4353 GLsizei depth)
4354{
4355 Extents size(width, height, depth);
4356 Texture *texture = getTargetTexture(target);
4357 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4358}
4359
Jiajia Qin5451d532017-11-16 17:16:34 +08004360void Context::memoryBarrier(GLbitfield barriers)
4361{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004362 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004363}
4364
4365void Context::memoryBarrierByRegion(GLbitfield barriers)
4366{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004367 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004368}
4369
Jamie Madillc1d770e2017-04-13 17:31:24 -04004370GLenum Context::checkFramebufferStatus(GLenum target)
4371{
4372 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4373 ASSERT(framebuffer);
4374
4375 return framebuffer->checkStatus(this);
4376}
4377
4378void Context::compileShader(GLuint shader)
4379{
4380 Shader *shaderObject = GetValidShader(this, shader);
4381 if (!shaderObject)
4382 {
4383 return;
4384 }
4385 shaderObject->compile(this);
4386}
4387
4388void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4389{
4390 for (int i = 0; i < n; i++)
4391 {
4392 deleteBuffer(buffers[i]);
4393 }
4394}
4395
4396void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4397{
4398 for (int i = 0; i < n; i++)
4399 {
4400 if (framebuffers[i] != 0)
4401 {
4402 deleteFramebuffer(framebuffers[i]);
4403 }
4404 }
4405}
4406
4407void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4408{
4409 for (int i = 0; i < n; i++)
4410 {
4411 deleteRenderbuffer(renderbuffers[i]);
4412 }
4413}
4414
4415void Context::deleteTextures(GLsizei n, const GLuint *textures)
4416{
4417 for (int i = 0; i < n; i++)
4418 {
4419 if (textures[i] != 0)
4420 {
4421 deleteTexture(textures[i]);
4422 }
4423 }
4424}
4425
4426void Context::detachShader(GLuint program, GLuint shader)
4427{
4428 Program *programObject = getProgram(program);
4429 ASSERT(programObject);
4430
4431 Shader *shaderObject = getShader(shader);
4432 ASSERT(shaderObject);
4433
4434 programObject->detachShader(this, shaderObject);
4435}
4436
4437void Context::genBuffers(GLsizei n, GLuint *buffers)
4438{
4439 for (int i = 0; i < n; i++)
4440 {
4441 buffers[i] = createBuffer();
4442 }
4443}
4444
4445void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4446{
4447 for (int i = 0; i < n; i++)
4448 {
4449 framebuffers[i] = createFramebuffer();
4450 }
4451}
4452
4453void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4454{
4455 for (int i = 0; i < n; i++)
4456 {
4457 renderbuffers[i] = createRenderbuffer();
4458 }
4459}
4460
4461void Context::genTextures(GLsizei n, GLuint *textures)
4462{
4463 for (int i = 0; i < n; i++)
4464 {
4465 textures[i] = createTexture();
4466 }
4467}
4468
4469void Context::getActiveAttrib(GLuint program,
4470 GLuint index,
4471 GLsizei bufsize,
4472 GLsizei *length,
4473 GLint *size,
4474 GLenum *type,
4475 GLchar *name)
4476{
4477 Program *programObject = getProgram(program);
4478 ASSERT(programObject);
4479 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4480}
4481
4482void Context::getActiveUniform(GLuint program,
4483 GLuint index,
4484 GLsizei bufsize,
4485 GLsizei *length,
4486 GLint *size,
4487 GLenum *type,
4488 GLchar *name)
4489{
4490 Program *programObject = getProgram(program);
4491 ASSERT(programObject);
4492 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4493}
4494
4495void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4496{
4497 Program *programObject = getProgram(program);
4498 ASSERT(programObject);
4499 programObject->getAttachedShaders(maxcount, count, shaders);
4500}
4501
4502GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4503{
4504 Program *programObject = getProgram(program);
4505 ASSERT(programObject);
4506 return programObject->getAttributeLocation(name);
4507}
4508
4509void Context::getBooleanv(GLenum pname, GLboolean *params)
4510{
4511 GLenum nativeType;
4512 unsigned int numParams = 0;
4513 getQueryParameterInfo(pname, &nativeType, &numParams);
4514
4515 if (nativeType == GL_BOOL)
4516 {
4517 getBooleanvImpl(pname, params);
4518 }
4519 else
4520 {
4521 CastStateValues(this, nativeType, pname, numParams, params);
4522 }
4523}
4524
4525void Context::getFloatv(GLenum pname, GLfloat *params)
4526{
4527 GLenum nativeType;
4528 unsigned int numParams = 0;
4529 getQueryParameterInfo(pname, &nativeType, &numParams);
4530
4531 if (nativeType == GL_FLOAT)
4532 {
4533 getFloatvImpl(pname, params);
4534 }
4535 else
4536 {
4537 CastStateValues(this, nativeType, pname, numParams, params);
4538 }
4539}
4540
4541void Context::getIntegerv(GLenum pname, GLint *params)
4542{
4543 GLenum nativeType;
4544 unsigned int numParams = 0;
4545 getQueryParameterInfo(pname, &nativeType, &numParams);
4546
4547 if (nativeType == GL_INT)
4548 {
4549 getIntegervImpl(pname, params);
4550 }
4551 else
4552 {
4553 CastStateValues(this, nativeType, pname, numParams, params);
4554 }
4555}
4556
4557void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4558{
4559 Program *programObject = getProgram(program);
4560 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004561 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004562}
4563
Jiajia Qin5451d532017-11-16 17:16:34 +08004564void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
4565{
4566 UNIMPLEMENTED();
4567}
4568
Jamie Madillbe849e42017-05-02 15:49:00 -04004569void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004570{
4571 Program *programObject = getProgram(program);
4572 ASSERT(programObject);
4573 programObject->getInfoLog(bufsize, length, infolog);
4574}
4575
Jiajia Qin5451d532017-11-16 17:16:34 +08004576void Context::getProgramPipelineInfoLog(GLuint pipeline,
4577 GLsizei bufSize,
4578 GLsizei *length,
4579 GLchar *infoLog)
4580{
4581 UNIMPLEMENTED();
4582}
4583
Jamie Madillc1d770e2017-04-13 17:31:24 -04004584void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4585{
4586 Shader *shaderObject = getShader(shader);
4587 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004588 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004589}
4590
4591void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4592{
4593 Shader *shaderObject = getShader(shader);
4594 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004595 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004596}
4597
4598void Context::getShaderPrecisionFormat(GLenum shadertype,
4599 GLenum precisiontype,
4600 GLint *range,
4601 GLint *precision)
4602{
4603 // TODO(jmadill): Compute shaders.
4604
4605 switch (shadertype)
4606 {
4607 case GL_VERTEX_SHADER:
4608 switch (precisiontype)
4609 {
4610 case GL_LOW_FLOAT:
4611 mCaps.vertexLowpFloat.get(range, precision);
4612 break;
4613 case GL_MEDIUM_FLOAT:
4614 mCaps.vertexMediumpFloat.get(range, precision);
4615 break;
4616 case GL_HIGH_FLOAT:
4617 mCaps.vertexHighpFloat.get(range, precision);
4618 break;
4619
4620 case GL_LOW_INT:
4621 mCaps.vertexLowpInt.get(range, precision);
4622 break;
4623 case GL_MEDIUM_INT:
4624 mCaps.vertexMediumpInt.get(range, precision);
4625 break;
4626 case GL_HIGH_INT:
4627 mCaps.vertexHighpInt.get(range, precision);
4628 break;
4629
4630 default:
4631 UNREACHABLE();
4632 return;
4633 }
4634 break;
4635
4636 case GL_FRAGMENT_SHADER:
4637 switch (precisiontype)
4638 {
4639 case GL_LOW_FLOAT:
4640 mCaps.fragmentLowpFloat.get(range, precision);
4641 break;
4642 case GL_MEDIUM_FLOAT:
4643 mCaps.fragmentMediumpFloat.get(range, precision);
4644 break;
4645 case GL_HIGH_FLOAT:
4646 mCaps.fragmentHighpFloat.get(range, precision);
4647 break;
4648
4649 case GL_LOW_INT:
4650 mCaps.fragmentLowpInt.get(range, precision);
4651 break;
4652 case GL_MEDIUM_INT:
4653 mCaps.fragmentMediumpInt.get(range, precision);
4654 break;
4655 case GL_HIGH_INT:
4656 mCaps.fragmentHighpInt.get(range, precision);
4657 break;
4658
4659 default:
4660 UNREACHABLE();
4661 return;
4662 }
4663 break;
4664
4665 default:
4666 UNREACHABLE();
4667 return;
4668 }
4669}
4670
4671void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4672{
4673 Shader *shaderObject = getShader(shader);
4674 ASSERT(shaderObject);
4675 shaderObject->getSource(bufsize, length, source);
4676}
4677
4678void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4679{
4680 Program *programObject = getProgram(program);
4681 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004682 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004683}
4684
4685void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4686{
4687 Program *programObject = getProgram(program);
4688 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004689 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004690}
4691
4692GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4693{
4694 Program *programObject = getProgram(program);
4695 ASSERT(programObject);
4696 return programObject->getUniformLocation(name);
4697}
4698
4699GLboolean Context::isBuffer(GLuint buffer)
4700{
4701 if (buffer == 0)
4702 {
4703 return GL_FALSE;
4704 }
4705
4706 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4707}
4708
4709GLboolean Context::isEnabled(GLenum cap)
4710{
4711 return mGLState.getEnableFeature(cap);
4712}
4713
4714GLboolean Context::isFramebuffer(GLuint framebuffer)
4715{
4716 if (framebuffer == 0)
4717 {
4718 return GL_FALSE;
4719 }
4720
4721 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4722}
4723
4724GLboolean Context::isProgram(GLuint program)
4725{
4726 if (program == 0)
4727 {
4728 return GL_FALSE;
4729 }
4730
4731 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4732}
4733
4734GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4735{
4736 if (renderbuffer == 0)
4737 {
4738 return GL_FALSE;
4739 }
4740
4741 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4742}
4743
4744GLboolean Context::isShader(GLuint shader)
4745{
4746 if (shader == 0)
4747 {
4748 return GL_FALSE;
4749 }
4750
4751 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4752}
4753
4754GLboolean Context::isTexture(GLuint texture)
4755{
4756 if (texture == 0)
4757 {
4758 return GL_FALSE;
4759 }
4760
4761 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4762}
4763
4764void Context::linkProgram(GLuint program)
4765{
4766 Program *programObject = getProgram(program);
4767 ASSERT(programObject);
4768 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004769 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004770}
4771
4772void Context::releaseShaderCompiler()
4773{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004774 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004775}
4776
4777void Context::shaderBinary(GLsizei n,
4778 const GLuint *shaders,
4779 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004780 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004781 GLsizei length)
4782{
4783 // No binary shader formats are supported.
4784 UNIMPLEMENTED();
4785}
4786
4787void Context::shaderSource(GLuint shader,
4788 GLsizei count,
4789 const GLchar *const *string,
4790 const GLint *length)
4791{
4792 Shader *shaderObject = getShader(shader);
4793 ASSERT(shaderObject);
4794 shaderObject->setSource(count, string, length);
4795}
4796
4797void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4798{
4799 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4800}
4801
4802void Context::stencilMask(GLuint mask)
4803{
4804 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4805}
4806
4807void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4808{
4809 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4810}
4811
4812void Context::uniform1f(GLint location, GLfloat x)
4813{
4814 Program *program = mGLState.getProgram();
4815 program->setUniform1fv(location, 1, &x);
4816}
4817
4818void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4819{
4820 Program *program = mGLState.getProgram();
4821 program->setUniform1fv(location, count, v);
4822}
4823
4824void Context::uniform1i(GLint location, GLint x)
4825{
4826 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004827 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4828 {
4829 mGLState.setObjectDirty(GL_PROGRAM);
4830 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004831}
4832
4833void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4834{
4835 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004836 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4837 {
4838 mGLState.setObjectDirty(GL_PROGRAM);
4839 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004840}
4841
4842void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4843{
4844 GLfloat xy[2] = {x, y};
4845 Program *program = mGLState.getProgram();
4846 program->setUniform2fv(location, 1, xy);
4847}
4848
4849void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4850{
4851 Program *program = mGLState.getProgram();
4852 program->setUniform2fv(location, count, v);
4853}
4854
4855void Context::uniform2i(GLint location, GLint x, GLint y)
4856{
4857 GLint xy[2] = {x, y};
4858 Program *program = mGLState.getProgram();
4859 program->setUniform2iv(location, 1, xy);
4860}
4861
4862void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4863{
4864 Program *program = mGLState.getProgram();
4865 program->setUniform2iv(location, count, v);
4866}
4867
4868void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4869{
4870 GLfloat xyz[3] = {x, y, z};
4871 Program *program = mGLState.getProgram();
4872 program->setUniform3fv(location, 1, xyz);
4873}
4874
4875void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4876{
4877 Program *program = mGLState.getProgram();
4878 program->setUniform3fv(location, count, v);
4879}
4880
4881void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4882{
4883 GLint xyz[3] = {x, y, z};
4884 Program *program = mGLState.getProgram();
4885 program->setUniform3iv(location, 1, xyz);
4886}
4887
4888void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4889{
4890 Program *program = mGLState.getProgram();
4891 program->setUniform3iv(location, count, v);
4892}
4893
4894void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4895{
4896 GLfloat xyzw[4] = {x, y, z, w};
4897 Program *program = mGLState.getProgram();
4898 program->setUniform4fv(location, 1, xyzw);
4899}
4900
4901void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4902{
4903 Program *program = mGLState.getProgram();
4904 program->setUniform4fv(location, count, v);
4905}
4906
4907void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4908{
4909 GLint xyzw[4] = {x, y, z, w};
4910 Program *program = mGLState.getProgram();
4911 program->setUniform4iv(location, 1, xyzw);
4912}
4913
4914void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4915{
4916 Program *program = mGLState.getProgram();
4917 program->setUniform4iv(location, count, v);
4918}
4919
4920void Context::uniformMatrix2fv(GLint location,
4921 GLsizei count,
4922 GLboolean transpose,
4923 const GLfloat *value)
4924{
4925 Program *program = mGLState.getProgram();
4926 program->setUniformMatrix2fv(location, count, transpose, value);
4927}
4928
4929void Context::uniformMatrix3fv(GLint location,
4930 GLsizei count,
4931 GLboolean transpose,
4932 const GLfloat *value)
4933{
4934 Program *program = mGLState.getProgram();
4935 program->setUniformMatrix3fv(location, count, transpose, value);
4936}
4937
4938void Context::uniformMatrix4fv(GLint location,
4939 GLsizei count,
4940 GLboolean transpose,
4941 const GLfloat *value)
4942{
4943 Program *program = mGLState.getProgram();
4944 program->setUniformMatrix4fv(location, count, transpose, value);
4945}
4946
4947void Context::validateProgram(GLuint program)
4948{
4949 Program *programObject = getProgram(program);
4950 ASSERT(programObject);
4951 programObject->validate(mCaps);
4952}
4953
Jiajia Qin5451d532017-11-16 17:16:34 +08004954void Context::validateProgramPipeline(GLuint pipeline)
4955{
4956 UNIMPLEMENTED();
4957}
4958
Jamie Madilld04908b2017-06-09 14:15:35 -04004959void Context::getProgramBinary(GLuint program,
4960 GLsizei bufSize,
4961 GLsizei *length,
4962 GLenum *binaryFormat,
4963 void *binary)
4964{
4965 Program *programObject = getProgram(program);
4966 ASSERT(programObject != nullptr);
4967
4968 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4969}
4970
4971void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4972{
4973 Program *programObject = getProgram(program);
4974 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04004975
Jamie Madilld04908b2017-06-09 14:15:35 -04004976 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
4977}
4978
Jamie Madillff325f12017-08-26 15:06:05 -04004979void Context::uniform1ui(GLint location, GLuint v0)
4980{
4981 Program *program = mGLState.getProgram();
4982 program->setUniform1uiv(location, 1, &v0);
4983}
4984
4985void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
4986{
4987 Program *program = mGLState.getProgram();
4988 const GLuint xy[] = {v0, v1};
4989 program->setUniform2uiv(location, 1, xy);
4990}
4991
4992void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
4993{
4994 Program *program = mGLState.getProgram();
4995 const GLuint xyz[] = {v0, v1, v2};
4996 program->setUniform3uiv(location, 1, xyz);
4997}
4998
4999void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5000{
5001 Program *program = mGLState.getProgram();
5002 const GLuint xyzw[] = {v0, v1, v2, v3};
5003 program->setUniform4uiv(location, 1, xyzw);
5004}
5005
5006void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5007{
5008 Program *program = mGLState.getProgram();
5009 program->setUniform1uiv(location, count, value);
5010}
5011void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5012{
5013 Program *program = mGLState.getProgram();
5014 program->setUniform2uiv(location, count, value);
5015}
5016
5017void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5018{
5019 Program *program = mGLState.getProgram();
5020 program->setUniform3uiv(location, count, value);
5021}
5022
5023void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5024{
5025 Program *program = mGLState.getProgram();
5026 program->setUniform4uiv(location, count, value);
5027}
5028
Jamie Madillf0e04492017-08-26 15:28:42 -04005029void Context::genQueries(GLsizei n, GLuint *ids)
5030{
5031 for (GLsizei i = 0; i < n; i++)
5032 {
5033 GLuint handle = mQueryHandleAllocator.allocate();
5034 mQueryMap.assign(handle, nullptr);
5035 ids[i] = handle;
5036 }
5037}
5038
5039void Context::deleteQueries(GLsizei n, const GLuint *ids)
5040{
5041 for (int i = 0; i < n; i++)
5042 {
5043 GLuint query = ids[i];
5044
5045 Query *queryObject = nullptr;
5046 if (mQueryMap.erase(query, &queryObject))
5047 {
5048 mQueryHandleAllocator.release(query);
5049 if (queryObject)
5050 {
5051 queryObject->release(this);
5052 }
5053 }
5054 }
5055}
5056
5057GLboolean Context::isQuery(GLuint id)
5058{
5059 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
5060}
5061
Jamie Madillc8c95812017-08-26 18:40:09 -04005062void Context::uniformMatrix2x3fv(GLint location,
5063 GLsizei count,
5064 GLboolean transpose,
5065 const GLfloat *value)
5066{
5067 Program *program = mGLState.getProgram();
5068 program->setUniformMatrix2x3fv(location, count, transpose, value);
5069}
5070
5071void Context::uniformMatrix3x2fv(GLint location,
5072 GLsizei count,
5073 GLboolean transpose,
5074 const GLfloat *value)
5075{
5076 Program *program = mGLState.getProgram();
5077 program->setUniformMatrix3x2fv(location, count, transpose, value);
5078}
5079
5080void Context::uniformMatrix2x4fv(GLint location,
5081 GLsizei count,
5082 GLboolean transpose,
5083 const GLfloat *value)
5084{
5085 Program *program = mGLState.getProgram();
5086 program->setUniformMatrix2x4fv(location, count, transpose, value);
5087}
5088
5089void Context::uniformMatrix4x2fv(GLint location,
5090 GLsizei count,
5091 GLboolean transpose,
5092 const GLfloat *value)
5093{
5094 Program *program = mGLState.getProgram();
5095 program->setUniformMatrix4x2fv(location, count, transpose, value);
5096}
5097
5098void Context::uniformMatrix3x4fv(GLint location,
5099 GLsizei count,
5100 GLboolean transpose,
5101 const GLfloat *value)
5102{
5103 Program *program = mGLState.getProgram();
5104 program->setUniformMatrix3x4fv(location, count, transpose, value);
5105}
5106
5107void Context::uniformMatrix4x3fv(GLint location,
5108 GLsizei count,
5109 GLboolean transpose,
5110 const GLfloat *value)
5111{
5112 Program *program = mGLState.getProgram();
5113 program->setUniformMatrix4x3fv(location, count, transpose, value);
5114}
5115
Jamie Madilld7576732017-08-26 18:49:50 -04005116void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5117{
5118 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5119 {
5120 GLuint vertexArray = arrays[arrayIndex];
5121
5122 if (arrays[arrayIndex] != 0)
5123 {
5124 VertexArray *vertexArrayObject = nullptr;
5125 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5126 {
5127 if (vertexArrayObject != nullptr)
5128 {
5129 detachVertexArray(vertexArray);
5130 vertexArrayObject->onDestroy(this);
5131 }
5132
5133 mVertexArrayHandleAllocator.release(vertexArray);
5134 }
5135 }
5136 }
5137}
5138
5139void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5140{
5141 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5142 {
5143 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5144 mVertexArrayMap.assign(vertexArray, nullptr);
5145 arrays[arrayIndex] = vertexArray;
5146 }
5147}
5148
5149bool Context::isVertexArray(GLuint array)
5150{
5151 if (array == 0)
5152 {
5153 return GL_FALSE;
5154 }
5155
5156 VertexArray *vao = getVertexArray(array);
5157 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5158}
5159
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005160void Context::endTransformFeedback()
5161{
5162 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5163 transformFeedback->end(this);
5164}
5165
5166void Context::transformFeedbackVaryings(GLuint program,
5167 GLsizei count,
5168 const GLchar *const *varyings,
5169 GLenum bufferMode)
5170{
5171 Program *programObject = getProgram(program);
5172 ASSERT(programObject);
5173 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5174}
5175
5176void Context::getTransformFeedbackVarying(GLuint program,
5177 GLuint index,
5178 GLsizei bufSize,
5179 GLsizei *length,
5180 GLsizei *size,
5181 GLenum *type,
5182 GLchar *name)
5183{
5184 Program *programObject = getProgram(program);
5185 ASSERT(programObject);
5186 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5187}
5188
5189void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5190{
5191 for (int i = 0; i < n; i++)
5192 {
5193 GLuint transformFeedback = ids[i];
5194 if (transformFeedback == 0)
5195 {
5196 continue;
5197 }
5198
5199 TransformFeedback *transformFeedbackObject = nullptr;
5200 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5201 {
5202 if (transformFeedbackObject != nullptr)
5203 {
5204 detachTransformFeedback(transformFeedback);
5205 transformFeedbackObject->release(this);
5206 }
5207
5208 mTransformFeedbackHandleAllocator.release(transformFeedback);
5209 }
5210 }
5211}
5212
5213void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5214{
5215 for (int i = 0; i < n; i++)
5216 {
5217 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5218 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5219 ids[i] = transformFeedback;
5220 }
5221}
5222
5223bool Context::isTransformFeedback(GLuint id)
5224{
5225 if (id == 0)
5226 {
5227 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5228 // returns FALSE
5229 return GL_FALSE;
5230 }
5231
5232 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5233 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5234}
5235
5236void Context::pauseTransformFeedback()
5237{
5238 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5239 transformFeedback->pause();
5240}
5241
5242void Context::resumeTransformFeedback()
5243{
5244 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5245 transformFeedback->resume();
5246}
5247
Jamie Madill12e957f2017-08-26 21:42:26 -04005248void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5249{
5250 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005251 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005252}
5253
5254GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5255{
5256 const Program *programObject = getProgram(program);
5257 return programObject->getFragDataLocation(name);
5258}
5259
5260void Context::getUniformIndices(GLuint program,
5261 GLsizei uniformCount,
5262 const GLchar *const *uniformNames,
5263 GLuint *uniformIndices)
5264{
5265 const Program *programObject = getProgram(program);
5266 if (!programObject->isLinked())
5267 {
5268 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5269 {
5270 uniformIndices[uniformId] = GL_INVALID_INDEX;
5271 }
5272 }
5273 else
5274 {
5275 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5276 {
5277 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5278 }
5279 }
5280}
5281
5282void Context::getActiveUniformsiv(GLuint program,
5283 GLsizei uniformCount,
5284 const GLuint *uniformIndices,
5285 GLenum pname,
5286 GLint *params)
5287{
5288 const Program *programObject = getProgram(program);
5289 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5290 {
5291 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005292 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005293 }
5294}
5295
5296GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5297{
5298 const Program *programObject = getProgram(program);
5299 return programObject->getUniformBlockIndex(uniformBlockName);
5300}
5301
5302void Context::getActiveUniformBlockiv(GLuint program,
5303 GLuint uniformBlockIndex,
5304 GLenum pname,
5305 GLint *params)
5306{
5307 const Program *programObject = getProgram(program);
5308 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5309}
5310
5311void Context::getActiveUniformBlockName(GLuint program,
5312 GLuint uniformBlockIndex,
5313 GLsizei bufSize,
5314 GLsizei *length,
5315 GLchar *uniformBlockName)
5316{
5317 const Program *programObject = getProgram(program);
5318 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5319}
5320
5321void Context::uniformBlockBinding(GLuint program,
5322 GLuint uniformBlockIndex,
5323 GLuint uniformBlockBinding)
5324{
5325 Program *programObject = getProgram(program);
5326 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5327}
5328
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005329GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5330{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005331 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5332 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005333
Jamie Madill70b5bb02017-08-28 13:32:37 -04005334 Sync *syncObject = getSync(syncHandle);
5335 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005336 if (error.isError())
5337 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005338 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005339 handleError(error);
5340 return nullptr;
5341 }
5342
Jamie Madill70b5bb02017-08-28 13:32:37 -04005343 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005344}
5345
5346GLboolean Context::isSync(GLsync sync)
5347{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005348 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005349}
5350
5351GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5352{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005353 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005354
5355 GLenum result = GL_WAIT_FAILED;
5356 handleError(syncObject->clientWait(flags, timeout, &result));
5357 return result;
5358}
5359
5360void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5361{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005362 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005363 handleError(syncObject->serverWait(flags, timeout));
5364}
5365
5366void Context::getInteger64v(GLenum pname, GLint64 *params)
5367{
5368 GLenum nativeType = GL_NONE;
5369 unsigned int numParams = 0;
5370 getQueryParameterInfo(pname, &nativeType, &numParams);
5371
5372 if (nativeType == GL_INT_64_ANGLEX)
5373 {
5374 getInteger64vImpl(pname, params);
5375 }
5376 else
5377 {
5378 CastStateValues(this, nativeType, pname, numParams, params);
5379 }
5380}
5381
Corentin Wallez336129f2017-10-17 15:55:40 -04005382void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04005383{
5384 Buffer *buffer = mGLState.getTargetBuffer(target);
5385 QueryBufferParameteri64v(buffer, pname, params);
5386}
5387
5388void Context::genSamplers(GLsizei count, GLuint *samplers)
5389{
5390 for (int i = 0; i < count; i++)
5391 {
5392 samplers[i] = mState.mSamplers->createSampler();
5393 }
5394}
5395
5396void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5397{
5398 for (int i = 0; i < count; i++)
5399 {
5400 GLuint sampler = samplers[i];
5401
5402 if (mState.mSamplers->getSampler(sampler))
5403 {
5404 detachSampler(sampler);
5405 }
5406
5407 mState.mSamplers->deleteObject(this, sampler);
5408 }
5409}
5410
5411void Context::getInternalformativ(GLenum target,
5412 GLenum internalformat,
5413 GLenum pname,
5414 GLsizei bufSize,
5415 GLint *params)
5416{
5417 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5418 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5419}
5420
Jiajia Qin5451d532017-11-16 17:16:34 +08005421void Context::programUniform1i(GLuint program, GLint location, GLint v0)
5422{
5423 programUniform1iv(program, location, 1, &v0);
5424}
5425
5426void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
5427{
5428 GLint xy[2] = {v0, v1};
5429 programUniform2iv(program, location, 1, xy);
5430}
5431
5432void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
5433{
5434 GLint xyz[3] = {v0, v1, v2};
5435 programUniform3iv(program, location, 1, xyz);
5436}
5437
5438void Context::programUniform4i(GLuint program,
5439 GLint location,
5440 GLint v0,
5441 GLint v1,
5442 GLint v2,
5443 GLint v3)
5444{
5445 GLint xyzw[4] = {v0, v1, v2, v3};
5446 programUniform4iv(program, location, 1, xyzw);
5447}
5448
5449void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
5450{
5451 programUniform1uiv(program, location, 1, &v0);
5452}
5453
5454void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
5455{
5456 GLuint xy[2] = {v0, v1};
5457 programUniform2uiv(program, location, 1, xy);
5458}
5459
5460void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
5461{
5462 GLuint xyz[3] = {v0, v1, v2};
5463 programUniform3uiv(program, location, 1, xyz);
5464}
5465
5466void Context::programUniform4ui(GLuint program,
5467 GLint location,
5468 GLuint v0,
5469 GLuint v1,
5470 GLuint v2,
5471 GLuint v3)
5472{
5473 GLuint xyzw[4] = {v0, v1, v2, v3};
5474 programUniform4uiv(program, location, 1, xyzw);
5475}
5476
5477void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
5478{
5479 programUniform1fv(program, location, 1, &v0);
5480}
5481
5482void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
5483{
5484 GLfloat xy[2] = {v0, v1};
5485 programUniform2fv(program, location, 1, xy);
5486}
5487
5488void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
5489{
5490 GLfloat xyz[3] = {v0, v1, v2};
5491 programUniform3fv(program, location, 1, xyz);
5492}
5493
5494void Context::programUniform4f(GLuint program,
5495 GLint location,
5496 GLfloat v0,
5497 GLfloat v1,
5498 GLfloat v2,
5499 GLfloat v3)
5500{
5501 GLfloat xyzw[4] = {v0, v1, v2, v3};
5502 programUniform4fv(program, location, 1, xyzw);
5503}
5504
Jamie Madill81c2e252017-09-09 23:32:46 -04005505void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5506{
5507 Program *programObject = getProgram(program);
5508 ASSERT(programObject);
5509 if (programObject->setUniform1iv(location, count, value) ==
5510 Program::SetUniformResult::SamplerChanged)
5511 {
5512 mGLState.setObjectDirty(GL_PROGRAM);
5513 }
5514}
5515
Jiajia Qin5451d532017-11-16 17:16:34 +08005516void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5517{
5518 Program *programObject = getProgram(program);
5519 ASSERT(programObject);
5520 programObject->setUniform2iv(location, count, value);
5521}
5522
5523void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5524{
5525 Program *programObject = getProgram(program);
5526 ASSERT(programObject);
5527 programObject->setUniform3iv(location, count, value);
5528}
5529
5530void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5531{
5532 Program *programObject = getProgram(program);
5533 ASSERT(programObject);
5534 programObject->setUniform4iv(location, count, value);
5535}
5536
5537void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5538{
5539 Program *programObject = getProgram(program);
5540 ASSERT(programObject);
5541 programObject->setUniform1uiv(location, count, value);
5542}
5543
5544void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5545{
5546 Program *programObject = getProgram(program);
5547 ASSERT(programObject);
5548 programObject->setUniform2uiv(location, count, value);
5549}
5550
5551void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5552{
5553 Program *programObject = getProgram(program);
5554 ASSERT(programObject);
5555 programObject->setUniform3uiv(location, count, value);
5556}
5557
5558void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5559{
5560 Program *programObject = getProgram(program);
5561 ASSERT(programObject);
5562 programObject->setUniform4uiv(location, count, value);
5563}
5564
5565void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5566{
5567 Program *programObject = getProgram(program);
5568 ASSERT(programObject);
5569 programObject->setUniform1fv(location, count, value);
5570}
5571
5572void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5573{
5574 Program *programObject = getProgram(program);
5575 ASSERT(programObject);
5576 programObject->setUniform2fv(location, count, value);
5577}
5578
5579void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5580{
5581 Program *programObject = getProgram(program);
5582 ASSERT(programObject);
5583 programObject->setUniform3fv(location, count, value);
5584}
5585
5586void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5587{
5588 Program *programObject = getProgram(program);
5589 ASSERT(programObject);
5590 programObject->setUniform4fv(location, count, value);
5591}
5592
5593void Context::programUniformMatrix2fv(GLuint program,
5594 GLint location,
5595 GLsizei count,
5596 GLboolean transpose,
5597 const GLfloat *value)
5598{
5599 Program *programObject = getProgram(program);
5600 ASSERT(programObject);
5601 programObject->setUniformMatrix2fv(location, count, transpose, value);
5602}
5603
5604void Context::programUniformMatrix3fv(GLuint program,
5605 GLint location,
5606 GLsizei count,
5607 GLboolean transpose,
5608 const GLfloat *value)
5609{
5610 Program *programObject = getProgram(program);
5611 ASSERT(programObject);
5612 programObject->setUniformMatrix3fv(location, count, transpose, value);
5613}
5614
5615void Context::programUniformMatrix4fv(GLuint program,
5616 GLint location,
5617 GLsizei count,
5618 GLboolean transpose,
5619 const GLfloat *value)
5620{
5621 Program *programObject = getProgram(program);
5622 ASSERT(programObject);
5623 programObject->setUniformMatrix4fv(location, count, transpose, value);
5624}
5625
5626void Context::programUniformMatrix2x3fv(GLuint program,
5627 GLint location,
5628 GLsizei count,
5629 GLboolean transpose,
5630 const GLfloat *value)
5631{
5632 Program *programObject = getProgram(program);
5633 ASSERT(programObject);
5634 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
5635}
5636
5637void Context::programUniformMatrix3x2fv(GLuint program,
5638 GLint location,
5639 GLsizei count,
5640 GLboolean transpose,
5641 const GLfloat *value)
5642{
5643 Program *programObject = getProgram(program);
5644 ASSERT(programObject);
5645 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
5646}
5647
5648void Context::programUniformMatrix2x4fv(GLuint program,
5649 GLint location,
5650 GLsizei count,
5651 GLboolean transpose,
5652 const GLfloat *value)
5653{
5654 Program *programObject = getProgram(program);
5655 ASSERT(programObject);
5656 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
5657}
5658
5659void Context::programUniformMatrix4x2fv(GLuint program,
5660 GLint location,
5661 GLsizei count,
5662 GLboolean transpose,
5663 const GLfloat *value)
5664{
5665 Program *programObject = getProgram(program);
5666 ASSERT(programObject);
5667 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
5668}
5669
5670void Context::programUniformMatrix3x4fv(GLuint program,
5671 GLint location,
5672 GLsizei count,
5673 GLboolean transpose,
5674 const GLfloat *value)
5675{
5676 Program *programObject = getProgram(program);
5677 ASSERT(programObject);
5678 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
5679}
5680
5681void Context::programUniformMatrix4x3fv(GLuint program,
5682 GLint location,
5683 GLsizei count,
5684 GLboolean transpose,
5685 const GLfloat *value)
5686{
5687 Program *programObject = getProgram(program);
5688 ASSERT(programObject);
5689 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
5690}
5691
Jamie Madill81c2e252017-09-09 23:32:46 -04005692void Context::onTextureChange(const Texture *texture)
5693{
5694 // Conservatively assume all textures are dirty.
5695 // TODO(jmadill): More fine-grained update.
5696 mGLState.setObjectDirty(GL_TEXTURE);
5697}
5698
Yunchao Hea336b902017-08-02 16:05:21 +08005699void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5700{
5701 for (int i = 0; i < count; i++)
5702 {
5703 pipelines[i] = createProgramPipeline();
5704 }
5705}
5706
5707void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5708{
5709 for (int i = 0; i < count; i++)
5710 {
5711 if (pipelines[i] != 0)
5712 {
5713 deleteProgramPipeline(pipelines[i]);
5714 }
5715 }
5716}
5717
5718GLboolean Context::isProgramPipeline(GLuint pipeline)
5719{
5720 if (pipeline == 0)
5721 {
5722 return GL_FALSE;
5723 }
5724
5725 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5726}
5727
Jamie Madill2b7bbc22017-12-21 17:30:38 -05005728void Context::finishFenceNV(GLuint fence)
5729{
5730 FenceNV *fenceObject = getFenceNV(fence);
5731
5732 ASSERT(fenceObject && fenceObject->isSet());
5733 handleError(fenceObject->finish());
5734}
5735
5736void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
5737{
5738 FenceNV *fenceObject = getFenceNV(fence);
5739
5740 ASSERT(fenceObject && fenceObject->isSet());
5741
5742 switch (pname)
5743 {
5744 case GL_FENCE_STATUS_NV:
5745 {
5746 // GL_NV_fence spec:
5747 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
5748 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
5749 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
5750 GLboolean status = GL_TRUE;
5751 if (fenceObject->getStatus() != GL_TRUE)
5752 {
5753 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
5754 }
5755 *params = status;
5756 break;
5757 }
5758
5759 case GL_FENCE_CONDITION_NV:
5760 {
5761 *params = static_cast<GLint>(fenceObject->getCondition());
5762 break;
5763 }
5764
5765 default:
5766 UNREACHABLE();
5767 }
5768}
5769
5770void Context::getTranslatedShaderSource(GLuint shader,
5771 GLsizei bufsize,
5772 GLsizei *length,
5773 GLchar *source)
5774{
5775 Shader *shaderObject = getShader(shader);
5776 ASSERT(shaderObject);
5777 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
5778}
5779
5780void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
5781{
5782 Program *programObject = getProgram(program);
5783 ASSERT(programObject);
5784
5785 programObject->getUniformfv(this, location, params);
5786}
5787
5788void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
5789{
5790 Program *programObject = getProgram(program);
5791 ASSERT(programObject);
5792
5793 programObject->getUniformiv(this, location, params);
5794}
5795
5796GLboolean Context::isFenceNV(GLuint fence)
5797{
5798 FenceNV *fenceObject = getFenceNV(fence);
5799
5800 if (fenceObject == nullptr)
5801 {
5802 return GL_FALSE;
5803 }
5804
5805 // GL_NV_fence spec:
5806 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
5807 // existing fence.
5808 return fenceObject->isSet();
5809}
5810
5811void Context::readnPixels(GLint x,
5812 GLint y,
5813 GLsizei width,
5814 GLsizei height,
5815 GLenum format,
5816 GLenum type,
5817 GLsizei bufSize,
5818 void *data)
5819{
5820 return readPixels(x, y, width, height, format, type, data);
5821}
5822
Jamie Madill007530e2017-12-28 14:27:04 -05005823void Context::setFenceNV(GLuint fence, GLenum condition)
5824{
5825 ASSERT(condition == GL_ALL_COMPLETED_NV);
5826
5827 FenceNV *fenceObject = getFenceNV(fence);
5828 ASSERT(fenceObject != nullptr);
5829 handleError(fenceObject->set(condition));
5830}
5831
5832GLboolean Context::testFenceNV(GLuint fence)
5833{
5834 FenceNV *fenceObject = getFenceNV(fence);
5835
5836 ASSERT(fenceObject != nullptr);
5837 ASSERT(fenceObject->isSet() == GL_TRUE);
5838
5839 GLboolean result = GL_TRUE;
5840 Error error = fenceObject->test(&result);
5841 if (error.isError())
5842 {
5843 handleError(error);
5844 return GL_TRUE;
5845 }
5846
5847 return result;
5848}
5849
Jamie Madillfa920eb2018-01-04 11:45:50 -05005850void Context::eGLImageTargetTexture2D(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005851{
5852 Texture *texture = getTargetTexture(target);
5853 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
5854 handleError(texture->setEGLImageTarget(this, target, imageObject));
5855}
5856
Jamie Madillfa920eb2018-01-04 11:45:50 -05005857void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005858{
5859 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
5860 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
5861 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
5862}
5863
Jamie Madillfa920eb2018-01-04 11:45:50 -05005864void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
5865{
5866 UNIMPLEMENTED();
5867}
5868
Geoff Lang2aaa7b42018-01-12 17:17:27 -05005869void Context::alphaFunc(GLenum func, GLfloat ref)
5870{
5871 UNIMPLEMENTED();
5872}
5873
5874void Context::alphaFuncx(GLenum func, GLfixed ref)
5875{
5876 UNIMPLEMENTED();
5877}
5878
5879void Context::clearColorx(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5880{
5881 UNIMPLEMENTED();
5882}
5883
5884void Context::clearDepthx(GLfixed depth)
5885{
5886 UNIMPLEMENTED();
5887}
5888
5889void Context::clientActiveTexture(GLenum texture)
5890{
5891 UNIMPLEMENTED();
5892}
5893
5894void Context::clipPlanef(GLenum p, const GLfloat *eqn)
5895{
5896 UNIMPLEMENTED();
5897}
5898
5899void Context::clipPlanex(GLenum plane, const GLfixed *equation)
5900{
5901 UNIMPLEMENTED();
5902}
5903
5904void Context::color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
5905{
5906 UNIMPLEMENTED();
5907}
5908
5909void Context::color4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
5910{
5911 UNIMPLEMENTED();
5912}
5913
5914void Context::color4x(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5915{
5916 UNIMPLEMENTED();
5917}
5918
5919void Context::colorPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
5920{
5921 UNIMPLEMENTED();
5922}
5923
5924void Context::cullFace(GLenum mode)
5925{
5926 UNIMPLEMENTED();
5927}
5928
5929void Context::depthRangex(GLfixed n, GLfixed f)
5930{
5931 UNIMPLEMENTED();
5932}
5933
5934void Context::disableClientState(GLenum array)
5935{
5936 UNIMPLEMENTED();
5937}
5938
5939void Context::enableClientState(GLenum array)
5940{
5941 UNIMPLEMENTED();
5942}
5943
5944void Context::fogf(GLenum pname, GLfloat param)
5945{
5946 UNIMPLEMENTED();
5947}
5948
5949void Context::fogfv(GLenum pname, const GLfloat *params)
5950{
5951 UNIMPLEMENTED();
5952}
5953
5954void Context::fogx(GLenum pname, GLfixed param)
5955{
5956 UNIMPLEMENTED();
5957}
5958
5959void Context::fogxv(GLenum pname, const GLfixed *param)
5960{
5961 UNIMPLEMENTED();
5962}
5963
5964void Context::frustumf(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
5965{
5966 UNIMPLEMENTED();
5967}
5968
5969void Context::frustumx(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
5970{
5971 UNIMPLEMENTED();
5972}
5973
5974void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
5975{
5976 UNIMPLEMENTED();
5977}
5978
5979void Context::getClipPlanef(GLenum plane, GLfloat *equation)
5980{
5981 UNIMPLEMENTED();
5982}
5983
5984void Context::getClipPlanex(GLenum plane, GLfixed *equation)
5985{
5986 UNIMPLEMENTED();
5987}
5988
5989void Context::getFixedv(GLenum pname, GLfixed *params)
5990{
5991 UNIMPLEMENTED();
5992}
5993
5994void Context::getLightfv(GLenum light, GLenum pname, GLfloat *params)
5995{
5996 UNIMPLEMENTED();
5997}
5998
5999void Context::getLightxv(GLenum light, GLenum pname, GLfixed *params)
6000{
6001 UNIMPLEMENTED();
6002}
6003
6004void Context::getMaterialfv(GLenum face, GLenum pname, GLfloat *params)
6005{
6006 UNIMPLEMENTED();
6007}
6008
6009void Context::getMaterialxv(GLenum face, GLenum pname, GLfixed *params)
6010{
6011 UNIMPLEMENTED();
6012}
6013
6014void Context::getTexEnvfv(GLenum target, GLenum pname, GLfloat *params)
6015{
6016 UNIMPLEMENTED();
6017}
6018
6019void Context::getTexEnviv(GLenum target, GLenum pname, GLint *params)
6020{
6021 UNIMPLEMENTED();
6022}
6023
6024void Context::getTexEnvxv(GLenum target, GLenum pname, GLfixed *params)
6025{
6026 UNIMPLEMENTED();
6027}
6028
6029void Context::getTexParameterxv(GLenum target, GLenum pname, GLfixed *params)
6030{
6031 UNIMPLEMENTED();
6032}
6033
6034void Context::lightModelf(GLenum pname, GLfloat param)
6035{
6036 UNIMPLEMENTED();
6037}
6038
6039void Context::lightModelfv(GLenum pname, const GLfloat *params)
6040{
6041 UNIMPLEMENTED();
6042}
6043
6044void Context::lightModelx(GLenum pname, GLfixed param)
6045{
6046 UNIMPLEMENTED();
6047}
6048
6049void Context::lightModelxv(GLenum pname, const GLfixed *param)
6050{
6051 UNIMPLEMENTED();
6052}
6053
6054void Context::lightf(GLenum light, GLenum pname, GLfloat param)
6055{
6056 UNIMPLEMENTED();
6057}
6058
6059void Context::lightfv(GLenum light, GLenum pname, const GLfloat *params)
6060{
6061 UNIMPLEMENTED();
6062}
6063
6064void Context::lightx(GLenum light, GLenum pname, GLfixed param)
6065{
6066 UNIMPLEMENTED();
6067}
6068
6069void Context::lightxv(GLenum light, GLenum pname, const GLfixed *params)
6070{
6071 UNIMPLEMENTED();
6072}
6073
6074void Context::lineWidthx(GLfixed width)
6075{
6076 UNIMPLEMENTED();
6077}
6078
6079void Context::loadIdentity()
6080{
6081 UNIMPLEMENTED();
6082}
6083
6084void Context::loadMatrixf(const GLfloat *m)
6085{
6086 UNIMPLEMENTED();
6087}
6088
6089void Context::loadMatrixx(const GLfixed *m)
6090{
6091 UNIMPLEMENTED();
6092}
6093
6094void Context::logicOp(GLenum opcode)
6095{
6096 UNIMPLEMENTED();
6097}
6098
6099void Context::materialf(GLenum face, GLenum pname, GLfloat param)
6100{
6101 UNIMPLEMENTED();
6102}
6103
6104void Context::materialfv(GLenum face, GLenum pname, const GLfloat *params)
6105{
6106 UNIMPLEMENTED();
6107}
6108
6109void Context::materialx(GLenum face, GLenum pname, GLfixed param)
6110{
6111 UNIMPLEMENTED();
6112}
6113
6114void Context::materialxv(GLenum face, GLenum pname, const GLfixed *param)
6115{
6116 UNIMPLEMENTED();
6117}
6118
6119void Context::matrixMode(GLenum mode)
6120{
6121 UNIMPLEMENTED();
6122}
6123
6124void Context::multMatrixf(const GLfloat *m)
6125{
6126 UNIMPLEMENTED();
6127}
6128
6129void Context::multMatrixx(const GLfixed *m)
6130{
6131 UNIMPLEMENTED();
6132}
6133
6134void Context::multiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q)
6135{
6136 UNIMPLEMENTED();
6137}
6138
6139void Context::multiTexCoord4x(GLenum texture, GLfixed s, GLfixed t, GLfixed r, GLfixed q)
6140{
6141 UNIMPLEMENTED();
6142}
6143
6144void Context::normal3f(GLfloat nx, GLfloat ny, GLfloat nz)
6145{
6146 UNIMPLEMENTED();
6147}
6148
6149void Context::normal3x(GLfixed nx, GLfixed ny, GLfixed nz)
6150{
6151 UNIMPLEMENTED();
6152}
6153
6154void Context::normalPointer(GLenum type, GLsizei stride, const void *pointer)
6155{
6156 UNIMPLEMENTED();
6157}
6158
6159void Context::orthof(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
6160{
6161 UNIMPLEMENTED();
6162}
6163
6164void Context::orthox(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
6165{
6166 UNIMPLEMENTED();
6167}
6168
6169void Context::pointParameterf(GLenum pname, GLfloat param)
6170{
6171 UNIMPLEMENTED();
6172}
6173
6174void Context::pointParameterfv(GLenum pname, const GLfloat *params)
6175{
6176 UNIMPLEMENTED();
6177}
6178
6179void Context::pointParameterx(GLenum pname, GLfixed param)
6180{
6181 UNIMPLEMENTED();
6182}
6183
6184void Context::pointParameterxv(GLenum pname, const GLfixed *params)
6185{
6186 UNIMPLEMENTED();
6187}
6188
6189void Context::pointSize(GLfloat size)
6190{
6191 UNIMPLEMENTED();
6192}
6193
6194void Context::pointSizex(GLfixed size)
6195{
6196 UNIMPLEMENTED();
6197}
6198
6199void Context::polygonOffsetx(GLfixed factor, GLfixed units)
6200{
6201 UNIMPLEMENTED();
6202}
6203
6204void Context::popMatrix()
6205{
6206 UNIMPLEMENTED();
6207}
6208
6209void Context::pushMatrix()
6210{
6211 UNIMPLEMENTED();
6212}
6213
6214void Context::rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
6215{
6216 UNIMPLEMENTED();
6217}
6218
6219void Context::rotatex(GLfixed angle, GLfixed x, GLfixed y, GLfixed z)
6220{
6221 UNIMPLEMENTED();
6222}
6223
6224void Context::sampleCoveragex(GLclampx value, GLboolean invert)
6225{
6226 UNIMPLEMENTED();
6227}
6228
6229void Context::scalef(GLfloat x, GLfloat y, GLfloat z)
6230{
6231 UNIMPLEMENTED();
6232}
6233
6234void Context::scalex(GLfixed x, GLfixed y, GLfixed z)
6235{
6236 UNIMPLEMENTED();
6237}
6238
6239void Context::shadeModel(GLenum mode)
6240{
6241 UNIMPLEMENTED();
6242}
6243
6244void Context::texCoordPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6245{
6246 UNIMPLEMENTED();
6247}
6248
6249void Context::texEnvf(GLenum target, GLenum pname, GLfloat param)
6250{
6251 UNIMPLEMENTED();
6252}
6253
6254void Context::texEnvfv(GLenum target, GLenum pname, const GLfloat *params)
6255{
6256 UNIMPLEMENTED();
6257}
6258
6259void Context::texEnvi(GLenum target, GLenum pname, GLint param)
6260{
6261 UNIMPLEMENTED();
6262}
6263
6264void Context::texEnviv(GLenum target, GLenum pname, const GLint *params)
6265{
6266 UNIMPLEMENTED();
6267}
6268
6269void Context::texEnvx(GLenum target, GLenum pname, GLfixed param)
6270{
6271 UNIMPLEMENTED();
6272}
6273
6274void Context::texEnvxv(GLenum target, GLenum pname, const GLfixed *params)
6275{
6276 UNIMPLEMENTED();
6277}
6278
6279void Context::texParameterx(GLenum target, GLenum pname, GLfixed param)
6280{
6281 UNIMPLEMENTED();
6282}
6283
6284void Context::texParameterxv(GLenum target, GLenum pname, const GLfixed *params)
6285{
6286 UNIMPLEMENTED();
6287}
6288
6289void Context::translatef(GLfloat x, GLfloat y, GLfloat z)
6290{
6291 UNIMPLEMENTED();
6292}
6293
6294void Context::translatex(GLfixed x, GLfixed y, GLfixed z)
6295{
6296 UNIMPLEMENTED();
6297}
6298
6299void Context::vertexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6300{
6301 UNIMPLEMENTED();
6302}
6303
6304void Context::drawTexf(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height)
6305{
6306 UNIMPLEMENTED();
6307}
6308
6309void Context::drawTexfv(const GLfloat *coords)
6310{
6311 UNIMPLEMENTED();
6312}
6313
6314void Context::drawTexi(GLint x, GLint y, GLint z, GLint width, GLint height)
6315{
6316 UNIMPLEMENTED();
6317}
6318
6319void Context::drawTexiv(const GLint *coords)
6320{
6321 UNIMPLEMENTED();
6322}
6323
6324void Context::drawTexs(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height)
6325{
6326 UNIMPLEMENTED();
6327}
6328
6329void Context::drawTexsv(const GLshort *coords)
6330{
6331 UNIMPLEMENTED();
6332}
6333
6334void Context::drawTexx(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height)
6335{
6336 UNIMPLEMENTED();
6337}
6338
6339void Context::drawTexxv(const GLfixed *coords)
6340{
6341 UNIMPLEMENTED();
6342}
6343
6344void Context::currentPaletteMatrix(GLuint matrixpaletteindex)
6345{
6346 UNIMPLEMENTED();
6347}
6348
6349void Context::loadPaletteFromModelViewMatrix()
6350{
6351 UNIMPLEMENTED();
6352}
6353
6354void Context::matrixIndexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6355{
6356 UNIMPLEMENTED();
6357}
6358
6359void Context::weightPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6360{
6361 UNIMPLEMENTED();
6362}
6363
6364void Context::pointSizePointer(GLenum type, GLsizei stride, const void *pointer)
6365{
6366 UNIMPLEMENTED();
6367}
6368
6369GLbitfield Context::queryMatrixx(GLfixed *mantissa, GLint *exponent)
6370{
6371 UNIMPLEMENTED();
6372 return 0;
6373}
6374
Jamie Madillc29968b2016-01-20 11:17:23 -05006375} // namespace gl