apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1 | // |
Geoff Lang | eeba6e1 | 2014-02-03 13:12:30 -0500 | [diff] [blame] | 2 | // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved. |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 3 | // 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 Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 10 | #include "libANGLE/Context.h" |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 11 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 12 | #include <string.h> |
Jamie Madill | b929397 | 2015-02-19 11:07:54 -0500 | [diff] [blame] | 13 | #include <iterator> |
| 14 | #include <sstream> |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 15 | #include <vector> |
Jamie Madill | b929397 | 2015-02-19 11:07:54 -0500 | [diff] [blame] | 16 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 17 | #include "common/matrix_utils.h" |
Geoff Lang | 0b7eef7 | 2014-06-12 14:10:47 -0400 | [diff] [blame] | 18 | #include "common/platform.h" |
Jamie Madill | b929397 | 2015-02-19 11:07:54 -0500 | [diff] [blame] | 19 | #include "common/utilities.h" |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 20 | #include "common/version.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 21 | #include "libANGLE/Buffer.h" |
Jamie Madill | b929397 | 2015-02-19 11:07:54 -0500 | [diff] [blame] | 22 | #include "libANGLE/Compiler.h" |
Jamie Madill | 948bbe5 | 2017-06-01 13:10:42 -0400 | [diff] [blame] | 23 | #include "libANGLE/Display.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 24 | #include "libANGLE/Fence.h" |
| 25 | #include "libANGLE/Framebuffer.h" |
| 26 | #include "libANGLE/FramebufferAttachment.h" |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 27 | #include "libANGLE/Path.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 28 | #include "libANGLE/Program.h" |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 29 | #include "libANGLE/ProgramPipeline.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 30 | #include "libANGLE/Query.h" |
Jamie Madill | b929397 | 2015-02-19 11:07:54 -0500 | [diff] [blame] | 31 | #include "libANGLE/Renderbuffer.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 32 | #include "libANGLE/ResourceManager.h" |
| 33 | #include "libANGLE/Sampler.h" |
Jamie Madill | 9dd0cf0 | 2014-11-24 11:38:51 -0500 | [diff] [blame] | 34 | #include "libANGLE/Surface.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 35 | #include "libANGLE/Texture.h" |
| 36 | #include "libANGLE/TransformFeedback.h" |
| 37 | #include "libANGLE/VertexArray.h" |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 38 | #include "libANGLE/Workarounds.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 39 | #include "libANGLE/formatutils.h" |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 40 | #include "libANGLE/queryconversions.h" |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 41 | #include "libANGLE/queryutils.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 42 | #include "libANGLE/renderer/ContextImpl.h" |
| 43 | #include "libANGLE/renderer/EGLImplFactory.h" |
Jamie Madill | 7b62cf9 | 2017-11-02 15:20:49 -0400 | [diff] [blame] | 44 | #include "libANGLE/renderer/Format.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 45 | #include "libANGLE/validationES.h" |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 46 | |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 47 | namespace |
| 48 | { |
| 49 | |
Jamie Madill | b666492 | 2017-07-25 12:55:04 -0400 | [diff] [blame] | 50 | #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 Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 55 | template <typename T> |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 56 | std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager, |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 57 | 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 Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 76 | std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager, |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 77 | 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 | |
| 107 | template <typename T> |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 108 | gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 109 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 110 | ASSERT(query != nullptr); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 111 | |
| 112 | switch (pname) |
| 113 | { |
| 114 | case GL_QUERY_RESULT_EXT: |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 115 | return query->getResult(params); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 116 | case GL_QUERY_RESULT_AVAILABLE_EXT: |
| 117 | { |
| 118 | bool available; |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 119 | gl::Error error = query->isResultAvailable(&available); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 120 | if (!error.isError()) |
| 121 | { |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 122 | *params = gl::CastFromStateValue<T>(pname, static_cast<GLuint>(available)); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 123 | } |
| 124 | return error; |
| 125 | } |
| 126 | default: |
| 127 | UNREACHABLE(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 128 | return gl::InternalError() << "Unreachable Error"; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 129 | } |
| 130 | } |
| 131 | |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 132 | void MarkTransformFeedbackBufferUsage(gl::TransformFeedback *transformFeedback) |
| 133 | { |
Geoff Lang | 1a68346 | 2015-09-29 15:09:59 -0400 | [diff] [blame] | 134 | if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused()) |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 135 | { |
| 136 | for (size_t tfBufferIndex = 0; tfBufferIndex < transformFeedback->getIndexedBufferCount(); |
| 137 | tfBufferIndex++) |
| 138 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 139 | const gl::OffsetBindingPointer<gl::Buffer> &buffer = |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 140 | transformFeedback->getIndexedBuffer(tfBufferIndex); |
| 141 | if (buffer.get() != nullptr) |
| 142 | { |
| 143 | buffer->onTransformFeedback(); |
| 144 | } |
| 145 | } |
| 146 | } |
| 147 | } |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 148 | |
| 149 | // Attribute map queries. |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 150 | EGLint GetClientMajorVersion(const egl::AttributeMap &attribs) |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 151 | { |
Ian Ewell | ec2c0c5 | 2016-04-05 13:46:26 -0400 | [diff] [blame] | 152 | return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1)); |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 153 | } |
| 154 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 155 | EGLint GetClientMinorVersion(const egl::AttributeMap &attribs) |
| 156 | { |
| 157 | return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0)); |
| 158 | } |
| 159 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 160 | gl::Version GetClientVersion(const egl::AttributeMap &attribs) |
| 161 | { |
| 162 | return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs)); |
| 163 | } |
| 164 | |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 165 | GLenum GetResetStrategy(const egl::AttributeMap &attribs) |
| 166 | { |
Ian Ewell | ec2c0c5 | 2016-04-05 13:46:26 -0400 | [diff] [blame] | 167 | EGLAttrib attrib = attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, |
Jeff Gilbert | c5de4d2 | 2017-10-31 15:07:53 -0700 | [diff] [blame] | 168 | EGL_NO_RESET_NOTIFICATION); |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 169 | 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 | |
| 181 | bool GetRobustAccess(const egl::AttributeMap &attribs) |
| 182 | { |
Geoff Lang | 077f20a | 2016-11-01 10:08:02 -0400 | [diff] [blame] | 183 | 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 Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | bool GetDebug(const egl::AttributeMap &attribs) |
| 189 | { |
Geoff Lang | 077f20a | 2016-11-01 10:08:02 -0400 | [diff] [blame] | 190 | 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 Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | bool GetNoError(const egl::AttributeMap &attribs) |
| 195 | { |
| 196 | return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE); |
| 197 | } |
| 198 | |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 199 | bool GetWebGLContext(const egl::AttributeMap &attribs) |
| 200 | { |
| 201 | return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE); |
| 202 | } |
| 203 | |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 204 | bool GetBindGeneratesResource(const egl::AttributeMap &attribs) |
| 205 | { |
| 206 | return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE); |
| 207 | } |
| 208 | |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 209 | bool GetClientArraysEnabled(const egl::AttributeMap &attribs) |
| 210 | { |
| 211 | return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE); |
| 212 | } |
| 213 | |
Geoff Lang | b433e87 | 2017-10-05 14:01:47 -0400 | [diff] [blame] | 214 | bool GetRobustResourceInit(const egl::AttributeMap &attribs) |
| 215 | { |
| 216 | return (attribs.get(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE, EGL_FALSE) == EGL_TRUE); |
| 217 | } |
| 218 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 219 | std::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 | |
| 230 | void 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 Madill | 0f80ed8 | 2017-09-19 00:24:56 -0400 | [diff] [blame] | 249 | template <typename CapT, typename MaxT> |
| 250 | void LimitCap(CapT *cap, MaxT maximum) |
| 251 | { |
| 252 | *cap = std::min(*cap, static_cast<CapT>(maximum)); |
| 253 | } |
| 254 | |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 255 | } // anonymous namespace |
| 256 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 257 | namespace gl |
| 258 | { |
daniel@transgaming.com | ca1ac1f | 2013-01-11 04:13:05 +0000 | [diff] [blame] | 259 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 260 | Context::Context(rx::EGLImplFactory *implFactory, |
| 261 | const egl::Config *config, |
Corentin Wallez | 51706ea | 2015-08-07 14:39:22 -0400 | [diff] [blame] | 262 | const Context *shareContext, |
Geoff Lang | ce02f08 | 2017-02-06 16:46:21 -0500 | [diff] [blame] | 263 | TextureManager *shareTextures, |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 264 | MemoryProgramCache *memoryProgramCache, |
Corentin Wallez | c295e51 | 2017-01-27 17:47:50 -0500 | [diff] [blame] | 265 | const egl::AttributeMap &attribs, |
Geoff Lang | b433e87 | 2017-10-05 14:01:47 -0400 | [diff] [blame] | 266 | const egl::DisplayExtensions &displayExtensions) |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 267 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 268 | : ValidationContext(shareContext, |
Geoff Lang | ce02f08 | 2017-02-06 16:46:21 -0500 | [diff] [blame] | 269 | shareTextures, |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 270 | GetClientVersion(attribs), |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 271 | &mGLState, |
Jamie Madill | f25855c | 2015-11-03 11:06:18 -0500 | [diff] [blame] | 272 | mCaps, |
| 273 | mTextureCaps, |
| 274 | mExtensions, |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 275 | mLimitations, |
| 276 | GetNoError(attribs)), |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 277 | mImplementation(implFactory->createContext(mState)), |
Jamie Madill | 2f348d2 | 2017-06-05 10:50:59 -0400 | [diff] [blame] | 278 | mCompiler(), |
Corentin Wallez | e3b10e8 | 2015-05-20 11:06:25 -0400 | [diff] [blame] | 279 | mConfig(config), |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 280 | mClientType(EGL_OPENGL_ES_API), |
| 281 | mHasBeenCurrent(false), |
| 282 | mContextLost(false), |
| 283 | mResetStatus(GL_NO_ERROR), |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 284 | mContextLostForced(false), |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 285 | mResetStrategy(GetResetStrategy(attribs)), |
| 286 | mRobustAccess(GetRobustAccess(attribs)), |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 287 | mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)), |
| 288 | mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)), |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 289 | mSurfacelessFramebuffer(nullptr), |
Jamie Madill | e14951e | 2017-03-09 18:55:16 -0500 | [diff] [blame] | 290 | mWebGLContext(GetWebGLContext(attribs)), |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 291 | mMemoryProgramCache(memoryProgramCache), |
Jamie Madill | b3f26b9 | 2017-07-19 15:07:41 -0400 | [diff] [blame] | 292 | mScratchBuffer(1000u), |
| 293 | mZeroFilledBuffer(1000u) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 294 | { |
Jamie Madill | 14bbb3f | 2017-09-12 15:23:01 -0400 | [diff] [blame] | 295 | mImplementation->setMemoryProgramCache(memoryProgramCache); |
| 296 | |
Geoff Lang | b433e87 | 2017-10-05 14:01:47 -0400 | [diff] [blame] | 297 | bool robustResourceInit = GetRobustResourceInit(attribs); |
| 298 | initCaps(displayExtensions, robustResourceInit); |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 299 | initWorkarounds(); |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 300 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 301 | mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs), |
Jamie Madill | c43be72 | 2017-07-13 16:22:14 -0400 | [diff] [blame] | 302 | GetClientArraysEnabled(attribs), robustResourceInit, |
| 303 | mMemoryProgramCache != nullptr); |
Régis Fénéon | 8310797 | 2015-02-05 12:57:44 +0100 | [diff] [blame] | 304 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 305 | mFenceNVHandleAllocator.setBaseHandle(0); |
Geoff Lang | 7dca186 | 2013-07-30 16:30:46 -0400 | [diff] [blame] | 306 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 307 | // [OpenGL ES 2.0.24] section 3.7 page 83: |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 308 | // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have two-dimensional |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 309 | // 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 Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 313 | Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 314 | mZeroTextures[GL_TEXTURE_2D].set(this, zeroTexture2D); |
Jamie Madill | dedd7b9 | 2014-11-05 16:30:36 -0500 | [diff] [blame] | 315 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 316 | Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, GL_TEXTURE_CUBE_MAP); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 317 | mZeroTextures[GL_TEXTURE_CUBE_MAP].set(this, zeroTextureCube); |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 318 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 319 | if (getClientVersion() >= Version(3, 0)) |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 320 | { |
| 321 | // TODO: These could also be enabled via extension |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 322 | Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, GL_TEXTURE_3D); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 323 | mZeroTextures[GL_TEXTURE_3D].set(this, zeroTexture3D); |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 324 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 325 | Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_ARRAY); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 326 | mZeroTextures[GL_TEXTURE_2D_ARRAY].set(this, zeroTexture2DArray); |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 327 | } |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 328 | if (getClientVersion() >= Version(3, 1)) |
| 329 | { |
| 330 | Texture *zeroTexture2DMultisample = |
| 331 | new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_MULTISAMPLE); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 332 | mZeroTextures[GL_TEXTURE_2D_MULTISAMPLE].set(this, zeroTexture2DMultisample); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 333 | |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 334 | for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++) |
| 335 | { |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 336 | bindBufferRange(BufferBinding::AtomicCounter, 0, i, 0, 0); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 337 | } |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 338 | |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 339 | for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++) |
| 340 | { |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 341 | bindBufferRange(BufferBinding::ShaderStorage, i, 0, 0, 0); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 342 | } |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 343 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 344 | |
Geoff Lang | 4751aab | 2017-10-30 15:14:52 -0400 | [diff] [blame] | 345 | const Extensions &nativeExtensions = mImplementation->getNativeExtensions(); |
| 346 | if (nativeExtensions.textureRectangle) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 347 | { |
| 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 Lang | 4751aab | 2017-10-30 15:14:52 -0400 | [diff] [blame] | 353 | if (nativeExtensions.eglImageExternal || nativeExtensions.eglStreamConsumerExternal) |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 354 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 355 | Texture *zeroTextureExternal = |
| 356 | new Texture(mImplementation.get(), 0, GL_TEXTURE_EXTERNAL_OES); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 357 | mZeroTextures[GL_TEXTURE_EXTERNAL_OES].set(this, zeroTextureExternal); |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 358 | } |
| 359 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 360 | mGLState.initializeZeroTextures(this, mZeroTextures); |
Jamie Madill | e6382c3 | 2014-11-07 15:05:26 -0500 | [diff] [blame] | 361 | |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 362 | bindVertexArray(0); |
shannon.woods%transgaming.com@gtempaccount.com | 5117188 | 2013-04-13 03:39:10 +0000 | [diff] [blame] | 363 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 364 | if (getClientVersion() >= Version(3, 0)) |
Geoff Lang | 1a68346 | 2015-09-29 15:09:59 -0400 | [diff] [blame] | 365 | { |
| 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 Madill | f0dcb8b | 2017-08-26 19:05:13 -0400 | [diff] [blame] | 370 | bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0); |
Geoff Lang | 1a68346 | 2015-09-29 15:09:59 -0400 | [diff] [blame] | 371 | } |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 372 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 373 | 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 Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 385 | // Initialize dirty bit masks |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 386 | mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_STATE); |
Corentin Wallez | 29a2099 | 2017-11-06 18:23:16 -0500 | [diff] [blame] | 387 | mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING); |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 388 | // No dirty objects. |
| 389 | |
| 390 | // Readpixels uses the pack state and read FBO |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 391 | mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_STATE); |
Corentin Wallez | 29a2099 | 2017-11-06 18:23:16 -0500 | [diff] [blame] | 392 | mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING); |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 393 | 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 Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 410 | mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB); |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 411 | mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER); |
| 412 | mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 413 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 414 | handleError(mImplementation->initialize()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 417 | egl::Error Context::onDestroy(const egl::Display *display) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 418 | { |
Corentin Wallez | 80b2411 | 2015-08-25 16:41:57 -0400 | [diff] [blame] | 419 | for (auto fence : mFenceNVMap) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 420 | { |
Corentin Wallez | 80b2411 | 2015-08-25 16:41:57 -0400 | [diff] [blame] | 421 | SafeDelete(fence.second); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 422 | } |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 423 | mFenceNVMap.clear(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 424 | |
Corentin Wallez | 80b2411 | 2015-08-25 16:41:57 -0400 | [diff] [blame] | 425 | for (auto query : mQueryMap) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 426 | { |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 427 | if (query.second != nullptr) |
| 428 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 429 | query.second->release(this); |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 430 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 431 | } |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 432 | mQueryMap.clear(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 433 | |
Corentin Wallez | 80b2411 | 2015-08-25 16:41:57 -0400 | [diff] [blame] | 434 | for (auto vertexArray : mVertexArrayMap) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 435 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 436 | if (vertexArray.second) |
| 437 | { |
| 438 | vertexArray.second->onDestroy(this); |
| 439 | } |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 440 | } |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 441 | mVertexArrayMap.clear(); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 442 | |
Corentin Wallez | 80b2411 | 2015-08-25 16:41:57 -0400 | [diff] [blame] | 443 | for (auto transformFeedback : mTransformFeedbackMap) |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 444 | { |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 445 | if (transformFeedback.second != nullptr) |
| 446 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 447 | transformFeedback.second->release(this); |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 448 | } |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 449 | } |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 450 | mTransformFeedbackMap.clear(); |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 451 | |
Jamie Madill | dedd7b9 | 2014-11-05 16:30:36 -0500 | [diff] [blame] | 452 | for (auto &zeroTexture : mZeroTextures) |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 453 | { |
Jamie Madill | 71c88b3 | 2017-09-14 22:20:29 -0400 | [diff] [blame] | 454 | ANGLE_TRY(zeroTexture.second->onDestroy(this)); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 455 | zeroTexture.second.set(this, nullptr); |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 456 | } |
| 457 | mZeroTextures.clear(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 458 | |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 459 | SafeDelete(mSurfacelessFramebuffer); |
| 460 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 461 | ANGLE_TRY(releaseSurface(display)); |
Jamie Madill | 2f348d2 | 2017-06-05 10:50:59 -0400 | [diff] [blame] | 462 | releaseShaderCompiler(); |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 463 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 464 | mGLState.reset(this); |
| 465 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 466 | mState.mBuffers->release(this); |
| 467 | mState.mShaderPrograms->release(this); |
| 468 | mState.mTextures->release(this); |
| 469 | mState.mRenderbuffers->release(this); |
| 470 | mState.mSamplers->release(this); |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 471 | mState.mSyncs->release(this); |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 472 | mState.mPaths->release(this); |
| 473 | mState.mFramebuffers->release(this); |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 474 | mState.mPipelines->release(this); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 475 | |
Jamie Madill | 76e471e | 2017-10-21 09:56:01 -0400 | [diff] [blame] | 476 | mImplementation->onDestroy(this); |
| 477 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 478 | return egl::NoError(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 479 | } |
| 480 | |
Jamie Madill | 70ee0f6 | 2017-02-06 16:04:20 -0500 | [diff] [blame] | 481 | Context::~Context() |
| 482 | { |
| 483 | } |
| 484 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 485 | egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 486 | { |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 487 | mCurrentDisplay = display; |
| 488 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 489 | if (!mHasBeenCurrent) |
| 490 | { |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 491 | initRendererString(); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 492 | initVersionStrings(); |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 493 | initExtensionStrings(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 494 | |
Corentin Wallez | c295e51 | 2017-01-27 17:47:50 -0500 | [diff] [blame] | 495 | int width = 0; |
| 496 | int height = 0; |
| 497 | if (surface != nullptr) |
| 498 | { |
| 499 | width = surface->getWidth(); |
| 500 | height = surface->getHeight(); |
| 501 | } |
| 502 | |
| 503 | mGLState.setViewportParams(0, 0, width, height); |
| 504 | mGLState.setScissorParams(0, 0, width, height); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 505 | |
| 506 | mHasBeenCurrent = true; |
| 507 | } |
| 508 | |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 509 | // TODO(jmadill): Rework this when we support ContextImpl |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 510 | mGLState.setAllDirtyBits(); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 511 | mGLState.setAllDirtyObjects(); |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 512 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 513 | ANGLE_TRY(releaseSurface(display)); |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 514 | |
| 515 | Framebuffer *newDefault = nullptr; |
| 516 | if (surface != nullptr) |
| 517 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 518 | ANGLE_TRY(surface->setIsCurrent(this, true)); |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 519 | mCurrentSurface = surface; |
| 520 | newDefault = surface->getDefaultFramebuffer(); |
| 521 | } |
| 522 | else |
| 523 | { |
| 524 | if (mSurfacelessFramebuffer == nullptr) |
| 525 | { |
| 526 | mSurfacelessFramebuffer = new Framebuffer(mImplementation.get()); |
| 527 | } |
| 528 | |
| 529 | newDefault = mSurfacelessFramebuffer; |
| 530 | } |
Jamie Madill | 18fdcbc | 2015-08-19 18:12:44 +0000 | [diff] [blame] | 531 | |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 532 | // Update default framebuffer, the binding of the previous default |
| 533 | // framebuffer (or lack of) will have a nullptr. |
Jamie Madill | c1c1cdc | 2015-04-30 09:42:26 -0400 | [diff] [blame] | 534 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 535 | if (mGLState.getReadFramebuffer() == nullptr) |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 536 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 537 | mGLState.setReadFramebufferBinding(newDefault); |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 538 | } |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 539 | if (mGLState.getDrawFramebuffer() == nullptr) |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 540 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 541 | mGLState.setDrawFramebufferBinding(newDefault); |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 542 | } |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 543 | mState.mFramebuffers->setDefaultFramebuffer(newDefault); |
Jamie Madill | c1c1cdc | 2015-04-30 09:42:26 -0400 | [diff] [blame] | 544 | } |
Ian Ewell | 292f005 | 2016-02-04 10:37:32 -0500 | [diff] [blame] | 545 | |
| 546 | // Notify the renderer of a context switch |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 547 | mImplementation->onMakeCurrent(this); |
| 548 | return egl::NoError(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 549 | } |
| 550 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 551 | egl::Error Context::releaseSurface(const egl::Display *display) |
Jamie Madill | 77a72f6 | 2015-04-14 11:18:32 -0400 | [diff] [blame] | 552 | { |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 553 | // Remove the default framebuffer |
Corentin Wallez | c295e51 | 2017-01-27 17:47:50 -0500 | [diff] [blame] | 554 | Framebuffer *currentDefault = nullptr; |
| 555 | if (mCurrentSurface != nullptr) |
Corentin Wallez | 51706ea | 2015-08-07 14:39:22 -0400 | [diff] [blame] | 556 | { |
Corentin Wallez | c295e51 | 2017-01-27 17:47:50 -0500 | [diff] [blame] | 557 | currentDefault = mCurrentSurface->getDefaultFramebuffer(); |
| 558 | } |
| 559 | else if (mSurfacelessFramebuffer != nullptr) |
| 560 | { |
| 561 | currentDefault = mSurfacelessFramebuffer; |
Corentin Wallez | 51706ea | 2015-08-07 14:39:22 -0400 | [diff] [blame] | 562 | } |
| 563 | |
Corentin Wallez | c295e51 | 2017-01-27 17:47:50 -0500 | [diff] [blame] | 564 | if (mGLState.getReadFramebuffer() == currentDefault) |
| 565 | { |
| 566 | mGLState.setReadFramebufferBinding(nullptr); |
| 567 | } |
| 568 | if (mGLState.getDrawFramebuffer() == currentDefault) |
| 569 | { |
| 570 | mGLState.setDrawFramebufferBinding(nullptr); |
| 571 | } |
| 572 | mState.mFramebuffers->setDefaultFramebuffer(nullptr); |
| 573 | |
| 574 | if (mCurrentSurface) |
| 575 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 576 | ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false)); |
Corentin Wallez | c295e51 | 2017-01-27 17:47:50 -0500 | [diff] [blame] | 577 | mCurrentSurface = nullptr; |
| 578 | } |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 579 | |
| 580 | return egl::NoError(); |
Jamie Madill | 77a72f6 | 2015-04-14 11:18:32 -0400 | [diff] [blame] | 581 | } |
| 582 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 583 | GLuint Context::createBuffer() |
| 584 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 585 | return mState.mBuffers->createBuffer(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | GLuint Context::createProgram() |
| 589 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 590 | return mState.mShaderPrograms->createProgram(mImplementation.get()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | GLuint Context::createShader(GLenum type) |
| 594 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 595 | return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | GLuint Context::createTexture() |
| 599 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 600 | return mState.mTextures->createTexture(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | GLuint Context::createRenderbuffer() |
| 604 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 605 | return mState.mRenderbuffers->createRenderbuffer(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 606 | } |
| 607 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 608 | GLuint Context::createPaths(GLsizei range) |
| 609 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 610 | auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 611 | if (resultOrError.isError()) |
| 612 | { |
| 613 | handleError(resultOrError.getError()); |
| 614 | return 0; |
| 615 | } |
| 616 | return resultOrError.getResult(); |
| 617 | } |
| 618 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 619 | // Returns an unused framebuffer name |
| 620 | GLuint Context::createFramebuffer() |
| 621 | { |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 622 | return mState.mFramebuffers->createFramebuffer(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 623 | } |
| 624 | |
Jamie Madill | 33dc843 | 2013-07-26 11:55:05 -0400 | [diff] [blame] | 625 | GLuint Context::createFenceNV() |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 626 | { |
Jamie Madill | 33dc843 | 2013-07-26 11:55:05 -0400 | [diff] [blame] | 627 | GLuint handle = mFenceNVHandleAllocator.allocate(); |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 628 | mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV())); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 629 | return handle; |
| 630 | } |
| 631 | |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 632 | GLuint Context::createProgramPipeline() |
| 633 | { |
| 634 | return mState.mPipelines->createProgramPipeline(); |
| 635 | } |
| 636 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 637 | void Context::deleteBuffer(GLuint buffer) |
| 638 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 639 | if (mState.mBuffers->getBuffer(buffer)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 640 | { |
| 641 | detachBuffer(buffer); |
| 642 | } |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 643 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 644 | mState.mBuffers->deleteObject(this, buffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | void Context::deleteShader(GLuint shader) |
| 648 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 649 | mState.mShaderPrograms->deleteShader(this, shader); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | void Context::deleteProgram(GLuint program) |
| 653 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 654 | mState.mShaderPrograms->deleteProgram(this, program); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 655 | } |
| 656 | |
| 657 | void Context::deleteTexture(GLuint texture) |
| 658 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 659 | if (mState.mTextures->getTexture(texture)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 660 | { |
| 661 | detachTexture(texture); |
| 662 | } |
| 663 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 664 | mState.mTextures->deleteObject(this, texture); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | void Context::deleteRenderbuffer(GLuint renderbuffer) |
| 668 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 669 | if (mState.mRenderbuffers->getRenderbuffer(renderbuffer)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 670 | { |
| 671 | detachRenderbuffer(renderbuffer); |
| 672 | } |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 673 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 674 | mState.mRenderbuffers->deleteObject(this, renderbuffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 675 | } |
| 676 | |
Jamie Madill | 7f0c5a4 | 2017-08-26 22:43:26 -0400 | [diff] [blame] | 677 | void Context::deleteSync(GLsync sync) |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame] | 678 | { |
| 679 | // The spec specifies the underlying Fence object is not deleted until all current |
| 680 | // wait commands finish. However, since the name becomes invalid, we cannot query the fence, |
| 681 | // and since our API is currently designed for being called from a single thread, we can delete |
| 682 | // the fence immediately. |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 683 | mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync))); |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame] | 684 | } |
| 685 | |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 686 | void Context::deleteProgramPipeline(GLuint pipeline) |
| 687 | { |
| 688 | if (mState.mPipelines->getProgramPipeline(pipeline)) |
| 689 | { |
| 690 | detachProgramPipeline(pipeline); |
| 691 | } |
| 692 | |
| 693 | mState.mPipelines->deleteObject(this, pipeline); |
| 694 | } |
| 695 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 696 | void Context::deletePaths(GLuint first, GLsizei range) |
| 697 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 698 | mState.mPaths->deletePaths(first, range); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 699 | } |
| 700 | |
| 701 | bool Context::hasPathData(GLuint path) const |
| 702 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 703 | const auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 704 | if (pathObj == nullptr) |
| 705 | return false; |
| 706 | |
| 707 | return pathObj->hasPathData(); |
| 708 | } |
| 709 | |
| 710 | bool Context::hasPath(GLuint path) const |
| 711 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 712 | return mState.mPaths->hasPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | void Context::setPathCommands(GLuint path, |
| 716 | GLsizei numCommands, |
| 717 | const GLubyte *commands, |
| 718 | GLsizei numCoords, |
| 719 | GLenum coordType, |
| 720 | const void *coords) |
| 721 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 722 | auto *pathObject = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 723 | |
| 724 | handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords)); |
| 725 | } |
| 726 | |
| 727 | void Context::setPathParameterf(GLuint path, GLenum pname, GLfloat value) |
| 728 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 729 | auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 730 | |
| 731 | switch (pname) |
| 732 | { |
| 733 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 734 | pathObj->setStrokeWidth(value); |
| 735 | break; |
| 736 | case GL_PATH_END_CAPS_CHROMIUM: |
| 737 | pathObj->setEndCaps(static_cast<GLenum>(value)); |
| 738 | break; |
| 739 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 740 | pathObj->setJoinStyle(static_cast<GLenum>(value)); |
| 741 | break; |
| 742 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 743 | pathObj->setMiterLimit(value); |
| 744 | break; |
| 745 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 746 | pathObj->setStrokeBound(value); |
| 747 | break; |
| 748 | default: |
| 749 | UNREACHABLE(); |
| 750 | break; |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value) const |
| 755 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 756 | const auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 757 | |
| 758 | switch (pname) |
| 759 | { |
| 760 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 761 | *value = pathObj->getStrokeWidth(); |
| 762 | break; |
| 763 | case GL_PATH_END_CAPS_CHROMIUM: |
| 764 | *value = static_cast<GLfloat>(pathObj->getEndCaps()); |
| 765 | break; |
| 766 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 767 | *value = static_cast<GLfloat>(pathObj->getJoinStyle()); |
| 768 | break; |
| 769 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 770 | *value = pathObj->getMiterLimit(); |
| 771 | break; |
| 772 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 773 | *value = pathObj->getStrokeBound(); |
| 774 | break; |
| 775 | default: |
| 776 | UNREACHABLE(); |
| 777 | break; |
| 778 | } |
| 779 | } |
| 780 | |
| 781 | void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask) |
| 782 | { |
| 783 | mGLState.setPathStencilFunc(func, ref, mask); |
| 784 | } |
| 785 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 786 | void Context::deleteFramebuffer(GLuint framebuffer) |
| 787 | { |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 788 | if (mState.mFramebuffers->getFramebuffer(framebuffer)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 789 | { |
| 790 | detachFramebuffer(framebuffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 791 | } |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 792 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 793 | mState.mFramebuffers->deleteObject(this, framebuffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 794 | } |
| 795 | |
Jamie Madill | 33dc843 | 2013-07-26 11:55:05 -0400 | [diff] [blame] | 796 | void Context::deleteFenceNV(GLuint fence) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 797 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 798 | FenceNV *fenceObject = nullptr; |
| 799 | if (mFenceNVMap.erase(fence, &fenceObject)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 800 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 801 | mFenceNVHandleAllocator.release(fence); |
| 802 | delete fenceObject; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 803 | } |
| 804 | } |
| 805 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 806 | Buffer *Context::getBuffer(GLuint handle) const |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 807 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 808 | return mState.mBuffers->getBuffer(handle); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 809 | } |
| 810 | |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 811 | Texture *Context::getTexture(GLuint handle) const |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 812 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 813 | return mState.mTextures->getTexture(handle); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 814 | } |
| 815 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 816 | Renderbuffer *Context::getRenderbuffer(GLuint handle) const |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 817 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 818 | return mState.mRenderbuffers->getRenderbuffer(handle); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 819 | } |
| 820 | |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 821 | Sync *Context::getSync(GLsync handle) const |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame] | 822 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 823 | return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle))); |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame] | 824 | } |
| 825 | |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 826 | VertexArray *Context::getVertexArray(GLuint handle) const |
| 827 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 828 | return mVertexArrayMap.query(handle); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 829 | } |
| 830 | |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 831 | Sampler *Context::getSampler(GLuint handle) const |
| 832 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 833 | return mState.mSamplers->getSampler(handle); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 834 | } |
| 835 | |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 836 | TransformFeedback *Context::getTransformFeedback(GLuint handle) const |
| 837 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 838 | return mTransformFeedbackMap.query(handle); |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 839 | } |
| 840 | |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 841 | ProgramPipeline *Context::getProgramPipeline(GLuint handle) const |
| 842 | { |
| 843 | return mState.mPipelines->getProgramPipeline(handle); |
| 844 | } |
| 845 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 846 | LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const |
| 847 | { |
| 848 | switch (identifier) |
| 849 | { |
| 850 | case GL_BUFFER: |
| 851 | return getBuffer(name); |
| 852 | case GL_SHADER: |
| 853 | return getShader(name); |
| 854 | case GL_PROGRAM: |
| 855 | return getProgram(name); |
| 856 | case GL_VERTEX_ARRAY: |
| 857 | return getVertexArray(name); |
| 858 | case GL_QUERY: |
| 859 | return getQuery(name); |
| 860 | case GL_TRANSFORM_FEEDBACK: |
| 861 | return getTransformFeedback(name); |
| 862 | case GL_SAMPLER: |
| 863 | return getSampler(name); |
| 864 | case GL_TEXTURE: |
| 865 | return getTexture(name); |
| 866 | case GL_RENDERBUFFER: |
| 867 | return getRenderbuffer(name); |
| 868 | case GL_FRAMEBUFFER: |
| 869 | return getFramebuffer(name); |
| 870 | default: |
| 871 | UNREACHABLE(); |
| 872 | return nullptr; |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const |
| 877 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 878 | return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr))); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 879 | } |
| 880 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 881 | void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label) |
| 882 | { |
| 883 | LabeledObject *object = getLabeledObject(identifier, name); |
| 884 | ASSERT(object != nullptr); |
| 885 | |
| 886 | std::string labelName = GetObjectLabelFromPointer(length, label); |
| 887 | object->setLabel(labelName); |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 888 | |
| 889 | // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the |
| 890 | // specified object is active until we do this. |
| 891 | mGLState.setObjectDirty(identifier); |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label) |
| 895 | { |
| 896 | LabeledObject *object = getLabeledObjectFromPtr(ptr); |
| 897 | ASSERT(object != nullptr); |
| 898 | |
| 899 | std::string labelName = GetObjectLabelFromPointer(length, label); |
| 900 | object->setLabel(labelName); |
| 901 | } |
| 902 | |
| 903 | void Context::getObjectLabel(GLenum identifier, |
| 904 | GLuint name, |
| 905 | GLsizei bufSize, |
| 906 | GLsizei *length, |
| 907 | GLchar *label) const |
| 908 | { |
| 909 | LabeledObject *object = getLabeledObject(identifier, name); |
| 910 | ASSERT(object != nullptr); |
| 911 | |
| 912 | const std::string &objectLabel = object->getLabel(); |
| 913 | GetObjectLabelBase(objectLabel, bufSize, length, label); |
| 914 | } |
| 915 | |
| 916 | void Context::getObjectPtrLabel(const void *ptr, |
| 917 | GLsizei bufSize, |
| 918 | GLsizei *length, |
| 919 | GLchar *label) const |
| 920 | { |
| 921 | LabeledObject *object = getLabeledObjectFromPtr(ptr); |
| 922 | ASSERT(object != nullptr); |
| 923 | |
| 924 | const std::string &objectLabel = object->getLabel(); |
| 925 | GetObjectLabelBase(objectLabel, bufSize, length, label); |
| 926 | } |
| 927 | |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 928 | bool Context::isSampler(GLuint samplerName) const |
| 929 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 930 | return mState.mSamplers->isSampler(samplerName); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 931 | } |
| 932 | |
Jamie Madill | dedd7b9 | 2014-11-05 16:30:36 -0500 | [diff] [blame] | 933 | void Context::bindTexture(GLenum target, GLuint handle) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 934 | { |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 935 | Texture *texture = nullptr; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 936 | |
Jamie Madill | dedd7b9 | 2014-11-05 16:30:36 -0500 | [diff] [blame] | 937 | if (handle == 0) |
| 938 | { |
| 939 | texture = mZeroTextures[target].get(); |
| 940 | } |
| 941 | else |
| 942 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 943 | texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target); |
Jamie Madill | dedd7b9 | 2014-11-05 16:30:36 -0500 | [diff] [blame] | 944 | } |
| 945 | |
| 946 | ASSERT(texture); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 947 | mGLState.setSamplerTexture(this, target, texture); |
shannon.woods%transgaming.com@gtempaccount.com | 90dbc44 | 2013-04-13 03:46:14 +0000 | [diff] [blame] | 948 | } |
| 949 | |
Jamie Madill | 5bf9ff4 | 2016-02-01 11:13:03 -0500 | [diff] [blame] | 950 | void Context::bindReadFramebuffer(GLuint framebufferHandle) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 951 | { |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 952 | Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation( |
| 953 | mImplementation.get(), mCaps, framebufferHandle); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 954 | mGLState.setReadFramebufferBinding(framebuffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 955 | } |
| 956 | |
Jamie Madill | 5bf9ff4 | 2016-02-01 11:13:03 -0500 | [diff] [blame] | 957 | void Context::bindDrawFramebuffer(GLuint framebufferHandle) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 958 | { |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 959 | Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation( |
| 960 | mImplementation.get(), mCaps, framebufferHandle); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 961 | mGLState.setDrawFramebufferBinding(framebuffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 962 | } |
| 963 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 964 | void Context::bindVertexArray(GLuint vertexArrayHandle) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 965 | { |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 966 | VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 967 | mGLState.setVertexArrayBinding(vertexArray); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 968 | } |
| 969 | |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 970 | void Context::bindVertexBuffer(GLuint bindingIndex, |
| 971 | GLuint bufferHandle, |
| 972 | GLintptr offset, |
| 973 | GLsizei stride) |
| 974 | { |
| 975 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 976 | mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 977 | } |
| 978 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 979 | void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle) |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 980 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 981 | ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits); |
Jamie Madill | 901b379 | 2016-05-26 09:20:40 -0400 | [diff] [blame] | 982 | Sampler *sampler = |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 983 | mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 984 | mGLState.setSamplerBinding(this, textureUnit, sampler); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 985 | } |
| 986 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 987 | void Context::bindImageTexture(GLuint unit, |
| 988 | GLuint texture, |
| 989 | GLint level, |
| 990 | GLboolean layered, |
| 991 | GLint layer, |
| 992 | GLenum access, |
| 993 | GLenum format) |
| 994 | { |
| 995 | Texture *tex = mState.mTextures->getTexture(texture); |
| 996 | mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format); |
| 997 | } |
| 998 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 999 | void Context::useProgram(GLuint program) |
| 1000 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 1001 | mGLState.setProgram(this, getProgram(program)); |
daniel@transgaming.com | 95d2942 | 2012-07-24 18:36:10 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
Jamie Madill | f0dcb8b | 2017-08-26 19:05:13 -0400 | [diff] [blame] | 1004 | void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle) |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 1005 | { |
Jamie Madill | f0dcb8b | 2017-08-26 19:05:13 -0400 | [diff] [blame] | 1006 | ASSERT(target == GL_TRANSFORM_FEEDBACK); |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 1007 | TransformFeedback *transformFeedback = |
| 1008 | checkTransformFeedbackAllocation(transformFeedbackHandle); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1009 | mGLState.setTransformFeedbackBinding(this, transformFeedback); |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 1010 | } |
| 1011 | |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 1012 | void Context::bindProgramPipeline(GLuint pipelineHandle) |
| 1013 | { |
| 1014 | ProgramPipeline *pipeline = |
| 1015 | mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle); |
| 1016 | mGLState.setProgramPipelineBinding(this, pipeline); |
| 1017 | } |
| 1018 | |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1019 | void Context::beginQuery(GLenum target, GLuint query) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1020 | { |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1021 | Query *queryObject = getQuery(query, true, target); |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1022 | ASSERT(queryObject); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1023 | |
Geoff Lang | 5aad967 | 2014-09-08 11:10:42 -0400 | [diff] [blame] | 1024 | // begin query |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1025 | ANGLE_CONTEXT_TRY(queryObject->begin()); |
Geoff Lang | 5aad967 | 2014-09-08 11:10:42 -0400 | [diff] [blame] | 1026 | |
| 1027 | // set query as active for specified target only if begin succeeded |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1028 | mGLState.setActiveQuery(this, target, queryObject); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1029 | } |
| 1030 | |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1031 | void Context::endQuery(GLenum target) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1032 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1033 | Query *queryObject = mGLState.getActiveQuery(target); |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1034 | ASSERT(queryObject); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1035 | |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1036 | handleError(queryObject->end()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1037 | |
Geoff Lang | 5aad967 | 2014-09-08 11:10:42 -0400 | [diff] [blame] | 1038 | // Always unbind the query, even if there was an error. This may delete the query object. |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1039 | mGLState.setActiveQuery(this, target, nullptr); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1042 | void Context::queryCounter(GLuint id, GLenum target) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1043 | { |
| 1044 | ASSERT(target == GL_TIMESTAMP_EXT); |
| 1045 | |
| 1046 | Query *queryObject = getQuery(id, true, target); |
| 1047 | ASSERT(queryObject); |
| 1048 | |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1049 | handleError(queryObject->queryCounter()); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | void Context::getQueryiv(GLenum target, GLenum pname, GLint *params) |
| 1053 | { |
| 1054 | switch (pname) |
| 1055 | { |
| 1056 | case GL_CURRENT_QUERY_EXT: |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1057 | params[0] = mGLState.getActiveQueryId(target); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1058 | break; |
| 1059 | case GL_QUERY_COUNTER_BITS_EXT: |
| 1060 | switch (target) |
| 1061 | { |
| 1062 | case GL_TIME_ELAPSED_EXT: |
| 1063 | params[0] = getExtensions().queryCounterBitsTimeElapsed; |
| 1064 | break; |
| 1065 | case GL_TIMESTAMP_EXT: |
| 1066 | params[0] = getExtensions().queryCounterBitsTimestamp; |
| 1067 | break; |
| 1068 | default: |
| 1069 | UNREACHABLE(); |
| 1070 | params[0] = 0; |
| 1071 | break; |
| 1072 | } |
| 1073 | break; |
| 1074 | default: |
| 1075 | UNREACHABLE(); |
| 1076 | return; |
| 1077 | } |
| 1078 | } |
| 1079 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1080 | void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1081 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1082 | handleError(GetQueryObjectParameter(getQuery(id), pname, params)); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1083 | } |
| 1084 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1085 | void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1086 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1087 | handleError(GetQueryObjectParameter(getQuery(id), pname, params)); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1088 | } |
| 1089 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1090 | void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1091 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1092 | handleError(GetQueryObjectParameter(getQuery(id), pname, params)); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1093 | } |
| 1094 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1095 | void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1096 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1097 | handleError(GetQueryObjectParameter(getQuery(id), pname, params)); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1098 | } |
| 1099 | |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 1100 | Framebuffer *Context::getFramebuffer(GLuint handle) const |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1101 | { |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 1102 | return mState.mFramebuffers->getFramebuffer(handle); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1103 | } |
| 1104 | |
Jamie Madill | 2f348d2 | 2017-06-05 10:50:59 -0400 | [diff] [blame] | 1105 | FenceNV *Context::getFenceNV(GLuint handle) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1106 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 1107 | return mFenceNVMap.query(handle); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1108 | } |
| 1109 | |
Jamie Madill | 2f348d2 | 2017-06-05 10:50:59 -0400 | [diff] [blame] | 1110 | Query *Context::getQuery(GLuint handle, bool create, GLenum type) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1111 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 1112 | if (!mQueryMap.contains(handle)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1113 | { |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 1114 | return nullptr; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1115 | } |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 1116 | |
| 1117 | Query *query = mQueryMap.query(handle); |
| 1118 | if (!query && create) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1119 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 1120 | query = new Query(mImplementation->createQuery(type), handle); |
| 1121 | query->addRef(); |
| 1122 | mQueryMap.assign(handle, query); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1123 | } |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 1124 | return query; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1125 | } |
| 1126 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1127 | Query *Context::getQuery(GLuint handle) const |
| 1128 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 1129 | return mQueryMap.query(handle); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1130 | } |
| 1131 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1132 | Texture *Context::getTargetTexture(GLenum target) const |
| 1133 | { |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 1134 | ASSERT(ValidTextureTarget(this, target) || ValidTextureExternalTarget(this, target)); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1135 | return mGLState.getTargetTexture(target); |
shannon.woods%transgaming.com@gtempaccount.com | c926e5f | 2013-04-13 03:39:18 +0000 | [diff] [blame] | 1136 | } |
| 1137 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 1138 | Texture *Context::getSamplerTexture(unsigned int sampler, GLenum type) const |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1139 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1140 | return mGLState.getSamplerTexture(sampler, type); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1141 | } |
| 1142 | |
Geoff Lang | 492a7e4 | 2014-11-05 13:27:06 -0500 | [diff] [blame] | 1143 | Compiler *Context::getCompiler() const |
| 1144 | { |
Jamie Madill | 2f348d2 | 2017-06-05 10:50:59 -0400 | [diff] [blame] | 1145 | if (mCompiler.get() == nullptr) |
| 1146 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1147 | mCompiler.set(this, new Compiler(mImplementation.get(), mState)); |
Jamie Madill | 2f348d2 | 2017-06-05 10:50:59 -0400 | [diff] [blame] | 1148 | } |
| 1149 | return mCompiler.get(); |
Geoff Lang | 492a7e4 | 2014-11-05 13:27:06 -0500 | [diff] [blame] | 1150 | } |
| 1151 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 1152 | void Context::getBooleanvImpl(GLenum pname, GLboolean *params) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1153 | { |
| 1154 | switch (pname) |
| 1155 | { |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 1156 | case GL_SHADER_COMPILER: |
| 1157 | *params = GL_TRUE; |
| 1158 | break; |
| 1159 | case GL_CONTEXT_ROBUST_ACCESS_EXT: |
| 1160 | *params = mRobustAccess ? GL_TRUE : GL_FALSE; |
| 1161 | break; |
| 1162 | default: |
| 1163 | mGLState.getBooleanv(pname, params); |
| 1164 | break; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1165 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1166 | } |
| 1167 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 1168 | void Context::getFloatvImpl(GLenum pname, GLfloat *params) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1169 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1170 | // Queries about context capabilities and maximums are answered by Context. |
| 1171 | // Queries about current GL state values are answered by State. |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1172 | switch (pname) |
| 1173 | { |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 1174 | case GL_ALIASED_LINE_WIDTH_RANGE: |
| 1175 | params[0] = mCaps.minAliasedLineWidth; |
| 1176 | params[1] = mCaps.maxAliasedLineWidth; |
| 1177 | break; |
| 1178 | case GL_ALIASED_POINT_SIZE_RANGE: |
| 1179 | params[0] = mCaps.minAliasedPointSize; |
| 1180 | params[1] = mCaps.maxAliasedPointSize; |
| 1181 | break; |
| 1182 | case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT: |
| 1183 | ASSERT(mExtensions.textureFilterAnisotropic); |
| 1184 | *params = mExtensions.maxTextureAnisotropy; |
| 1185 | break; |
| 1186 | case GL_MAX_TEXTURE_LOD_BIAS: |
| 1187 | *params = mCaps.maxLODBias; |
| 1188 | break; |
| 1189 | |
| 1190 | case GL_PATH_MODELVIEW_MATRIX_CHROMIUM: |
| 1191 | case GL_PATH_PROJECTION_MATRIX_CHROMIUM: |
| 1192 | { |
| 1193 | ASSERT(mExtensions.pathRendering); |
| 1194 | const GLfloat *m = mGLState.getPathRenderingMatrix(pname); |
| 1195 | memcpy(params, m, 16 * sizeof(GLfloat)); |
| 1196 | } |
Geoff Lang | e6d4e12 | 2015-06-29 13:33:55 -0400 | [diff] [blame] | 1197 | break; |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1198 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 1199 | default: |
| 1200 | mGLState.getFloatv(pname, params); |
| 1201 | break; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1202 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1203 | } |
| 1204 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 1205 | void Context::getIntegervImpl(GLenum pname, GLint *params) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1206 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1207 | // Queries about context capabilities and maximums are answered by Context. |
| 1208 | // Queries about current GL state values are answered by State. |
shannon.woods%transgaming.com@gtempaccount.com | bc373e5 | 2013-04-13 03:31:23 +0000 | [diff] [blame] | 1209 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1210 | switch (pname) |
| 1211 | { |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 1212 | case GL_MAX_VERTEX_ATTRIBS: |
| 1213 | *params = mCaps.maxVertexAttributes; |
| 1214 | break; |
| 1215 | case GL_MAX_VERTEX_UNIFORM_VECTORS: |
| 1216 | *params = mCaps.maxVertexUniformVectors; |
| 1217 | break; |
| 1218 | case GL_MAX_VERTEX_UNIFORM_COMPONENTS: |
| 1219 | *params = mCaps.maxVertexUniformComponents; |
| 1220 | break; |
| 1221 | case GL_MAX_VARYING_VECTORS: |
| 1222 | *params = mCaps.maxVaryingVectors; |
| 1223 | break; |
| 1224 | case GL_MAX_VARYING_COMPONENTS: |
| 1225 | *params = mCaps.maxVertexOutputComponents; |
| 1226 | break; |
| 1227 | case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: |
| 1228 | *params = mCaps.maxCombinedTextureImageUnits; |
| 1229 | break; |
| 1230 | case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS: |
| 1231 | *params = mCaps.maxVertexTextureImageUnits; |
| 1232 | break; |
| 1233 | case GL_MAX_TEXTURE_IMAGE_UNITS: |
| 1234 | *params = mCaps.maxTextureImageUnits; |
| 1235 | break; |
| 1236 | case GL_MAX_FRAGMENT_UNIFORM_VECTORS: |
| 1237 | *params = mCaps.maxFragmentUniformVectors; |
| 1238 | break; |
| 1239 | case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS: |
| 1240 | *params = mCaps.maxFragmentUniformComponents; |
| 1241 | break; |
| 1242 | case GL_MAX_RENDERBUFFER_SIZE: |
| 1243 | *params = mCaps.maxRenderbufferSize; |
| 1244 | break; |
| 1245 | case GL_MAX_COLOR_ATTACHMENTS_EXT: |
| 1246 | *params = mCaps.maxColorAttachments; |
| 1247 | break; |
| 1248 | case GL_MAX_DRAW_BUFFERS_EXT: |
| 1249 | *params = mCaps.maxDrawBuffers; |
| 1250 | break; |
| 1251 | // case GL_FRAMEBUFFER_BINDING: // now equivalent to |
| 1252 | // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE |
| 1253 | case GL_SUBPIXEL_BITS: |
| 1254 | *params = 4; |
| 1255 | break; |
| 1256 | case GL_MAX_TEXTURE_SIZE: |
| 1257 | *params = mCaps.max2DTextureSize; |
| 1258 | break; |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1259 | case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE: |
| 1260 | *params = mCaps.maxRectangleTextureSize; |
| 1261 | break; |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 1262 | case GL_MAX_CUBE_MAP_TEXTURE_SIZE: |
| 1263 | *params = mCaps.maxCubeMapTextureSize; |
| 1264 | break; |
| 1265 | case GL_MAX_3D_TEXTURE_SIZE: |
| 1266 | *params = mCaps.max3DTextureSize; |
| 1267 | break; |
| 1268 | case GL_MAX_ARRAY_TEXTURE_LAYERS: |
| 1269 | *params = mCaps.maxArrayTextureLayers; |
| 1270 | break; |
| 1271 | case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT: |
| 1272 | *params = mCaps.uniformBufferOffsetAlignment; |
| 1273 | break; |
| 1274 | case GL_MAX_UNIFORM_BUFFER_BINDINGS: |
| 1275 | *params = mCaps.maxUniformBufferBindings; |
| 1276 | break; |
| 1277 | case GL_MAX_VERTEX_UNIFORM_BLOCKS: |
| 1278 | *params = mCaps.maxVertexUniformBlocks; |
| 1279 | break; |
| 1280 | case GL_MAX_FRAGMENT_UNIFORM_BLOCKS: |
| 1281 | *params = mCaps.maxFragmentUniformBlocks; |
| 1282 | break; |
| 1283 | case GL_MAX_COMBINED_UNIFORM_BLOCKS: |
| 1284 | *params = mCaps.maxCombinedTextureImageUnits; |
| 1285 | break; |
| 1286 | case GL_MAX_VERTEX_OUTPUT_COMPONENTS: |
| 1287 | *params = mCaps.maxVertexOutputComponents; |
| 1288 | break; |
| 1289 | case GL_MAX_FRAGMENT_INPUT_COMPONENTS: |
| 1290 | *params = mCaps.maxFragmentInputComponents; |
| 1291 | break; |
| 1292 | case GL_MIN_PROGRAM_TEXEL_OFFSET: |
| 1293 | *params = mCaps.minProgramTexelOffset; |
| 1294 | break; |
| 1295 | case GL_MAX_PROGRAM_TEXEL_OFFSET: |
| 1296 | *params = mCaps.maxProgramTexelOffset; |
| 1297 | break; |
| 1298 | case GL_MAJOR_VERSION: |
| 1299 | *params = getClientVersion().major; |
| 1300 | break; |
| 1301 | case GL_MINOR_VERSION: |
| 1302 | *params = getClientVersion().minor; |
| 1303 | break; |
| 1304 | case GL_MAX_ELEMENTS_INDICES: |
| 1305 | *params = mCaps.maxElementsIndices; |
| 1306 | break; |
| 1307 | case GL_MAX_ELEMENTS_VERTICES: |
| 1308 | *params = mCaps.maxElementsVertices; |
| 1309 | break; |
| 1310 | case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS: |
| 1311 | *params = mCaps.maxTransformFeedbackInterleavedComponents; |
| 1312 | break; |
| 1313 | case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS: |
| 1314 | *params = mCaps.maxTransformFeedbackSeparateAttributes; |
| 1315 | break; |
| 1316 | case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS: |
| 1317 | *params = mCaps.maxTransformFeedbackSeparateComponents; |
| 1318 | break; |
| 1319 | case GL_NUM_COMPRESSED_TEXTURE_FORMATS: |
| 1320 | *params = static_cast<GLint>(mCaps.compressedTextureFormats.size()); |
| 1321 | break; |
| 1322 | case GL_MAX_SAMPLES_ANGLE: |
| 1323 | *params = mCaps.maxSamples; |
| 1324 | break; |
| 1325 | case GL_MAX_VIEWPORT_DIMS: |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1326 | { |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1327 | params[0] = mCaps.maxViewportWidth; |
| 1328 | params[1] = mCaps.maxViewportHeight; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1329 | } |
| 1330 | break; |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 1331 | case GL_COMPRESSED_TEXTURE_FORMATS: |
| 1332 | std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(), |
| 1333 | params); |
| 1334 | break; |
| 1335 | case GL_RESET_NOTIFICATION_STRATEGY_EXT: |
| 1336 | *params = mResetStrategy; |
| 1337 | break; |
| 1338 | case GL_NUM_SHADER_BINARY_FORMATS: |
| 1339 | *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size()); |
| 1340 | break; |
| 1341 | case GL_SHADER_BINARY_FORMATS: |
| 1342 | std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params); |
| 1343 | break; |
| 1344 | case GL_NUM_PROGRAM_BINARY_FORMATS: |
| 1345 | *params = static_cast<GLint>(mCaps.programBinaryFormats.size()); |
| 1346 | break; |
| 1347 | case GL_PROGRAM_BINARY_FORMATS: |
| 1348 | std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params); |
| 1349 | break; |
| 1350 | case GL_NUM_EXTENSIONS: |
| 1351 | *params = static_cast<GLint>(mExtensionStrings.size()); |
| 1352 | break; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1353 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 1354 | // GL_KHR_debug |
| 1355 | case GL_MAX_DEBUG_MESSAGE_LENGTH: |
| 1356 | *params = mExtensions.maxDebugMessageLength; |
| 1357 | break; |
| 1358 | case GL_MAX_DEBUG_LOGGED_MESSAGES: |
| 1359 | *params = mExtensions.maxDebugLoggedMessages; |
| 1360 | break; |
| 1361 | case GL_MAX_DEBUG_GROUP_STACK_DEPTH: |
| 1362 | *params = mExtensions.maxDebugGroupStackDepth; |
| 1363 | break; |
| 1364 | case GL_MAX_LABEL_LENGTH: |
| 1365 | *params = mExtensions.maxLabelLength; |
| 1366 | break; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1367 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 1368 | // GL_ANGLE_multiview |
| 1369 | case GL_MAX_VIEWS_ANGLE: |
| 1370 | *params = mExtensions.maxViews; |
| 1371 | break; |
| 1372 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 1373 | // GL_EXT_disjoint_timer_query |
| 1374 | case GL_GPU_DISJOINT_EXT: |
| 1375 | *params = mImplementation->getGPUDisjoint(); |
| 1376 | break; |
| 1377 | case GL_MAX_FRAMEBUFFER_WIDTH: |
| 1378 | *params = mCaps.maxFramebufferWidth; |
| 1379 | break; |
| 1380 | case GL_MAX_FRAMEBUFFER_HEIGHT: |
| 1381 | *params = mCaps.maxFramebufferHeight; |
| 1382 | break; |
| 1383 | case GL_MAX_FRAMEBUFFER_SAMPLES: |
| 1384 | *params = mCaps.maxFramebufferSamples; |
| 1385 | break; |
| 1386 | case GL_MAX_SAMPLE_MASK_WORDS: |
| 1387 | *params = mCaps.maxSampleMaskWords; |
| 1388 | break; |
| 1389 | case GL_MAX_COLOR_TEXTURE_SAMPLES: |
| 1390 | *params = mCaps.maxColorTextureSamples; |
| 1391 | break; |
| 1392 | case GL_MAX_DEPTH_TEXTURE_SAMPLES: |
| 1393 | *params = mCaps.maxDepthTextureSamples; |
| 1394 | break; |
| 1395 | case GL_MAX_INTEGER_SAMPLES: |
| 1396 | *params = mCaps.maxIntegerSamples; |
| 1397 | break; |
| 1398 | case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET: |
| 1399 | *params = mCaps.maxVertexAttribRelativeOffset; |
| 1400 | break; |
| 1401 | case GL_MAX_VERTEX_ATTRIB_BINDINGS: |
| 1402 | *params = mCaps.maxVertexAttribBindings; |
| 1403 | break; |
| 1404 | case GL_MAX_VERTEX_ATTRIB_STRIDE: |
| 1405 | *params = mCaps.maxVertexAttribStride; |
| 1406 | break; |
| 1407 | case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS: |
| 1408 | *params = mCaps.maxVertexAtomicCounterBuffers; |
| 1409 | break; |
| 1410 | case GL_MAX_VERTEX_ATOMIC_COUNTERS: |
| 1411 | *params = mCaps.maxVertexAtomicCounters; |
| 1412 | break; |
| 1413 | case GL_MAX_VERTEX_IMAGE_UNIFORMS: |
| 1414 | *params = mCaps.maxVertexImageUniforms; |
| 1415 | break; |
| 1416 | case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS: |
| 1417 | *params = mCaps.maxVertexShaderStorageBlocks; |
| 1418 | break; |
| 1419 | case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS: |
| 1420 | *params = mCaps.maxFragmentAtomicCounterBuffers; |
| 1421 | break; |
| 1422 | case GL_MAX_FRAGMENT_ATOMIC_COUNTERS: |
| 1423 | *params = mCaps.maxFragmentAtomicCounters; |
| 1424 | break; |
| 1425 | case GL_MAX_FRAGMENT_IMAGE_UNIFORMS: |
| 1426 | *params = mCaps.maxFragmentImageUniforms; |
| 1427 | break; |
| 1428 | case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS: |
| 1429 | *params = mCaps.maxFragmentShaderStorageBlocks; |
| 1430 | break; |
| 1431 | case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET: |
| 1432 | *params = mCaps.minProgramTextureGatherOffset; |
| 1433 | break; |
| 1434 | case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET: |
| 1435 | *params = mCaps.maxProgramTextureGatherOffset; |
| 1436 | break; |
| 1437 | case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS: |
| 1438 | *params = mCaps.maxComputeWorkGroupInvocations; |
| 1439 | break; |
| 1440 | case GL_MAX_COMPUTE_UNIFORM_BLOCKS: |
| 1441 | *params = mCaps.maxComputeUniformBlocks; |
| 1442 | break; |
| 1443 | case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS: |
| 1444 | *params = mCaps.maxComputeTextureImageUnits; |
| 1445 | break; |
| 1446 | case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE: |
| 1447 | *params = mCaps.maxComputeSharedMemorySize; |
| 1448 | break; |
| 1449 | case GL_MAX_COMPUTE_UNIFORM_COMPONENTS: |
| 1450 | *params = mCaps.maxComputeUniformComponents; |
| 1451 | break; |
| 1452 | case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS: |
| 1453 | *params = mCaps.maxComputeAtomicCounterBuffers; |
| 1454 | break; |
| 1455 | case GL_MAX_COMPUTE_ATOMIC_COUNTERS: |
| 1456 | *params = mCaps.maxComputeAtomicCounters; |
| 1457 | break; |
| 1458 | case GL_MAX_COMPUTE_IMAGE_UNIFORMS: |
| 1459 | *params = mCaps.maxComputeImageUniforms; |
| 1460 | break; |
| 1461 | case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS: |
| 1462 | *params = mCaps.maxCombinedComputeUniformComponents; |
| 1463 | break; |
| 1464 | case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS: |
| 1465 | *params = mCaps.maxComputeShaderStorageBlocks; |
| 1466 | break; |
| 1467 | case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES: |
| 1468 | *params = mCaps.maxCombinedShaderOutputResources; |
| 1469 | break; |
| 1470 | case GL_MAX_UNIFORM_LOCATIONS: |
| 1471 | *params = mCaps.maxUniformLocations; |
| 1472 | break; |
| 1473 | case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS: |
| 1474 | *params = mCaps.maxAtomicCounterBufferBindings; |
| 1475 | break; |
| 1476 | case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE: |
| 1477 | *params = mCaps.maxAtomicCounterBufferSize; |
| 1478 | break; |
| 1479 | case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS: |
| 1480 | *params = mCaps.maxCombinedAtomicCounterBuffers; |
| 1481 | break; |
| 1482 | case GL_MAX_COMBINED_ATOMIC_COUNTERS: |
| 1483 | *params = mCaps.maxCombinedAtomicCounters; |
| 1484 | break; |
| 1485 | case GL_MAX_IMAGE_UNITS: |
| 1486 | *params = mCaps.maxImageUnits; |
| 1487 | break; |
| 1488 | case GL_MAX_COMBINED_IMAGE_UNIFORMS: |
| 1489 | *params = mCaps.maxCombinedImageUniforms; |
| 1490 | break; |
| 1491 | case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS: |
| 1492 | *params = mCaps.maxShaderStorageBufferBindings; |
| 1493 | break; |
| 1494 | case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS: |
| 1495 | *params = mCaps.maxCombinedShaderStorageBlocks; |
| 1496 | break; |
| 1497 | case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT: |
| 1498 | *params = mCaps.shaderStorageBufferOffsetAlignment; |
| 1499 | break; |
| 1500 | default: |
| 1501 | mGLState.getIntegerv(this, pname, params); |
| 1502 | break; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1503 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1504 | } |
| 1505 | |
Jamie Madill | 7f0c5a4 | 2017-08-26 22:43:26 -0400 | [diff] [blame] | 1506 | void Context::getInteger64vImpl(GLenum pname, GLint64 *params) |
Jamie Madill | 0fda986 | 2013-07-19 16:36:55 -0400 | [diff] [blame] | 1507 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1508 | // Queries about context capabilities and maximums are answered by Context. |
| 1509 | // Queries about current GL state values are answered by State. |
Jamie Madill | 0fda986 | 2013-07-19 16:36:55 -0400 | [diff] [blame] | 1510 | switch (pname) |
| 1511 | { |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 1512 | case GL_MAX_ELEMENT_INDEX: |
| 1513 | *params = mCaps.maxElementIndex; |
| 1514 | break; |
| 1515 | case GL_MAX_UNIFORM_BLOCK_SIZE: |
| 1516 | *params = mCaps.maxUniformBlockSize; |
| 1517 | break; |
| 1518 | case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS: |
| 1519 | *params = mCaps.maxCombinedVertexUniformComponents; |
| 1520 | break; |
| 1521 | case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS: |
| 1522 | *params = mCaps.maxCombinedFragmentUniformComponents; |
| 1523 | break; |
| 1524 | case GL_MAX_SERVER_WAIT_TIMEOUT: |
| 1525 | *params = mCaps.maxServerWaitTimeout; |
| 1526 | break; |
Ian Ewell | 53f59f4 | 2016-01-28 17:36:55 -0500 | [diff] [blame] | 1527 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 1528 | // GL_EXT_disjoint_timer_query |
| 1529 | case GL_TIMESTAMP_EXT: |
| 1530 | *params = mImplementation->getTimestamp(); |
| 1531 | break; |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1532 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 1533 | case GL_MAX_SHADER_STORAGE_BLOCK_SIZE: |
| 1534 | *params = mCaps.maxShaderStorageBlockSize; |
| 1535 | break; |
| 1536 | default: |
| 1537 | UNREACHABLE(); |
| 1538 | break; |
Jamie Madill | 0fda986 | 2013-07-19 16:36:55 -0400 | [diff] [blame] | 1539 | } |
Jamie Madill | 0fda986 | 2013-07-19 16:36:55 -0400 | [diff] [blame] | 1540 | } |
| 1541 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1542 | void Context::getPointerv(GLenum pname, void **params) const |
| 1543 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1544 | mGLState.getPointerv(pname, params); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1545 | } |
| 1546 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1547 | void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data) |
Shannon Woods | 1b2fb85 | 2013-08-19 14:28:48 -0400 | [diff] [blame] | 1548 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1549 | // Queries about context capabilities and maximums are answered by Context. |
| 1550 | // Queries about current GL state values are answered by State. |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1551 | |
| 1552 | GLenum nativeType; |
| 1553 | unsigned int numParams; |
| 1554 | bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams); |
| 1555 | ASSERT(queryStatus); |
| 1556 | |
| 1557 | if (nativeType == GL_INT) |
| 1558 | { |
| 1559 | switch (target) |
| 1560 | { |
| 1561 | case GL_MAX_COMPUTE_WORK_GROUP_COUNT: |
| 1562 | ASSERT(index < 3u); |
| 1563 | *data = mCaps.maxComputeWorkGroupCount[index]; |
| 1564 | break; |
| 1565 | case GL_MAX_COMPUTE_WORK_GROUP_SIZE: |
| 1566 | ASSERT(index < 3u); |
| 1567 | *data = mCaps.maxComputeWorkGroupSize[index]; |
| 1568 | break; |
| 1569 | default: |
| 1570 | mGLState.getIntegeri_v(target, index, data); |
| 1571 | } |
| 1572 | } |
| 1573 | else |
| 1574 | { |
| 1575 | CastIndexedStateValues(this, nativeType, target, index, numParams, data); |
| 1576 | } |
Shannon Woods | 1b2fb85 | 2013-08-19 14:28:48 -0400 | [diff] [blame] | 1577 | } |
| 1578 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1579 | void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data) |
Shannon Woods | 1b2fb85 | 2013-08-19 14:28:48 -0400 | [diff] [blame] | 1580 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1581 | // Queries about context capabilities and maximums are answered by Context. |
| 1582 | // Queries about current GL state values are answered by State. |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1583 | |
| 1584 | GLenum nativeType; |
| 1585 | unsigned int numParams; |
| 1586 | bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams); |
| 1587 | ASSERT(queryStatus); |
| 1588 | |
| 1589 | if (nativeType == GL_INT_64_ANGLEX) |
| 1590 | { |
| 1591 | mGLState.getInteger64i_v(target, index, data); |
| 1592 | } |
| 1593 | else |
| 1594 | { |
| 1595 | CastIndexedStateValues(this, nativeType, target, index, numParams, data); |
| 1596 | } |
| 1597 | } |
| 1598 | |
| 1599 | void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data) |
| 1600 | { |
| 1601 | // Queries about context capabilities and maximums are answered by Context. |
| 1602 | // Queries about current GL state values are answered by State. |
| 1603 | |
| 1604 | GLenum nativeType; |
| 1605 | unsigned int numParams; |
| 1606 | bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams); |
| 1607 | ASSERT(queryStatus); |
| 1608 | |
| 1609 | if (nativeType == GL_BOOL) |
| 1610 | { |
| 1611 | mGLState.getBooleani_v(target, index, data); |
| 1612 | } |
| 1613 | else |
| 1614 | { |
| 1615 | CastIndexedStateValues(this, nativeType, target, index, numParams, data); |
| 1616 | } |
Shannon Woods | 1b2fb85 | 2013-08-19 14:28:48 -0400 | [diff] [blame] | 1617 | } |
| 1618 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 1619 | void Context::getBufferParameteriv(BufferBinding target, GLenum pname, GLint *params) |
He Yunchao | 010e4db | 2017-03-03 14:22:06 +0800 | [diff] [blame] | 1620 | { |
| 1621 | Buffer *buffer = mGLState.getTargetBuffer(target); |
| 1622 | QueryBufferParameteriv(buffer, pname, params); |
| 1623 | } |
| 1624 | |
| 1625 | void Context::getFramebufferAttachmentParameteriv(GLenum target, |
| 1626 | GLenum attachment, |
| 1627 | GLenum pname, |
| 1628 | GLint *params) |
| 1629 | { |
| 1630 | const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
| 1631 | QueryFramebufferAttachmentParameteriv(framebuffer, attachment, pname, params); |
| 1632 | } |
| 1633 | |
| 1634 | void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params) |
| 1635 | { |
| 1636 | Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer(); |
| 1637 | QueryRenderbufferiv(this, renderbuffer, pname, params); |
| 1638 | } |
| 1639 | |
| 1640 | void Context::getTexParameterfv(GLenum target, GLenum pname, GLfloat *params) |
| 1641 | { |
| 1642 | Texture *texture = getTargetTexture(target); |
| 1643 | QueryTexParameterfv(texture, pname, params); |
| 1644 | } |
| 1645 | |
| 1646 | void Context::getTexParameteriv(GLenum target, GLenum pname, GLint *params) |
| 1647 | { |
| 1648 | Texture *texture = getTargetTexture(target); |
| 1649 | QueryTexParameteriv(texture, pname, params); |
| 1650 | } |
| 1651 | void Context::texParameterf(GLenum target, GLenum pname, GLfloat param) |
| 1652 | { |
| 1653 | Texture *texture = getTargetTexture(target); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1654 | SetTexParameterf(this, texture, pname, param); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1655 | onTextureChange(texture); |
He Yunchao | 010e4db | 2017-03-03 14:22:06 +0800 | [diff] [blame] | 1656 | } |
| 1657 | |
| 1658 | void Context::texParameterfv(GLenum target, GLenum pname, const GLfloat *params) |
| 1659 | { |
| 1660 | Texture *texture = getTargetTexture(target); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1661 | SetTexParameterfv(this, texture, pname, params); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1662 | onTextureChange(texture); |
He Yunchao | 010e4db | 2017-03-03 14:22:06 +0800 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | void Context::texParameteri(GLenum target, GLenum pname, GLint param) |
| 1666 | { |
| 1667 | Texture *texture = getTargetTexture(target); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1668 | SetTexParameteri(this, texture, pname, param); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1669 | onTextureChange(texture); |
He Yunchao | 010e4db | 2017-03-03 14:22:06 +0800 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | void Context::texParameteriv(GLenum target, GLenum pname, const GLint *params) |
| 1673 | { |
| 1674 | Texture *texture = getTargetTexture(target); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1675 | SetTexParameteriv(this, texture, pname, params); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1676 | onTextureChange(texture); |
He Yunchao | 010e4db | 2017-03-03 14:22:06 +0800 | [diff] [blame] | 1677 | } |
| 1678 | |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1679 | void Context::drawArrays(GLenum mode, GLint first, GLsizei count) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1680 | { |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1681 | ANGLE_CONTEXT_TRY(prepareForDraw()); |
Jamie Madill | b666492 | 2017-07-25 12:55:04 -0400 | [diff] [blame] | 1682 | ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count)); |
| 1683 | MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1684 | } |
| 1685 | |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1686 | void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount) |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 1687 | { |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1688 | ANGLE_CONTEXT_TRY(prepareForDraw()); |
Jamie Madill | b666492 | 2017-07-25 12:55:04 -0400 | [diff] [blame] | 1689 | ANGLE_CONTEXT_TRY( |
| 1690 | mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount)); |
| 1691 | MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback()); |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 1692 | } |
| 1693 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1694 | void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1695 | { |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1696 | ANGLE_CONTEXT_TRY(prepareForDraw()); |
Jamie Madill | b666492 | 2017-07-25 12:55:04 -0400 | [diff] [blame] | 1697 | ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices)); |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 1698 | } |
| 1699 | |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1700 | void Context::drawElementsInstanced(GLenum mode, |
| 1701 | GLsizei count, |
| 1702 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1703 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 1704 | GLsizei instances) |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 1705 | { |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1706 | ANGLE_CONTEXT_TRY(prepareForDraw()); |
Jamie Madill | b666492 | 2017-07-25 12:55:04 -0400 | [diff] [blame] | 1707 | ANGLE_CONTEXT_TRY( |
Qin Jiajia | 1da0065 | 2017-06-20 17:16:25 +0800 | [diff] [blame] | 1708 | mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances)); |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 1709 | } |
| 1710 | |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1711 | void Context::drawRangeElements(GLenum mode, |
| 1712 | GLuint start, |
| 1713 | GLuint end, |
| 1714 | GLsizei count, |
| 1715 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1716 | const void *indices) |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 1717 | { |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1718 | ANGLE_CONTEXT_TRY(prepareForDraw()); |
Jamie Madill | b666492 | 2017-07-25 12:55:04 -0400 | [diff] [blame] | 1719 | ANGLE_CONTEXT_TRY( |
| 1720 | mImplementation->drawRangeElements(this, mode, start, end, count, type, indices)); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1721 | } |
| 1722 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1723 | void Context::drawArraysIndirect(GLenum mode, const void *indirect) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1724 | { |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1725 | ANGLE_CONTEXT_TRY(prepareForDraw()); |
Jamie Madill | b666492 | 2017-07-25 12:55:04 -0400 | [diff] [blame] | 1726 | ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect)); |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1727 | } |
| 1728 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1729 | void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1730 | { |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 1731 | ANGLE_CONTEXT_TRY(prepareForDraw()); |
Jamie Madill | b666492 | 2017-07-25 12:55:04 -0400 | [diff] [blame] | 1732 | ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect)); |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1733 | } |
| 1734 | |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1735 | void Context::flush() |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1736 | { |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1737 | handleError(mImplementation->flush()); |
Geoff Lang | 129753a | 2015-01-09 16:52:09 -0500 | [diff] [blame] | 1738 | } |
| 1739 | |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1740 | void Context::finish() |
Geoff Lang | 129753a | 2015-01-09 16:52:09 -0500 | [diff] [blame] | 1741 | { |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1742 | handleError(mImplementation->finish()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1743 | } |
| 1744 | |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 1745 | void Context::insertEventMarker(GLsizei length, const char *marker) |
| 1746 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 1747 | ASSERT(mImplementation); |
| 1748 | mImplementation->insertEventMarker(length, marker); |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | void Context::pushGroupMarker(GLsizei length, const char *marker) |
| 1752 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 1753 | ASSERT(mImplementation); |
| 1754 | mImplementation->pushGroupMarker(length, marker); |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 1755 | } |
| 1756 | |
| 1757 | void Context::popGroupMarker() |
| 1758 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 1759 | ASSERT(mImplementation); |
| 1760 | mImplementation->popGroupMarker(); |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 1761 | } |
| 1762 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 1763 | void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name) |
| 1764 | { |
| 1765 | Program *programObject = getProgram(program); |
| 1766 | ASSERT(programObject); |
| 1767 | |
| 1768 | programObject->bindUniformLocation(location, name); |
| 1769 | } |
| 1770 | |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 1771 | void Context::setCoverageModulation(GLenum components) |
| 1772 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1773 | mGLState.setCoverageModulation(components); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 1774 | } |
| 1775 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1776 | void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix) |
| 1777 | { |
| 1778 | mGLState.loadPathRenderingMatrix(matrixMode, matrix); |
| 1779 | } |
| 1780 | |
| 1781 | void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode) |
| 1782 | { |
| 1783 | GLfloat I[16]; |
| 1784 | angle::Matrix<GLfloat>::setToIdentity(I); |
| 1785 | |
| 1786 | mGLState.loadPathRenderingMatrix(matrixMode, I); |
| 1787 | } |
| 1788 | |
| 1789 | void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask) |
| 1790 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1791 | const auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1792 | if (!pathObj) |
| 1793 | return; |
| 1794 | |
| 1795 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1796 | syncRendererState(); |
| 1797 | |
| 1798 | mImplementation->stencilFillPath(pathObj, fillMode, mask); |
| 1799 | } |
| 1800 | |
| 1801 | void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask) |
| 1802 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1803 | const auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1804 | if (!pathObj) |
| 1805 | return; |
| 1806 | |
| 1807 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1808 | syncRendererState(); |
| 1809 | |
| 1810 | mImplementation->stencilStrokePath(pathObj, reference, mask); |
| 1811 | } |
| 1812 | |
| 1813 | void Context::coverFillPath(GLuint path, GLenum coverMode) |
| 1814 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1815 | const auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1816 | if (!pathObj) |
| 1817 | return; |
| 1818 | |
| 1819 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1820 | syncRendererState(); |
| 1821 | |
| 1822 | mImplementation->coverFillPath(pathObj, coverMode); |
| 1823 | } |
| 1824 | |
| 1825 | void Context::coverStrokePath(GLuint path, GLenum coverMode) |
| 1826 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1827 | const auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1828 | if (!pathObj) |
| 1829 | return; |
| 1830 | |
| 1831 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1832 | syncRendererState(); |
| 1833 | |
| 1834 | mImplementation->coverStrokePath(pathObj, coverMode); |
| 1835 | } |
| 1836 | |
| 1837 | void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode) |
| 1838 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1839 | const auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1840 | if (!pathObj) |
| 1841 | return; |
| 1842 | |
| 1843 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1844 | syncRendererState(); |
| 1845 | |
| 1846 | mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode); |
| 1847 | } |
| 1848 | |
| 1849 | void Context::stencilThenCoverStrokePath(GLuint path, |
| 1850 | GLint reference, |
| 1851 | GLuint mask, |
| 1852 | GLenum coverMode) |
| 1853 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1854 | const auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1855 | if (!pathObj) |
| 1856 | return; |
| 1857 | |
| 1858 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1859 | syncRendererState(); |
| 1860 | |
| 1861 | mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode); |
| 1862 | } |
| 1863 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1864 | void Context::coverFillPathInstanced(GLsizei numPaths, |
| 1865 | GLenum pathNameType, |
| 1866 | const void *paths, |
| 1867 | GLuint pathBase, |
| 1868 | GLenum coverMode, |
| 1869 | GLenum transformType, |
| 1870 | const GLfloat *transformValues) |
| 1871 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1872 | const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1873 | |
| 1874 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1875 | syncRendererState(); |
| 1876 | |
| 1877 | mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues); |
| 1878 | } |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1879 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1880 | void Context::coverStrokePathInstanced(GLsizei numPaths, |
| 1881 | GLenum pathNameType, |
| 1882 | const void *paths, |
| 1883 | GLuint pathBase, |
| 1884 | GLenum coverMode, |
| 1885 | GLenum transformType, |
| 1886 | const GLfloat *transformValues) |
| 1887 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1888 | const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1889 | |
| 1890 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1891 | syncRendererState(); |
| 1892 | |
| 1893 | mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType, |
| 1894 | transformValues); |
| 1895 | } |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1896 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1897 | void Context::stencilFillPathInstanced(GLsizei numPaths, |
| 1898 | GLenum pathNameType, |
| 1899 | const void *paths, |
| 1900 | GLuint pathBase, |
| 1901 | GLenum fillMode, |
| 1902 | GLuint mask, |
| 1903 | GLenum transformType, |
| 1904 | const GLfloat *transformValues) |
| 1905 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1906 | const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1907 | |
| 1908 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1909 | syncRendererState(); |
| 1910 | |
| 1911 | mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType, |
| 1912 | transformValues); |
| 1913 | } |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1914 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1915 | void Context::stencilStrokePathInstanced(GLsizei numPaths, |
| 1916 | GLenum pathNameType, |
| 1917 | const void *paths, |
| 1918 | GLuint pathBase, |
| 1919 | GLint reference, |
| 1920 | GLuint mask, |
| 1921 | GLenum transformType, |
| 1922 | const GLfloat *transformValues) |
| 1923 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1924 | const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1925 | |
| 1926 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1927 | syncRendererState(); |
| 1928 | |
| 1929 | mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType, |
| 1930 | transformValues); |
| 1931 | } |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1932 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1933 | void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths, |
| 1934 | GLenum pathNameType, |
| 1935 | const void *paths, |
| 1936 | GLuint pathBase, |
| 1937 | GLenum fillMode, |
| 1938 | GLuint mask, |
| 1939 | GLenum coverMode, |
| 1940 | GLenum transformType, |
| 1941 | const GLfloat *transformValues) |
| 1942 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1943 | const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1944 | |
| 1945 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1946 | syncRendererState(); |
| 1947 | |
| 1948 | mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask, |
| 1949 | transformType, transformValues); |
| 1950 | } |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1951 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1952 | void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths, |
| 1953 | GLenum pathNameType, |
| 1954 | const void *paths, |
| 1955 | GLuint pathBase, |
| 1956 | GLint reference, |
| 1957 | GLuint mask, |
| 1958 | GLenum coverMode, |
| 1959 | GLenum transformType, |
| 1960 | const GLfloat *transformValues) |
| 1961 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1962 | const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1963 | |
| 1964 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1965 | syncRendererState(); |
| 1966 | |
| 1967 | mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask, |
| 1968 | transformType, transformValues); |
| 1969 | } |
| 1970 | |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1971 | void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name) |
| 1972 | { |
| 1973 | auto *programObject = getProgram(program); |
| 1974 | |
| 1975 | programObject->bindFragmentInputLocation(location, name); |
| 1976 | } |
| 1977 | |
| 1978 | void Context::programPathFragmentInputGen(GLuint program, |
| 1979 | GLint location, |
| 1980 | GLenum genMode, |
| 1981 | GLint components, |
| 1982 | const GLfloat *coeffs) |
| 1983 | { |
| 1984 | auto *programObject = getProgram(program); |
| 1985 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 1986 | programObject->pathFragmentInputGen(this, location, genMode, components, coeffs); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1987 | } |
| 1988 | |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 1989 | GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name) |
| 1990 | { |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 1991 | const auto *programObject = getProgram(program); |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 1992 | return QueryProgramResourceIndex(programObject, programInterface, name); |
| 1993 | } |
| 1994 | |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 1995 | void Context::getProgramResourceName(GLuint program, |
| 1996 | GLenum programInterface, |
| 1997 | GLuint index, |
| 1998 | GLsizei bufSize, |
| 1999 | GLsizei *length, |
| 2000 | GLchar *name) |
| 2001 | { |
| 2002 | const auto *programObject = getProgram(program); |
| 2003 | QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name); |
| 2004 | } |
| 2005 | |
jchen10 | 191381f | 2017-04-11 13:59:04 +0800 | [diff] [blame] | 2006 | GLint Context::getProgramResourceLocation(GLuint program, |
| 2007 | GLenum programInterface, |
| 2008 | const GLchar *name) |
| 2009 | { |
| 2010 | const auto *programObject = getProgram(program); |
| 2011 | return QueryProgramResourceLocation(programObject, programInterface, name); |
| 2012 | } |
| 2013 | |
jchen10 | 880683b | 2017-04-12 16:21:55 +0800 | [diff] [blame] | 2014 | void Context::getProgramResourceiv(GLuint program, |
| 2015 | GLenum programInterface, |
| 2016 | GLuint index, |
| 2017 | GLsizei propCount, |
| 2018 | const GLenum *props, |
| 2019 | GLsizei bufSize, |
| 2020 | GLsizei *length, |
| 2021 | GLint *params) |
| 2022 | { |
| 2023 | const auto *programObject = getProgram(program); |
| 2024 | QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize, |
| 2025 | length, params); |
| 2026 | } |
| 2027 | |
jchen10 | d9cd7b7 | 2017-08-30 15:04:25 +0800 | [diff] [blame] | 2028 | void Context::getProgramInterfaceiv(GLuint program, |
| 2029 | GLenum programInterface, |
| 2030 | GLenum pname, |
| 2031 | GLint *params) |
| 2032 | { |
| 2033 | const auto *programObject = getProgram(program); |
| 2034 | QueryProgramInterfaceiv(programObject, programInterface, pname, params); |
| 2035 | } |
| 2036 | |
Jamie Madill | 71c88b3 | 2017-09-14 22:20:29 -0400 | [diff] [blame] | 2037 | void Context::handleError(const Error &error) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2038 | { |
Geoff Lang | da5777c | 2014-07-11 09:52:58 -0400 | [diff] [blame] | 2039 | if (error.isError()) |
| 2040 | { |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 2041 | GLenum code = error.getCode(); |
| 2042 | mErrors.insert(code); |
| 2043 | if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory) |
| 2044 | { |
| 2045 | markContextLost(); |
| 2046 | } |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2047 | |
Geoff Lang | ee6884e | 2017-11-09 16:51:11 -0500 | [diff] [blame] | 2048 | ASSERT(!error.getMessage().empty()); |
| 2049 | mGLState.getDebug().insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(), |
| 2050 | GL_DEBUG_SEVERITY_HIGH, error.getMessage()); |
Geoff Lang | da5777c | 2014-07-11 09:52:58 -0400 | [diff] [blame] | 2051 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2052 | } |
| 2053 | |
| 2054 | // Get one of the recorded errors and clear its flag, if any. |
| 2055 | // [OpenGL ES 2.0.24] section 2.5 page 13. |
| 2056 | GLenum Context::getError() |
| 2057 | { |
Geoff Lang | da5777c | 2014-07-11 09:52:58 -0400 | [diff] [blame] | 2058 | if (mErrors.empty()) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2059 | { |
Geoff Lang | da5777c | 2014-07-11 09:52:58 -0400 | [diff] [blame] | 2060 | return GL_NO_ERROR; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2061 | } |
Geoff Lang | da5777c | 2014-07-11 09:52:58 -0400 | [diff] [blame] | 2062 | else |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2063 | { |
Geoff Lang | da5777c | 2014-07-11 09:52:58 -0400 | [diff] [blame] | 2064 | GLenum error = *mErrors.begin(); |
| 2065 | mErrors.erase(mErrors.begin()); |
| 2066 | return error; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2067 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2068 | } |
| 2069 | |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2070 | // NOTE: this function should not assume that this context is current! |
| 2071 | void Context::markContextLost() |
| 2072 | { |
| 2073 | if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT) |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 2074 | { |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 2075 | mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT; |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 2076 | mContextLostForced = true; |
| 2077 | } |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 2078 | mContextLost = true; |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2079 | } |
| 2080 | |
| 2081 | bool Context::isContextLost() |
| 2082 | { |
| 2083 | return mContextLost; |
| 2084 | } |
| 2085 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2086 | GLenum Context::getResetStatus() |
| 2087 | { |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2088 | // Even if the application doesn't want to know about resets, we want to know |
| 2089 | // as it will allow us to skip all the calls. |
| 2090 | if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2091 | { |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2092 | if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR) |
Jamie Madill | 9dd0cf0 | 2014-11-24 11:38:51 -0500 | [diff] [blame] | 2093 | { |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2094 | mContextLost = true; |
Jamie Madill | 9dd0cf0 | 2014-11-24 11:38:51 -0500 | [diff] [blame] | 2095 | } |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2096 | |
| 2097 | // EXT_robustness, section 2.6: If the reset notification behavior is |
| 2098 | // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of |
| 2099 | // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR. |
| 2100 | return GL_NO_ERROR; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2101 | } |
| 2102 | |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2103 | // The GL_EXT_robustness spec says that if a reset is encountered, a reset |
| 2104 | // status should be returned at least once, and GL_NO_ERROR should be returned |
| 2105 | // once the device has finished resetting. |
| 2106 | if (!mContextLost) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2107 | { |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2108 | ASSERT(mResetStatus == GL_NO_ERROR); |
| 2109 | mResetStatus = mImplementation->getResetStatus(); |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 2110 | |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2111 | if (mResetStatus != GL_NO_ERROR) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2112 | { |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2113 | mContextLost = true; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2114 | } |
| 2115 | } |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 2116 | else if (!mContextLostForced && mResetStatus != GL_NO_ERROR) |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2117 | { |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 2118 | // If markContextLost was used to mark the context lost then |
| 2119 | // assume that is not recoverable, and continue to report the |
| 2120 | // lost reset status for the lifetime of this context. |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2121 | mResetStatus = mImplementation->getResetStatus(); |
| 2122 | } |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2123 | |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2124 | return mResetStatus; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2125 | } |
| 2126 | |
| 2127 | bool Context::isResetNotificationEnabled() |
| 2128 | { |
| 2129 | return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT); |
| 2130 | } |
| 2131 | |
Corentin Wallez | e3b10e8 | 2015-05-20 11:06:25 -0400 | [diff] [blame] | 2132 | const egl::Config *Context::getConfig() const |
Régis Fénéon | 8310797 | 2015-02-05 12:57:44 +0100 | [diff] [blame] | 2133 | { |
Corentin Wallez | e3b10e8 | 2015-05-20 11:06:25 -0400 | [diff] [blame] | 2134 | return mConfig; |
Régis Fénéon | 8310797 | 2015-02-05 12:57:44 +0100 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | EGLenum Context::getClientType() const |
| 2138 | { |
| 2139 | return mClientType; |
| 2140 | } |
| 2141 | |
| 2142 | EGLenum Context::getRenderBuffer() const |
| 2143 | { |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 2144 | const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0); |
| 2145 | if (framebuffer == nullptr) |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 2146 | { |
| 2147 | return EGL_NONE; |
| 2148 | } |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 2149 | |
| 2150 | const FramebufferAttachment *backAttachment = framebuffer->getAttachment(GL_BACK); |
| 2151 | ASSERT(backAttachment != nullptr); |
| 2152 | return backAttachment->getSurface()->getRenderBuffer(); |
Régis Fénéon | 8310797 | 2015-02-05 12:57:44 +0100 | [diff] [blame] | 2153 | } |
| 2154 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 2155 | VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle) |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2156 | { |
Jamie Madill | 5bf9ff4 | 2016-02-01 11:13:03 -0500 | [diff] [blame] | 2157 | // Only called after a prior call to Gen. |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 2158 | VertexArray *vertexArray = getVertexArray(vertexArrayHandle); |
| 2159 | if (!vertexArray) |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2160 | { |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 2161 | vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle, |
| 2162 | mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings); |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 2163 | |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 2164 | mVertexArrayMap.assign(vertexArrayHandle, vertexArray); |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2165 | } |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 2166 | |
| 2167 | return vertexArray; |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2168 | } |
| 2169 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 2170 | TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle) |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2171 | { |
Jamie Madill | 5bf9ff4 | 2016-02-01 11:13:03 -0500 | [diff] [blame] | 2172 | // Only called after a prior call to Gen. |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 2173 | TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle); |
| 2174 | if (!transformFeedback) |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2175 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 2176 | transformFeedback = |
| 2177 | new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps); |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 2178 | transformFeedback->addRef(); |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 2179 | mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback); |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2180 | } |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 2181 | |
| 2182 | return transformFeedback; |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2183 | } |
| 2184 | |
| 2185 | bool Context::isVertexArrayGenerated(GLuint vertexArray) |
| 2186 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 2187 | ASSERT(mVertexArrayMap.contains(0)); |
| 2188 | return mVertexArrayMap.contains(vertexArray); |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2189 | } |
| 2190 | |
| 2191 | bool Context::isTransformFeedbackGenerated(GLuint transformFeedback) |
| 2192 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 2193 | ASSERT(mTransformFeedbackMap.contains(0)); |
| 2194 | return mTransformFeedbackMap.contains(transformFeedback); |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2195 | } |
| 2196 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2197 | void Context::detachTexture(GLuint texture) |
| 2198 | { |
| 2199 | // Simple pass-through to State's detachTexture method, as textures do not require |
| 2200 | // allocation map management either here or in the resource manager at detach time. |
| 2201 | // Zero textures are held by the Context, and we don't attempt to request them from |
| 2202 | // the State. |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 2203 | mGLState.detachTexture(this, mZeroTextures, texture); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2204 | } |
| 2205 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2206 | void Context::detachBuffer(GLuint buffer) |
| 2207 | { |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 2208 | // Simple pass-through to State's detachBuffer method, since |
| 2209 | // only buffer attachments to container objects that are bound to the current context |
| 2210 | // should be detached. And all those are available in State. |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2211 | |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 2212 | // [OpenGL ES 3.2] section 5.1.2 page 45: |
| 2213 | // Attachments to unbound container objects, such as |
| 2214 | // deletion of a buffer attached to a vertex array object which is not bound to the context, |
| 2215 | // are not affected and continue to act as references on the deleted object |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 2216 | mGLState.detachBuffer(this, buffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2217 | } |
| 2218 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2219 | void Context::detachFramebuffer(GLuint framebuffer) |
| 2220 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2221 | // Framebuffer detachment is handled by Context, because 0 is a valid |
| 2222 | // Framebuffer object, and a pointer to it must be passed from Context |
| 2223 | // to State at binding time. |
| 2224 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2225 | // [OpenGL ES 2.0.24] section 4.4 page 107: |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 2226 | // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as |
| 2227 | // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of |
| 2228 | // zero. |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2229 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2230 | if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2231 | { |
| 2232 | bindReadFramebuffer(0); |
| 2233 | } |
| 2234 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2235 | if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2236 | { |
| 2237 | bindDrawFramebuffer(0); |
| 2238 | } |
| 2239 | } |
| 2240 | |
| 2241 | void Context::detachRenderbuffer(GLuint renderbuffer) |
| 2242 | { |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 2243 | mGLState.detachRenderbuffer(this, renderbuffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2244 | } |
| 2245 | |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 2246 | void Context::detachVertexArray(GLuint vertexArray) |
| 2247 | { |
Jamie Madill | 77a72f6 | 2015-04-14 11:18:32 -0400 | [diff] [blame] | 2248 | // Vertex array detachment is handled by Context, because 0 is a valid |
| 2249 | // VAO, and a pointer to it must be passed from Context to State at |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2250 | // binding time. |
| 2251 | |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 2252 | // [OpenGL ES 3.0.2] section 2.10 page 43: |
| 2253 | // If a vertex array object that is currently bound is deleted, the binding |
| 2254 | // for that object reverts to zero and the default vertex array becomes current. |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2255 | if (mGLState.removeVertexArrayBinding(vertexArray)) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 2256 | { |
| 2257 | bindVertexArray(0); |
| 2258 | } |
| 2259 | } |
| 2260 | |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 2261 | void Context::detachTransformFeedback(GLuint transformFeedback) |
| 2262 | { |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 2263 | // Transform feedback detachment is handled by Context, because 0 is a valid |
| 2264 | // transform feedback, and a pointer to it must be passed from Context to State at |
| 2265 | // binding time. |
| 2266 | |
| 2267 | // The OpenGL specification doesn't mention what should happen when the currently bound |
| 2268 | // transform feedback object is deleted. Since it is a container object, we treat it like |
| 2269 | // VAOs and FBOs and set the current bound transform feedback back to 0. |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 2270 | if (mGLState.removeTransformFeedbackBinding(this, transformFeedback)) |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 2271 | { |
Jamie Madill | f0dcb8b | 2017-08-26 19:05:13 -0400 | [diff] [blame] | 2272 | bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0); |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 2273 | } |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 2274 | } |
| 2275 | |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 2276 | void Context::detachSampler(GLuint sampler) |
| 2277 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 2278 | mGLState.detachSampler(this, sampler); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 2279 | } |
| 2280 | |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 2281 | void Context::detachProgramPipeline(GLuint pipeline) |
| 2282 | { |
| 2283 | mGLState.detachProgramPipeline(this, pipeline); |
| 2284 | } |
| 2285 | |
Jamie Madill | 3ef140a | 2017-08-26 23:11:21 -0400 | [diff] [blame] | 2286 | void Context::vertexAttribDivisor(GLuint index, GLuint divisor) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2287 | { |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 2288 | mGLState.setVertexAttribDivisor(this, index, divisor); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2289 | } |
| 2290 | |
Jamie Madill | e29d167 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 2291 | void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param) |
| 2292 | { |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2293 | Sampler *samplerObject = |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 2294 | mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2295 | SetSamplerParameteri(samplerObject, pname, param); |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2296 | mGLState.setObjectDirty(GL_SAMPLER); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2297 | } |
Jamie Madill | e29d167 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 2298 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2299 | void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param) |
| 2300 | { |
| 2301 | Sampler *samplerObject = |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 2302 | mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2303 | SetSamplerParameteriv(samplerObject, pname, param); |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2304 | mGLState.setObjectDirty(GL_SAMPLER); |
Jamie Madill | e29d167 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 2305 | } |
| 2306 | |
| 2307 | void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param) |
| 2308 | { |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2309 | Sampler *samplerObject = |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 2310 | mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2311 | SetSamplerParameterf(samplerObject, pname, param); |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2312 | mGLState.setObjectDirty(GL_SAMPLER); |
Jamie Madill | e29d167 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 2313 | } |
| 2314 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2315 | void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param) |
Jamie Madill | 9675b80 | 2013-07-19 16:36:59 -0400 | [diff] [blame] | 2316 | { |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2317 | Sampler *samplerObject = |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 2318 | mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2319 | SetSamplerParameterfv(samplerObject, pname, param); |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2320 | mGLState.setObjectDirty(GL_SAMPLER); |
Jamie Madill | 9675b80 | 2013-07-19 16:36:59 -0400 | [diff] [blame] | 2321 | } |
| 2322 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2323 | void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params) |
Jamie Madill | 9675b80 | 2013-07-19 16:36:59 -0400 | [diff] [blame] | 2324 | { |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2325 | const Sampler *samplerObject = |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 2326 | mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2327 | QuerySamplerParameteriv(samplerObject, pname, params); |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2328 | mGLState.setObjectDirty(GL_SAMPLER); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2329 | } |
Jamie Madill | 9675b80 | 2013-07-19 16:36:59 -0400 | [diff] [blame] | 2330 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2331 | void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params) |
| 2332 | { |
| 2333 | const Sampler *samplerObject = |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 2334 | mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2335 | QuerySamplerParameterfv(samplerObject, pname, params); |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2336 | mGLState.setObjectDirty(GL_SAMPLER); |
Jamie Madill | 9675b80 | 2013-07-19 16:36:59 -0400 | [diff] [blame] | 2337 | } |
| 2338 | |
Olli Etuaho | f0fee07 | 2016-03-30 15:11:58 +0300 | [diff] [blame] | 2339 | void Context::programParameteri(GLuint program, GLenum pname, GLint value) |
| 2340 | { |
| 2341 | gl::Program *programObject = getProgram(program); |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 2342 | SetProgramParameteri(programObject, pname, value); |
Olli Etuaho | f0fee07 | 2016-03-30 15:11:58 +0300 | [diff] [blame] | 2343 | } |
| 2344 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2345 | void Context::initRendererString() |
| 2346 | { |
daniel@transgaming.com | ca1ac1f | 2013-01-11 04:13:05 +0000 | [diff] [blame] | 2347 | std::ostringstream rendererString; |
| 2348 | rendererString << "ANGLE ("; |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 2349 | rendererString << mImplementation->getRendererDescription(); |
daniel@transgaming.com | ca1ac1f | 2013-01-11 04:13:05 +0000 | [diff] [blame] | 2350 | rendererString << ")"; |
| 2351 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2352 | mRendererString = MakeStaticString(rendererString.str()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2353 | } |
| 2354 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2355 | void Context::initVersionStrings() |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2356 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2357 | const Version &clientVersion = getClientVersion(); |
| 2358 | |
| 2359 | std::ostringstream versionString; |
| 2360 | versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE " |
| 2361 | << ANGLE_VERSION_STRING << ")"; |
| 2362 | mVersionString = MakeStaticString(versionString.str()); |
| 2363 | |
| 2364 | std::ostringstream shadingLanguageVersionString; |
| 2365 | shadingLanguageVersionString << "OpenGL ES GLSL ES " |
| 2366 | << (clientVersion.major == 2 ? 1 : clientVersion.major) << "." |
| 2367 | << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING |
| 2368 | << ")"; |
| 2369 | mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2370 | } |
| 2371 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2372 | void Context::initExtensionStrings() |
| 2373 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2374 | auto mergeExtensionStrings = [](const std::vector<const char *> &strings) { |
| 2375 | std::ostringstream combinedStringStream; |
| 2376 | std::copy(strings.begin(), strings.end(), |
| 2377 | std::ostream_iterator<const char *>(combinedStringStream, " ")); |
| 2378 | return MakeStaticString(combinedStringStream.str()); |
| 2379 | }; |
| 2380 | |
| 2381 | mExtensionStrings.clear(); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 2382 | for (const auto &extensionString : mExtensions.getStrings()) |
| 2383 | { |
| 2384 | mExtensionStrings.push_back(MakeStaticString(extensionString)); |
| 2385 | } |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2386 | mExtensionString = mergeExtensionStrings(mExtensionStrings); |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2387 | |
Bryan Bernhart | 5880656 | 2017-01-05 13:09:31 -0800 | [diff] [blame] | 2388 | const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions(); |
| 2389 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2390 | mRequestableExtensionStrings.clear(); |
| 2391 | for (const auto &extensionInfo : GetExtensionInfoMap()) |
| 2392 | { |
| 2393 | if (extensionInfo.second.Requestable && |
Bryan Bernhart | 5880656 | 2017-01-05 13:09:31 -0800 | [diff] [blame] | 2394 | !(mExtensions.*(extensionInfo.second.ExtensionsMember)) && |
| 2395 | nativeExtensions.*(extensionInfo.second.ExtensionsMember)) |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2396 | { |
| 2397 | mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first)); |
| 2398 | } |
| 2399 | } |
| 2400 | mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings); |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2401 | } |
| 2402 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2403 | const GLubyte *Context::getString(GLenum name) const |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2404 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2405 | switch (name) |
| 2406 | { |
| 2407 | case GL_VENDOR: |
| 2408 | return reinterpret_cast<const GLubyte *>("Google Inc."); |
| 2409 | |
| 2410 | case GL_RENDERER: |
| 2411 | return reinterpret_cast<const GLubyte *>(mRendererString); |
| 2412 | |
| 2413 | case GL_VERSION: |
| 2414 | return reinterpret_cast<const GLubyte *>(mVersionString); |
| 2415 | |
| 2416 | case GL_SHADING_LANGUAGE_VERSION: |
| 2417 | return reinterpret_cast<const GLubyte *>(mShadingLanguageString); |
| 2418 | |
| 2419 | case GL_EXTENSIONS: |
| 2420 | return reinterpret_cast<const GLubyte *>(mExtensionString); |
| 2421 | |
| 2422 | case GL_REQUESTABLE_EXTENSIONS_ANGLE: |
| 2423 | return reinterpret_cast<const GLubyte *>(mRequestableExtensionString); |
| 2424 | |
| 2425 | default: |
| 2426 | UNREACHABLE(); |
| 2427 | return nullptr; |
| 2428 | } |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2429 | } |
| 2430 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2431 | const GLubyte *Context::getStringi(GLenum name, GLuint index) const |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2432 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2433 | switch (name) |
| 2434 | { |
| 2435 | case GL_EXTENSIONS: |
| 2436 | return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]); |
| 2437 | |
| 2438 | case GL_REQUESTABLE_EXTENSIONS_ANGLE: |
| 2439 | return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]); |
| 2440 | |
| 2441 | default: |
| 2442 | UNREACHABLE(); |
| 2443 | return nullptr; |
| 2444 | } |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2445 | } |
| 2446 | |
| 2447 | size_t Context::getExtensionStringCount() const |
| 2448 | { |
| 2449 | return mExtensionStrings.size(); |
| 2450 | } |
| 2451 | |
Geoff Lang | 111a99e | 2017-10-17 10:58:41 -0400 | [diff] [blame] | 2452 | bool Context::isExtensionRequestable(const char *name) |
| 2453 | { |
| 2454 | const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap(); |
| 2455 | auto extension = extensionInfos.find(name); |
| 2456 | |
| 2457 | const Extensions &nativeExtensions = mImplementation->getNativeExtensions(); |
| 2458 | return extension != extensionInfos.end() && extension->second.Requestable && |
| 2459 | nativeExtensions.*(extension->second.ExtensionsMember); |
| 2460 | } |
| 2461 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2462 | void Context::requestExtension(const char *name) |
| 2463 | { |
| 2464 | const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap(); |
| 2465 | ASSERT(extensionInfos.find(name) != extensionInfos.end()); |
| 2466 | const auto &extension = extensionInfos.at(name); |
| 2467 | ASSERT(extension.Requestable); |
Geoff Lang | 111a99e | 2017-10-17 10:58:41 -0400 | [diff] [blame] | 2468 | ASSERT(mImplementation->getNativeExtensions().*(extension.ExtensionsMember)); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2469 | |
| 2470 | if (mExtensions.*(extension.ExtensionsMember)) |
| 2471 | { |
| 2472 | // Extension already enabled |
| 2473 | return; |
| 2474 | } |
| 2475 | |
| 2476 | mExtensions.*(extension.ExtensionsMember) = true; |
| 2477 | updateCaps(); |
| 2478 | initExtensionStrings(); |
Bryan Bernhart | 5880656 | 2017-01-05 13:09:31 -0800 | [diff] [blame] | 2479 | |
Jamie Madill | 2f348d2 | 2017-06-05 10:50:59 -0400 | [diff] [blame] | 2480 | // Release the shader compiler so it will be re-created with the requested extensions enabled. |
| 2481 | releaseShaderCompiler(); |
Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 2482 | |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2483 | // Invalidate all textures and framebuffer. Some extensions make new formats renderable or |
| 2484 | // sampleable. |
| 2485 | mState.mTextures->signalAllTexturesDirty(); |
Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 2486 | for (auto &zeroTexture : mZeroTextures) |
| 2487 | { |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2488 | zeroTexture.second->signalDirty(InitState::Initialized); |
Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | mState.mFramebuffers->invalidateFramebufferComplenessCache(); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2492 | } |
| 2493 | |
| 2494 | size_t Context::getRequestableExtensionStringCount() const |
| 2495 | { |
| 2496 | return mRequestableExtensionStrings.size(); |
| 2497 | } |
| 2498 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2499 | void Context::beginTransformFeedback(GLenum primitiveMode) |
| 2500 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2501 | TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback(); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2502 | ASSERT(transformFeedback != nullptr); |
| 2503 | ASSERT(!transformFeedback->isPaused()); |
| 2504 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 2505 | transformFeedback->begin(this, primitiveMode, mGLState.getProgram()); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2506 | } |
| 2507 | |
| 2508 | bool Context::hasActiveTransformFeedback(GLuint program) const |
| 2509 | { |
| 2510 | for (auto pair : mTransformFeedbackMap) |
| 2511 | { |
| 2512 | if (pair.second != nullptr && pair.second->hasBoundProgram(program)) |
| 2513 | { |
| 2514 | return true; |
| 2515 | } |
| 2516 | } |
| 2517 | return false; |
| 2518 | } |
| 2519 | |
Geoff Lang | b433e87 | 2017-10-05 14:01:47 -0400 | [diff] [blame] | 2520 | void Context::initCaps(const egl::DisplayExtensions &displayExtensions, bool robustResourceInit) |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2521 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 2522 | mCaps = mImplementation->getNativeCaps(); |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2523 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 2524 | mExtensions = mImplementation->getNativeExtensions(); |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2525 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 2526 | mLimitations = mImplementation->getNativeLimitations(); |
Austin Kinross | 02df796 | 2015-07-01 10:03:42 -0700 | [diff] [blame] | 2527 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2528 | if (getClientVersion() < Version(3, 0)) |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2529 | { |
| 2530 | // Disable ES3+ extensions |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 2531 | mExtensions.colorBufferFloat = false; |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 2532 | mExtensions.eglImageExternalEssl3 = false; |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 2533 | mExtensions.textureNorm16 = false; |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 2534 | mExtensions.multiview = false; |
| 2535 | mExtensions.maxViews = 1u; |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2536 | } |
| 2537 | |
Jiawei Shao | 89be29a | 2017-11-06 14:36:45 +0800 | [diff] [blame] | 2538 | if (getClientVersion() < ES_3_1) |
| 2539 | { |
| 2540 | // Disable ES3.1+ extensions |
| 2541 | mExtensions.geometryShader = false; |
| 2542 | } |
| 2543 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2544 | if (getClientVersion() > Version(2, 0)) |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2545 | { |
| 2546 | // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 2547 | // mExtensions.sRGB = false; |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2548 | } |
| 2549 | |
Jamie Madill | 00ed7a1 | 2016-05-19 13:13:38 -0400 | [diff] [blame] | 2550 | // Some extensions are always available because they are implemented in the GL layer. |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 2551 | mExtensions.bindUniformLocation = true; |
| 2552 | mExtensions.vertexArrayObject = true; |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 2553 | mExtensions.bindGeneratesResource = true; |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 2554 | mExtensions.clientArrays = true; |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2555 | mExtensions.requestExtension = true; |
Jamie Madill | 00ed7a1 | 2016-05-19 13:13:38 -0400 | [diff] [blame] | 2556 | |
| 2557 | // Enable the no error extension if the context was created with the flag. |
| 2558 | mExtensions.noError = mSkipValidation; |
| 2559 | |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 2560 | // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO |
Corentin Wallez | c295e51 | 2017-01-27 17:47:50 -0500 | [diff] [blame] | 2561 | mExtensions.surfacelessContext = displayExtensions.surfacelessContext; |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 2562 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2563 | // Explicitly enable GL_KHR_debug |
| 2564 | mExtensions.debug = true; |
| 2565 | mExtensions.maxDebugMessageLength = 1024; |
| 2566 | mExtensions.maxDebugLoggedMessages = 1024; |
| 2567 | mExtensions.maxDebugGroupStackDepth = 1024; |
| 2568 | mExtensions.maxLabelLength = 1024; |
| 2569 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2570 | // Explicitly enable GL_ANGLE_robust_client_memory |
| 2571 | mExtensions.robustClientMemory = true; |
| 2572 | |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 2573 | // Determine robust resource init availability from EGL. |
Geoff Lang | b433e87 | 2017-10-05 14:01:47 -0400 | [diff] [blame] | 2574 | mExtensions.robustResourceInitialization = robustResourceInit; |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 2575 | |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 2576 | // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend |
| 2577 | // supports it. |
| 2578 | mExtensions.robustBufferAccessBehavior = |
| 2579 | mRobustAccess && mExtensions.robustBufferAccessBehavior; |
| 2580 | |
Jamie Madill | c43be72 | 2017-07-13 16:22:14 -0400 | [diff] [blame] | 2581 | // Enable the cache control query unconditionally. |
| 2582 | mExtensions.programCacheControl = true; |
| 2583 | |
Geoff Lang | 301d161 | 2014-07-09 10:34:37 -0400 | [diff] [blame] | 2584 | // Apply implementation limits |
Jamie Madill | 0f80ed8 | 2017-09-19 00:24:56 -0400 | [diff] [blame] | 2585 | LimitCap(&mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 2586 | |
Jamie Madill | 0f80ed8 | 2017-09-19 00:24:56 -0400 | [diff] [blame] | 2587 | if (getClientVersion() < ES_3_1) |
| 2588 | { |
| 2589 | mCaps.maxVertexAttribBindings = mCaps.maxVertexAttributes; |
| 2590 | } |
| 2591 | else |
| 2592 | { |
| 2593 | LimitCap(&mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS); |
| 2594 | } |
Geoff Lang | 301d161 | 2014-07-09 10:34:37 -0400 | [diff] [blame] | 2595 | |
Jamie Madill | 0f80ed8 | 2017-09-19 00:24:56 -0400 | [diff] [blame] | 2596 | LimitCap(&mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS); |
| 2597 | LimitCap(&mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4); |
| 2598 | LimitCap(&mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4); |
| 2599 | |
| 2600 | // Limit textures as well, so we can use fast bitsets with texture bindings. |
| 2601 | LimitCap(&mCaps.maxCombinedTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES); |
| 2602 | LimitCap(&mCaps.maxVertexTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2); |
| 2603 | LimitCap(&mCaps.maxTextureImageUnits, IMPLEMENTATION_MAX_ACTIVE_TEXTURES / 2); |
Geoff Lang | 3a61c32 | 2014-07-10 13:01:54 -0400 | [diff] [blame] | 2604 | |
Jiawei Shao | db34227 | 2017-09-27 10:21:45 +0800 | [diff] [blame] | 2605 | mCaps.maxSampleMaskWords = std::min<GLuint>(mCaps.maxSampleMaskWords, MAX_SAMPLE_MASK_WORDS); |
| 2606 | |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 2607 | // WebGL compatibility |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 2608 | mExtensions.webglCompatibility = mWebGLContext; |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 2609 | for (const auto &extensionInfo : GetExtensionInfoMap()) |
| 2610 | { |
| 2611 | // If this context is for WebGL, disable all enableable extensions |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 2612 | if (mWebGLContext && extensionInfo.second.Requestable) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 2613 | { |
| 2614 | mExtensions.*(extensionInfo.second.ExtensionsMember) = false; |
| 2615 | } |
| 2616 | } |
| 2617 | |
| 2618 | // Generate texture caps |
| 2619 | updateCaps(); |
| 2620 | } |
| 2621 | |
| 2622 | void Context::updateCaps() |
| 2623 | { |
Geoff Lang | 900013c | 2014-07-07 11:32:19 -0400 | [diff] [blame] | 2624 | mCaps.compressedTextureFormats.clear(); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 2625 | mTextureCaps.clear(); |
Geoff Lang | 900013c | 2014-07-07 11:32:19 -0400 | [diff] [blame] | 2626 | |
Jamie Madill | 7b62cf9 | 2017-11-02 15:20:49 -0400 | [diff] [blame] | 2627 | for (GLenum sizedInternalFormat : GetAllSizedInternalFormats()) |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2628 | { |
Jamie Madill | 7b62cf9 | 2017-11-02 15:20:49 -0400 | [diff] [blame] | 2629 | TextureCaps formatCaps = mImplementation->getNativeTextureCaps().get(sizedInternalFormat); |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2630 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat); |
Geoff Lang | d87878e | 2014-09-19 15:42:59 -0400 | [diff] [blame] | 2631 | |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 2632 | // Update the format caps based on the client version and extensions. |
| 2633 | // Caps are AND'd with the renderer caps because some core formats are still unsupported in |
| 2634 | // ES3. |
| 2635 | formatCaps.texturable = |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2636 | formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions); |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 2637 | formatCaps.renderable = |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2638 | formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions); |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 2639 | formatCaps.filterable = |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2640 | formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions); |
Geoff Lang | d87878e | 2014-09-19 15:42:59 -0400 | [diff] [blame] | 2641 | |
He Yunchao | ccd8c9b | 2017-01-18 17:36:14 +0800 | [diff] [blame] | 2642 | // OpenGL ES does not support multisampling with non-rendererable formats |
| 2643 | // OpenGL ES 3.0 or prior does not support multisampling with integer formats |
Olli Etuaho | 50c562d | 2017-06-06 14:43:30 +0300 | [diff] [blame] | 2644 | if (!formatCaps.renderable || |
He Yunchao | ccd8c9b | 2017-01-18 17:36:14 +0800 | [diff] [blame] | 2645 | (getClientVersion() < ES_3_1 && |
| 2646 | (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT))) |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2647 | { |
Geoff Lang | d87878e | 2014-09-19 15:42:59 -0400 | [diff] [blame] | 2648 | formatCaps.sampleCounts.clear(); |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2649 | } |
Olli Etuaho | 50c562d | 2017-06-06 14:43:30 +0300 | [diff] [blame] | 2650 | else |
| 2651 | { |
| 2652 | // We may have limited the max samples for some required renderbuffer formats due to |
| 2653 | // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly. |
| 2654 | GLuint formatMaxSamples = formatCaps.getMaxSamples(); |
| 2655 | |
| 2656 | // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers |
| 2657 | // in these required formats with up to the value of MAX_SAMPLES multisamples, with the |
| 2658 | // exception of signed and unsigned integer formats." |
| 2659 | if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT && |
| 2660 | formatInfo.isRequiredRenderbufferFormat(getClientVersion())) |
| 2661 | { |
| 2662 | ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4); |
| 2663 | mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples); |
| 2664 | } |
| 2665 | |
| 2666 | // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES. |
| 2667 | if (getClientVersion() >= ES_3_1) |
| 2668 | { |
| 2669 | // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers |
| 2670 | // in these required formats with up to the value of MAX_SAMPLES multisamples, with |
| 2671 | // the exception that the signed and unsigned integer formats are required only to |
| 2672 | // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES |
| 2673 | // multisamples, which must be at least one." |
| 2674 | if (formatInfo.componentType == GL_INT || |
| 2675 | formatInfo.componentType == GL_UNSIGNED_INT) |
| 2676 | { |
| 2677 | mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples); |
| 2678 | } |
| 2679 | |
| 2680 | // GLES 3.1 section 19.3.1. |
| 2681 | if (formatCaps.texturable) |
| 2682 | { |
| 2683 | if (formatInfo.depthBits > 0) |
| 2684 | { |
| 2685 | mCaps.maxDepthTextureSamples = |
| 2686 | std::min(mCaps.maxDepthTextureSamples, formatMaxSamples); |
| 2687 | } |
| 2688 | else if (formatInfo.redBits > 0) |
| 2689 | { |
| 2690 | mCaps.maxColorTextureSamples = |
| 2691 | std::min(mCaps.maxColorTextureSamples, formatMaxSamples); |
| 2692 | } |
| 2693 | } |
| 2694 | } |
| 2695 | } |
Geoff Lang | d87878e | 2014-09-19 15:42:59 -0400 | [diff] [blame] | 2696 | |
| 2697 | if (formatCaps.texturable && formatInfo.compressed) |
| 2698 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2699 | mCaps.compressedTextureFormats.push_back(sizedInternalFormat); |
Geoff Lang | d87878e | 2014-09-19 15:42:59 -0400 | [diff] [blame] | 2700 | } |
| 2701 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2702 | mTextureCaps.insert(sizedInternalFormat, formatCaps); |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2703 | } |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 2704 | |
| 2705 | // If program binary is disabled, blank out the memory cache pointer. |
| 2706 | if (!mImplementation->getNativeExtensions().getProgramBinary) |
| 2707 | { |
| 2708 | mMemoryProgramCache = nullptr; |
| 2709 | } |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2710 | } |
| 2711 | |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 2712 | void Context::initWorkarounds() |
| 2713 | { |
Jamie Madill | 761b02c | 2017-06-23 16:27:06 -0400 | [diff] [blame] | 2714 | // Apply back-end workarounds. |
| 2715 | mImplementation->applyNativeWorkarounds(&mWorkarounds); |
| 2716 | |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 2717 | // Lose the context upon out of memory error if the application is |
| 2718 | // expecting to watch for those events. |
| 2719 | mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT); |
| 2720 | } |
| 2721 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2722 | Error Context::prepareForDraw() |
| 2723 | { |
| 2724 | syncRendererState(); |
Jamie Madill | a59fc19 | 2017-11-02 12:57:58 -0400 | [diff] [blame] | 2725 | |
| 2726 | if (isRobustResourceInitEnabled()) |
| 2727 | { |
| 2728 | ANGLE_TRY(mGLState.clearUnclearedActiveTextures(this)); |
| 2729 | ANGLE_TRY(mGLState.getDrawFramebuffer()->ensureDrawAttachmentsInitialized(this)); |
| 2730 | } |
| 2731 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2732 | return NoError(); |
| 2733 | } |
| 2734 | |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 2735 | void Context::syncRendererState() |
| 2736 | { |
Jamie Madill | 7d1f5c6 | 2017-09-02 15:32:15 -0400 | [diff] [blame] | 2737 | mGLState.syncDirtyObjects(this); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2738 | const State::DirtyBits &dirtyBits = mGLState.getDirtyBits(); |
Jamie Madill | fe54834 | 2017-06-19 11:13:24 -0400 | [diff] [blame] | 2739 | mImplementation->syncState(this, dirtyBits); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2740 | mGLState.clearDirtyBits(); |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 2741 | } |
| 2742 | |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2743 | void Context::syncRendererState(const State::DirtyBits &bitMask, |
| 2744 | const State::DirtyObjects &objectMask) |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 2745 | { |
Jamie Madill | 7d1f5c6 | 2017-09-02 15:32:15 -0400 | [diff] [blame] | 2746 | mGLState.syncDirtyObjects(this, objectMask); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2747 | const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask); |
Jamie Madill | fe54834 | 2017-06-19 11:13:24 -0400 | [diff] [blame] | 2748 | mImplementation->syncState(this, dirtyBits); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2749 | mGLState.clearDirtyBits(dirtyBits); |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 2750 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2751 | |
| 2752 | void Context::blitFramebuffer(GLint srcX0, |
| 2753 | GLint srcY0, |
| 2754 | GLint srcX1, |
| 2755 | GLint srcY1, |
| 2756 | GLint dstX0, |
| 2757 | GLint dstY0, |
| 2758 | GLint dstX1, |
| 2759 | GLint dstY1, |
| 2760 | GLbitfield mask, |
| 2761 | GLenum filter) |
| 2762 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2763 | Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2764 | ASSERT(drawFramebuffer); |
| 2765 | |
| 2766 | Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0); |
| 2767 | Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0); |
| 2768 | |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2769 | syncStateForBlit(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2770 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 2771 | handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter)); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2772 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2773 | |
| 2774 | void Context::clear(GLbitfield mask) |
| 2775 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2776 | syncStateForClear(); |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 2777 | handleError(mGLState.getDrawFramebuffer()->clear(this, mask)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2778 | } |
| 2779 | |
| 2780 | void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values) |
| 2781 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2782 | syncStateForClear(); |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 2783 | handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2784 | } |
| 2785 | |
| 2786 | void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values) |
| 2787 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2788 | syncStateForClear(); |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 2789 | handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2790 | } |
| 2791 | |
| 2792 | void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values) |
| 2793 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2794 | syncStateForClear(); |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 2795 | handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2796 | } |
| 2797 | |
| 2798 | void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil) |
| 2799 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2800 | Framebuffer *framebufferObject = mGLState.getDrawFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2801 | ASSERT(framebufferObject); |
| 2802 | |
| 2803 | // If a buffer is not present, the clear has no effect |
| 2804 | if (framebufferObject->getDepthbuffer() == nullptr && |
| 2805 | framebufferObject->getStencilbuffer() == nullptr) |
| 2806 | { |
| 2807 | return; |
| 2808 | } |
| 2809 | |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2810 | syncStateForClear(); |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 2811 | handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2812 | } |
| 2813 | |
| 2814 | void Context::readPixels(GLint x, |
| 2815 | GLint y, |
| 2816 | GLsizei width, |
| 2817 | GLsizei height, |
| 2818 | GLenum format, |
| 2819 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2820 | void *pixels) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2821 | { |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 2822 | if (width == 0 || height == 0) |
| 2823 | { |
| 2824 | return; |
| 2825 | } |
| 2826 | |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2827 | syncStateForReadPixels(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2828 | |
Jamie Madill | b666492 | 2017-07-25 12:55:04 -0400 | [diff] [blame] | 2829 | Framebuffer *readFBO = mGLState.getReadFramebuffer(); |
| 2830 | ASSERT(readFBO); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2831 | |
| 2832 | Rectangle area(x, y, width, height); |
Jamie Madill | b666492 | 2017-07-25 12:55:04 -0400 | [diff] [blame] | 2833 | handleError(readFBO->readPixels(this, area, format, type, pixels)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2834 | } |
| 2835 | |
| 2836 | void Context::copyTexImage2D(GLenum target, |
| 2837 | GLint level, |
| 2838 | GLenum internalformat, |
| 2839 | GLint x, |
| 2840 | GLint y, |
| 2841 | GLsizei width, |
| 2842 | GLsizei height, |
| 2843 | GLint border) |
| 2844 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2845 | // Only sync the read FBO |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2846 | mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2847 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2848 | Rectangle sourceArea(x, y, width, height); |
| 2849 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2850 | Framebuffer *framebuffer = mGLState.getReadFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2851 | Texture *texture = |
| 2852 | getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 2853 | handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2854 | } |
| 2855 | |
| 2856 | void Context::copyTexSubImage2D(GLenum target, |
| 2857 | GLint level, |
| 2858 | GLint xoffset, |
| 2859 | GLint yoffset, |
| 2860 | GLint x, |
| 2861 | GLint y, |
| 2862 | GLsizei width, |
| 2863 | GLsizei height) |
| 2864 | { |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 2865 | if (width == 0 || height == 0) |
| 2866 | { |
| 2867 | return; |
| 2868 | } |
| 2869 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2870 | // Only sync the read FBO |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2871 | mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2872 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2873 | Offset destOffset(xoffset, yoffset, 0); |
| 2874 | Rectangle sourceArea(x, y, width, height); |
| 2875 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2876 | Framebuffer *framebuffer = mGLState.getReadFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2877 | Texture *texture = |
| 2878 | getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 2879 | handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2880 | } |
| 2881 | |
| 2882 | void Context::copyTexSubImage3D(GLenum target, |
| 2883 | GLint level, |
| 2884 | GLint xoffset, |
| 2885 | GLint yoffset, |
| 2886 | GLint zoffset, |
| 2887 | GLint x, |
| 2888 | GLint y, |
| 2889 | GLsizei width, |
| 2890 | GLsizei height) |
| 2891 | { |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 2892 | if (width == 0 || height == 0) |
| 2893 | { |
| 2894 | return; |
| 2895 | } |
| 2896 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2897 | // Only sync the read FBO |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2898 | mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2899 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2900 | Offset destOffset(xoffset, yoffset, zoffset); |
| 2901 | Rectangle sourceArea(x, y, width, height); |
| 2902 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 2903 | Framebuffer *framebuffer = mGLState.getReadFramebuffer(); |
| 2904 | Texture *texture = getTargetTexture(target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 2905 | handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2906 | } |
| 2907 | |
| 2908 | void Context::framebufferTexture2D(GLenum target, |
| 2909 | GLenum attachment, |
| 2910 | GLenum textarget, |
| 2911 | GLuint texture, |
| 2912 | GLint level) |
| 2913 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2914 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2915 | ASSERT(framebuffer); |
| 2916 | |
| 2917 | if (texture != 0) |
| 2918 | { |
| 2919 | Texture *textureObj = getTexture(texture); |
| 2920 | |
| 2921 | ImageIndex index = ImageIndex::MakeInvalid(); |
| 2922 | |
| 2923 | if (textarget == GL_TEXTURE_2D) |
| 2924 | { |
| 2925 | index = ImageIndex::Make2D(level); |
| 2926 | } |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2927 | else if (textarget == GL_TEXTURE_RECTANGLE_ANGLE) |
| 2928 | { |
| 2929 | index = ImageIndex::MakeRectangle(level); |
| 2930 | } |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 2931 | else if (textarget == GL_TEXTURE_2D_MULTISAMPLE) |
| 2932 | { |
| 2933 | ASSERT(level == 0); |
| 2934 | index = ImageIndex::Make2DMultisample(); |
| 2935 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2936 | else |
| 2937 | { |
| 2938 | ASSERT(IsCubeMapTextureTarget(textarget)); |
| 2939 | index = ImageIndex::MakeCube(textarget, level); |
| 2940 | } |
| 2941 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 2942 | framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2943 | } |
| 2944 | else |
| 2945 | { |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 2946 | framebuffer->resetAttachment(this, attachment); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2947 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2948 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2949 | mGLState.setObjectDirty(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2950 | } |
| 2951 | |
| 2952 | void Context::framebufferRenderbuffer(GLenum target, |
| 2953 | GLenum attachment, |
| 2954 | GLenum renderbuffertarget, |
| 2955 | GLuint renderbuffer) |
| 2956 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2957 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2958 | ASSERT(framebuffer); |
| 2959 | |
| 2960 | if (renderbuffer != 0) |
| 2961 | { |
| 2962 | Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 2963 | |
| 2964 | framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(), |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2965 | renderbufferObject); |
| 2966 | } |
| 2967 | else |
| 2968 | { |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 2969 | framebuffer->resetAttachment(this, attachment); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2970 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2971 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2972 | mGLState.setObjectDirty(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2973 | } |
| 2974 | |
| 2975 | void Context::framebufferTextureLayer(GLenum target, |
| 2976 | GLenum attachment, |
| 2977 | GLuint texture, |
| 2978 | GLint level, |
| 2979 | GLint layer) |
| 2980 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2981 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2982 | ASSERT(framebuffer); |
| 2983 | |
| 2984 | if (texture != 0) |
| 2985 | { |
| 2986 | Texture *textureObject = getTexture(texture); |
| 2987 | |
| 2988 | ImageIndex index = ImageIndex::MakeInvalid(); |
| 2989 | |
| 2990 | if (textureObject->getTarget() == GL_TEXTURE_3D) |
| 2991 | { |
| 2992 | index = ImageIndex::Make3D(level, layer); |
| 2993 | } |
| 2994 | else |
| 2995 | { |
| 2996 | ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY); |
| 2997 | index = ImageIndex::Make2DArray(level, layer); |
| 2998 | } |
| 2999 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 3000 | framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3001 | } |
| 3002 | else |
| 3003 | { |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 3004 | framebuffer->resetAttachment(this, attachment); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3005 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 3006 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3007 | mGLState.setObjectDirty(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3008 | } |
| 3009 | |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 3010 | void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target, |
| 3011 | GLenum attachment, |
| 3012 | GLuint texture, |
| 3013 | GLint level, |
| 3014 | GLint baseViewIndex, |
| 3015 | GLsizei numViews) |
| 3016 | { |
Martin Radev | 82ef774 | 2017-08-08 17:44:58 +0300 | [diff] [blame] | 3017 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
| 3018 | ASSERT(framebuffer); |
| 3019 | |
| 3020 | if (texture != 0) |
| 3021 | { |
| 3022 | Texture *textureObj = getTexture(texture); |
| 3023 | |
Martin Radev | 18b75ba | 2017-08-15 15:50:40 +0300 | [diff] [blame] | 3024 | ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews); |
Martin Radev | 82ef774 | 2017-08-08 17:44:58 +0300 | [diff] [blame] | 3025 | framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj, |
| 3026 | numViews, baseViewIndex); |
| 3027 | } |
| 3028 | else |
| 3029 | { |
| 3030 | framebuffer->resetAttachment(this, attachment); |
| 3031 | } |
| 3032 | |
| 3033 | mGLState.setObjectDirty(target); |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 3034 | } |
| 3035 | |
| 3036 | void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target, |
| 3037 | GLenum attachment, |
| 3038 | GLuint texture, |
| 3039 | GLint level, |
| 3040 | GLsizei numViews, |
| 3041 | const GLint *viewportOffsets) |
| 3042 | { |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 3043 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
| 3044 | ASSERT(framebuffer); |
| 3045 | |
| 3046 | if (texture != 0) |
| 3047 | { |
| 3048 | Texture *textureObj = getTexture(texture); |
| 3049 | |
| 3050 | ImageIndex index = ImageIndex::Make2D(level); |
| 3051 | framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index, |
| 3052 | textureObj, numViews, viewportOffsets); |
| 3053 | } |
| 3054 | else |
| 3055 | { |
| 3056 | framebuffer->resetAttachment(this, attachment); |
| 3057 | } |
| 3058 | |
| 3059 | mGLState.setObjectDirty(target); |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 3060 | } |
| 3061 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3062 | void Context::drawBuffers(GLsizei n, const GLenum *bufs) |
| 3063 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3064 | Framebuffer *framebuffer = mGLState.getDrawFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3065 | ASSERT(framebuffer); |
| 3066 | framebuffer->setDrawBuffers(n, bufs); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3067 | mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3068 | } |
| 3069 | |
| 3070 | void Context::readBuffer(GLenum mode) |
| 3071 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3072 | Framebuffer *readFBO = mGLState.getReadFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3073 | readFBO->setReadBuffer(mode); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3074 | mGLState.setObjectDirty(GL_READ_FRAMEBUFFER); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3075 | } |
| 3076 | |
| 3077 | void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments) |
| 3078 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 3079 | // Only sync the FBO |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 3080 | mGLState.syncDirtyObject(this, target); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 3081 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3082 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3083 | ASSERT(framebuffer); |
| 3084 | |
| 3085 | // The specification isn't clear what should be done when the framebuffer isn't complete. |
| 3086 | // We leave it up to the framebuffer implementation to decide what to do. |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 3087 | handleError(framebuffer->discard(this, numAttachments, attachments)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3088 | } |
| 3089 | |
| 3090 | void Context::invalidateFramebuffer(GLenum target, |
| 3091 | GLsizei numAttachments, |
| 3092 | const GLenum *attachments) |
| 3093 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 3094 | // Only sync the FBO |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 3095 | mGLState.syncDirtyObject(this, target); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 3096 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3097 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3098 | ASSERT(framebuffer); |
| 3099 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 3100 | if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3101 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3102 | return; |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3103 | } |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3104 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 3105 | handleError(framebuffer->invalidate(this, numAttachments, attachments)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3106 | } |
| 3107 | |
| 3108 | void Context::invalidateSubFramebuffer(GLenum target, |
| 3109 | GLsizei numAttachments, |
| 3110 | const GLenum *attachments, |
| 3111 | GLint x, |
| 3112 | GLint y, |
| 3113 | GLsizei width, |
| 3114 | GLsizei height) |
| 3115 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 3116 | // Only sync the FBO |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 3117 | mGLState.syncDirtyObject(this, target); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 3118 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3119 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3120 | ASSERT(framebuffer); |
| 3121 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 3122 | if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3123 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3124 | return; |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3125 | } |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3126 | |
| 3127 | Rectangle area(x, y, width, height); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 3128 | handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3129 | } |
| 3130 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3131 | void Context::texImage2D(GLenum target, |
| 3132 | GLint level, |
| 3133 | GLint internalformat, |
| 3134 | GLsizei width, |
| 3135 | GLsizei height, |
| 3136 | GLint border, |
| 3137 | GLenum format, |
| 3138 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3139 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3140 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 3141 | syncStateForTexImage(); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3142 | |
| 3143 | Extents size(width, height, 1); |
| 3144 | Texture *texture = |
| 3145 | getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 3146 | handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat, |
| 3147 | size, format, type, reinterpret_cast<const uint8_t *>(pixels))); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3148 | } |
| 3149 | |
| 3150 | void Context::texImage3D(GLenum target, |
| 3151 | GLint level, |
| 3152 | GLint internalformat, |
| 3153 | GLsizei width, |
| 3154 | GLsizei height, |
| 3155 | GLsizei depth, |
| 3156 | GLint border, |
| 3157 | GLenum format, |
| 3158 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3159 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3160 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 3161 | syncStateForTexImage(); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3162 | |
| 3163 | Extents size(width, height, depth); |
| 3164 | Texture *texture = getTargetTexture(target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 3165 | handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat, |
| 3166 | size, format, type, reinterpret_cast<const uint8_t *>(pixels))); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3167 | } |
| 3168 | |
| 3169 | void Context::texSubImage2D(GLenum target, |
| 3170 | GLint level, |
| 3171 | GLint xoffset, |
| 3172 | GLint yoffset, |
| 3173 | GLsizei width, |
| 3174 | GLsizei height, |
| 3175 | GLenum format, |
| 3176 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3177 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3178 | { |
| 3179 | // Zero sized uploads are valid but no-ops |
| 3180 | if (width == 0 || height == 0) |
| 3181 | { |
| 3182 | return; |
| 3183 | } |
| 3184 | |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 3185 | syncStateForTexImage(); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3186 | |
| 3187 | Box area(xoffset, yoffset, 0, width, height, 1); |
| 3188 | Texture *texture = |
| 3189 | getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 3190 | handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format, |
| 3191 | type, reinterpret_cast<const uint8_t *>(pixels))); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3192 | } |
| 3193 | |
| 3194 | void Context::texSubImage3D(GLenum target, |
| 3195 | GLint level, |
| 3196 | GLint xoffset, |
| 3197 | GLint yoffset, |
| 3198 | GLint zoffset, |
| 3199 | GLsizei width, |
| 3200 | GLsizei height, |
| 3201 | GLsizei depth, |
| 3202 | GLenum format, |
| 3203 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3204 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3205 | { |
| 3206 | // Zero sized uploads are valid but no-ops |
| 3207 | if (width == 0 || height == 0 || depth == 0) |
| 3208 | { |
| 3209 | return; |
| 3210 | } |
| 3211 | |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 3212 | syncStateForTexImage(); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3213 | |
| 3214 | Box area(xoffset, yoffset, zoffset, width, height, depth); |
| 3215 | Texture *texture = getTargetTexture(target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 3216 | handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format, |
| 3217 | type, reinterpret_cast<const uint8_t *>(pixels))); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3218 | } |
| 3219 | |
| 3220 | void Context::compressedTexImage2D(GLenum target, |
| 3221 | GLint level, |
| 3222 | GLenum internalformat, |
| 3223 | GLsizei width, |
| 3224 | GLsizei height, |
| 3225 | GLint border, |
| 3226 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3227 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3228 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 3229 | syncStateForTexImage(); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3230 | |
| 3231 | Extents size(width, height, 1); |
| 3232 | Texture *texture = |
| 3233 | getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 3234 | handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level, |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3235 | internalformat, size, imageSize, |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3236 | reinterpret_cast<const uint8_t *>(data))); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3237 | } |
| 3238 | |
| 3239 | void Context::compressedTexImage3D(GLenum target, |
| 3240 | GLint level, |
| 3241 | GLenum internalformat, |
| 3242 | GLsizei width, |
| 3243 | GLsizei height, |
| 3244 | GLsizei depth, |
| 3245 | GLint border, |
| 3246 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3247 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3248 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 3249 | syncStateForTexImage(); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3250 | |
| 3251 | Extents size(width, height, depth); |
| 3252 | Texture *texture = getTargetTexture(target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 3253 | handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level, |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3254 | internalformat, size, imageSize, |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3255 | reinterpret_cast<const uint8_t *>(data))); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3256 | } |
| 3257 | |
| 3258 | void Context::compressedTexSubImage2D(GLenum target, |
| 3259 | GLint level, |
| 3260 | GLint xoffset, |
| 3261 | GLint yoffset, |
| 3262 | GLsizei width, |
| 3263 | GLsizei height, |
| 3264 | GLenum format, |
| 3265 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3266 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3267 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 3268 | syncStateForTexImage(); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3269 | |
| 3270 | Box area(xoffset, yoffset, 0, width, height, 1); |
| 3271 | Texture *texture = |
| 3272 | getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 3273 | handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area, |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3274 | format, imageSize, |
| 3275 | reinterpret_cast<const uint8_t *>(data))); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3276 | } |
| 3277 | |
| 3278 | void Context::compressedTexSubImage3D(GLenum target, |
| 3279 | GLint level, |
| 3280 | GLint xoffset, |
| 3281 | GLint yoffset, |
| 3282 | GLint zoffset, |
| 3283 | GLsizei width, |
| 3284 | GLsizei height, |
| 3285 | GLsizei depth, |
| 3286 | GLenum format, |
| 3287 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3288 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3289 | { |
| 3290 | // Zero sized uploads are valid but no-ops |
| 3291 | if (width == 0 || height == 0) |
| 3292 | { |
| 3293 | return; |
| 3294 | } |
| 3295 | |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 3296 | syncStateForTexImage(); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3297 | |
| 3298 | Box area(xoffset, yoffset, zoffset, width, height, depth); |
| 3299 | Texture *texture = getTargetTexture(target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 3300 | handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area, |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3301 | format, imageSize, |
| 3302 | reinterpret_cast<const uint8_t *>(data))); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3303 | } |
| 3304 | |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 3305 | void Context::generateMipmap(GLenum target) |
| 3306 | { |
| 3307 | Texture *texture = getTargetTexture(target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 3308 | handleError(texture->generateMipmap(this)); |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 3309 | } |
| 3310 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3311 | void Context::copyTextureCHROMIUM(GLuint sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 3312 | GLint sourceLevel, |
| 3313 | GLenum destTarget, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3314 | GLuint destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 3315 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3316 | GLint internalFormat, |
| 3317 | GLenum destType, |
| 3318 | GLboolean unpackFlipY, |
| 3319 | GLboolean unpackPremultiplyAlpha, |
| 3320 | GLboolean unpackUnmultiplyAlpha) |
| 3321 | { |
| 3322 | syncStateForTexImage(); |
| 3323 | |
| 3324 | gl::Texture *sourceTexture = getTexture(sourceId); |
| 3325 | gl::Texture *destTexture = getTexture(destId); |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 3326 | handleError(destTexture->copyTexture(this, destTarget, destLevel, internalFormat, destType, |
| 3327 | sourceLevel, ConvertToBool(unpackFlipY), |
| 3328 | ConvertToBool(unpackPremultiplyAlpha), |
| 3329 | ConvertToBool(unpackUnmultiplyAlpha), sourceTexture)); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3330 | } |
| 3331 | |
| 3332 | void Context::copySubTextureCHROMIUM(GLuint sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 3333 | GLint sourceLevel, |
| 3334 | GLenum destTarget, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3335 | GLuint destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 3336 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3337 | GLint xoffset, |
| 3338 | GLint yoffset, |
| 3339 | GLint x, |
| 3340 | GLint y, |
| 3341 | GLsizei width, |
| 3342 | GLsizei height, |
| 3343 | GLboolean unpackFlipY, |
| 3344 | GLboolean unpackPremultiplyAlpha, |
| 3345 | GLboolean unpackUnmultiplyAlpha) |
| 3346 | { |
| 3347 | // Zero sized copies are valid but no-ops |
| 3348 | if (width == 0 || height == 0) |
| 3349 | { |
| 3350 | return; |
| 3351 | } |
| 3352 | |
| 3353 | syncStateForTexImage(); |
| 3354 | |
| 3355 | gl::Texture *sourceTexture = getTexture(sourceId); |
| 3356 | gl::Texture *destTexture = getTexture(destId); |
| 3357 | Offset offset(xoffset, yoffset, 0); |
| 3358 | Rectangle area(x, y, width, height); |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 3359 | handleError(destTexture->copySubTexture(this, destTarget, destLevel, offset, sourceLevel, area, |
| 3360 | ConvertToBool(unpackFlipY), |
| 3361 | ConvertToBool(unpackPremultiplyAlpha), |
| 3362 | ConvertToBool(unpackUnmultiplyAlpha), sourceTexture)); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3363 | } |
| 3364 | |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 3365 | void Context::compressedCopyTextureCHROMIUM(GLuint sourceId, GLuint destId) |
| 3366 | { |
| 3367 | syncStateForTexImage(); |
| 3368 | |
| 3369 | gl::Texture *sourceTexture = getTexture(sourceId); |
| 3370 | gl::Texture *destTexture = getTexture(destId); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 3371 | handleError(destTexture->copyCompressedTexture(this, sourceTexture)); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 3372 | } |
| 3373 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3374 | void Context::getBufferPointerv(BufferBinding target, GLenum pname, void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3375 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3376 | Buffer *buffer = mGLState.getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3377 | ASSERT(buffer); |
| 3378 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3379 | QueryBufferPointerv(buffer, pname, params); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3380 | } |
| 3381 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3382 | void *Context::mapBuffer(BufferBinding target, GLenum access) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3383 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3384 | Buffer *buffer = mGLState.getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3385 | ASSERT(buffer); |
| 3386 | |
Jamie Madill | 5f56ddb | 2017-01-13 17:29:55 -0500 | [diff] [blame] | 3387 | Error error = buffer->map(this, access); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3388 | if (error.isError()) |
| 3389 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3390 | handleError(error); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3391 | return nullptr; |
| 3392 | } |
| 3393 | |
| 3394 | return buffer->getMapPointer(); |
| 3395 | } |
| 3396 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3397 | GLboolean Context::unmapBuffer(BufferBinding target) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3398 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3399 | Buffer *buffer = mGLState.getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3400 | ASSERT(buffer); |
| 3401 | |
| 3402 | GLboolean result; |
Jamie Madill | 5f56ddb | 2017-01-13 17:29:55 -0500 | [diff] [blame] | 3403 | Error error = buffer->unmap(this, &result); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3404 | if (error.isError()) |
| 3405 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3406 | handleError(error); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3407 | return GL_FALSE; |
| 3408 | } |
| 3409 | |
| 3410 | return result; |
| 3411 | } |
| 3412 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3413 | void *Context::mapBufferRange(BufferBinding target, |
| 3414 | GLintptr offset, |
| 3415 | GLsizeiptr length, |
| 3416 | GLbitfield access) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3417 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3418 | Buffer *buffer = mGLState.getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3419 | ASSERT(buffer); |
| 3420 | |
Jamie Madill | 5f56ddb | 2017-01-13 17:29:55 -0500 | [diff] [blame] | 3421 | Error error = buffer->mapRange(this, offset, length, access); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3422 | if (error.isError()) |
| 3423 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3424 | handleError(error); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3425 | return nullptr; |
| 3426 | } |
| 3427 | |
| 3428 | return buffer->getMapPointer(); |
| 3429 | } |
| 3430 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3431 | void Context::flushMappedBufferRange(BufferBinding /*target*/, |
| 3432 | GLintptr /*offset*/, |
| 3433 | GLsizeiptr /*length*/) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3434 | { |
| 3435 | // We do not currently support a non-trivial implementation of FlushMappedBufferRange |
| 3436 | } |
| 3437 | |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 3438 | void Context::syncStateForReadPixels() |
| 3439 | { |
| 3440 | syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects); |
| 3441 | } |
| 3442 | |
| 3443 | void Context::syncStateForTexImage() |
| 3444 | { |
| 3445 | syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects); |
| 3446 | } |
| 3447 | |
| 3448 | void Context::syncStateForClear() |
| 3449 | { |
| 3450 | syncRendererState(mClearDirtyBits, mClearDirtyObjects); |
| 3451 | } |
| 3452 | |
| 3453 | void Context::syncStateForBlit() |
| 3454 | { |
| 3455 | syncRendererState(mBlitDirtyBits, mBlitDirtyObjects); |
| 3456 | } |
| 3457 | |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3458 | void Context::activeTexture(GLenum texture) |
| 3459 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3460 | mGLState.setActiveSampler(texture - GL_TEXTURE0); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3461 | } |
| 3462 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3463 | void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3464 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3465 | mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha)); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3466 | } |
| 3467 | |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 3468 | void Context::blendEquation(GLenum mode) |
| 3469 | { |
| 3470 | mGLState.setBlendEquation(mode, mode); |
| 3471 | } |
| 3472 | |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3473 | void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha) |
| 3474 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3475 | mGLState.setBlendEquation(modeRGB, modeAlpha); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3476 | } |
| 3477 | |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 3478 | void Context::blendFunc(GLenum sfactor, GLenum dfactor) |
| 3479 | { |
| 3480 | mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor); |
| 3481 | } |
| 3482 | |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3483 | void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) |
| 3484 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3485 | mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3486 | } |
| 3487 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3488 | void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3489 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3490 | mGLState.setColorClearValue(red, green, blue, alpha); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3491 | } |
| 3492 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3493 | void Context::clearDepthf(GLfloat depth) |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3494 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3495 | mGLState.setDepthClearValue(depth); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3496 | } |
| 3497 | |
| 3498 | void Context::clearStencil(GLint s) |
| 3499 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3500 | mGLState.setStencilClearValue(s); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3501 | } |
| 3502 | |
| 3503 | void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) |
| 3504 | { |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 3505 | mGLState.setColorMask(ConvertToBool(red), ConvertToBool(green), ConvertToBool(blue), |
| 3506 | ConvertToBool(alpha)); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3507 | } |
| 3508 | |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 3509 | void Context::cullFace(CullFaceMode mode) |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3510 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3511 | mGLState.setCullMode(mode); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3512 | } |
| 3513 | |
| 3514 | void Context::depthFunc(GLenum func) |
| 3515 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3516 | mGLState.setDepthFunc(func); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3517 | } |
| 3518 | |
| 3519 | void Context::depthMask(GLboolean flag) |
| 3520 | { |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 3521 | mGLState.setDepthMask(ConvertToBool(flag)); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3522 | } |
| 3523 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3524 | void Context::depthRangef(GLfloat zNear, GLfloat zFar) |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3525 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3526 | mGLState.setDepthRange(zNear, zFar); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3527 | } |
| 3528 | |
| 3529 | void Context::disable(GLenum cap) |
| 3530 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3531 | mGLState.setEnableFeature(cap, false); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3532 | } |
| 3533 | |
| 3534 | void Context::disableVertexAttribArray(GLuint index) |
| 3535 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3536 | mGLState.setEnableVertexAttribArray(index, false); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3537 | } |
| 3538 | |
| 3539 | void Context::enable(GLenum cap) |
| 3540 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3541 | mGLState.setEnableFeature(cap, true); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3542 | } |
| 3543 | |
| 3544 | void Context::enableVertexAttribArray(GLuint index) |
| 3545 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3546 | mGLState.setEnableVertexAttribArray(index, true); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3547 | } |
| 3548 | |
| 3549 | void Context::frontFace(GLenum mode) |
| 3550 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3551 | mGLState.setFrontFace(mode); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3552 | } |
| 3553 | |
| 3554 | void Context::hint(GLenum target, GLenum mode) |
| 3555 | { |
| 3556 | switch (target) |
| 3557 | { |
| 3558 | case GL_GENERATE_MIPMAP_HINT: |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3559 | mGLState.setGenerateMipmapHint(mode); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3560 | break; |
| 3561 | |
| 3562 | case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3563 | mGLState.setFragmentShaderDerivativeHint(mode); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3564 | break; |
| 3565 | |
| 3566 | default: |
| 3567 | UNREACHABLE(); |
| 3568 | return; |
| 3569 | } |
| 3570 | } |
| 3571 | |
| 3572 | void Context::lineWidth(GLfloat width) |
| 3573 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3574 | mGLState.setLineWidth(width); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3575 | } |
| 3576 | |
| 3577 | void Context::pixelStorei(GLenum pname, GLint param) |
| 3578 | { |
| 3579 | switch (pname) |
| 3580 | { |
| 3581 | case GL_UNPACK_ALIGNMENT: |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3582 | mGLState.setUnpackAlignment(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3583 | break; |
| 3584 | |
| 3585 | case GL_PACK_ALIGNMENT: |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3586 | mGLState.setPackAlignment(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3587 | break; |
| 3588 | |
| 3589 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3590 | mGLState.setPackReverseRowOrder(param != 0); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3591 | break; |
| 3592 | |
| 3593 | case GL_UNPACK_ROW_LENGTH: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3594 | ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3595 | mGLState.setUnpackRowLength(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3596 | break; |
| 3597 | |
| 3598 | case GL_UNPACK_IMAGE_HEIGHT: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3599 | ASSERT(getClientMajorVersion() >= 3); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3600 | mGLState.setUnpackImageHeight(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3601 | break; |
| 3602 | |
| 3603 | case GL_UNPACK_SKIP_IMAGES: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3604 | ASSERT(getClientMajorVersion() >= 3); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3605 | mGLState.setUnpackSkipImages(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3606 | break; |
| 3607 | |
| 3608 | case GL_UNPACK_SKIP_ROWS: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3609 | ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3610 | mGLState.setUnpackSkipRows(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3611 | break; |
| 3612 | |
| 3613 | case GL_UNPACK_SKIP_PIXELS: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3614 | ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3615 | mGLState.setUnpackSkipPixels(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3616 | break; |
| 3617 | |
| 3618 | case GL_PACK_ROW_LENGTH: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3619 | ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3620 | mGLState.setPackRowLength(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3621 | break; |
| 3622 | |
| 3623 | case GL_PACK_SKIP_ROWS: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3624 | ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3625 | mGLState.setPackSkipRows(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3626 | break; |
| 3627 | |
| 3628 | case GL_PACK_SKIP_PIXELS: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3629 | ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3630 | mGLState.setPackSkipPixels(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3631 | break; |
| 3632 | |
| 3633 | default: |
| 3634 | UNREACHABLE(); |
| 3635 | return; |
| 3636 | } |
| 3637 | } |
| 3638 | |
| 3639 | void Context::polygonOffset(GLfloat factor, GLfloat units) |
| 3640 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3641 | mGLState.setPolygonOffsetParams(factor, units); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3642 | } |
| 3643 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3644 | void Context::sampleCoverage(GLfloat value, GLboolean invert) |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3645 | { |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 3646 | mGLState.setSampleCoverageParams(clamp01(value), ConvertToBool(invert)); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3647 | } |
| 3648 | |
Jiawei Shao | db34227 | 2017-09-27 10:21:45 +0800 | [diff] [blame] | 3649 | void Context::sampleMaski(GLuint maskNumber, GLbitfield mask) |
| 3650 | { |
| 3651 | mGLState.setSampleMaskParams(maskNumber, mask); |
| 3652 | } |
| 3653 | |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3654 | void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height) |
| 3655 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3656 | mGLState.setScissorParams(x, y, width, height); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3657 | } |
| 3658 | |
| 3659 | void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask) |
| 3660 | { |
| 3661 | if (face == GL_FRONT || face == GL_FRONT_AND_BACK) |
| 3662 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3663 | mGLState.setStencilParams(func, ref, mask); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3664 | } |
| 3665 | |
| 3666 | if (face == GL_BACK || face == GL_FRONT_AND_BACK) |
| 3667 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3668 | mGLState.setStencilBackParams(func, ref, mask); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3669 | } |
| 3670 | } |
| 3671 | |
| 3672 | void Context::stencilMaskSeparate(GLenum face, GLuint mask) |
| 3673 | { |
| 3674 | if (face == GL_FRONT || face == GL_FRONT_AND_BACK) |
| 3675 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3676 | mGLState.setStencilWritemask(mask); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3677 | } |
| 3678 | |
| 3679 | if (face == GL_BACK || face == GL_FRONT_AND_BACK) |
| 3680 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3681 | mGLState.setStencilBackWritemask(mask); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3682 | } |
| 3683 | } |
| 3684 | |
| 3685 | void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass) |
| 3686 | { |
| 3687 | if (face == GL_FRONT || face == GL_FRONT_AND_BACK) |
| 3688 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3689 | mGLState.setStencilOperations(fail, zfail, zpass); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3690 | } |
| 3691 | |
| 3692 | if (face == GL_BACK || face == GL_FRONT_AND_BACK) |
| 3693 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3694 | mGLState.setStencilBackOperations(fail, zfail, zpass); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3695 | } |
| 3696 | } |
| 3697 | |
| 3698 | void Context::vertexAttrib1f(GLuint index, GLfloat x) |
| 3699 | { |
| 3700 | GLfloat vals[4] = {x, 0, 0, 1}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3701 | mGLState.setVertexAttribf(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3702 | } |
| 3703 | |
| 3704 | void Context::vertexAttrib1fv(GLuint index, const GLfloat *values) |
| 3705 | { |
| 3706 | GLfloat vals[4] = {values[0], 0, 0, 1}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3707 | mGLState.setVertexAttribf(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3708 | } |
| 3709 | |
| 3710 | void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y) |
| 3711 | { |
| 3712 | GLfloat vals[4] = {x, y, 0, 1}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3713 | mGLState.setVertexAttribf(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3714 | } |
| 3715 | |
| 3716 | void Context::vertexAttrib2fv(GLuint index, const GLfloat *values) |
| 3717 | { |
| 3718 | GLfloat vals[4] = {values[0], values[1], 0, 1}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3719 | mGLState.setVertexAttribf(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3720 | } |
| 3721 | |
| 3722 | void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z) |
| 3723 | { |
| 3724 | GLfloat vals[4] = {x, y, z, 1}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3725 | mGLState.setVertexAttribf(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3726 | } |
| 3727 | |
| 3728 | void Context::vertexAttrib3fv(GLuint index, const GLfloat *values) |
| 3729 | { |
| 3730 | GLfloat vals[4] = {values[0], values[1], values[2], 1}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3731 | mGLState.setVertexAttribf(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3732 | } |
| 3733 | |
| 3734 | void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) |
| 3735 | { |
| 3736 | GLfloat vals[4] = {x, y, z, w}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3737 | mGLState.setVertexAttribf(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3738 | } |
| 3739 | |
| 3740 | void Context::vertexAttrib4fv(GLuint index, const GLfloat *values) |
| 3741 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3742 | mGLState.setVertexAttribf(index, values); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3743 | } |
| 3744 | |
| 3745 | void Context::vertexAttribPointer(GLuint index, |
| 3746 | GLint size, |
| 3747 | GLenum type, |
| 3748 | GLboolean normalized, |
| 3749 | GLsizei stride, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3750 | const void *ptr) |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3751 | { |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3752 | mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array), |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 3753 | size, type, ConvertToBool(normalized), false, stride, ptr); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3754 | } |
| 3755 | |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 3756 | void Context::vertexAttribFormat(GLuint attribIndex, |
| 3757 | GLint size, |
| 3758 | GLenum type, |
| 3759 | GLboolean normalized, |
| 3760 | GLuint relativeOffset) |
| 3761 | { |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 3762 | mGLState.setVertexAttribFormat(attribIndex, size, type, ConvertToBool(normalized), false, |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 3763 | relativeOffset); |
| 3764 | } |
| 3765 | |
| 3766 | void Context::vertexAttribIFormat(GLuint attribIndex, |
| 3767 | GLint size, |
| 3768 | GLenum type, |
| 3769 | GLuint relativeOffset) |
| 3770 | { |
| 3771 | mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset); |
| 3772 | } |
| 3773 | |
| 3774 | void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex) |
| 3775 | { |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 3776 | mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 3777 | } |
| 3778 | |
| 3779 | void Context::setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor) |
| 3780 | { |
| 3781 | mGLState.setVertexBindingDivisor(bindingIndex, divisor); |
| 3782 | } |
| 3783 | |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3784 | void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height) |
| 3785 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3786 | mGLState.setViewportParams(x, y, width, height); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3787 | } |
| 3788 | |
| 3789 | void Context::vertexAttribIPointer(GLuint index, |
| 3790 | GLint size, |
| 3791 | GLenum type, |
| 3792 | GLsizei stride, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3793 | const void *pointer) |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3794 | { |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3795 | mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(BufferBinding::Array), |
| 3796 | size, type, false, true, stride, pointer); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3797 | } |
| 3798 | |
| 3799 | void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w) |
| 3800 | { |
| 3801 | GLint vals[4] = {x, y, z, w}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3802 | mGLState.setVertexAttribi(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3803 | } |
| 3804 | |
| 3805 | void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w) |
| 3806 | { |
| 3807 | GLuint vals[4] = {x, y, z, w}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3808 | mGLState.setVertexAttribu(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3809 | } |
| 3810 | |
| 3811 | void Context::vertexAttribI4iv(GLuint index, const GLint *v) |
| 3812 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3813 | mGLState.setVertexAttribi(index, v); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3814 | } |
| 3815 | |
| 3816 | void Context::vertexAttribI4uiv(GLuint index, const GLuint *v) |
| 3817 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3818 | mGLState.setVertexAttribu(index, v); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3819 | } |
| 3820 | |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 3821 | void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params) |
| 3822 | { |
| 3823 | const VertexAttribCurrentValueData ¤tValues = |
| 3824 | getGLState().getVertexAttribCurrentValue(index); |
| 3825 | const VertexArray *vao = getGLState().getVertexArray(); |
| 3826 | QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index), |
| 3827 | currentValues, pname, params); |
| 3828 | } |
| 3829 | |
| 3830 | void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params) |
| 3831 | { |
| 3832 | const VertexAttribCurrentValueData ¤tValues = |
| 3833 | getGLState().getVertexAttribCurrentValue(index); |
| 3834 | const VertexArray *vao = getGLState().getVertexArray(); |
| 3835 | QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index), |
| 3836 | currentValues, pname, params); |
| 3837 | } |
| 3838 | |
| 3839 | void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params) |
| 3840 | { |
| 3841 | const VertexAttribCurrentValueData ¤tValues = |
| 3842 | getGLState().getVertexAttribCurrentValue(index); |
| 3843 | const VertexArray *vao = getGLState().getVertexArray(); |
| 3844 | QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index), |
| 3845 | currentValues, pname, params); |
| 3846 | } |
| 3847 | |
| 3848 | void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params) |
| 3849 | { |
| 3850 | const VertexAttribCurrentValueData ¤tValues = |
| 3851 | getGLState().getVertexAttribCurrentValue(index); |
| 3852 | const VertexArray *vao = getGLState().getVertexArray(); |
| 3853 | QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index), |
| 3854 | currentValues, pname, params); |
| 3855 | } |
| 3856 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3857 | void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer) |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 3858 | { |
| 3859 | const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index); |
| 3860 | QueryVertexAttribPointerv(attrib, pname, pointer); |
| 3861 | } |
| 3862 | |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3863 | void Context::debugMessageControl(GLenum source, |
| 3864 | GLenum type, |
| 3865 | GLenum severity, |
| 3866 | GLsizei count, |
| 3867 | const GLuint *ids, |
| 3868 | GLboolean enabled) |
| 3869 | { |
| 3870 | std::vector<GLuint> idVector(ids, ids + count); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3871 | mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector), |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 3872 | ConvertToBool(enabled)); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3873 | } |
| 3874 | |
| 3875 | void Context::debugMessageInsert(GLenum source, |
| 3876 | GLenum type, |
| 3877 | GLuint id, |
| 3878 | GLenum severity, |
| 3879 | GLsizei length, |
| 3880 | const GLchar *buf) |
| 3881 | { |
| 3882 | std::string msg(buf, (length > 0) ? static_cast<size_t>(length) : strlen(buf)); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3883 | mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg)); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3884 | } |
| 3885 | |
| 3886 | void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam) |
| 3887 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3888 | mGLState.getDebug().setCallback(callback, userParam); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3889 | } |
| 3890 | |
| 3891 | GLuint Context::getDebugMessageLog(GLuint count, |
| 3892 | GLsizei bufSize, |
| 3893 | GLenum *sources, |
| 3894 | GLenum *types, |
| 3895 | GLuint *ids, |
| 3896 | GLenum *severities, |
| 3897 | GLsizei *lengths, |
| 3898 | GLchar *messageLog) |
| 3899 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3900 | return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids, |
| 3901 | severities, lengths, messageLog)); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3902 | } |
| 3903 | |
| 3904 | void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message) |
| 3905 | { |
| 3906 | std::string msg(message, (length > 0) ? static_cast<size_t>(length) : strlen(message)); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3907 | mGLState.getDebug().pushGroup(source, id, std::move(msg)); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3908 | } |
| 3909 | |
| 3910 | void Context::popDebugGroup() |
| 3911 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3912 | mGLState.getDebug().popGroup(); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3913 | } |
| 3914 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3915 | void Context::bufferData(BufferBinding target, GLsizeiptr size, const void *data, BufferUsage usage) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 3916 | { |
| 3917 | Buffer *buffer = mGLState.getTargetBuffer(target); |
| 3918 | ASSERT(buffer); |
Jamie Madill | b8353b0 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 3919 | handleError(buffer->bufferData(this, target, data, size, usage)); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 3920 | } |
| 3921 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3922 | void Context::bufferSubData(BufferBinding target, |
| 3923 | GLintptr offset, |
| 3924 | GLsizeiptr size, |
| 3925 | const void *data) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 3926 | { |
| 3927 | if (data == nullptr) |
| 3928 | { |
| 3929 | return; |
| 3930 | } |
| 3931 | |
| 3932 | Buffer *buffer = mGLState.getTargetBuffer(target); |
| 3933 | ASSERT(buffer); |
Jamie Madill | b8353b0 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 3934 | handleError(buffer->bufferSubData(this, target, data, size, offset)); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 3935 | } |
| 3936 | |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 3937 | void Context::attachShader(GLuint program, GLuint shader) |
| 3938 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 3939 | auto programObject = mState.mShaderPrograms->getProgram(program); |
| 3940 | auto shaderObject = mState.mShaderPrograms->getShader(shader); |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 3941 | ASSERT(programObject && shaderObject); |
| 3942 | programObject->attachShader(shaderObject); |
| 3943 | } |
| 3944 | |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 3945 | const Workarounds &Context::getWorkarounds() const |
| 3946 | { |
| 3947 | return mWorkarounds; |
| 3948 | } |
| 3949 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3950 | void Context::copyBufferSubData(BufferBinding readTarget, |
| 3951 | BufferBinding writeTarget, |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 3952 | GLintptr readOffset, |
| 3953 | GLintptr writeOffset, |
| 3954 | GLsizeiptr size) |
| 3955 | { |
| 3956 | // if size is zero, the copy is a successful no-op |
| 3957 | if (size == 0) |
| 3958 | { |
| 3959 | return; |
| 3960 | } |
| 3961 | |
| 3962 | // TODO(jmadill): cache these. |
| 3963 | Buffer *readBuffer = mGLState.getTargetBuffer(readTarget); |
| 3964 | Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget); |
| 3965 | |
Jamie Madill | 5f56ddb | 2017-01-13 17:29:55 -0500 | [diff] [blame] | 3966 | handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size)); |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 3967 | } |
| 3968 | |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 3969 | void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name) |
| 3970 | { |
| 3971 | Program *programObject = getProgram(program); |
| 3972 | // TODO(jmadill): Re-use this from the validation if possible. |
| 3973 | ASSERT(programObject); |
| 3974 | programObject->bindAttributeLocation(index, name); |
| 3975 | } |
| 3976 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3977 | void Context::bindBuffer(BufferBinding target, GLuint buffer) |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 3978 | { |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3979 | Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer); |
| 3980 | mGLState.setBufferBinding(this, target, bufferObject); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 3981 | } |
| 3982 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3983 | void Context::bindBufferBase(BufferBinding target, GLuint index, GLuint buffer) |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 3984 | { |
| 3985 | bindBufferRange(target, index, buffer, 0, 0); |
| 3986 | } |
| 3987 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3988 | void Context::bindBufferRange(BufferBinding target, |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 3989 | GLuint index, |
| 3990 | GLuint buffer, |
| 3991 | GLintptr offset, |
| 3992 | GLsizeiptr size) |
| 3993 | { |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 3994 | Buffer *bufferObject = mState.mBuffers->checkBufferAllocation(mImplementation.get(), buffer); |
| 3995 | mGLState.setIndexedBufferBinding(this, target, index, bufferObject, offset, size); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 3996 | } |
| 3997 | |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 3998 | void Context::bindFramebuffer(GLenum target, GLuint framebuffer) |
| 3999 | { |
| 4000 | if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER) |
| 4001 | { |
| 4002 | bindReadFramebuffer(framebuffer); |
| 4003 | } |
| 4004 | |
| 4005 | if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER) |
| 4006 | { |
| 4007 | bindDrawFramebuffer(framebuffer); |
| 4008 | } |
| 4009 | } |
| 4010 | |
| 4011 | void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer) |
| 4012 | { |
| 4013 | ASSERT(target == GL_RENDERBUFFER); |
| 4014 | Renderbuffer *object = |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 4015 | mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 4016 | mGLState.setRenderbufferBinding(this, object); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4017 | } |
| 4018 | |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 4019 | void Context::texStorage2DMultisample(GLenum target, |
| 4020 | GLsizei samples, |
| 4021 | GLenum internalformat, |
| 4022 | GLsizei width, |
| 4023 | GLsizei height, |
| 4024 | GLboolean fixedsamplelocations) |
| 4025 | { |
| 4026 | Extents size(width, height, 1); |
| 4027 | Texture *texture = getTargetTexture(target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 4028 | handleError(texture->setStorageMultisample(this, target, samples, internalformat, size, |
Geoff Lang | 9201943 | 2017-11-20 13:09:34 -0500 | [diff] [blame] | 4029 | ConvertToBool(fixedsamplelocations))); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 4030 | } |
| 4031 | |
| 4032 | void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val) |
| 4033 | { |
JiangYizhou | 5b03f47 | 2017-01-09 10:22:53 +0800 | [diff] [blame] | 4034 | // According to spec 3.1 Table 20.49: Framebuffer Dependent Values, |
| 4035 | // the sample position should be queried by DRAW_FRAMEBUFFER. |
| 4036 | mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER); |
| 4037 | const Framebuffer *framebuffer = mGLState.getDrawFramebuffer(); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 4038 | |
| 4039 | switch (pname) |
| 4040 | { |
| 4041 | case GL_SAMPLE_POSITION: |
| 4042 | handleError(framebuffer->getSamplePosition(index, val)); |
| 4043 | break; |
| 4044 | default: |
| 4045 | UNREACHABLE(); |
| 4046 | } |
| 4047 | } |
| 4048 | |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4049 | void Context::renderbufferStorage(GLenum target, |
| 4050 | GLenum internalformat, |
| 4051 | GLsizei width, |
| 4052 | GLsizei height) |
| 4053 | { |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 4054 | // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format. |
| 4055 | GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat); |
| 4056 | |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4057 | Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer(); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 4058 | handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height)); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4059 | } |
| 4060 | |
| 4061 | void Context::renderbufferStorageMultisample(GLenum target, |
| 4062 | GLsizei samples, |
| 4063 | GLenum internalformat, |
| 4064 | GLsizei width, |
| 4065 | GLsizei height) |
| 4066 | { |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 4067 | // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format. |
| 4068 | GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4069 | |
| 4070 | Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer(); |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 4071 | handleError( |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 4072 | renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height)); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4073 | } |
| 4074 | |
Geoff Lang | 38f2cfb | 2017-04-11 15:23:08 -0400 | [diff] [blame] | 4075 | void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values) |
| 4076 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 4077 | const Sync *syncObject = getSync(sync); |
Geoff Lang | 82483b9 | 2017-04-11 15:33:00 -0400 | [diff] [blame] | 4078 | handleError(QuerySynciv(syncObject, pname, bufSize, length, values)); |
Geoff Lang | 38f2cfb | 2017-04-11 15:23:08 -0400 | [diff] [blame] | 4079 | } |
| 4080 | |
JiangYizhou | e18e639 | 2017-02-20 10:32:23 +0800 | [diff] [blame] | 4081 | void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params) |
| 4082 | { |
| 4083 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
| 4084 | QueryFramebufferParameteriv(framebuffer, pname, params); |
| 4085 | } |
| 4086 | |
| 4087 | void Context::setFramebufferParameteri(GLenum target, GLenum pname, GLint param) |
| 4088 | { |
| 4089 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
| 4090 | SetFramebufferParameteri(framebuffer, pname, param); |
| 4091 | } |
| 4092 | |
Jamie Madill | b3f26b9 | 2017-07-19 15:07:41 -0400 | [diff] [blame] | 4093 | Error Context::getScratchBuffer(size_t requstedSizeBytes, |
| 4094 | angle::MemoryBuffer **scratchBufferOut) const |
Jamie Madill | e14951e | 2017-03-09 18:55:16 -0500 | [diff] [blame] | 4095 | { |
Jamie Madill | b3f26b9 | 2017-07-19 15:07:41 -0400 | [diff] [blame] | 4096 | if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut)) |
| 4097 | { |
| 4098 | return OutOfMemory() << "Failed to allocate internal buffer."; |
| 4099 | } |
| 4100 | return NoError(); |
| 4101 | } |
| 4102 | |
| 4103 | Error Context::getZeroFilledBuffer(size_t requstedSizeBytes, |
| 4104 | angle::MemoryBuffer **zeroBufferOut) const |
| 4105 | { |
| 4106 | if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0)) |
Jamie Madill | e14951e | 2017-03-09 18:55:16 -0500 | [diff] [blame] | 4107 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4108 | return OutOfMemory() << "Failed to allocate internal buffer."; |
Jamie Madill | e14951e | 2017-03-09 18:55:16 -0500 | [diff] [blame] | 4109 | } |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4110 | return NoError(); |
Jamie Madill | e14951e | 2017-03-09 18:55:16 -0500 | [diff] [blame] | 4111 | } |
| 4112 | |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 4113 | void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ) |
| 4114 | { |
| 4115 | if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u) |
| 4116 | { |
| 4117 | return; |
| 4118 | } |
| 4119 | |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 4120 | // TODO(jmadill): Dirty bits for compute. |
Jamie Madill | a59fc19 | 2017-11-02 12:57:58 -0400 | [diff] [blame] | 4121 | if (isRobustResourceInitEnabled()) |
| 4122 | { |
| 4123 | ANGLE_CONTEXT_TRY(mGLState.clearUnclearedActiveTextures(this)); |
| 4124 | } |
Jamie Madill | 05b35b2 | 2017-10-03 09:01:44 -0400 | [diff] [blame] | 4125 | |
Jamie Madill | 71c88b3 | 2017-09-14 22:20:29 -0400 | [diff] [blame] | 4126 | handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ)); |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 4127 | } |
| 4128 | |
JiangYizhou | 165361c | 2017-06-07 14:56:57 +0800 | [diff] [blame] | 4129 | void Context::texStorage2D(GLenum target, |
| 4130 | GLsizei levels, |
| 4131 | GLenum internalFormat, |
| 4132 | GLsizei width, |
| 4133 | GLsizei height) |
| 4134 | { |
| 4135 | Extents size(width, height, 1); |
| 4136 | Texture *texture = getTargetTexture(target); |
| 4137 | handleError(texture->setStorage(this, target, levels, internalFormat, size)); |
| 4138 | } |
| 4139 | |
| 4140 | void Context::texStorage3D(GLenum target, |
| 4141 | GLsizei levels, |
| 4142 | GLenum internalFormat, |
| 4143 | GLsizei width, |
| 4144 | GLsizei height, |
| 4145 | GLsizei depth) |
| 4146 | { |
| 4147 | Extents size(width, height, depth); |
| 4148 | Texture *texture = getTargetTexture(target); |
| 4149 | handleError(texture->setStorage(this, target, levels, internalFormat, size)); |
| 4150 | } |
| 4151 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4152 | GLenum Context::checkFramebufferStatus(GLenum target) |
| 4153 | { |
| 4154 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
| 4155 | ASSERT(framebuffer); |
| 4156 | |
| 4157 | return framebuffer->checkStatus(this); |
| 4158 | } |
| 4159 | |
| 4160 | void Context::compileShader(GLuint shader) |
| 4161 | { |
| 4162 | Shader *shaderObject = GetValidShader(this, shader); |
| 4163 | if (!shaderObject) |
| 4164 | { |
| 4165 | return; |
| 4166 | } |
| 4167 | shaderObject->compile(this); |
| 4168 | } |
| 4169 | |
| 4170 | void Context::deleteBuffers(GLsizei n, const GLuint *buffers) |
| 4171 | { |
| 4172 | for (int i = 0; i < n; i++) |
| 4173 | { |
| 4174 | deleteBuffer(buffers[i]); |
| 4175 | } |
| 4176 | } |
| 4177 | |
| 4178 | void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers) |
| 4179 | { |
| 4180 | for (int i = 0; i < n; i++) |
| 4181 | { |
| 4182 | if (framebuffers[i] != 0) |
| 4183 | { |
| 4184 | deleteFramebuffer(framebuffers[i]); |
| 4185 | } |
| 4186 | } |
| 4187 | } |
| 4188 | |
| 4189 | void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers) |
| 4190 | { |
| 4191 | for (int i = 0; i < n; i++) |
| 4192 | { |
| 4193 | deleteRenderbuffer(renderbuffers[i]); |
| 4194 | } |
| 4195 | } |
| 4196 | |
| 4197 | void Context::deleteTextures(GLsizei n, const GLuint *textures) |
| 4198 | { |
| 4199 | for (int i = 0; i < n; i++) |
| 4200 | { |
| 4201 | if (textures[i] != 0) |
| 4202 | { |
| 4203 | deleteTexture(textures[i]); |
| 4204 | } |
| 4205 | } |
| 4206 | } |
| 4207 | |
| 4208 | void Context::detachShader(GLuint program, GLuint shader) |
| 4209 | { |
| 4210 | Program *programObject = getProgram(program); |
| 4211 | ASSERT(programObject); |
| 4212 | |
| 4213 | Shader *shaderObject = getShader(shader); |
| 4214 | ASSERT(shaderObject); |
| 4215 | |
| 4216 | programObject->detachShader(this, shaderObject); |
| 4217 | } |
| 4218 | |
| 4219 | void Context::genBuffers(GLsizei n, GLuint *buffers) |
| 4220 | { |
| 4221 | for (int i = 0; i < n; i++) |
| 4222 | { |
| 4223 | buffers[i] = createBuffer(); |
| 4224 | } |
| 4225 | } |
| 4226 | |
| 4227 | void Context::genFramebuffers(GLsizei n, GLuint *framebuffers) |
| 4228 | { |
| 4229 | for (int i = 0; i < n; i++) |
| 4230 | { |
| 4231 | framebuffers[i] = createFramebuffer(); |
| 4232 | } |
| 4233 | } |
| 4234 | |
| 4235 | void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers) |
| 4236 | { |
| 4237 | for (int i = 0; i < n; i++) |
| 4238 | { |
| 4239 | renderbuffers[i] = createRenderbuffer(); |
| 4240 | } |
| 4241 | } |
| 4242 | |
| 4243 | void Context::genTextures(GLsizei n, GLuint *textures) |
| 4244 | { |
| 4245 | for (int i = 0; i < n; i++) |
| 4246 | { |
| 4247 | textures[i] = createTexture(); |
| 4248 | } |
| 4249 | } |
| 4250 | |
| 4251 | void Context::getActiveAttrib(GLuint program, |
| 4252 | GLuint index, |
| 4253 | GLsizei bufsize, |
| 4254 | GLsizei *length, |
| 4255 | GLint *size, |
| 4256 | GLenum *type, |
| 4257 | GLchar *name) |
| 4258 | { |
| 4259 | Program *programObject = getProgram(program); |
| 4260 | ASSERT(programObject); |
| 4261 | programObject->getActiveAttribute(index, bufsize, length, size, type, name); |
| 4262 | } |
| 4263 | |
| 4264 | void Context::getActiveUniform(GLuint program, |
| 4265 | GLuint index, |
| 4266 | GLsizei bufsize, |
| 4267 | GLsizei *length, |
| 4268 | GLint *size, |
| 4269 | GLenum *type, |
| 4270 | GLchar *name) |
| 4271 | { |
| 4272 | Program *programObject = getProgram(program); |
| 4273 | ASSERT(programObject); |
| 4274 | programObject->getActiveUniform(index, bufsize, length, size, type, name); |
| 4275 | } |
| 4276 | |
| 4277 | void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders) |
| 4278 | { |
| 4279 | Program *programObject = getProgram(program); |
| 4280 | ASSERT(programObject); |
| 4281 | programObject->getAttachedShaders(maxcount, count, shaders); |
| 4282 | } |
| 4283 | |
| 4284 | GLint Context::getAttribLocation(GLuint program, const GLchar *name) |
| 4285 | { |
| 4286 | Program *programObject = getProgram(program); |
| 4287 | ASSERT(programObject); |
| 4288 | return programObject->getAttributeLocation(name); |
| 4289 | } |
| 4290 | |
| 4291 | void Context::getBooleanv(GLenum pname, GLboolean *params) |
| 4292 | { |
| 4293 | GLenum nativeType; |
| 4294 | unsigned int numParams = 0; |
| 4295 | getQueryParameterInfo(pname, &nativeType, &numParams); |
| 4296 | |
| 4297 | if (nativeType == GL_BOOL) |
| 4298 | { |
| 4299 | getBooleanvImpl(pname, params); |
| 4300 | } |
| 4301 | else |
| 4302 | { |
| 4303 | CastStateValues(this, nativeType, pname, numParams, params); |
| 4304 | } |
| 4305 | } |
| 4306 | |
| 4307 | void Context::getFloatv(GLenum pname, GLfloat *params) |
| 4308 | { |
| 4309 | GLenum nativeType; |
| 4310 | unsigned int numParams = 0; |
| 4311 | getQueryParameterInfo(pname, &nativeType, &numParams); |
| 4312 | |
| 4313 | if (nativeType == GL_FLOAT) |
| 4314 | { |
| 4315 | getFloatvImpl(pname, params); |
| 4316 | } |
| 4317 | else |
| 4318 | { |
| 4319 | CastStateValues(this, nativeType, pname, numParams, params); |
| 4320 | } |
| 4321 | } |
| 4322 | |
| 4323 | void Context::getIntegerv(GLenum pname, GLint *params) |
| 4324 | { |
| 4325 | GLenum nativeType; |
| 4326 | unsigned int numParams = 0; |
| 4327 | getQueryParameterInfo(pname, &nativeType, &numParams); |
| 4328 | |
| 4329 | if (nativeType == GL_INT) |
| 4330 | { |
| 4331 | getIntegervImpl(pname, params); |
| 4332 | } |
| 4333 | else |
| 4334 | { |
| 4335 | CastStateValues(this, nativeType, pname, numParams, params); |
| 4336 | } |
| 4337 | } |
| 4338 | |
| 4339 | void Context::getProgramiv(GLuint program, GLenum pname, GLint *params) |
| 4340 | { |
| 4341 | Program *programObject = getProgram(program); |
| 4342 | ASSERT(programObject); |
Jamie Madill | ffe00c0 | 2017-06-27 16:26:55 -0400 | [diff] [blame] | 4343 | QueryProgramiv(this, programObject, pname, params); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4344 | } |
| 4345 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4346 | void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4347 | { |
| 4348 | Program *programObject = getProgram(program); |
| 4349 | ASSERT(programObject); |
| 4350 | programObject->getInfoLog(bufsize, length, infolog); |
| 4351 | } |
| 4352 | |
| 4353 | void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params) |
| 4354 | { |
| 4355 | Shader *shaderObject = getShader(shader); |
| 4356 | ASSERT(shaderObject); |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 4357 | QueryShaderiv(this, shaderObject, pname, params); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4358 | } |
| 4359 | |
| 4360 | void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog) |
| 4361 | { |
| 4362 | Shader *shaderObject = getShader(shader); |
| 4363 | ASSERT(shaderObject); |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 4364 | shaderObject->getInfoLog(this, bufsize, length, infolog); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4365 | } |
| 4366 | |
| 4367 | void Context::getShaderPrecisionFormat(GLenum shadertype, |
| 4368 | GLenum precisiontype, |
| 4369 | GLint *range, |
| 4370 | GLint *precision) |
| 4371 | { |
| 4372 | // TODO(jmadill): Compute shaders. |
| 4373 | |
| 4374 | switch (shadertype) |
| 4375 | { |
| 4376 | case GL_VERTEX_SHADER: |
| 4377 | switch (precisiontype) |
| 4378 | { |
| 4379 | case GL_LOW_FLOAT: |
| 4380 | mCaps.vertexLowpFloat.get(range, precision); |
| 4381 | break; |
| 4382 | case GL_MEDIUM_FLOAT: |
| 4383 | mCaps.vertexMediumpFloat.get(range, precision); |
| 4384 | break; |
| 4385 | case GL_HIGH_FLOAT: |
| 4386 | mCaps.vertexHighpFloat.get(range, precision); |
| 4387 | break; |
| 4388 | |
| 4389 | case GL_LOW_INT: |
| 4390 | mCaps.vertexLowpInt.get(range, precision); |
| 4391 | break; |
| 4392 | case GL_MEDIUM_INT: |
| 4393 | mCaps.vertexMediumpInt.get(range, precision); |
| 4394 | break; |
| 4395 | case GL_HIGH_INT: |
| 4396 | mCaps.vertexHighpInt.get(range, precision); |
| 4397 | break; |
| 4398 | |
| 4399 | default: |
| 4400 | UNREACHABLE(); |
| 4401 | return; |
| 4402 | } |
| 4403 | break; |
| 4404 | |
| 4405 | case GL_FRAGMENT_SHADER: |
| 4406 | switch (precisiontype) |
| 4407 | { |
| 4408 | case GL_LOW_FLOAT: |
| 4409 | mCaps.fragmentLowpFloat.get(range, precision); |
| 4410 | break; |
| 4411 | case GL_MEDIUM_FLOAT: |
| 4412 | mCaps.fragmentMediumpFloat.get(range, precision); |
| 4413 | break; |
| 4414 | case GL_HIGH_FLOAT: |
| 4415 | mCaps.fragmentHighpFloat.get(range, precision); |
| 4416 | break; |
| 4417 | |
| 4418 | case GL_LOW_INT: |
| 4419 | mCaps.fragmentLowpInt.get(range, precision); |
| 4420 | break; |
| 4421 | case GL_MEDIUM_INT: |
| 4422 | mCaps.fragmentMediumpInt.get(range, precision); |
| 4423 | break; |
| 4424 | case GL_HIGH_INT: |
| 4425 | mCaps.fragmentHighpInt.get(range, precision); |
| 4426 | break; |
| 4427 | |
| 4428 | default: |
| 4429 | UNREACHABLE(); |
| 4430 | return; |
| 4431 | } |
| 4432 | break; |
| 4433 | |
| 4434 | default: |
| 4435 | UNREACHABLE(); |
| 4436 | return; |
| 4437 | } |
| 4438 | } |
| 4439 | |
| 4440 | void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source) |
| 4441 | { |
| 4442 | Shader *shaderObject = getShader(shader); |
| 4443 | ASSERT(shaderObject); |
| 4444 | shaderObject->getSource(bufsize, length, source); |
| 4445 | } |
| 4446 | |
| 4447 | void Context::getUniformfv(GLuint program, GLint location, GLfloat *params) |
| 4448 | { |
| 4449 | Program *programObject = getProgram(program); |
| 4450 | ASSERT(programObject); |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 4451 | programObject->getUniformfv(this, location, params); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4452 | } |
| 4453 | |
| 4454 | void Context::getUniformiv(GLuint program, GLint location, GLint *params) |
| 4455 | { |
| 4456 | Program *programObject = getProgram(program); |
| 4457 | ASSERT(programObject); |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 4458 | programObject->getUniformiv(this, location, params); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4459 | } |
| 4460 | |
| 4461 | GLint Context::getUniformLocation(GLuint program, const GLchar *name) |
| 4462 | { |
| 4463 | Program *programObject = getProgram(program); |
| 4464 | ASSERT(programObject); |
| 4465 | return programObject->getUniformLocation(name); |
| 4466 | } |
| 4467 | |
| 4468 | GLboolean Context::isBuffer(GLuint buffer) |
| 4469 | { |
| 4470 | if (buffer == 0) |
| 4471 | { |
| 4472 | return GL_FALSE; |
| 4473 | } |
| 4474 | |
| 4475 | return (getBuffer(buffer) ? GL_TRUE : GL_FALSE); |
| 4476 | } |
| 4477 | |
| 4478 | GLboolean Context::isEnabled(GLenum cap) |
| 4479 | { |
| 4480 | return mGLState.getEnableFeature(cap); |
| 4481 | } |
| 4482 | |
| 4483 | GLboolean Context::isFramebuffer(GLuint framebuffer) |
| 4484 | { |
| 4485 | if (framebuffer == 0) |
| 4486 | { |
| 4487 | return GL_FALSE; |
| 4488 | } |
| 4489 | |
| 4490 | return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE); |
| 4491 | } |
| 4492 | |
| 4493 | GLboolean Context::isProgram(GLuint program) |
| 4494 | { |
| 4495 | if (program == 0) |
| 4496 | { |
| 4497 | return GL_FALSE; |
| 4498 | } |
| 4499 | |
| 4500 | return (getProgram(program) ? GL_TRUE : GL_FALSE); |
| 4501 | } |
| 4502 | |
| 4503 | GLboolean Context::isRenderbuffer(GLuint renderbuffer) |
| 4504 | { |
| 4505 | if (renderbuffer == 0) |
| 4506 | { |
| 4507 | return GL_FALSE; |
| 4508 | } |
| 4509 | |
| 4510 | return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE); |
| 4511 | } |
| 4512 | |
| 4513 | GLboolean Context::isShader(GLuint shader) |
| 4514 | { |
| 4515 | if (shader == 0) |
| 4516 | { |
| 4517 | return GL_FALSE; |
| 4518 | } |
| 4519 | |
| 4520 | return (getShader(shader) ? GL_TRUE : GL_FALSE); |
| 4521 | } |
| 4522 | |
| 4523 | GLboolean Context::isTexture(GLuint texture) |
| 4524 | { |
| 4525 | if (texture == 0) |
| 4526 | { |
| 4527 | return GL_FALSE; |
| 4528 | } |
| 4529 | |
| 4530 | return (getTexture(texture) ? GL_TRUE : GL_FALSE); |
| 4531 | } |
| 4532 | |
| 4533 | void Context::linkProgram(GLuint program) |
| 4534 | { |
| 4535 | Program *programObject = getProgram(program); |
| 4536 | ASSERT(programObject); |
| 4537 | handleError(programObject->link(this)); |
Martin Radev | 0abb7a2 | 2017-08-28 15:34:45 +0300 | [diff] [blame] | 4538 | mGLState.onProgramExecutableChange(programObject); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4539 | } |
| 4540 | |
| 4541 | void Context::releaseShaderCompiler() |
| 4542 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 4543 | mCompiler.set(this, nullptr); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4544 | } |
| 4545 | |
| 4546 | void Context::shaderBinary(GLsizei n, |
| 4547 | const GLuint *shaders, |
| 4548 | GLenum binaryformat, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4549 | const void *binary, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4550 | GLsizei length) |
| 4551 | { |
| 4552 | // No binary shader formats are supported. |
| 4553 | UNIMPLEMENTED(); |
| 4554 | } |
| 4555 | |
| 4556 | void Context::shaderSource(GLuint shader, |
| 4557 | GLsizei count, |
| 4558 | const GLchar *const *string, |
| 4559 | const GLint *length) |
| 4560 | { |
| 4561 | Shader *shaderObject = getShader(shader); |
| 4562 | ASSERT(shaderObject); |
| 4563 | shaderObject->setSource(count, string, length); |
| 4564 | } |
| 4565 | |
| 4566 | void Context::stencilFunc(GLenum func, GLint ref, GLuint mask) |
| 4567 | { |
| 4568 | stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask); |
| 4569 | } |
| 4570 | |
| 4571 | void Context::stencilMask(GLuint mask) |
| 4572 | { |
| 4573 | stencilMaskSeparate(GL_FRONT_AND_BACK, mask); |
| 4574 | } |
| 4575 | |
| 4576 | void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass) |
| 4577 | { |
| 4578 | stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass); |
| 4579 | } |
| 4580 | |
| 4581 | void Context::uniform1f(GLint location, GLfloat x) |
| 4582 | { |
| 4583 | Program *program = mGLState.getProgram(); |
| 4584 | program->setUniform1fv(location, 1, &x); |
| 4585 | } |
| 4586 | |
| 4587 | void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v) |
| 4588 | { |
| 4589 | Program *program = mGLState.getProgram(); |
| 4590 | program->setUniform1fv(location, count, v); |
| 4591 | } |
| 4592 | |
| 4593 | void Context::uniform1i(GLint location, GLint x) |
| 4594 | { |
| 4595 | Program *program = mGLState.getProgram(); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 4596 | if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged) |
| 4597 | { |
| 4598 | mGLState.setObjectDirty(GL_PROGRAM); |
| 4599 | } |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4600 | } |
| 4601 | |
| 4602 | void Context::uniform1iv(GLint location, GLsizei count, const GLint *v) |
| 4603 | { |
| 4604 | Program *program = mGLState.getProgram(); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 4605 | if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged) |
| 4606 | { |
| 4607 | mGLState.setObjectDirty(GL_PROGRAM); |
| 4608 | } |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4609 | } |
| 4610 | |
| 4611 | void Context::uniform2f(GLint location, GLfloat x, GLfloat y) |
| 4612 | { |
| 4613 | GLfloat xy[2] = {x, y}; |
| 4614 | Program *program = mGLState.getProgram(); |
| 4615 | program->setUniform2fv(location, 1, xy); |
| 4616 | } |
| 4617 | |
| 4618 | void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v) |
| 4619 | { |
| 4620 | Program *program = mGLState.getProgram(); |
| 4621 | program->setUniform2fv(location, count, v); |
| 4622 | } |
| 4623 | |
| 4624 | void Context::uniform2i(GLint location, GLint x, GLint y) |
| 4625 | { |
| 4626 | GLint xy[2] = {x, y}; |
| 4627 | Program *program = mGLState.getProgram(); |
| 4628 | program->setUniform2iv(location, 1, xy); |
| 4629 | } |
| 4630 | |
| 4631 | void Context::uniform2iv(GLint location, GLsizei count, const GLint *v) |
| 4632 | { |
| 4633 | Program *program = mGLState.getProgram(); |
| 4634 | program->setUniform2iv(location, count, v); |
| 4635 | } |
| 4636 | |
| 4637 | void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z) |
| 4638 | { |
| 4639 | GLfloat xyz[3] = {x, y, z}; |
| 4640 | Program *program = mGLState.getProgram(); |
| 4641 | program->setUniform3fv(location, 1, xyz); |
| 4642 | } |
| 4643 | |
| 4644 | void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v) |
| 4645 | { |
| 4646 | Program *program = mGLState.getProgram(); |
| 4647 | program->setUniform3fv(location, count, v); |
| 4648 | } |
| 4649 | |
| 4650 | void Context::uniform3i(GLint location, GLint x, GLint y, GLint z) |
| 4651 | { |
| 4652 | GLint xyz[3] = {x, y, z}; |
| 4653 | Program *program = mGLState.getProgram(); |
| 4654 | program->setUniform3iv(location, 1, xyz); |
| 4655 | } |
| 4656 | |
| 4657 | void Context::uniform3iv(GLint location, GLsizei count, const GLint *v) |
| 4658 | { |
| 4659 | Program *program = mGLState.getProgram(); |
| 4660 | program->setUniform3iv(location, count, v); |
| 4661 | } |
| 4662 | |
| 4663 | void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w) |
| 4664 | { |
| 4665 | GLfloat xyzw[4] = {x, y, z, w}; |
| 4666 | Program *program = mGLState.getProgram(); |
| 4667 | program->setUniform4fv(location, 1, xyzw); |
| 4668 | } |
| 4669 | |
| 4670 | void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v) |
| 4671 | { |
| 4672 | Program *program = mGLState.getProgram(); |
| 4673 | program->setUniform4fv(location, count, v); |
| 4674 | } |
| 4675 | |
| 4676 | void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w) |
| 4677 | { |
| 4678 | GLint xyzw[4] = {x, y, z, w}; |
| 4679 | Program *program = mGLState.getProgram(); |
| 4680 | program->setUniform4iv(location, 1, xyzw); |
| 4681 | } |
| 4682 | |
| 4683 | void Context::uniform4iv(GLint location, GLsizei count, const GLint *v) |
| 4684 | { |
| 4685 | Program *program = mGLState.getProgram(); |
| 4686 | program->setUniform4iv(location, count, v); |
| 4687 | } |
| 4688 | |
| 4689 | void Context::uniformMatrix2fv(GLint location, |
| 4690 | GLsizei count, |
| 4691 | GLboolean transpose, |
| 4692 | const GLfloat *value) |
| 4693 | { |
| 4694 | Program *program = mGLState.getProgram(); |
| 4695 | program->setUniformMatrix2fv(location, count, transpose, value); |
| 4696 | } |
| 4697 | |
| 4698 | void Context::uniformMatrix3fv(GLint location, |
| 4699 | GLsizei count, |
| 4700 | GLboolean transpose, |
| 4701 | const GLfloat *value) |
| 4702 | { |
| 4703 | Program *program = mGLState.getProgram(); |
| 4704 | program->setUniformMatrix3fv(location, count, transpose, value); |
| 4705 | } |
| 4706 | |
| 4707 | void Context::uniformMatrix4fv(GLint location, |
| 4708 | GLsizei count, |
| 4709 | GLboolean transpose, |
| 4710 | const GLfloat *value) |
| 4711 | { |
| 4712 | Program *program = mGLState.getProgram(); |
| 4713 | program->setUniformMatrix4fv(location, count, transpose, value); |
| 4714 | } |
| 4715 | |
| 4716 | void Context::validateProgram(GLuint program) |
| 4717 | { |
| 4718 | Program *programObject = getProgram(program); |
| 4719 | ASSERT(programObject); |
| 4720 | programObject->validate(mCaps); |
| 4721 | } |
| 4722 | |
Jamie Madill | d04908b | 2017-06-09 14:15:35 -0400 | [diff] [blame] | 4723 | void Context::getProgramBinary(GLuint program, |
| 4724 | GLsizei bufSize, |
| 4725 | GLsizei *length, |
| 4726 | GLenum *binaryFormat, |
| 4727 | void *binary) |
| 4728 | { |
| 4729 | Program *programObject = getProgram(program); |
| 4730 | ASSERT(programObject != nullptr); |
| 4731 | |
| 4732 | handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length)); |
| 4733 | } |
| 4734 | |
| 4735 | void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length) |
| 4736 | { |
| 4737 | Program *programObject = getProgram(program); |
| 4738 | ASSERT(programObject != nullptr); |
Jamie Madill | b666492 | 2017-07-25 12:55:04 -0400 | [diff] [blame] | 4739 | |
Jamie Madill | d04908b | 2017-06-09 14:15:35 -0400 | [diff] [blame] | 4740 | handleError(programObject->loadBinary(this, binaryFormat, binary, length)); |
| 4741 | } |
| 4742 | |
Jamie Madill | ff325f1 | 2017-08-26 15:06:05 -0400 | [diff] [blame] | 4743 | void Context::uniform1ui(GLint location, GLuint v0) |
| 4744 | { |
| 4745 | Program *program = mGLState.getProgram(); |
| 4746 | program->setUniform1uiv(location, 1, &v0); |
| 4747 | } |
| 4748 | |
| 4749 | void Context::uniform2ui(GLint location, GLuint v0, GLuint v1) |
| 4750 | { |
| 4751 | Program *program = mGLState.getProgram(); |
| 4752 | const GLuint xy[] = {v0, v1}; |
| 4753 | program->setUniform2uiv(location, 1, xy); |
| 4754 | } |
| 4755 | |
| 4756 | void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2) |
| 4757 | { |
| 4758 | Program *program = mGLState.getProgram(); |
| 4759 | const GLuint xyz[] = {v0, v1, v2}; |
| 4760 | program->setUniform3uiv(location, 1, xyz); |
| 4761 | } |
| 4762 | |
| 4763 | void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3) |
| 4764 | { |
| 4765 | Program *program = mGLState.getProgram(); |
| 4766 | const GLuint xyzw[] = {v0, v1, v2, v3}; |
| 4767 | program->setUniform4uiv(location, 1, xyzw); |
| 4768 | } |
| 4769 | |
| 4770 | void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value) |
| 4771 | { |
| 4772 | Program *program = mGLState.getProgram(); |
| 4773 | program->setUniform1uiv(location, count, value); |
| 4774 | } |
| 4775 | void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value) |
| 4776 | { |
| 4777 | Program *program = mGLState.getProgram(); |
| 4778 | program->setUniform2uiv(location, count, value); |
| 4779 | } |
| 4780 | |
| 4781 | void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value) |
| 4782 | { |
| 4783 | Program *program = mGLState.getProgram(); |
| 4784 | program->setUniform3uiv(location, count, value); |
| 4785 | } |
| 4786 | |
| 4787 | void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value) |
| 4788 | { |
| 4789 | Program *program = mGLState.getProgram(); |
| 4790 | program->setUniform4uiv(location, count, value); |
| 4791 | } |
| 4792 | |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 4793 | void Context::genQueries(GLsizei n, GLuint *ids) |
| 4794 | { |
| 4795 | for (GLsizei i = 0; i < n; i++) |
| 4796 | { |
| 4797 | GLuint handle = mQueryHandleAllocator.allocate(); |
| 4798 | mQueryMap.assign(handle, nullptr); |
| 4799 | ids[i] = handle; |
| 4800 | } |
| 4801 | } |
| 4802 | |
| 4803 | void Context::deleteQueries(GLsizei n, const GLuint *ids) |
| 4804 | { |
| 4805 | for (int i = 0; i < n; i++) |
| 4806 | { |
| 4807 | GLuint query = ids[i]; |
| 4808 | |
| 4809 | Query *queryObject = nullptr; |
| 4810 | if (mQueryMap.erase(query, &queryObject)) |
| 4811 | { |
| 4812 | mQueryHandleAllocator.release(query); |
| 4813 | if (queryObject) |
| 4814 | { |
| 4815 | queryObject->release(this); |
| 4816 | } |
| 4817 | } |
| 4818 | } |
| 4819 | } |
| 4820 | |
| 4821 | GLboolean Context::isQuery(GLuint id) |
| 4822 | { |
| 4823 | return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE; |
| 4824 | } |
| 4825 | |
Jamie Madill | c8c9581 | 2017-08-26 18:40:09 -0400 | [diff] [blame] | 4826 | void Context::uniformMatrix2x3fv(GLint location, |
| 4827 | GLsizei count, |
| 4828 | GLboolean transpose, |
| 4829 | const GLfloat *value) |
| 4830 | { |
| 4831 | Program *program = mGLState.getProgram(); |
| 4832 | program->setUniformMatrix2x3fv(location, count, transpose, value); |
| 4833 | } |
| 4834 | |
| 4835 | void Context::uniformMatrix3x2fv(GLint location, |
| 4836 | GLsizei count, |
| 4837 | GLboolean transpose, |
| 4838 | const GLfloat *value) |
| 4839 | { |
| 4840 | Program *program = mGLState.getProgram(); |
| 4841 | program->setUniformMatrix3x2fv(location, count, transpose, value); |
| 4842 | } |
| 4843 | |
| 4844 | void Context::uniformMatrix2x4fv(GLint location, |
| 4845 | GLsizei count, |
| 4846 | GLboolean transpose, |
| 4847 | const GLfloat *value) |
| 4848 | { |
| 4849 | Program *program = mGLState.getProgram(); |
| 4850 | program->setUniformMatrix2x4fv(location, count, transpose, value); |
| 4851 | } |
| 4852 | |
| 4853 | void Context::uniformMatrix4x2fv(GLint location, |
| 4854 | GLsizei count, |
| 4855 | GLboolean transpose, |
| 4856 | const GLfloat *value) |
| 4857 | { |
| 4858 | Program *program = mGLState.getProgram(); |
| 4859 | program->setUniformMatrix4x2fv(location, count, transpose, value); |
| 4860 | } |
| 4861 | |
| 4862 | void Context::uniformMatrix3x4fv(GLint location, |
| 4863 | GLsizei count, |
| 4864 | GLboolean transpose, |
| 4865 | const GLfloat *value) |
| 4866 | { |
| 4867 | Program *program = mGLState.getProgram(); |
| 4868 | program->setUniformMatrix3x4fv(location, count, transpose, value); |
| 4869 | } |
| 4870 | |
| 4871 | void Context::uniformMatrix4x3fv(GLint location, |
| 4872 | GLsizei count, |
| 4873 | GLboolean transpose, |
| 4874 | const GLfloat *value) |
| 4875 | { |
| 4876 | Program *program = mGLState.getProgram(); |
| 4877 | program->setUniformMatrix4x3fv(location, count, transpose, value); |
| 4878 | } |
| 4879 | |
Jamie Madill | d757673 | 2017-08-26 18:49:50 -0400 | [diff] [blame] | 4880 | void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays) |
| 4881 | { |
| 4882 | for (int arrayIndex = 0; arrayIndex < n; arrayIndex++) |
| 4883 | { |
| 4884 | GLuint vertexArray = arrays[arrayIndex]; |
| 4885 | |
| 4886 | if (arrays[arrayIndex] != 0) |
| 4887 | { |
| 4888 | VertexArray *vertexArrayObject = nullptr; |
| 4889 | if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject)) |
| 4890 | { |
| 4891 | if (vertexArrayObject != nullptr) |
| 4892 | { |
| 4893 | detachVertexArray(vertexArray); |
| 4894 | vertexArrayObject->onDestroy(this); |
| 4895 | } |
| 4896 | |
| 4897 | mVertexArrayHandleAllocator.release(vertexArray); |
| 4898 | } |
| 4899 | } |
| 4900 | } |
| 4901 | } |
| 4902 | |
| 4903 | void Context::genVertexArrays(GLsizei n, GLuint *arrays) |
| 4904 | { |
| 4905 | for (int arrayIndex = 0; arrayIndex < n; arrayIndex++) |
| 4906 | { |
| 4907 | GLuint vertexArray = mVertexArrayHandleAllocator.allocate(); |
| 4908 | mVertexArrayMap.assign(vertexArray, nullptr); |
| 4909 | arrays[arrayIndex] = vertexArray; |
| 4910 | } |
| 4911 | } |
| 4912 | |
| 4913 | bool Context::isVertexArray(GLuint array) |
| 4914 | { |
| 4915 | if (array == 0) |
| 4916 | { |
| 4917 | return GL_FALSE; |
| 4918 | } |
| 4919 | |
| 4920 | VertexArray *vao = getVertexArray(array); |
| 4921 | return (vao != nullptr ? GL_TRUE : GL_FALSE); |
| 4922 | } |
| 4923 | |
Jamie Madill | f0dcb8b | 2017-08-26 19:05:13 -0400 | [diff] [blame] | 4924 | void Context::endTransformFeedback() |
| 4925 | { |
| 4926 | TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback(); |
| 4927 | transformFeedback->end(this); |
| 4928 | } |
| 4929 | |
| 4930 | void Context::transformFeedbackVaryings(GLuint program, |
| 4931 | GLsizei count, |
| 4932 | const GLchar *const *varyings, |
| 4933 | GLenum bufferMode) |
| 4934 | { |
| 4935 | Program *programObject = getProgram(program); |
| 4936 | ASSERT(programObject); |
| 4937 | programObject->setTransformFeedbackVaryings(count, varyings, bufferMode); |
| 4938 | } |
| 4939 | |
| 4940 | void Context::getTransformFeedbackVarying(GLuint program, |
| 4941 | GLuint index, |
| 4942 | GLsizei bufSize, |
| 4943 | GLsizei *length, |
| 4944 | GLsizei *size, |
| 4945 | GLenum *type, |
| 4946 | GLchar *name) |
| 4947 | { |
| 4948 | Program *programObject = getProgram(program); |
| 4949 | ASSERT(programObject); |
| 4950 | programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name); |
| 4951 | } |
| 4952 | |
| 4953 | void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids) |
| 4954 | { |
| 4955 | for (int i = 0; i < n; i++) |
| 4956 | { |
| 4957 | GLuint transformFeedback = ids[i]; |
| 4958 | if (transformFeedback == 0) |
| 4959 | { |
| 4960 | continue; |
| 4961 | } |
| 4962 | |
| 4963 | TransformFeedback *transformFeedbackObject = nullptr; |
| 4964 | if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject)) |
| 4965 | { |
| 4966 | if (transformFeedbackObject != nullptr) |
| 4967 | { |
| 4968 | detachTransformFeedback(transformFeedback); |
| 4969 | transformFeedbackObject->release(this); |
| 4970 | } |
| 4971 | |
| 4972 | mTransformFeedbackHandleAllocator.release(transformFeedback); |
| 4973 | } |
| 4974 | } |
| 4975 | } |
| 4976 | |
| 4977 | void Context::genTransformFeedbacks(GLsizei n, GLuint *ids) |
| 4978 | { |
| 4979 | for (int i = 0; i < n; i++) |
| 4980 | { |
| 4981 | GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate(); |
| 4982 | mTransformFeedbackMap.assign(transformFeedback, nullptr); |
| 4983 | ids[i] = transformFeedback; |
| 4984 | } |
| 4985 | } |
| 4986 | |
| 4987 | bool Context::isTransformFeedback(GLuint id) |
| 4988 | { |
| 4989 | if (id == 0) |
| 4990 | { |
| 4991 | // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback |
| 4992 | // returns FALSE |
| 4993 | return GL_FALSE; |
| 4994 | } |
| 4995 | |
| 4996 | const TransformFeedback *transformFeedback = getTransformFeedback(id); |
| 4997 | return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE); |
| 4998 | } |
| 4999 | |
| 5000 | void Context::pauseTransformFeedback() |
| 5001 | { |
| 5002 | TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback(); |
| 5003 | transformFeedback->pause(); |
| 5004 | } |
| 5005 | |
| 5006 | void Context::resumeTransformFeedback() |
| 5007 | { |
| 5008 | TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback(); |
| 5009 | transformFeedback->resume(); |
| 5010 | } |
| 5011 | |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 5012 | void Context::getUniformuiv(GLuint program, GLint location, GLuint *params) |
| 5013 | { |
| 5014 | const Program *programObject = getProgram(program); |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 5015 | programObject->getUniformuiv(this, location, params); |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 5016 | } |
| 5017 | |
| 5018 | GLint Context::getFragDataLocation(GLuint program, const GLchar *name) |
| 5019 | { |
| 5020 | const Program *programObject = getProgram(program); |
| 5021 | return programObject->getFragDataLocation(name); |
| 5022 | } |
| 5023 | |
| 5024 | void Context::getUniformIndices(GLuint program, |
| 5025 | GLsizei uniformCount, |
| 5026 | const GLchar *const *uniformNames, |
| 5027 | GLuint *uniformIndices) |
| 5028 | { |
| 5029 | const Program *programObject = getProgram(program); |
| 5030 | if (!programObject->isLinked()) |
| 5031 | { |
| 5032 | for (int uniformId = 0; uniformId < uniformCount; uniformId++) |
| 5033 | { |
| 5034 | uniformIndices[uniformId] = GL_INVALID_INDEX; |
| 5035 | } |
| 5036 | } |
| 5037 | else |
| 5038 | { |
| 5039 | for (int uniformId = 0; uniformId < uniformCount; uniformId++) |
| 5040 | { |
| 5041 | uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]); |
| 5042 | } |
| 5043 | } |
| 5044 | } |
| 5045 | |
| 5046 | void Context::getActiveUniformsiv(GLuint program, |
| 5047 | GLsizei uniformCount, |
| 5048 | const GLuint *uniformIndices, |
| 5049 | GLenum pname, |
| 5050 | GLint *params) |
| 5051 | { |
| 5052 | const Program *programObject = getProgram(program); |
| 5053 | for (int uniformId = 0; uniformId < uniformCount; uniformId++) |
| 5054 | { |
| 5055 | const GLuint index = uniformIndices[uniformId]; |
jchen10 | baf5d94 | 2017-08-28 20:45:48 +0800 | [diff] [blame] | 5056 | params[uniformId] = GetUniformResourceProperty(programObject, index, pname); |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 5057 | } |
| 5058 | } |
| 5059 | |
| 5060 | GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName) |
| 5061 | { |
| 5062 | const Program *programObject = getProgram(program); |
| 5063 | return programObject->getUniformBlockIndex(uniformBlockName); |
| 5064 | } |
| 5065 | |
| 5066 | void Context::getActiveUniformBlockiv(GLuint program, |
| 5067 | GLuint uniformBlockIndex, |
| 5068 | GLenum pname, |
| 5069 | GLint *params) |
| 5070 | { |
| 5071 | const Program *programObject = getProgram(program); |
| 5072 | QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params); |
| 5073 | } |
| 5074 | |
| 5075 | void Context::getActiveUniformBlockName(GLuint program, |
| 5076 | GLuint uniformBlockIndex, |
| 5077 | GLsizei bufSize, |
| 5078 | GLsizei *length, |
| 5079 | GLchar *uniformBlockName) |
| 5080 | { |
| 5081 | const Program *programObject = getProgram(program); |
| 5082 | programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName); |
| 5083 | } |
| 5084 | |
| 5085 | void Context::uniformBlockBinding(GLuint program, |
| 5086 | GLuint uniformBlockIndex, |
| 5087 | GLuint uniformBlockBinding) |
| 5088 | { |
| 5089 | Program *programObject = getProgram(program); |
| 5090 | programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding); |
| 5091 | } |
| 5092 | |
Jamie Madill | 7f0c5a4 | 2017-08-26 22:43:26 -0400 | [diff] [blame] | 5093 | GLsync Context::fenceSync(GLenum condition, GLbitfield flags) |
| 5094 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 5095 | GLuint handle = mState.mSyncs->createSync(mImplementation.get()); |
| 5096 | GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle)); |
Jamie Madill | 7f0c5a4 | 2017-08-26 22:43:26 -0400 | [diff] [blame] | 5097 | |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 5098 | Sync *syncObject = getSync(syncHandle); |
| 5099 | Error error = syncObject->set(condition, flags); |
Jamie Madill | 7f0c5a4 | 2017-08-26 22:43:26 -0400 | [diff] [blame] | 5100 | if (error.isError()) |
| 5101 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 5102 | deleteSync(syncHandle); |
Jamie Madill | 7f0c5a4 | 2017-08-26 22:43:26 -0400 | [diff] [blame] | 5103 | handleError(error); |
| 5104 | return nullptr; |
| 5105 | } |
| 5106 | |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 5107 | return syncHandle; |
Jamie Madill | 7f0c5a4 | 2017-08-26 22:43:26 -0400 | [diff] [blame] | 5108 | } |
| 5109 | |
| 5110 | GLboolean Context::isSync(GLsync sync) |
| 5111 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 5112 | return (getSync(sync) != nullptr); |
Jamie Madill | 7f0c5a4 | 2017-08-26 22:43:26 -0400 | [diff] [blame] | 5113 | } |
| 5114 | |
| 5115 | GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout) |
| 5116 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 5117 | Sync *syncObject = getSync(sync); |
Jamie Madill | 7f0c5a4 | 2017-08-26 22:43:26 -0400 | [diff] [blame] | 5118 | |
| 5119 | GLenum result = GL_WAIT_FAILED; |
| 5120 | handleError(syncObject->clientWait(flags, timeout, &result)); |
| 5121 | return result; |
| 5122 | } |
| 5123 | |
| 5124 | void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout) |
| 5125 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 5126 | Sync *syncObject = getSync(sync); |
Jamie Madill | 7f0c5a4 | 2017-08-26 22:43:26 -0400 | [diff] [blame] | 5127 | handleError(syncObject->serverWait(flags, timeout)); |
| 5128 | } |
| 5129 | |
| 5130 | void Context::getInteger64v(GLenum pname, GLint64 *params) |
| 5131 | { |
| 5132 | GLenum nativeType = GL_NONE; |
| 5133 | unsigned int numParams = 0; |
| 5134 | getQueryParameterInfo(pname, &nativeType, &numParams); |
| 5135 | |
| 5136 | if (nativeType == GL_INT_64_ANGLEX) |
| 5137 | { |
| 5138 | getInteger64vImpl(pname, params); |
| 5139 | } |
| 5140 | else |
| 5141 | { |
| 5142 | CastStateValues(this, nativeType, pname, numParams, params); |
| 5143 | } |
| 5144 | } |
| 5145 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 5146 | void Context::getBufferParameteri64v(BufferBinding target, GLenum pname, GLint64 *params) |
Jamie Madill | 3ef140a | 2017-08-26 23:11:21 -0400 | [diff] [blame] | 5147 | { |
| 5148 | Buffer *buffer = mGLState.getTargetBuffer(target); |
| 5149 | QueryBufferParameteri64v(buffer, pname, params); |
| 5150 | } |
| 5151 | |
| 5152 | void Context::genSamplers(GLsizei count, GLuint *samplers) |
| 5153 | { |
| 5154 | for (int i = 0; i < count; i++) |
| 5155 | { |
| 5156 | samplers[i] = mState.mSamplers->createSampler(); |
| 5157 | } |
| 5158 | } |
| 5159 | |
| 5160 | void Context::deleteSamplers(GLsizei count, const GLuint *samplers) |
| 5161 | { |
| 5162 | for (int i = 0; i < count; i++) |
| 5163 | { |
| 5164 | GLuint sampler = samplers[i]; |
| 5165 | |
| 5166 | if (mState.mSamplers->getSampler(sampler)) |
| 5167 | { |
| 5168 | detachSampler(sampler); |
| 5169 | } |
| 5170 | |
| 5171 | mState.mSamplers->deleteObject(this, sampler); |
| 5172 | } |
| 5173 | } |
| 5174 | |
| 5175 | void Context::getInternalformativ(GLenum target, |
| 5176 | GLenum internalformat, |
| 5177 | GLenum pname, |
| 5178 | GLsizei bufSize, |
| 5179 | GLint *params) |
| 5180 | { |
| 5181 | const TextureCaps &formatCaps = mTextureCaps.get(internalformat); |
| 5182 | QueryInternalFormativ(formatCaps, pname, bufSize, params); |
| 5183 | } |
| 5184 | |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 5185 | void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value) |
| 5186 | { |
| 5187 | Program *programObject = getProgram(program); |
| 5188 | ASSERT(programObject); |
| 5189 | if (programObject->setUniform1iv(location, count, value) == |
| 5190 | Program::SetUniformResult::SamplerChanged) |
| 5191 | { |
| 5192 | mGLState.setObjectDirty(GL_PROGRAM); |
| 5193 | } |
| 5194 | } |
| 5195 | |
| 5196 | void Context::onTextureChange(const Texture *texture) |
| 5197 | { |
| 5198 | // Conservatively assume all textures are dirty. |
| 5199 | // TODO(jmadill): More fine-grained update. |
| 5200 | mGLState.setObjectDirty(GL_TEXTURE); |
| 5201 | } |
| 5202 | |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 5203 | void Context::genProgramPipelines(GLsizei count, GLuint *pipelines) |
| 5204 | { |
| 5205 | for (int i = 0; i < count; i++) |
| 5206 | { |
| 5207 | pipelines[i] = createProgramPipeline(); |
| 5208 | } |
| 5209 | } |
| 5210 | |
| 5211 | void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines) |
| 5212 | { |
| 5213 | for (int i = 0; i < count; i++) |
| 5214 | { |
| 5215 | if (pipelines[i] != 0) |
| 5216 | { |
| 5217 | deleteProgramPipeline(pipelines[i]); |
| 5218 | } |
| 5219 | } |
| 5220 | } |
| 5221 | |
| 5222 | GLboolean Context::isProgramPipeline(GLuint pipeline) |
| 5223 | { |
| 5224 | if (pipeline == 0) |
| 5225 | { |
| 5226 | return GL_FALSE; |
| 5227 | } |
| 5228 | |
| 5229 | return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE); |
| 5230 | } |
| 5231 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 5232 | } // namespace gl |