blob: e854012dfaa36eb8f6ddb275affb382b6833096e [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);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800314 mZeroTextures[TextureType::_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);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800317 mZeroTextures[TextureType::CubeMap].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400318
Geoff Langeb66a6e2016-10-31 13:06:12 -0400319 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400320 {
321 // TODO: These could also be enabled via extension
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400322 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, GL_TEXTURE_3D);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800323 mZeroTextures[TextureType::_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);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800326 mZeroTextures[TextureType::_2DArray].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400327 }
Geoff Lang3b573612016-10-31 14:08:10 -0400328 if (getClientVersion() >= Version(3, 1))
329 {
330 Texture *zeroTexture2DMultisample =
331 new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_MULTISAMPLE);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800332 mZeroTextures[TextureType::_2DMultisample].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800333
Jiajia Qin6eafb042016-12-27 17:04:07 +0800334 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
335 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800336 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800337 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800338
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800339 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
340 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400341 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800342 }
Geoff Lang3b573612016-10-31 14:08:10 -0400343 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000344
Geoff Lang4751aab2017-10-30 15:14:52 -0400345 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
346 if (nativeExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400347 {
348 Texture *zeroTextureRectangle =
349 new Texture(mImplementation.get(), 0, GL_TEXTURE_RECTANGLE_ANGLE);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800350 mZeroTextures[TextureType::Rectangle].set(this, zeroTextureRectangle);
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400351 }
352
Geoff Lang4751aab2017-10-30 15:14:52 -0400353 if (nativeExtensions.eglImageExternal || nativeExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400354 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400355 Texture *zeroTextureExternal =
356 new Texture(mImplementation.get(), 0, GL_TEXTURE_EXTERNAL_OES);
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800357 mZeroTextures[TextureType::External].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 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800462 if (zeroTexture.get() != nullptr)
463 {
464 ANGLE_TRY(zeroTexture->onDestroy(this));
465 zeroTexture.set(this, nullptr);
466 }
Geoff Lang76b10c92014-09-05 16:28:14 -0400467 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000468
Corentin Wallezccab69d2017-01-27 16:57:15 -0500469 SafeDelete(mSurfacelessFramebuffer);
470
Jamie Madill4928b7c2017-06-20 12:57:39 -0400471 ANGLE_TRY(releaseSurface(display));
Jamie Madill2f348d22017-06-05 10:50:59 -0400472 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500473
Jamie Madill4928b7c2017-06-20 12:57:39 -0400474 mGLState.reset(this);
475
Jamie Madill6c1f6712017-02-14 19:08:04 -0500476 mState.mBuffers->release(this);
477 mState.mShaderPrograms->release(this);
478 mState.mTextures->release(this);
479 mState.mRenderbuffers->release(this);
480 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400481 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500482 mState.mPaths->release(this);
483 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800484 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400485
Jamie Madill76e471e2017-10-21 09:56:01 -0400486 mImplementation->onDestroy(this);
487
Jamie Madill4928b7c2017-06-20 12:57:39 -0400488 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000489}
490
Jamie Madill70ee0f62017-02-06 16:04:20 -0500491Context::~Context()
492{
493}
494
Jamie Madill4928b7c2017-06-20 12:57:39 -0400495egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000496{
Jamie Madill61e16b42017-06-19 11:13:23 -0400497 mCurrentDisplay = display;
498
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000499 if (!mHasBeenCurrent)
500 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000501 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500502 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400503 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000504
Corentin Wallezc295e512017-01-27 17:47:50 -0500505 int width = 0;
506 int height = 0;
507 if (surface != nullptr)
508 {
509 width = surface->getWidth();
510 height = surface->getHeight();
511 }
512
513 mGLState.setViewportParams(0, 0, width, height);
514 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000515
516 mHasBeenCurrent = true;
517 }
518
Jamie Madill1b94d432015-08-07 13:23:23 -0400519 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700520 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400521 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400522
Jamie Madill4928b7c2017-06-20 12:57:39 -0400523 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500524
525 Framebuffer *newDefault = nullptr;
526 if (surface != nullptr)
527 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400528 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500529 mCurrentSurface = surface;
530 newDefault = surface->getDefaultFramebuffer();
531 }
532 else
533 {
534 if (mSurfacelessFramebuffer == nullptr)
535 {
536 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
537 }
538
539 newDefault = mSurfacelessFramebuffer;
540 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000541
Corentin Wallez37c39792015-08-20 14:19:46 -0400542 // Update default framebuffer, the binding of the previous default
543 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400544 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700545 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400546 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700547 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400548 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700549 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400550 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700551 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400552 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500553 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400554 }
Ian Ewell292f0052016-02-04 10:37:32 -0500555
556 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400557 mImplementation->onMakeCurrent(this);
558 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000559}
560
Jamie Madill4928b7c2017-06-20 12:57:39 -0400561egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400562{
Corentin Wallez37c39792015-08-20 14:19:46 -0400563 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500564 Framebuffer *currentDefault = nullptr;
565 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400566 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500567 currentDefault = mCurrentSurface->getDefaultFramebuffer();
568 }
569 else if (mSurfacelessFramebuffer != nullptr)
570 {
571 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400572 }
573
Corentin Wallezc295e512017-01-27 17:47:50 -0500574 if (mGLState.getReadFramebuffer() == currentDefault)
575 {
576 mGLState.setReadFramebufferBinding(nullptr);
577 }
578 if (mGLState.getDrawFramebuffer() == currentDefault)
579 {
580 mGLState.setDrawFramebufferBinding(nullptr);
581 }
582 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
583
584 if (mCurrentSurface)
585 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400586 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500587 mCurrentSurface = nullptr;
588 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400589
590 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400591}
592
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000593GLuint Context::createBuffer()
594{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500595 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000596}
597
598GLuint Context::createProgram()
599{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500600 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000601}
602
603GLuint Context::createShader(GLenum type)
604{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500605 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000606}
607
608GLuint Context::createTexture()
609{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500610 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000611}
612
613GLuint Context::createRenderbuffer()
614{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500615 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000616}
617
Sami Väisänene45e53b2016-05-25 10:36:04 +0300618GLuint Context::createPaths(GLsizei range)
619{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500620 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300621 if (resultOrError.isError())
622 {
623 handleError(resultOrError.getError());
624 return 0;
625 }
626 return resultOrError.getResult();
627}
628
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000629// Returns an unused framebuffer name
630GLuint Context::createFramebuffer()
631{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500632 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000633}
634
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500635void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000636{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500637 for (int i = 0; i < n; i++)
638 {
639 GLuint handle = mFenceNVHandleAllocator.allocate();
640 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
641 fences[i] = handle;
642 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000643}
644
Yunchao Hea336b902017-08-02 16:05:21 +0800645GLuint Context::createProgramPipeline()
646{
647 return mState.mPipelines->createProgramPipeline();
648}
649
Jiajia Qin5451d532017-11-16 17:16:34 +0800650GLuint Context::createShaderProgramv(GLenum type, GLsizei count, const GLchar *const *strings)
651{
652 UNIMPLEMENTED();
653 return 0u;
654}
655
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000656void Context::deleteBuffer(GLuint buffer)
657{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500658 if (mState.mBuffers->getBuffer(buffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000659 {
660 detachBuffer(buffer);
661 }
Jamie Madill893ab082014-05-16 16:56:10 -0400662
Jamie Madill6c1f6712017-02-14 19:08:04 -0500663 mState.mBuffers->deleteObject(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000664}
665
666void Context::deleteShader(GLuint shader)
667{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500668 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000669}
670
671void Context::deleteProgram(GLuint program)
672{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500673 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000674}
675
676void Context::deleteTexture(GLuint texture)
677{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500678 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000679 {
680 detachTexture(texture);
681 }
682
Jamie Madill6c1f6712017-02-14 19:08:04 -0500683 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000684}
685
686void Context::deleteRenderbuffer(GLuint renderbuffer)
687{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500688 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000689 {
690 detachRenderbuffer(renderbuffer);
691 }
Jamie Madill893ab082014-05-16 16:56:10 -0400692
Jamie Madill6c1f6712017-02-14 19:08:04 -0500693 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000694}
695
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400696void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400697{
698 // The spec specifies the underlying Fence object is not deleted until all current
699 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
700 // and since our API is currently designed for being called from a single thread, we can delete
701 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400702 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400703}
704
Yunchao Hea336b902017-08-02 16:05:21 +0800705void Context::deleteProgramPipeline(GLuint pipeline)
706{
707 if (mState.mPipelines->getProgramPipeline(pipeline))
708 {
709 detachProgramPipeline(pipeline);
710 }
711
712 mState.mPipelines->deleteObject(this, pipeline);
713}
714
Sami Väisänene45e53b2016-05-25 10:36:04 +0300715void Context::deletePaths(GLuint first, GLsizei range)
716{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500717 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300718}
719
720bool Context::hasPathData(GLuint path) const
721{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500722 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300723 if (pathObj == nullptr)
724 return false;
725
726 return pathObj->hasPathData();
727}
728
729bool Context::hasPath(GLuint path) const
730{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500731 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300732}
733
734void Context::setPathCommands(GLuint path,
735 GLsizei numCommands,
736 const GLubyte *commands,
737 GLsizei numCoords,
738 GLenum coordType,
739 const void *coords)
740{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500741 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300742
743 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
744}
745
Jamie Madill007530e2017-12-28 14:27:04 -0500746void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300747{
Jamie Madill007530e2017-12-28 14:27:04 -0500748 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300749
750 switch (pname)
751 {
752 case GL_PATH_STROKE_WIDTH_CHROMIUM:
753 pathObj->setStrokeWidth(value);
754 break;
755 case GL_PATH_END_CAPS_CHROMIUM:
756 pathObj->setEndCaps(static_cast<GLenum>(value));
757 break;
758 case GL_PATH_JOIN_STYLE_CHROMIUM:
759 pathObj->setJoinStyle(static_cast<GLenum>(value));
760 break;
761 case GL_PATH_MITER_LIMIT_CHROMIUM:
762 pathObj->setMiterLimit(value);
763 break;
764 case GL_PATH_STROKE_BOUND_CHROMIUM:
765 pathObj->setStrokeBound(value);
766 break;
767 default:
768 UNREACHABLE();
769 break;
770 }
771}
772
Jamie Madill007530e2017-12-28 14:27:04 -0500773void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300774{
Jamie Madill007530e2017-12-28 14:27:04 -0500775 // TODO(jmadill): Should use proper clamping/casting.
776 pathParameterf(path, pname, static_cast<GLfloat>(value));
777}
778
779void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
780{
781 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300782
783 switch (pname)
784 {
785 case GL_PATH_STROKE_WIDTH_CHROMIUM:
786 *value = pathObj->getStrokeWidth();
787 break;
788 case GL_PATH_END_CAPS_CHROMIUM:
789 *value = static_cast<GLfloat>(pathObj->getEndCaps());
790 break;
791 case GL_PATH_JOIN_STYLE_CHROMIUM:
792 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
793 break;
794 case GL_PATH_MITER_LIMIT_CHROMIUM:
795 *value = pathObj->getMiterLimit();
796 break;
797 case GL_PATH_STROKE_BOUND_CHROMIUM:
798 *value = pathObj->getStrokeBound();
799 break;
800 default:
801 UNREACHABLE();
802 break;
803 }
804}
805
Jamie Madill007530e2017-12-28 14:27:04 -0500806void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
807{
808 GLfloat val = 0.0f;
809 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
810 if (value)
811 *value = static_cast<GLint>(val);
812}
813
Sami Väisänene45e53b2016-05-25 10:36:04 +0300814void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
815{
816 mGLState.setPathStencilFunc(func, ref, mask);
817}
818
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000819void Context::deleteFramebuffer(GLuint framebuffer)
820{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500821 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000822 {
823 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000824 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500825
Jamie Madill6c1f6712017-02-14 19:08:04 -0500826 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000827}
828
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500829void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000830{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500831 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000832 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500833 GLuint fence = fences[i];
834
835 FenceNV *fenceObject = nullptr;
836 if (mFenceNVMap.erase(fence, &fenceObject))
837 {
838 mFenceNVHandleAllocator.release(fence);
839 delete fenceObject;
840 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000841 }
842}
843
Geoff Lang70d0f492015-12-10 17:45:46 -0500844Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000845{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500846 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000847}
848
Jamie Madill570f7c82014-07-03 10:38:54 -0400849Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000850{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500851 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000852}
853
Geoff Lang70d0f492015-12-10 17:45:46 -0500854Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000855{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500856 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000857}
858
Jamie Madill70b5bb02017-08-28 13:32:37 -0400859Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400860{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400861 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400862}
863
Jamie Madill57a89722013-07-02 11:57:03 -0400864VertexArray *Context::getVertexArray(GLuint handle) const
865{
Jamie Madill96a483b2017-06-27 16:49:21 -0400866 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400867}
868
Jamie Madilldc356042013-07-19 16:36:57 -0400869Sampler *Context::getSampler(GLuint handle) const
870{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500871 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400872}
873
Geoff Langc8058452014-02-03 12:04:11 -0500874TransformFeedback *Context::getTransformFeedback(GLuint handle) const
875{
Jamie Madill96a483b2017-06-27 16:49:21 -0400876 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500877}
878
Yunchao Hea336b902017-08-02 16:05:21 +0800879ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
880{
881 return mState.mPipelines->getProgramPipeline(handle);
882}
883
Geoff Lang70d0f492015-12-10 17:45:46 -0500884LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
885{
886 switch (identifier)
887 {
888 case GL_BUFFER:
889 return getBuffer(name);
890 case GL_SHADER:
891 return getShader(name);
892 case GL_PROGRAM:
893 return getProgram(name);
894 case GL_VERTEX_ARRAY:
895 return getVertexArray(name);
896 case GL_QUERY:
897 return getQuery(name);
898 case GL_TRANSFORM_FEEDBACK:
899 return getTransformFeedback(name);
900 case GL_SAMPLER:
901 return getSampler(name);
902 case GL_TEXTURE:
903 return getTexture(name);
904 case GL_RENDERBUFFER:
905 return getRenderbuffer(name);
906 case GL_FRAMEBUFFER:
907 return getFramebuffer(name);
908 default:
909 UNREACHABLE();
910 return nullptr;
911 }
912}
913
914LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
915{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400916 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500917}
918
Martin Radev9d901792016-07-15 15:58:58 +0300919void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
920{
921 LabeledObject *object = getLabeledObject(identifier, name);
922 ASSERT(object != nullptr);
923
924 std::string labelName = GetObjectLabelFromPointer(length, label);
925 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400926
927 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
928 // specified object is active until we do this.
929 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300930}
931
932void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
933{
934 LabeledObject *object = getLabeledObjectFromPtr(ptr);
935 ASSERT(object != nullptr);
936
937 std::string labelName = GetObjectLabelFromPointer(length, label);
938 object->setLabel(labelName);
939}
940
941void Context::getObjectLabel(GLenum identifier,
942 GLuint name,
943 GLsizei bufSize,
944 GLsizei *length,
945 GLchar *label) const
946{
947 LabeledObject *object = getLabeledObject(identifier, name);
948 ASSERT(object != nullptr);
949
950 const std::string &objectLabel = object->getLabel();
951 GetObjectLabelBase(objectLabel, bufSize, length, label);
952}
953
954void Context::getObjectPtrLabel(const void *ptr,
955 GLsizei bufSize,
956 GLsizei *length,
957 GLchar *label) const
958{
959 LabeledObject *object = getLabeledObjectFromPtr(ptr);
960 ASSERT(object != nullptr);
961
962 const std::string &objectLabel = object->getLabel();
963 GetObjectLabelBase(objectLabel, bufSize, length, label);
964}
965
Jamie Madilldc356042013-07-19 16:36:57 -0400966bool Context::isSampler(GLuint samplerName) const
967{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500968 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400969}
970
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800971void Context::bindTexture(TextureType target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000972{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500973 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000974
Jamie Madilldedd7b92014-11-05 16:30:36 -0500975 if (handle == 0)
976 {
977 texture = mZeroTextures[target].get();
978 }
979 else
980 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -0800981 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle,
982 ToGLenum(target));
Jamie Madilldedd7b92014-11-05 16:30:36 -0500983 }
984
985 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400986 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000987}
988
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500989void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000990{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500991 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
992 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700993 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000994}
995
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500996void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000997{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500998 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
999 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001000 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001001}
1002
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001003void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001004{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001005 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001006 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001007}
1008
Shao80957d92017-02-20 21:25:59 +08001009void Context::bindVertexBuffer(GLuint bindingIndex,
1010 GLuint bufferHandle,
1011 GLintptr offset,
1012 GLsizei stride)
1013{
1014 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001015 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001016}
1017
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001018void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001019{
Geoff Lang76b10c92014-09-05 16:28:14 -04001020 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001021 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001022 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001023 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001024}
1025
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001026void Context::bindImageTexture(GLuint unit,
1027 GLuint texture,
1028 GLint level,
1029 GLboolean layered,
1030 GLint layer,
1031 GLenum access,
1032 GLenum format)
1033{
1034 Texture *tex = mState.mTextures->getTexture(texture);
1035 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1036}
1037
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001038void Context::useProgram(GLuint program)
1039{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001040 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001041}
1042
Jiajia Qin5451d532017-11-16 17:16:34 +08001043void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1044{
1045 UNIMPLEMENTED();
1046}
1047
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001048void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001049{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001050 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001051 TransformFeedback *transformFeedback =
1052 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001053 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001054}
1055
Yunchao Hea336b902017-08-02 16:05:21 +08001056void Context::bindProgramPipeline(GLuint pipelineHandle)
1057{
1058 ProgramPipeline *pipeline =
1059 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1060 mGLState.setProgramPipelineBinding(this, pipeline);
1061}
1062
Jamie Madillf0e04492017-08-26 15:28:42 -04001063void Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001064{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001065 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001066 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001067
Geoff Lang5aad9672014-09-08 11:10:42 -04001068 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001069 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001070
1071 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001072 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001073}
1074
Jamie Madillf0e04492017-08-26 15:28:42 -04001075void Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001076{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001077 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001078 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001079
Jamie Madillf0e04492017-08-26 15:28:42 -04001080 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001081
Geoff Lang5aad9672014-09-08 11:10:42 -04001082 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001083 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001084}
1085
Jamie Madillf0e04492017-08-26 15:28:42 -04001086void Context::queryCounter(GLuint id, GLenum target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001087{
1088 ASSERT(target == GL_TIMESTAMP_EXT);
1089
1090 Query *queryObject = getQuery(id, true, target);
1091 ASSERT(queryObject);
1092
Jamie Madillf0e04492017-08-26 15:28:42 -04001093 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001094}
1095
1096void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1097{
1098 switch (pname)
1099 {
1100 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001101 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001102 break;
1103 case GL_QUERY_COUNTER_BITS_EXT:
1104 switch (target)
1105 {
1106 case GL_TIME_ELAPSED_EXT:
1107 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1108 break;
1109 case GL_TIMESTAMP_EXT:
1110 params[0] = getExtensions().queryCounterBitsTimestamp;
1111 break;
1112 default:
1113 UNREACHABLE();
1114 params[0] = 0;
1115 break;
1116 }
1117 break;
1118 default:
1119 UNREACHABLE();
1120 return;
1121 }
1122}
1123
Geoff Lang2186c382016-10-14 10:54:54 -04001124void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001125{
Geoff Lang2186c382016-10-14 10:54:54 -04001126 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001127}
1128
Geoff Lang2186c382016-10-14 10:54:54 -04001129void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001130{
Geoff Lang2186c382016-10-14 10:54:54 -04001131 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001132}
1133
Geoff Lang2186c382016-10-14 10:54:54 -04001134void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001135{
Geoff Lang2186c382016-10-14 10:54:54 -04001136 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001137}
1138
Geoff Lang2186c382016-10-14 10:54:54 -04001139void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001140{
Geoff Lang2186c382016-10-14 10:54:54 -04001141 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001142}
1143
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001144Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001145{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001146 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001147}
1148
Jamie Madill2f348d22017-06-05 10:50:59 -04001149FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001150{
Jamie Madill96a483b2017-06-27 16:49:21 -04001151 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001152}
1153
Jamie Madill2f348d22017-06-05 10:50:59 -04001154Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001155{
Jamie Madill96a483b2017-06-27 16:49:21 -04001156 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001157 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001158 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001159 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001160
1161 Query *query = mQueryMap.query(handle);
1162 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001163 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001164 query = new Query(mImplementation->createQuery(type), handle);
1165 query->addRef();
1166 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001167 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001168 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001169}
1170
Geoff Lang70d0f492015-12-10 17:45:46 -05001171Query *Context::getQuery(GLuint handle) const
1172{
Jamie Madill96a483b2017-06-27 16:49:21 -04001173 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001174}
1175
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001176Texture *Context::getTargetTexture(TextureType type) const
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001177{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001178 ASSERT(ValidTextureTarget(this, type) || ValidTextureExternalTarget(this, type));
1179 return mGLState.getTargetTexture(type);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001180}
1181
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001182Texture *Context::getSamplerTexture(unsigned int sampler, TextureType type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001183{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001184 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001185}
1186
Geoff Lang492a7e42014-11-05 13:27:06 -05001187Compiler *Context::getCompiler() const
1188{
Jamie Madill2f348d22017-06-05 10:50:59 -04001189 if (mCompiler.get() == nullptr)
1190 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001191 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001192 }
1193 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001194}
1195
Jamie Madillc1d770e2017-04-13 17:31:24 -04001196void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001197{
1198 switch (pname)
1199 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001200 case GL_SHADER_COMPILER:
1201 *params = GL_TRUE;
1202 break;
1203 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1204 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1205 break;
1206 default:
1207 mGLState.getBooleanv(pname, params);
1208 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001209 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001210}
1211
Jamie Madillc1d770e2017-04-13 17:31:24 -04001212void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001213{
Shannon Woods53a94a82014-06-24 15:20:36 -04001214 // Queries about context capabilities and maximums are answered by Context.
1215 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001216 switch (pname)
1217 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001218 case GL_ALIASED_LINE_WIDTH_RANGE:
1219 params[0] = mCaps.minAliasedLineWidth;
1220 params[1] = mCaps.maxAliasedLineWidth;
1221 break;
1222 case GL_ALIASED_POINT_SIZE_RANGE:
1223 params[0] = mCaps.minAliasedPointSize;
1224 params[1] = mCaps.maxAliasedPointSize;
1225 break;
1226 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1227 ASSERT(mExtensions.textureFilterAnisotropic);
1228 *params = mExtensions.maxTextureAnisotropy;
1229 break;
1230 case GL_MAX_TEXTURE_LOD_BIAS:
1231 *params = mCaps.maxLODBias;
1232 break;
1233
1234 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1235 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1236 {
1237 ASSERT(mExtensions.pathRendering);
1238 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1239 memcpy(params, m, 16 * sizeof(GLfloat));
1240 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001241 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001242
Jamie Madill231c7f52017-04-26 13:45:37 -04001243 default:
1244 mGLState.getFloatv(pname, params);
1245 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001246 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001247}
1248
Jamie Madillc1d770e2017-04-13 17:31:24 -04001249void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001250{
Shannon Woods53a94a82014-06-24 15:20:36 -04001251 // Queries about context capabilities and maximums are answered by Context.
1252 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001253
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001254 switch (pname)
1255 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001256 case GL_MAX_VERTEX_ATTRIBS:
1257 *params = mCaps.maxVertexAttributes;
1258 break;
1259 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1260 *params = mCaps.maxVertexUniformVectors;
1261 break;
1262 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1263 *params = mCaps.maxVertexUniformComponents;
1264 break;
1265 case GL_MAX_VARYING_VECTORS:
1266 *params = mCaps.maxVaryingVectors;
1267 break;
1268 case GL_MAX_VARYING_COMPONENTS:
1269 *params = mCaps.maxVertexOutputComponents;
1270 break;
1271 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1272 *params = mCaps.maxCombinedTextureImageUnits;
1273 break;
1274 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1275 *params = mCaps.maxVertexTextureImageUnits;
1276 break;
1277 case GL_MAX_TEXTURE_IMAGE_UNITS:
1278 *params = mCaps.maxTextureImageUnits;
1279 break;
1280 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1281 *params = mCaps.maxFragmentUniformVectors;
1282 break;
1283 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1284 *params = mCaps.maxFragmentUniformComponents;
1285 break;
1286 case GL_MAX_RENDERBUFFER_SIZE:
1287 *params = mCaps.maxRenderbufferSize;
1288 break;
1289 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1290 *params = mCaps.maxColorAttachments;
1291 break;
1292 case GL_MAX_DRAW_BUFFERS_EXT:
1293 *params = mCaps.maxDrawBuffers;
1294 break;
1295 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1296 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1297 case GL_SUBPIXEL_BITS:
1298 *params = 4;
1299 break;
1300 case GL_MAX_TEXTURE_SIZE:
1301 *params = mCaps.max2DTextureSize;
1302 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001303 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1304 *params = mCaps.maxRectangleTextureSize;
1305 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001306 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1307 *params = mCaps.maxCubeMapTextureSize;
1308 break;
1309 case GL_MAX_3D_TEXTURE_SIZE:
1310 *params = mCaps.max3DTextureSize;
1311 break;
1312 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1313 *params = mCaps.maxArrayTextureLayers;
1314 break;
1315 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1316 *params = mCaps.uniformBufferOffsetAlignment;
1317 break;
1318 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1319 *params = mCaps.maxUniformBufferBindings;
1320 break;
1321 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1322 *params = mCaps.maxVertexUniformBlocks;
1323 break;
1324 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1325 *params = mCaps.maxFragmentUniformBlocks;
1326 break;
1327 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1328 *params = mCaps.maxCombinedTextureImageUnits;
1329 break;
1330 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1331 *params = mCaps.maxVertexOutputComponents;
1332 break;
1333 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1334 *params = mCaps.maxFragmentInputComponents;
1335 break;
1336 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1337 *params = mCaps.minProgramTexelOffset;
1338 break;
1339 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1340 *params = mCaps.maxProgramTexelOffset;
1341 break;
1342 case GL_MAJOR_VERSION:
1343 *params = getClientVersion().major;
1344 break;
1345 case GL_MINOR_VERSION:
1346 *params = getClientVersion().minor;
1347 break;
1348 case GL_MAX_ELEMENTS_INDICES:
1349 *params = mCaps.maxElementsIndices;
1350 break;
1351 case GL_MAX_ELEMENTS_VERTICES:
1352 *params = mCaps.maxElementsVertices;
1353 break;
1354 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1355 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1356 break;
1357 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1358 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1359 break;
1360 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1361 *params = mCaps.maxTransformFeedbackSeparateComponents;
1362 break;
1363 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1364 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1365 break;
1366 case GL_MAX_SAMPLES_ANGLE:
1367 *params = mCaps.maxSamples;
1368 break;
1369 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001370 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001371 params[0] = mCaps.maxViewportWidth;
1372 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001373 }
1374 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001375 case GL_COMPRESSED_TEXTURE_FORMATS:
1376 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1377 params);
1378 break;
1379 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1380 *params = mResetStrategy;
1381 break;
1382 case GL_NUM_SHADER_BINARY_FORMATS:
1383 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1384 break;
1385 case GL_SHADER_BINARY_FORMATS:
1386 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1387 break;
1388 case GL_NUM_PROGRAM_BINARY_FORMATS:
1389 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1390 break;
1391 case GL_PROGRAM_BINARY_FORMATS:
1392 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1393 break;
1394 case GL_NUM_EXTENSIONS:
1395 *params = static_cast<GLint>(mExtensionStrings.size());
1396 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001397
Jamie Madill231c7f52017-04-26 13:45:37 -04001398 // GL_KHR_debug
1399 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1400 *params = mExtensions.maxDebugMessageLength;
1401 break;
1402 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1403 *params = mExtensions.maxDebugLoggedMessages;
1404 break;
1405 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1406 *params = mExtensions.maxDebugGroupStackDepth;
1407 break;
1408 case GL_MAX_LABEL_LENGTH:
1409 *params = mExtensions.maxLabelLength;
1410 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001411
Martin Radeve5285d22017-07-14 16:23:53 +03001412 // GL_ANGLE_multiview
1413 case GL_MAX_VIEWS_ANGLE:
1414 *params = mExtensions.maxViews;
1415 break;
1416
Jamie Madill231c7f52017-04-26 13:45:37 -04001417 // GL_EXT_disjoint_timer_query
1418 case GL_GPU_DISJOINT_EXT:
1419 *params = mImplementation->getGPUDisjoint();
1420 break;
1421 case GL_MAX_FRAMEBUFFER_WIDTH:
1422 *params = mCaps.maxFramebufferWidth;
1423 break;
1424 case GL_MAX_FRAMEBUFFER_HEIGHT:
1425 *params = mCaps.maxFramebufferHeight;
1426 break;
1427 case GL_MAX_FRAMEBUFFER_SAMPLES:
1428 *params = mCaps.maxFramebufferSamples;
1429 break;
1430 case GL_MAX_SAMPLE_MASK_WORDS:
1431 *params = mCaps.maxSampleMaskWords;
1432 break;
1433 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1434 *params = mCaps.maxColorTextureSamples;
1435 break;
1436 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1437 *params = mCaps.maxDepthTextureSamples;
1438 break;
1439 case GL_MAX_INTEGER_SAMPLES:
1440 *params = mCaps.maxIntegerSamples;
1441 break;
1442 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1443 *params = mCaps.maxVertexAttribRelativeOffset;
1444 break;
1445 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1446 *params = mCaps.maxVertexAttribBindings;
1447 break;
1448 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1449 *params = mCaps.maxVertexAttribStride;
1450 break;
1451 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1452 *params = mCaps.maxVertexAtomicCounterBuffers;
1453 break;
1454 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1455 *params = mCaps.maxVertexAtomicCounters;
1456 break;
1457 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1458 *params = mCaps.maxVertexImageUniforms;
1459 break;
1460 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1461 *params = mCaps.maxVertexShaderStorageBlocks;
1462 break;
1463 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1464 *params = mCaps.maxFragmentAtomicCounterBuffers;
1465 break;
1466 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1467 *params = mCaps.maxFragmentAtomicCounters;
1468 break;
1469 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1470 *params = mCaps.maxFragmentImageUniforms;
1471 break;
1472 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1473 *params = mCaps.maxFragmentShaderStorageBlocks;
1474 break;
1475 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1476 *params = mCaps.minProgramTextureGatherOffset;
1477 break;
1478 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1479 *params = mCaps.maxProgramTextureGatherOffset;
1480 break;
1481 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1482 *params = mCaps.maxComputeWorkGroupInvocations;
1483 break;
1484 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1485 *params = mCaps.maxComputeUniformBlocks;
1486 break;
1487 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1488 *params = mCaps.maxComputeTextureImageUnits;
1489 break;
1490 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1491 *params = mCaps.maxComputeSharedMemorySize;
1492 break;
1493 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1494 *params = mCaps.maxComputeUniformComponents;
1495 break;
1496 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1497 *params = mCaps.maxComputeAtomicCounterBuffers;
1498 break;
1499 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1500 *params = mCaps.maxComputeAtomicCounters;
1501 break;
1502 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1503 *params = mCaps.maxComputeImageUniforms;
1504 break;
1505 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1506 *params = mCaps.maxCombinedComputeUniformComponents;
1507 break;
1508 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1509 *params = mCaps.maxComputeShaderStorageBlocks;
1510 break;
1511 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1512 *params = mCaps.maxCombinedShaderOutputResources;
1513 break;
1514 case GL_MAX_UNIFORM_LOCATIONS:
1515 *params = mCaps.maxUniformLocations;
1516 break;
1517 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1518 *params = mCaps.maxAtomicCounterBufferBindings;
1519 break;
1520 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1521 *params = mCaps.maxAtomicCounterBufferSize;
1522 break;
1523 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1524 *params = mCaps.maxCombinedAtomicCounterBuffers;
1525 break;
1526 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1527 *params = mCaps.maxCombinedAtomicCounters;
1528 break;
1529 case GL_MAX_IMAGE_UNITS:
1530 *params = mCaps.maxImageUnits;
1531 break;
1532 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1533 *params = mCaps.maxCombinedImageUniforms;
1534 break;
1535 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1536 *params = mCaps.maxShaderStorageBufferBindings;
1537 break;
1538 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1539 *params = mCaps.maxCombinedShaderStorageBlocks;
1540 break;
1541 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1542 *params = mCaps.shaderStorageBufferOffsetAlignment;
1543 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001544
1545 // GL_EXT_geometry_shader
1546 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1547 *params = mCaps.maxFramebufferLayers;
1548 break;
1549 case GL_LAYER_PROVOKING_VERTEX_EXT:
1550 *params = mCaps.layerProvokingVertex;
1551 break;
1552 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1553 *params = mCaps.maxGeometryUniformComponents;
1554 break;
1555 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
1556 *params = mCaps.maxGeometryUniformBlocks;
1557 break;
1558 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1559 *params = mCaps.maxCombinedGeometryUniformComponents;
1560 break;
1561 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1562 *params = mCaps.maxGeometryInputComponents;
1563 break;
1564 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1565 *params = mCaps.maxGeometryOutputComponents;
1566 break;
1567 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1568 *params = mCaps.maxGeometryOutputVertices;
1569 break;
1570 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1571 *params = mCaps.maxGeometryTotalOutputComponents;
1572 break;
1573 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1574 *params = mCaps.maxGeometryShaderInvocations;
1575 break;
1576 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
1577 *params = mCaps.maxGeometryTextureImageUnits;
1578 break;
1579 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
1580 *params = mCaps.maxGeometryAtomicCounterBuffers;
1581 break;
1582 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
1583 *params = mCaps.maxGeometryAtomicCounters;
1584 break;
1585 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
1586 *params = mCaps.maxGeometryImageUniforms;
1587 break;
1588 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
1589 *params = mCaps.maxGeometryShaderStorageBlocks;
1590 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001591 default:
1592 mGLState.getIntegerv(this, pname, params);
1593 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001594 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001595}
1596
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001597void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001598{
Shannon Woods53a94a82014-06-24 15:20:36 -04001599 // Queries about context capabilities and maximums are answered by Context.
1600 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001601 switch (pname)
1602 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001603 case GL_MAX_ELEMENT_INDEX:
1604 *params = mCaps.maxElementIndex;
1605 break;
1606 case GL_MAX_UNIFORM_BLOCK_SIZE:
1607 *params = mCaps.maxUniformBlockSize;
1608 break;
1609 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1610 *params = mCaps.maxCombinedVertexUniformComponents;
1611 break;
1612 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1613 *params = mCaps.maxCombinedFragmentUniformComponents;
1614 break;
1615 case GL_MAX_SERVER_WAIT_TIMEOUT:
1616 *params = mCaps.maxServerWaitTimeout;
1617 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001618
Jamie Madill231c7f52017-04-26 13:45:37 -04001619 // GL_EXT_disjoint_timer_query
1620 case GL_TIMESTAMP_EXT:
1621 *params = mImplementation->getTimestamp();
1622 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001623
Jamie Madill231c7f52017-04-26 13:45:37 -04001624 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1625 *params = mCaps.maxShaderStorageBlockSize;
1626 break;
1627 default:
1628 UNREACHABLE();
1629 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001630 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001631}
1632
Geoff Lang70d0f492015-12-10 17:45:46 -05001633void Context::getPointerv(GLenum pname, void **params) const
1634{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001635 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001636}
1637
Martin Radev66fb8202016-07-28 11:45:20 +03001638void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001639{
Shannon Woods53a94a82014-06-24 15:20:36 -04001640 // Queries about context capabilities and maximums are answered by Context.
1641 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001642
1643 GLenum nativeType;
1644 unsigned int numParams;
1645 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1646 ASSERT(queryStatus);
1647
1648 if (nativeType == GL_INT)
1649 {
1650 switch (target)
1651 {
1652 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1653 ASSERT(index < 3u);
1654 *data = mCaps.maxComputeWorkGroupCount[index];
1655 break;
1656 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1657 ASSERT(index < 3u);
1658 *data = mCaps.maxComputeWorkGroupSize[index];
1659 break;
1660 default:
1661 mGLState.getIntegeri_v(target, index, data);
1662 }
1663 }
1664 else
1665 {
1666 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1667 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001668}
1669
Martin Radev66fb8202016-07-28 11:45:20 +03001670void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001671{
Shannon Woods53a94a82014-06-24 15:20:36 -04001672 // Queries about context capabilities and maximums are answered by Context.
1673 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001674
1675 GLenum nativeType;
1676 unsigned int numParams;
1677 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1678 ASSERT(queryStatus);
1679
1680 if (nativeType == GL_INT_64_ANGLEX)
1681 {
1682 mGLState.getInteger64i_v(target, index, data);
1683 }
1684 else
1685 {
1686 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1687 }
1688}
1689
1690void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1691{
1692 // Queries about context capabilities and maximums are answered by Context.
1693 // Queries about current GL state values are answered by State.
1694
1695 GLenum nativeType;
1696 unsigned int numParams;
1697 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1698 ASSERT(queryStatus);
1699
1700 if (nativeType == GL_BOOL)
1701 {
1702 mGLState.getBooleani_v(target, index, data);
1703 }
1704 else
1705 {
1706 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1707 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001708}
1709
Corentin Wallez336129f2017-10-17 15:55:40 -04001710void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001711{
1712 Buffer *buffer = mGLState.getTargetBuffer(target);
1713 QueryBufferParameteriv(buffer, pname, params);
1714}
1715
1716void Context::getFramebufferAttachmentParameteriv(GLenum target,
1717 GLenum attachment,
1718 GLenum pname,
1719 GLint *params)
1720{
1721 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001722 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001723}
1724
1725void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1726{
1727 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1728 QueryRenderbufferiv(this, renderbuffer, pname, params);
1729}
1730
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001731void Context::getTexParameterfv(TextureType target, GLenum pname, GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001732{
1733 Texture *texture = getTargetTexture(target);
1734 QueryTexParameterfv(texture, pname, params);
1735}
1736
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001737void Context::getTexParameteriv(TextureType target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001738{
1739 Texture *texture = getTargetTexture(target);
1740 QueryTexParameteriv(texture, pname, params);
1741}
Jiajia Qin5451d532017-11-16 17:16:34 +08001742
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001743void Context::getTexLevelParameteriv(TextureTarget target, GLint level, GLenum pname, GLint *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001744{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001745 Texture *texture = getTargetTexture(TextureTargetToType(target));
1746 QueryTexLevelParameteriv(texture, ToGLenum(target), level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001747}
1748
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001749void Context::getTexLevelParameterfv(TextureTarget target,
1750 GLint level,
1751 GLenum pname,
1752 GLfloat *params)
Jiajia Qin5451d532017-11-16 17:16:34 +08001753{
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001754 Texture *texture = getTargetTexture(TextureTargetToType(target));
1755 QueryTexLevelParameterfv(texture, ToGLenum(target), level, pname, params);
Jiajia Qin5451d532017-11-16 17:16:34 +08001756}
1757
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001758void Context::texParameterf(TextureType target, GLenum pname, GLfloat param)
He Yunchao010e4db2017-03-03 14:22:06 +08001759{
1760 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001761 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001762 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001763}
1764
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001765void Context::texParameterfv(TextureType target, GLenum pname, const GLfloat *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001766{
1767 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001768 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001769 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001770}
1771
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001772void Context::texParameteri(TextureType target, GLenum pname, GLint param)
He Yunchao010e4db2017-03-03 14:22:06 +08001773{
1774 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001775 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001776 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001777}
1778
Corentin Wallezf0e89be2017-11-08 14:00:32 -08001779void Context::texParameteriv(TextureType target, GLenum pname, const GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001780{
1781 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001782 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001783 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001784}
1785
Jamie Madill675fe712016-12-19 13:07:54 -05001786void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001787{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001788 // No-op if zero count
1789 if (count == 0)
1790 {
1791 return;
1792 }
1793
Jamie Madill05b35b22017-10-03 09:01:44 -04001794 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001795 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
1796 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001797}
1798
Jamie Madill675fe712016-12-19 13:07:54 -05001799void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001800{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001801 // No-op if zero count
1802 if (count == 0 || instanceCount == 0)
1803 {
1804 return;
1805 }
1806
Jamie Madill05b35b22017-10-03 09:01:44 -04001807 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001808 ANGLE_CONTEXT_TRY(
1809 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
1810 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
Geoff Langf6db0982015-08-25 13:04:00 -04001811}
1812
Jamie Madill876429b2017-04-20 15:46:24 -04001813void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001814{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001815 // No-op if zero count
1816 if (count == 0)
1817 {
1818 return;
1819 }
1820
Jamie Madill05b35b22017-10-03 09:01:44 -04001821 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001822 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001823}
1824
Jamie Madill675fe712016-12-19 13:07:54 -05001825void Context::drawElementsInstanced(GLenum mode,
1826 GLsizei count,
1827 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001828 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001829 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001830{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001831 // No-op if zero count
1832 if (count == 0 || instances == 0)
1833 {
1834 return;
1835 }
1836
Jamie Madill05b35b22017-10-03 09:01:44 -04001837 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001838 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001839 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001840}
1841
Jamie Madill675fe712016-12-19 13:07:54 -05001842void Context::drawRangeElements(GLenum mode,
1843 GLuint start,
1844 GLuint end,
1845 GLsizei count,
1846 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001847 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001848{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001849 // No-op if zero count
1850 if (count == 0)
1851 {
1852 return;
1853 }
1854
Jamie Madill05b35b22017-10-03 09:01:44 -04001855 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001856 ANGLE_CONTEXT_TRY(
1857 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001858}
1859
Jamie Madill876429b2017-04-20 15:46:24 -04001860void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001861{
Jamie Madill05b35b22017-10-03 09:01:44 -04001862 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001863 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001864}
1865
Jamie Madill876429b2017-04-20 15:46:24 -04001866void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001867{
Jamie Madill05b35b22017-10-03 09:01:44 -04001868 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001869 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001870}
1871
Jamie Madill675fe712016-12-19 13:07:54 -05001872void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001873{
Jamie Madillafa02a22017-11-23 12:57:38 -05001874 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05001875}
1876
Jamie Madill675fe712016-12-19 13:07:54 -05001877void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001878{
Jamie Madillafa02a22017-11-23 12:57:38 -05001879 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001880}
1881
Austin Kinross6ee1e782015-05-29 17:05:37 -07001882void Context::insertEventMarker(GLsizei length, const char *marker)
1883{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001884 ASSERT(mImplementation);
1885 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001886}
1887
1888void Context::pushGroupMarker(GLsizei length, const char *marker)
1889{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001890 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05001891
1892 if (marker == nullptr)
1893 {
1894 // From the EXT_debug_marker spec,
1895 // "If <marker> is null then an empty string is pushed on the stack."
1896 mImplementation->pushGroupMarker(length, "");
1897 }
1898 else
1899 {
1900 mImplementation->pushGroupMarker(length, marker);
1901 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07001902}
1903
1904void Context::popGroupMarker()
1905{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001906 ASSERT(mImplementation);
1907 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001908}
1909
Geoff Langd8605522016-04-13 10:19:12 -04001910void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1911{
1912 Program *programObject = getProgram(program);
1913 ASSERT(programObject);
1914
1915 programObject->bindUniformLocation(location, name);
1916}
1917
Sami Väisänena797e062016-05-12 15:23:40 +03001918void Context::setCoverageModulation(GLenum components)
1919{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001920 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001921}
1922
Sami Väisänene45e53b2016-05-25 10:36:04 +03001923void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1924{
1925 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1926}
1927
1928void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1929{
1930 GLfloat I[16];
1931 angle::Matrix<GLfloat>::setToIdentity(I);
1932
1933 mGLState.loadPathRenderingMatrix(matrixMode, I);
1934}
1935
1936void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1937{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001938 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001939 if (!pathObj)
1940 return;
1941
1942 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1943 syncRendererState();
1944
1945 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1946}
1947
1948void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1949{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001950 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001951 if (!pathObj)
1952 return;
1953
1954 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1955 syncRendererState();
1956
1957 mImplementation->stencilStrokePath(pathObj, reference, mask);
1958}
1959
1960void Context::coverFillPath(GLuint path, GLenum coverMode)
1961{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001962 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001963 if (!pathObj)
1964 return;
1965
1966 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1967 syncRendererState();
1968
1969 mImplementation->coverFillPath(pathObj, coverMode);
1970}
1971
1972void Context::coverStrokePath(GLuint path, GLenum coverMode)
1973{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001974 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001975 if (!pathObj)
1976 return;
1977
1978 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1979 syncRendererState();
1980
1981 mImplementation->coverStrokePath(pathObj, coverMode);
1982}
1983
1984void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1985{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001986 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001987 if (!pathObj)
1988 return;
1989
1990 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1991 syncRendererState();
1992
1993 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
1994}
1995
1996void Context::stencilThenCoverStrokePath(GLuint path,
1997 GLint reference,
1998 GLuint mask,
1999 GLenum coverMode)
2000{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002001 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03002002 if (!pathObj)
2003 return;
2004
2005 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2006 syncRendererState();
2007
2008 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2009}
2010
Sami Väisänend59ca052016-06-21 16:10:00 +03002011void Context::coverFillPathInstanced(GLsizei numPaths,
2012 GLenum pathNameType,
2013 const void *paths,
2014 GLuint pathBase,
2015 GLenum coverMode,
2016 GLenum transformType,
2017 const GLfloat *transformValues)
2018{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002019 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002020
2021 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2022 syncRendererState();
2023
2024 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2025}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002026
Sami Väisänend59ca052016-06-21 16:10:00 +03002027void Context::coverStrokePathInstanced(GLsizei numPaths,
2028 GLenum pathNameType,
2029 const void *paths,
2030 GLuint pathBase,
2031 GLenum coverMode,
2032 GLenum transformType,
2033 const GLfloat *transformValues)
2034{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002035 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002036
2037 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2038 syncRendererState();
2039
2040 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2041 transformValues);
2042}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002043
Sami Väisänend59ca052016-06-21 16:10:00 +03002044void Context::stencilFillPathInstanced(GLsizei numPaths,
2045 GLenum pathNameType,
2046 const void *paths,
2047 GLuint pathBase,
2048 GLenum fillMode,
2049 GLuint mask,
2050 GLenum transformType,
2051 const GLfloat *transformValues)
2052{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002053 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002054
2055 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2056 syncRendererState();
2057
2058 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2059 transformValues);
2060}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002061
Sami Väisänend59ca052016-06-21 16:10:00 +03002062void Context::stencilStrokePathInstanced(GLsizei numPaths,
2063 GLenum pathNameType,
2064 const void *paths,
2065 GLuint pathBase,
2066 GLint reference,
2067 GLuint mask,
2068 GLenum transformType,
2069 const GLfloat *transformValues)
2070{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002071 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002072
2073 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2074 syncRendererState();
2075
2076 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2077 transformValues);
2078}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002079
Sami Väisänend59ca052016-06-21 16:10:00 +03002080void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2081 GLenum pathNameType,
2082 const void *paths,
2083 GLuint pathBase,
2084 GLenum fillMode,
2085 GLuint mask,
2086 GLenum coverMode,
2087 GLenum transformType,
2088 const GLfloat *transformValues)
2089{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002090 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002091
2092 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2093 syncRendererState();
2094
2095 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2096 transformType, transformValues);
2097}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002098
Sami Väisänend59ca052016-06-21 16:10:00 +03002099void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2100 GLenum pathNameType,
2101 const void *paths,
2102 GLuint pathBase,
2103 GLint reference,
2104 GLuint mask,
2105 GLenum coverMode,
2106 GLenum transformType,
2107 const GLfloat *transformValues)
2108{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002109 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002110
2111 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2112 syncRendererState();
2113
2114 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2115 transformType, transformValues);
2116}
2117
Sami Väisänen46eaa942016-06-29 10:26:37 +03002118void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2119{
2120 auto *programObject = getProgram(program);
2121
2122 programObject->bindFragmentInputLocation(location, name);
2123}
2124
2125void Context::programPathFragmentInputGen(GLuint program,
2126 GLint location,
2127 GLenum genMode,
2128 GLint components,
2129 const GLfloat *coeffs)
2130{
2131 auto *programObject = getProgram(program);
2132
Jamie Madillbd044ed2017-06-05 12:59:21 -04002133 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002134}
2135
jchen1015015f72017-03-16 13:54:21 +08002136GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2137{
jchen10fd7c3b52017-03-21 15:36:03 +08002138 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002139 return QueryProgramResourceIndex(programObject, programInterface, name);
2140}
2141
jchen10fd7c3b52017-03-21 15:36:03 +08002142void Context::getProgramResourceName(GLuint program,
2143 GLenum programInterface,
2144 GLuint index,
2145 GLsizei bufSize,
2146 GLsizei *length,
2147 GLchar *name)
2148{
2149 const auto *programObject = getProgram(program);
2150 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2151}
2152
jchen10191381f2017-04-11 13:59:04 +08002153GLint Context::getProgramResourceLocation(GLuint program,
2154 GLenum programInterface,
2155 const GLchar *name)
2156{
2157 const auto *programObject = getProgram(program);
2158 return QueryProgramResourceLocation(programObject, programInterface, name);
2159}
2160
jchen10880683b2017-04-12 16:21:55 +08002161void Context::getProgramResourceiv(GLuint program,
2162 GLenum programInterface,
2163 GLuint index,
2164 GLsizei propCount,
2165 const GLenum *props,
2166 GLsizei bufSize,
2167 GLsizei *length,
2168 GLint *params)
2169{
2170 const auto *programObject = getProgram(program);
2171 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2172 length, params);
2173}
2174
jchen10d9cd7b72017-08-30 15:04:25 +08002175void Context::getProgramInterfaceiv(GLuint program,
2176 GLenum programInterface,
2177 GLenum pname,
2178 GLint *params)
2179{
2180 const auto *programObject = getProgram(program);
2181 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2182}
2183
Jamie Madill71c88b32017-09-14 22:20:29 -04002184void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002185{
Geoff Langda5777c2014-07-11 09:52:58 -04002186 if (error.isError())
2187 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002188 GLenum code = error.getCode();
2189 mErrors.insert(code);
2190 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2191 {
2192 markContextLost();
2193 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002194
Geoff Langee6884e2017-11-09 16:51:11 -05002195 ASSERT(!error.getMessage().empty());
2196 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2197 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002198 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002199}
2200
2201// Get one of the recorded errors and clear its flag, if any.
2202// [OpenGL ES 2.0.24] section 2.5 page 13.
2203GLenum Context::getError()
2204{
Geoff Langda5777c2014-07-11 09:52:58 -04002205 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002206 {
Geoff Langda5777c2014-07-11 09:52:58 -04002207 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002208 }
Geoff Langda5777c2014-07-11 09:52:58 -04002209 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002210 {
Geoff Langda5777c2014-07-11 09:52:58 -04002211 GLenum error = *mErrors.begin();
2212 mErrors.erase(mErrors.begin());
2213 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002214 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002215}
2216
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002217// NOTE: this function should not assume that this context is current!
2218void Context::markContextLost()
2219{
2220 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002221 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002222 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002223 mContextLostForced = true;
2224 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002225 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002226}
2227
2228bool Context::isContextLost()
2229{
2230 return mContextLost;
2231}
2232
Jamie Madillfa920eb2018-01-04 11:45:50 -05002233GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002234{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002235 // Even if the application doesn't want to know about resets, we want to know
2236 // as it will allow us to skip all the calls.
2237 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002238 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002239 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002240 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002241 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002242 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002243
2244 // EXT_robustness, section 2.6: If the reset notification behavior is
2245 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2246 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2247 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002248 }
2249
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002250 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2251 // status should be returned at least once, and GL_NO_ERROR should be returned
2252 // once the device has finished resetting.
2253 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002254 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002255 ASSERT(mResetStatus == GL_NO_ERROR);
2256 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002257
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002258 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002259 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002260 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002261 }
2262 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002263 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002264 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002265 // If markContextLost was used to mark the context lost then
2266 // assume that is not recoverable, and continue to report the
2267 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002268 mResetStatus = mImplementation->getResetStatus();
2269 }
Jamie Madill893ab082014-05-16 16:56:10 -04002270
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002271 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002272}
2273
2274bool Context::isResetNotificationEnabled()
2275{
2276 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2277}
2278
Corentin Walleze3b10e82015-05-20 11:06:25 -04002279const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002280{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002281 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002282}
2283
2284EGLenum Context::getClientType() const
2285{
2286 return mClientType;
2287}
2288
2289EGLenum Context::getRenderBuffer() const
2290{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002291 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2292 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002293 {
2294 return EGL_NONE;
2295 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002296
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002297 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002298 ASSERT(backAttachment != nullptr);
2299 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002300}
2301
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002302VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002303{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002304 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002305 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2306 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002307 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002308 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2309 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002310
Jamie Madill96a483b2017-06-27 16:49:21 -04002311 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002312 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002313
2314 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002315}
2316
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002317TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002318{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002319 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002320 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2321 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002322 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002323 transformFeedback =
2324 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002325 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002326 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002327 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002328
2329 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002330}
2331
2332bool Context::isVertexArrayGenerated(GLuint vertexArray)
2333{
Jamie Madill96a483b2017-06-27 16:49:21 -04002334 ASSERT(mVertexArrayMap.contains(0));
2335 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002336}
2337
2338bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2339{
Jamie Madill96a483b2017-06-27 16:49:21 -04002340 ASSERT(mTransformFeedbackMap.contains(0));
2341 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002342}
2343
Shannon Woods53a94a82014-06-24 15:20:36 -04002344void Context::detachTexture(GLuint texture)
2345{
2346 // Simple pass-through to State's detachTexture method, as textures do not require
2347 // allocation map management either here or in the resource manager at detach time.
2348 // Zero textures are held by the Context, and we don't attempt to request them from
2349 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002350 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002351}
2352
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002353void Context::detachBuffer(GLuint buffer)
2354{
Yuly Novikov5807a532015-12-03 13:01:22 -05002355 // Simple pass-through to State's detachBuffer method, since
2356 // only buffer attachments to container objects that are bound to the current context
2357 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002358
Yuly Novikov5807a532015-12-03 13:01:22 -05002359 // [OpenGL ES 3.2] section 5.1.2 page 45:
2360 // Attachments to unbound container objects, such as
2361 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2362 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002363 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002364}
2365
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002366void Context::detachFramebuffer(GLuint framebuffer)
2367{
Shannon Woods53a94a82014-06-24 15:20:36 -04002368 // Framebuffer detachment is handled by Context, because 0 is a valid
2369 // Framebuffer object, and a pointer to it must be passed from Context
2370 // to State at binding time.
2371
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002372 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002373 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2374 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2375 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002376
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002377 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002378 {
2379 bindReadFramebuffer(0);
2380 }
2381
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002382 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002383 {
2384 bindDrawFramebuffer(0);
2385 }
2386}
2387
2388void Context::detachRenderbuffer(GLuint renderbuffer)
2389{
Jamie Madilla02315b2017-02-23 14:14:47 -05002390 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002391}
2392
Jamie Madill57a89722013-07-02 11:57:03 -04002393void Context::detachVertexArray(GLuint vertexArray)
2394{
Jamie Madill77a72f62015-04-14 11:18:32 -04002395 // Vertex array detachment is handled by Context, because 0 is a valid
2396 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002397 // binding time.
2398
Jamie Madill57a89722013-07-02 11:57:03 -04002399 // [OpenGL ES 3.0.2] section 2.10 page 43:
2400 // If a vertex array object that is currently bound is deleted, the binding
2401 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002402 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002403 {
2404 bindVertexArray(0);
2405 }
2406}
2407
Geoff Langc8058452014-02-03 12:04:11 -05002408void Context::detachTransformFeedback(GLuint transformFeedback)
2409{
Corentin Walleza2257da2016-04-19 16:43:12 -04002410 // Transform feedback detachment is handled by Context, because 0 is a valid
2411 // transform feedback, and a pointer to it must be passed from Context to State at
2412 // binding time.
2413
2414 // The OpenGL specification doesn't mention what should happen when the currently bound
2415 // transform feedback object is deleted. Since it is a container object, we treat it like
2416 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002417 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002418 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002419 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002420 }
Geoff Langc8058452014-02-03 12:04:11 -05002421}
2422
Jamie Madilldc356042013-07-19 16:36:57 -04002423void Context::detachSampler(GLuint sampler)
2424{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002425 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002426}
2427
Yunchao Hea336b902017-08-02 16:05:21 +08002428void Context::detachProgramPipeline(GLuint pipeline)
2429{
2430 mGLState.detachProgramPipeline(this, pipeline);
2431}
2432
Jamie Madill3ef140a2017-08-26 23:11:21 -04002433void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002434{
Shaodde78e82017-05-22 14:13:27 +08002435 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002436}
2437
Jamie Madille29d1672013-07-19 16:36:57 -04002438void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2439{
Geoff Langc1984ed2016-10-07 12:41:00 -04002440 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002441 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002442 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002443 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002444}
Jamie Madille29d1672013-07-19 16:36:57 -04002445
Geoff Langc1984ed2016-10-07 12:41:00 -04002446void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2447{
2448 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002449 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002450 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002451 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002452}
2453
2454void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2455{
Geoff Langc1984ed2016-10-07 12:41:00 -04002456 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002457 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002458 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002459 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002460}
2461
Geoff Langc1984ed2016-10-07 12:41:00 -04002462void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002463{
Geoff Langc1984ed2016-10-07 12:41:00 -04002464 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002465 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002466 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002467 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002468}
2469
Geoff Langc1984ed2016-10-07 12:41:00 -04002470void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002471{
Geoff Langc1984ed2016-10-07 12:41:00 -04002472 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002473 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002474 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002475 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002476}
Jamie Madill9675b802013-07-19 16:36:59 -04002477
Geoff Langc1984ed2016-10-07 12:41:00 -04002478void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2479{
2480 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002481 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002482 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002483 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002484}
2485
Olli Etuahof0fee072016-03-30 15:11:58 +03002486void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2487{
2488 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002489 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002490}
2491
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002492void Context::initRendererString()
2493{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002494 std::ostringstream rendererString;
2495 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002496 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002497 rendererString << ")";
2498
Geoff Langcec35902014-04-16 10:52:36 -04002499 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002500}
2501
Geoff Langc339c4e2016-11-29 10:37:36 -05002502void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002503{
Geoff Langc339c4e2016-11-29 10:37:36 -05002504 const Version &clientVersion = getClientVersion();
2505
2506 std::ostringstream versionString;
2507 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2508 << ANGLE_VERSION_STRING << ")";
2509 mVersionString = MakeStaticString(versionString.str());
2510
2511 std::ostringstream shadingLanguageVersionString;
2512 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2513 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2514 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2515 << ")";
2516 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002517}
2518
Geoff Langcec35902014-04-16 10:52:36 -04002519void Context::initExtensionStrings()
2520{
Geoff Langc339c4e2016-11-29 10:37:36 -05002521 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2522 std::ostringstream combinedStringStream;
2523 std::copy(strings.begin(), strings.end(),
2524 std::ostream_iterator<const char *>(combinedStringStream, " "));
2525 return MakeStaticString(combinedStringStream.str());
2526 };
2527
2528 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002529 for (const auto &extensionString : mExtensions.getStrings())
2530 {
2531 mExtensionStrings.push_back(MakeStaticString(extensionString));
2532 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002533 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002534
Bryan Bernhart58806562017-01-05 13:09:31 -08002535 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2536
Geoff Langc339c4e2016-11-29 10:37:36 -05002537 mRequestableExtensionStrings.clear();
2538 for (const auto &extensionInfo : GetExtensionInfoMap())
2539 {
2540 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002541 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2542 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002543 {
2544 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2545 }
2546 }
2547 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002548}
2549
Geoff Langc339c4e2016-11-29 10:37:36 -05002550const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002551{
Geoff Langc339c4e2016-11-29 10:37:36 -05002552 switch (name)
2553 {
2554 case GL_VENDOR:
2555 return reinterpret_cast<const GLubyte *>("Google Inc.");
2556
2557 case GL_RENDERER:
2558 return reinterpret_cast<const GLubyte *>(mRendererString);
2559
2560 case GL_VERSION:
2561 return reinterpret_cast<const GLubyte *>(mVersionString);
2562
2563 case GL_SHADING_LANGUAGE_VERSION:
2564 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2565
2566 case GL_EXTENSIONS:
2567 return reinterpret_cast<const GLubyte *>(mExtensionString);
2568
2569 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2570 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2571
2572 default:
2573 UNREACHABLE();
2574 return nullptr;
2575 }
Geoff Langcec35902014-04-16 10:52:36 -04002576}
2577
Geoff Langc339c4e2016-11-29 10:37:36 -05002578const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002579{
Geoff Langc339c4e2016-11-29 10:37:36 -05002580 switch (name)
2581 {
2582 case GL_EXTENSIONS:
2583 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2584
2585 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2586 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2587
2588 default:
2589 UNREACHABLE();
2590 return nullptr;
2591 }
Geoff Langcec35902014-04-16 10:52:36 -04002592}
2593
2594size_t Context::getExtensionStringCount() const
2595{
2596 return mExtensionStrings.size();
2597}
2598
Geoff Lang111a99e2017-10-17 10:58:41 -04002599bool Context::isExtensionRequestable(const char *name)
2600{
2601 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2602 auto extension = extensionInfos.find(name);
2603
2604 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2605 return extension != extensionInfos.end() && extension->second.Requestable &&
2606 nativeExtensions.*(extension->second.ExtensionsMember);
2607}
2608
Geoff Langc339c4e2016-11-29 10:37:36 -05002609void Context::requestExtension(const char *name)
2610{
2611 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2612 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2613 const auto &extension = extensionInfos.at(name);
2614 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002615 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002616
2617 if (mExtensions.*(extension.ExtensionsMember))
2618 {
2619 // Extension already enabled
2620 return;
2621 }
2622
2623 mExtensions.*(extension.ExtensionsMember) = true;
2624 updateCaps();
2625 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002626
Jamie Madill2f348d22017-06-05 10:50:59 -04002627 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2628 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002629
Jamie Madill81c2e252017-09-09 23:32:46 -04002630 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2631 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002632 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002633 for (auto &zeroTexture : mZeroTextures)
2634 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08002635 if (zeroTexture.get() != nullptr)
2636 {
2637 zeroTexture->signalDirty(this, InitState::Initialized);
2638 }
Geoff Lang9aded172017-04-05 11:07:56 -04002639 }
2640
2641 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002642}
2643
2644size_t Context::getRequestableExtensionStringCount() const
2645{
2646 return mRequestableExtensionStrings.size();
2647}
2648
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002649void Context::beginTransformFeedback(GLenum primitiveMode)
2650{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002651 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002652 ASSERT(transformFeedback != nullptr);
2653 ASSERT(!transformFeedback->isPaused());
2654
Jamie Madill6c1f6712017-02-14 19:08:04 -05002655 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002656}
2657
2658bool Context::hasActiveTransformFeedback(GLuint program) const
2659{
2660 for (auto pair : mTransformFeedbackMap)
2661 {
2662 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2663 {
2664 return true;
2665 }
2666 }
2667 return false;
2668}
2669
Geoff Langb433e872017-10-05 14:01:47 -04002670void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002671{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002672 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002673
Lingfeng Yangb27b03a2018-02-19 13:38:48 -08002674 // GLES1 emulation: Initialize caps (Table 6.20 / 6.22 in the ES 1.1 spec)
2675 if (getClientVersion() < Version(2, 0))
2676 {
2677 mCaps.maxMultitextureUnits = 4;
2678 mCaps.maxClipPlanes = 6;
2679 mCaps.maxLights = 8;
2680 mCaps.maxModelviewMatrixStackDepth = 16;
2681 mCaps.maxProjectionMatrixStackDepth = 16;
2682 mCaps.maxTextureMatrixStackDepth = 16;
2683 }
2684
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002685 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002686
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002687 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002688
Geoff Langeb66a6e2016-10-31 13:06:12 -04002689 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002690 {
2691 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002692 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002693 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002694 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002695 mExtensions.multiview = false;
2696 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002697 }
2698
Jiawei Shao89be29a2017-11-06 14:36:45 +08002699 if (getClientVersion() < ES_3_1)
2700 {
2701 // Disable ES3.1+ extensions
2702 mExtensions.geometryShader = false;
2703 }
2704
Geoff Langeb66a6e2016-10-31 13:06:12 -04002705 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002706 {
2707 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002708 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002709 }
2710
Jamie Madill00ed7a12016-05-19 13:13:38 -04002711 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002712 mExtensions.bindUniformLocation = true;
2713 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002714 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002715 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002716 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002717
2718 // Enable the no error extension if the context was created with the flag.
2719 mExtensions.noError = mSkipValidation;
2720
Corentin Wallezccab69d2017-01-27 16:57:15 -05002721 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002722 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002723
Geoff Lang70d0f492015-12-10 17:45:46 -05002724 // Explicitly enable GL_KHR_debug
2725 mExtensions.debug = true;
2726 mExtensions.maxDebugMessageLength = 1024;
2727 mExtensions.maxDebugLoggedMessages = 1024;
2728 mExtensions.maxDebugGroupStackDepth = 1024;
2729 mExtensions.maxLabelLength = 1024;
2730
Geoff Langff5b2d52016-09-07 11:32:23 -04002731 // Explicitly enable GL_ANGLE_robust_client_memory
2732 mExtensions.robustClientMemory = true;
2733
Jamie Madille08a1d32017-03-07 17:24:06 -05002734 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002735 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002736
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002737 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2738 // supports it.
2739 mExtensions.robustBufferAccessBehavior =
2740 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2741
Jamie Madillc43be722017-07-13 16:22:14 -04002742 // Enable the cache control query unconditionally.
2743 mExtensions.programCacheControl = true;
2744
Geoff Lang301d1612014-07-09 10:34:37 -04002745 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002746 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002747
Jamie Madill0f80ed82017-09-19 00:24:56 -04002748 if (getClientVersion() < ES_3_1)
2749 {
2750 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2751 }
2752 else
2753 {
2754 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2755 }
Geoff Lang301d1612014-07-09 10:34:37 -04002756
Jamie Madill0f80ed82017-09-19 00:24:56 -04002757 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2758 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2759 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2760
2761 // Limit textures as well, so we can use fast bitsets with texture bindings.
2762 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2763 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2764 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002765
Jiawei Shaodb342272017-09-27 10:21:45 +08002766 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2767
Geoff Langc287ea62016-09-16 14:46:51 -04002768 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002769 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002770 for (const auto &extensionInfo : GetExtensionInfoMap())
2771 {
2772 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002773 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002774 {
2775 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2776 }
2777 }
2778
2779 // Generate texture caps
2780 updateCaps();
2781}
2782
2783void Context::updateCaps()
2784{
Geoff Lang900013c2014-07-07 11:32:19 -04002785 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002786 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002787
Jamie Madill7b62cf92017-11-02 15:20:49 -04002788 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04002789 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04002790 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04002791 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002792
Geoff Lang0d8b7242015-09-09 14:56:53 -04002793 // Update the format caps based on the client version and extensions.
2794 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2795 // ES3.
2796 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002797 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002798 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002799 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002800 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002801 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002802
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002803 // OpenGL ES does not support multisampling with non-rendererable formats
2804 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002805 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002806 (getClientVersion() < ES_3_1 &&
2807 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002808 {
Geoff Langd87878e2014-09-19 15:42:59 -04002809 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002810 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002811 else
2812 {
2813 // We may have limited the max samples for some required renderbuffer formats due to
2814 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2815 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2816
2817 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2818 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2819 // exception of signed and unsigned integer formats."
2820 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2821 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2822 {
2823 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2824 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2825 }
2826
2827 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2828 if (getClientVersion() >= ES_3_1)
2829 {
2830 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2831 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2832 // the exception that the signed and unsigned integer formats are required only to
2833 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2834 // multisamples, which must be at least one."
2835 if (formatInfo.componentType == GL_INT ||
2836 formatInfo.componentType == GL_UNSIGNED_INT)
2837 {
2838 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2839 }
2840
2841 // GLES 3.1 section 19.3.1.
2842 if (formatCaps.texturable)
2843 {
2844 if (formatInfo.depthBits > 0)
2845 {
2846 mCaps.maxDepthTextureSamples =
2847 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2848 }
2849 else if (formatInfo.redBits > 0)
2850 {
2851 mCaps.maxColorTextureSamples =
2852 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2853 }
2854 }
2855 }
2856 }
Geoff Langd87878e2014-09-19 15:42:59 -04002857
2858 if (formatCaps.texturable && formatInfo.compressed)
2859 {
Geoff Langca271392017-04-05 12:30:00 -04002860 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002861 }
2862
Geoff Langca271392017-04-05 12:30:00 -04002863 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002864 }
Jamie Madill32447362017-06-28 14:53:52 -04002865
2866 // If program binary is disabled, blank out the memory cache pointer.
2867 if (!mImplementation->getNativeExtensions().getProgramBinary)
2868 {
2869 mMemoryProgramCache = nullptr;
2870 }
Corentin Walleze4477002017-12-01 14:39:58 -05002871
2872 // Compute which buffer types are allowed
2873 mValidBufferBindings.reset();
2874 mValidBufferBindings.set(BufferBinding::ElementArray);
2875 mValidBufferBindings.set(BufferBinding::Array);
2876
2877 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
2878 {
2879 mValidBufferBindings.set(BufferBinding::PixelPack);
2880 mValidBufferBindings.set(BufferBinding::PixelUnpack);
2881 }
2882
2883 if (getClientVersion() >= ES_3_0)
2884 {
2885 mValidBufferBindings.set(BufferBinding::CopyRead);
2886 mValidBufferBindings.set(BufferBinding::CopyWrite);
2887 mValidBufferBindings.set(BufferBinding::TransformFeedback);
2888 mValidBufferBindings.set(BufferBinding::Uniform);
2889 }
2890
2891 if (getClientVersion() >= ES_3_1)
2892 {
2893 mValidBufferBindings.set(BufferBinding::AtomicCounter);
2894 mValidBufferBindings.set(BufferBinding::ShaderStorage);
2895 mValidBufferBindings.set(BufferBinding::DrawIndirect);
2896 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
2897 }
Geoff Lang493daf52014-07-03 13:38:44 -04002898}
2899
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002900void Context::initWorkarounds()
2901{
Jamie Madill761b02c2017-06-23 16:27:06 -04002902 // Apply back-end workarounds.
2903 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2904
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002905 // Lose the context upon out of memory error if the application is
2906 // expecting to watch for those events.
2907 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2908}
2909
Jamie Madill05b35b22017-10-03 09:01:44 -04002910Error Context::prepareForDraw()
2911{
2912 syncRendererState();
Jamie Madilla59fc192017-11-02 12:57:58 -04002913
2914 if (isRobustResourceInitEnabled())
2915 {
2916 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
2917 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
2918 }
2919
Jamie Madill05b35b22017-10-03 09:01:44 -04002920 return NoError();
2921}
2922
Jamie Madill1b94d432015-08-07 13:23:23 -04002923void Context::syncRendererState()
2924{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002925 mGLState.syncDirtyObjects(this);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002926 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madillfe548342017-06-19 11:13:24 -04002927 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002928 mGLState.clearDirtyBits();
Jamie Madill1b94d432015-08-07 13:23:23 -04002929}
2930
Jamie Madillad9f24e2016-02-12 09:27:24 -05002931void Context::syncRendererState(const State::DirtyBits &bitMask,
2932 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002933{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002934 mGLState.syncDirtyObjects(this, objectMask);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002935 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002936 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002937 mGLState.clearDirtyBits(dirtyBits);
Jamie Madill1b94d432015-08-07 13:23:23 -04002938}
Jamie Madillc29968b2016-01-20 11:17:23 -05002939
2940void Context::blitFramebuffer(GLint srcX0,
2941 GLint srcY0,
2942 GLint srcX1,
2943 GLint srcY1,
2944 GLint dstX0,
2945 GLint dstY0,
2946 GLint dstX1,
2947 GLint dstY1,
2948 GLbitfield mask,
2949 GLenum filter)
2950{
Qin Jiajiaaef92162018-02-27 13:51:44 +08002951 if (mask == 0)
2952 {
2953 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
2954 // buffers are copied.
2955 return;
2956 }
2957
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002958 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002959 ASSERT(drawFramebuffer);
2960
2961 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2962 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2963
Jamie Madillad9f24e2016-02-12 09:27:24 -05002964 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002965
Jamie Madillc564c072017-06-01 12:45:42 -04002966 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002967}
Jamie Madillc29968b2016-01-20 11:17:23 -05002968
2969void Context::clear(GLbitfield mask)
2970{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002971 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002972 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002973}
2974
2975void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2976{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002977 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002978 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002979}
2980
2981void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2982{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002983 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002984 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002985}
2986
2987void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2988{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002989 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002990 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002991}
2992
2993void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2994{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002995 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002996 ASSERT(framebufferObject);
2997
2998 // If a buffer is not present, the clear has no effect
2999 if (framebufferObject->getDepthbuffer() == nullptr &&
3000 framebufferObject->getStencilbuffer() == nullptr)
3001 {
3002 return;
3003 }
3004
Jamie Madillad9f24e2016-02-12 09:27:24 -05003005 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04003006 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05003007}
3008
3009void Context::readPixels(GLint x,
3010 GLint y,
3011 GLsizei width,
3012 GLsizei height,
3013 GLenum format,
3014 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003015 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05003016{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003017 if (width == 0 || height == 0)
3018 {
3019 return;
3020 }
3021
Jamie Madillad9f24e2016-02-12 09:27:24 -05003022 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05003023
Jamie Madillb6664922017-07-25 12:55:04 -04003024 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3025 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003026
3027 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003028 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003029}
3030
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003031void Context::copyTexImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003032 GLint level,
3033 GLenum internalformat,
3034 GLint x,
3035 GLint y,
3036 GLsizei width,
3037 GLsizei height,
3038 GLint border)
3039{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003040 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003041 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003042
Jamie Madillc29968b2016-01-20 11:17:23 -05003043 Rectangle sourceArea(x, y, width, height);
3044
Jamie Madill05b35b22017-10-03 09:01:44 -04003045 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003046 Texture *texture = getTargetTexture(TextureTargetToType(target));
3047 handleError(
3048 texture->copyImage(this, ToGLenum(target), level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003049}
3050
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003051void Context::copyTexSubImage2D(TextureTarget target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003052 GLint level,
3053 GLint xoffset,
3054 GLint yoffset,
3055 GLint x,
3056 GLint y,
3057 GLsizei width,
3058 GLsizei height)
3059{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003060 if (width == 0 || height == 0)
3061 {
3062 return;
3063 }
3064
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003065 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003066 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003067
Jamie Madillc29968b2016-01-20 11:17:23 -05003068 Offset destOffset(xoffset, yoffset, 0);
3069 Rectangle sourceArea(x, y, width, height);
3070
Jamie Madill05b35b22017-10-03 09:01:44 -04003071 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003072 Texture *texture = getTargetTexture(TextureTargetToType(target));
3073 handleError(
3074 texture->copySubImage(this, ToGLenum(target), level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003075}
3076
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003077void Context::copyTexSubImage3D(TextureType target,
Jamie Madillc29968b2016-01-20 11:17:23 -05003078 GLint level,
3079 GLint xoffset,
3080 GLint yoffset,
3081 GLint zoffset,
3082 GLint x,
3083 GLint y,
3084 GLsizei width,
3085 GLsizei height)
3086{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003087 if (width == 0 || height == 0)
3088 {
3089 return;
3090 }
3091
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003092 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003093 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003094
Jamie Madillc29968b2016-01-20 11:17:23 -05003095 Offset destOffset(xoffset, yoffset, zoffset);
3096 Rectangle sourceArea(x, y, width, height);
3097
Jamie Madill05b35b22017-10-03 09:01:44 -04003098 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3099 Texture *texture = getTargetTexture(target);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003100 handleError(
3101 texture->copySubImage(this, ToGLenum(target), level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003102}
3103
3104void Context::framebufferTexture2D(GLenum target,
3105 GLenum attachment,
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003106 TextureTarget textarget,
Jamie Madillc29968b2016-01-20 11:17:23 -05003107 GLuint texture,
3108 GLint level)
3109{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003110 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003111 ASSERT(framebuffer);
3112
3113 if (texture != 0)
3114 {
3115 Texture *textureObj = getTexture(texture);
3116
3117 ImageIndex index = ImageIndex::MakeInvalid();
3118
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003119 if (textarget == TextureTarget::_2D)
Jamie Madillc29968b2016-01-20 11:17:23 -05003120 {
3121 index = ImageIndex::Make2D(level);
3122 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003123 else if (textarget == TextureTarget::Rectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003124 {
3125 index = ImageIndex::MakeRectangle(level);
3126 }
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003127 else if (textarget == TextureTarget::_2DMultisample)
JiangYizhoubddc46b2016-12-09 09:50:51 +08003128 {
3129 ASSERT(level == 0);
3130 index = ImageIndex::Make2DMultisample();
3131 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003132 else
3133 {
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003134 ASSERT(TextureTargetToType(textarget) == TextureType::CubeMap);
3135 index = ImageIndex::MakeCube(ToGLenum(textarget), level);
Jamie Madillc29968b2016-01-20 11:17:23 -05003136 }
3137
Jamie Madilla02315b2017-02-23 14:14:47 -05003138 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003139 }
3140 else
3141 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003142 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003143 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003144
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003145 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003146}
3147
3148void Context::framebufferRenderbuffer(GLenum target,
3149 GLenum attachment,
3150 GLenum renderbuffertarget,
3151 GLuint renderbuffer)
3152{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003153 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003154 ASSERT(framebuffer);
3155
3156 if (renderbuffer != 0)
3157 {
3158 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003159
3160 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003161 renderbufferObject);
3162 }
3163 else
3164 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003165 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003166 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003167
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003168 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003169}
3170
3171void Context::framebufferTextureLayer(GLenum target,
3172 GLenum attachment,
3173 GLuint texture,
3174 GLint level,
3175 GLint layer)
3176{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003177 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003178 ASSERT(framebuffer);
3179
3180 if (texture != 0)
3181 {
3182 Texture *textureObject = getTexture(texture);
3183
3184 ImageIndex index = ImageIndex::MakeInvalid();
3185
3186 if (textureObject->getTarget() == GL_TEXTURE_3D)
3187 {
3188 index = ImageIndex::Make3D(level, layer);
3189 }
3190 else
3191 {
3192 ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY);
3193 index = ImageIndex::Make2DArray(level, layer);
3194 }
3195
Jamie Madilla02315b2017-02-23 14:14:47 -05003196 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003197 }
3198 else
3199 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003200 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003201 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003202
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003203 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003204}
3205
Martin Radev137032d2017-07-13 10:11:12 +03003206void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3207 GLenum attachment,
3208 GLuint texture,
3209 GLint level,
3210 GLint baseViewIndex,
3211 GLsizei numViews)
3212{
Martin Radev82ef7742017-08-08 17:44:58 +03003213 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3214 ASSERT(framebuffer);
3215
3216 if (texture != 0)
3217 {
3218 Texture *textureObj = getTexture(texture);
3219
Martin Radev18b75ba2017-08-15 15:50:40 +03003220 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003221 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3222 numViews, baseViewIndex);
3223 }
3224 else
3225 {
3226 framebuffer->resetAttachment(this, attachment);
3227 }
3228
3229 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003230}
3231
3232void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3233 GLenum attachment,
3234 GLuint texture,
3235 GLint level,
3236 GLsizei numViews,
3237 const GLint *viewportOffsets)
3238{
Martin Radev5dae57b2017-07-14 16:15:55 +03003239 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3240 ASSERT(framebuffer);
3241
3242 if (texture != 0)
3243 {
3244 Texture *textureObj = getTexture(texture);
3245
3246 ImageIndex index = ImageIndex::Make2D(level);
3247 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3248 textureObj, numViews, viewportOffsets);
3249 }
3250 else
3251 {
3252 framebuffer->resetAttachment(this, attachment);
3253 }
3254
3255 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003256}
3257
Jamie Madillc29968b2016-01-20 11:17:23 -05003258void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3259{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003260 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003261 ASSERT(framebuffer);
3262 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003263 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003264}
3265
3266void Context::readBuffer(GLenum mode)
3267{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003268 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003269 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003270 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003271}
3272
3273void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3274{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003275 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003276 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003277
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003278 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003279 ASSERT(framebuffer);
3280
3281 // The specification isn't clear what should be done when the framebuffer isn't complete.
3282 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003283 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003284}
3285
3286void Context::invalidateFramebuffer(GLenum target,
3287 GLsizei numAttachments,
3288 const GLenum *attachments)
3289{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003290 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003291 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003292
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003293 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003294 ASSERT(framebuffer);
3295
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003296 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003297 {
Jamie Madill437fa652016-05-03 15:13:24 -04003298 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003299 }
Jamie Madill437fa652016-05-03 15:13:24 -04003300
Jamie Madill4928b7c2017-06-20 12:57:39 -04003301 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003302}
3303
3304void Context::invalidateSubFramebuffer(GLenum target,
3305 GLsizei numAttachments,
3306 const GLenum *attachments,
3307 GLint x,
3308 GLint y,
3309 GLsizei width,
3310 GLsizei height)
3311{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003312 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003313 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003314
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003315 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003316 ASSERT(framebuffer);
3317
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003318 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003319 {
Jamie Madill437fa652016-05-03 15:13:24 -04003320 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003321 }
Jamie Madill437fa652016-05-03 15:13:24 -04003322
3323 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003324 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003325}
3326
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003327void Context::texImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003328 GLint level,
3329 GLint internalformat,
3330 GLsizei width,
3331 GLsizei height,
3332 GLint border,
3333 GLenum format,
3334 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003335 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003336{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003337 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003338
3339 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003340 Texture *texture = getTargetTexture(TextureTargetToType(target));
3341 handleError(texture->setImage(this, mGLState.getUnpackState(), ToGLenum(target), level,
3342 internalformat, size, format, type,
3343 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003344}
3345
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003346void Context::texImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003347 GLint level,
3348 GLint internalformat,
3349 GLsizei width,
3350 GLsizei height,
3351 GLsizei depth,
3352 GLint border,
3353 GLenum format,
3354 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003355 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003356{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003357 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003358
3359 Extents size(width, height, depth);
3360 Texture *texture = getTargetTexture(target);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003361 handleError(texture->setImage(this, mGLState.getUnpackState(), ToGLenum(target), level,
3362 internalformat, size, format, type,
3363 reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003364}
3365
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003366void Context::texSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003367 GLint level,
3368 GLint xoffset,
3369 GLint yoffset,
3370 GLsizei width,
3371 GLsizei height,
3372 GLenum format,
3373 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003374 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003375{
3376 // Zero sized uploads are valid but no-ops
3377 if (width == 0 || height == 0)
3378 {
3379 return;
3380 }
3381
Jamie Madillad9f24e2016-02-12 09:27:24 -05003382 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003383
3384 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003385 Texture *texture = getTargetTexture(TextureTargetToType(target));
3386 handleError(texture->setSubImage(this, mGLState.getUnpackState(), ToGLenum(target), level, area,
3387 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003388}
3389
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003390void Context::texSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003391 GLint level,
3392 GLint xoffset,
3393 GLint yoffset,
3394 GLint zoffset,
3395 GLsizei width,
3396 GLsizei height,
3397 GLsizei depth,
3398 GLenum format,
3399 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003400 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003401{
3402 // Zero sized uploads are valid but no-ops
3403 if (width == 0 || height == 0 || depth == 0)
3404 {
3405 return;
3406 }
3407
Jamie Madillad9f24e2016-02-12 09:27:24 -05003408 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003409
3410 Box area(xoffset, yoffset, zoffset, width, height, depth);
3411 Texture *texture = getTargetTexture(target);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003412 handleError(texture->setSubImage(this, mGLState.getUnpackState(), ToGLenum(target), level, area,
3413 format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003414}
3415
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003416void Context::compressedTexImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003417 GLint level,
3418 GLenum internalformat,
3419 GLsizei width,
3420 GLsizei height,
3421 GLint border,
3422 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003423 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003424{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003425 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003426
3427 Extents size(width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003428 Texture *texture = getTargetTexture(TextureTargetToType(target));
3429 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), ToGLenum(target),
3430 level, internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003431 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003432}
3433
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003434void Context::compressedTexImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003435 GLint level,
3436 GLenum internalformat,
3437 GLsizei width,
3438 GLsizei height,
3439 GLsizei depth,
3440 GLint border,
3441 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003442 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003443{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003444 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003445
3446 Extents size(width, height, depth);
3447 Texture *texture = getTargetTexture(target);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003448 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), ToGLenum(target),
3449 level, internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003450 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003451}
3452
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003453void Context::compressedTexSubImage2D(TextureTarget target,
Jamie Madill73a84962016-02-12 09:27:23 -05003454 GLint level,
3455 GLint xoffset,
3456 GLint yoffset,
3457 GLsizei width,
3458 GLsizei height,
3459 GLenum format,
3460 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003461 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003462{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003463 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003464
3465 Box area(xoffset, yoffset, 0, width, height, 1);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003466 Texture *texture = getTargetTexture(TextureTargetToType(target));
3467 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), ToGLenum(target),
3468 level, area, format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003469 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003470}
3471
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003472void Context::compressedTexSubImage3D(TextureType target,
Jamie Madill73a84962016-02-12 09:27:23 -05003473 GLint level,
3474 GLint xoffset,
3475 GLint yoffset,
3476 GLint zoffset,
3477 GLsizei width,
3478 GLsizei height,
3479 GLsizei depth,
3480 GLenum format,
3481 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003482 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003483{
3484 // Zero sized uploads are valid but no-ops
3485 if (width == 0 || height == 0)
3486 {
3487 return;
3488 }
3489
Jamie Madillad9f24e2016-02-12 09:27:24 -05003490 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003491
3492 Box area(xoffset, yoffset, zoffset, width, height, depth);
3493 Texture *texture = getTargetTexture(target);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003494 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), ToGLenum(target),
3495 level, area, format, imageSize,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003496 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003497}
3498
Corentin Wallezf0e89be2017-11-08 14:00:32 -08003499void Context::generateMipmap(TextureType target)
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003500{
3501 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003502 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003503}
3504
Jamie Madill007530e2017-12-28 14:27:04 -05003505void Context::copyTexture(GLuint sourceId,
3506 GLint sourceLevel,
3507 GLenum destTarget,
3508 GLuint destId,
3509 GLint destLevel,
3510 GLint internalFormat,
3511 GLenum destType,
3512 GLboolean unpackFlipY,
3513 GLboolean unpackPremultiplyAlpha,
3514 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003515{
3516 syncStateForTexImage();
3517
3518 gl::Texture *sourceTexture = getTexture(sourceId);
3519 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05003520 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
3521 sourceLevel, ConvertToBool(unpackFlipY),
3522 ConvertToBool(unpackPremultiplyAlpha),
3523 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003524}
3525
Jamie Madill007530e2017-12-28 14:27:04 -05003526void Context::copySubTexture(GLuint sourceId,
3527 GLint sourceLevel,
3528 GLenum destTarget,
3529 GLuint destId,
3530 GLint destLevel,
3531 GLint xoffset,
3532 GLint yoffset,
3533 GLint x,
3534 GLint y,
3535 GLsizei width,
3536 GLsizei height,
3537 GLboolean unpackFlipY,
3538 GLboolean unpackPremultiplyAlpha,
3539 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003540{
3541 // Zero sized copies are valid but no-ops
3542 if (width == 0 || height == 0)
3543 {
3544 return;
3545 }
3546
3547 syncStateForTexImage();
3548
3549 gl::Texture *sourceTexture = getTexture(sourceId);
3550 gl::Texture *destTexture = getTexture(destId);
3551 Offset offset(xoffset, yoffset, 0);
3552 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05003553 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
3554 ConvertToBool(unpackFlipY),
3555 ConvertToBool(unpackPremultiplyAlpha),
3556 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003557}
3558
Jamie Madill007530e2017-12-28 14:27:04 -05003559void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07003560{
3561 syncStateForTexImage();
3562
3563 gl::Texture *sourceTexture = getTexture(sourceId);
3564 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003565 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003566}
3567
Corentin Wallez336129f2017-10-17 15:55:40 -04003568void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003569{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003570 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003571 ASSERT(buffer);
3572
Geoff Lang496c02d2016-10-20 11:38:11 -07003573 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003574}
3575
Corentin Wallez336129f2017-10-17 15:55:40 -04003576void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003577{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003578 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003579 ASSERT(buffer);
3580
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003581 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003582 if (error.isError())
3583 {
Jamie Madill437fa652016-05-03 15:13:24 -04003584 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003585 return nullptr;
3586 }
3587
3588 return buffer->getMapPointer();
3589}
3590
Corentin Wallez336129f2017-10-17 15:55:40 -04003591GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003592{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003593 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003594 ASSERT(buffer);
3595
3596 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003597 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003598 if (error.isError())
3599 {
Jamie Madill437fa652016-05-03 15:13:24 -04003600 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003601 return GL_FALSE;
3602 }
3603
3604 return result;
3605}
3606
Corentin Wallez336129f2017-10-17 15:55:40 -04003607void *Context::mapBufferRange(BufferBinding target,
3608 GLintptr offset,
3609 GLsizeiptr length,
3610 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003611{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003612 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003613 ASSERT(buffer);
3614
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003615 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003616 if (error.isError())
3617 {
Jamie Madill437fa652016-05-03 15:13:24 -04003618 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003619 return nullptr;
3620 }
3621
3622 return buffer->getMapPointer();
3623}
3624
Corentin Wallez336129f2017-10-17 15:55:40 -04003625void Context::flushMappedBufferRange(BufferBinding /*target*/,
3626 GLintptr /*offset*/,
3627 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03003628{
3629 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3630}
3631
Jamie Madillad9f24e2016-02-12 09:27:24 -05003632void Context::syncStateForReadPixels()
3633{
3634 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3635}
3636
3637void Context::syncStateForTexImage()
3638{
3639 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3640}
3641
3642void Context::syncStateForClear()
3643{
3644 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3645}
3646
3647void Context::syncStateForBlit()
3648{
3649 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3650}
3651
Jiajia Qin5451d532017-11-16 17:16:34 +08003652void Context::activeShaderProgram(GLuint pipeline, GLuint program)
3653{
3654 UNIMPLEMENTED();
3655}
3656
Jamie Madillc20ab272016-06-09 07:20:46 -07003657void Context::activeTexture(GLenum texture)
3658{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003659 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003660}
3661
Jamie Madill876429b2017-04-20 15:46:24 -04003662void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003663{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003664 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003665}
3666
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003667void Context::blendEquation(GLenum mode)
3668{
3669 mGLState.setBlendEquation(mode, mode);
3670}
3671
Jamie Madillc20ab272016-06-09 07:20:46 -07003672void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3673{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003674 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003675}
3676
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003677void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3678{
3679 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3680}
3681
Jamie Madillc20ab272016-06-09 07:20:46 -07003682void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3683{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003684 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003685}
3686
Jamie Madill876429b2017-04-20 15:46:24 -04003687void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003688{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003689 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003690}
3691
Jamie Madill876429b2017-04-20 15:46:24 -04003692void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003693{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003694 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003695}
3696
3697void Context::clearStencil(GLint s)
3698{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003699 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003700}
3701
3702void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3703{
Geoff Lang92019432017-11-20 13:09:34 -05003704 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
3705 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003706}
3707
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003708void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003709{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003710 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003711}
3712
3713void Context::depthFunc(GLenum func)
3714{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003715 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003716}
3717
3718void Context::depthMask(GLboolean flag)
3719{
Geoff Lang92019432017-11-20 13:09:34 -05003720 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07003721}
3722
Jamie Madill876429b2017-04-20 15:46:24 -04003723void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003724{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003725 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003726}
3727
3728void Context::disable(GLenum cap)
3729{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003730 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003731}
3732
3733void Context::disableVertexAttribArray(GLuint index)
3734{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003735 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003736}
3737
3738void Context::enable(GLenum cap)
3739{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003740 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003741}
3742
3743void Context::enableVertexAttribArray(GLuint index)
3744{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003745 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003746}
3747
3748void Context::frontFace(GLenum mode)
3749{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003750 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003751}
3752
3753void Context::hint(GLenum target, GLenum mode)
3754{
3755 switch (target)
3756 {
3757 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003758 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003759 break;
3760
3761 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003762 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003763 break;
3764
3765 default:
3766 UNREACHABLE();
3767 return;
3768 }
3769}
3770
3771void Context::lineWidth(GLfloat width)
3772{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003773 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003774}
3775
3776void Context::pixelStorei(GLenum pname, GLint param)
3777{
3778 switch (pname)
3779 {
3780 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003781 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003782 break;
3783
3784 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003785 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003786 break;
3787
3788 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003789 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003790 break;
3791
3792 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003793 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003794 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003795 break;
3796
3797 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003798 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003799 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003800 break;
3801
3802 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003803 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003804 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003805 break;
3806
3807 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003808 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003809 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003810 break;
3811
3812 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003813 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003814 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003815 break;
3816
3817 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003818 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003819 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003820 break;
3821
3822 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003823 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003824 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003825 break;
3826
3827 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003828 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003829 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003830 break;
3831
3832 default:
3833 UNREACHABLE();
3834 return;
3835 }
3836}
3837
3838void Context::polygonOffset(GLfloat factor, GLfloat units)
3839{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003840 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003841}
3842
Jamie Madill876429b2017-04-20 15:46:24 -04003843void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003844{
Geoff Lang92019432017-11-20 13:09:34 -05003845 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07003846}
3847
Jiawei Shaodb342272017-09-27 10:21:45 +08003848void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3849{
3850 mGLState.setSampleMaskParams(maskNumber, mask);
3851}
3852
Jamie Madillc20ab272016-06-09 07:20:46 -07003853void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3854{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003855 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003856}
3857
3858void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3859{
3860 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3861 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003862 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003863 }
3864
3865 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3866 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003867 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003868 }
3869}
3870
3871void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3872{
3873 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3874 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003875 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003876 }
3877
3878 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3879 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003880 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003881 }
3882}
3883
3884void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3885{
3886 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3887 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003888 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003889 }
3890
3891 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3892 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003893 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003894 }
3895}
3896
3897void Context::vertexAttrib1f(GLuint index, GLfloat x)
3898{
3899 GLfloat vals[4] = {x, 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::vertexAttrib1fv(GLuint index, const GLfloat *values)
3904{
3905 GLfloat vals[4] = {values[0], 0, 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::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3910{
3911 GLfloat vals[4] = {x, y, 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::vertexAttrib2fv(GLuint index, const GLfloat *values)
3916{
3917 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003918 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003919}
3920
3921void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3922{
3923 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003924 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003925}
3926
3927void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3928{
3929 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003930 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003931}
3932
3933void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3934{
3935 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003936 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003937}
3938
3939void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3940{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003941 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003942}
3943
3944void Context::vertexAttribPointer(GLuint index,
3945 GLint size,
3946 GLenum type,
3947 GLboolean normalized,
3948 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003949 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003950{
Corentin Wallez336129f2017-10-17 15:55:40 -04003951 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05003952 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003953}
3954
Shao80957d92017-02-20 21:25:59 +08003955void Context::vertexAttribFormat(GLuint attribIndex,
3956 GLint size,
3957 GLenum type,
3958 GLboolean normalized,
3959 GLuint relativeOffset)
3960{
Geoff Lang92019432017-11-20 13:09:34 -05003961 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08003962 relativeOffset);
3963}
3964
3965void Context::vertexAttribIFormat(GLuint attribIndex,
3966 GLint size,
3967 GLenum type,
3968 GLuint relativeOffset)
3969{
3970 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3971}
3972
3973void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3974{
Shaodde78e82017-05-22 14:13:27 +08003975 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08003976}
3977
Jiajia Qin5451d532017-11-16 17:16:34 +08003978void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08003979{
3980 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3981}
3982
Jamie Madillc20ab272016-06-09 07:20:46 -07003983void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3984{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003985 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003986}
3987
3988void Context::vertexAttribIPointer(GLuint index,
3989 GLint size,
3990 GLenum type,
3991 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003992 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003993{
Corentin Wallez336129f2017-10-17 15:55:40 -04003994 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
3995 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003996}
3997
3998void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3999{
4000 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004001 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004002}
4003
4004void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
4005{
4006 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004007 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07004008}
4009
4010void Context::vertexAttribI4iv(GLuint index, const GLint *v)
4011{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004012 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004013}
4014
4015void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
4016{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004017 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004018}
4019
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004020void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4021{
4022 const VertexAttribCurrentValueData &currentValues =
4023 getGLState().getVertexAttribCurrentValue(index);
4024 const VertexArray *vao = getGLState().getVertexArray();
4025 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4026 currentValues, pname, params);
4027}
4028
4029void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4030{
4031 const VertexAttribCurrentValueData &currentValues =
4032 getGLState().getVertexAttribCurrentValue(index);
4033 const VertexArray *vao = getGLState().getVertexArray();
4034 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4035 currentValues, pname, params);
4036}
4037
4038void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4039{
4040 const VertexAttribCurrentValueData &currentValues =
4041 getGLState().getVertexAttribCurrentValue(index);
4042 const VertexArray *vao = getGLState().getVertexArray();
4043 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4044 currentValues, pname, params);
4045}
4046
4047void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4048{
4049 const VertexAttribCurrentValueData &currentValues =
4050 getGLState().getVertexAttribCurrentValue(index);
4051 const VertexArray *vao = getGLState().getVertexArray();
4052 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4053 currentValues, pname, params);
4054}
4055
Jamie Madill876429b2017-04-20 15:46:24 -04004056void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004057{
4058 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4059 QueryVertexAttribPointerv(attrib, pname, pointer);
4060}
4061
Jamie Madillc20ab272016-06-09 07:20:46 -07004062void Context::debugMessageControl(GLenum source,
4063 GLenum type,
4064 GLenum severity,
4065 GLsizei count,
4066 const GLuint *ids,
4067 GLboolean enabled)
4068{
4069 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004070 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004071 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004072}
4073
4074void Context::debugMessageInsert(GLenum source,
4075 GLenum type,
4076 GLuint id,
4077 GLenum severity,
4078 GLsizei length,
4079 const GLchar *buf)
4080{
4081 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004082 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004083}
4084
4085void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4086{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004087 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004088}
4089
4090GLuint Context::getDebugMessageLog(GLuint count,
4091 GLsizei bufSize,
4092 GLenum *sources,
4093 GLenum *types,
4094 GLuint *ids,
4095 GLenum *severities,
4096 GLsizei *lengths,
4097 GLchar *messageLog)
4098{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004099 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4100 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004101}
4102
4103void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4104{
4105 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004106 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004107 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004108}
4109
4110void Context::popDebugGroup()
4111{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004112 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004113 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004114}
4115
Corentin Wallez336129f2017-10-17 15:55:40 -04004116void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004117{
4118 Buffer *buffer = mGLState.getTargetBuffer(target);
4119 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004120 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004121}
4122
Corentin Wallez336129f2017-10-17 15:55:40 -04004123void Context::bufferSubData(BufferBinding target,
4124 GLintptr offset,
4125 GLsizeiptr size,
4126 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004127{
4128 if (data == nullptr)
4129 {
4130 return;
4131 }
4132
4133 Buffer *buffer = mGLState.getTargetBuffer(target);
4134 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004135 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004136}
4137
Jamie Madillef300b12016-10-07 15:12:09 -04004138void Context::attachShader(GLuint program, GLuint shader)
4139{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004140 Program *programObject = mState.mShaderPrograms->getProgram(program);
4141 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004142 ASSERT(programObject && shaderObject);
4143 programObject->attachShader(shaderObject);
4144}
4145
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004146const Workarounds &Context::getWorkarounds() const
4147{
4148 return mWorkarounds;
4149}
4150
Corentin Wallez336129f2017-10-17 15:55:40 -04004151void Context::copyBufferSubData(BufferBinding readTarget,
4152 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004153 GLintptr readOffset,
4154 GLintptr writeOffset,
4155 GLsizeiptr size)
4156{
4157 // if size is zero, the copy is a successful no-op
4158 if (size == 0)
4159 {
4160 return;
4161 }
4162
4163 // TODO(jmadill): cache these.
4164 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4165 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4166
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004167 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004168}
4169
Jamie Madill01a80ee2016-11-07 12:06:18 -05004170void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4171{
4172 Program *programObject = getProgram(program);
4173 // TODO(jmadill): Re-use this from the validation if possible.
4174 ASSERT(programObject);
4175 programObject->bindAttributeLocation(index, name);
4176}
4177
Corentin Wallez336129f2017-10-17 15:55:40 -04004178void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004179{
Corentin Wallez336129f2017-10-17 15:55:40 -04004180 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4181 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004182}
4183
Corentin Wallez336129f2017-10-17 15:55:40 -04004184void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004185{
4186 bindBufferRange(target, index, buffer, 0, 0);
4187}
4188
Corentin Wallez336129f2017-10-17 15:55:40 -04004189void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004190 GLuint index,
4191 GLuint buffer,
4192 GLintptr offset,
4193 GLsizeiptr size)
4194{
Corentin Wallez336129f2017-10-17 15:55:40 -04004195 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4196 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004197}
4198
Jamie Madill01a80ee2016-11-07 12:06:18 -05004199void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4200{
4201 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4202 {
4203 bindReadFramebuffer(framebuffer);
4204 }
4205
4206 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4207 {
4208 bindDrawFramebuffer(framebuffer);
4209 }
4210}
4211
4212void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4213{
4214 ASSERT(target == GL_RENDERBUFFER);
4215 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004216 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004217 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004218}
4219
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004220void Context::texStorage2DMultisample(TextureType target,
JiangYizhoubddc46b2016-12-09 09:50:51 +08004221 GLsizei samples,
4222 GLenum internalformat,
4223 GLsizei width,
4224 GLsizei height,
4225 GLboolean fixedsamplelocations)
4226{
4227 Extents size(width, height, 1);
4228 Texture *texture = getTargetTexture(target);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004229 handleError(texture->setStorageMultisample(this, ToGLenum(target), samples, internalformat,
4230 size, ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004231}
4232
4233void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4234{
JiangYizhou5b03f472017-01-09 10:22:53 +08004235 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4236 // the sample position should be queried by DRAW_FRAMEBUFFER.
4237 mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER);
4238 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004239
4240 switch (pname)
4241 {
4242 case GL_SAMPLE_POSITION:
4243 handleError(framebuffer->getSamplePosition(index, val));
4244 break;
4245 default:
4246 UNREACHABLE();
4247 }
4248}
4249
Jamie Madille8fb6402017-02-14 17:56:40 -05004250void Context::renderbufferStorage(GLenum target,
4251 GLenum internalformat,
4252 GLsizei width,
4253 GLsizei height)
4254{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004255 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4256 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4257
Jamie Madille8fb6402017-02-14 17:56:40 -05004258 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004259 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004260}
4261
4262void Context::renderbufferStorageMultisample(GLenum target,
4263 GLsizei samples,
4264 GLenum internalformat,
4265 GLsizei width,
4266 GLsizei height)
4267{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004268 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4269 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004270
4271 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004272 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004273 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004274}
4275
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004276void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4277{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004278 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004279 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004280}
4281
JiangYizhoue18e6392017-02-20 10:32:23 +08004282void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4283{
4284 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4285 QueryFramebufferParameteriv(framebuffer, pname, params);
4286}
4287
Jiajia Qin5451d532017-11-16 17:16:34 +08004288void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004289{
4290 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4291 SetFramebufferParameteri(framebuffer, pname, param);
4292}
4293
Jamie Madillb3f26b92017-07-19 15:07:41 -04004294Error Context::getScratchBuffer(size_t requstedSizeBytes,
4295 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004296{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004297 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4298 {
4299 return OutOfMemory() << "Failed to allocate internal buffer.";
4300 }
4301 return NoError();
4302}
4303
4304Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4305 angle::MemoryBuffer **zeroBufferOut) const
4306{
4307 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004308 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004309 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004310 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004311 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004312}
4313
Xinghua Cao10a4d432017-11-28 14:46:26 +08004314Error Context::prepareForDispatch()
4315{
4316 syncRendererState(mComputeDirtyBits, mComputeDirtyObjects);
4317
4318 if (isRobustResourceInitEnabled())
4319 {
4320 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4321 }
4322
4323 return NoError();
4324}
4325
Xinghua Cao2b396592017-03-29 15:36:04 +08004326void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4327{
4328 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4329 {
4330 return;
4331 }
4332
Xinghua Cao10a4d432017-11-28 14:46:26 +08004333 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004334 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004335}
4336
Jiajia Qin5451d532017-11-16 17:16:34 +08004337void Context::dispatchComputeIndirect(GLintptr indirect)
4338{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004339 ANGLE_CONTEXT_TRY(prepareForDispatch());
4340 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004341}
4342
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004343void Context::texStorage2D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004344 GLsizei levels,
4345 GLenum internalFormat,
4346 GLsizei width,
4347 GLsizei height)
4348{
4349 Extents size(width, height, 1);
4350 Texture *texture = getTargetTexture(target);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004351 handleError(texture->setStorage(this, ToGLenum(target), levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004352}
4353
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004354void Context::texStorage3D(TextureType target,
JiangYizhou165361c2017-06-07 14:56:57 +08004355 GLsizei levels,
4356 GLenum internalFormat,
4357 GLsizei width,
4358 GLsizei height,
4359 GLsizei depth)
4360{
4361 Extents size(width, height, depth);
4362 Texture *texture = getTargetTexture(target);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08004363 handleError(texture->setStorage(this, ToGLenum(target), levels, internalFormat, size));
JiangYizhou165361c2017-06-07 14:56:57 +08004364}
4365
Jiajia Qin5451d532017-11-16 17:16:34 +08004366void Context::memoryBarrier(GLbitfield barriers)
4367{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004368 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004369}
4370
4371void Context::memoryBarrierByRegion(GLbitfield barriers)
4372{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004373 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004374}
4375
Jamie Madillc1d770e2017-04-13 17:31:24 -04004376GLenum Context::checkFramebufferStatus(GLenum target)
4377{
4378 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4379 ASSERT(framebuffer);
4380
4381 return framebuffer->checkStatus(this);
4382}
4383
4384void Context::compileShader(GLuint shader)
4385{
4386 Shader *shaderObject = GetValidShader(this, shader);
4387 if (!shaderObject)
4388 {
4389 return;
4390 }
4391 shaderObject->compile(this);
4392}
4393
4394void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4395{
4396 for (int i = 0; i < n; i++)
4397 {
4398 deleteBuffer(buffers[i]);
4399 }
4400}
4401
4402void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4403{
4404 for (int i = 0; i < n; i++)
4405 {
4406 if (framebuffers[i] != 0)
4407 {
4408 deleteFramebuffer(framebuffers[i]);
4409 }
4410 }
4411}
4412
4413void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4414{
4415 for (int i = 0; i < n; i++)
4416 {
4417 deleteRenderbuffer(renderbuffers[i]);
4418 }
4419}
4420
4421void Context::deleteTextures(GLsizei n, const GLuint *textures)
4422{
4423 for (int i = 0; i < n; i++)
4424 {
4425 if (textures[i] != 0)
4426 {
4427 deleteTexture(textures[i]);
4428 }
4429 }
4430}
4431
4432void Context::detachShader(GLuint program, GLuint shader)
4433{
4434 Program *programObject = getProgram(program);
4435 ASSERT(programObject);
4436
4437 Shader *shaderObject = getShader(shader);
4438 ASSERT(shaderObject);
4439
4440 programObject->detachShader(this, shaderObject);
4441}
4442
4443void Context::genBuffers(GLsizei n, GLuint *buffers)
4444{
4445 for (int i = 0; i < n; i++)
4446 {
4447 buffers[i] = createBuffer();
4448 }
4449}
4450
4451void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4452{
4453 for (int i = 0; i < n; i++)
4454 {
4455 framebuffers[i] = createFramebuffer();
4456 }
4457}
4458
4459void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4460{
4461 for (int i = 0; i < n; i++)
4462 {
4463 renderbuffers[i] = createRenderbuffer();
4464 }
4465}
4466
4467void Context::genTextures(GLsizei n, GLuint *textures)
4468{
4469 for (int i = 0; i < n; i++)
4470 {
4471 textures[i] = createTexture();
4472 }
4473}
4474
4475void Context::getActiveAttrib(GLuint program,
4476 GLuint index,
4477 GLsizei bufsize,
4478 GLsizei *length,
4479 GLint *size,
4480 GLenum *type,
4481 GLchar *name)
4482{
4483 Program *programObject = getProgram(program);
4484 ASSERT(programObject);
4485 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4486}
4487
4488void Context::getActiveUniform(GLuint program,
4489 GLuint index,
4490 GLsizei bufsize,
4491 GLsizei *length,
4492 GLint *size,
4493 GLenum *type,
4494 GLchar *name)
4495{
4496 Program *programObject = getProgram(program);
4497 ASSERT(programObject);
4498 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4499}
4500
4501void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4502{
4503 Program *programObject = getProgram(program);
4504 ASSERT(programObject);
4505 programObject->getAttachedShaders(maxcount, count, shaders);
4506}
4507
4508GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4509{
4510 Program *programObject = getProgram(program);
4511 ASSERT(programObject);
4512 return programObject->getAttributeLocation(name);
4513}
4514
4515void Context::getBooleanv(GLenum pname, GLboolean *params)
4516{
4517 GLenum nativeType;
4518 unsigned int numParams = 0;
4519 getQueryParameterInfo(pname, &nativeType, &numParams);
4520
4521 if (nativeType == GL_BOOL)
4522 {
4523 getBooleanvImpl(pname, params);
4524 }
4525 else
4526 {
4527 CastStateValues(this, nativeType, pname, numParams, params);
4528 }
4529}
4530
4531void Context::getFloatv(GLenum pname, GLfloat *params)
4532{
4533 GLenum nativeType;
4534 unsigned int numParams = 0;
4535 getQueryParameterInfo(pname, &nativeType, &numParams);
4536
4537 if (nativeType == GL_FLOAT)
4538 {
4539 getFloatvImpl(pname, params);
4540 }
4541 else
4542 {
4543 CastStateValues(this, nativeType, pname, numParams, params);
4544 }
4545}
4546
4547void Context::getIntegerv(GLenum pname, GLint *params)
4548{
4549 GLenum nativeType;
4550 unsigned int numParams = 0;
4551 getQueryParameterInfo(pname, &nativeType, &numParams);
4552
4553 if (nativeType == GL_INT)
4554 {
4555 getIntegervImpl(pname, params);
4556 }
4557 else
4558 {
4559 CastStateValues(this, nativeType, pname, numParams, params);
4560 }
4561}
4562
4563void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4564{
4565 Program *programObject = getProgram(program);
4566 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004567 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004568}
4569
Jiajia Qin5451d532017-11-16 17:16:34 +08004570void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
4571{
4572 UNIMPLEMENTED();
4573}
4574
Jamie Madillbe849e42017-05-02 15:49:00 -04004575void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004576{
4577 Program *programObject = getProgram(program);
4578 ASSERT(programObject);
4579 programObject->getInfoLog(bufsize, length, infolog);
4580}
4581
Jiajia Qin5451d532017-11-16 17:16:34 +08004582void Context::getProgramPipelineInfoLog(GLuint pipeline,
4583 GLsizei bufSize,
4584 GLsizei *length,
4585 GLchar *infoLog)
4586{
4587 UNIMPLEMENTED();
4588}
4589
Jamie Madillc1d770e2017-04-13 17:31:24 -04004590void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4591{
4592 Shader *shaderObject = getShader(shader);
4593 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004594 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004595}
4596
4597void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4598{
4599 Shader *shaderObject = getShader(shader);
4600 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004601 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004602}
4603
4604void Context::getShaderPrecisionFormat(GLenum shadertype,
4605 GLenum precisiontype,
4606 GLint *range,
4607 GLint *precision)
4608{
4609 // TODO(jmadill): Compute shaders.
4610
4611 switch (shadertype)
4612 {
4613 case GL_VERTEX_SHADER:
4614 switch (precisiontype)
4615 {
4616 case GL_LOW_FLOAT:
4617 mCaps.vertexLowpFloat.get(range, precision);
4618 break;
4619 case GL_MEDIUM_FLOAT:
4620 mCaps.vertexMediumpFloat.get(range, precision);
4621 break;
4622 case GL_HIGH_FLOAT:
4623 mCaps.vertexHighpFloat.get(range, precision);
4624 break;
4625
4626 case GL_LOW_INT:
4627 mCaps.vertexLowpInt.get(range, precision);
4628 break;
4629 case GL_MEDIUM_INT:
4630 mCaps.vertexMediumpInt.get(range, precision);
4631 break;
4632 case GL_HIGH_INT:
4633 mCaps.vertexHighpInt.get(range, precision);
4634 break;
4635
4636 default:
4637 UNREACHABLE();
4638 return;
4639 }
4640 break;
4641
4642 case GL_FRAGMENT_SHADER:
4643 switch (precisiontype)
4644 {
4645 case GL_LOW_FLOAT:
4646 mCaps.fragmentLowpFloat.get(range, precision);
4647 break;
4648 case GL_MEDIUM_FLOAT:
4649 mCaps.fragmentMediumpFloat.get(range, precision);
4650 break;
4651 case GL_HIGH_FLOAT:
4652 mCaps.fragmentHighpFloat.get(range, precision);
4653 break;
4654
4655 case GL_LOW_INT:
4656 mCaps.fragmentLowpInt.get(range, precision);
4657 break;
4658 case GL_MEDIUM_INT:
4659 mCaps.fragmentMediumpInt.get(range, precision);
4660 break;
4661 case GL_HIGH_INT:
4662 mCaps.fragmentHighpInt.get(range, precision);
4663 break;
4664
4665 default:
4666 UNREACHABLE();
4667 return;
4668 }
4669 break;
4670
4671 default:
4672 UNREACHABLE();
4673 return;
4674 }
4675}
4676
4677void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4678{
4679 Shader *shaderObject = getShader(shader);
4680 ASSERT(shaderObject);
4681 shaderObject->getSource(bufsize, length, source);
4682}
4683
4684void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4685{
4686 Program *programObject = getProgram(program);
4687 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004688 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004689}
4690
4691void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4692{
4693 Program *programObject = getProgram(program);
4694 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004695 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004696}
4697
4698GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4699{
4700 Program *programObject = getProgram(program);
4701 ASSERT(programObject);
4702 return programObject->getUniformLocation(name);
4703}
4704
4705GLboolean Context::isBuffer(GLuint buffer)
4706{
4707 if (buffer == 0)
4708 {
4709 return GL_FALSE;
4710 }
4711
4712 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4713}
4714
4715GLboolean Context::isEnabled(GLenum cap)
4716{
4717 return mGLState.getEnableFeature(cap);
4718}
4719
4720GLboolean Context::isFramebuffer(GLuint framebuffer)
4721{
4722 if (framebuffer == 0)
4723 {
4724 return GL_FALSE;
4725 }
4726
4727 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4728}
4729
4730GLboolean Context::isProgram(GLuint program)
4731{
4732 if (program == 0)
4733 {
4734 return GL_FALSE;
4735 }
4736
4737 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4738}
4739
4740GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4741{
4742 if (renderbuffer == 0)
4743 {
4744 return GL_FALSE;
4745 }
4746
4747 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4748}
4749
4750GLboolean Context::isShader(GLuint shader)
4751{
4752 if (shader == 0)
4753 {
4754 return GL_FALSE;
4755 }
4756
4757 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4758}
4759
4760GLboolean Context::isTexture(GLuint texture)
4761{
4762 if (texture == 0)
4763 {
4764 return GL_FALSE;
4765 }
4766
4767 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4768}
4769
4770void Context::linkProgram(GLuint program)
4771{
4772 Program *programObject = getProgram(program);
4773 ASSERT(programObject);
4774 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004775 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004776}
4777
4778void Context::releaseShaderCompiler()
4779{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004780 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004781}
4782
4783void Context::shaderBinary(GLsizei n,
4784 const GLuint *shaders,
4785 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004786 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004787 GLsizei length)
4788{
4789 // No binary shader formats are supported.
4790 UNIMPLEMENTED();
4791}
4792
4793void Context::shaderSource(GLuint shader,
4794 GLsizei count,
4795 const GLchar *const *string,
4796 const GLint *length)
4797{
4798 Shader *shaderObject = getShader(shader);
4799 ASSERT(shaderObject);
4800 shaderObject->setSource(count, string, length);
4801}
4802
4803void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4804{
4805 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4806}
4807
4808void Context::stencilMask(GLuint mask)
4809{
4810 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4811}
4812
4813void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4814{
4815 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4816}
4817
4818void Context::uniform1f(GLint location, GLfloat x)
4819{
4820 Program *program = mGLState.getProgram();
4821 program->setUniform1fv(location, 1, &x);
4822}
4823
4824void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4825{
4826 Program *program = mGLState.getProgram();
4827 program->setUniform1fv(location, count, v);
4828}
4829
4830void Context::uniform1i(GLint location, GLint x)
4831{
4832 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004833 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4834 {
4835 mGLState.setObjectDirty(GL_PROGRAM);
4836 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004837}
4838
4839void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4840{
4841 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004842 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4843 {
4844 mGLState.setObjectDirty(GL_PROGRAM);
4845 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004846}
4847
4848void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4849{
4850 GLfloat xy[2] = {x, y};
4851 Program *program = mGLState.getProgram();
4852 program->setUniform2fv(location, 1, xy);
4853}
4854
4855void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4856{
4857 Program *program = mGLState.getProgram();
4858 program->setUniform2fv(location, count, v);
4859}
4860
4861void Context::uniform2i(GLint location, GLint x, GLint y)
4862{
4863 GLint xy[2] = {x, y};
4864 Program *program = mGLState.getProgram();
4865 program->setUniform2iv(location, 1, xy);
4866}
4867
4868void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4869{
4870 Program *program = mGLState.getProgram();
4871 program->setUniform2iv(location, count, v);
4872}
4873
4874void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4875{
4876 GLfloat xyz[3] = {x, y, z};
4877 Program *program = mGLState.getProgram();
4878 program->setUniform3fv(location, 1, xyz);
4879}
4880
4881void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4882{
4883 Program *program = mGLState.getProgram();
4884 program->setUniform3fv(location, count, v);
4885}
4886
4887void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4888{
4889 GLint xyz[3] = {x, y, z};
4890 Program *program = mGLState.getProgram();
4891 program->setUniform3iv(location, 1, xyz);
4892}
4893
4894void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4895{
4896 Program *program = mGLState.getProgram();
4897 program->setUniform3iv(location, count, v);
4898}
4899
4900void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4901{
4902 GLfloat xyzw[4] = {x, y, z, w};
4903 Program *program = mGLState.getProgram();
4904 program->setUniform4fv(location, 1, xyzw);
4905}
4906
4907void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4908{
4909 Program *program = mGLState.getProgram();
4910 program->setUniform4fv(location, count, v);
4911}
4912
4913void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4914{
4915 GLint xyzw[4] = {x, y, z, w};
4916 Program *program = mGLState.getProgram();
4917 program->setUniform4iv(location, 1, xyzw);
4918}
4919
4920void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4921{
4922 Program *program = mGLState.getProgram();
4923 program->setUniform4iv(location, count, v);
4924}
4925
4926void Context::uniformMatrix2fv(GLint location,
4927 GLsizei count,
4928 GLboolean transpose,
4929 const GLfloat *value)
4930{
4931 Program *program = mGLState.getProgram();
4932 program->setUniformMatrix2fv(location, count, transpose, value);
4933}
4934
4935void Context::uniformMatrix3fv(GLint location,
4936 GLsizei count,
4937 GLboolean transpose,
4938 const GLfloat *value)
4939{
4940 Program *program = mGLState.getProgram();
4941 program->setUniformMatrix3fv(location, count, transpose, value);
4942}
4943
4944void Context::uniformMatrix4fv(GLint location,
4945 GLsizei count,
4946 GLboolean transpose,
4947 const GLfloat *value)
4948{
4949 Program *program = mGLState.getProgram();
4950 program->setUniformMatrix4fv(location, count, transpose, value);
4951}
4952
4953void Context::validateProgram(GLuint program)
4954{
4955 Program *programObject = getProgram(program);
4956 ASSERT(programObject);
4957 programObject->validate(mCaps);
4958}
4959
Jiajia Qin5451d532017-11-16 17:16:34 +08004960void Context::validateProgramPipeline(GLuint pipeline)
4961{
4962 UNIMPLEMENTED();
4963}
4964
Jamie Madilld04908b2017-06-09 14:15:35 -04004965void Context::getProgramBinary(GLuint program,
4966 GLsizei bufSize,
4967 GLsizei *length,
4968 GLenum *binaryFormat,
4969 void *binary)
4970{
4971 Program *programObject = getProgram(program);
4972 ASSERT(programObject != nullptr);
4973
4974 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4975}
4976
4977void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4978{
4979 Program *programObject = getProgram(program);
4980 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04004981
Jamie Madilld04908b2017-06-09 14:15:35 -04004982 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
4983}
4984
Jamie Madillff325f12017-08-26 15:06:05 -04004985void Context::uniform1ui(GLint location, GLuint v0)
4986{
4987 Program *program = mGLState.getProgram();
4988 program->setUniform1uiv(location, 1, &v0);
4989}
4990
4991void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
4992{
4993 Program *program = mGLState.getProgram();
4994 const GLuint xy[] = {v0, v1};
4995 program->setUniform2uiv(location, 1, xy);
4996}
4997
4998void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
4999{
5000 Program *program = mGLState.getProgram();
5001 const GLuint xyz[] = {v0, v1, v2};
5002 program->setUniform3uiv(location, 1, xyz);
5003}
5004
5005void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
5006{
5007 Program *program = mGLState.getProgram();
5008 const GLuint xyzw[] = {v0, v1, v2, v3};
5009 program->setUniform4uiv(location, 1, xyzw);
5010}
5011
5012void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
5013{
5014 Program *program = mGLState.getProgram();
5015 program->setUniform1uiv(location, count, value);
5016}
5017void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5018{
5019 Program *program = mGLState.getProgram();
5020 program->setUniform2uiv(location, count, value);
5021}
5022
5023void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5024{
5025 Program *program = mGLState.getProgram();
5026 program->setUniform3uiv(location, count, value);
5027}
5028
5029void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5030{
5031 Program *program = mGLState.getProgram();
5032 program->setUniform4uiv(location, count, value);
5033}
5034
Jamie Madillf0e04492017-08-26 15:28:42 -04005035void Context::genQueries(GLsizei n, GLuint *ids)
5036{
5037 for (GLsizei i = 0; i < n; i++)
5038 {
5039 GLuint handle = mQueryHandleAllocator.allocate();
5040 mQueryMap.assign(handle, nullptr);
5041 ids[i] = handle;
5042 }
5043}
5044
5045void Context::deleteQueries(GLsizei n, const GLuint *ids)
5046{
5047 for (int i = 0; i < n; i++)
5048 {
5049 GLuint query = ids[i];
5050
5051 Query *queryObject = nullptr;
5052 if (mQueryMap.erase(query, &queryObject))
5053 {
5054 mQueryHandleAllocator.release(query);
5055 if (queryObject)
5056 {
5057 queryObject->release(this);
5058 }
5059 }
5060 }
5061}
5062
5063GLboolean Context::isQuery(GLuint id)
5064{
5065 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
5066}
5067
Jamie Madillc8c95812017-08-26 18:40:09 -04005068void Context::uniformMatrix2x3fv(GLint location,
5069 GLsizei count,
5070 GLboolean transpose,
5071 const GLfloat *value)
5072{
5073 Program *program = mGLState.getProgram();
5074 program->setUniformMatrix2x3fv(location, count, transpose, value);
5075}
5076
5077void Context::uniformMatrix3x2fv(GLint location,
5078 GLsizei count,
5079 GLboolean transpose,
5080 const GLfloat *value)
5081{
5082 Program *program = mGLState.getProgram();
5083 program->setUniformMatrix3x2fv(location, count, transpose, value);
5084}
5085
5086void Context::uniformMatrix2x4fv(GLint location,
5087 GLsizei count,
5088 GLboolean transpose,
5089 const GLfloat *value)
5090{
5091 Program *program = mGLState.getProgram();
5092 program->setUniformMatrix2x4fv(location, count, transpose, value);
5093}
5094
5095void Context::uniformMatrix4x2fv(GLint location,
5096 GLsizei count,
5097 GLboolean transpose,
5098 const GLfloat *value)
5099{
5100 Program *program = mGLState.getProgram();
5101 program->setUniformMatrix4x2fv(location, count, transpose, value);
5102}
5103
5104void Context::uniformMatrix3x4fv(GLint location,
5105 GLsizei count,
5106 GLboolean transpose,
5107 const GLfloat *value)
5108{
5109 Program *program = mGLState.getProgram();
5110 program->setUniformMatrix3x4fv(location, count, transpose, value);
5111}
5112
5113void Context::uniformMatrix4x3fv(GLint location,
5114 GLsizei count,
5115 GLboolean transpose,
5116 const GLfloat *value)
5117{
5118 Program *program = mGLState.getProgram();
5119 program->setUniformMatrix4x3fv(location, count, transpose, value);
5120}
5121
Jamie Madilld7576732017-08-26 18:49:50 -04005122void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5123{
5124 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5125 {
5126 GLuint vertexArray = arrays[arrayIndex];
5127
5128 if (arrays[arrayIndex] != 0)
5129 {
5130 VertexArray *vertexArrayObject = nullptr;
5131 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5132 {
5133 if (vertexArrayObject != nullptr)
5134 {
5135 detachVertexArray(vertexArray);
5136 vertexArrayObject->onDestroy(this);
5137 }
5138
5139 mVertexArrayHandleAllocator.release(vertexArray);
5140 }
5141 }
5142 }
5143}
5144
5145void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5146{
5147 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5148 {
5149 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5150 mVertexArrayMap.assign(vertexArray, nullptr);
5151 arrays[arrayIndex] = vertexArray;
5152 }
5153}
5154
5155bool Context::isVertexArray(GLuint array)
5156{
5157 if (array == 0)
5158 {
5159 return GL_FALSE;
5160 }
5161
5162 VertexArray *vao = getVertexArray(array);
5163 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5164}
5165
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005166void Context::endTransformFeedback()
5167{
5168 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5169 transformFeedback->end(this);
5170}
5171
5172void Context::transformFeedbackVaryings(GLuint program,
5173 GLsizei count,
5174 const GLchar *const *varyings,
5175 GLenum bufferMode)
5176{
5177 Program *programObject = getProgram(program);
5178 ASSERT(programObject);
5179 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5180}
5181
5182void Context::getTransformFeedbackVarying(GLuint program,
5183 GLuint index,
5184 GLsizei bufSize,
5185 GLsizei *length,
5186 GLsizei *size,
5187 GLenum *type,
5188 GLchar *name)
5189{
5190 Program *programObject = getProgram(program);
5191 ASSERT(programObject);
5192 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5193}
5194
5195void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5196{
5197 for (int i = 0; i < n; i++)
5198 {
5199 GLuint transformFeedback = ids[i];
5200 if (transformFeedback == 0)
5201 {
5202 continue;
5203 }
5204
5205 TransformFeedback *transformFeedbackObject = nullptr;
5206 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5207 {
5208 if (transformFeedbackObject != nullptr)
5209 {
5210 detachTransformFeedback(transformFeedback);
5211 transformFeedbackObject->release(this);
5212 }
5213
5214 mTransformFeedbackHandleAllocator.release(transformFeedback);
5215 }
5216 }
5217}
5218
5219void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5220{
5221 for (int i = 0; i < n; i++)
5222 {
5223 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5224 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5225 ids[i] = transformFeedback;
5226 }
5227}
5228
5229bool Context::isTransformFeedback(GLuint id)
5230{
5231 if (id == 0)
5232 {
5233 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5234 // returns FALSE
5235 return GL_FALSE;
5236 }
5237
5238 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5239 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5240}
5241
5242void Context::pauseTransformFeedback()
5243{
5244 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5245 transformFeedback->pause();
5246}
5247
5248void Context::resumeTransformFeedback()
5249{
5250 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5251 transformFeedback->resume();
5252}
5253
Jamie Madill12e957f2017-08-26 21:42:26 -04005254void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5255{
5256 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005257 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005258}
5259
5260GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5261{
5262 const Program *programObject = getProgram(program);
5263 return programObject->getFragDataLocation(name);
5264}
5265
5266void Context::getUniformIndices(GLuint program,
5267 GLsizei uniformCount,
5268 const GLchar *const *uniformNames,
5269 GLuint *uniformIndices)
5270{
5271 const Program *programObject = getProgram(program);
5272 if (!programObject->isLinked())
5273 {
5274 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5275 {
5276 uniformIndices[uniformId] = GL_INVALID_INDEX;
5277 }
5278 }
5279 else
5280 {
5281 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5282 {
5283 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5284 }
5285 }
5286}
5287
5288void Context::getActiveUniformsiv(GLuint program,
5289 GLsizei uniformCount,
5290 const GLuint *uniformIndices,
5291 GLenum pname,
5292 GLint *params)
5293{
5294 const Program *programObject = getProgram(program);
5295 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5296 {
5297 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005298 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005299 }
5300}
5301
5302GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5303{
5304 const Program *programObject = getProgram(program);
5305 return programObject->getUniformBlockIndex(uniformBlockName);
5306}
5307
5308void Context::getActiveUniformBlockiv(GLuint program,
5309 GLuint uniformBlockIndex,
5310 GLenum pname,
5311 GLint *params)
5312{
5313 const Program *programObject = getProgram(program);
5314 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5315}
5316
5317void Context::getActiveUniformBlockName(GLuint program,
5318 GLuint uniformBlockIndex,
5319 GLsizei bufSize,
5320 GLsizei *length,
5321 GLchar *uniformBlockName)
5322{
5323 const Program *programObject = getProgram(program);
5324 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5325}
5326
5327void Context::uniformBlockBinding(GLuint program,
5328 GLuint uniformBlockIndex,
5329 GLuint uniformBlockBinding)
5330{
5331 Program *programObject = getProgram(program);
5332 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5333}
5334
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005335GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5336{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005337 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5338 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005339
Jamie Madill70b5bb02017-08-28 13:32:37 -04005340 Sync *syncObject = getSync(syncHandle);
5341 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005342 if (error.isError())
5343 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005344 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005345 handleError(error);
5346 return nullptr;
5347 }
5348
Jamie Madill70b5bb02017-08-28 13:32:37 -04005349 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005350}
5351
5352GLboolean Context::isSync(GLsync sync)
5353{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005354 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005355}
5356
5357GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5358{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005359 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005360
5361 GLenum result = GL_WAIT_FAILED;
5362 handleError(syncObject->clientWait(flags, timeout, &result));
5363 return result;
5364}
5365
5366void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5367{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005368 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005369 handleError(syncObject->serverWait(flags, timeout));
5370}
5371
5372void Context::getInteger64v(GLenum pname, GLint64 *params)
5373{
5374 GLenum nativeType = GL_NONE;
5375 unsigned int numParams = 0;
5376 getQueryParameterInfo(pname, &nativeType, &numParams);
5377
5378 if (nativeType == GL_INT_64_ANGLEX)
5379 {
5380 getInteger64vImpl(pname, params);
5381 }
5382 else
5383 {
5384 CastStateValues(this, nativeType, pname, numParams, params);
5385 }
5386}
5387
Corentin Wallez336129f2017-10-17 15:55:40 -04005388void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04005389{
5390 Buffer *buffer = mGLState.getTargetBuffer(target);
5391 QueryBufferParameteri64v(buffer, pname, params);
5392}
5393
5394void Context::genSamplers(GLsizei count, GLuint *samplers)
5395{
5396 for (int i = 0; i < count; i++)
5397 {
5398 samplers[i] = mState.mSamplers->createSampler();
5399 }
5400}
5401
5402void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5403{
5404 for (int i = 0; i < count; i++)
5405 {
5406 GLuint sampler = samplers[i];
5407
5408 if (mState.mSamplers->getSampler(sampler))
5409 {
5410 detachSampler(sampler);
5411 }
5412
5413 mState.mSamplers->deleteObject(this, sampler);
5414 }
5415}
5416
5417void Context::getInternalformativ(GLenum target,
5418 GLenum internalformat,
5419 GLenum pname,
5420 GLsizei bufSize,
5421 GLint *params)
5422{
5423 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5424 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5425}
5426
Jiajia Qin5451d532017-11-16 17:16:34 +08005427void Context::programUniform1i(GLuint program, GLint location, GLint v0)
5428{
5429 programUniform1iv(program, location, 1, &v0);
5430}
5431
5432void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
5433{
5434 GLint xy[2] = {v0, v1};
5435 programUniform2iv(program, location, 1, xy);
5436}
5437
5438void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
5439{
5440 GLint xyz[3] = {v0, v1, v2};
5441 programUniform3iv(program, location, 1, xyz);
5442}
5443
5444void Context::programUniform4i(GLuint program,
5445 GLint location,
5446 GLint v0,
5447 GLint v1,
5448 GLint v2,
5449 GLint v3)
5450{
5451 GLint xyzw[4] = {v0, v1, v2, v3};
5452 programUniform4iv(program, location, 1, xyzw);
5453}
5454
5455void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
5456{
5457 programUniform1uiv(program, location, 1, &v0);
5458}
5459
5460void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
5461{
5462 GLuint xy[2] = {v0, v1};
5463 programUniform2uiv(program, location, 1, xy);
5464}
5465
5466void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
5467{
5468 GLuint xyz[3] = {v0, v1, v2};
5469 programUniform3uiv(program, location, 1, xyz);
5470}
5471
5472void Context::programUniform4ui(GLuint program,
5473 GLint location,
5474 GLuint v0,
5475 GLuint v1,
5476 GLuint v2,
5477 GLuint v3)
5478{
5479 GLuint xyzw[4] = {v0, v1, v2, v3};
5480 programUniform4uiv(program, location, 1, xyzw);
5481}
5482
5483void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
5484{
5485 programUniform1fv(program, location, 1, &v0);
5486}
5487
5488void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
5489{
5490 GLfloat xy[2] = {v0, v1};
5491 programUniform2fv(program, location, 1, xy);
5492}
5493
5494void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
5495{
5496 GLfloat xyz[3] = {v0, v1, v2};
5497 programUniform3fv(program, location, 1, xyz);
5498}
5499
5500void Context::programUniform4f(GLuint program,
5501 GLint location,
5502 GLfloat v0,
5503 GLfloat v1,
5504 GLfloat v2,
5505 GLfloat v3)
5506{
5507 GLfloat xyzw[4] = {v0, v1, v2, v3};
5508 programUniform4fv(program, location, 1, xyzw);
5509}
5510
Jamie Madill81c2e252017-09-09 23:32:46 -04005511void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5512{
5513 Program *programObject = getProgram(program);
5514 ASSERT(programObject);
5515 if (programObject->setUniform1iv(location, count, value) ==
5516 Program::SetUniformResult::SamplerChanged)
5517 {
5518 mGLState.setObjectDirty(GL_PROGRAM);
5519 }
5520}
5521
Jiajia Qin5451d532017-11-16 17:16:34 +08005522void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5523{
5524 Program *programObject = getProgram(program);
5525 ASSERT(programObject);
5526 programObject->setUniform2iv(location, count, value);
5527}
5528
5529void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5530{
5531 Program *programObject = getProgram(program);
5532 ASSERT(programObject);
5533 programObject->setUniform3iv(location, count, value);
5534}
5535
5536void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5537{
5538 Program *programObject = getProgram(program);
5539 ASSERT(programObject);
5540 programObject->setUniform4iv(location, count, value);
5541}
5542
5543void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5544{
5545 Program *programObject = getProgram(program);
5546 ASSERT(programObject);
5547 programObject->setUniform1uiv(location, count, value);
5548}
5549
5550void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5551{
5552 Program *programObject = getProgram(program);
5553 ASSERT(programObject);
5554 programObject->setUniform2uiv(location, count, value);
5555}
5556
5557void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5558{
5559 Program *programObject = getProgram(program);
5560 ASSERT(programObject);
5561 programObject->setUniform3uiv(location, count, value);
5562}
5563
5564void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5565{
5566 Program *programObject = getProgram(program);
5567 ASSERT(programObject);
5568 programObject->setUniform4uiv(location, count, value);
5569}
5570
5571void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5572{
5573 Program *programObject = getProgram(program);
5574 ASSERT(programObject);
5575 programObject->setUniform1fv(location, count, value);
5576}
5577
5578void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5579{
5580 Program *programObject = getProgram(program);
5581 ASSERT(programObject);
5582 programObject->setUniform2fv(location, count, value);
5583}
5584
5585void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5586{
5587 Program *programObject = getProgram(program);
5588 ASSERT(programObject);
5589 programObject->setUniform3fv(location, count, value);
5590}
5591
5592void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5593{
5594 Program *programObject = getProgram(program);
5595 ASSERT(programObject);
5596 programObject->setUniform4fv(location, count, value);
5597}
5598
5599void Context::programUniformMatrix2fv(GLuint program,
5600 GLint location,
5601 GLsizei count,
5602 GLboolean transpose,
5603 const GLfloat *value)
5604{
5605 Program *programObject = getProgram(program);
5606 ASSERT(programObject);
5607 programObject->setUniformMatrix2fv(location, count, transpose, value);
5608}
5609
5610void Context::programUniformMatrix3fv(GLuint program,
5611 GLint location,
5612 GLsizei count,
5613 GLboolean transpose,
5614 const GLfloat *value)
5615{
5616 Program *programObject = getProgram(program);
5617 ASSERT(programObject);
5618 programObject->setUniformMatrix3fv(location, count, transpose, value);
5619}
5620
5621void Context::programUniformMatrix4fv(GLuint program,
5622 GLint location,
5623 GLsizei count,
5624 GLboolean transpose,
5625 const GLfloat *value)
5626{
5627 Program *programObject = getProgram(program);
5628 ASSERT(programObject);
5629 programObject->setUniformMatrix4fv(location, count, transpose, value);
5630}
5631
5632void Context::programUniformMatrix2x3fv(GLuint program,
5633 GLint location,
5634 GLsizei count,
5635 GLboolean transpose,
5636 const GLfloat *value)
5637{
5638 Program *programObject = getProgram(program);
5639 ASSERT(programObject);
5640 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
5641}
5642
5643void Context::programUniformMatrix3x2fv(GLuint program,
5644 GLint location,
5645 GLsizei count,
5646 GLboolean transpose,
5647 const GLfloat *value)
5648{
5649 Program *programObject = getProgram(program);
5650 ASSERT(programObject);
5651 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
5652}
5653
5654void Context::programUniformMatrix2x4fv(GLuint program,
5655 GLint location,
5656 GLsizei count,
5657 GLboolean transpose,
5658 const GLfloat *value)
5659{
5660 Program *programObject = getProgram(program);
5661 ASSERT(programObject);
5662 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
5663}
5664
5665void Context::programUniformMatrix4x2fv(GLuint program,
5666 GLint location,
5667 GLsizei count,
5668 GLboolean transpose,
5669 const GLfloat *value)
5670{
5671 Program *programObject = getProgram(program);
5672 ASSERT(programObject);
5673 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
5674}
5675
5676void Context::programUniformMatrix3x4fv(GLuint program,
5677 GLint location,
5678 GLsizei count,
5679 GLboolean transpose,
5680 const GLfloat *value)
5681{
5682 Program *programObject = getProgram(program);
5683 ASSERT(programObject);
5684 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
5685}
5686
5687void Context::programUniformMatrix4x3fv(GLuint program,
5688 GLint location,
5689 GLsizei count,
5690 GLboolean transpose,
5691 const GLfloat *value)
5692{
5693 Program *programObject = getProgram(program);
5694 ASSERT(programObject);
5695 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
5696}
5697
Jamie Madill81c2e252017-09-09 23:32:46 -04005698void Context::onTextureChange(const Texture *texture)
5699{
5700 // Conservatively assume all textures are dirty.
5701 // TODO(jmadill): More fine-grained update.
5702 mGLState.setObjectDirty(GL_TEXTURE);
5703}
5704
Yunchao Hea336b902017-08-02 16:05:21 +08005705void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5706{
5707 for (int i = 0; i < count; i++)
5708 {
5709 pipelines[i] = createProgramPipeline();
5710 }
5711}
5712
5713void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5714{
5715 for (int i = 0; i < count; i++)
5716 {
5717 if (pipelines[i] != 0)
5718 {
5719 deleteProgramPipeline(pipelines[i]);
5720 }
5721 }
5722}
5723
5724GLboolean Context::isProgramPipeline(GLuint pipeline)
5725{
5726 if (pipeline == 0)
5727 {
5728 return GL_FALSE;
5729 }
5730
5731 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5732}
5733
Jamie Madill2b7bbc22017-12-21 17:30:38 -05005734void Context::finishFenceNV(GLuint fence)
5735{
5736 FenceNV *fenceObject = getFenceNV(fence);
5737
5738 ASSERT(fenceObject && fenceObject->isSet());
5739 handleError(fenceObject->finish());
5740}
5741
5742void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
5743{
5744 FenceNV *fenceObject = getFenceNV(fence);
5745
5746 ASSERT(fenceObject && fenceObject->isSet());
5747
5748 switch (pname)
5749 {
5750 case GL_FENCE_STATUS_NV:
5751 {
5752 // GL_NV_fence spec:
5753 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
5754 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
5755 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
5756 GLboolean status = GL_TRUE;
5757 if (fenceObject->getStatus() != GL_TRUE)
5758 {
5759 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
5760 }
5761 *params = status;
5762 break;
5763 }
5764
5765 case GL_FENCE_CONDITION_NV:
5766 {
5767 *params = static_cast<GLint>(fenceObject->getCondition());
5768 break;
5769 }
5770
5771 default:
5772 UNREACHABLE();
5773 }
5774}
5775
5776void Context::getTranslatedShaderSource(GLuint shader,
5777 GLsizei bufsize,
5778 GLsizei *length,
5779 GLchar *source)
5780{
5781 Shader *shaderObject = getShader(shader);
5782 ASSERT(shaderObject);
5783 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
5784}
5785
5786void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
5787{
5788 Program *programObject = getProgram(program);
5789 ASSERT(programObject);
5790
5791 programObject->getUniformfv(this, location, params);
5792}
5793
5794void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
5795{
5796 Program *programObject = getProgram(program);
5797 ASSERT(programObject);
5798
5799 programObject->getUniformiv(this, location, params);
5800}
5801
5802GLboolean Context::isFenceNV(GLuint fence)
5803{
5804 FenceNV *fenceObject = getFenceNV(fence);
5805
5806 if (fenceObject == nullptr)
5807 {
5808 return GL_FALSE;
5809 }
5810
5811 // GL_NV_fence spec:
5812 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
5813 // existing fence.
5814 return fenceObject->isSet();
5815}
5816
5817void Context::readnPixels(GLint x,
5818 GLint y,
5819 GLsizei width,
5820 GLsizei height,
5821 GLenum format,
5822 GLenum type,
5823 GLsizei bufSize,
5824 void *data)
5825{
5826 return readPixels(x, y, width, height, format, type, data);
5827}
5828
Jamie Madill007530e2017-12-28 14:27:04 -05005829void Context::setFenceNV(GLuint fence, GLenum condition)
5830{
5831 ASSERT(condition == GL_ALL_COMPLETED_NV);
5832
5833 FenceNV *fenceObject = getFenceNV(fence);
5834 ASSERT(fenceObject != nullptr);
5835 handleError(fenceObject->set(condition));
5836}
5837
5838GLboolean Context::testFenceNV(GLuint fence)
5839{
5840 FenceNV *fenceObject = getFenceNV(fence);
5841
5842 ASSERT(fenceObject != nullptr);
5843 ASSERT(fenceObject->isSet() == GL_TRUE);
5844
5845 GLboolean result = GL_TRUE;
5846 Error error = fenceObject->test(&result);
5847 if (error.isError())
5848 {
5849 handleError(error);
5850 return GL_TRUE;
5851 }
5852
5853 return result;
5854}
5855
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005856void Context::eGLImageTargetTexture2D(TextureType target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005857{
5858 Texture *texture = getTargetTexture(target);
5859 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
Corentin Wallezf0e89be2017-11-08 14:00:32 -08005860 handleError(texture->setEGLImageTarget(this, ToGLenum(target), imageObject));
Jamie Madill007530e2017-12-28 14:27:04 -05005861}
5862
Jamie Madillfa920eb2018-01-04 11:45:50 -05005863void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005864{
5865 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
5866 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
5867 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
5868}
5869
Jamie Madillfa920eb2018-01-04 11:45:50 -05005870void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
5871{
5872 UNIMPLEMENTED();
5873}
5874
Geoff Lang2aaa7b42018-01-12 17:17:27 -05005875void Context::alphaFunc(GLenum func, GLfloat ref)
5876{
5877 UNIMPLEMENTED();
5878}
5879
5880void Context::alphaFuncx(GLenum func, GLfixed ref)
5881{
5882 UNIMPLEMENTED();
5883}
5884
5885void Context::clearColorx(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5886{
5887 UNIMPLEMENTED();
5888}
5889
5890void Context::clearDepthx(GLfixed depth)
5891{
5892 UNIMPLEMENTED();
5893}
5894
5895void Context::clientActiveTexture(GLenum texture)
5896{
5897 UNIMPLEMENTED();
5898}
5899
5900void Context::clipPlanef(GLenum p, const GLfloat *eqn)
5901{
5902 UNIMPLEMENTED();
5903}
5904
5905void Context::clipPlanex(GLenum plane, const GLfixed *equation)
5906{
5907 UNIMPLEMENTED();
5908}
5909
5910void Context::color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
5911{
5912 UNIMPLEMENTED();
5913}
5914
5915void Context::color4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
5916{
5917 UNIMPLEMENTED();
5918}
5919
5920void Context::color4x(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5921{
5922 UNIMPLEMENTED();
5923}
5924
5925void Context::colorPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
5926{
5927 UNIMPLEMENTED();
5928}
5929
5930void Context::cullFace(GLenum mode)
5931{
5932 UNIMPLEMENTED();
5933}
5934
5935void Context::depthRangex(GLfixed n, GLfixed f)
5936{
5937 UNIMPLEMENTED();
5938}
5939
5940void Context::disableClientState(GLenum array)
5941{
5942 UNIMPLEMENTED();
5943}
5944
5945void Context::enableClientState(GLenum array)
5946{
5947 UNIMPLEMENTED();
5948}
5949
5950void Context::fogf(GLenum pname, GLfloat param)
5951{
5952 UNIMPLEMENTED();
5953}
5954
5955void Context::fogfv(GLenum pname, const GLfloat *params)
5956{
5957 UNIMPLEMENTED();
5958}
5959
5960void Context::fogx(GLenum pname, GLfixed param)
5961{
5962 UNIMPLEMENTED();
5963}
5964
5965void Context::fogxv(GLenum pname, const GLfixed *param)
5966{
5967 UNIMPLEMENTED();
5968}
5969
5970void Context::frustumf(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
5971{
5972 UNIMPLEMENTED();
5973}
5974
5975void Context::frustumx(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
5976{
5977 UNIMPLEMENTED();
5978}
5979
5980void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
5981{
5982 UNIMPLEMENTED();
5983}
5984
5985void Context::getClipPlanef(GLenum plane, GLfloat *equation)
5986{
5987 UNIMPLEMENTED();
5988}
5989
5990void Context::getClipPlanex(GLenum plane, GLfixed *equation)
5991{
5992 UNIMPLEMENTED();
5993}
5994
5995void Context::getFixedv(GLenum pname, GLfixed *params)
5996{
5997 UNIMPLEMENTED();
5998}
5999
6000void Context::getLightfv(GLenum light, GLenum pname, GLfloat *params)
6001{
6002 UNIMPLEMENTED();
6003}
6004
6005void Context::getLightxv(GLenum light, GLenum pname, GLfixed *params)
6006{
6007 UNIMPLEMENTED();
6008}
6009
6010void Context::getMaterialfv(GLenum face, GLenum pname, GLfloat *params)
6011{
6012 UNIMPLEMENTED();
6013}
6014
6015void Context::getMaterialxv(GLenum face, GLenum pname, GLfixed *params)
6016{
6017 UNIMPLEMENTED();
6018}
6019
6020void Context::getTexEnvfv(GLenum target, GLenum pname, GLfloat *params)
6021{
6022 UNIMPLEMENTED();
6023}
6024
6025void Context::getTexEnviv(GLenum target, GLenum pname, GLint *params)
6026{
6027 UNIMPLEMENTED();
6028}
6029
6030void Context::getTexEnvxv(GLenum target, GLenum pname, GLfixed *params)
6031{
6032 UNIMPLEMENTED();
6033}
6034
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006035void Context::getTexParameterxv(TextureType target, GLenum pname, GLfixed *params)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006036{
6037 UNIMPLEMENTED();
6038}
6039
6040void Context::lightModelf(GLenum pname, GLfloat param)
6041{
6042 UNIMPLEMENTED();
6043}
6044
6045void Context::lightModelfv(GLenum pname, const GLfloat *params)
6046{
6047 UNIMPLEMENTED();
6048}
6049
6050void Context::lightModelx(GLenum pname, GLfixed param)
6051{
6052 UNIMPLEMENTED();
6053}
6054
6055void Context::lightModelxv(GLenum pname, const GLfixed *param)
6056{
6057 UNIMPLEMENTED();
6058}
6059
6060void Context::lightf(GLenum light, GLenum pname, GLfloat param)
6061{
6062 UNIMPLEMENTED();
6063}
6064
6065void Context::lightfv(GLenum light, GLenum pname, const GLfloat *params)
6066{
6067 UNIMPLEMENTED();
6068}
6069
6070void Context::lightx(GLenum light, GLenum pname, GLfixed param)
6071{
6072 UNIMPLEMENTED();
6073}
6074
6075void Context::lightxv(GLenum light, GLenum pname, const GLfixed *params)
6076{
6077 UNIMPLEMENTED();
6078}
6079
6080void Context::lineWidthx(GLfixed width)
6081{
6082 UNIMPLEMENTED();
6083}
6084
6085void Context::loadIdentity()
6086{
6087 UNIMPLEMENTED();
6088}
6089
6090void Context::loadMatrixf(const GLfloat *m)
6091{
6092 UNIMPLEMENTED();
6093}
6094
6095void Context::loadMatrixx(const GLfixed *m)
6096{
6097 UNIMPLEMENTED();
6098}
6099
6100void Context::logicOp(GLenum opcode)
6101{
6102 UNIMPLEMENTED();
6103}
6104
6105void Context::materialf(GLenum face, GLenum pname, GLfloat param)
6106{
6107 UNIMPLEMENTED();
6108}
6109
6110void Context::materialfv(GLenum face, GLenum pname, const GLfloat *params)
6111{
6112 UNIMPLEMENTED();
6113}
6114
6115void Context::materialx(GLenum face, GLenum pname, GLfixed param)
6116{
6117 UNIMPLEMENTED();
6118}
6119
6120void Context::materialxv(GLenum face, GLenum pname, const GLfixed *param)
6121{
6122 UNIMPLEMENTED();
6123}
6124
6125void Context::matrixMode(GLenum mode)
6126{
6127 UNIMPLEMENTED();
6128}
6129
6130void Context::multMatrixf(const GLfloat *m)
6131{
6132 UNIMPLEMENTED();
6133}
6134
6135void Context::multMatrixx(const GLfixed *m)
6136{
6137 UNIMPLEMENTED();
6138}
6139
6140void Context::multiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q)
6141{
6142 UNIMPLEMENTED();
6143}
6144
6145void Context::multiTexCoord4x(GLenum texture, GLfixed s, GLfixed t, GLfixed r, GLfixed q)
6146{
6147 UNIMPLEMENTED();
6148}
6149
6150void Context::normal3f(GLfloat nx, GLfloat ny, GLfloat nz)
6151{
6152 UNIMPLEMENTED();
6153}
6154
6155void Context::normal3x(GLfixed nx, GLfixed ny, GLfixed nz)
6156{
6157 UNIMPLEMENTED();
6158}
6159
6160void Context::normalPointer(GLenum type, GLsizei stride, const void *pointer)
6161{
6162 UNIMPLEMENTED();
6163}
6164
6165void Context::orthof(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
6166{
6167 UNIMPLEMENTED();
6168}
6169
6170void Context::orthox(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
6171{
6172 UNIMPLEMENTED();
6173}
6174
6175void Context::pointParameterf(GLenum pname, GLfloat param)
6176{
6177 UNIMPLEMENTED();
6178}
6179
6180void Context::pointParameterfv(GLenum pname, const GLfloat *params)
6181{
6182 UNIMPLEMENTED();
6183}
6184
6185void Context::pointParameterx(GLenum pname, GLfixed param)
6186{
6187 UNIMPLEMENTED();
6188}
6189
6190void Context::pointParameterxv(GLenum pname, const GLfixed *params)
6191{
6192 UNIMPLEMENTED();
6193}
6194
6195void Context::pointSize(GLfloat size)
6196{
6197 UNIMPLEMENTED();
6198}
6199
6200void Context::pointSizex(GLfixed size)
6201{
6202 UNIMPLEMENTED();
6203}
6204
6205void Context::polygonOffsetx(GLfixed factor, GLfixed units)
6206{
6207 UNIMPLEMENTED();
6208}
6209
6210void Context::popMatrix()
6211{
6212 UNIMPLEMENTED();
6213}
6214
6215void Context::pushMatrix()
6216{
6217 UNIMPLEMENTED();
6218}
6219
6220void Context::rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
6221{
6222 UNIMPLEMENTED();
6223}
6224
6225void Context::rotatex(GLfixed angle, GLfixed x, GLfixed y, GLfixed z)
6226{
6227 UNIMPLEMENTED();
6228}
6229
6230void Context::sampleCoveragex(GLclampx value, GLboolean invert)
6231{
6232 UNIMPLEMENTED();
6233}
6234
6235void Context::scalef(GLfloat x, GLfloat y, GLfloat z)
6236{
6237 UNIMPLEMENTED();
6238}
6239
6240void Context::scalex(GLfixed x, GLfixed y, GLfixed z)
6241{
6242 UNIMPLEMENTED();
6243}
6244
6245void Context::shadeModel(GLenum mode)
6246{
6247 UNIMPLEMENTED();
6248}
6249
6250void Context::texCoordPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6251{
6252 UNIMPLEMENTED();
6253}
6254
6255void Context::texEnvf(GLenum target, GLenum pname, GLfloat param)
6256{
6257 UNIMPLEMENTED();
6258}
6259
6260void Context::texEnvfv(GLenum target, GLenum pname, const GLfloat *params)
6261{
6262 UNIMPLEMENTED();
6263}
6264
6265void Context::texEnvi(GLenum target, GLenum pname, GLint param)
6266{
6267 UNIMPLEMENTED();
6268}
6269
6270void Context::texEnviv(GLenum target, GLenum pname, const GLint *params)
6271{
6272 UNIMPLEMENTED();
6273}
6274
6275void Context::texEnvx(GLenum target, GLenum pname, GLfixed param)
6276{
6277 UNIMPLEMENTED();
6278}
6279
6280void Context::texEnvxv(GLenum target, GLenum pname, const GLfixed *params)
6281{
6282 UNIMPLEMENTED();
6283}
6284
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006285void Context::texParameterx(TextureType target, GLenum pname, GLfixed param)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006286{
6287 UNIMPLEMENTED();
6288}
6289
Corentin Wallezf0e89be2017-11-08 14:00:32 -08006290void Context::texParameterxv(TextureType target, GLenum pname, const GLfixed *params)
Geoff Lang2aaa7b42018-01-12 17:17:27 -05006291{
6292 UNIMPLEMENTED();
6293}
6294
6295void Context::translatef(GLfloat x, GLfloat y, GLfloat z)
6296{
6297 UNIMPLEMENTED();
6298}
6299
6300void Context::translatex(GLfixed x, GLfixed y, GLfixed z)
6301{
6302 UNIMPLEMENTED();
6303}
6304
6305void Context::vertexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6306{
6307 UNIMPLEMENTED();
6308}
6309
6310void Context::drawTexf(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height)
6311{
6312 UNIMPLEMENTED();
6313}
6314
6315void Context::drawTexfv(const GLfloat *coords)
6316{
6317 UNIMPLEMENTED();
6318}
6319
6320void Context::drawTexi(GLint x, GLint y, GLint z, GLint width, GLint height)
6321{
6322 UNIMPLEMENTED();
6323}
6324
6325void Context::drawTexiv(const GLint *coords)
6326{
6327 UNIMPLEMENTED();
6328}
6329
6330void Context::drawTexs(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height)
6331{
6332 UNIMPLEMENTED();
6333}
6334
6335void Context::drawTexsv(const GLshort *coords)
6336{
6337 UNIMPLEMENTED();
6338}
6339
6340void Context::drawTexx(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height)
6341{
6342 UNIMPLEMENTED();
6343}
6344
6345void Context::drawTexxv(const GLfixed *coords)
6346{
6347 UNIMPLEMENTED();
6348}
6349
6350void Context::currentPaletteMatrix(GLuint matrixpaletteindex)
6351{
6352 UNIMPLEMENTED();
6353}
6354
6355void Context::loadPaletteFromModelViewMatrix()
6356{
6357 UNIMPLEMENTED();
6358}
6359
6360void Context::matrixIndexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6361{
6362 UNIMPLEMENTED();
6363}
6364
6365void Context::weightPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6366{
6367 UNIMPLEMENTED();
6368}
6369
6370void Context::pointSizePointer(GLenum type, GLsizei stride, const void *pointer)
6371{
6372 UNIMPLEMENTED();
6373}
6374
6375GLbitfield Context::queryMatrixx(GLfixed *mantissa, GLint *exponent)
6376{
6377 UNIMPLEMENTED();
6378 return 0;
6379}
6380
Jamie Madillc29968b2016-01-20 11:17:23 -05006381} // namespace gl