blob: 1f8c1476e09839a95100ab7d7ff748d32437131a [file] [log] [blame]
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001//
Geoff Langeeba6e12014-02-03 13:12:30 -05002// Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
7// Context.cpp: Implements the gl::Context class, managing all GL state and performing
8// rendering operations. It is the GLES2 specific implementation of EGLContext.
9
Geoff Lang2b5420c2014-11-19 14:20:15 -050010#include "libANGLE/Context.h"
apatrick@chromium.org144f2802012-07-12 01:42:34 +000011
Jamie Madill231c7f52017-04-26 13:45:37 -040012#include <string.h>
Jamie Madillb9293972015-02-19 11:07:54 -050013#include <iterator>
14#include <sstream>
Sami Väisänend59ca052016-06-21 16:10:00 +030015#include <vector>
Jamie Madillb9293972015-02-19 11:07:54 -050016
Sami Väisänene45e53b2016-05-25 10:36:04 +030017#include "common/matrix_utils.h"
Geoff Lang0b7eef72014-06-12 14:10:47 -040018#include "common/platform.h"
Jamie Madillb9293972015-02-19 11:07:54 -050019#include "common/utilities.h"
Geoff Langc339c4e2016-11-29 10:37:36 -050020#include "common/version.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050021#include "libANGLE/Buffer.h"
Jamie Madillb9293972015-02-19 11:07:54 -050022#include "libANGLE/Compiler.h"
Jamie Madill948bbe52017-06-01 13:10:42 -040023#include "libANGLE/Display.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050024#include "libANGLE/Fence.h"
25#include "libANGLE/Framebuffer.h"
26#include "libANGLE/FramebufferAttachment.h"
Sami Väisänene45e53b2016-05-25 10:36:04 +030027#include "libANGLE/Path.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050028#include "libANGLE/Program.h"
Yunchao Hea336b902017-08-02 16:05:21 +080029#include "libANGLE/ProgramPipeline.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050030#include "libANGLE/Query.h"
Jamie Madillb9293972015-02-19 11:07:54 -050031#include "libANGLE/Renderbuffer.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050032#include "libANGLE/ResourceManager.h"
33#include "libANGLE/Sampler.h"
Jamie Madill9dd0cf02014-11-24 11:38:51 -050034#include "libANGLE/Surface.h"
Geoff Lang2b5420c2014-11-19 14:20:15 -050035#include "libANGLE/Texture.h"
36#include "libANGLE/TransformFeedback.h"
37#include "libANGLE/VertexArray.h"
Kenneth Russellf2f6f652016-10-05 19:53:23 -070038#include "libANGLE/Workarounds.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040039#include "libANGLE/formatutils.h"
Martin Radev66fb8202016-07-28 11:45:20 +030040#include "libANGLE/queryconversions.h"
Geoff Langc1984ed2016-10-07 12:41:00 -040041#include "libANGLE/queryutils.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040042#include "libANGLE/renderer/ContextImpl.h"
43#include "libANGLE/renderer/EGLImplFactory.h"
Jamie Madill7b62cf92017-11-02 15:20:49 -040044#include "libANGLE/renderer/Format.h"
Jamie Madill231c7f52017-04-26 13:45:37 -040045#include "libANGLE/validationES.h"
shannon.woods@transgaming.com486d9e92013-02-28 23:15:41 +000046
Geoff Langf6db0982015-08-25 13:04:00 -040047namespace
48{
49
Jamie Madillb6664922017-07-25 12:55:04 -040050#define ANGLE_HANDLE_ERR(X) \
51 handleError(X); \
52 return;
53#define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR);
54
Ian Ewell3ffd78b2016-01-22 16:09:42 -050055template <typename T>
Geoff Lang4ddf5af2016-12-01 14:30:44 -050056std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030057 GLsizei numPaths,
58 const void *paths,
59 GLuint pathBase)
60{
61 std::vector<gl::Path *> ret;
62 ret.reserve(numPaths);
63
64 const auto *nameArray = static_cast<const T *>(paths);
65
66 for (GLsizei i = 0; i < numPaths; ++i)
67 {
68 const GLuint pathName = nameArray[i] + pathBase;
69
70 ret.push_back(resourceManager.getPath(pathName));
71 }
72
73 return ret;
74}
75
Geoff Lang4ddf5af2016-12-01 14:30:44 -050076std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager,
Sami Väisänend59ca052016-06-21 16:10:00 +030077 GLsizei numPaths,
78 GLenum pathNameType,
79 const void *paths,
80 GLuint pathBase)
81{
82 switch (pathNameType)
83 {
84 case GL_UNSIGNED_BYTE:
85 return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase);
86
87 case GL_BYTE:
88 return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase);
89
90 case GL_UNSIGNED_SHORT:
91 return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase);
92
93 case GL_SHORT:
94 return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase);
95
96 case GL_UNSIGNED_INT:
97 return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase);
98
99 case GL_INT:
100 return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase);
101 }
102
103 UNREACHABLE();
104 return std::vector<gl::Path *>();
105}
106
107template <typename T>
Geoff Lang2186c382016-10-14 10:54:54 -0400108gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500109{
Geoff Lang2186c382016-10-14 10:54:54 -0400110 ASSERT(query != nullptr);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500111
112 switch (pname)
113 {
114 case GL_QUERY_RESULT_EXT:
Geoff Lang2186c382016-10-14 10:54:54 -0400115 return query->getResult(params);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500116 case GL_QUERY_RESULT_AVAILABLE_EXT:
117 {
118 bool available;
Geoff Lang2186c382016-10-14 10:54:54 -0400119 gl::Error error = query->isResultAvailable(&available);
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500120 if (!error.isError())
121 {
jchen10a99ed552017-09-22 08:10:32 +0800122 *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available));
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500123 }
124 return error;
125 }
126 default:
127 UNREACHABLE();
Yuly Novikovc4d18aa2017-03-09 18:45:02 -0500128 return gl::InternalError() << "Unreachable Error";
Ian Ewell3ffd78b2016-01-22 16:09:42 -0500129 }
130}
131
Geoff Langf6db0982015-08-25 13:04:00 -0400132void MarkTransformFeedbackBufferUsage(gl::TransformFeedback *transformFeedback)
133{
Geoff Lang1a683462015-09-29 15:09:59 -0400134 if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused())
Geoff Langf6db0982015-08-25 13:04:00 -0400135 {
136 for (size_t tfBufferIndex = 0; tfBufferIndex < transformFeedback->getIndexedBufferCount();
137 tfBufferIndex++)
138 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400139 const gl::OffsetBindingPointer<gl::Buffer> &buffer =
Geoff Langf6db0982015-08-25 13:04:00 -0400140 transformFeedback->getIndexedBuffer(tfBufferIndex);
141 if (buffer.get() != nullptr)
142 {
143 buffer->onTransformFeedback();
144 }
145 }
146 }
147}
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500148
149// Attribute map queries.
Martin Radev1be913c2016-07-11 17:59:16 +0300150EGLint GetClientMajorVersion(const egl::AttributeMap &attribs)
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500151{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400152 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1));
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500153}
154
Martin Radev1be913c2016-07-11 17:59:16 +0300155EGLint GetClientMinorVersion(const egl::AttributeMap &attribs)
156{
157 return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0));
158}
159
Geoff Langeb66a6e2016-10-31 13:06:12 -0400160gl::Version GetClientVersion(const egl::AttributeMap &attribs)
161{
162 return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs));
163}
164
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500165GLenum GetResetStrategy(const egl::AttributeMap &attribs)
166{
Ian Ewellec2c0c52016-04-05 13:46:26 -0400167 EGLAttrib attrib = attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT,
Jeff Gilbertc5de4d22017-10-31 15:07:53 -0700168 EGL_NO_RESET_NOTIFICATION);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500169 switch (attrib)
170 {
171 case EGL_NO_RESET_NOTIFICATION:
172 return GL_NO_RESET_NOTIFICATION_EXT;
173 case EGL_LOSE_CONTEXT_ON_RESET:
174 return GL_LOSE_CONTEXT_ON_RESET_EXT;
175 default:
176 UNREACHABLE();
177 return GL_NONE;
178 }
179}
180
181bool GetRobustAccess(const egl::AttributeMap &attribs)
182{
Geoff Lang077f20a2016-11-01 10:08:02 -0400183 return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) ||
184 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) !=
185 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500186}
187
188bool GetDebug(const egl::AttributeMap &attribs)
189{
Geoff Lang077f20a2016-11-01 10:08:02 -0400190 return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) ||
191 ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR) != 0);
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500192}
193
194bool GetNoError(const egl::AttributeMap &attribs)
195{
196 return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE);
197}
198
Geoff Langc287ea62016-09-16 14:46:51 -0400199bool GetWebGLContext(const egl::AttributeMap &attribs)
200{
201 return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE);
202}
203
Geoff Langf41a7152016-09-19 15:11:17 -0400204bool GetBindGeneratesResource(const egl::AttributeMap &attribs)
205{
206 return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE);
207}
208
Geoff Langfeb8c682017-02-13 16:07:35 -0500209bool GetClientArraysEnabled(const egl::AttributeMap &attribs)
210{
211 return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE);
212}
213
Geoff Langb433e872017-10-05 14:01:47 -0400214bool GetRobustResourceInit(const egl::AttributeMap &attribs)
215{
216 return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE);
217}
218
Martin Radev9d901792016-07-15 15:58:58 +0300219std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label)
220{
221 std::string labelName;
222 if (label != nullptr)
223 {
224 size_t labelLength = length < 0 ? strlen(label) : length;
225 labelName = std::string(label, labelLength);
226 }
227 return labelName;
228}
229
230void GetObjectLabelBase(const std::string &objectLabel,
231 GLsizei bufSize,
232 GLsizei *length,
233 GLchar *label)
234{
235 size_t writeLength = objectLabel.length();
236 if (label != nullptr && bufSize > 0)
237 {
238 writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length());
239 std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label);
240 label[writeLength] = '\0';
241 }
242
243 if (length != nullptr)
244 {
245 *length = static_cast<GLsizei>(writeLength);
246 }
247}
248
Jamie Madill0f80ed82017-09-19 00:24:56 -0400249template <typename CapT, typename MaxT>
250void LimitCap(CapT *cap, MaxT maximum)
251{
252 *cap = std::min(*cap, static_cast<CapT>(maximum));
253}
254
Geoff Langf6db0982015-08-25 13:04:00 -0400255} // anonymous namespace
256
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000257namespace gl
258{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +0000259
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400260Context::Context(rx::EGLImplFactory *implFactory,
261 const egl::Config *config,
Corentin Wallez51706ea2015-08-07 14:39:22 -0400262 const Context *shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500263 TextureManager *shareTextures,
Jamie Madill32447362017-06-28 14:53:52 -0400264 MemoryProgramCache *memoryProgramCache,
Corentin Wallezc295e512017-01-27 17:47:50 -0500265 const egl::AttributeMap &attribs,
Geoff Langb433e872017-10-05 14:01:47 -0400266 const egl::DisplayExtensions &displayExtensions)
Martin Radev1be913c2016-07-11 17:59:16 +0300267
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500268 : ValidationContext(shareContext,
Geoff Langce02f082017-02-06 16:46:21 -0500269 shareTextures,
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500270 GetClientVersion(attribs),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700271 &mGLState,
Jamie Madillf25855c2015-11-03 11:06:18 -0500272 mCaps,
273 mTextureCaps,
274 mExtensions,
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500275 mLimitations,
276 GetNoError(attribs)),
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700277 mImplementation(implFactory->createContext(mState)),
Jamie Madill2f348d22017-06-05 10:50:59 -0400278 mCompiler(),
Corentin Walleze3b10e82015-05-20 11:06:25 -0400279 mConfig(config),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500280 mClientType(EGL_OPENGL_ES_API),
281 mHasBeenCurrent(false),
282 mContextLost(false),
283 mResetStatus(GL_NO_ERROR),
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700284 mContextLostForced(false),
Jamie Madill46e6c7a2016-01-18 14:42:30 -0500285 mResetStrategy(GetResetStrategy(attribs)),
286 mRobustAccess(GetRobustAccess(attribs)),
Jamie Madill61e16b42017-06-19 11:13:23 -0400287 mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)),
288 mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)),
Jamie Madill4e0e6f82017-02-17 11:06:03 -0500289 mSurfacelessFramebuffer(nullptr),
Jamie Madille14951e2017-03-09 18:55:16 -0500290 mWebGLContext(GetWebGLContext(attribs)),
Jamie Madill32447362017-06-28 14:53:52 -0400291 mMemoryProgramCache(memoryProgramCache),
Jamie Madillb3f26b92017-07-19 15:07:41 -0400292 mScratchBuffer(1000u),
293 mZeroFilledBuffer(1000u)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000294{
Jamie Madill14bbb3f2017-09-12 15:23:01 -0400295 mImplementation->setMemoryProgramCache(memoryProgramCache);
296
Geoff Langb433e872017-10-05 14:01:47 -0400297 bool robustResourceInit = GetRobustResourceInit(attribs);
298 initCaps(displayExtensions, robustResourceInit);
Kenneth Russellf2f6f652016-10-05 19:53:23 -0700299 initWorkarounds();
Geoff Langc0b9ef42014-07-02 10:02:37 -0400300
Jamie Madill4928b7c2017-06-20 12:57:39 -0400301 mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs),
Jamie Madillc43be722017-07-13 16:22:14 -0400302 GetClientArraysEnabled(attribs), robustResourceInit,
303 mMemoryProgramCache != nullptr);
Régis Fénéon83107972015-02-05 12:57:44 +0100304
Shannon Woods53a94a82014-06-24 15:20:36 -0400305 mFenceNVHandleAllocator.setBaseHandle(0);
Geoff Lang7dca1862013-07-30 16:30:46 -0400306
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000307 // [OpenGL ES 2.0.24] section 3.7 page 83:
Corentin Wallez336129f2017-10-17 15:55:40 -0400308 // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000309 // and cube map texture state vectors respectively associated with them.
310 // In order that access to these initial textures not be lost, they are treated as texture
311 // objects all of whose names are 0.
312
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400313 Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400314 mZeroTextures[GL_TEXTURE_2D].set(this, zeroTexture2D);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500315
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400316 Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, GL_TEXTURE_CUBE_MAP);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400317 mZeroTextures[GL_TEXTURE_CUBE_MAP].set(this, zeroTextureCube);
Geoff Lang76b10c92014-09-05 16:28:14 -0400318
Geoff Langeb66a6e2016-10-31 13:06:12 -0400319 if (getClientVersion() >= Version(3, 0))
Geoff Lang76b10c92014-09-05 16:28:14 -0400320 {
321 // TODO: These could also be enabled via extension
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400322 Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, GL_TEXTURE_3D);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400323 mZeroTextures[GL_TEXTURE_3D].set(this, zeroTexture3D);
Geoff Lang76b10c92014-09-05 16:28:14 -0400324
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400325 Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_ARRAY);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400326 mZeroTextures[GL_TEXTURE_2D_ARRAY].set(this, zeroTexture2DArray);
Geoff Lang76b10c92014-09-05 16:28:14 -0400327 }
Geoff Lang3b573612016-10-31 14:08:10 -0400328 if (getClientVersion() >= Version(3, 1))
329 {
330 Texture *zeroTexture2DMultisample =
331 new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_MULTISAMPLE);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400332 mZeroTextures[GL_TEXTURE_2D_MULTISAMPLE].set(this, zeroTexture2DMultisample);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800333
Jiajia Qin6eafb042016-12-27 17:04:07 +0800334 for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++)
335 {
Qin Jiajia339f65b2018-02-27 12:52:48 +0800336 bindBufferRange(BufferBinding::AtomicCounter, i, 0, 0, 0);
Jiajia Qin6eafb042016-12-27 17:04:07 +0800337 }
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800338
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800339 for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++)
340 {
Corentin Wallez336129f2017-10-17 15:55:40 -0400341 bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0);
Jiajia Qinf546e7d2017-03-27 14:12:59 +0800342 }
Geoff Lang3b573612016-10-31 14:08:10 -0400343 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000344
Geoff Lang4751aab2017-10-30 15:14:52 -0400345 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
346 if (nativeExtensions.textureRectangle)
Corentin Wallez13c0dd42017-07-04 18:27:01 -0400347 {
348 Texture *zeroTextureRectangle =
349 new Texture(mImplementation.get(), 0, GL_TEXTURE_RECTANGLE_ANGLE);
350 mZeroTextures[GL_TEXTURE_RECTANGLE_ANGLE].set(this, zeroTextureRectangle);
351 }
352
Geoff Lang4751aab2017-10-30 15:14:52 -0400353 if (nativeExtensions.eglImageExternal || nativeExtensions.eglStreamConsumerExternal)
Ian Ewellbda75592016-04-18 17:25:54 -0400354 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400355 Texture *zeroTextureExternal =
356 new Texture(mImplementation.get(), 0, GL_TEXTURE_EXTERNAL_OES);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400357 mZeroTextures[GL_TEXTURE_EXTERNAL_OES].set(this, zeroTextureExternal);
Ian Ewellbda75592016-04-18 17:25:54 -0400358 }
359
Jamie Madill4928b7c2017-06-20 12:57:39 -0400360 mGLState.initializeZeroTextures(this, mZeroTextures);
Jamie Madille6382c32014-11-07 15:05:26 -0500361
Jamie Madill57a89722013-07-02 11:57:03 -0400362 bindVertexArray(0);
shannon.woods%transgaming.com@gtempaccount.com51171882013-04-13 03:39:10 +0000363
Geoff Langeb66a6e2016-10-31 13:06:12 -0400364 if (getClientVersion() >= Version(3, 0))
Geoff Lang1a683462015-09-29 15:09:59 -0400365 {
366 // [OpenGL ES 3.0.2] section 2.14.1 pg 85:
367 // In the initial state, a default transform feedback object is bound and treated as
368 // a transform feedback object with a name of zero. That object is bound any time
369 // BindTransformFeedback is called with id of zero
Jamie Madillf0dcb8b2017-08-26 19:05:13 -0400370 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Geoff Lang1a683462015-09-29 15:09:59 -0400371 }
Geoff Langc8058452014-02-03 12:04:11 -0500372
Corentin Wallez336129f2017-10-17 15:55:40 -0400373 for (auto type : angle::AllEnums<BufferBinding>())
374 {
375 bindBuffer(type, 0);
376 }
377
378 bindRenderbuffer(GL_RENDERBUFFER, 0);
379
380 for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++)
381 {
382 bindBufferRange(BufferBinding::Uniform, i, 0, 0, -1);
383 }
384
Jamie Madillad9f24e2016-02-12 09:27:24 -0500385 // Initialize dirty bit masks
Jamie Madillc67323a2017-11-02 23:11:41 -0400386 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500387 mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500388 // No dirty objects.
389
390 // Readpixels uses the pack state and read FBO
Jamie Madillc67323a2017-11-02 23:11:41 -0400391 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE);
Corentin Wallez29a20992017-11-06 18:23:16 -0500392 mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500393 mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
394
395 mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED);
396 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
397 mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR);
398 mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT);
399 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR);
400 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH);
401 mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL);
402 mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK);
403 mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK);
404 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT);
405 mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK);
406 mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
407
408 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED);
409 mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR);
Geoff Lang1d2c41d2016-10-19 16:14:46 -0700410 mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB);
Jamie Madillad9f24e2016-02-12 09:27:24 -0500411 mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER);
412 mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER);
Jamie Madill437fa652016-05-03 15:13:24 -0400413
Xinghua Cao10a4d432017-11-28 14:46:26 +0800414 // TODO(xinghua.cao@intel.com): add other dirty bits and dirty objects.
415 mComputeDirtyBits.set(State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING);
416 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_BINDING);
417 mComputeDirtyBits.set(State::DIRTY_BIT_PROGRAM_EXECUTABLE);
418 mComputeDirtyBits.set(State::DIRTY_BIT_TEXTURE_BINDINGS);
419 mComputeDirtyBits.set(State::DIRTY_BIT_SAMPLER_BINDINGS);
Qin Jiajia62fcf622017-11-30 16:16:12 +0800420 mComputeDirtyBits.set(State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING);
Xinghua Cao10a4d432017-11-28 14:46:26 +0800421
Jamie Madill53ea9cc2016-05-17 10:12:52 -0400422 handleError(mImplementation->initialize());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000423}
424
Jamie Madill4928b7c2017-06-20 12:57:39 -0400425egl::Error Context::onDestroy(const egl::Display *display)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000426{
Corentin Wallez80b24112015-08-25 16:41:57 -0400427 for (auto fence : mFenceNVMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000428 {
Corentin Wallez80b24112015-08-25 16:41:57 -0400429 SafeDelete(fence.second);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000430 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400431 mFenceNVMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000432
Corentin Wallez80b24112015-08-25 16:41:57 -0400433 for (auto query : mQueryMap)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000434 {
Geoff Langf0aa8422015-09-29 15:08:34 -0400435 if (query.second != nullptr)
436 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400437 query.second->release(this);
Geoff Langf0aa8422015-09-29 15:08:34 -0400438 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000439 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400440 mQueryMap.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000441
Corentin Wallez80b24112015-08-25 16:41:57 -0400442 for (auto vertexArray : mVertexArrayMap)
Jamie Madill57a89722013-07-02 11:57:03 -0400443 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400444 if (vertexArray.second)
445 {
446 vertexArray.second->onDestroy(this);
447 }
Jamie Madill57a89722013-07-02 11:57:03 -0400448 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400449 mVertexArrayMap.clear();
Jamie Madill57a89722013-07-02 11:57:03 -0400450
Corentin Wallez80b24112015-08-25 16:41:57 -0400451 for (auto transformFeedback : mTransformFeedbackMap)
Geoff Langc8058452014-02-03 12:04:11 -0500452 {
Geoff Lang36167ab2015-12-07 10:27:14 -0500453 if (transformFeedback.second != nullptr)
454 {
Jamie Madill6c1f6712017-02-14 19:08:04 -0500455 transformFeedback.second->release(this);
Geoff Lang36167ab2015-12-07 10:27:14 -0500456 }
Geoff Langc8058452014-02-03 12:04:11 -0500457 }
Jamie Madill96a483b2017-06-27 16:49:21 -0400458 mTransformFeedbackMap.clear();
Geoff Langc8058452014-02-03 12:04:11 -0500459
Jamie Madilldedd7b92014-11-05 16:30:36 -0500460 for (auto &zeroTexture : mZeroTextures)
Geoff Lang76b10c92014-09-05 16:28:14 -0400461 {
Jamie Madill71c88b32017-09-14 22:20:29 -0400462 ANGLE_TRY(zeroTexture.second->onDestroy(this));
Jamie Madill4928b7c2017-06-20 12:57:39 -0400463 zeroTexture.second.set(this, nullptr);
Geoff Lang76b10c92014-09-05 16:28:14 -0400464 }
465 mZeroTextures.clear();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000466
Corentin Wallezccab69d2017-01-27 16:57:15 -0500467 SafeDelete(mSurfacelessFramebuffer);
468
Jamie Madill4928b7c2017-06-20 12:57:39 -0400469 ANGLE_TRY(releaseSurface(display));
Jamie Madill2f348d22017-06-05 10:50:59 -0400470 releaseShaderCompiler();
Jamie Madill6c1f6712017-02-14 19:08:04 -0500471
Jamie Madill4928b7c2017-06-20 12:57:39 -0400472 mGLState.reset(this);
473
Jamie Madill6c1f6712017-02-14 19:08:04 -0500474 mState.mBuffers->release(this);
475 mState.mShaderPrograms->release(this);
476 mState.mTextures->release(this);
477 mState.mRenderbuffers->release(this);
478 mState.mSamplers->release(this);
Jamie Madill70b5bb02017-08-28 13:32:37 -0400479 mState.mSyncs->release(this);
Jamie Madill6c1f6712017-02-14 19:08:04 -0500480 mState.mPaths->release(this);
481 mState.mFramebuffers->release(this);
Yunchao Hea336b902017-08-02 16:05:21 +0800482 mState.mPipelines->release(this);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400483
Jamie Madill76e471e2017-10-21 09:56:01 -0400484 mImplementation->onDestroy(this);
485
Jamie Madill4928b7c2017-06-20 12:57:39 -0400486 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000487}
488
Jamie Madill70ee0f62017-02-06 16:04:20 -0500489Context::~Context()
490{
491}
492
Jamie Madill4928b7c2017-06-20 12:57:39 -0400493egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000494{
Jamie Madill61e16b42017-06-19 11:13:23 -0400495 mCurrentDisplay = display;
496
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000497 if (!mHasBeenCurrent)
498 {
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000499 initRendererString();
Geoff Langc339c4e2016-11-29 10:37:36 -0500500 initVersionStrings();
Geoff Langcec35902014-04-16 10:52:36 -0400501 initExtensionStrings();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000502
Corentin Wallezc295e512017-01-27 17:47:50 -0500503 int width = 0;
504 int height = 0;
505 if (surface != nullptr)
506 {
507 width = surface->getWidth();
508 height = surface->getHeight();
509 }
510
511 mGLState.setViewportParams(0, 0, width, height);
512 mGLState.setScissorParams(0, 0, width, height);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000513
514 mHasBeenCurrent = true;
515 }
516
Jamie Madill1b94d432015-08-07 13:23:23 -0400517 // TODO(jmadill): Rework this when we support ContextImpl
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700518 mGLState.setAllDirtyBits();
Jamie Madill81c2e252017-09-09 23:32:46 -0400519 mGLState.setAllDirtyObjects();
Jamie Madill1b94d432015-08-07 13:23:23 -0400520
Jamie Madill4928b7c2017-06-20 12:57:39 -0400521 ANGLE_TRY(releaseSurface(display));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500522
523 Framebuffer *newDefault = nullptr;
524 if (surface != nullptr)
525 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400526 ANGLE_TRY(surface->setIsCurrent(this, true));
Corentin Wallezccab69d2017-01-27 16:57:15 -0500527 mCurrentSurface = surface;
528 newDefault = surface->getDefaultFramebuffer();
529 }
530 else
531 {
532 if (mSurfacelessFramebuffer == nullptr)
533 {
534 mSurfacelessFramebuffer = new Framebuffer(mImplementation.get());
535 }
536
537 newDefault = mSurfacelessFramebuffer;
538 }
Jamie Madill18fdcbc2015-08-19 18:12:44 +0000539
Corentin Wallez37c39792015-08-20 14:19:46 -0400540 // Update default framebuffer, the binding of the previous default
541 // framebuffer (or lack of) will have a nullptr.
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400542 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700543 if (mGLState.getReadFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400544 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700545 mGLState.setReadFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400546 }
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700547 if (mGLState.getDrawFramebuffer() == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -0400548 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700549 mGLState.setDrawFramebufferBinding(newDefault);
Corentin Wallez37c39792015-08-20 14:19:46 -0400550 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500551 mState.mFramebuffers->setDefaultFramebuffer(newDefault);
Jamie Madillc1c1cdc2015-04-30 09:42:26 -0400552 }
Ian Ewell292f0052016-02-04 10:37:32 -0500553
554 // Notify the renderer of a context switch
Jamie Madill4928b7c2017-06-20 12:57:39 -0400555 mImplementation->onMakeCurrent(this);
556 return egl::NoError();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000557}
558
Jamie Madill4928b7c2017-06-20 12:57:39 -0400559egl::Error Context::releaseSurface(const egl::Display *display)
Jamie Madill77a72f62015-04-14 11:18:32 -0400560{
Corentin Wallez37c39792015-08-20 14:19:46 -0400561 // Remove the default framebuffer
Corentin Wallezc295e512017-01-27 17:47:50 -0500562 Framebuffer *currentDefault = nullptr;
563 if (mCurrentSurface != nullptr)
Corentin Wallez51706ea2015-08-07 14:39:22 -0400564 {
Corentin Wallezc295e512017-01-27 17:47:50 -0500565 currentDefault = mCurrentSurface->getDefaultFramebuffer();
566 }
567 else if (mSurfacelessFramebuffer != nullptr)
568 {
569 currentDefault = mSurfacelessFramebuffer;
Corentin Wallez51706ea2015-08-07 14:39:22 -0400570 }
571
Corentin Wallezc295e512017-01-27 17:47:50 -0500572 if (mGLState.getReadFramebuffer() == currentDefault)
573 {
574 mGLState.setReadFramebufferBinding(nullptr);
575 }
576 if (mGLState.getDrawFramebuffer() == currentDefault)
577 {
578 mGLState.setDrawFramebufferBinding(nullptr);
579 }
580 mState.mFramebuffers->setDefaultFramebuffer(nullptr);
581
582 if (mCurrentSurface)
583 {
Jamie Madill4928b7c2017-06-20 12:57:39 -0400584 ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false));
Corentin Wallezc295e512017-01-27 17:47:50 -0500585 mCurrentSurface = nullptr;
586 }
Jamie Madill4928b7c2017-06-20 12:57:39 -0400587
588 return egl::NoError();
Jamie Madill77a72f62015-04-14 11:18:32 -0400589}
590
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000591GLuint Context::createBuffer()
592{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500593 return mState.mBuffers->createBuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000594}
595
596GLuint Context::createProgram()
597{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500598 return mState.mShaderPrograms->createProgram(mImplementation.get());
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000599}
600
601GLuint Context::createShader(GLenum type)
602{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500603 return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000604}
605
606GLuint Context::createTexture()
607{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500608 return mState.mTextures->createTexture();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000609}
610
611GLuint Context::createRenderbuffer()
612{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500613 return mState.mRenderbuffers->createRenderbuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000614}
615
Sami Väisänene45e53b2016-05-25 10:36:04 +0300616GLuint Context::createPaths(GLsizei range)
617{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500618 auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300619 if (resultOrError.isError())
620 {
621 handleError(resultOrError.getError());
622 return 0;
623 }
624 return resultOrError.getResult();
625}
626
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000627// Returns an unused framebuffer name
628GLuint Context::createFramebuffer()
629{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500630 return mState.mFramebuffers->createFramebuffer();
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000631}
632
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500633void Context::genFencesNV(GLsizei n, GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000634{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500635 for (int i = 0; i < n; i++)
636 {
637 GLuint handle = mFenceNVHandleAllocator.allocate();
638 mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV()));
639 fences[i] = handle;
640 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000641}
642
Yunchao Hea336b902017-08-02 16:05:21 +0800643GLuint Context::createProgramPipeline()
644{
645 return mState.mPipelines->createProgramPipeline();
646}
647
Jiajia Qin5451d532017-11-16 17:16:34 +0800648GLuint Context::createShaderProgramv(GLenum type, GLsizei count, const GLchar *const *strings)
649{
650 UNIMPLEMENTED();
651 return 0u;
652}
653
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000654void Context::deleteBuffer(GLuint buffer)
655{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500656 if (mState.mBuffers->getBuffer(buffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000657 {
658 detachBuffer(buffer);
659 }
Jamie Madill893ab082014-05-16 16:56:10 -0400660
Jamie Madill6c1f6712017-02-14 19:08:04 -0500661 mState.mBuffers->deleteObject(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000662}
663
664void Context::deleteShader(GLuint shader)
665{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500666 mState.mShaderPrograms->deleteShader(this, shader);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000667}
668
669void Context::deleteProgram(GLuint program)
670{
Jamie Madill6c1f6712017-02-14 19:08:04 -0500671 mState.mShaderPrograms->deleteProgram(this, program);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000672}
673
674void Context::deleteTexture(GLuint texture)
675{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500676 if (mState.mTextures->getTexture(texture))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000677 {
678 detachTexture(texture);
679 }
680
Jamie Madill6c1f6712017-02-14 19:08:04 -0500681 mState.mTextures->deleteObject(this, texture);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000682}
683
684void Context::deleteRenderbuffer(GLuint renderbuffer)
685{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500686 if (mState.mRenderbuffers->getRenderbuffer(renderbuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000687 {
688 detachRenderbuffer(renderbuffer);
689 }
Jamie Madill893ab082014-05-16 16:56:10 -0400690
Jamie Madill6c1f6712017-02-14 19:08:04 -0500691 mState.mRenderbuffers->deleteObject(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000692}
693
Jamie Madill7f0c5a42017-08-26 22:43:26 -0400694void Context::deleteSync(GLsync sync)
Jamie Madillcd055f82013-07-26 11:55:15 -0400695{
696 // The spec specifies the underlying Fence object is not deleted until all current
697 // wait commands finish. However, since the name becomes invalid, we cannot query the fence,
698 // and since our API is currently designed for being called from a single thread, we can delete
699 // the fence immediately.
Jamie Madill70b5bb02017-08-28 13:32:37 -0400700 mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400701}
702
Yunchao Hea336b902017-08-02 16:05:21 +0800703void Context::deleteProgramPipeline(GLuint pipeline)
704{
705 if (mState.mPipelines->getProgramPipeline(pipeline))
706 {
707 detachProgramPipeline(pipeline);
708 }
709
710 mState.mPipelines->deleteObject(this, pipeline);
711}
712
Sami Väisänene45e53b2016-05-25 10:36:04 +0300713void Context::deletePaths(GLuint first, GLsizei range)
714{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500715 mState.mPaths->deletePaths(first, range);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300716}
717
718bool Context::hasPathData(GLuint path) const
719{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500720 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300721 if (pathObj == nullptr)
722 return false;
723
724 return pathObj->hasPathData();
725}
726
727bool Context::hasPath(GLuint path) const
728{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500729 return mState.mPaths->hasPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300730}
731
732void Context::setPathCommands(GLuint path,
733 GLsizei numCommands,
734 const GLubyte *commands,
735 GLsizei numCoords,
736 GLenum coordType,
737 const void *coords)
738{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500739 auto *pathObject = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300740
741 handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords));
742}
743
Jamie Madill007530e2017-12-28 14:27:04 -0500744void Context::pathParameterf(GLuint path, GLenum pname, GLfloat value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300745{
Jamie Madill007530e2017-12-28 14:27:04 -0500746 Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300747
748 switch (pname)
749 {
750 case GL_PATH_STROKE_WIDTH_CHROMIUM:
751 pathObj->setStrokeWidth(value);
752 break;
753 case GL_PATH_END_CAPS_CHROMIUM:
754 pathObj->setEndCaps(static_cast<GLenum>(value));
755 break;
756 case GL_PATH_JOIN_STYLE_CHROMIUM:
757 pathObj->setJoinStyle(static_cast<GLenum>(value));
758 break;
759 case GL_PATH_MITER_LIMIT_CHROMIUM:
760 pathObj->setMiterLimit(value);
761 break;
762 case GL_PATH_STROKE_BOUND_CHROMIUM:
763 pathObj->setStrokeBound(value);
764 break;
765 default:
766 UNREACHABLE();
767 break;
768 }
769}
770
Jamie Madill007530e2017-12-28 14:27:04 -0500771void Context::pathParameteri(GLuint path, GLenum pname, GLint value)
Sami Väisänene45e53b2016-05-25 10:36:04 +0300772{
Jamie Madill007530e2017-12-28 14:27:04 -0500773 // TODO(jmadill): Should use proper clamping/casting.
774 pathParameterf(path, pname, static_cast<GLfloat>(value));
775}
776
777void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value)
778{
779 const Path *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +0300780
781 switch (pname)
782 {
783 case GL_PATH_STROKE_WIDTH_CHROMIUM:
784 *value = pathObj->getStrokeWidth();
785 break;
786 case GL_PATH_END_CAPS_CHROMIUM:
787 *value = static_cast<GLfloat>(pathObj->getEndCaps());
788 break;
789 case GL_PATH_JOIN_STYLE_CHROMIUM:
790 *value = static_cast<GLfloat>(pathObj->getJoinStyle());
791 break;
792 case GL_PATH_MITER_LIMIT_CHROMIUM:
793 *value = pathObj->getMiterLimit();
794 break;
795 case GL_PATH_STROKE_BOUND_CHROMIUM:
796 *value = pathObj->getStrokeBound();
797 break;
798 default:
799 UNREACHABLE();
800 break;
801 }
802}
803
Jamie Madill007530e2017-12-28 14:27:04 -0500804void Context::getPathParameteriv(GLuint path, GLenum pname, GLint *value)
805{
806 GLfloat val = 0.0f;
807 getPathParameterfv(path, pname, value != nullptr ? &val : nullptr);
808 if (value)
809 *value = static_cast<GLint>(val);
810}
811
Sami Väisänene45e53b2016-05-25 10:36:04 +0300812void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask)
813{
814 mGLState.setPathStencilFunc(func, ref, mask);
815}
816
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000817void Context::deleteFramebuffer(GLuint framebuffer)
818{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500819 if (mState.mFramebuffers->getFramebuffer(framebuffer))
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000820 {
821 detachFramebuffer(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000822 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500823
Jamie Madill6c1f6712017-02-14 19:08:04 -0500824 mState.mFramebuffers->deleteObject(this, framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000825}
826
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500827void Context::deleteFencesNV(GLsizei n, const GLuint *fences)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000828{
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500829 for (int i = 0; i < n; i++)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000830 {
Jamie Madill2b7bbc22017-12-21 17:30:38 -0500831 GLuint fence = fences[i];
832
833 FenceNV *fenceObject = nullptr;
834 if (mFenceNVMap.erase(fence, &fenceObject))
835 {
836 mFenceNVHandleAllocator.release(fence);
837 delete fenceObject;
838 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000839 }
840}
841
Geoff Lang70d0f492015-12-10 17:45:46 -0500842Buffer *Context::getBuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000843{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500844 return mState.mBuffers->getBuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000845}
846
Jamie Madill570f7c82014-07-03 10:38:54 -0400847Texture *Context::getTexture(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000848{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500849 return mState.mTextures->getTexture(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000850}
851
Geoff Lang70d0f492015-12-10 17:45:46 -0500852Renderbuffer *Context::getRenderbuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000853{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500854 return mState.mRenderbuffers->getRenderbuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000855}
856
Jamie Madill70b5bb02017-08-28 13:32:37 -0400857Sync *Context::getSync(GLsync handle) const
Jamie Madillcd055f82013-07-26 11:55:15 -0400858{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400859 return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle)));
Jamie Madillcd055f82013-07-26 11:55:15 -0400860}
861
Jamie Madill57a89722013-07-02 11:57:03 -0400862VertexArray *Context::getVertexArray(GLuint handle) const
863{
Jamie Madill96a483b2017-06-27 16:49:21 -0400864 return mVertexArrayMap.query(handle);
Jamie Madill57a89722013-07-02 11:57:03 -0400865}
866
Jamie Madilldc356042013-07-19 16:36:57 -0400867Sampler *Context::getSampler(GLuint handle) const
868{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500869 return mState.mSamplers->getSampler(handle);
Jamie Madilldc356042013-07-19 16:36:57 -0400870}
871
Geoff Langc8058452014-02-03 12:04:11 -0500872TransformFeedback *Context::getTransformFeedback(GLuint handle) const
873{
Jamie Madill96a483b2017-06-27 16:49:21 -0400874 return mTransformFeedbackMap.query(handle);
Geoff Langc8058452014-02-03 12:04:11 -0500875}
876
Yunchao Hea336b902017-08-02 16:05:21 +0800877ProgramPipeline *Context::getProgramPipeline(GLuint handle) const
878{
879 return mState.mPipelines->getProgramPipeline(handle);
880}
881
Geoff Lang70d0f492015-12-10 17:45:46 -0500882LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const
883{
884 switch (identifier)
885 {
886 case GL_BUFFER:
887 return getBuffer(name);
888 case GL_SHADER:
889 return getShader(name);
890 case GL_PROGRAM:
891 return getProgram(name);
892 case GL_VERTEX_ARRAY:
893 return getVertexArray(name);
894 case GL_QUERY:
895 return getQuery(name);
896 case GL_TRANSFORM_FEEDBACK:
897 return getTransformFeedback(name);
898 case GL_SAMPLER:
899 return getSampler(name);
900 case GL_TEXTURE:
901 return getTexture(name);
902 case GL_RENDERBUFFER:
903 return getRenderbuffer(name);
904 case GL_FRAMEBUFFER:
905 return getFramebuffer(name);
906 default:
907 UNREACHABLE();
908 return nullptr;
909 }
910}
911
912LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const
913{
Jamie Madill70b5bb02017-08-28 13:32:37 -0400914 return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr)));
Geoff Lang70d0f492015-12-10 17:45:46 -0500915}
916
Martin Radev9d901792016-07-15 15:58:58 +0300917void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label)
918{
919 LabeledObject *object = getLabeledObject(identifier, name);
920 ASSERT(object != nullptr);
921
922 std::string labelName = GetObjectLabelFromPointer(length, label);
923 object->setLabel(labelName);
Jamie Madill8693bdb2017-09-02 15:32:14 -0400924
925 // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the
926 // specified object is active until we do this.
927 mGLState.setObjectDirty(identifier);
Martin Radev9d901792016-07-15 15:58:58 +0300928}
929
930void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label)
931{
932 LabeledObject *object = getLabeledObjectFromPtr(ptr);
933 ASSERT(object != nullptr);
934
935 std::string labelName = GetObjectLabelFromPointer(length, label);
936 object->setLabel(labelName);
937}
938
939void Context::getObjectLabel(GLenum identifier,
940 GLuint name,
941 GLsizei bufSize,
942 GLsizei *length,
943 GLchar *label) const
944{
945 LabeledObject *object = getLabeledObject(identifier, name);
946 ASSERT(object != nullptr);
947
948 const std::string &objectLabel = object->getLabel();
949 GetObjectLabelBase(objectLabel, bufSize, length, label);
950}
951
952void Context::getObjectPtrLabel(const void *ptr,
953 GLsizei bufSize,
954 GLsizei *length,
955 GLchar *label) const
956{
957 LabeledObject *object = getLabeledObjectFromPtr(ptr);
958 ASSERT(object != nullptr);
959
960 const std::string &objectLabel = object->getLabel();
961 GetObjectLabelBase(objectLabel, bufSize, length, label);
962}
963
Jamie Madilldc356042013-07-19 16:36:57 -0400964bool Context::isSampler(GLuint samplerName) const
965{
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500966 return mState.mSamplers->isSampler(samplerName);
Jamie Madilldc356042013-07-19 16:36:57 -0400967}
968
Jamie Madilldedd7b92014-11-05 16:30:36 -0500969void Context::bindTexture(GLenum target, GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000970{
Jamie Madill3f01e6c2016-03-08 13:53:02 -0500971 Texture *texture = nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000972
Jamie Madilldedd7b92014-11-05 16:30:36 -0500973 if (handle == 0)
974 {
975 texture = mZeroTextures[target].get();
976 }
977 else
978 {
Geoff Lang4ddf5af2016-12-01 14:30:44 -0500979 texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target);
Jamie Madilldedd7b92014-11-05 16:30:36 -0500980 }
981
982 ASSERT(texture);
Jamie Madill4928b7c2017-06-20 12:57:39 -0400983 mGLState.setSamplerTexture(this, target, texture);
shannon.woods%transgaming.com@gtempaccount.com90dbc442013-04-13 03:46:14 +0000984}
985
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500986void Context::bindReadFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000987{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500988 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
989 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700990 mGLState.setReadFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000991}
992
Jamie Madill5bf9ff42016-02-01 11:13:03 -0500993void Context::bindDrawFramebuffer(GLuint framebufferHandle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000994{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -0500995 Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation(
996 mImplementation.get(), mCaps, framebufferHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -0700997 mGLState.setDrawFramebufferBinding(framebuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +0000998}
999
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001000void Context::bindVertexArray(GLuint vertexArrayHandle)
Jamie Madill57a89722013-07-02 11:57:03 -04001001{
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001002 VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001003 mGLState.setVertexArrayBinding(vertexArray);
Jamie Madill57a89722013-07-02 11:57:03 -04001004}
1005
Shao80957d92017-02-20 21:25:59 +08001006void Context::bindVertexBuffer(GLuint bindingIndex,
1007 GLuint bufferHandle,
1008 GLintptr offset,
1009 GLsizei stride)
1010{
1011 Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001012 mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride);
Shao80957d92017-02-20 21:25:59 +08001013}
1014
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001015void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle)
Jamie Madilldc356042013-07-19 16:36:57 -04001016{
Geoff Lang76b10c92014-09-05 16:28:14 -04001017 ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits);
Jamie Madill901b3792016-05-26 09:20:40 -04001018 Sampler *sampler =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001019 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001020 mGLState.setSamplerBinding(this, textureUnit, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04001021}
1022
Xinghua Cao65ec0b22017-03-28 16:10:52 +08001023void Context::bindImageTexture(GLuint unit,
1024 GLuint texture,
1025 GLint level,
1026 GLboolean layered,
1027 GLint layer,
1028 GLenum access,
1029 GLenum format)
1030{
1031 Texture *tex = mState.mTextures->getTexture(texture);
1032 mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format);
1033}
1034
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001035void Context::useProgram(GLuint program)
1036{
Jamie Madill6c1f6712017-02-14 19:08:04 -05001037 mGLState.setProgram(this, getProgram(program));
daniel@transgaming.com95d29422012-07-24 18:36:10 +00001038}
1039
Jiajia Qin5451d532017-11-16 17:16:34 +08001040void Context::useProgramStages(GLuint pipeline, GLbitfield stages, GLuint program)
1041{
1042 UNIMPLEMENTED();
1043}
1044
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001045void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle)
Geoff Langc8058452014-02-03 12:04:11 -05001046{
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04001047 ASSERT(target == GL_TRANSFORM_FEEDBACK);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05001048 TransformFeedback *transformFeedback =
1049 checkTransformFeedbackAllocation(transformFeedbackHandle);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001050 mGLState.setTransformFeedbackBinding(this, transformFeedback);
Geoff Langc8058452014-02-03 12:04:11 -05001051}
1052
Yunchao Hea336b902017-08-02 16:05:21 +08001053void Context::bindProgramPipeline(GLuint pipelineHandle)
1054{
1055 ProgramPipeline *pipeline =
1056 mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle);
1057 mGLState.setProgramPipelineBinding(this, pipeline);
1058}
1059
Jamie Madillf0e04492017-08-26 15:28:42 -04001060void Context::beginQuery(GLenum target, GLuint query)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001061{
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001062 Query *queryObject = getQuery(query, true, target);
Jamie Madilldb2f14c2014-05-13 13:56:30 -04001063 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001064
Geoff Lang5aad9672014-09-08 11:10:42 -04001065 // begin query
Jamie Madillf0e04492017-08-26 15:28:42 -04001066 ANGLE_CONTEXT_TRY(queryObject->begin());
Geoff Lang5aad9672014-09-08 11:10:42 -04001067
1068 // set query as active for specified target only if begin succeeded
Jamie Madill4928b7c2017-06-20 12:57:39 -04001069 mGLState.setActiveQuery(this, target, queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001070}
1071
Jamie Madillf0e04492017-08-26 15:28:42 -04001072void Context::endQuery(GLenum target)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001073{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001074 Query *queryObject = mGLState.getActiveQuery(target);
Jamie Madill45c785d2014-05-13 14:09:34 -04001075 ASSERT(queryObject);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001076
Jamie Madillf0e04492017-08-26 15:28:42 -04001077 handleError(queryObject->end());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001078
Geoff Lang5aad9672014-09-08 11:10:42 -04001079 // Always unbind the query, even if there was an error. This may delete the query object.
Jamie Madill4928b7c2017-06-20 12:57:39 -04001080 mGLState.setActiveQuery(this, target, nullptr);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001081}
1082
Jamie Madillf0e04492017-08-26 15:28:42 -04001083void Context::queryCounter(GLuint id, GLenum target)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001084{
1085 ASSERT(target == GL_TIMESTAMP_EXT);
1086
1087 Query *queryObject = getQuery(id, true, target);
1088 ASSERT(queryObject);
1089
Jamie Madillf0e04492017-08-26 15:28:42 -04001090 handleError(queryObject->queryCounter());
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001091}
1092
1093void Context::getQueryiv(GLenum target, GLenum pname, GLint *params)
1094{
1095 switch (pname)
1096 {
1097 case GL_CURRENT_QUERY_EXT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001098 params[0] = mGLState.getActiveQueryId(target);
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001099 break;
1100 case GL_QUERY_COUNTER_BITS_EXT:
1101 switch (target)
1102 {
1103 case GL_TIME_ELAPSED_EXT:
1104 params[0] = getExtensions().queryCounterBitsTimeElapsed;
1105 break;
1106 case GL_TIMESTAMP_EXT:
1107 params[0] = getExtensions().queryCounterBitsTimestamp;
1108 break;
1109 default:
1110 UNREACHABLE();
1111 params[0] = 0;
1112 break;
1113 }
1114 break;
1115 default:
1116 UNREACHABLE();
1117 return;
1118 }
1119}
1120
Geoff Lang2186c382016-10-14 10:54:54 -04001121void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001122{
Geoff Lang2186c382016-10-14 10:54:54 -04001123 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001124}
1125
Geoff Lang2186c382016-10-14 10:54:54 -04001126void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001127{
Geoff Lang2186c382016-10-14 10:54:54 -04001128 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001129}
1130
Geoff Lang2186c382016-10-14 10:54:54 -04001131void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001132{
Geoff Lang2186c382016-10-14 10:54:54 -04001133 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001134}
1135
Geoff Lang2186c382016-10-14 10:54:54 -04001136void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params)
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001137{
Geoff Lang2186c382016-10-14 10:54:54 -04001138 handleError(GetQueryObjectParameter(getQuery(id), pname, params));
Ian Ewell3ffd78b2016-01-22 16:09:42 -05001139}
1140
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001141Framebuffer *Context::getFramebuffer(GLuint handle) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001142{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05001143 return mState.mFramebuffers->getFramebuffer(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001144}
1145
Jamie Madill2f348d22017-06-05 10:50:59 -04001146FenceNV *Context::getFenceNV(GLuint handle)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001147{
Jamie Madill96a483b2017-06-27 16:49:21 -04001148 return mFenceNVMap.query(handle);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001149}
1150
Jamie Madill2f348d22017-06-05 10:50:59 -04001151Query *Context::getQuery(GLuint handle, bool create, GLenum type)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001152{
Jamie Madill96a483b2017-06-27 16:49:21 -04001153 if (!mQueryMap.contains(handle))
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001154 {
Yunchao Hef81ce4a2017-04-24 10:49:17 +08001155 return nullptr;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001156 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001157
1158 Query *query = mQueryMap.query(handle);
1159 if (!query && create)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001160 {
Jamie Madill96a483b2017-06-27 16:49:21 -04001161 query = new Query(mImplementation->createQuery(type), handle);
1162 query->addRef();
1163 mQueryMap.assign(handle, query);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001164 }
Jamie Madill96a483b2017-06-27 16:49:21 -04001165 return query;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001166}
1167
Geoff Lang70d0f492015-12-10 17:45:46 -05001168Query *Context::getQuery(GLuint handle) const
1169{
Jamie Madill96a483b2017-06-27 16:49:21 -04001170 return mQueryMap.query(handle);
Geoff Lang70d0f492015-12-10 17:45:46 -05001171}
1172
Jamie Madill1fc7e2c2014-01-21 16:47:10 -05001173Texture *Context::getTargetTexture(GLenum target) const
1174{
Ian Ewellbda75592016-04-18 17:25:54 -04001175 ASSERT(ValidTextureTarget(this, target) || ValidTextureExternalTarget(this, target));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001176 return mGLState.getTargetTexture(target);
shannon.woods%transgaming.com@gtempaccount.comc926e5f2013-04-13 03:39:18 +00001177}
1178
Geoff Lang76b10c92014-09-05 16:28:14 -04001179Texture *Context::getSamplerTexture(unsigned int sampler, GLenum type) const
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001180{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001181 return mGLState.getSamplerTexture(sampler, type);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001182}
1183
Geoff Lang492a7e42014-11-05 13:27:06 -05001184Compiler *Context::getCompiler() const
1185{
Jamie Madill2f348d22017-06-05 10:50:59 -04001186 if (mCompiler.get() == nullptr)
1187 {
Jamie Madill4928b7c2017-06-20 12:57:39 -04001188 mCompiler.set(this, new Compiler(mImplementation.get(), mState));
Jamie Madill2f348d22017-06-05 10:50:59 -04001189 }
1190 return mCompiler.get();
Geoff Lang492a7e42014-11-05 13:27:06 -05001191}
1192
Jamie Madillc1d770e2017-04-13 17:31:24 -04001193void Context::getBooleanvImpl(GLenum pname, GLboolean *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001194{
1195 switch (pname)
1196 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001197 case GL_SHADER_COMPILER:
1198 *params = GL_TRUE;
1199 break;
1200 case GL_CONTEXT_ROBUST_ACCESS_EXT:
1201 *params = mRobustAccess ? GL_TRUE : GL_FALSE;
1202 break;
1203 default:
1204 mGLState.getBooleanv(pname, params);
1205 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001206 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001207}
1208
Jamie Madillc1d770e2017-04-13 17:31:24 -04001209void Context::getFloatvImpl(GLenum pname, GLfloat *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001210{
Shannon Woods53a94a82014-06-24 15:20:36 -04001211 // Queries about context capabilities and maximums are answered by Context.
1212 // Queries about current GL state values are answered by State.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001213 switch (pname)
1214 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001215 case GL_ALIASED_LINE_WIDTH_RANGE:
1216 params[0] = mCaps.minAliasedLineWidth;
1217 params[1] = mCaps.maxAliasedLineWidth;
1218 break;
1219 case GL_ALIASED_POINT_SIZE_RANGE:
1220 params[0] = mCaps.minAliasedPointSize;
1221 params[1] = mCaps.maxAliasedPointSize;
1222 break;
1223 case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT:
1224 ASSERT(mExtensions.textureFilterAnisotropic);
1225 *params = mExtensions.maxTextureAnisotropy;
1226 break;
1227 case GL_MAX_TEXTURE_LOD_BIAS:
1228 *params = mCaps.maxLODBias;
1229 break;
1230
1231 case GL_PATH_MODELVIEW_MATRIX_CHROMIUM:
1232 case GL_PATH_PROJECTION_MATRIX_CHROMIUM:
1233 {
1234 ASSERT(mExtensions.pathRendering);
1235 const GLfloat *m = mGLState.getPathRenderingMatrix(pname);
1236 memcpy(params, m, 16 * sizeof(GLfloat));
1237 }
Geoff Lange6d4e122015-06-29 13:33:55 -04001238 break;
Sami Väisänene45e53b2016-05-25 10:36:04 +03001239
Jamie Madill231c7f52017-04-26 13:45:37 -04001240 default:
1241 mGLState.getFloatv(pname, params);
1242 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001243 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001244}
1245
Jamie Madillc1d770e2017-04-13 17:31:24 -04001246void Context::getIntegervImpl(GLenum pname, GLint *params)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001247{
Shannon Woods53a94a82014-06-24 15:20:36 -04001248 // Queries about context capabilities and maximums are answered by Context.
1249 // Queries about current GL state values are answered by State.
shannon.woods%transgaming.com@gtempaccount.combc373e52013-04-13 03:31:23 +00001250
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001251 switch (pname)
1252 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001253 case GL_MAX_VERTEX_ATTRIBS:
1254 *params = mCaps.maxVertexAttributes;
1255 break;
1256 case GL_MAX_VERTEX_UNIFORM_VECTORS:
1257 *params = mCaps.maxVertexUniformVectors;
1258 break;
1259 case GL_MAX_VERTEX_UNIFORM_COMPONENTS:
1260 *params = mCaps.maxVertexUniformComponents;
1261 break;
1262 case GL_MAX_VARYING_VECTORS:
1263 *params = mCaps.maxVaryingVectors;
1264 break;
1265 case GL_MAX_VARYING_COMPONENTS:
1266 *params = mCaps.maxVertexOutputComponents;
1267 break;
1268 case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS:
1269 *params = mCaps.maxCombinedTextureImageUnits;
1270 break;
1271 case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS:
1272 *params = mCaps.maxVertexTextureImageUnits;
1273 break;
1274 case GL_MAX_TEXTURE_IMAGE_UNITS:
1275 *params = mCaps.maxTextureImageUnits;
1276 break;
1277 case GL_MAX_FRAGMENT_UNIFORM_VECTORS:
1278 *params = mCaps.maxFragmentUniformVectors;
1279 break;
1280 case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS:
1281 *params = mCaps.maxFragmentUniformComponents;
1282 break;
1283 case GL_MAX_RENDERBUFFER_SIZE:
1284 *params = mCaps.maxRenderbufferSize;
1285 break;
1286 case GL_MAX_COLOR_ATTACHMENTS_EXT:
1287 *params = mCaps.maxColorAttachments;
1288 break;
1289 case GL_MAX_DRAW_BUFFERS_EXT:
1290 *params = mCaps.maxDrawBuffers;
1291 break;
1292 // case GL_FRAMEBUFFER_BINDING: // now equivalent to
1293 // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE
1294 case GL_SUBPIXEL_BITS:
1295 *params = 4;
1296 break;
1297 case GL_MAX_TEXTURE_SIZE:
1298 *params = mCaps.max2DTextureSize;
1299 break;
Corentin Wallez13c0dd42017-07-04 18:27:01 -04001300 case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE:
1301 *params = mCaps.maxRectangleTextureSize;
1302 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001303 case GL_MAX_CUBE_MAP_TEXTURE_SIZE:
1304 *params = mCaps.maxCubeMapTextureSize;
1305 break;
1306 case GL_MAX_3D_TEXTURE_SIZE:
1307 *params = mCaps.max3DTextureSize;
1308 break;
1309 case GL_MAX_ARRAY_TEXTURE_LAYERS:
1310 *params = mCaps.maxArrayTextureLayers;
1311 break;
1312 case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT:
1313 *params = mCaps.uniformBufferOffsetAlignment;
1314 break;
1315 case GL_MAX_UNIFORM_BUFFER_BINDINGS:
1316 *params = mCaps.maxUniformBufferBindings;
1317 break;
1318 case GL_MAX_VERTEX_UNIFORM_BLOCKS:
1319 *params = mCaps.maxVertexUniformBlocks;
1320 break;
1321 case GL_MAX_FRAGMENT_UNIFORM_BLOCKS:
1322 *params = mCaps.maxFragmentUniformBlocks;
1323 break;
1324 case GL_MAX_COMBINED_UNIFORM_BLOCKS:
1325 *params = mCaps.maxCombinedTextureImageUnits;
1326 break;
1327 case GL_MAX_VERTEX_OUTPUT_COMPONENTS:
1328 *params = mCaps.maxVertexOutputComponents;
1329 break;
1330 case GL_MAX_FRAGMENT_INPUT_COMPONENTS:
1331 *params = mCaps.maxFragmentInputComponents;
1332 break;
1333 case GL_MIN_PROGRAM_TEXEL_OFFSET:
1334 *params = mCaps.minProgramTexelOffset;
1335 break;
1336 case GL_MAX_PROGRAM_TEXEL_OFFSET:
1337 *params = mCaps.maxProgramTexelOffset;
1338 break;
1339 case GL_MAJOR_VERSION:
1340 *params = getClientVersion().major;
1341 break;
1342 case GL_MINOR_VERSION:
1343 *params = getClientVersion().minor;
1344 break;
1345 case GL_MAX_ELEMENTS_INDICES:
1346 *params = mCaps.maxElementsIndices;
1347 break;
1348 case GL_MAX_ELEMENTS_VERTICES:
1349 *params = mCaps.maxElementsVertices;
1350 break;
1351 case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS:
1352 *params = mCaps.maxTransformFeedbackInterleavedComponents;
1353 break;
1354 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS:
1355 *params = mCaps.maxTransformFeedbackSeparateAttributes;
1356 break;
1357 case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS:
1358 *params = mCaps.maxTransformFeedbackSeparateComponents;
1359 break;
1360 case GL_NUM_COMPRESSED_TEXTURE_FORMATS:
1361 *params = static_cast<GLint>(mCaps.compressedTextureFormats.size());
1362 break;
1363 case GL_MAX_SAMPLES_ANGLE:
1364 *params = mCaps.maxSamples;
1365 break;
1366 case GL_MAX_VIEWPORT_DIMS:
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001367 {
Geoff Langc0b9ef42014-07-02 10:02:37 -04001368 params[0] = mCaps.maxViewportWidth;
1369 params[1] = mCaps.maxViewportHeight;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001370 }
1371 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001372 case GL_COMPRESSED_TEXTURE_FORMATS:
1373 std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(),
1374 params);
1375 break;
1376 case GL_RESET_NOTIFICATION_STRATEGY_EXT:
1377 *params = mResetStrategy;
1378 break;
1379 case GL_NUM_SHADER_BINARY_FORMATS:
1380 *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size());
1381 break;
1382 case GL_SHADER_BINARY_FORMATS:
1383 std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params);
1384 break;
1385 case GL_NUM_PROGRAM_BINARY_FORMATS:
1386 *params = static_cast<GLint>(mCaps.programBinaryFormats.size());
1387 break;
1388 case GL_PROGRAM_BINARY_FORMATS:
1389 std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params);
1390 break;
1391 case GL_NUM_EXTENSIONS:
1392 *params = static_cast<GLint>(mExtensionStrings.size());
1393 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001394
Jamie Madill231c7f52017-04-26 13:45:37 -04001395 // GL_KHR_debug
1396 case GL_MAX_DEBUG_MESSAGE_LENGTH:
1397 *params = mExtensions.maxDebugMessageLength;
1398 break;
1399 case GL_MAX_DEBUG_LOGGED_MESSAGES:
1400 *params = mExtensions.maxDebugLoggedMessages;
1401 break;
1402 case GL_MAX_DEBUG_GROUP_STACK_DEPTH:
1403 *params = mExtensions.maxDebugGroupStackDepth;
1404 break;
1405 case GL_MAX_LABEL_LENGTH:
1406 *params = mExtensions.maxLabelLength;
1407 break;
Geoff Lang70d0f492015-12-10 17:45:46 -05001408
Martin Radeve5285d22017-07-14 16:23:53 +03001409 // GL_ANGLE_multiview
1410 case GL_MAX_VIEWS_ANGLE:
1411 *params = mExtensions.maxViews;
1412 break;
1413
Jamie Madill231c7f52017-04-26 13:45:37 -04001414 // GL_EXT_disjoint_timer_query
1415 case GL_GPU_DISJOINT_EXT:
1416 *params = mImplementation->getGPUDisjoint();
1417 break;
1418 case GL_MAX_FRAMEBUFFER_WIDTH:
1419 *params = mCaps.maxFramebufferWidth;
1420 break;
1421 case GL_MAX_FRAMEBUFFER_HEIGHT:
1422 *params = mCaps.maxFramebufferHeight;
1423 break;
1424 case GL_MAX_FRAMEBUFFER_SAMPLES:
1425 *params = mCaps.maxFramebufferSamples;
1426 break;
1427 case GL_MAX_SAMPLE_MASK_WORDS:
1428 *params = mCaps.maxSampleMaskWords;
1429 break;
1430 case GL_MAX_COLOR_TEXTURE_SAMPLES:
1431 *params = mCaps.maxColorTextureSamples;
1432 break;
1433 case GL_MAX_DEPTH_TEXTURE_SAMPLES:
1434 *params = mCaps.maxDepthTextureSamples;
1435 break;
1436 case GL_MAX_INTEGER_SAMPLES:
1437 *params = mCaps.maxIntegerSamples;
1438 break;
1439 case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET:
1440 *params = mCaps.maxVertexAttribRelativeOffset;
1441 break;
1442 case GL_MAX_VERTEX_ATTRIB_BINDINGS:
1443 *params = mCaps.maxVertexAttribBindings;
1444 break;
1445 case GL_MAX_VERTEX_ATTRIB_STRIDE:
1446 *params = mCaps.maxVertexAttribStride;
1447 break;
1448 case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS:
1449 *params = mCaps.maxVertexAtomicCounterBuffers;
1450 break;
1451 case GL_MAX_VERTEX_ATOMIC_COUNTERS:
1452 *params = mCaps.maxVertexAtomicCounters;
1453 break;
1454 case GL_MAX_VERTEX_IMAGE_UNIFORMS:
1455 *params = mCaps.maxVertexImageUniforms;
1456 break;
1457 case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS:
1458 *params = mCaps.maxVertexShaderStorageBlocks;
1459 break;
1460 case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS:
1461 *params = mCaps.maxFragmentAtomicCounterBuffers;
1462 break;
1463 case GL_MAX_FRAGMENT_ATOMIC_COUNTERS:
1464 *params = mCaps.maxFragmentAtomicCounters;
1465 break;
1466 case GL_MAX_FRAGMENT_IMAGE_UNIFORMS:
1467 *params = mCaps.maxFragmentImageUniforms;
1468 break;
1469 case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS:
1470 *params = mCaps.maxFragmentShaderStorageBlocks;
1471 break;
1472 case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET:
1473 *params = mCaps.minProgramTextureGatherOffset;
1474 break;
1475 case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET:
1476 *params = mCaps.maxProgramTextureGatherOffset;
1477 break;
1478 case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS:
1479 *params = mCaps.maxComputeWorkGroupInvocations;
1480 break;
1481 case GL_MAX_COMPUTE_UNIFORM_BLOCKS:
1482 *params = mCaps.maxComputeUniformBlocks;
1483 break;
1484 case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS:
1485 *params = mCaps.maxComputeTextureImageUnits;
1486 break;
1487 case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE:
1488 *params = mCaps.maxComputeSharedMemorySize;
1489 break;
1490 case GL_MAX_COMPUTE_UNIFORM_COMPONENTS:
1491 *params = mCaps.maxComputeUniformComponents;
1492 break;
1493 case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS:
1494 *params = mCaps.maxComputeAtomicCounterBuffers;
1495 break;
1496 case GL_MAX_COMPUTE_ATOMIC_COUNTERS:
1497 *params = mCaps.maxComputeAtomicCounters;
1498 break;
1499 case GL_MAX_COMPUTE_IMAGE_UNIFORMS:
1500 *params = mCaps.maxComputeImageUniforms;
1501 break;
1502 case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS:
1503 *params = mCaps.maxCombinedComputeUniformComponents;
1504 break;
1505 case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS:
1506 *params = mCaps.maxComputeShaderStorageBlocks;
1507 break;
1508 case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES:
1509 *params = mCaps.maxCombinedShaderOutputResources;
1510 break;
1511 case GL_MAX_UNIFORM_LOCATIONS:
1512 *params = mCaps.maxUniformLocations;
1513 break;
1514 case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS:
1515 *params = mCaps.maxAtomicCounterBufferBindings;
1516 break;
1517 case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE:
1518 *params = mCaps.maxAtomicCounterBufferSize;
1519 break;
1520 case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS:
1521 *params = mCaps.maxCombinedAtomicCounterBuffers;
1522 break;
1523 case GL_MAX_COMBINED_ATOMIC_COUNTERS:
1524 *params = mCaps.maxCombinedAtomicCounters;
1525 break;
1526 case GL_MAX_IMAGE_UNITS:
1527 *params = mCaps.maxImageUnits;
1528 break;
1529 case GL_MAX_COMBINED_IMAGE_UNIFORMS:
1530 *params = mCaps.maxCombinedImageUniforms;
1531 break;
1532 case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS:
1533 *params = mCaps.maxShaderStorageBufferBindings;
1534 break;
1535 case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS:
1536 *params = mCaps.maxCombinedShaderStorageBlocks;
1537 break;
1538 case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT:
1539 *params = mCaps.shaderStorageBufferOffsetAlignment;
1540 break;
Jiawei Shao361df072017-11-22 09:33:59 +08001541
1542 // GL_EXT_geometry_shader
1543 case GL_MAX_FRAMEBUFFER_LAYERS_EXT:
1544 *params = mCaps.maxFramebufferLayers;
1545 break;
1546 case GL_LAYER_PROVOKING_VERTEX_EXT:
1547 *params = mCaps.layerProvokingVertex;
1548 break;
1549 case GL_MAX_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1550 *params = mCaps.maxGeometryUniformComponents;
1551 break;
1552 case GL_MAX_GEOMETRY_UNIFORM_BLOCKS_EXT:
1553 *params = mCaps.maxGeometryUniformBlocks;
1554 break;
1555 case GL_MAX_COMBINED_GEOMETRY_UNIFORM_COMPONENTS_EXT:
1556 *params = mCaps.maxCombinedGeometryUniformComponents;
1557 break;
1558 case GL_MAX_GEOMETRY_INPUT_COMPONENTS_EXT:
1559 *params = mCaps.maxGeometryInputComponents;
1560 break;
1561 case GL_MAX_GEOMETRY_OUTPUT_COMPONENTS_EXT:
1562 *params = mCaps.maxGeometryOutputComponents;
1563 break;
1564 case GL_MAX_GEOMETRY_OUTPUT_VERTICES_EXT:
1565 *params = mCaps.maxGeometryOutputVertices;
1566 break;
1567 case GL_MAX_GEOMETRY_TOTAL_OUTPUT_COMPONENTS_EXT:
1568 *params = mCaps.maxGeometryTotalOutputComponents;
1569 break;
1570 case GL_MAX_GEOMETRY_SHADER_INVOCATIONS_EXT:
1571 *params = mCaps.maxGeometryShaderInvocations;
1572 break;
1573 case GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS_EXT:
1574 *params = mCaps.maxGeometryTextureImageUnits;
1575 break;
1576 case GL_MAX_GEOMETRY_ATOMIC_COUNTER_BUFFERS_EXT:
1577 *params = mCaps.maxGeometryAtomicCounterBuffers;
1578 break;
1579 case GL_MAX_GEOMETRY_ATOMIC_COUNTERS_EXT:
1580 *params = mCaps.maxGeometryAtomicCounters;
1581 break;
1582 case GL_MAX_GEOMETRY_IMAGE_UNIFORMS_EXT:
1583 *params = mCaps.maxGeometryImageUniforms;
1584 break;
1585 case GL_MAX_GEOMETRY_SHADER_STORAGE_BLOCKS_EXT:
1586 *params = mCaps.maxGeometryShaderStorageBlocks;
1587 break;
Jamie Madill231c7f52017-04-26 13:45:37 -04001588 default:
1589 mGLState.getIntegerv(this, pname, params);
1590 break;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001591 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001592}
1593
Jamie Madill7f0c5a42017-08-26 22:43:26 -04001594void Context::getInteger64vImpl(GLenum pname, GLint64 *params)
Jamie Madill0fda9862013-07-19 16:36:55 -04001595{
Shannon Woods53a94a82014-06-24 15:20:36 -04001596 // Queries about context capabilities and maximums are answered by Context.
1597 // Queries about current GL state values are answered by State.
Jamie Madill0fda9862013-07-19 16:36:55 -04001598 switch (pname)
1599 {
Jamie Madill231c7f52017-04-26 13:45:37 -04001600 case GL_MAX_ELEMENT_INDEX:
1601 *params = mCaps.maxElementIndex;
1602 break;
1603 case GL_MAX_UNIFORM_BLOCK_SIZE:
1604 *params = mCaps.maxUniformBlockSize;
1605 break;
1606 case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS:
1607 *params = mCaps.maxCombinedVertexUniformComponents;
1608 break;
1609 case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS:
1610 *params = mCaps.maxCombinedFragmentUniformComponents;
1611 break;
1612 case GL_MAX_SERVER_WAIT_TIMEOUT:
1613 *params = mCaps.maxServerWaitTimeout;
1614 break;
Ian Ewell53f59f42016-01-28 17:36:55 -05001615
Jamie Madill231c7f52017-04-26 13:45:37 -04001616 // GL_EXT_disjoint_timer_query
1617 case GL_TIMESTAMP_EXT:
1618 *params = mImplementation->getTimestamp();
1619 break;
Martin Radev66fb8202016-07-28 11:45:20 +03001620
Jamie Madill231c7f52017-04-26 13:45:37 -04001621 case GL_MAX_SHADER_STORAGE_BLOCK_SIZE:
1622 *params = mCaps.maxShaderStorageBlockSize;
1623 break;
1624 default:
1625 UNREACHABLE();
1626 break;
Jamie Madill0fda9862013-07-19 16:36:55 -04001627 }
Jamie Madill0fda9862013-07-19 16:36:55 -04001628}
1629
Geoff Lang70d0f492015-12-10 17:45:46 -05001630void Context::getPointerv(GLenum pname, void **params) const
1631{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001632 mGLState.getPointerv(pname, params);
Geoff Lang70d0f492015-12-10 17:45:46 -05001633}
1634
Martin Radev66fb8202016-07-28 11:45:20 +03001635void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001636{
Shannon Woods53a94a82014-06-24 15:20:36 -04001637 // Queries about context capabilities and maximums are answered by Context.
1638 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001639
1640 GLenum nativeType;
1641 unsigned int numParams;
1642 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1643 ASSERT(queryStatus);
1644
1645 if (nativeType == GL_INT)
1646 {
1647 switch (target)
1648 {
1649 case GL_MAX_COMPUTE_WORK_GROUP_COUNT:
1650 ASSERT(index < 3u);
1651 *data = mCaps.maxComputeWorkGroupCount[index];
1652 break;
1653 case GL_MAX_COMPUTE_WORK_GROUP_SIZE:
1654 ASSERT(index < 3u);
1655 *data = mCaps.maxComputeWorkGroupSize[index];
1656 break;
1657 default:
1658 mGLState.getIntegeri_v(target, index, data);
1659 }
1660 }
1661 else
1662 {
1663 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1664 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001665}
1666
Martin Radev66fb8202016-07-28 11:45:20 +03001667void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data)
Shannon Woods1b2fb852013-08-19 14:28:48 -04001668{
Shannon Woods53a94a82014-06-24 15:20:36 -04001669 // Queries about context capabilities and maximums are answered by Context.
1670 // Queries about current GL state values are answered by State.
Martin Radev66fb8202016-07-28 11:45:20 +03001671
1672 GLenum nativeType;
1673 unsigned int numParams;
1674 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1675 ASSERT(queryStatus);
1676
1677 if (nativeType == GL_INT_64_ANGLEX)
1678 {
1679 mGLState.getInteger64i_v(target, index, data);
1680 }
1681 else
1682 {
1683 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1684 }
1685}
1686
1687void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data)
1688{
1689 // Queries about context capabilities and maximums are answered by Context.
1690 // Queries about current GL state values are answered by State.
1691
1692 GLenum nativeType;
1693 unsigned int numParams;
1694 bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams);
1695 ASSERT(queryStatus);
1696
1697 if (nativeType == GL_BOOL)
1698 {
1699 mGLState.getBooleani_v(target, index, data);
1700 }
1701 else
1702 {
1703 CastIndexedStateValues(this, nativeType, target, index, numParams, data);
1704 }
Shannon Woods1b2fb852013-08-19 14:28:48 -04001705}
1706
Corentin Wallez336129f2017-10-17 15:55:40 -04001707void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params)
He Yunchao010e4db2017-03-03 14:22:06 +08001708{
1709 Buffer *buffer = mGLState.getTargetBuffer(target);
1710 QueryBufferParameteriv(buffer, pname, params);
1711}
1712
1713void Context::getFramebufferAttachmentParameteriv(GLenum target,
1714 GLenum attachment,
1715 GLenum pname,
1716 GLint *params)
1717{
1718 const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08001719 QueryFramebufferAttachmentParameteriv(this, framebuffer, attachment, pname, params);
He Yunchao010e4db2017-03-03 14:22:06 +08001720}
1721
1722void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params)
1723{
1724 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
1725 QueryRenderbufferiv(this, renderbuffer, pname, params);
1726}
1727
1728void Context::getTexParameterfv(GLenum target, GLenum pname, GLfloat *params)
1729{
1730 Texture *texture = getTargetTexture(target);
1731 QueryTexParameterfv(texture, pname, params);
1732}
1733
1734void Context::getTexParameteriv(GLenum target, GLenum pname, GLint *params)
1735{
1736 Texture *texture = getTargetTexture(target);
1737 QueryTexParameteriv(texture, pname, params);
1738}
Jiajia Qin5451d532017-11-16 17:16:34 +08001739
1740void Context::getTexLevelParameteriv(GLenum target, GLint level, GLenum pname, GLint *params)
1741{
1742 Texture *texture =
1743 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
1744 QueryTexLevelParameteriv(texture, target, level, pname, params);
1745}
1746
1747void Context::getTexLevelParameterfv(GLenum target, GLint level, GLenum pname, GLfloat *params)
1748{
1749 Texture *texture =
1750 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
1751 QueryTexLevelParameterfv(texture, target, level, pname, params);
1752}
1753
He Yunchao010e4db2017-03-03 14:22:06 +08001754void Context::texParameterf(GLenum target, GLenum pname, GLfloat param)
1755{
1756 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001757 SetTexParameterf(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001758 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001759}
1760
1761void Context::texParameterfv(GLenum target, GLenum pname, const GLfloat *params)
1762{
1763 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001764 SetTexParameterfv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001765 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001766}
1767
1768void Context::texParameteri(GLenum target, GLenum pname, GLint param)
1769{
1770 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001771 SetTexParameteri(this, texture, pname, param);
Jamie Madill81c2e252017-09-09 23:32:46 -04001772 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001773}
1774
1775void Context::texParameteriv(GLenum target, GLenum pname, const GLint *params)
1776{
1777 Texture *texture = getTargetTexture(target);
Jamie Madill4928b7c2017-06-20 12:57:39 -04001778 SetTexParameteriv(this, texture, pname, params);
Jamie Madill81c2e252017-09-09 23:32:46 -04001779 onTextureChange(texture);
He Yunchao010e4db2017-03-03 14:22:06 +08001780}
1781
Jamie Madill675fe712016-12-19 13:07:54 -05001782void Context::drawArrays(GLenum mode, GLint first, GLsizei count)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001783{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001784 // No-op if zero count
1785 if (count == 0)
1786 {
1787 return;
1788 }
1789
Jamie Madill05b35b22017-10-03 09:01:44 -04001790 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001791 ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count));
1792 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001793}
1794
Jamie Madill675fe712016-12-19 13:07:54 -05001795void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount)
Geoff Langf6db0982015-08-25 13:04:00 -04001796{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001797 // No-op if zero count
1798 if (count == 0 || instanceCount == 0)
1799 {
1800 return;
1801 }
1802
Jamie Madill05b35b22017-10-03 09:01:44 -04001803 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001804 ANGLE_CONTEXT_TRY(
1805 mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount));
1806 MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback());
Geoff Langf6db0982015-08-25 13:04:00 -04001807}
1808
Jamie Madill876429b2017-04-20 15:46:24 -04001809void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001810{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001811 // No-op if zero count
1812 if (count == 0)
1813 {
1814 return;
1815 }
1816
Jamie Madill05b35b22017-10-03 09:01:44 -04001817 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001818 ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices));
Geoff Langf6db0982015-08-25 13:04:00 -04001819}
1820
Jamie Madill675fe712016-12-19 13:07:54 -05001821void Context::drawElementsInstanced(GLenum mode,
1822 GLsizei count,
1823 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001824 const void *indices,
Jamie Madill9c9b40a2017-04-26 16:31:57 -04001825 GLsizei instances)
Geoff Langf6db0982015-08-25 13:04:00 -04001826{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001827 // No-op if zero count
1828 if (count == 0 || instances == 0)
1829 {
1830 return;
1831 }
1832
Jamie Madill05b35b22017-10-03 09:01:44 -04001833 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001834 ANGLE_CONTEXT_TRY(
Qin Jiajia1da00652017-06-20 17:16:25 +08001835 mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances));
Geoff Langf6db0982015-08-25 13:04:00 -04001836}
1837
Jamie Madill675fe712016-12-19 13:07:54 -05001838void Context::drawRangeElements(GLenum mode,
1839 GLuint start,
1840 GLuint end,
1841 GLsizei count,
1842 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04001843 const void *indices)
Geoff Langf6db0982015-08-25 13:04:00 -04001844{
Jamie Madill9fdaa492018-02-16 10:52:11 -05001845 // No-op if zero count
1846 if (count == 0)
1847 {
1848 return;
1849 }
1850
Jamie Madill05b35b22017-10-03 09:01:44 -04001851 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001852 ANGLE_CONTEXT_TRY(
1853 mImplementation->drawRangeElements(this, mode, start, end, count, type, indices));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001854}
1855
Jamie Madill876429b2017-04-20 15:46:24 -04001856void Context::drawArraysIndirect(GLenum mode, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001857{
Jamie Madill05b35b22017-10-03 09:01:44 -04001858 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001859 ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001860}
1861
Jamie Madill876429b2017-04-20 15:46:24 -04001862void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect)
Jiajia Qind9671222016-11-29 16:30:31 +08001863{
Jamie Madill05b35b22017-10-03 09:01:44 -04001864 ANGLE_CONTEXT_TRY(prepareForDraw());
Jamie Madillb6664922017-07-25 12:55:04 -04001865 ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect));
Jiajia Qind9671222016-11-29 16:30:31 +08001866}
1867
Jamie Madill675fe712016-12-19 13:07:54 -05001868void Context::flush()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001869{
Jamie Madillafa02a22017-11-23 12:57:38 -05001870 handleError(mImplementation->flush(this));
Geoff Lang129753a2015-01-09 16:52:09 -05001871}
1872
Jamie Madill675fe712016-12-19 13:07:54 -05001873void Context::finish()
Geoff Lang129753a2015-01-09 16:52:09 -05001874{
Jamie Madillafa02a22017-11-23 12:57:38 -05001875 handleError(mImplementation->finish(this));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00001876}
1877
Austin Kinross6ee1e782015-05-29 17:05:37 -07001878void Context::insertEventMarker(GLsizei length, const char *marker)
1879{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001880 ASSERT(mImplementation);
1881 mImplementation->insertEventMarker(length, marker);
Austin Kinross6ee1e782015-05-29 17:05:37 -07001882}
1883
1884void Context::pushGroupMarker(GLsizei length, const char *marker)
1885{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001886 ASSERT(mImplementation);
Jamie Madill007530e2017-12-28 14:27:04 -05001887
1888 if (marker == nullptr)
1889 {
1890 // From the EXT_debug_marker spec,
1891 // "If <marker> is null then an empty string is pushed on the stack."
1892 mImplementation->pushGroupMarker(length, "");
1893 }
1894 else
1895 {
1896 mImplementation->pushGroupMarker(length, marker);
1897 }
Austin Kinross6ee1e782015-05-29 17:05:37 -07001898}
1899
1900void Context::popGroupMarker()
1901{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04001902 ASSERT(mImplementation);
1903 mImplementation->popGroupMarker();
Austin Kinross6ee1e782015-05-29 17:05:37 -07001904}
1905
Geoff Langd8605522016-04-13 10:19:12 -04001906void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name)
1907{
1908 Program *programObject = getProgram(program);
1909 ASSERT(programObject);
1910
1911 programObject->bindUniformLocation(location, name);
1912}
1913
Sami Väisänena797e062016-05-12 15:23:40 +03001914void Context::setCoverageModulation(GLenum components)
1915{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07001916 mGLState.setCoverageModulation(components);
Sami Väisänena797e062016-05-12 15:23:40 +03001917}
1918
Sami Väisänene45e53b2016-05-25 10:36:04 +03001919void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix)
1920{
1921 mGLState.loadPathRenderingMatrix(matrixMode, matrix);
1922}
1923
1924void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode)
1925{
1926 GLfloat I[16];
1927 angle::Matrix<GLfloat>::setToIdentity(I);
1928
1929 mGLState.loadPathRenderingMatrix(matrixMode, I);
1930}
1931
1932void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask)
1933{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001934 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001935 if (!pathObj)
1936 return;
1937
1938 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1939 syncRendererState();
1940
1941 mImplementation->stencilFillPath(pathObj, fillMode, mask);
1942}
1943
1944void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask)
1945{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001946 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001947 if (!pathObj)
1948 return;
1949
1950 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1951 syncRendererState();
1952
1953 mImplementation->stencilStrokePath(pathObj, reference, mask);
1954}
1955
1956void Context::coverFillPath(GLuint path, GLenum coverMode)
1957{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001958 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001959 if (!pathObj)
1960 return;
1961
1962 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1963 syncRendererState();
1964
1965 mImplementation->coverFillPath(pathObj, coverMode);
1966}
1967
1968void Context::coverStrokePath(GLuint path, GLenum coverMode)
1969{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001970 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001971 if (!pathObj)
1972 return;
1973
1974 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1975 syncRendererState();
1976
1977 mImplementation->coverStrokePath(pathObj, coverMode);
1978}
1979
1980void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode)
1981{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001982 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001983 if (!pathObj)
1984 return;
1985
1986 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
1987 syncRendererState();
1988
1989 mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode);
1990}
1991
1992void Context::stencilThenCoverStrokePath(GLuint path,
1993 GLint reference,
1994 GLuint mask,
1995 GLenum coverMode)
1996{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05001997 const auto *pathObj = mState.mPaths->getPath(path);
Sami Väisänene45e53b2016-05-25 10:36:04 +03001998 if (!pathObj)
1999 return;
2000
2001 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2002 syncRendererState();
2003
2004 mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode);
2005}
2006
Sami Väisänend59ca052016-06-21 16:10:00 +03002007void Context::coverFillPathInstanced(GLsizei numPaths,
2008 GLenum pathNameType,
2009 const void *paths,
2010 GLuint pathBase,
2011 GLenum coverMode,
2012 GLenum transformType,
2013 const GLfloat *transformValues)
2014{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002015 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002016
2017 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2018 syncRendererState();
2019
2020 mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues);
2021}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002022
Sami Väisänend59ca052016-06-21 16:10:00 +03002023void Context::coverStrokePathInstanced(GLsizei numPaths,
2024 GLenum pathNameType,
2025 const void *paths,
2026 GLuint pathBase,
2027 GLenum coverMode,
2028 GLenum transformType,
2029 const GLfloat *transformValues)
2030{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002031 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002032
2033 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2034 syncRendererState();
2035
2036 mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType,
2037 transformValues);
2038}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002039
Sami Väisänend59ca052016-06-21 16:10:00 +03002040void Context::stencilFillPathInstanced(GLsizei numPaths,
2041 GLenum pathNameType,
2042 const void *paths,
2043 GLuint pathBase,
2044 GLenum fillMode,
2045 GLuint mask,
2046 GLenum transformType,
2047 const GLfloat *transformValues)
2048{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002049 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002050
2051 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2052 syncRendererState();
2053
2054 mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType,
2055 transformValues);
2056}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002057
Sami Väisänend59ca052016-06-21 16:10:00 +03002058void Context::stencilStrokePathInstanced(GLsizei numPaths,
2059 GLenum pathNameType,
2060 const void *paths,
2061 GLuint pathBase,
2062 GLint reference,
2063 GLuint mask,
2064 GLenum transformType,
2065 const GLfloat *transformValues)
2066{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002067 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002068
2069 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2070 syncRendererState();
2071
2072 mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType,
2073 transformValues);
2074}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002075
Sami Väisänend59ca052016-06-21 16:10:00 +03002076void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths,
2077 GLenum pathNameType,
2078 const void *paths,
2079 GLuint pathBase,
2080 GLenum fillMode,
2081 GLuint mask,
2082 GLenum coverMode,
2083 GLenum transformType,
2084 const GLfloat *transformValues)
2085{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002086 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002087
2088 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2089 syncRendererState();
2090
2091 mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask,
2092 transformType, transformValues);
2093}
Sami Väisänen46eaa942016-06-29 10:26:37 +03002094
Sami Väisänend59ca052016-06-21 16:10:00 +03002095void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths,
2096 GLenum pathNameType,
2097 const void *paths,
2098 GLuint pathBase,
2099 GLint reference,
2100 GLuint mask,
2101 GLenum coverMode,
2102 GLenum transformType,
2103 const GLfloat *transformValues)
2104{
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002105 const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase);
Sami Väisänend59ca052016-06-21 16:10:00 +03002106
2107 // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering?
2108 syncRendererState();
2109
2110 mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask,
2111 transformType, transformValues);
2112}
2113
Sami Väisänen46eaa942016-06-29 10:26:37 +03002114void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name)
2115{
2116 auto *programObject = getProgram(program);
2117
2118 programObject->bindFragmentInputLocation(location, name);
2119}
2120
2121void Context::programPathFragmentInputGen(GLuint program,
2122 GLint location,
2123 GLenum genMode,
2124 GLint components,
2125 const GLfloat *coeffs)
2126{
2127 auto *programObject = getProgram(program);
2128
Jamie Madillbd044ed2017-06-05 12:59:21 -04002129 programObject->pathFragmentInputGen(this, location, genMode, components, coeffs);
Sami Väisänen46eaa942016-06-29 10:26:37 +03002130}
2131
jchen1015015f72017-03-16 13:54:21 +08002132GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name)
2133{
jchen10fd7c3b52017-03-21 15:36:03 +08002134 const auto *programObject = getProgram(program);
jchen1015015f72017-03-16 13:54:21 +08002135 return QueryProgramResourceIndex(programObject, programInterface, name);
2136}
2137
jchen10fd7c3b52017-03-21 15:36:03 +08002138void Context::getProgramResourceName(GLuint program,
2139 GLenum programInterface,
2140 GLuint index,
2141 GLsizei bufSize,
2142 GLsizei *length,
2143 GLchar *name)
2144{
2145 const auto *programObject = getProgram(program);
2146 QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name);
2147}
2148
jchen10191381f2017-04-11 13:59:04 +08002149GLint Context::getProgramResourceLocation(GLuint program,
2150 GLenum programInterface,
2151 const GLchar *name)
2152{
2153 const auto *programObject = getProgram(program);
2154 return QueryProgramResourceLocation(programObject, programInterface, name);
2155}
2156
jchen10880683b2017-04-12 16:21:55 +08002157void Context::getProgramResourceiv(GLuint program,
2158 GLenum programInterface,
2159 GLuint index,
2160 GLsizei propCount,
2161 const GLenum *props,
2162 GLsizei bufSize,
2163 GLsizei *length,
2164 GLint *params)
2165{
2166 const auto *programObject = getProgram(program);
2167 QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize,
2168 length, params);
2169}
2170
jchen10d9cd7b72017-08-30 15:04:25 +08002171void Context::getProgramInterfaceiv(GLuint program,
2172 GLenum programInterface,
2173 GLenum pname,
2174 GLint *params)
2175{
2176 const auto *programObject = getProgram(program);
2177 QueryProgramInterfaceiv(programObject, programInterface, pname, params);
2178}
2179
Jamie Madill71c88b32017-09-14 22:20:29 -04002180void Context::handleError(const Error &error)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002181{
Geoff Langda5777c2014-07-11 09:52:58 -04002182 if (error.isError())
2183 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002184 GLenum code = error.getCode();
2185 mErrors.insert(code);
2186 if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory)
2187 {
2188 markContextLost();
2189 }
Geoff Lang70d0f492015-12-10 17:45:46 -05002190
Geoff Langee6884e2017-11-09 16:51:11 -05002191 ASSERT(!error.getMessage().empty());
2192 mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(),
2193 GL_DEBUG_SEVERITY_HIGH, error.getMessage());
Geoff Langda5777c2014-07-11 09:52:58 -04002194 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002195}
2196
2197// Get one of the recorded errors and clear its flag, if any.
2198// [OpenGL ES 2.0.24] section 2.5 page 13.
2199GLenum Context::getError()
2200{
Geoff Langda5777c2014-07-11 09:52:58 -04002201 if (mErrors.empty())
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002202 {
Geoff Langda5777c2014-07-11 09:52:58 -04002203 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002204 }
Geoff Langda5777c2014-07-11 09:52:58 -04002205 else
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002206 {
Geoff Langda5777c2014-07-11 09:52:58 -04002207 GLenum error = *mErrors.begin();
2208 mErrors.erase(mErrors.begin());
2209 return error;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002210 }
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002211}
2212
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002213// NOTE: this function should not assume that this context is current!
2214void Context::markContextLost()
2215{
2216 if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT)
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002217 {
Jamie Madill231c7f52017-04-26 13:45:37 -04002218 mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT;
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002219 mContextLostForced = true;
2220 }
Jamie Madill231c7f52017-04-26 13:45:37 -04002221 mContextLost = true;
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002222}
2223
2224bool Context::isContextLost()
2225{
2226 return mContextLost;
2227}
2228
Jamie Madillfa920eb2018-01-04 11:45:50 -05002229GLenum Context::getGraphicsResetStatus()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002230{
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002231 // Even if the application doesn't want to know about resets, we want to know
2232 // as it will allow us to skip all the calls.
2233 if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002234 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002235 if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR)
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002236 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002237 mContextLost = true;
Jamie Madill9dd0cf02014-11-24 11:38:51 -05002238 }
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002239
2240 // EXT_robustness, section 2.6: If the reset notification behavior is
2241 // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of
2242 // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR.
2243 return GL_NO_ERROR;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002244 }
2245
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002246 // The GL_EXT_robustness spec says that if a reset is encountered, a reset
2247 // status should be returned at least once, and GL_NO_ERROR should be returned
2248 // once the device has finished resetting.
2249 if (!mContextLost)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002250 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002251 ASSERT(mResetStatus == GL_NO_ERROR);
2252 mResetStatus = mImplementation->getResetStatus();
shannon.woods@transgaming.comddd6c802013-02-28 23:05:14 +00002253
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002254 if (mResetStatus != GL_NO_ERROR)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002255 {
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002256 mContextLost = true;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002257 }
2258 }
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002259 else if (!mContextLostForced && mResetStatus != GL_NO_ERROR)
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002260 {
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002261 // If markContextLost was used to mark the context lost then
2262 // assume that is not recoverable, and continue to report the
2263 // lost reset status for the lifetime of this context.
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002264 mResetStatus = mImplementation->getResetStatus();
2265 }
Jamie Madill893ab082014-05-16 16:56:10 -04002266
Corentin Wallez87fbe1c2016-08-03 14:41:42 -04002267 return mResetStatus;
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002268}
2269
2270bool Context::isResetNotificationEnabled()
2271{
2272 return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2273}
2274
Corentin Walleze3b10e82015-05-20 11:06:25 -04002275const egl::Config *Context::getConfig() const
Régis Fénéon83107972015-02-05 12:57:44 +01002276{
Corentin Walleze3b10e82015-05-20 11:06:25 -04002277 return mConfig;
Régis Fénéon83107972015-02-05 12:57:44 +01002278}
2279
2280EGLenum Context::getClientType() const
2281{
2282 return mClientType;
2283}
2284
2285EGLenum Context::getRenderBuffer() const
2286{
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002287 const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0);
2288 if (framebuffer == nullptr)
Corentin Wallez37c39792015-08-20 14:19:46 -04002289 {
2290 return EGL_NONE;
2291 }
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002292
Bryan Bernhart (Intel Americas Inc)2eeb1b32017-11-29 16:06:43 -08002293 const FramebufferAttachment *backAttachment = framebuffer->getAttachment(this, GL_BACK);
Geoff Lang3bf8e3a2016-12-01 17:28:52 -05002294 ASSERT(backAttachment != nullptr);
2295 return backAttachment->getSurface()->getRenderBuffer();
Régis Fénéon83107972015-02-05 12:57:44 +01002296}
2297
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002298VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002299{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002300 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002301 VertexArray *vertexArray = getVertexArray(vertexArrayHandle);
2302 if (!vertexArray)
Geoff Lang36167ab2015-12-07 10:27:14 -05002303 {
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002304 vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle,
2305 mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings);
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002306
Jamie Madill96a483b2017-06-27 16:49:21 -04002307 mVertexArrayMap.assign(vertexArrayHandle, vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002308 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002309
2310 return vertexArray;
Geoff Lang36167ab2015-12-07 10:27:14 -05002311}
2312
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002313TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle)
Geoff Lang36167ab2015-12-07 10:27:14 -05002314{
Jamie Madill5bf9ff42016-02-01 11:13:03 -05002315 // Only called after a prior call to Gen.
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002316 TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle);
2317 if (!transformFeedback)
Geoff Lang36167ab2015-12-07 10:27:14 -05002318 {
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002319 transformFeedback =
2320 new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps);
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002321 transformFeedback->addRef();
Jamie Madill96a483b2017-06-27 16:49:21 -04002322 mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002323 }
Jamie Madill3f01e6c2016-03-08 13:53:02 -05002324
2325 return transformFeedback;
Geoff Lang36167ab2015-12-07 10:27:14 -05002326}
2327
2328bool Context::isVertexArrayGenerated(GLuint vertexArray)
2329{
Jamie Madill96a483b2017-06-27 16:49:21 -04002330 ASSERT(mVertexArrayMap.contains(0));
2331 return mVertexArrayMap.contains(vertexArray);
Geoff Lang36167ab2015-12-07 10:27:14 -05002332}
2333
2334bool Context::isTransformFeedbackGenerated(GLuint transformFeedback)
2335{
Jamie Madill96a483b2017-06-27 16:49:21 -04002336 ASSERT(mTransformFeedbackMap.contains(0));
2337 return mTransformFeedbackMap.contains(transformFeedback);
Geoff Lang36167ab2015-12-07 10:27:14 -05002338}
2339
Shannon Woods53a94a82014-06-24 15:20:36 -04002340void Context::detachTexture(GLuint texture)
2341{
2342 // Simple pass-through to State's detachTexture method, as textures do not require
2343 // allocation map management either here or in the resource manager at detach time.
2344 // Zero textures are held by the Context, and we don't attempt to request them from
2345 // the State.
Jamie Madilla02315b2017-02-23 14:14:47 -05002346 mGLState.detachTexture(this, mZeroTextures, texture);
Shannon Woods53a94a82014-06-24 15:20:36 -04002347}
2348
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002349void Context::detachBuffer(GLuint buffer)
2350{
Yuly Novikov5807a532015-12-03 13:01:22 -05002351 // Simple pass-through to State's detachBuffer method, since
2352 // only buffer attachments to container objects that are bound to the current context
2353 // should be detached. And all those are available in State.
Shannon Woods53a94a82014-06-24 15:20:36 -04002354
Yuly Novikov5807a532015-12-03 13:01:22 -05002355 // [OpenGL ES 3.2] section 5.1.2 page 45:
2356 // Attachments to unbound container objects, such as
2357 // deletion of a buffer attached to a vertex array object which is not bound to the context,
2358 // are not affected and continue to act as references on the deleted object
Jamie Madill4928b7c2017-06-20 12:57:39 -04002359 mGLState.detachBuffer(this, buffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002360}
2361
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002362void Context::detachFramebuffer(GLuint framebuffer)
2363{
Shannon Woods53a94a82014-06-24 15:20:36 -04002364 // Framebuffer detachment is handled by Context, because 0 is a valid
2365 // Framebuffer object, and a pointer to it must be passed from Context
2366 // to State at binding time.
2367
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002368 // [OpenGL ES 2.0.24] section 4.4 page 107:
Jamie Madill231c7f52017-04-26 13:45:37 -04002369 // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as
2370 // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of
2371 // zero.
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002372
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002373 if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002374 {
2375 bindReadFramebuffer(0);
2376 }
2377
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002378 if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002379 {
2380 bindDrawFramebuffer(0);
2381 }
2382}
2383
2384void Context::detachRenderbuffer(GLuint renderbuffer)
2385{
Jamie Madilla02315b2017-02-23 14:14:47 -05002386 mGLState.detachRenderbuffer(this, renderbuffer);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002387}
2388
Jamie Madill57a89722013-07-02 11:57:03 -04002389void Context::detachVertexArray(GLuint vertexArray)
2390{
Jamie Madill77a72f62015-04-14 11:18:32 -04002391 // Vertex array detachment is handled by Context, because 0 is a valid
2392 // VAO, and a pointer to it must be passed from Context to State at
Shannon Woods53a94a82014-06-24 15:20:36 -04002393 // binding time.
2394
Jamie Madill57a89722013-07-02 11:57:03 -04002395 // [OpenGL ES 3.0.2] section 2.10 page 43:
2396 // If a vertex array object that is currently bound is deleted, the binding
2397 // for that object reverts to zero and the default vertex array becomes current.
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002398 if (mGLState.removeVertexArrayBinding(vertexArray))
Jamie Madill57a89722013-07-02 11:57:03 -04002399 {
2400 bindVertexArray(0);
2401 }
2402}
2403
Geoff Langc8058452014-02-03 12:04:11 -05002404void Context::detachTransformFeedback(GLuint transformFeedback)
2405{
Corentin Walleza2257da2016-04-19 16:43:12 -04002406 // Transform feedback detachment is handled by Context, because 0 is a valid
2407 // transform feedback, and a pointer to it must be passed from Context to State at
2408 // binding time.
2409
2410 // The OpenGL specification doesn't mention what should happen when the currently bound
2411 // transform feedback object is deleted. Since it is a container object, we treat it like
2412 // VAOs and FBOs and set the current bound transform feedback back to 0.
Jamie Madill4928b7c2017-06-20 12:57:39 -04002413 if (mGLState.removeTransformFeedbackBinding(this, transformFeedback))
Corentin Walleza2257da2016-04-19 16:43:12 -04002414 {
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04002415 bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0);
Corentin Walleza2257da2016-04-19 16:43:12 -04002416 }
Geoff Langc8058452014-02-03 12:04:11 -05002417}
2418
Jamie Madilldc356042013-07-19 16:36:57 -04002419void Context::detachSampler(GLuint sampler)
2420{
Jamie Madill4928b7c2017-06-20 12:57:39 -04002421 mGLState.detachSampler(this, sampler);
Jamie Madilldc356042013-07-19 16:36:57 -04002422}
2423
Yunchao Hea336b902017-08-02 16:05:21 +08002424void Context::detachProgramPipeline(GLuint pipeline)
2425{
2426 mGLState.detachProgramPipeline(this, pipeline);
2427}
2428
Jamie Madill3ef140a2017-08-26 23:11:21 -04002429void Context::vertexAttribDivisor(GLuint index, GLuint divisor)
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002430{
Shaodde78e82017-05-22 14:13:27 +08002431 mGLState.setVertexAttribDivisor(this, index, divisor);
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002432}
2433
Jamie Madille29d1672013-07-19 16:36:57 -04002434void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param)
2435{
Geoff Langc1984ed2016-10-07 12:41:00 -04002436 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002437 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002438 SetSamplerParameteri(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002439 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002440}
Jamie Madille29d1672013-07-19 16:36:57 -04002441
Geoff Langc1984ed2016-10-07 12:41:00 -04002442void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param)
2443{
2444 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002445 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002446 SetSamplerParameteriv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002447 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002448}
2449
2450void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param)
2451{
Geoff Langc1984ed2016-10-07 12:41:00 -04002452 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002453 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002454 SetSamplerParameterf(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002455 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madille29d1672013-07-19 16:36:57 -04002456}
2457
Geoff Langc1984ed2016-10-07 12:41:00 -04002458void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param)
Jamie Madill9675b802013-07-19 16:36:59 -04002459{
Geoff Langc1984ed2016-10-07 12:41:00 -04002460 Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002461 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002462 SetSamplerParameterfv(samplerObject, pname, param);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002463 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002464}
2465
Geoff Langc1984ed2016-10-07 12:41:00 -04002466void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params)
Jamie Madill9675b802013-07-19 16:36:59 -04002467{
Geoff Langc1984ed2016-10-07 12:41:00 -04002468 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002469 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002470 QuerySamplerParameteriv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002471 mGLState.setObjectDirty(GL_SAMPLER);
Geoff Langc1984ed2016-10-07 12:41:00 -04002472}
Jamie Madill9675b802013-07-19 16:36:59 -04002473
Geoff Langc1984ed2016-10-07 12:41:00 -04002474void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params)
2475{
2476 const Sampler *samplerObject =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05002477 mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler);
Geoff Langc1984ed2016-10-07 12:41:00 -04002478 QuerySamplerParameterfv(samplerObject, pname, params);
Jamie Madill06ef36b2017-09-09 23:32:46 -04002479 mGLState.setObjectDirty(GL_SAMPLER);
Jamie Madill9675b802013-07-19 16:36:59 -04002480}
2481
Olli Etuahof0fee072016-03-30 15:11:58 +03002482void Context::programParameteri(GLuint program, GLenum pname, GLint value)
2483{
2484 gl::Program *programObject = getProgram(program);
Yunchao He61afff12017-03-14 15:34:03 +08002485 SetProgramParameteri(programObject, pname, value);
Olli Etuahof0fee072016-03-30 15:11:58 +03002486}
2487
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002488void Context::initRendererString()
2489{
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002490 std::ostringstream rendererString;
2491 rendererString << "ANGLE (";
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002492 rendererString << mImplementation->getRendererDescription();
daniel@transgaming.comca1ac1f2013-01-11 04:13:05 +00002493 rendererString << ")";
2494
Geoff Langcec35902014-04-16 10:52:36 -04002495 mRendererString = MakeStaticString(rendererString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002496}
2497
Geoff Langc339c4e2016-11-29 10:37:36 -05002498void Context::initVersionStrings()
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002499{
Geoff Langc339c4e2016-11-29 10:37:36 -05002500 const Version &clientVersion = getClientVersion();
2501
2502 std::ostringstream versionString;
2503 versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE "
2504 << ANGLE_VERSION_STRING << ")";
2505 mVersionString = MakeStaticString(versionString.str());
2506
2507 std::ostringstream shadingLanguageVersionString;
2508 shadingLanguageVersionString << "OpenGL ES GLSL ES "
2509 << (clientVersion.major == 2 ? 1 : clientVersion.major) << "."
2510 << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING
2511 << ")";
2512 mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str());
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002513}
2514
Geoff Langcec35902014-04-16 10:52:36 -04002515void Context::initExtensionStrings()
2516{
Geoff Langc339c4e2016-11-29 10:37:36 -05002517 auto mergeExtensionStrings = [](const std::vector<const char *> &strings) {
2518 std::ostringstream combinedStringStream;
2519 std::copy(strings.begin(), strings.end(),
2520 std::ostream_iterator<const char *>(combinedStringStream, " "));
2521 return MakeStaticString(combinedStringStream.str());
2522 };
2523
2524 mExtensionStrings.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002525 for (const auto &extensionString : mExtensions.getStrings())
2526 {
2527 mExtensionStrings.push_back(MakeStaticString(extensionString));
2528 }
Geoff Langc339c4e2016-11-29 10:37:36 -05002529 mExtensionString = mergeExtensionStrings(mExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002530
Bryan Bernhart58806562017-01-05 13:09:31 -08002531 const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2532
Geoff Langc339c4e2016-11-29 10:37:36 -05002533 mRequestableExtensionStrings.clear();
2534 for (const auto &extensionInfo : GetExtensionInfoMap())
2535 {
2536 if (extensionInfo.second.Requestable &&
Bryan Bernhart58806562017-01-05 13:09:31 -08002537 !(mExtensions.*(extensionInfo.second.ExtensionsMember)) &&
2538 nativeExtensions.*(extensionInfo.second.ExtensionsMember))
Geoff Langc339c4e2016-11-29 10:37:36 -05002539 {
2540 mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first));
2541 }
2542 }
2543 mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings);
Geoff Langcec35902014-04-16 10:52:36 -04002544}
2545
Geoff Langc339c4e2016-11-29 10:37:36 -05002546const GLubyte *Context::getString(GLenum name) const
Geoff Langcec35902014-04-16 10:52:36 -04002547{
Geoff Langc339c4e2016-11-29 10:37:36 -05002548 switch (name)
2549 {
2550 case GL_VENDOR:
2551 return reinterpret_cast<const GLubyte *>("Google Inc.");
2552
2553 case GL_RENDERER:
2554 return reinterpret_cast<const GLubyte *>(mRendererString);
2555
2556 case GL_VERSION:
2557 return reinterpret_cast<const GLubyte *>(mVersionString);
2558
2559 case GL_SHADING_LANGUAGE_VERSION:
2560 return reinterpret_cast<const GLubyte *>(mShadingLanguageString);
2561
2562 case GL_EXTENSIONS:
2563 return reinterpret_cast<const GLubyte *>(mExtensionString);
2564
2565 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2566 return reinterpret_cast<const GLubyte *>(mRequestableExtensionString);
2567
2568 default:
2569 UNREACHABLE();
2570 return nullptr;
2571 }
Geoff Langcec35902014-04-16 10:52:36 -04002572}
2573
Geoff Langc339c4e2016-11-29 10:37:36 -05002574const GLubyte *Context::getStringi(GLenum name, GLuint index) const
Geoff Langcec35902014-04-16 10:52:36 -04002575{
Geoff Langc339c4e2016-11-29 10:37:36 -05002576 switch (name)
2577 {
2578 case GL_EXTENSIONS:
2579 return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]);
2580
2581 case GL_REQUESTABLE_EXTENSIONS_ANGLE:
2582 return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]);
2583
2584 default:
2585 UNREACHABLE();
2586 return nullptr;
2587 }
Geoff Langcec35902014-04-16 10:52:36 -04002588}
2589
2590size_t Context::getExtensionStringCount() const
2591{
2592 return mExtensionStrings.size();
2593}
2594
Geoff Lang111a99e2017-10-17 10:58:41 -04002595bool Context::isExtensionRequestable(const char *name)
2596{
2597 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2598 auto extension = extensionInfos.find(name);
2599
2600 const Extensions &nativeExtensions = mImplementation->getNativeExtensions();
2601 return extension != extensionInfos.end() && extension->second.Requestable &&
2602 nativeExtensions.*(extension->second.ExtensionsMember);
2603}
2604
Geoff Langc339c4e2016-11-29 10:37:36 -05002605void Context::requestExtension(const char *name)
2606{
2607 const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap();
2608 ASSERT(extensionInfos.find(name) != extensionInfos.end());
2609 const auto &extension = extensionInfos.at(name);
2610 ASSERT(extension.Requestable);
Geoff Lang111a99e2017-10-17 10:58:41 -04002611 ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember));
Geoff Langc339c4e2016-11-29 10:37:36 -05002612
2613 if (mExtensions.*(extension.ExtensionsMember))
2614 {
2615 // Extension already enabled
2616 return;
2617 }
2618
2619 mExtensions.*(extension.ExtensionsMember) = true;
2620 updateCaps();
2621 initExtensionStrings();
Bryan Bernhart58806562017-01-05 13:09:31 -08002622
Jamie Madill2f348d22017-06-05 10:50:59 -04002623 // Release the shader compiler so it will be re-created with the requested extensions enabled.
2624 releaseShaderCompiler();
Geoff Lang9aded172017-04-05 11:07:56 -04002625
Jamie Madill81c2e252017-09-09 23:32:46 -04002626 // Invalidate all textures and framebuffer. Some extensions make new formats renderable or
2627 // sampleable.
Jamie Madilld4442552018-02-27 22:03:47 -05002628 mState.mTextures->signalAllTexturesDirty(this);
Geoff Lang9aded172017-04-05 11:07:56 -04002629 for (auto &zeroTexture : mZeroTextures)
2630 {
Jamie Madilld4442552018-02-27 22:03:47 -05002631 zeroTexture.second->signalDirty(this, InitState::Initialized);
Geoff Lang9aded172017-04-05 11:07:56 -04002632 }
2633
2634 mState.mFramebuffers->invalidateFramebufferComplenessCache();
Geoff Langc339c4e2016-11-29 10:37:36 -05002635}
2636
2637size_t Context::getRequestableExtensionStringCount() const
2638{
2639 return mRequestableExtensionStrings.size();
2640}
2641
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002642void Context::beginTransformFeedback(GLenum primitiveMode)
2643{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002644 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002645 ASSERT(transformFeedback != nullptr);
2646 ASSERT(!transformFeedback->isPaused());
2647
Jamie Madill6c1f6712017-02-14 19:08:04 -05002648 transformFeedback->begin(this, primitiveMode, mGLState.getProgram());
Olli Etuahoc3e55a42016-03-09 16:29:18 +02002649}
2650
2651bool Context::hasActiveTransformFeedback(GLuint program) const
2652{
2653 for (auto pair : mTransformFeedbackMap)
2654 {
2655 if (pair.second != nullptr && pair.second->hasBoundProgram(program))
2656 {
2657 return true;
2658 }
2659 }
2660 return false;
2661}
2662
Geoff Langb433e872017-10-05 14:01:47 -04002663void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit)
Geoff Lang493daf52014-07-03 13:38:44 -04002664{
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002665 mCaps = mImplementation->getNativeCaps();
Geoff Lang493daf52014-07-03 13:38:44 -04002666
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002667 mExtensions = mImplementation->getNativeExtensions();
Geoff Lang493daf52014-07-03 13:38:44 -04002668
Jamie Madill53ea9cc2016-05-17 10:12:52 -04002669 mLimitations = mImplementation->getNativeLimitations();
Austin Kinross02df7962015-07-01 10:03:42 -07002670
Geoff Langeb66a6e2016-10-31 13:06:12 -04002671 if (getClientVersion() < Version(3, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002672 {
2673 // Disable ES3+ extensions
Jamie Madill231c7f52017-04-26 13:45:37 -04002674 mExtensions.colorBufferFloat = false;
Geoff Langb66a9092016-05-16 15:59:14 -04002675 mExtensions.eglImageExternalEssl3 = false;
Vincent Lang25ab4512016-05-13 18:13:59 +02002676 mExtensions.textureNorm16 = false;
Martin Radev137032d2017-07-13 10:11:12 +03002677 mExtensions.multiview = false;
2678 mExtensions.maxViews = 1u;
Geoff Lang493daf52014-07-03 13:38:44 -04002679 }
2680
Jiawei Shao89be29a2017-11-06 14:36:45 +08002681 if (getClientVersion() < ES_3_1)
2682 {
2683 // Disable ES3.1+ extensions
2684 mExtensions.geometryShader = false;
2685 }
2686
Geoff Langeb66a6e2016-10-31 13:06:12 -04002687 if (getClientVersion() > Version(2, 0))
Geoff Lang493daf52014-07-03 13:38:44 -04002688 {
2689 // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts
Jamie Madill231c7f52017-04-26 13:45:37 -04002690 // mExtensions.sRGB = false;
Geoff Lang493daf52014-07-03 13:38:44 -04002691 }
2692
Jamie Madill00ed7a12016-05-19 13:13:38 -04002693 // Some extensions are always available because they are implemented in the GL layer.
Jamie Madill231c7f52017-04-26 13:45:37 -04002694 mExtensions.bindUniformLocation = true;
2695 mExtensions.vertexArrayObject = true;
Geoff Langf41a7152016-09-19 15:11:17 -04002696 mExtensions.bindGeneratesResource = true;
Geoff Langfeb8c682017-02-13 16:07:35 -05002697 mExtensions.clientArrays = true;
Geoff Langc339c4e2016-11-29 10:37:36 -05002698 mExtensions.requestExtension = true;
Jamie Madill00ed7a12016-05-19 13:13:38 -04002699
2700 // Enable the no error extension if the context was created with the flag.
2701 mExtensions.noError = mSkipValidation;
2702
Corentin Wallezccab69d2017-01-27 16:57:15 -05002703 // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO
Corentin Wallezc295e512017-01-27 17:47:50 -05002704 mExtensions.surfacelessContext = displayExtensions.surfacelessContext;
Corentin Wallezccab69d2017-01-27 16:57:15 -05002705
Geoff Lang70d0f492015-12-10 17:45:46 -05002706 // Explicitly enable GL_KHR_debug
2707 mExtensions.debug = true;
2708 mExtensions.maxDebugMessageLength = 1024;
2709 mExtensions.maxDebugLoggedMessages = 1024;
2710 mExtensions.maxDebugGroupStackDepth = 1024;
2711 mExtensions.maxLabelLength = 1024;
2712
Geoff Langff5b2d52016-09-07 11:32:23 -04002713 // Explicitly enable GL_ANGLE_robust_client_memory
2714 mExtensions.robustClientMemory = true;
2715
Jamie Madille08a1d32017-03-07 17:24:06 -05002716 // Determine robust resource init availability from EGL.
Geoff Langb433e872017-10-05 14:01:47 -04002717 mExtensions.robustResourceInitialization = robustResourceInit;
Jamie Madille08a1d32017-03-07 17:24:06 -05002718
Jiajia Qin8a7b3a02017-08-25 16:05:48 +08002719 // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend
2720 // supports it.
2721 mExtensions.robustBufferAccessBehavior =
2722 mRobustAccess && mExtensions.robustBufferAccessBehavior;
2723
Jamie Madillc43be722017-07-13 16:22:14 -04002724 // Enable the cache control query unconditionally.
2725 mExtensions.programCacheControl = true;
2726
Geoff Lang301d1612014-07-09 10:34:37 -04002727 // Apply implementation limits
Jamie Madill0f80ed82017-09-19 00:24:56 -04002728 LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS);
Jiawei-Shao2597fb62016-12-09 16:38:02 +08002729
Jamie Madill0f80ed82017-09-19 00:24:56 -04002730 if (getClientVersion() < ES_3_1)
2731 {
2732 mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes;
2733 }
2734 else
2735 {
2736 LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS);
2737 }
Geoff Lang301d1612014-07-09 10:34:37 -04002738
Jamie Madill0f80ed82017-09-19 00:24:56 -04002739 LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS);
2740 LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2741 LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4);
2742
2743 // Limit textures as well, so we can use fast bitsets with texture bindings.
2744 LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES);
2745 LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
2746 LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2);
Geoff Lang3a61c322014-07-10 13:01:54 -04002747
Jiawei Shaodb342272017-09-27 10:21:45 +08002748 mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS);
2749
Geoff Langc287ea62016-09-16 14:46:51 -04002750 // WebGL compatibility
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002751 mExtensions.webglCompatibility = mWebGLContext;
Geoff Langc287ea62016-09-16 14:46:51 -04002752 for (const auto &extensionInfo : GetExtensionInfoMap())
2753 {
2754 // If this context is for WebGL, disable all enableable extensions
Jamie Madill4e0e6f82017-02-17 11:06:03 -05002755 if (mWebGLContext && extensionInfo.second.Requestable)
Geoff Langc287ea62016-09-16 14:46:51 -04002756 {
2757 mExtensions.*(extensionInfo.second.ExtensionsMember) = false;
2758 }
2759 }
2760
2761 // Generate texture caps
2762 updateCaps();
2763}
2764
2765void Context::updateCaps()
2766{
Geoff Lang900013c2014-07-07 11:32:19 -04002767 mCaps.compressedTextureFormats.clear();
Geoff Langc287ea62016-09-16 14:46:51 -04002768 mTextureCaps.clear();
Geoff Lang900013c2014-07-07 11:32:19 -04002769
Jamie Madill7b62cf92017-11-02 15:20:49 -04002770 for (GLenum sizedInternalFormat : GetAllSizedInternalFormats())
Geoff Lang493daf52014-07-03 13:38:44 -04002771 {
Jamie Madill7b62cf92017-11-02 15:20:49 -04002772 TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat);
Geoff Langca271392017-04-05 12:30:00 -04002773 const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002774
Geoff Lang0d8b7242015-09-09 14:56:53 -04002775 // Update the format caps based on the client version and extensions.
2776 // Caps are AND'd with the renderer caps because some core formats are still unsupported in
2777 // ES3.
2778 formatCaps.texturable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002779 formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002780 formatCaps.renderable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002781 formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions);
Geoff Lang0d8b7242015-09-09 14:56:53 -04002782 formatCaps.filterable =
Geoff Langeb66a6e2016-10-31 13:06:12 -04002783 formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions);
Geoff Langd87878e2014-09-19 15:42:59 -04002784
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002785 // OpenGL ES does not support multisampling with non-rendererable formats
2786 // OpenGL ES 3.0 or prior does not support multisampling with integer formats
Olli Etuaho50c562d2017-06-06 14:43:30 +03002787 if (!formatCaps.renderable ||
He Yunchaoccd8c9b2017-01-18 17:36:14 +08002788 (getClientVersion() < ES_3_1 &&
2789 (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT)))
Geoff Lang493daf52014-07-03 13:38:44 -04002790 {
Geoff Langd87878e2014-09-19 15:42:59 -04002791 formatCaps.sampleCounts.clear();
Geoff Lang493daf52014-07-03 13:38:44 -04002792 }
Olli Etuaho50c562d2017-06-06 14:43:30 +03002793 else
2794 {
2795 // We may have limited the max samples for some required renderbuffer formats due to
2796 // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly.
2797 GLuint formatMaxSamples = formatCaps.getMaxSamples();
2798
2799 // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers
2800 // in these required formats with up to the value of MAX_SAMPLES multisamples, with the
2801 // exception of signed and unsigned integer formats."
2802 if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT &&
2803 formatInfo.isRequiredRenderbufferFormat(getClientVersion()))
2804 {
2805 ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4);
2806 mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples);
2807 }
2808
2809 // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES.
2810 if (getClientVersion() >= ES_3_1)
2811 {
2812 // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers
2813 // in these required formats with up to the value of MAX_SAMPLES multisamples, with
2814 // the exception that the signed and unsigned integer formats are required only to
2815 // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES
2816 // multisamples, which must be at least one."
2817 if (formatInfo.componentType == GL_INT ||
2818 formatInfo.componentType == GL_UNSIGNED_INT)
2819 {
2820 mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples);
2821 }
2822
2823 // GLES 3.1 section 19.3.1.
2824 if (formatCaps.texturable)
2825 {
2826 if (formatInfo.depthBits > 0)
2827 {
2828 mCaps.maxDepthTextureSamples =
2829 std::min(mCaps.maxDepthTextureSamples, formatMaxSamples);
2830 }
2831 else if (formatInfo.redBits > 0)
2832 {
2833 mCaps.maxColorTextureSamples =
2834 std::min(mCaps.maxColorTextureSamples, formatMaxSamples);
2835 }
2836 }
2837 }
2838 }
Geoff Langd87878e2014-09-19 15:42:59 -04002839
2840 if (formatCaps.texturable && formatInfo.compressed)
2841 {
Geoff Langca271392017-04-05 12:30:00 -04002842 mCaps.compressedTextureFormats.push_back(sizedInternalFormat);
Geoff Langd87878e2014-09-19 15:42:59 -04002843 }
2844
Geoff Langca271392017-04-05 12:30:00 -04002845 mTextureCaps.insert(sizedInternalFormat, formatCaps);
Geoff Lang493daf52014-07-03 13:38:44 -04002846 }
Jamie Madill32447362017-06-28 14:53:52 -04002847
2848 // If program binary is disabled, blank out the memory cache pointer.
2849 if (!mImplementation->getNativeExtensions().getProgramBinary)
2850 {
2851 mMemoryProgramCache = nullptr;
2852 }
Corentin Walleze4477002017-12-01 14:39:58 -05002853
2854 // Compute which buffer types are allowed
2855 mValidBufferBindings.reset();
2856 mValidBufferBindings.set(BufferBinding::ElementArray);
2857 mValidBufferBindings.set(BufferBinding::Array);
2858
2859 if (mExtensions.pixelBufferObject || getClientVersion() >= ES_3_0)
2860 {
2861 mValidBufferBindings.set(BufferBinding::PixelPack);
2862 mValidBufferBindings.set(BufferBinding::PixelUnpack);
2863 }
2864
2865 if (getClientVersion() >= ES_3_0)
2866 {
2867 mValidBufferBindings.set(BufferBinding::CopyRead);
2868 mValidBufferBindings.set(BufferBinding::CopyWrite);
2869 mValidBufferBindings.set(BufferBinding::TransformFeedback);
2870 mValidBufferBindings.set(BufferBinding::Uniform);
2871 }
2872
2873 if (getClientVersion() >= ES_3_1)
2874 {
2875 mValidBufferBindings.set(BufferBinding::AtomicCounter);
2876 mValidBufferBindings.set(BufferBinding::ShaderStorage);
2877 mValidBufferBindings.set(BufferBinding::DrawIndirect);
2878 mValidBufferBindings.set(BufferBinding::DispatchIndirect);
2879 }
Geoff Lang493daf52014-07-03 13:38:44 -04002880}
2881
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002882void Context::initWorkarounds()
2883{
Jamie Madill761b02c2017-06-23 16:27:06 -04002884 // Apply back-end workarounds.
2885 mImplementation->applyNativeWorkarounds(&mWorkarounds);
2886
Kenneth Russellf2f6f652016-10-05 19:53:23 -07002887 // Lose the context upon out of memory error if the application is
2888 // expecting to watch for those events.
2889 mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT);
2890}
2891
Jamie Madill05b35b22017-10-03 09:01:44 -04002892Error Context::prepareForDraw()
2893{
2894 syncRendererState();
Jamie Madilla59fc192017-11-02 12:57:58 -04002895
2896 if (isRobustResourceInitEnabled())
2897 {
2898 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
2899 ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this));
2900 }
2901
Jamie Madill05b35b22017-10-03 09:01:44 -04002902 return NoError();
2903}
2904
Jamie Madill1b94d432015-08-07 13:23:23 -04002905void Context::syncRendererState()
2906{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002907 mGLState.syncDirtyObjects(this);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002908 const State::DirtyBits &dirtyBits = mGLState.getDirtyBits();
Jamie Madillfe548342017-06-19 11:13:24 -04002909 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002910 mGLState.clearDirtyBits();
Jamie Madill1b94d432015-08-07 13:23:23 -04002911}
2912
Jamie Madillad9f24e2016-02-12 09:27:24 -05002913void Context::syncRendererState(const State::DirtyBits &bitMask,
2914 const State::DirtyObjects &objectMask)
Jamie Madill1b94d432015-08-07 13:23:23 -04002915{
Jamie Madill7d1f5c62017-09-02 15:32:15 -04002916 mGLState.syncDirtyObjects(this, objectMask);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002917 const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask);
Jamie Madillfe548342017-06-19 11:13:24 -04002918 mImplementation->syncState(this, dirtyBits);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002919 mGLState.clearDirtyBits(dirtyBits);
Jamie Madill1b94d432015-08-07 13:23:23 -04002920}
Jamie Madillc29968b2016-01-20 11:17:23 -05002921
2922void Context::blitFramebuffer(GLint srcX0,
2923 GLint srcY0,
2924 GLint srcX1,
2925 GLint srcY1,
2926 GLint dstX0,
2927 GLint dstY0,
2928 GLint dstX1,
2929 GLint dstY1,
2930 GLbitfield mask,
2931 GLenum filter)
2932{
Qin Jiajiaaef92162018-02-27 13:51:44 +08002933 if (mask == 0)
2934 {
2935 // ES3.0 spec, section 4.3.2 specifies that a mask of zero is valid and no
2936 // buffers are copied.
2937 return;
2938 }
2939
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002940 Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002941 ASSERT(drawFramebuffer);
2942
2943 Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0);
2944 Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0);
2945
Jamie Madillad9f24e2016-02-12 09:27:24 -05002946 syncStateForBlit();
Jamie Madillc29968b2016-01-20 11:17:23 -05002947
Jamie Madillc564c072017-06-01 12:45:42 -04002948 handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter));
apatrick@chromium.org144f2802012-07-12 01:42:34 +00002949}
Jamie Madillc29968b2016-01-20 11:17:23 -05002950
2951void Context::clear(GLbitfield mask)
2952{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002953 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002954 handleError(mGLState.getDrawFramebuffer()->clear(this, mask));
Jamie Madillc29968b2016-01-20 11:17:23 -05002955}
2956
2957void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values)
2958{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002959 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002960 handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002961}
2962
2963void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values)
2964{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002965 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002966 handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002967}
2968
2969void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values)
2970{
Jamie Madillad9f24e2016-02-12 09:27:24 -05002971 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002972 handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values));
Jamie Madillc29968b2016-01-20 11:17:23 -05002973}
2974
2975void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil)
2976{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07002977 Framebuffer *framebufferObject = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05002978 ASSERT(framebufferObject);
2979
2980 // If a buffer is not present, the clear has no effect
2981 if (framebufferObject->getDepthbuffer() == nullptr &&
2982 framebufferObject->getStencilbuffer() == nullptr)
2983 {
2984 return;
2985 }
2986
Jamie Madillad9f24e2016-02-12 09:27:24 -05002987 syncStateForClear();
Jamie Madillc564c072017-06-01 12:45:42 -04002988 handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil));
Jamie Madillc29968b2016-01-20 11:17:23 -05002989}
2990
2991void Context::readPixels(GLint x,
2992 GLint y,
2993 GLsizei width,
2994 GLsizei height,
2995 GLenum format,
2996 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04002997 void *pixels)
Jamie Madillc29968b2016-01-20 11:17:23 -05002998{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04002999 if (width == 0 || height == 0)
3000 {
3001 return;
3002 }
3003
Jamie Madillad9f24e2016-02-12 09:27:24 -05003004 syncStateForReadPixels();
Jamie Madillc29968b2016-01-20 11:17:23 -05003005
Jamie Madillb6664922017-07-25 12:55:04 -04003006 Framebuffer *readFBO = mGLState.getReadFramebuffer();
3007 ASSERT(readFBO);
Jamie Madillc29968b2016-01-20 11:17:23 -05003008
3009 Rectangle area(x, y, width, height);
Jamie Madillb6664922017-07-25 12:55:04 -04003010 handleError(readFBO->readPixels(this, area, format, type, pixels));
Jamie Madillc29968b2016-01-20 11:17:23 -05003011}
3012
3013void Context::copyTexImage2D(GLenum target,
3014 GLint level,
3015 GLenum internalformat,
3016 GLint x,
3017 GLint y,
3018 GLsizei width,
3019 GLsizei height,
3020 GLint border)
3021{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003022 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003023 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003024
Jamie Madillc29968b2016-01-20 11:17:23 -05003025 Rectangle sourceArea(x, y, width, height);
3026
Jamie Madill05b35b22017-10-03 09:01:44 -04003027 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003028 Texture *texture =
3029 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003030 handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003031}
3032
3033void Context::copyTexSubImage2D(GLenum target,
3034 GLint level,
3035 GLint xoffset,
3036 GLint yoffset,
3037 GLint x,
3038 GLint y,
3039 GLsizei width,
3040 GLsizei height)
3041{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003042 if (width == 0 || height == 0)
3043 {
3044 return;
3045 }
3046
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003047 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003048 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003049
Jamie Madillc29968b2016-01-20 11:17:23 -05003050 Offset destOffset(xoffset, yoffset, 0);
3051 Rectangle sourceArea(x, y, width, height);
3052
Jamie Madill05b35b22017-10-03 09:01:44 -04003053 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003054 Texture *texture =
3055 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003056 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003057}
3058
3059void Context::copyTexSubImage3D(GLenum target,
3060 GLint level,
3061 GLint xoffset,
3062 GLint yoffset,
3063 GLint zoffset,
3064 GLint x,
3065 GLint y,
3066 GLsizei width,
3067 GLsizei height)
3068{
Corentin Wallez9a8d3662016-09-22 12:18:29 -04003069 if (width == 0 || height == 0)
3070 {
3071 return;
3072 }
3073
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003074 // Only sync the read FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003075 mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003076
Jamie Madillc29968b2016-01-20 11:17:23 -05003077 Offset destOffset(xoffset, yoffset, zoffset);
3078 Rectangle sourceArea(x, y, width, height);
3079
Jamie Madill05b35b22017-10-03 09:01:44 -04003080 Framebuffer *framebuffer = mGLState.getReadFramebuffer();
3081 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003082 handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer));
Jamie Madillc29968b2016-01-20 11:17:23 -05003083}
3084
3085void Context::framebufferTexture2D(GLenum target,
3086 GLenum attachment,
3087 GLenum textarget,
3088 GLuint texture,
3089 GLint level)
3090{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003091 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003092 ASSERT(framebuffer);
3093
3094 if (texture != 0)
3095 {
3096 Texture *textureObj = getTexture(texture);
3097
3098 ImageIndex index = ImageIndex::MakeInvalid();
3099
3100 if (textarget == GL_TEXTURE_2D)
3101 {
3102 index = ImageIndex::Make2D(level);
3103 }
Corentin Wallez13c0dd42017-07-04 18:27:01 -04003104 else if (textarget == GL_TEXTURE_RECTANGLE_ANGLE)
3105 {
3106 index = ImageIndex::MakeRectangle(level);
3107 }
JiangYizhoubddc46b2016-12-09 09:50:51 +08003108 else if (textarget == GL_TEXTURE_2D_MULTISAMPLE)
3109 {
3110 ASSERT(level == 0);
3111 index = ImageIndex::Make2DMultisample();
3112 }
Jamie Madillc29968b2016-01-20 11:17:23 -05003113 else
3114 {
3115 ASSERT(IsCubeMapTextureTarget(textarget));
3116 index = ImageIndex::MakeCube(textarget, level);
3117 }
3118
Jamie Madilla02315b2017-02-23 14:14:47 -05003119 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj);
Jamie Madillc29968b2016-01-20 11:17:23 -05003120 }
3121 else
3122 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003123 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003124 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003125
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003126 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003127}
3128
3129void Context::framebufferRenderbuffer(GLenum target,
3130 GLenum attachment,
3131 GLenum renderbuffertarget,
3132 GLuint renderbuffer)
3133{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003134 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003135 ASSERT(framebuffer);
3136
3137 if (renderbuffer != 0)
3138 {
3139 Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer);
Jamie Madilla02315b2017-02-23 14:14:47 -05003140
3141 framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(),
Jamie Madillc29968b2016-01-20 11:17:23 -05003142 renderbufferObject);
3143 }
3144 else
3145 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003146 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003147 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003148
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003149 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003150}
3151
3152void Context::framebufferTextureLayer(GLenum target,
3153 GLenum attachment,
3154 GLuint texture,
3155 GLint level,
3156 GLint layer)
3157{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003158 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003159 ASSERT(framebuffer);
3160
3161 if (texture != 0)
3162 {
3163 Texture *textureObject = getTexture(texture);
3164
3165 ImageIndex index = ImageIndex::MakeInvalid();
3166
3167 if (textureObject->getTarget() == GL_TEXTURE_3D)
3168 {
3169 index = ImageIndex::Make3D(level, layer);
3170 }
3171 else
3172 {
3173 ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY);
3174 index = ImageIndex::Make2DArray(level, layer);
3175 }
3176
Jamie Madilla02315b2017-02-23 14:14:47 -05003177 framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject);
Jamie Madillc29968b2016-01-20 11:17:23 -05003178 }
3179 else
3180 {
Jamie Madilla02315b2017-02-23 14:14:47 -05003181 framebuffer->resetAttachment(this, attachment);
Jamie Madillc29968b2016-01-20 11:17:23 -05003182 }
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003183
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003184 mGLState.setObjectDirty(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003185}
3186
Martin Radev137032d2017-07-13 10:11:12 +03003187void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target,
3188 GLenum attachment,
3189 GLuint texture,
3190 GLint level,
3191 GLint baseViewIndex,
3192 GLsizei numViews)
3193{
Martin Radev82ef7742017-08-08 17:44:58 +03003194 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3195 ASSERT(framebuffer);
3196
3197 if (texture != 0)
3198 {
3199 Texture *textureObj = getTexture(texture);
3200
Martin Radev18b75ba2017-08-15 15:50:40 +03003201 ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews);
Martin Radev82ef7742017-08-08 17:44:58 +03003202 framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj,
3203 numViews, baseViewIndex);
3204 }
3205 else
3206 {
3207 framebuffer->resetAttachment(this, attachment);
3208 }
3209
3210 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003211}
3212
3213void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target,
3214 GLenum attachment,
3215 GLuint texture,
3216 GLint level,
3217 GLsizei numViews,
3218 const GLint *viewportOffsets)
3219{
Martin Radev5dae57b2017-07-14 16:15:55 +03003220 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
3221 ASSERT(framebuffer);
3222
3223 if (texture != 0)
3224 {
3225 Texture *textureObj = getTexture(texture);
3226
3227 ImageIndex index = ImageIndex::Make2D(level);
3228 framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index,
3229 textureObj, numViews, viewportOffsets);
3230 }
3231 else
3232 {
3233 framebuffer->resetAttachment(this, attachment);
3234 }
3235
3236 mGLState.setObjectDirty(target);
Martin Radev137032d2017-07-13 10:11:12 +03003237}
3238
Jamie Madillc29968b2016-01-20 11:17:23 -05003239void Context::drawBuffers(GLsizei n, const GLenum *bufs)
3240{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003241 Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003242 ASSERT(framebuffer);
3243 framebuffer->setDrawBuffers(n, bufs);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003244 mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003245}
3246
3247void Context::readBuffer(GLenum mode)
3248{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003249 Framebuffer *readFBO = mGLState.getReadFramebuffer();
Jamie Madillc29968b2016-01-20 11:17:23 -05003250 readFBO->setReadBuffer(mode);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003251 mGLState.setObjectDirty(GL_READ_FRAMEBUFFER);
Jamie Madillc29968b2016-01-20 11:17:23 -05003252}
3253
3254void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments)
3255{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003256 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003257 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003258
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003259 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003260 ASSERT(framebuffer);
3261
3262 // The specification isn't clear what should be done when the framebuffer isn't complete.
3263 // We leave it up to the framebuffer implementation to decide what to do.
Jamie Madill4928b7c2017-06-20 12:57:39 -04003264 handleError(framebuffer->discard(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003265}
3266
3267void Context::invalidateFramebuffer(GLenum target,
3268 GLsizei numAttachments,
3269 const GLenum *attachments)
3270{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003271 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003272 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003273
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003274 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003275 ASSERT(framebuffer);
3276
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003277 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003278 {
Jamie Madill437fa652016-05-03 15:13:24 -04003279 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003280 }
Jamie Madill437fa652016-05-03 15:13:24 -04003281
Jamie Madill4928b7c2017-06-20 12:57:39 -04003282 handleError(framebuffer->invalidate(this, numAttachments, attachments));
Jamie Madillc29968b2016-01-20 11:17:23 -05003283}
3284
3285void Context::invalidateSubFramebuffer(GLenum target,
3286 GLsizei numAttachments,
3287 const GLenum *attachments,
3288 GLint x,
3289 GLint y,
3290 GLsizei width,
3291 GLsizei height)
3292{
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003293 // Only sync the FBO
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003294 mGLState.syncDirtyObject(this, target);
Jamie Madill60ec6ea2016-01-22 15:27:19 -05003295
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003296 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
Jamie Madillc29968b2016-01-20 11:17:23 -05003297 ASSERT(framebuffer);
3298
Jamie Madilldd43e6c2017-03-24 14:18:49 -04003299 if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE)
Jamie Madillc29968b2016-01-20 11:17:23 -05003300 {
Jamie Madill437fa652016-05-03 15:13:24 -04003301 return;
Jamie Madillc29968b2016-01-20 11:17:23 -05003302 }
Jamie Madill437fa652016-05-03 15:13:24 -04003303
3304 Rectangle area(x, y, width, height);
Jamie Madill4928b7c2017-06-20 12:57:39 -04003305 handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area));
Jamie Madillc29968b2016-01-20 11:17:23 -05003306}
3307
Jamie Madill73a84962016-02-12 09:27:23 -05003308void Context::texImage2D(GLenum target,
3309 GLint level,
3310 GLint internalformat,
3311 GLsizei width,
3312 GLsizei height,
3313 GLint border,
3314 GLenum format,
3315 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003316 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003317{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003318 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003319
3320 Extents size(width, height, 1);
3321 Texture *texture =
3322 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003323 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3324 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003325}
3326
3327void Context::texImage3D(GLenum target,
3328 GLint level,
3329 GLint internalformat,
3330 GLsizei width,
3331 GLsizei height,
3332 GLsizei depth,
3333 GLint border,
3334 GLenum format,
3335 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003336 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003337{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003338 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003339
3340 Extents size(width, height, depth);
3341 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003342 handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat,
3343 size, format, type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003344}
3345
3346void Context::texSubImage2D(GLenum target,
3347 GLint level,
3348 GLint xoffset,
3349 GLint yoffset,
3350 GLsizei width,
3351 GLsizei height,
3352 GLenum format,
3353 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003354 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003355{
3356 // Zero sized uploads are valid but no-ops
3357 if (width == 0 || height == 0)
3358 {
3359 return;
3360 }
3361
Jamie Madillad9f24e2016-02-12 09:27:24 -05003362 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003363
3364 Box area(xoffset, yoffset, 0, width, height, 1);
3365 Texture *texture =
3366 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003367 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3368 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003369}
3370
3371void Context::texSubImage3D(GLenum target,
3372 GLint level,
3373 GLint xoffset,
3374 GLint yoffset,
3375 GLint zoffset,
3376 GLsizei width,
3377 GLsizei height,
3378 GLsizei depth,
3379 GLenum format,
3380 GLenum type,
Jamie Madill876429b2017-04-20 15:46:24 -04003381 const void *pixels)
Jamie Madill73a84962016-02-12 09:27:23 -05003382{
3383 // Zero sized uploads are valid but no-ops
3384 if (width == 0 || height == 0 || depth == 0)
3385 {
3386 return;
3387 }
3388
Jamie Madillad9f24e2016-02-12 09:27:24 -05003389 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003390
3391 Box area(xoffset, yoffset, zoffset, width, height, depth);
3392 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003393 handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format,
3394 type, reinterpret_cast<const uint8_t *>(pixels)));
Jamie Madill73a84962016-02-12 09:27:23 -05003395}
3396
3397void Context::compressedTexImage2D(GLenum target,
3398 GLint level,
3399 GLenum internalformat,
3400 GLsizei width,
3401 GLsizei height,
3402 GLint border,
3403 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003404 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003405{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003406 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003407
3408 Extents size(width, height, 1);
3409 Texture *texture =
3410 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003411 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003412 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003413 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003414}
3415
3416void Context::compressedTexImage3D(GLenum target,
3417 GLint level,
3418 GLenum internalformat,
3419 GLsizei width,
3420 GLsizei height,
3421 GLsizei depth,
3422 GLint border,
3423 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003424 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003425{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003426 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003427
3428 Extents size(width, height, depth);
3429 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003430 handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003431 internalformat, size, imageSize,
Jamie Madill437fa652016-05-03 15:13:24 -04003432 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003433}
3434
3435void Context::compressedTexSubImage2D(GLenum target,
3436 GLint level,
3437 GLint xoffset,
3438 GLint yoffset,
3439 GLsizei width,
3440 GLsizei height,
3441 GLenum format,
3442 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003443 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003444{
Jamie Madillad9f24e2016-02-12 09:27:24 -05003445 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003446
3447 Box area(xoffset, yoffset, 0, width, height, 1);
3448 Texture *texture =
3449 getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003450 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003451 format, imageSize,
3452 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003453}
3454
3455void Context::compressedTexSubImage3D(GLenum target,
3456 GLint level,
3457 GLint xoffset,
3458 GLint yoffset,
3459 GLint zoffset,
3460 GLsizei width,
3461 GLsizei height,
3462 GLsizei depth,
3463 GLenum format,
3464 GLsizei imageSize,
Jamie Madill876429b2017-04-20 15:46:24 -04003465 const void *data)
Jamie Madill73a84962016-02-12 09:27:23 -05003466{
3467 // Zero sized uploads are valid but no-ops
3468 if (width == 0 || height == 0)
3469 {
3470 return;
3471 }
3472
Jamie Madillad9f24e2016-02-12 09:27:24 -05003473 syncStateForTexImage();
Jamie Madill73a84962016-02-12 09:27:23 -05003474
3475 Box area(xoffset, yoffset, zoffset, width, height, depth);
3476 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003477 handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area,
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003478 format, imageSize,
3479 reinterpret_cast<const uint8_t *>(data)));
Jamie Madill73a84962016-02-12 09:27:23 -05003480}
3481
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003482void Context::generateMipmap(GLenum target)
3483{
3484 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05003485 handleError(texture->generateMipmap(this));
Olli Etuaho0f2b1562016-05-13 16:15:35 +03003486}
3487
Jamie Madill007530e2017-12-28 14:27:04 -05003488void Context::copyTexture(GLuint sourceId,
3489 GLint sourceLevel,
3490 GLenum destTarget,
3491 GLuint destId,
3492 GLint destLevel,
3493 GLint internalFormat,
3494 GLenum destType,
3495 GLboolean unpackFlipY,
3496 GLboolean unpackPremultiplyAlpha,
3497 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003498{
3499 syncStateForTexImage();
3500
3501 gl::Texture *sourceTexture = getTexture(sourceId);
3502 gl::Texture *destTexture = getTexture(destId);
Geoff Lang92019432017-11-20 13:09:34 -05003503 handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType,
3504 sourceLevel, ConvertToBool(unpackFlipY),
3505 ConvertToBool(unpackPremultiplyAlpha),
3506 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003507}
3508
Jamie Madill007530e2017-12-28 14:27:04 -05003509void Context::copySubTexture(GLuint sourceId,
3510 GLint sourceLevel,
3511 GLenum destTarget,
3512 GLuint destId,
3513 GLint destLevel,
3514 GLint xoffset,
3515 GLint yoffset,
3516 GLint x,
3517 GLint y,
3518 GLsizei width,
3519 GLsizei height,
3520 GLboolean unpackFlipY,
3521 GLboolean unpackPremultiplyAlpha,
3522 GLboolean unpackUnmultiplyAlpha)
Geoff Lang97073d12016-04-20 10:42:34 -07003523{
3524 // Zero sized copies are valid but no-ops
3525 if (width == 0 || height == 0)
3526 {
3527 return;
3528 }
3529
3530 syncStateForTexImage();
3531
3532 gl::Texture *sourceTexture = getTexture(sourceId);
3533 gl::Texture *destTexture = getTexture(destId);
3534 Offset offset(xoffset, yoffset, 0);
3535 Rectangle area(x, y, width, height);
Geoff Lang92019432017-11-20 13:09:34 -05003536 handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area,
3537 ConvertToBool(unpackFlipY),
3538 ConvertToBool(unpackPremultiplyAlpha),
3539 ConvertToBool(unpackUnmultiplyAlpha), sourceTexture));
Geoff Lang97073d12016-04-20 10:42:34 -07003540}
3541
Jamie Madill007530e2017-12-28 14:27:04 -05003542void Context::compressedCopyTexture(GLuint sourceId, GLuint destId)
Geoff Lang47110bf2016-04-20 11:13:22 -07003543{
3544 syncStateForTexImage();
3545
3546 gl::Texture *sourceTexture = getTexture(sourceId);
3547 gl::Texture *destTexture = getTexture(destId);
Jamie Madill8897afa2017-02-06 17:17:23 -05003548 handleError(destTexture->copyCompressedTexture(this, sourceTexture));
Geoff Lang47110bf2016-04-20 11:13:22 -07003549}
3550
Corentin Wallez336129f2017-10-17 15:55:40 -04003551void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params)
Olli Etuaho4f667482016-03-30 15:56:35 +03003552{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003553 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003554 ASSERT(buffer);
3555
Geoff Lang496c02d2016-10-20 11:38:11 -07003556 QueryBufferPointerv(buffer, pname, params);
Olli Etuaho4f667482016-03-30 15:56:35 +03003557}
3558
Corentin Wallez336129f2017-10-17 15:55:40 -04003559void *Context::mapBuffer(BufferBinding target, GLenum access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003560{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003561 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003562 ASSERT(buffer);
3563
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003564 Error error = buffer->map(this, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003565 if (error.isError())
3566 {
Jamie Madill437fa652016-05-03 15:13:24 -04003567 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003568 return nullptr;
3569 }
3570
3571 return buffer->getMapPointer();
3572}
3573
Corentin Wallez336129f2017-10-17 15:55:40 -04003574GLboolean Context::unmapBuffer(BufferBinding target)
Olli Etuaho4f667482016-03-30 15:56:35 +03003575{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003576 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003577 ASSERT(buffer);
3578
3579 GLboolean result;
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003580 Error error = buffer->unmap(this, &result);
Olli Etuaho4f667482016-03-30 15:56:35 +03003581 if (error.isError())
3582 {
Jamie Madill437fa652016-05-03 15:13:24 -04003583 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003584 return GL_FALSE;
3585 }
3586
3587 return result;
3588}
3589
Corentin Wallez336129f2017-10-17 15:55:40 -04003590void *Context::mapBufferRange(BufferBinding target,
3591 GLintptr offset,
3592 GLsizeiptr length,
3593 GLbitfield access)
Olli Etuaho4f667482016-03-30 15:56:35 +03003594{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003595 Buffer *buffer = mGLState.getTargetBuffer(target);
Olli Etuaho4f667482016-03-30 15:56:35 +03003596 ASSERT(buffer);
3597
Jamie Madill5f56ddb2017-01-13 17:29:55 -05003598 Error error = buffer->mapRange(this, offset, length, access);
Olli Etuaho4f667482016-03-30 15:56:35 +03003599 if (error.isError())
3600 {
Jamie Madill437fa652016-05-03 15:13:24 -04003601 handleError(error);
Olli Etuaho4f667482016-03-30 15:56:35 +03003602 return nullptr;
3603 }
3604
3605 return buffer->getMapPointer();
3606}
3607
Corentin Wallez336129f2017-10-17 15:55:40 -04003608void Context::flushMappedBufferRange(BufferBinding /*target*/,
3609 GLintptr /*offset*/,
3610 GLsizeiptr /*length*/)
Olli Etuaho4f667482016-03-30 15:56:35 +03003611{
3612 // We do not currently support a non-trivial implementation of FlushMappedBufferRange
3613}
3614
Jamie Madillad9f24e2016-02-12 09:27:24 -05003615void Context::syncStateForReadPixels()
3616{
3617 syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects);
3618}
3619
3620void Context::syncStateForTexImage()
3621{
3622 syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects);
3623}
3624
3625void Context::syncStateForClear()
3626{
3627 syncRendererState(mClearDirtyBits, mClearDirtyObjects);
3628}
3629
3630void Context::syncStateForBlit()
3631{
3632 syncRendererState(mBlitDirtyBits, mBlitDirtyObjects);
3633}
3634
Jiajia Qin5451d532017-11-16 17:16:34 +08003635void Context::activeShaderProgram(GLuint pipeline, GLuint program)
3636{
3637 UNIMPLEMENTED();
3638}
3639
Jamie Madillc20ab272016-06-09 07:20:46 -07003640void Context::activeTexture(GLenum texture)
3641{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003642 mGLState.setActiveSampler(texture - GL_TEXTURE0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003643}
3644
Jamie Madill876429b2017-04-20 15:46:24 -04003645void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003646{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003647 mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003648}
3649
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003650void Context::blendEquation(GLenum mode)
3651{
3652 mGLState.setBlendEquation(mode, mode);
3653}
3654
Jamie Madillc20ab272016-06-09 07:20:46 -07003655void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha)
3656{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003657 mGLState.setBlendEquation(modeRGB, modeAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003658}
3659
Jamie Madill8a9e4bc2016-11-13 20:02:12 -05003660void Context::blendFunc(GLenum sfactor, GLenum dfactor)
3661{
3662 mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor);
3663}
3664
Jamie Madillc20ab272016-06-09 07:20:46 -07003665void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha)
3666{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003667 mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003668}
3669
Jamie Madill876429b2017-04-20 15:46:24 -04003670void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
Jamie Madillc20ab272016-06-09 07:20:46 -07003671{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003672 mGLState.setColorClearValue(red, green, blue, alpha);
Jamie Madillc20ab272016-06-09 07:20:46 -07003673}
3674
Jamie Madill876429b2017-04-20 15:46:24 -04003675void Context::clearDepthf(GLfloat depth)
Jamie Madillc20ab272016-06-09 07:20:46 -07003676{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003677 mGLState.setDepthClearValue(depth);
Jamie Madillc20ab272016-06-09 07:20:46 -07003678}
3679
3680void Context::clearStencil(GLint s)
3681{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003682 mGLState.setStencilClearValue(s);
Jamie Madillc20ab272016-06-09 07:20:46 -07003683}
3684
3685void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha)
3686{
Geoff Lang92019432017-11-20 13:09:34 -05003687 mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue),
3688 ConvertToBool(alpha));
Jamie Madillc20ab272016-06-09 07:20:46 -07003689}
3690
Corentin Wallez2e568cf2017-09-18 17:05:22 -04003691void Context::cullFace(CullFaceMode mode)
Jamie Madillc20ab272016-06-09 07:20:46 -07003692{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003693 mGLState.setCullMode(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003694}
3695
3696void Context::depthFunc(GLenum func)
3697{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003698 mGLState.setDepthFunc(func);
Jamie Madillc20ab272016-06-09 07:20:46 -07003699}
3700
3701void Context::depthMask(GLboolean flag)
3702{
Geoff Lang92019432017-11-20 13:09:34 -05003703 mGLState.setDepthMask(ConvertToBool(flag));
Jamie Madillc20ab272016-06-09 07:20:46 -07003704}
3705
Jamie Madill876429b2017-04-20 15:46:24 -04003706void Context::depthRangef(GLfloat zNear, GLfloat zFar)
Jamie Madillc20ab272016-06-09 07:20:46 -07003707{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003708 mGLState.setDepthRange(zNear, zFar);
Jamie Madillc20ab272016-06-09 07:20:46 -07003709}
3710
3711void Context::disable(GLenum cap)
3712{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003713 mGLState.setEnableFeature(cap, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003714}
3715
3716void Context::disableVertexAttribArray(GLuint index)
3717{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003718 mGLState.setEnableVertexAttribArray(index, false);
Jamie Madillc20ab272016-06-09 07:20:46 -07003719}
3720
3721void Context::enable(GLenum cap)
3722{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003723 mGLState.setEnableFeature(cap, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003724}
3725
3726void Context::enableVertexAttribArray(GLuint index)
3727{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003728 mGLState.setEnableVertexAttribArray(index, true);
Jamie Madillc20ab272016-06-09 07:20:46 -07003729}
3730
3731void Context::frontFace(GLenum mode)
3732{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003733 mGLState.setFrontFace(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003734}
3735
3736void Context::hint(GLenum target, GLenum mode)
3737{
3738 switch (target)
3739 {
3740 case GL_GENERATE_MIPMAP_HINT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003741 mGLState.setGenerateMipmapHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003742 break;
3743
3744 case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003745 mGLState.setFragmentShaderDerivativeHint(mode);
Jamie Madillc20ab272016-06-09 07:20:46 -07003746 break;
3747
3748 default:
3749 UNREACHABLE();
3750 return;
3751 }
3752}
3753
3754void Context::lineWidth(GLfloat width)
3755{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003756 mGLState.setLineWidth(width);
Jamie Madillc20ab272016-06-09 07:20:46 -07003757}
3758
3759void Context::pixelStorei(GLenum pname, GLint param)
3760{
3761 switch (pname)
3762 {
3763 case GL_UNPACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003764 mGLState.setUnpackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003765 break;
3766
3767 case GL_PACK_ALIGNMENT:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003768 mGLState.setPackAlignment(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003769 break;
3770
3771 case GL_PACK_REVERSE_ROW_ORDER_ANGLE:
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003772 mGLState.setPackReverseRowOrder(param != 0);
Jamie Madillc20ab272016-06-09 07:20:46 -07003773 break;
3774
3775 case GL_UNPACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003776 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003777 mGLState.setUnpackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003778 break;
3779
3780 case GL_UNPACK_IMAGE_HEIGHT:
Martin Radev1be913c2016-07-11 17:59:16 +03003781 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003782 mGLState.setUnpackImageHeight(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003783 break;
3784
3785 case GL_UNPACK_SKIP_IMAGES:
Martin Radev1be913c2016-07-11 17:59:16 +03003786 ASSERT(getClientMajorVersion() >= 3);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003787 mGLState.setUnpackSkipImages(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003788 break;
3789
3790 case GL_UNPACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003791 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003792 mGLState.setUnpackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003793 break;
3794
3795 case GL_UNPACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003796 ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003797 mGLState.setUnpackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003798 break;
3799
3800 case GL_PACK_ROW_LENGTH:
Martin Radev1be913c2016-07-11 17:59:16 +03003801 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003802 mGLState.setPackRowLength(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003803 break;
3804
3805 case GL_PACK_SKIP_ROWS:
Martin Radev1be913c2016-07-11 17:59:16 +03003806 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003807 mGLState.setPackSkipRows(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003808 break;
3809
3810 case GL_PACK_SKIP_PIXELS:
Martin Radev1be913c2016-07-11 17:59:16 +03003811 ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003812 mGLState.setPackSkipPixels(param);
Jamie Madillc20ab272016-06-09 07:20:46 -07003813 break;
3814
3815 default:
3816 UNREACHABLE();
3817 return;
3818 }
3819}
3820
3821void Context::polygonOffset(GLfloat factor, GLfloat units)
3822{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003823 mGLState.setPolygonOffsetParams(factor, units);
Jamie Madillc20ab272016-06-09 07:20:46 -07003824}
3825
Jamie Madill876429b2017-04-20 15:46:24 -04003826void Context::sampleCoverage(GLfloat value, GLboolean invert)
Jamie Madillc20ab272016-06-09 07:20:46 -07003827{
Geoff Lang92019432017-11-20 13:09:34 -05003828 mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert));
Jamie Madillc20ab272016-06-09 07:20:46 -07003829}
3830
Jiawei Shaodb342272017-09-27 10:21:45 +08003831void Context::sampleMaski(GLuint maskNumber, GLbitfield mask)
3832{
3833 mGLState.setSampleMaskParams(maskNumber, mask);
3834}
3835
Jamie Madillc20ab272016-06-09 07:20:46 -07003836void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height)
3837{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003838 mGLState.setScissorParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003839}
3840
3841void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask)
3842{
3843 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3844 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003845 mGLState.setStencilParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003846 }
3847
3848 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3849 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003850 mGLState.setStencilBackParams(func, ref, mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003851 }
3852}
3853
3854void Context::stencilMaskSeparate(GLenum face, GLuint mask)
3855{
3856 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3857 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003858 mGLState.setStencilWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003859 }
3860
3861 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3862 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003863 mGLState.setStencilBackWritemask(mask);
Jamie Madillc20ab272016-06-09 07:20:46 -07003864 }
3865}
3866
3867void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass)
3868{
3869 if (face == GL_FRONT || face == GL_FRONT_AND_BACK)
3870 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003871 mGLState.setStencilOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003872 }
3873
3874 if (face == GL_BACK || face == GL_FRONT_AND_BACK)
3875 {
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003876 mGLState.setStencilBackOperations(fail, zfail, zpass);
Jamie Madillc20ab272016-06-09 07:20:46 -07003877 }
3878}
3879
3880void Context::vertexAttrib1f(GLuint index, GLfloat x)
3881{
3882 GLfloat vals[4] = {x, 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003883 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003884}
3885
3886void Context::vertexAttrib1fv(GLuint index, const GLfloat *values)
3887{
3888 GLfloat vals[4] = {values[0], 0, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003889 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003890}
3891
3892void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y)
3893{
3894 GLfloat vals[4] = {x, y, 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003895 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003896}
3897
3898void Context::vertexAttrib2fv(GLuint index, const GLfloat *values)
3899{
3900 GLfloat vals[4] = {values[0], values[1], 0, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003901 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003902}
3903
3904void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z)
3905{
3906 GLfloat vals[4] = {x, y, z, 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003907 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003908}
3909
3910void Context::vertexAttrib3fv(GLuint index, const GLfloat *values)
3911{
3912 GLfloat vals[4] = {values[0], values[1], values[2], 1};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003913 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003914}
3915
3916void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
3917{
3918 GLfloat vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003919 mGLState.setVertexAttribf(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003920}
3921
3922void Context::vertexAttrib4fv(GLuint index, const GLfloat *values)
3923{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003924 mGLState.setVertexAttribf(index, values);
Jamie Madillc20ab272016-06-09 07:20:46 -07003925}
3926
3927void Context::vertexAttribPointer(GLuint index,
3928 GLint size,
3929 GLenum type,
3930 GLboolean normalized,
3931 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003932 const void *ptr)
Jamie Madillc20ab272016-06-09 07:20:46 -07003933{
Corentin Wallez336129f2017-10-17 15:55:40 -04003934 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
Geoff Lang92019432017-11-20 13:09:34 -05003935 size, type, ConvertToBool(normalized), false, stride, ptr);
Jamie Madillc20ab272016-06-09 07:20:46 -07003936}
3937
Shao80957d92017-02-20 21:25:59 +08003938void Context::vertexAttribFormat(GLuint attribIndex,
3939 GLint size,
3940 GLenum type,
3941 GLboolean normalized,
3942 GLuint relativeOffset)
3943{
Geoff Lang92019432017-11-20 13:09:34 -05003944 mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false,
Shao80957d92017-02-20 21:25:59 +08003945 relativeOffset);
3946}
3947
3948void Context::vertexAttribIFormat(GLuint attribIndex,
3949 GLint size,
3950 GLenum type,
3951 GLuint relativeOffset)
3952{
3953 mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset);
3954}
3955
3956void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex)
3957{
Shaodde78e82017-05-22 14:13:27 +08003958 mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex);
Shao80957d92017-02-20 21:25:59 +08003959}
3960
Jiajia Qin5451d532017-11-16 17:16:34 +08003961void Context::vertexBindingDivisor(GLuint bindingIndex, GLuint divisor)
Shao80957d92017-02-20 21:25:59 +08003962{
3963 mGLState.setVertexBindingDivisor(bindingIndex, divisor);
3964}
3965
Jamie Madillc20ab272016-06-09 07:20:46 -07003966void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height)
3967{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003968 mGLState.setViewportParams(x, y, width, height);
Jamie Madillc20ab272016-06-09 07:20:46 -07003969}
3970
3971void Context::vertexAttribIPointer(GLuint index,
3972 GLint size,
3973 GLenum type,
3974 GLsizei stride,
Jamie Madill876429b2017-04-20 15:46:24 -04003975 const void *pointer)
Jamie Madillc20ab272016-06-09 07:20:46 -07003976{
Corentin Wallez336129f2017-10-17 15:55:40 -04003977 mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array),
3978 size, type, false, true, stride, pointer);
Jamie Madillc20ab272016-06-09 07:20:46 -07003979}
3980
3981void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w)
3982{
3983 GLint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003984 mGLState.setVertexAttribi(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003985}
3986
3987void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w)
3988{
3989 GLuint vals[4] = {x, y, z, w};
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003990 mGLState.setVertexAttribu(index, vals);
Jamie Madillc20ab272016-06-09 07:20:46 -07003991}
3992
3993void Context::vertexAttribI4iv(GLuint index, const GLint *v)
3994{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07003995 mGLState.setVertexAttribi(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07003996}
3997
3998void Context::vertexAttribI4uiv(GLuint index, const GLuint *v)
3999{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004000 mGLState.setVertexAttribu(index, v);
Jamie Madillc20ab272016-06-09 07:20:46 -07004001}
4002
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004003void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params)
4004{
4005 const VertexAttribCurrentValueData &currentValues =
4006 getGLState().getVertexAttribCurrentValue(index);
4007 const VertexArray *vao = getGLState().getVertexArray();
4008 QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4009 currentValues, pname, params);
4010}
4011
4012void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params)
4013{
4014 const VertexAttribCurrentValueData &currentValues =
4015 getGLState().getVertexAttribCurrentValue(index);
4016 const VertexArray *vao = getGLState().getVertexArray();
4017 QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4018 currentValues, pname, params);
4019}
4020
4021void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params)
4022{
4023 const VertexAttribCurrentValueData &currentValues =
4024 getGLState().getVertexAttribCurrentValue(index);
4025 const VertexArray *vao = getGLState().getVertexArray();
4026 QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4027 currentValues, pname, params);
4028}
4029
4030void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params)
4031{
4032 const VertexAttribCurrentValueData &currentValues =
4033 getGLState().getVertexAttribCurrentValue(index);
4034 const VertexArray *vao = getGLState().getVertexArray();
4035 QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index),
4036 currentValues, pname, params);
4037}
4038
Jamie Madill876429b2017-04-20 15:46:24 -04004039void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer)
Jiawei-Shao2597fb62016-12-09 16:38:02 +08004040{
4041 const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index);
4042 QueryVertexAttribPointerv(attrib, pname, pointer);
4043}
4044
Jamie Madillc20ab272016-06-09 07:20:46 -07004045void Context::debugMessageControl(GLenum source,
4046 GLenum type,
4047 GLenum severity,
4048 GLsizei count,
4049 const GLuint *ids,
4050 GLboolean enabled)
4051{
4052 std::vector<GLuint> idVector(ids, ids + count);
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004053 mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector),
Geoff Lang92019432017-11-20 13:09:34 -05004054 ConvertToBool(enabled));
Jamie Madillc20ab272016-06-09 07:20:46 -07004055}
4056
4057void Context::debugMessageInsert(GLenum source,
4058 GLenum type,
4059 GLuint id,
4060 GLenum severity,
4061 GLsizei length,
4062 const GLchar *buf)
4063{
4064 std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004065 mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg));
Jamie Madillc20ab272016-06-09 07:20:46 -07004066}
4067
4068void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam)
4069{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004070 mGLState.getDebug().setCallback(callback, userParam);
Jamie Madillc20ab272016-06-09 07:20:46 -07004071}
4072
4073GLuint Context::getDebugMessageLog(GLuint count,
4074 GLsizei bufSize,
4075 GLenum *sources,
4076 GLenum *types,
4077 GLuint *ids,
4078 GLenum *severities,
4079 GLsizei *lengths,
4080 GLchar *messageLog)
4081{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004082 return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids,
4083 severities, lengths, messageLog));
Jamie Madillc20ab272016-06-09 07:20:46 -07004084}
4085
4086void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message)
4087{
4088 std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message));
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004089 mGLState.getDebug().pushGroup(source, id, std::move(msg));
Geoff Lang5d5253a2017-11-22 14:51:12 -05004090 mImplementation->pushDebugGroup(source, id, length, message);
Jamie Madillc20ab272016-06-09 07:20:46 -07004091}
4092
4093void Context::popDebugGroup()
4094{
Jamie Madilldfde6ab2016-06-09 07:07:18 -07004095 mGLState.getDebug().popGroup();
Geoff Lang5d5253a2017-11-22 14:51:12 -05004096 mImplementation->popDebugGroup();
Jamie Madillc20ab272016-06-09 07:20:46 -07004097}
4098
Corentin Wallez336129f2017-10-17 15:55:40 -04004099void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage)
Jamie Madill29639852016-09-02 15:00:09 -04004100{
4101 Buffer *buffer = mGLState.getTargetBuffer(target);
4102 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004103 handleError(buffer->bufferData(this, target, data, size, usage));
Jamie Madill29639852016-09-02 15:00:09 -04004104}
4105
Corentin Wallez336129f2017-10-17 15:55:40 -04004106void Context::bufferSubData(BufferBinding target,
4107 GLintptr offset,
4108 GLsizeiptr size,
4109 const void *data)
Jamie Madill29639852016-09-02 15:00:09 -04004110{
4111 if (data == nullptr)
4112 {
4113 return;
4114 }
4115
4116 Buffer *buffer = mGLState.getTargetBuffer(target);
4117 ASSERT(buffer);
Jamie Madillb8353b02017-01-25 12:57:21 -08004118 handleError(buffer->bufferSubData(this, target, data, size, offset));
Jamie Madill29639852016-09-02 15:00:09 -04004119}
4120
Jamie Madillef300b12016-10-07 15:12:09 -04004121void Context::attachShader(GLuint program, GLuint shader)
4122{
Jamie Madillacf2f3a2017-11-21 19:22:44 -05004123 Program *programObject = mState.mShaderPrograms->getProgram(program);
4124 Shader *shaderObject = mState.mShaderPrograms->getShader(shader);
Jamie Madillef300b12016-10-07 15:12:09 -04004125 ASSERT(programObject && shaderObject);
4126 programObject->attachShader(shaderObject);
4127}
4128
Kenneth Russellf2f6f652016-10-05 19:53:23 -07004129const Workarounds &Context::getWorkarounds() const
4130{
4131 return mWorkarounds;
4132}
4133
Corentin Wallez336129f2017-10-17 15:55:40 -04004134void Context::copyBufferSubData(BufferBinding readTarget,
4135 BufferBinding writeTarget,
Jamie Madillb0817d12016-11-01 15:48:31 -04004136 GLintptr readOffset,
4137 GLintptr writeOffset,
4138 GLsizeiptr size)
4139{
4140 // if size is zero, the copy is a successful no-op
4141 if (size == 0)
4142 {
4143 return;
4144 }
4145
4146 // TODO(jmadill): cache these.
4147 Buffer *readBuffer = mGLState.getTargetBuffer(readTarget);
4148 Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget);
4149
Jamie Madill5f56ddb2017-01-13 17:29:55 -05004150 handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size));
Jamie Madillb0817d12016-11-01 15:48:31 -04004151}
4152
Jamie Madill01a80ee2016-11-07 12:06:18 -05004153void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name)
4154{
4155 Program *programObject = getProgram(program);
4156 // TODO(jmadill): Re-use this from the validation if possible.
4157 ASSERT(programObject);
4158 programObject->bindAttributeLocation(index, name);
4159}
4160
Corentin Wallez336129f2017-10-17 15:55:40 -04004161void Context::bindBuffer(BufferBinding target, GLuint buffer)
Jamie Madill01a80ee2016-11-07 12:06:18 -05004162{
Corentin Wallez336129f2017-10-17 15:55:40 -04004163 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4164 mGLState.setBufferBinding(this, target, bufferObject);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004165}
4166
Corentin Wallez336129f2017-10-17 15:55:40 -04004167void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer)
Jiajia Qin6eafb042016-12-27 17:04:07 +08004168{
4169 bindBufferRange(target, index, buffer, 0, 0);
4170}
4171
Corentin Wallez336129f2017-10-17 15:55:40 -04004172void Context::bindBufferRange(BufferBinding target,
Jiajia Qin6eafb042016-12-27 17:04:07 +08004173 GLuint index,
4174 GLuint buffer,
4175 GLintptr offset,
4176 GLsizeiptr size)
4177{
Corentin Wallez336129f2017-10-17 15:55:40 -04004178 Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer);
4179 mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size);
Jiajia Qin6eafb042016-12-27 17:04:07 +08004180}
4181
Jamie Madill01a80ee2016-11-07 12:06:18 -05004182void Context::bindFramebuffer(GLenum target, GLuint framebuffer)
4183{
4184 if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4185 {
4186 bindReadFramebuffer(framebuffer);
4187 }
4188
4189 if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER)
4190 {
4191 bindDrawFramebuffer(framebuffer);
4192 }
4193}
4194
4195void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer)
4196{
4197 ASSERT(target == GL_RENDERBUFFER);
4198 Renderbuffer *object =
Geoff Lang4ddf5af2016-12-01 14:30:44 -05004199 mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer);
Jamie Madill4928b7c2017-06-20 12:57:39 -04004200 mGLState.setRenderbufferBinding(this, object);
Jamie Madill01a80ee2016-11-07 12:06:18 -05004201}
4202
JiangYizhoubddc46b2016-12-09 09:50:51 +08004203void Context::texStorage2DMultisample(GLenum target,
4204 GLsizei samples,
4205 GLenum internalformat,
4206 GLsizei width,
4207 GLsizei height,
4208 GLboolean fixedsamplelocations)
4209{
4210 Extents size(width, height, 1);
4211 Texture *texture = getTargetTexture(target);
Jamie Madill8897afa2017-02-06 17:17:23 -05004212 handleError(texture->setStorageMultisample(this, target, samples, internalformat, size,
Geoff Lang92019432017-11-20 13:09:34 -05004213 ConvertToBool(fixedsamplelocations)));
JiangYizhoubddc46b2016-12-09 09:50:51 +08004214}
4215
4216void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val)
4217{
JiangYizhou5b03f472017-01-09 10:22:53 +08004218 // According to spec 3.1 Table 20.49: Framebuffer Dependent Values,
4219 // the sample position should be queried by DRAW_FRAMEBUFFER.
4220 mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER);
4221 const Framebuffer *framebuffer = mGLState.getDrawFramebuffer();
JiangYizhoubddc46b2016-12-09 09:50:51 +08004222
4223 switch (pname)
4224 {
4225 case GL_SAMPLE_POSITION:
4226 handleError(framebuffer->getSamplePosition(index, val));
4227 break;
4228 default:
4229 UNREACHABLE();
4230 }
4231}
4232
Jamie Madille8fb6402017-02-14 17:56:40 -05004233void Context::renderbufferStorage(GLenum target,
4234 GLenum internalformat,
4235 GLsizei width,
4236 GLsizei height)
4237{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004238 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4239 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
4240
Jamie Madille8fb6402017-02-14 17:56:40 -05004241 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4928b7c2017-06-20 12:57:39 -04004242 handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004243}
4244
4245void Context::renderbufferStorageMultisample(GLenum target,
4246 GLsizei samples,
4247 GLenum internalformat,
4248 GLsizei width,
4249 GLsizei height)
4250{
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004251 // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format.
4252 GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat);
Jamie Madille8fb6402017-02-14 17:56:40 -05004253
4254 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
Jamie Madill4e0e6f82017-02-17 11:06:03 -05004255 handleError(
Jamie Madill4928b7c2017-06-20 12:57:39 -04004256 renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height));
Jamie Madille8fb6402017-02-14 17:56:40 -05004257}
4258
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004259void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values)
4260{
Jamie Madill70b5bb02017-08-28 13:32:37 -04004261 const Sync *syncObject = getSync(sync);
Geoff Lang82483b92017-04-11 15:33:00 -04004262 handleError(QuerySynciv(syncObject, pname, bufSize, length, values));
Geoff Lang38f2cfb2017-04-11 15:23:08 -04004263}
4264
JiangYizhoue18e6392017-02-20 10:32:23 +08004265void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params)
4266{
4267 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4268 QueryFramebufferParameteriv(framebuffer, pname, params);
4269}
4270
Jiajia Qin5451d532017-11-16 17:16:34 +08004271void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
JiangYizhoue18e6392017-02-20 10:32:23 +08004272{
4273 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4274 SetFramebufferParameteri(framebuffer, pname, param);
4275}
4276
Jamie Madillb3f26b92017-07-19 15:07:41 -04004277Error Context::getScratchBuffer(size_t requstedSizeBytes,
4278 angle::MemoryBuffer **scratchBufferOut) const
Jamie Madille14951e2017-03-09 18:55:16 -05004279{
Jamie Madillb3f26b92017-07-19 15:07:41 -04004280 if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut))
4281 {
4282 return OutOfMemory() << "Failed to allocate internal buffer.";
4283 }
4284 return NoError();
4285}
4286
4287Error Context::getZeroFilledBuffer(size_t requstedSizeBytes,
4288 angle::MemoryBuffer **zeroBufferOut) const
4289{
4290 if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0))
Jamie Madille14951e2017-03-09 18:55:16 -05004291 {
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004292 return OutOfMemory() << "Failed to allocate internal buffer.";
Jamie Madille14951e2017-03-09 18:55:16 -05004293 }
Yuly Novikovc4d18aa2017-03-09 18:45:02 -05004294 return NoError();
Jamie Madille14951e2017-03-09 18:55:16 -05004295}
4296
Xinghua Cao10a4d432017-11-28 14:46:26 +08004297Error Context::prepareForDispatch()
4298{
4299 syncRendererState(mComputeDirtyBits, mComputeDirtyObjects);
4300
4301 if (isRobustResourceInitEnabled())
4302 {
4303 ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this));
4304 }
4305
4306 return NoError();
4307}
4308
Xinghua Cao2b396592017-03-29 15:36:04 +08004309void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
4310{
4311 if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u)
4312 {
4313 return;
4314 }
4315
Xinghua Cao10a4d432017-11-28 14:46:26 +08004316 ANGLE_CONTEXT_TRY(prepareForDispatch());
Jamie Madill71c88b32017-09-14 22:20:29 -04004317 handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ));
Xinghua Cao2b396592017-03-29 15:36:04 +08004318}
4319
Jiajia Qin5451d532017-11-16 17:16:34 +08004320void Context::dispatchComputeIndirect(GLintptr indirect)
4321{
Qin Jiajia62fcf622017-11-30 16:16:12 +08004322 ANGLE_CONTEXT_TRY(prepareForDispatch());
4323 handleError(mImplementation->dispatchComputeIndirect(this, indirect));
Jiajia Qin5451d532017-11-16 17:16:34 +08004324}
4325
JiangYizhou165361c2017-06-07 14:56:57 +08004326void Context::texStorage2D(GLenum target,
4327 GLsizei levels,
4328 GLenum internalFormat,
4329 GLsizei width,
4330 GLsizei height)
4331{
4332 Extents size(width, height, 1);
4333 Texture *texture = getTargetTexture(target);
4334 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4335}
4336
4337void Context::texStorage3D(GLenum target,
4338 GLsizei levels,
4339 GLenum internalFormat,
4340 GLsizei width,
4341 GLsizei height,
4342 GLsizei depth)
4343{
4344 Extents size(width, height, depth);
4345 Texture *texture = getTargetTexture(target);
4346 handleError(texture->setStorage(this, target, levels, internalFormat, size));
4347}
4348
Jiajia Qin5451d532017-11-16 17:16:34 +08004349void Context::memoryBarrier(GLbitfield barriers)
4350{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004351 handleError(mImplementation->memoryBarrier(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004352}
4353
4354void Context::memoryBarrierByRegion(GLbitfield barriers)
4355{
Xinghua Cao89c422a2017-11-29 18:24:20 +08004356 handleError(mImplementation->memoryBarrierByRegion(this, barriers));
Jiajia Qin5451d532017-11-16 17:16:34 +08004357}
4358
Jamie Madillc1d770e2017-04-13 17:31:24 -04004359GLenum Context::checkFramebufferStatus(GLenum target)
4360{
4361 Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target);
4362 ASSERT(framebuffer);
4363
4364 return framebuffer->checkStatus(this);
4365}
4366
4367void Context::compileShader(GLuint shader)
4368{
4369 Shader *shaderObject = GetValidShader(this, shader);
4370 if (!shaderObject)
4371 {
4372 return;
4373 }
4374 shaderObject->compile(this);
4375}
4376
4377void Context::deleteBuffers(GLsizei n, const GLuint *buffers)
4378{
4379 for (int i = 0; i < n; i++)
4380 {
4381 deleteBuffer(buffers[i]);
4382 }
4383}
4384
4385void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers)
4386{
4387 for (int i = 0; i < n; i++)
4388 {
4389 if (framebuffers[i] != 0)
4390 {
4391 deleteFramebuffer(framebuffers[i]);
4392 }
4393 }
4394}
4395
4396void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers)
4397{
4398 for (int i = 0; i < n; i++)
4399 {
4400 deleteRenderbuffer(renderbuffers[i]);
4401 }
4402}
4403
4404void Context::deleteTextures(GLsizei n, const GLuint *textures)
4405{
4406 for (int i = 0; i < n; i++)
4407 {
4408 if (textures[i] != 0)
4409 {
4410 deleteTexture(textures[i]);
4411 }
4412 }
4413}
4414
4415void Context::detachShader(GLuint program, GLuint shader)
4416{
4417 Program *programObject = getProgram(program);
4418 ASSERT(programObject);
4419
4420 Shader *shaderObject = getShader(shader);
4421 ASSERT(shaderObject);
4422
4423 programObject->detachShader(this, shaderObject);
4424}
4425
4426void Context::genBuffers(GLsizei n, GLuint *buffers)
4427{
4428 for (int i = 0; i < n; i++)
4429 {
4430 buffers[i] = createBuffer();
4431 }
4432}
4433
4434void Context::genFramebuffers(GLsizei n, GLuint *framebuffers)
4435{
4436 for (int i = 0; i < n; i++)
4437 {
4438 framebuffers[i] = createFramebuffer();
4439 }
4440}
4441
4442void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers)
4443{
4444 for (int i = 0; i < n; i++)
4445 {
4446 renderbuffers[i] = createRenderbuffer();
4447 }
4448}
4449
4450void Context::genTextures(GLsizei n, GLuint *textures)
4451{
4452 for (int i = 0; i < n; i++)
4453 {
4454 textures[i] = createTexture();
4455 }
4456}
4457
4458void Context::getActiveAttrib(GLuint program,
4459 GLuint index,
4460 GLsizei bufsize,
4461 GLsizei *length,
4462 GLint *size,
4463 GLenum *type,
4464 GLchar *name)
4465{
4466 Program *programObject = getProgram(program);
4467 ASSERT(programObject);
4468 programObject->getActiveAttribute(index, bufsize, length, size, type, name);
4469}
4470
4471void Context::getActiveUniform(GLuint program,
4472 GLuint index,
4473 GLsizei bufsize,
4474 GLsizei *length,
4475 GLint *size,
4476 GLenum *type,
4477 GLchar *name)
4478{
4479 Program *programObject = getProgram(program);
4480 ASSERT(programObject);
4481 programObject->getActiveUniform(index, bufsize, length, size, type, name);
4482}
4483
4484void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders)
4485{
4486 Program *programObject = getProgram(program);
4487 ASSERT(programObject);
4488 programObject->getAttachedShaders(maxcount, count, shaders);
4489}
4490
4491GLint Context::getAttribLocation(GLuint program, const GLchar *name)
4492{
4493 Program *programObject = getProgram(program);
4494 ASSERT(programObject);
4495 return programObject->getAttributeLocation(name);
4496}
4497
4498void Context::getBooleanv(GLenum pname, GLboolean *params)
4499{
4500 GLenum nativeType;
4501 unsigned int numParams = 0;
4502 getQueryParameterInfo(pname, &nativeType, &numParams);
4503
4504 if (nativeType == GL_BOOL)
4505 {
4506 getBooleanvImpl(pname, params);
4507 }
4508 else
4509 {
4510 CastStateValues(this, nativeType, pname, numParams, params);
4511 }
4512}
4513
4514void Context::getFloatv(GLenum pname, GLfloat *params)
4515{
4516 GLenum nativeType;
4517 unsigned int numParams = 0;
4518 getQueryParameterInfo(pname, &nativeType, &numParams);
4519
4520 if (nativeType == GL_FLOAT)
4521 {
4522 getFloatvImpl(pname, params);
4523 }
4524 else
4525 {
4526 CastStateValues(this, nativeType, pname, numParams, params);
4527 }
4528}
4529
4530void Context::getIntegerv(GLenum pname, GLint *params)
4531{
4532 GLenum nativeType;
4533 unsigned int numParams = 0;
4534 getQueryParameterInfo(pname, &nativeType, &numParams);
4535
4536 if (nativeType == GL_INT)
4537 {
4538 getIntegervImpl(pname, params);
4539 }
4540 else
4541 {
4542 CastStateValues(this, nativeType, pname, numParams, params);
4543 }
4544}
4545
4546void Context::getProgramiv(GLuint program, GLenum pname, GLint *params)
4547{
4548 Program *programObject = getProgram(program);
4549 ASSERT(programObject);
Jamie Madillffe00c02017-06-27 16:26:55 -04004550 QueryProgramiv(this, programObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004551}
4552
Jiajia Qin5451d532017-11-16 17:16:34 +08004553void Context::getProgramPipelineiv(GLuint pipeline, GLenum pname, GLint *params)
4554{
4555 UNIMPLEMENTED();
4556}
4557
Jamie Madillbe849e42017-05-02 15:49:00 -04004558void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog)
Jamie Madillc1d770e2017-04-13 17:31:24 -04004559{
4560 Program *programObject = getProgram(program);
4561 ASSERT(programObject);
4562 programObject->getInfoLog(bufsize, length, infolog);
4563}
4564
Jiajia Qin5451d532017-11-16 17:16:34 +08004565void Context::getProgramPipelineInfoLog(GLuint pipeline,
4566 GLsizei bufSize,
4567 GLsizei *length,
4568 GLchar *infoLog)
4569{
4570 UNIMPLEMENTED();
4571}
4572
Jamie Madillc1d770e2017-04-13 17:31:24 -04004573void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params)
4574{
4575 Shader *shaderObject = getShader(shader);
4576 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004577 QueryShaderiv(this, shaderObject, pname, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004578}
4579
4580void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog)
4581{
4582 Shader *shaderObject = getShader(shader);
4583 ASSERT(shaderObject);
Jamie Madillbd044ed2017-06-05 12:59:21 -04004584 shaderObject->getInfoLog(this, bufsize, length, infolog);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004585}
4586
4587void Context::getShaderPrecisionFormat(GLenum shadertype,
4588 GLenum precisiontype,
4589 GLint *range,
4590 GLint *precision)
4591{
4592 // TODO(jmadill): Compute shaders.
4593
4594 switch (shadertype)
4595 {
4596 case GL_VERTEX_SHADER:
4597 switch (precisiontype)
4598 {
4599 case GL_LOW_FLOAT:
4600 mCaps.vertexLowpFloat.get(range, precision);
4601 break;
4602 case GL_MEDIUM_FLOAT:
4603 mCaps.vertexMediumpFloat.get(range, precision);
4604 break;
4605 case GL_HIGH_FLOAT:
4606 mCaps.vertexHighpFloat.get(range, precision);
4607 break;
4608
4609 case GL_LOW_INT:
4610 mCaps.vertexLowpInt.get(range, precision);
4611 break;
4612 case GL_MEDIUM_INT:
4613 mCaps.vertexMediumpInt.get(range, precision);
4614 break;
4615 case GL_HIGH_INT:
4616 mCaps.vertexHighpInt.get(range, precision);
4617 break;
4618
4619 default:
4620 UNREACHABLE();
4621 return;
4622 }
4623 break;
4624
4625 case GL_FRAGMENT_SHADER:
4626 switch (precisiontype)
4627 {
4628 case GL_LOW_FLOAT:
4629 mCaps.fragmentLowpFloat.get(range, precision);
4630 break;
4631 case GL_MEDIUM_FLOAT:
4632 mCaps.fragmentMediumpFloat.get(range, precision);
4633 break;
4634 case GL_HIGH_FLOAT:
4635 mCaps.fragmentHighpFloat.get(range, precision);
4636 break;
4637
4638 case GL_LOW_INT:
4639 mCaps.fragmentLowpInt.get(range, precision);
4640 break;
4641 case GL_MEDIUM_INT:
4642 mCaps.fragmentMediumpInt.get(range, precision);
4643 break;
4644 case GL_HIGH_INT:
4645 mCaps.fragmentHighpInt.get(range, precision);
4646 break;
4647
4648 default:
4649 UNREACHABLE();
4650 return;
4651 }
4652 break;
4653
4654 default:
4655 UNREACHABLE();
4656 return;
4657 }
4658}
4659
4660void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source)
4661{
4662 Shader *shaderObject = getShader(shader);
4663 ASSERT(shaderObject);
4664 shaderObject->getSource(bufsize, length, source);
4665}
4666
4667void Context::getUniformfv(GLuint program, GLint location, GLfloat *params)
4668{
4669 Program *programObject = getProgram(program);
4670 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004671 programObject->getUniformfv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004672}
4673
4674void Context::getUniformiv(GLuint program, GLint location, GLint *params)
4675{
4676 Program *programObject = getProgram(program);
4677 ASSERT(programObject);
Jamie Madill54164b02017-08-28 15:17:37 -04004678 programObject->getUniformiv(this, location, params);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004679}
4680
4681GLint Context::getUniformLocation(GLuint program, const GLchar *name)
4682{
4683 Program *programObject = getProgram(program);
4684 ASSERT(programObject);
4685 return programObject->getUniformLocation(name);
4686}
4687
4688GLboolean Context::isBuffer(GLuint buffer)
4689{
4690 if (buffer == 0)
4691 {
4692 return GL_FALSE;
4693 }
4694
4695 return (getBuffer(buffer) ? GL_TRUE : GL_FALSE);
4696}
4697
4698GLboolean Context::isEnabled(GLenum cap)
4699{
4700 return mGLState.getEnableFeature(cap);
4701}
4702
4703GLboolean Context::isFramebuffer(GLuint framebuffer)
4704{
4705 if (framebuffer == 0)
4706 {
4707 return GL_FALSE;
4708 }
4709
4710 return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE);
4711}
4712
4713GLboolean Context::isProgram(GLuint program)
4714{
4715 if (program == 0)
4716 {
4717 return GL_FALSE;
4718 }
4719
4720 return (getProgram(program) ? GL_TRUE : GL_FALSE);
4721}
4722
4723GLboolean Context::isRenderbuffer(GLuint renderbuffer)
4724{
4725 if (renderbuffer == 0)
4726 {
4727 return GL_FALSE;
4728 }
4729
4730 return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE);
4731}
4732
4733GLboolean Context::isShader(GLuint shader)
4734{
4735 if (shader == 0)
4736 {
4737 return GL_FALSE;
4738 }
4739
4740 return (getShader(shader) ? GL_TRUE : GL_FALSE);
4741}
4742
4743GLboolean Context::isTexture(GLuint texture)
4744{
4745 if (texture == 0)
4746 {
4747 return GL_FALSE;
4748 }
4749
4750 return (getTexture(texture) ? GL_TRUE : GL_FALSE);
4751}
4752
4753void Context::linkProgram(GLuint program)
4754{
4755 Program *programObject = getProgram(program);
4756 ASSERT(programObject);
4757 handleError(programObject->link(this));
Martin Radev0abb7a22017-08-28 15:34:45 +03004758 mGLState.onProgramExecutableChange(programObject);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004759}
4760
4761void Context::releaseShaderCompiler()
4762{
Jamie Madill4928b7c2017-06-20 12:57:39 -04004763 mCompiler.set(this, nullptr);
Jamie Madillc1d770e2017-04-13 17:31:24 -04004764}
4765
4766void Context::shaderBinary(GLsizei n,
4767 const GLuint *shaders,
4768 GLenum binaryformat,
Jamie Madill876429b2017-04-20 15:46:24 -04004769 const void *binary,
Jamie Madillc1d770e2017-04-13 17:31:24 -04004770 GLsizei length)
4771{
4772 // No binary shader formats are supported.
4773 UNIMPLEMENTED();
4774}
4775
4776void Context::shaderSource(GLuint shader,
4777 GLsizei count,
4778 const GLchar *const *string,
4779 const GLint *length)
4780{
4781 Shader *shaderObject = getShader(shader);
4782 ASSERT(shaderObject);
4783 shaderObject->setSource(count, string, length);
4784}
4785
4786void Context::stencilFunc(GLenum func, GLint ref, GLuint mask)
4787{
4788 stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask);
4789}
4790
4791void Context::stencilMask(GLuint mask)
4792{
4793 stencilMaskSeparate(GL_FRONT_AND_BACK, mask);
4794}
4795
4796void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass)
4797{
4798 stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass);
4799}
4800
4801void Context::uniform1f(GLint location, GLfloat x)
4802{
4803 Program *program = mGLState.getProgram();
4804 program->setUniform1fv(location, 1, &x);
4805}
4806
4807void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v)
4808{
4809 Program *program = mGLState.getProgram();
4810 program->setUniform1fv(location, count, v);
4811}
4812
4813void Context::uniform1i(GLint location, GLint x)
4814{
4815 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004816 if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged)
4817 {
4818 mGLState.setObjectDirty(GL_PROGRAM);
4819 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004820}
4821
4822void Context::uniform1iv(GLint location, GLsizei count, const GLint *v)
4823{
4824 Program *program = mGLState.getProgram();
Jamie Madill81c2e252017-09-09 23:32:46 -04004825 if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged)
4826 {
4827 mGLState.setObjectDirty(GL_PROGRAM);
4828 }
Jamie Madillc1d770e2017-04-13 17:31:24 -04004829}
4830
4831void Context::uniform2f(GLint location, GLfloat x, GLfloat y)
4832{
4833 GLfloat xy[2] = {x, y};
4834 Program *program = mGLState.getProgram();
4835 program->setUniform2fv(location, 1, xy);
4836}
4837
4838void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v)
4839{
4840 Program *program = mGLState.getProgram();
4841 program->setUniform2fv(location, count, v);
4842}
4843
4844void Context::uniform2i(GLint location, GLint x, GLint y)
4845{
4846 GLint xy[2] = {x, y};
4847 Program *program = mGLState.getProgram();
4848 program->setUniform2iv(location, 1, xy);
4849}
4850
4851void Context::uniform2iv(GLint location, GLsizei count, const GLint *v)
4852{
4853 Program *program = mGLState.getProgram();
4854 program->setUniform2iv(location, count, v);
4855}
4856
4857void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
4858{
4859 GLfloat xyz[3] = {x, y, z};
4860 Program *program = mGLState.getProgram();
4861 program->setUniform3fv(location, 1, xyz);
4862}
4863
4864void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v)
4865{
4866 Program *program = mGLState.getProgram();
4867 program->setUniform3fv(location, count, v);
4868}
4869
4870void Context::uniform3i(GLint location, GLint x, GLint y, GLint z)
4871{
4872 GLint xyz[3] = {x, y, z};
4873 Program *program = mGLState.getProgram();
4874 program->setUniform3iv(location, 1, xyz);
4875}
4876
4877void Context::uniform3iv(GLint location, GLsizei count, const GLint *v)
4878{
4879 Program *program = mGLState.getProgram();
4880 program->setUniform3iv(location, count, v);
4881}
4882
4883void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
4884{
4885 GLfloat xyzw[4] = {x, y, z, w};
4886 Program *program = mGLState.getProgram();
4887 program->setUniform4fv(location, 1, xyzw);
4888}
4889
4890void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v)
4891{
4892 Program *program = mGLState.getProgram();
4893 program->setUniform4fv(location, count, v);
4894}
4895
4896void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
4897{
4898 GLint xyzw[4] = {x, y, z, w};
4899 Program *program = mGLState.getProgram();
4900 program->setUniform4iv(location, 1, xyzw);
4901}
4902
4903void Context::uniform4iv(GLint location, GLsizei count, const GLint *v)
4904{
4905 Program *program = mGLState.getProgram();
4906 program->setUniform4iv(location, count, v);
4907}
4908
4909void Context::uniformMatrix2fv(GLint location,
4910 GLsizei count,
4911 GLboolean transpose,
4912 const GLfloat *value)
4913{
4914 Program *program = mGLState.getProgram();
4915 program->setUniformMatrix2fv(location, count, transpose, value);
4916}
4917
4918void Context::uniformMatrix3fv(GLint location,
4919 GLsizei count,
4920 GLboolean transpose,
4921 const GLfloat *value)
4922{
4923 Program *program = mGLState.getProgram();
4924 program->setUniformMatrix3fv(location, count, transpose, value);
4925}
4926
4927void Context::uniformMatrix4fv(GLint location,
4928 GLsizei count,
4929 GLboolean transpose,
4930 const GLfloat *value)
4931{
4932 Program *program = mGLState.getProgram();
4933 program->setUniformMatrix4fv(location, count, transpose, value);
4934}
4935
4936void Context::validateProgram(GLuint program)
4937{
4938 Program *programObject = getProgram(program);
4939 ASSERT(programObject);
4940 programObject->validate(mCaps);
4941}
4942
Jiajia Qin5451d532017-11-16 17:16:34 +08004943void Context::validateProgramPipeline(GLuint pipeline)
4944{
4945 UNIMPLEMENTED();
4946}
4947
Jamie Madilld04908b2017-06-09 14:15:35 -04004948void Context::getProgramBinary(GLuint program,
4949 GLsizei bufSize,
4950 GLsizei *length,
4951 GLenum *binaryFormat,
4952 void *binary)
4953{
4954 Program *programObject = getProgram(program);
4955 ASSERT(programObject != nullptr);
4956
4957 handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length));
4958}
4959
4960void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length)
4961{
4962 Program *programObject = getProgram(program);
4963 ASSERT(programObject != nullptr);
Jamie Madillb6664922017-07-25 12:55:04 -04004964
Jamie Madilld04908b2017-06-09 14:15:35 -04004965 handleError(programObject->loadBinary(this, binaryFormat, binary, length));
4966}
4967
Jamie Madillff325f12017-08-26 15:06:05 -04004968void Context::uniform1ui(GLint location, GLuint v0)
4969{
4970 Program *program = mGLState.getProgram();
4971 program->setUniform1uiv(location, 1, &v0);
4972}
4973
4974void Context::uniform2ui(GLint location, GLuint v0, GLuint v1)
4975{
4976 Program *program = mGLState.getProgram();
4977 const GLuint xy[] = {v0, v1};
4978 program->setUniform2uiv(location, 1, xy);
4979}
4980
4981void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2)
4982{
4983 Program *program = mGLState.getProgram();
4984 const GLuint xyz[] = {v0, v1, v2};
4985 program->setUniform3uiv(location, 1, xyz);
4986}
4987
4988void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3)
4989{
4990 Program *program = mGLState.getProgram();
4991 const GLuint xyzw[] = {v0, v1, v2, v3};
4992 program->setUniform4uiv(location, 1, xyzw);
4993}
4994
4995void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value)
4996{
4997 Program *program = mGLState.getProgram();
4998 program->setUniform1uiv(location, count, value);
4999}
5000void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value)
5001{
5002 Program *program = mGLState.getProgram();
5003 program->setUniform2uiv(location, count, value);
5004}
5005
5006void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value)
5007{
5008 Program *program = mGLState.getProgram();
5009 program->setUniform3uiv(location, count, value);
5010}
5011
5012void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value)
5013{
5014 Program *program = mGLState.getProgram();
5015 program->setUniform4uiv(location, count, value);
5016}
5017
Jamie Madillf0e04492017-08-26 15:28:42 -04005018void Context::genQueries(GLsizei n, GLuint *ids)
5019{
5020 for (GLsizei i = 0; i < n; i++)
5021 {
5022 GLuint handle = mQueryHandleAllocator.allocate();
5023 mQueryMap.assign(handle, nullptr);
5024 ids[i] = handle;
5025 }
5026}
5027
5028void Context::deleteQueries(GLsizei n, const GLuint *ids)
5029{
5030 for (int i = 0; i < n; i++)
5031 {
5032 GLuint query = ids[i];
5033
5034 Query *queryObject = nullptr;
5035 if (mQueryMap.erase(query, &queryObject))
5036 {
5037 mQueryHandleAllocator.release(query);
5038 if (queryObject)
5039 {
5040 queryObject->release(this);
5041 }
5042 }
5043 }
5044}
5045
5046GLboolean Context::isQuery(GLuint id)
5047{
5048 return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE;
5049}
5050
Jamie Madillc8c95812017-08-26 18:40:09 -04005051void Context::uniformMatrix2x3fv(GLint location,
5052 GLsizei count,
5053 GLboolean transpose,
5054 const GLfloat *value)
5055{
5056 Program *program = mGLState.getProgram();
5057 program->setUniformMatrix2x3fv(location, count, transpose, value);
5058}
5059
5060void Context::uniformMatrix3x2fv(GLint location,
5061 GLsizei count,
5062 GLboolean transpose,
5063 const GLfloat *value)
5064{
5065 Program *program = mGLState.getProgram();
5066 program->setUniformMatrix3x2fv(location, count, transpose, value);
5067}
5068
5069void Context::uniformMatrix2x4fv(GLint location,
5070 GLsizei count,
5071 GLboolean transpose,
5072 const GLfloat *value)
5073{
5074 Program *program = mGLState.getProgram();
5075 program->setUniformMatrix2x4fv(location, count, transpose, value);
5076}
5077
5078void Context::uniformMatrix4x2fv(GLint location,
5079 GLsizei count,
5080 GLboolean transpose,
5081 const GLfloat *value)
5082{
5083 Program *program = mGLState.getProgram();
5084 program->setUniformMatrix4x2fv(location, count, transpose, value);
5085}
5086
5087void Context::uniformMatrix3x4fv(GLint location,
5088 GLsizei count,
5089 GLboolean transpose,
5090 const GLfloat *value)
5091{
5092 Program *program = mGLState.getProgram();
5093 program->setUniformMatrix3x4fv(location, count, transpose, value);
5094}
5095
5096void Context::uniformMatrix4x3fv(GLint location,
5097 GLsizei count,
5098 GLboolean transpose,
5099 const GLfloat *value)
5100{
5101 Program *program = mGLState.getProgram();
5102 program->setUniformMatrix4x3fv(location, count, transpose, value);
5103}
5104
Jamie Madilld7576732017-08-26 18:49:50 -04005105void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays)
5106{
5107 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5108 {
5109 GLuint vertexArray = arrays[arrayIndex];
5110
5111 if (arrays[arrayIndex] != 0)
5112 {
5113 VertexArray *vertexArrayObject = nullptr;
5114 if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject))
5115 {
5116 if (vertexArrayObject != nullptr)
5117 {
5118 detachVertexArray(vertexArray);
5119 vertexArrayObject->onDestroy(this);
5120 }
5121
5122 mVertexArrayHandleAllocator.release(vertexArray);
5123 }
5124 }
5125 }
5126}
5127
5128void Context::genVertexArrays(GLsizei n, GLuint *arrays)
5129{
5130 for (int arrayIndex = 0; arrayIndex < n; arrayIndex++)
5131 {
5132 GLuint vertexArray = mVertexArrayHandleAllocator.allocate();
5133 mVertexArrayMap.assign(vertexArray, nullptr);
5134 arrays[arrayIndex] = vertexArray;
5135 }
5136}
5137
5138bool Context::isVertexArray(GLuint array)
5139{
5140 if (array == 0)
5141 {
5142 return GL_FALSE;
5143 }
5144
5145 VertexArray *vao = getVertexArray(array);
5146 return (vao != nullptr ? GL_TRUE : GL_FALSE);
5147}
5148
Jamie Madillf0dcb8b2017-08-26 19:05:13 -04005149void Context::endTransformFeedback()
5150{
5151 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5152 transformFeedback->end(this);
5153}
5154
5155void Context::transformFeedbackVaryings(GLuint program,
5156 GLsizei count,
5157 const GLchar *const *varyings,
5158 GLenum bufferMode)
5159{
5160 Program *programObject = getProgram(program);
5161 ASSERT(programObject);
5162 programObject->setTransformFeedbackVaryings(count, varyings, bufferMode);
5163}
5164
5165void Context::getTransformFeedbackVarying(GLuint program,
5166 GLuint index,
5167 GLsizei bufSize,
5168 GLsizei *length,
5169 GLsizei *size,
5170 GLenum *type,
5171 GLchar *name)
5172{
5173 Program *programObject = getProgram(program);
5174 ASSERT(programObject);
5175 programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name);
5176}
5177
5178void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids)
5179{
5180 for (int i = 0; i < n; i++)
5181 {
5182 GLuint transformFeedback = ids[i];
5183 if (transformFeedback == 0)
5184 {
5185 continue;
5186 }
5187
5188 TransformFeedback *transformFeedbackObject = nullptr;
5189 if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject))
5190 {
5191 if (transformFeedbackObject != nullptr)
5192 {
5193 detachTransformFeedback(transformFeedback);
5194 transformFeedbackObject->release(this);
5195 }
5196
5197 mTransformFeedbackHandleAllocator.release(transformFeedback);
5198 }
5199 }
5200}
5201
5202void Context::genTransformFeedbacks(GLsizei n, GLuint *ids)
5203{
5204 for (int i = 0; i < n; i++)
5205 {
5206 GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate();
5207 mTransformFeedbackMap.assign(transformFeedback, nullptr);
5208 ids[i] = transformFeedback;
5209 }
5210}
5211
5212bool Context::isTransformFeedback(GLuint id)
5213{
5214 if (id == 0)
5215 {
5216 // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback
5217 // returns FALSE
5218 return GL_FALSE;
5219 }
5220
5221 const TransformFeedback *transformFeedback = getTransformFeedback(id);
5222 return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE);
5223}
5224
5225void Context::pauseTransformFeedback()
5226{
5227 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5228 transformFeedback->pause();
5229}
5230
5231void Context::resumeTransformFeedback()
5232{
5233 TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback();
5234 transformFeedback->resume();
5235}
5236
Jamie Madill12e957f2017-08-26 21:42:26 -04005237void Context::getUniformuiv(GLuint program, GLint location, GLuint *params)
5238{
5239 const Program *programObject = getProgram(program);
Jamie Madill54164b02017-08-28 15:17:37 -04005240 programObject->getUniformuiv(this, location, params);
Jamie Madill12e957f2017-08-26 21:42:26 -04005241}
5242
5243GLint Context::getFragDataLocation(GLuint program, const GLchar *name)
5244{
5245 const Program *programObject = getProgram(program);
5246 return programObject->getFragDataLocation(name);
5247}
5248
5249void Context::getUniformIndices(GLuint program,
5250 GLsizei uniformCount,
5251 const GLchar *const *uniformNames,
5252 GLuint *uniformIndices)
5253{
5254 const Program *programObject = getProgram(program);
5255 if (!programObject->isLinked())
5256 {
5257 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5258 {
5259 uniformIndices[uniformId] = GL_INVALID_INDEX;
5260 }
5261 }
5262 else
5263 {
5264 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5265 {
5266 uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]);
5267 }
5268 }
5269}
5270
5271void Context::getActiveUniformsiv(GLuint program,
5272 GLsizei uniformCount,
5273 const GLuint *uniformIndices,
5274 GLenum pname,
5275 GLint *params)
5276{
5277 const Program *programObject = getProgram(program);
5278 for (int uniformId = 0; uniformId < uniformCount; uniformId++)
5279 {
5280 const GLuint index = uniformIndices[uniformId];
jchen10baf5d942017-08-28 20:45:48 +08005281 params[uniformId] = GetUniformResourceProperty(programObject, index, pname);
Jamie Madill12e957f2017-08-26 21:42:26 -04005282 }
5283}
5284
5285GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName)
5286{
5287 const Program *programObject = getProgram(program);
5288 return programObject->getUniformBlockIndex(uniformBlockName);
5289}
5290
5291void Context::getActiveUniformBlockiv(GLuint program,
5292 GLuint uniformBlockIndex,
5293 GLenum pname,
5294 GLint *params)
5295{
5296 const Program *programObject = getProgram(program);
5297 QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params);
5298}
5299
5300void Context::getActiveUniformBlockName(GLuint program,
5301 GLuint uniformBlockIndex,
5302 GLsizei bufSize,
5303 GLsizei *length,
5304 GLchar *uniformBlockName)
5305{
5306 const Program *programObject = getProgram(program);
5307 programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName);
5308}
5309
5310void Context::uniformBlockBinding(GLuint program,
5311 GLuint uniformBlockIndex,
5312 GLuint uniformBlockBinding)
5313{
5314 Program *programObject = getProgram(program);
5315 programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding);
5316}
5317
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005318GLsync Context::fenceSync(GLenum condition, GLbitfield flags)
5319{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005320 GLuint handle = mState.mSyncs->createSync(mImplementation.get());
5321 GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle));
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005322
Jamie Madill70b5bb02017-08-28 13:32:37 -04005323 Sync *syncObject = getSync(syncHandle);
5324 Error error = syncObject->set(condition, flags);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005325 if (error.isError())
5326 {
Jamie Madill70b5bb02017-08-28 13:32:37 -04005327 deleteSync(syncHandle);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005328 handleError(error);
5329 return nullptr;
5330 }
5331
Jamie Madill70b5bb02017-08-28 13:32:37 -04005332 return syncHandle;
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005333}
5334
5335GLboolean Context::isSync(GLsync sync)
5336{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005337 return (getSync(sync) != nullptr);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005338}
5339
5340GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5341{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005342 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005343
5344 GLenum result = GL_WAIT_FAILED;
5345 handleError(syncObject->clientWait(flags, timeout, &result));
5346 return result;
5347}
5348
5349void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout)
5350{
Jamie Madill70b5bb02017-08-28 13:32:37 -04005351 Sync *syncObject = getSync(sync);
Jamie Madill7f0c5a42017-08-26 22:43:26 -04005352 handleError(syncObject->serverWait(flags, timeout));
5353}
5354
5355void Context::getInteger64v(GLenum pname, GLint64 *params)
5356{
5357 GLenum nativeType = GL_NONE;
5358 unsigned int numParams = 0;
5359 getQueryParameterInfo(pname, &nativeType, &numParams);
5360
5361 if (nativeType == GL_INT_64_ANGLEX)
5362 {
5363 getInteger64vImpl(pname, params);
5364 }
5365 else
5366 {
5367 CastStateValues(this, nativeType, pname, numParams, params);
5368 }
5369}
5370
Corentin Wallez336129f2017-10-17 15:55:40 -04005371void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params)
Jamie Madill3ef140a2017-08-26 23:11:21 -04005372{
5373 Buffer *buffer = mGLState.getTargetBuffer(target);
5374 QueryBufferParameteri64v(buffer, pname, params);
5375}
5376
5377void Context::genSamplers(GLsizei count, GLuint *samplers)
5378{
5379 for (int i = 0; i < count; i++)
5380 {
5381 samplers[i] = mState.mSamplers->createSampler();
5382 }
5383}
5384
5385void Context::deleteSamplers(GLsizei count, const GLuint *samplers)
5386{
5387 for (int i = 0; i < count; i++)
5388 {
5389 GLuint sampler = samplers[i];
5390
5391 if (mState.mSamplers->getSampler(sampler))
5392 {
5393 detachSampler(sampler);
5394 }
5395
5396 mState.mSamplers->deleteObject(this, sampler);
5397 }
5398}
5399
5400void Context::getInternalformativ(GLenum target,
5401 GLenum internalformat,
5402 GLenum pname,
5403 GLsizei bufSize,
5404 GLint *params)
5405{
5406 const TextureCaps &formatCaps = mTextureCaps.get(internalformat);
5407 QueryInternalFormativ(formatCaps, pname, bufSize, params);
5408}
5409
Jiajia Qin5451d532017-11-16 17:16:34 +08005410void Context::programUniform1i(GLuint program, GLint location, GLint v0)
5411{
5412 programUniform1iv(program, location, 1, &v0);
5413}
5414
5415void Context::programUniform2i(GLuint program, GLint location, GLint v0, GLint v1)
5416{
5417 GLint xy[2] = {v0, v1};
5418 programUniform2iv(program, location, 1, xy);
5419}
5420
5421void Context::programUniform3i(GLuint program, GLint location, GLint v0, GLint v1, GLint v2)
5422{
5423 GLint xyz[3] = {v0, v1, v2};
5424 programUniform3iv(program, location, 1, xyz);
5425}
5426
5427void Context::programUniform4i(GLuint program,
5428 GLint location,
5429 GLint v0,
5430 GLint v1,
5431 GLint v2,
5432 GLint v3)
5433{
5434 GLint xyzw[4] = {v0, v1, v2, v3};
5435 programUniform4iv(program, location, 1, xyzw);
5436}
5437
5438void Context::programUniform1ui(GLuint program, GLint location, GLuint v0)
5439{
5440 programUniform1uiv(program, location, 1, &v0);
5441}
5442
5443void Context::programUniform2ui(GLuint program, GLint location, GLuint v0, GLuint v1)
5444{
5445 GLuint xy[2] = {v0, v1};
5446 programUniform2uiv(program, location, 1, xy);
5447}
5448
5449void Context::programUniform3ui(GLuint program, GLint location, GLuint v0, GLuint v1, GLuint v2)
5450{
5451 GLuint xyz[3] = {v0, v1, v2};
5452 programUniform3uiv(program, location, 1, xyz);
5453}
5454
5455void Context::programUniform4ui(GLuint program,
5456 GLint location,
5457 GLuint v0,
5458 GLuint v1,
5459 GLuint v2,
5460 GLuint v3)
5461{
5462 GLuint xyzw[4] = {v0, v1, v2, v3};
5463 programUniform4uiv(program, location, 1, xyzw);
5464}
5465
5466void Context::programUniform1f(GLuint program, GLint location, GLfloat v0)
5467{
5468 programUniform1fv(program, location, 1, &v0);
5469}
5470
5471void Context::programUniform2f(GLuint program, GLint location, GLfloat v0, GLfloat v1)
5472{
5473 GLfloat xy[2] = {v0, v1};
5474 programUniform2fv(program, location, 1, xy);
5475}
5476
5477void Context::programUniform3f(GLuint program, GLint location, GLfloat v0, GLfloat v1, GLfloat v2)
5478{
5479 GLfloat xyz[3] = {v0, v1, v2};
5480 programUniform3fv(program, location, 1, xyz);
5481}
5482
5483void Context::programUniform4f(GLuint program,
5484 GLint location,
5485 GLfloat v0,
5486 GLfloat v1,
5487 GLfloat v2,
5488 GLfloat v3)
5489{
5490 GLfloat xyzw[4] = {v0, v1, v2, v3};
5491 programUniform4fv(program, location, 1, xyzw);
5492}
5493
Jamie Madill81c2e252017-09-09 23:32:46 -04005494void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5495{
5496 Program *programObject = getProgram(program);
5497 ASSERT(programObject);
5498 if (programObject->setUniform1iv(location, count, value) ==
5499 Program::SetUniformResult::SamplerChanged)
5500 {
5501 mGLState.setObjectDirty(GL_PROGRAM);
5502 }
5503}
5504
Jiajia Qin5451d532017-11-16 17:16:34 +08005505void Context::programUniform2iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5506{
5507 Program *programObject = getProgram(program);
5508 ASSERT(programObject);
5509 programObject->setUniform2iv(location, count, value);
5510}
5511
5512void Context::programUniform3iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5513{
5514 Program *programObject = getProgram(program);
5515 ASSERT(programObject);
5516 programObject->setUniform3iv(location, count, value);
5517}
5518
5519void Context::programUniform4iv(GLuint program, GLint location, GLsizei count, const GLint *value)
5520{
5521 Program *programObject = getProgram(program);
5522 ASSERT(programObject);
5523 programObject->setUniform4iv(location, count, value);
5524}
5525
5526void Context::programUniform1uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5527{
5528 Program *programObject = getProgram(program);
5529 ASSERT(programObject);
5530 programObject->setUniform1uiv(location, count, value);
5531}
5532
5533void Context::programUniform2uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5534{
5535 Program *programObject = getProgram(program);
5536 ASSERT(programObject);
5537 programObject->setUniform2uiv(location, count, value);
5538}
5539
5540void Context::programUniform3uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5541{
5542 Program *programObject = getProgram(program);
5543 ASSERT(programObject);
5544 programObject->setUniform3uiv(location, count, value);
5545}
5546
5547void Context::programUniform4uiv(GLuint program, GLint location, GLsizei count, const GLuint *value)
5548{
5549 Program *programObject = getProgram(program);
5550 ASSERT(programObject);
5551 programObject->setUniform4uiv(location, count, value);
5552}
5553
5554void Context::programUniform1fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5555{
5556 Program *programObject = getProgram(program);
5557 ASSERT(programObject);
5558 programObject->setUniform1fv(location, count, value);
5559}
5560
5561void Context::programUniform2fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5562{
5563 Program *programObject = getProgram(program);
5564 ASSERT(programObject);
5565 programObject->setUniform2fv(location, count, value);
5566}
5567
5568void Context::programUniform3fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5569{
5570 Program *programObject = getProgram(program);
5571 ASSERT(programObject);
5572 programObject->setUniform3fv(location, count, value);
5573}
5574
5575void Context::programUniform4fv(GLuint program, GLint location, GLsizei count, const GLfloat *value)
5576{
5577 Program *programObject = getProgram(program);
5578 ASSERT(programObject);
5579 programObject->setUniform4fv(location, count, value);
5580}
5581
5582void Context::programUniformMatrix2fv(GLuint program,
5583 GLint location,
5584 GLsizei count,
5585 GLboolean transpose,
5586 const GLfloat *value)
5587{
5588 Program *programObject = getProgram(program);
5589 ASSERT(programObject);
5590 programObject->setUniformMatrix2fv(location, count, transpose, value);
5591}
5592
5593void Context::programUniformMatrix3fv(GLuint program,
5594 GLint location,
5595 GLsizei count,
5596 GLboolean transpose,
5597 const GLfloat *value)
5598{
5599 Program *programObject = getProgram(program);
5600 ASSERT(programObject);
5601 programObject->setUniformMatrix3fv(location, count, transpose, value);
5602}
5603
5604void Context::programUniformMatrix4fv(GLuint program,
5605 GLint location,
5606 GLsizei count,
5607 GLboolean transpose,
5608 const GLfloat *value)
5609{
5610 Program *programObject = getProgram(program);
5611 ASSERT(programObject);
5612 programObject->setUniformMatrix4fv(location, count, transpose, value);
5613}
5614
5615void Context::programUniformMatrix2x3fv(GLuint program,
5616 GLint location,
5617 GLsizei count,
5618 GLboolean transpose,
5619 const GLfloat *value)
5620{
5621 Program *programObject = getProgram(program);
5622 ASSERT(programObject);
5623 programObject->setUniformMatrix2x3fv(location, count, transpose, value);
5624}
5625
5626void Context::programUniformMatrix3x2fv(GLuint program,
5627 GLint location,
5628 GLsizei count,
5629 GLboolean transpose,
5630 const GLfloat *value)
5631{
5632 Program *programObject = getProgram(program);
5633 ASSERT(programObject);
5634 programObject->setUniformMatrix3x2fv(location, count, transpose, value);
5635}
5636
5637void Context::programUniformMatrix2x4fv(GLuint program,
5638 GLint location,
5639 GLsizei count,
5640 GLboolean transpose,
5641 const GLfloat *value)
5642{
5643 Program *programObject = getProgram(program);
5644 ASSERT(programObject);
5645 programObject->setUniformMatrix2x4fv(location, count, transpose, value);
5646}
5647
5648void Context::programUniformMatrix4x2fv(GLuint program,
5649 GLint location,
5650 GLsizei count,
5651 GLboolean transpose,
5652 const GLfloat *value)
5653{
5654 Program *programObject = getProgram(program);
5655 ASSERT(programObject);
5656 programObject->setUniformMatrix4x2fv(location, count, transpose, value);
5657}
5658
5659void Context::programUniformMatrix3x4fv(GLuint program,
5660 GLint location,
5661 GLsizei count,
5662 GLboolean transpose,
5663 const GLfloat *value)
5664{
5665 Program *programObject = getProgram(program);
5666 ASSERT(programObject);
5667 programObject->setUniformMatrix3x4fv(location, count, transpose, value);
5668}
5669
5670void Context::programUniformMatrix4x3fv(GLuint program,
5671 GLint location,
5672 GLsizei count,
5673 GLboolean transpose,
5674 const GLfloat *value)
5675{
5676 Program *programObject = getProgram(program);
5677 ASSERT(programObject);
5678 programObject->setUniformMatrix4x3fv(location, count, transpose, value);
5679}
5680
Jamie Madill81c2e252017-09-09 23:32:46 -04005681void Context::onTextureChange(const Texture *texture)
5682{
5683 // Conservatively assume all textures are dirty.
5684 // TODO(jmadill): More fine-grained update.
5685 mGLState.setObjectDirty(GL_TEXTURE);
5686}
5687
Yunchao Hea336b902017-08-02 16:05:21 +08005688void Context::genProgramPipelines(GLsizei count, GLuint *pipelines)
5689{
5690 for (int i = 0; i < count; i++)
5691 {
5692 pipelines[i] = createProgramPipeline();
5693 }
5694}
5695
5696void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines)
5697{
5698 for (int i = 0; i < count; i++)
5699 {
5700 if (pipelines[i] != 0)
5701 {
5702 deleteProgramPipeline(pipelines[i]);
5703 }
5704 }
5705}
5706
5707GLboolean Context::isProgramPipeline(GLuint pipeline)
5708{
5709 if (pipeline == 0)
5710 {
5711 return GL_FALSE;
5712 }
5713
5714 return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE);
5715}
5716
Jamie Madill2b7bbc22017-12-21 17:30:38 -05005717void Context::finishFenceNV(GLuint fence)
5718{
5719 FenceNV *fenceObject = getFenceNV(fence);
5720
5721 ASSERT(fenceObject && fenceObject->isSet());
5722 handleError(fenceObject->finish());
5723}
5724
5725void Context::getFenceivNV(GLuint fence, GLenum pname, GLint *params)
5726{
5727 FenceNV *fenceObject = getFenceNV(fence);
5728
5729 ASSERT(fenceObject && fenceObject->isSet());
5730
5731 switch (pname)
5732 {
5733 case GL_FENCE_STATUS_NV:
5734 {
5735 // GL_NV_fence spec:
5736 // Once the status of a fence has been finished (via FinishFenceNV) or tested and
5737 // the returned status is TRUE (via either TestFenceNV or GetFenceivNV querying the
5738 // FENCE_STATUS_NV), the status remains TRUE until the next SetFenceNV of the fence.
5739 GLboolean status = GL_TRUE;
5740 if (fenceObject->getStatus() != GL_TRUE)
5741 {
5742 ANGLE_CONTEXT_TRY(fenceObject->test(&status));
5743 }
5744 *params = status;
5745 break;
5746 }
5747
5748 case GL_FENCE_CONDITION_NV:
5749 {
5750 *params = static_cast<GLint>(fenceObject->getCondition());
5751 break;
5752 }
5753
5754 default:
5755 UNREACHABLE();
5756 }
5757}
5758
5759void Context::getTranslatedShaderSource(GLuint shader,
5760 GLsizei bufsize,
5761 GLsizei *length,
5762 GLchar *source)
5763{
5764 Shader *shaderObject = getShader(shader);
5765 ASSERT(shaderObject);
5766 shaderObject->getTranslatedSourceWithDebugInfo(this, bufsize, length, source);
5767}
5768
5769void Context::getnUniformfv(GLuint program, GLint location, GLsizei bufSize, GLfloat *params)
5770{
5771 Program *programObject = getProgram(program);
5772 ASSERT(programObject);
5773
5774 programObject->getUniformfv(this, location, params);
5775}
5776
5777void Context::getnUniformiv(GLuint program, GLint location, GLsizei bufSize, GLint *params)
5778{
5779 Program *programObject = getProgram(program);
5780 ASSERT(programObject);
5781
5782 programObject->getUniformiv(this, location, params);
5783}
5784
5785GLboolean Context::isFenceNV(GLuint fence)
5786{
5787 FenceNV *fenceObject = getFenceNV(fence);
5788
5789 if (fenceObject == nullptr)
5790 {
5791 return GL_FALSE;
5792 }
5793
5794 // GL_NV_fence spec:
5795 // A name returned by GenFencesNV, but not yet set via SetFenceNV, is not the name of an
5796 // existing fence.
5797 return fenceObject->isSet();
5798}
5799
5800void Context::readnPixels(GLint x,
5801 GLint y,
5802 GLsizei width,
5803 GLsizei height,
5804 GLenum format,
5805 GLenum type,
5806 GLsizei bufSize,
5807 void *data)
5808{
5809 return readPixels(x, y, width, height, format, type, data);
5810}
5811
Jamie Madill007530e2017-12-28 14:27:04 -05005812void Context::setFenceNV(GLuint fence, GLenum condition)
5813{
5814 ASSERT(condition == GL_ALL_COMPLETED_NV);
5815
5816 FenceNV *fenceObject = getFenceNV(fence);
5817 ASSERT(fenceObject != nullptr);
5818 handleError(fenceObject->set(condition));
5819}
5820
5821GLboolean Context::testFenceNV(GLuint fence)
5822{
5823 FenceNV *fenceObject = getFenceNV(fence);
5824
5825 ASSERT(fenceObject != nullptr);
5826 ASSERT(fenceObject->isSet() == GL_TRUE);
5827
5828 GLboolean result = GL_TRUE;
5829 Error error = fenceObject->test(&result);
5830 if (error.isError())
5831 {
5832 handleError(error);
5833 return GL_TRUE;
5834 }
5835
5836 return result;
5837}
5838
Jamie Madillfa920eb2018-01-04 11:45:50 -05005839void Context::eGLImageTargetTexture2D(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005840{
5841 Texture *texture = getTargetTexture(target);
5842 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
5843 handleError(texture->setEGLImageTarget(this, target, imageObject));
5844}
5845
Jamie Madillfa920eb2018-01-04 11:45:50 -05005846void Context::eGLImageTargetRenderbufferStorage(GLenum target, GLeglImageOES image)
Jamie Madill007530e2017-12-28 14:27:04 -05005847{
5848 Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer();
5849 egl::Image *imageObject = reinterpret_cast<egl::Image *>(image);
5850 handleError(renderbuffer->setStorageEGLImageTarget(this, imageObject));
5851}
5852
Jamie Madillfa920eb2018-01-04 11:45:50 -05005853void Context::texStorage1D(GLenum target, GLsizei levels, GLenum internalformat, GLsizei width)
5854{
5855 UNIMPLEMENTED();
5856}
5857
Geoff Lang2aaa7b42018-01-12 17:17:27 -05005858void Context::alphaFunc(GLenum func, GLfloat ref)
5859{
5860 UNIMPLEMENTED();
5861}
5862
5863void Context::alphaFuncx(GLenum func, GLfixed ref)
5864{
5865 UNIMPLEMENTED();
5866}
5867
5868void Context::clearColorx(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5869{
5870 UNIMPLEMENTED();
5871}
5872
5873void Context::clearDepthx(GLfixed depth)
5874{
5875 UNIMPLEMENTED();
5876}
5877
5878void Context::clientActiveTexture(GLenum texture)
5879{
5880 UNIMPLEMENTED();
5881}
5882
5883void Context::clipPlanef(GLenum p, const GLfloat *eqn)
5884{
5885 UNIMPLEMENTED();
5886}
5887
5888void Context::clipPlanex(GLenum plane, const GLfixed *equation)
5889{
5890 UNIMPLEMENTED();
5891}
5892
5893void Context::color4f(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha)
5894{
5895 UNIMPLEMENTED();
5896}
5897
5898void Context::color4ub(GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha)
5899{
5900 UNIMPLEMENTED();
5901}
5902
5903void Context::color4x(GLfixed red, GLfixed green, GLfixed blue, GLfixed alpha)
5904{
5905 UNIMPLEMENTED();
5906}
5907
5908void Context::colorPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
5909{
5910 UNIMPLEMENTED();
5911}
5912
5913void Context::cullFace(GLenum mode)
5914{
5915 UNIMPLEMENTED();
5916}
5917
5918void Context::depthRangex(GLfixed n, GLfixed f)
5919{
5920 UNIMPLEMENTED();
5921}
5922
5923void Context::disableClientState(GLenum array)
5924{
5925 UNIMPLEMENTED();
5926}
5927
5928void Context::enableClientState(GLenum array)
5929{
5930 UNIMPLEMENTED();
5931}
5932
5933void Context::fogf(GLenum pname, GLfloat param)
5934{
5935 UNIMPLEMENTED();
5936}
5937
5938void Context::fogfv(GLenum pname, const GLfloat *params)
5939{
5940 UNIMPLEMENTED();
5941}
5942
5943void Context::fogx(GLenum pname, GLfixed param)
5944{
5945 UNIMPLEMENTED();
5946}
5947
5948void Context::fogxv(GLenum pname, const GLfixed *param)
5949{
5950 UNIMPLEMENTED();
5951}
5952
5953void Context::frustumf(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
5954{
5955 UNIMPLEMENTED();
5956}
5957
5958void Context::frustumx(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
5959{
5960 UNIMPLEMENTED();
5961}
5962
5963void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params)
5964{
5965 UNIMPLEMENTED();
5966}
5967
5968void Context::getClipPlanef(GLenum plane, GLfloat *equation)
5969{
5970 UNIMPLEMENTED();
5971}
5972
5973void Context::getClipPlanex(GLenum plane, GLfixed *equation)
5974{
5975 UNIMPLEMENTED();
5976}
5977
5978void Context::getFixedv(GLenum pname, GLfixed *params)
5979{
5980 UNIMPLEMENTED();
5981}
5982
5983void Context::getLightfv(GLenum light, GLenum pname, GLfloat *params)
5984{
5985 UNIMPLEMENTED();
5986}
5987
5988void Context::getLightxv(GLenum light, GLenum pname, GLfixed *params)
5989{
5990 UNIMPLEMENTED();
5991}
5992
5993void Context::getMaterialfv(GLenum face, GLenum pname, GLfloat *params)
5994{
5995 UNIMPLEMENTED();
5996}
5997
5998void Context::getMaterialxv(GLenum face, GLenum pname, GLfixed *params)
5999{
6000 UNIMPLEMENTED();
6001}
6002
6003void Context::getTexEnvfv(GLenum target, GLenum pname, GLfloat *params)
6004{
6005 UNIMPLEMENTED();
6006}
6007
6008void Context::getTexEnviv(GLenum target, GLenum pname, GLint *params)
6009{
6010 UNIMPLEMENTED();
6011}
6012
6013void Context::getTexEnvxv(GLenum target, GLenum pname, GLfixed *params)
6014{
6015 UNIMPLEMENTED();
6016}
6017
6018void Context::getTexParameterxv(GLenum target, GLenum pname, GLfixed *params)
6019{
6020 UNIMPLEMENTED();
6021}
6022
6023void Context::lightModelf(GLenum pname, GLfloat param)
6024{
6025 UNIMPLEMENTED();
6026}
6027
6028void Context::lightModelfv(GLenum pname, const GLfloat *params)
6029{
6030 UNIMPLEMENTED();
6031}
6032
6033void Context::lightModelx(GLenum pname, GLfixed param)
6034{
6035 UNIMPLEMENTED();
6036}
6037
6038void Context::lightModelxv(GLenum pname, const GLfixed *param)
6039{
6040 UNIMPLEMENTED();
6041}
6042
6043void Context::lightf(GLenum light, GLenum pname, GLfloat param)
6044{
6045 UNIMPLEMENTED();
6046}
6047
6048void Context::lightfv(GLenum light, GLenum pname, const GLfloat *params)
6049{
6050 UNIMPLEMENTED();
6051}
6052
6053void Context::lightx(GLenum light, GLenum pname, GLfixed param)
6054{
6055 UNIMPLEMENTED();
6056}
6057
6058void Context::lightxv(GLenum light, GLenum pname, const GLfixed *params)
6059{
6060 UNIMPLEMENTED();
6061}
6062
6063void Context::lineWidthx(GLfixed width)
6064{
6065 UNIMPLEMENTED();
6066}
6067
6068void Context::loadIdentity()
6069{
6070 UNIMPLEMENTED();
6071}
6072
6073void Context::loadMatrixf(const GLfloat *m)
6074{
6075 UNIMPLEMENTED();
6076}
6077
6078void Context::loadMatrixx(const GLfixed *m)
6079{
6080 UNIMPLEMENTED();
6081}
6082
6083void Context::logicOp(GLenum opcode)
6084{
6085 UNIMPLEMENTED();
6086}
6087
6088void Context::materialf(GLenum face, GLenum pname, GLfloat param)
6089{
6090 UNIMPLEMENTED();
6091}
6092
6093void Context::materialfv(GLenum face, GLenum pname, const GLfloat *params)
6094{
6095 UNIMPLEMENTED();
6096}
6097
6098void Context::materialx(GLenum face, GLenum pname, GLfixed param)
6099{
6100 UNIMPLEMENTED();
6101}
6102
6103void Context::materialxv(GLenum face, GLenum pname, const GLfixed *param)
6104{
6105 UNIMPLEMENTED();
6106}
6107
6108void Context::matrixMode(GLenum mode)
6109{
6110 UNIMPLEMENTED();
6111}
6112
6113void Context::multMatrixf(const GLfloat *m)
6114{
6115 UNIMPLEMENTED();
6116}
6117
6118void Context::multMatrixx(const GLfixed *m)
6119{
6120 UNIMPLEMENTED();
6121}
6122
6123void Context::multiTexCoord4f(GLenum target, GLfloat s, GLfloat t, GLfloat r, GLfloat q)
6124{
6125 UNIMPLEMENTED();
6126}
6127
6128void Context::multiTexCoord4x(GLenum texture, GLfixed s, GLfixed t, GLfixed r, GLfixed q)
6129{
6130 UNIMPLEMENTED();
6131}
6132
6133void Context::normal3f(GLfloat nx, GLfloat ny, GLfloat nz)
6134{
6135 UNIMPLEMENTED();
6136}
6137
6138void Context::normal3x(GLfixed nx, GLfixed ny, GLfixed nz)
6139{
6140 UNIMPLEMENTED();
6141}
6142
6143void Context::normalPointer(GLenum type, GLsizei stride, const void *pointer)
6144{
6145 UNIMPLEMENTED();
6146}
6147
6148void Context::orthof(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLfloat f)
6149{
6150 UNIMPLEMENTED();
6151}
6152
6153void Context::orthox(GLfixed l, GLfixed r, GLfixed b, GLfixed t, GLfixed n, GLfixed f)
6154{
6155 UNIMPLEMENTED();
6156}
6157
6158void Context::pointParameterf(GLenum pname, GLfloat param)
6159{
6160 UNIMPLEMENTED();
6161}
6162
6163void Context::pointParameterfv(GLenum pname, const GLfloat *params)
6164{
6165 UNIMPLEMENTED();
6166}
6167
6168void Context::pointParameterx(GLenum pname, GLfixed param)
6169{
6170 UNIMPLEMENTED();
6171}
6172
6173void Context::pointParameterxv(GLenum pname, const GLfixed *params)
6174{
6175 UNIMPLEMENTED();
6176}
6177
6178void Context::pointSize(GLfloat size)
6179{
6180 UNIMPLEMENTED();
6181}
6182
6183void Context::pointSizex(GLfixed size)
6184{
6185 UNIMPLEMENTED();
6186}
6187
6188void Context::polygonOffsetx(GLfixed factor, GLfixed units)
6189{
6190 UNIMPLEMENTED();
6191}
6192
6193void Context::popMatrix()
6194{
6195 UNIMPLEMENTED();
6196}
6197
6198void Context::pushMatrix()
6199{
6200 UNIMPLEMENTED();
6201}
6202
6203void Context::rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
6204{
6205 UNIMPLEMENTED();
6206}
6207
6208void Context::rotatex(GLfixed angle, GLfixed x, GLfixed y, GLfixed z)
6209{
6210 UNIMPLEMENTED();
6211}
6212
6213void Context::sampleCoveragex(GLclampx value, GLboolean invert)
6214{
6215 UNIMPLEMENTED();
6216}
6217
6218void Context::scalef(GLfloat x, GLfloat y, GLfloat z)
6219{
6220 UNIMPLEMENTED();
6221}
6222
6223void Context::scalex(GLfixed x, GLfixed y, GLfixed z)
6224{
6225 UNIMPLEMENTED();
6226}
6227
6228void Context::shadeModel(GLenum mode)
6229{
6230 UNIMPLEMENTED();
6231}
6232
6233void Context::texCoordPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6234{
6235 UNIMPLEMENTED();
6236}
6237
6238void Context::texEnvf(GLenum target, GLenum pname, GLfloat param)
6239{
6240 UNIMPLEMENTED();
6241}
6242
6243void Context::texEnvfv(GLenum target, GLenum pname, const GLfloat *params)
6244{
6245 UNIMPLEMENTED();
6246}
6247
6248void Context::texEnvi(GLenum target, GLenum pname, GLint param)
6249{
6250 UNIMPLEMENTED();
6251}
6252
6253void Context::texEnviv(GLenum target, GLenum pname, const GLint *params)
6254{
6255 UNIMPLEMENTED();
6256}
6257
6258void Context::texEnvx(GLenum target, GLenum pname, GLfixed param)
6259{
6260 UNIMPLEMENTED();
6261}
6262
6263void Context::texEnvxv(GLenum target, GLenum pname, const GLfixed *params)
6264{
6265 UNIMPLEMENTED();
6266}
6267
6268void Context::texParameterx(GLenum target, GLenum pname, GLfixed param)
6269{
6270 UNIMPLEMENTED();
6271}
6272
6273void Context::texParameterxv(GLenum target, GLenum pname, const GLfixed *params)
6274{
6275 UNIMPLEMENTED();
6276}
6277
6278void Context::translatef(GLfloat x, GLfloat y, GLfloat z)
6279{
6280 UNIMPLEMENTED();
6281}
6282
6283void Context::translatex(GLfixed x, GLfixed y, GLfixed z)
6284{
6285 UNIMPLEMENTED();
6286}
6287
6288void Context::vertexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6289{
6290 UNIMPLEMENTED();
6291}
6292
6293void Context::drawTexf(GLfloat x, GLfloat y, GLfloat z, GLfloat width, GLfloat height)
6294{
6295 UNIMPLEMENTED();
6296}
6297
6298void Context::drawTexfv(const GLfloat *coords)
6299{
6300 UNIMPLEMENTED();
6301}
6302
6303void Context::drawTexi(GLint x, GLint y, GLint z, GLint width, GLint height)
6304{
6305 UNIMPLEMENTED();
6306}
6307
6308void Context::drawTexiv(const GLint *coords)
6309{
6310 UNIMPLEMENTED();
6311}
6312
6313void Context::drawTexs(GLshort x, GLshort y, GLshort z, GLshort width, GLshort height)
6314{
6315 UNIMPLEMENTED();
6316}
6317
6318void Context::drawTexsv(const GLshort *coords)
6319{
6320 UNIMPLEMENTED();
6321}
6322
6323void Context::drawTexx(GLfixed x, GLfixed y, GLfixed z, GLfixed width, GLfixed height)
6324{
6325 UNIMPLEMENTED();
6326}
6327
6328void Context::drawTexxv(const GLfixed *coords)
6329{
6330 UNIMPLEMENTED();
6331}
6332
6333void Context::currentPaletteMatrix(GLuint matrixpaletteindex)
6334{
6335 UNIMPLEMENTED();
6336}
6337
6338void Context::loadPaletteFromModelViewMatrix()
6339{
6340 UNIMPLEMENTED();
6341}
6342
6343void Context::matrixIndexPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6344{
6345 UNIMPLEMENTED();
6346}
6347
6348void Context::weightPointer(GLint size, GLenum type, GLsizei stride, const void *pointer)
6349{
6350 UNIMPLEMENTED();
6351}
6352
6353void Context::pointSizePointer(GLenum type, GLsizei stride, const void *pointer)
6354{
6355 UNIMPLEMENTED();
6356}
6357
6358GLbitfield Context::queryMatrixx(GLfixed *mantissa, GLint *exponent)
6359{
6360 UNIMPLEMENTED();
6361 return 0;
6362}
6363
Jamie Madillc29968b2016-01-20 11:17:23 -05006364} // namespace gl