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 | b929397 | 2015-02-19 11:07:54 -0500 | [diff] [blame] | 12 | #include <iterator> |
| 13 | #include <sstream> |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 14 | #include <string.h> |
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 | 9dd0cf0 | 2014-11-24 11:38:51 -0500 | [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" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 29 | #include "libANGLE/Query.h" |
Jamie Madill | b929397 | 2015-02-19 11:07:54 -0500 | [diff] [blame] | 30 | #include "libANGLE/Renderbuffer.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 31 | #include "libANGLE/ResourceManager.h" |
| 32 | #include "libANGLE/Sampler.h" |
Jamie Madill | 9dd0cf0 | 2014-11-24 11:38:51 -0500 | [diff] [blame] | 33 | #include "libANGLE/Surface.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 34 | #include "libANGLE/Texture.h" |
| 35 | #include "libANGLE/TransformFeedback.h" |
| 36 | #include "libANGLE/VertexArray.h" |
| 37 | #include "libANGLE/formatutils.h" |
| 38 | #include "libANGLE/validationES.h" |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 39 | #include "libANGLE/Workarounds.h" |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 40 | #include "libANGLE/renderer/ContextImpl.h" |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 41 | #include "libANGLE/renderer/EGLImplFactory.h" |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 42 | #include "libANGLE/queryconversions.h" |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 43 | #include "libANGLE/queryutils.h" |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 44 | |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 45 | namespace |
| 46 | { |
| 47 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 48 | template <typename T> |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 49 | std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager, |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 50 | GLsizei numPaths, |
| 51 | const void *paths, |
| 52 | GLuint pathBase) |
| 53 | { |
| 54 | std::vector<gl::Path *> ret; |
| 55 | ret.reserve(numPaths); |
| 56 | |
| 57 | const auto *nameArray = static_cast<const T *>(paths); |
| 58 | |
| 59 | for (GLsizei i = 0; i < numPaths; ++i) |
| 60 | { |
| 61 | const GLuint pathName = nameArray[i] + pathBase; |
| 62 | |
| 63 | ret.push_back(resourceManager.getPath(pathName)); |
| 64 | } |
| 65 | |
| 66 | return ret; |
| 67 | } |
| 68 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 69 | std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager, |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 70 | GLsizei numPaths, |
| 71 | GLenum pathNameType, |
| 72 | const void *paths, |
| 73 | GLuint pathBase) |
| 74 | { |
| 75 | switch (pathNameType) |
| 76 | { |
| 77 | case GL_UNSIGNED_BYTE: |
| 78 | return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase); |
| 79 | |
| 80 | case GL_BYTE: |
| 81 | return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase); |
| 82 | |
| 83 | case GL_UNSIGNED_SHORT: |
| 84 | return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase); |
| 85 | |
| 86 | case GL_SHORT: |
| 87 | return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase); |
| 88 | |
| 89 | case GL_UNSIGNED_INT: |
| 90 | return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase); |
| 91 | |
| 92 | case GL_INT: |
| 93 | return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase); |
| 94 | } |
| 95 | |
| 96 | UNREACHABLE(); |
| 97 | return std::vector<gl::Path *>(); |
| 98 | } |
| 99 | |
| 100 | template <typename T> |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 101 | gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 102 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 103 | ASSERT(query != nullptr); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 104 | |
| 105 | switch (pname) |
| 106 | { |
| 107 | case GL_QUERY_RESULT_EXT: |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 108 | return query->getResult(params); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 109 | case GL_QUERY_RESULT_AVAILABLE_EXT: |
| 110 | { |
| 111 | bool available; |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 112 | gl::Error error = query->isResultAvailable(&available); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 113 | if (!error.isError()) |
| 114 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 115 | *params = gl::ConvertFromGLboolean<T>(available); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 116 | } |
| 117 | return error; |
| 118 | } |
| 119 | default: |
| 120 | UNREACHABLE(); |
| 121 | return gl::Error(GL_INVALID_OPERATION, "Unreachable Error"); |
| 122 | } |
| 123 | } |
| 124 | |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 125 | void MarkTransformFeedbackBufferUsage(gl::TransformFeedback *transformFeedback) |
| 126 | { |
Geoff Lang | 1a68346 | 2015-09-29 15:09:59 -0400 | [diff] [blame] | 127 | if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused()) |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 128 | { |
| 129 | for (size_t tfBufferIndex = 0; tfBufferIndex < transformFeedback->getIndexedBufferCount(); |
| 130 | tfBufferIndex++) |
| 131 | { |
| 132 | const OffsetBindingPointer<gl::Buffer> &buffer = |
| 133 | transformFeedback->getIndexedBuffer(tfBufferIndex); |
| 134 | if (buffer.get() != nullptr) |
| 135 | { |
| 136 | buffer->onTransformFeedback(); |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | } |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 141 | |
| 142 | // Attribute map queries. |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 143 | EGLint GetClientMajorVersion(const egl::AttributeMap &attribs) |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 144 | { |
Ian Ewell | ec2c0c5 | 2016-04-05 13:46:26 -0400 | [diff] [blame] | 145 | return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1)); |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 146 | } |
| 147 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 148 | EGLint GetClientMinorVersion(const egl::AttributeMap &attribs) |
| 149 | { |
| 150 | return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0)); |
| 151 | } |
| 152 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 153 | gl::Version GetClientVersion(const egl::AttributeMap &attribs) |
| 154 | { |
| 155 | return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs)); |
| 156 | } |
| 157 | |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 158 | GLenum GetResetStrategy(const egl::AttributeMap &attribs) |
| 159 | { |
Ian Ewell | ec2c0c5 | 2016-04-05 13:46:26 -0400 | [diff] [blame] | 160 | EGLAttrib attrib = attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, |
| 161 | EGL_NO_RESET_NOTIFICATION_EXT); |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 162 | switch (attrib) |
| 163 | { |
| 164 | case EGL_NO_RESET_NOTIFICATION: |
| 165 | return GL_NO_RESET_NOTIFICATION_EXT; |
| 166 | case EGL_LOSE_CONTEXT_ON_RESET: |
| 167 | return GL_LOSE_CONTEXT_ON_RESET_EXT; |
| 168 | default: |
| 169 | UNREACHABLE(); |
| 170 | return GL_NONE; |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | bool GetRobustAccess(const egl::AttributeMap &attribs) |
| 175 | { |
Geoff Lang | 077f20a | 2016-11-01 10:08:02 -0400 | [diff] [blame] | 176 | return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) || |
| 177 | ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) != |
| 178 | 0); |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | bool GetDebug(const egl::AttributeMap &attribs) |
| 182 | { |
Geoff Lang | 077f20a | 2016-11-01 10:08:02 -0400 | [diff] [blame] | 183 | return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) || |
| 184 | ((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] | 185 | } |
| 186 | |
| 187 | bool GetNoError(const egl::AttributeMap &attribs) |
| 188 | { |
| 189 | return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE); |
| 190 | } |
| 191 | |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 192 | bool GetWebGLContext(const egl::AttributeMap &attribs) |
| 193 | { |
| 194 | return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE); |
| 195 | } |
| 196 | |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 197 | bool GetBindGeneratesResource(const egl::AttributeMap &attribs) |
| 198 | { |
| 199 | return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE); |
| 200 | } |
| 201 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 202 | std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label) |
| 203 | { |
| 204 | std::string labelName; |
| 205 | if (label != nullptr) |
| 206 | { |
| 207 | size_t labelLength = length < 0 ? strlen(label) : length; |
| 208 | labelName = std::string(label, labelLength); |
| 209 | } |
| 210 | return labelName; |
| 211 | } |
| 212 | |
| 213 | void GetObjectLabelBase(const std::string &objectLabel, |
| 214 | GLsizei bufSize, |
| 215 | GLsizei *length, |
| 216 | GLchar *label) |
| 217 | { |
| 218 | size_t writeLength = objectLabel.length(); |
| 219 | if (label != nullptr && bufSize > 0) |
| 220 | { |
| 221 | writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length()); |
| 222 | std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label); |
| 223 | label[writeLength] = '\0'; |
| 224 | } |
| 225 | |
| 226 | if (length != nullptr) |
| 227 | { |
| 228 | *length = static_cast<GLsizei>(writeLength); |
| 229 | } |
| 230 | } |
| 231 | |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 232 | } // anonymous namespace |
| 233 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 234 | namespace gl |
| 235 | { |
daniel@transgaming.com | ca1ac1f | 2013-01-11 04:13:05 +0000 | [diff] [blame] | 236 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 237 | Context::Context(rx::EGLImplFactory *implFactory, |
| 238 | const egl::Config *config, |
Corentin Wallez | 51706ea | 2015-08-07 14:39:22 -0400 | [diff] [blame] | 239 | const Context *shareContext, |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 240 | const egl::AttributeMap &attribs) |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 241 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 242 | : ValidationContext(shareContext, |
| 243 | GetClientVersion(attribs), |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 244 | &mGLState, |
Jamie Madill | f25855c | 2015-11-03 11:06:18 -0500 | [diff] [blame] | 245 | mCaps, |
| 246 | mTextureCaps, |
| 247 | mExtensions, |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 248 | mLimitations, |
| 249 | GetNoError(attribs)), |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 250 | mImplementation(implFactory->createContext(mState)), |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 251 | mCompiler(nullptr), |
Corentin Wallez | e3b10e8 | 2015-05-20 11:06:25 -0400 | [diff] [blame] | 252 | mConfig(config), |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 253 | mClientType(EGL_OPENGL_ES_API), |
| 254 | mHasBeenCurrent(false), |
| 255 | mContextLost(false), |
| 256 | mResetStatus(GL_NO_ERROR), |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 257 | mContextLostForced(false), |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 258 | mResetStrategy(GetResetStrategy(attribs)), |
| 259 | mRobustAccess(GetRobustAccess(attribs)), |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 260 | mCurrentSurface(nullptr), |
| 261 | mSurfacelessFramebuffer(nullptr) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 262 | { |
Geoff Lang | 077f20a | 2016-11-01 10:08:02 -0400 | [diff] [blame] | 263 | if (mRobustAccess) |
| 264 | { |
| 265 | UNIMPLEMENTED(); |
| 266 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 267 | |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 268 | initCaps(GetWebGLContext(attribs)); |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 269 | initWorkarounds(); |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 270 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 271 | mGLState.initialize(mCaps, mExtensions, getClientVersion(), GetDebug(attribs), |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 272 | GetBindGeneratesResource(attribs)); |
Régis Fénéon | 8310797 | 2015-02-05 12:57:44 +0100 | [diff] [blame] | 273 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 274 | mFenceNVHandleAllocator.setBaseHandle(0); |
Geoff Lang | 7dca186 | 2013-07-30 16:30:46 -0400 | [diff] [blame] | 275 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 276 | // [OpenGL ES 2.0.24] section 3.7 page 83: |
| 277 | // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have twodimensional |
| 278 | // and cube map texture state vectors respectively associated with them. |
| 279 | // In order that access to these initial textures not be lost, they are treated as texture |
| 280 | // objects all of whose names are 0. |
| 281 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 282 | Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D); |
Jamie Madill | dedd7b9 | 2014-11-05 16:30:36 -0500 | [diff] [blame] | 283 | mZeroTextures[GL_TEXTURE_2D].set(zeroTexture2D); |
Jamie Madill | dedd7b9 | 2014-11-05 16:30:36 -0500 | [diff] [blame] | 284 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 285 | Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, GL_TEXTURE_CUBE_MAP); |
Jamie Madill | dedd7b9 | 2014-11-05 16:30:36 -0500 | [diff] [blame] | 286 | mZeroTextures[GL_TEXTURE_CUBE_MAP].set(zeroTextureCube); |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 287 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 288 | if (getClientVersion() >= Version(3, 0)) |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 289 | { |
| 290 | // TODO: These could also be enabled via extension |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 291 | Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, GL_TEXTURE_3D); |
Jamie Madill | dedd7b9 | 2014-11-05 16:30:36 -0500 | [diff] [blame] | 292 | mZeroTextures[GL_TEXTURE_3D].set(zeroTexture3D); |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 293 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 294 | Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_ARRAY); |
Jamie Madill | dedd7b9 | 2014-11-05 16:30:36 -0500 | [diff] [blame] | 295 | mZeroTextures[GL_TEXTURE_2D_ARRAY].set(zeroTexture2DArray); |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 296 | } |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 297 | if (getClientVersion() >= Version(3, 1)) |
| 298 | { |
| 299 | Texture *zeroTexture2DMultisample = |
| 300 | new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_MULTISAMPLE); |
| 301 | mZeroTextures[GL_TEXTURE_2D_MULTISAMPLE].set(zeroTexture2DMultisample); |
| 302 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 303 | |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 304 | if (mExtensions.eglImageExternal || mExtensions.eglStreamConsumerExternal) |
| 305 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 306 | Texture *zeroTextureExternal = |
| 307 | new Texture(mImplementation.get(), 0, GL_TEXTURE_EXTERNAL_OES); |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 308 | mZeroTextures[GL_TEXTURE_EXTERNAL_OES].set(zeroTextureExternal); |
| 309 | } |
| 310 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 311 | mGLState.initializeZeroTextures(mZeroTextures); |
Jamie Madill | e6382c3 | 2014-11-07 15:05:26 -0500 | [diff] [blame] | 312 | |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 313 | bindVertexArray(0); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 314 | bindArrayBuffer(0); |
Jiajia Qin | 9d7d0b1 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 315 | bindDrawIndirectBuffer(0); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 316 | bindElementArrayBuffer(0); |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 317 | |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 318 | bindRenderbuffer(GL_RENDERBUFFER, 0); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 319 | |
shannon.woods%transgaming.com@gtempaccount.com | 667a29c | 2013-04-13 03:39:04 +0000 | [diff] [blame] | 320 | bindGenericUniformBuffer(0); |
Geoff Lang | 4dc3af0 | 2016-11-18 14:09:27 -0500 | [diff] [blame] | 321 | for (unsigned int i = 0; i < mCaps.maxUniformBufferBindings; i++) |
shannon.woods%transgaming.com@gtempaccount.com | 667a29c | 2013-04-13 03:39:04 +0000 | [diff] [blame] | 322 | { |
| 323 | bindIndexedUniformBuffer(0, i, 0, -1); |
| 324 | } |
| 325 | |
shannon.woods%transgaming.com@gtempaccount.com | 5117188 | 2013-04-13 03:39:10 +0000 | [diff] [blame] | 326 | bindCopyReadBuffer(0); |
| 327 | bindCopyWriteBuffer(0); |
shannon.woods%transgaming.com@gtempaccount.com | c926e5f | 2013-04-13 03:39:18 +0000 | [diff] [blame] | 328 | bindPixelPackBuffer(0); |
| 329 | bindPixelUnpackBuffer(0); |
shannon.woods%transgaming.com@gtempaccount.com | 5117188 | 2013-04-13 03:39:10 +0000 | [diff] [blame] | 330 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 331 | if (getClientVersion() >= Version(3, 0)) |
Geoff Lang | 1a68346 | 2015-09-29 15:09:59 -0400 | [diff] [blame] | 332 | { |
| 333 | // [OpenGL ES 3.0.2] section 2.14.1 pg 85: |
| 334 | // In the initial state, a default transform feedback object is bound and treated as |
| 335 | // a transform feedback object with a name of zero. That object is bound any time |
| 336 | // BindTransformFeedback is called with id of zero |
Geoff Lang | 1a68346 | 2015-09-29 15:09:59 -0400 | [diff] [blame] | 337 | bindTransformFeedback(0); |
| 338 | } |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 339 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 340 | mCompiler = new Compiler(mImplementation.get(), mState); |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 341 | |
| 342 | // Initialize dirty bit masks |
| 343 | // TODO(jmadill): additional ES3 state |
| 344 | mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_ALIGNMENT); |
| 345 | mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_ROW_LENGTH); |
| 346 | mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_IMAGE_HEIGHT); |
| 347 | mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_IMAGES); |
| 348 | mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_ROWS); |
| 349 | mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_PIXELS); |
Corentin Wallez | bbd663a | 2016-04-20 17:49:17 -0400 | [diff] [blame] | 350 | mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING); |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 351 | // No dirty objects. |
| 352 | |
| 353 | // Readpixels uses the pack state and read FBO |
| 354 | mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_ALIGNMENT); |
| 355 | mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_REVERSE_ROW_ORDER); |
| 356 | mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_ROW_LENGTH); |
| 357 | mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_SKIP_ROWS); |
| 358 | mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_SKIP_PIXELS); |
Corentin Wallez | bbd663a | 2016-04-20 17:49:17 -0400 | [diff] [blame] | 359 | mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING); |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 360 | mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER); |
| 361 | |
| 362 | mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED); |
| 363 | mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED); |
| 364 | mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR); |
| 365 | mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT); |
| 366 | mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR); |
| 367 | mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH); |
| 368 | mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL); |
| 369 | mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK); |
| 370 | mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK); |
| 371 | mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT); |
| 372 | mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK); |
| 373 | mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
| 374 | |
| 375 | mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED); |
| 376 | mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR); |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 377 | mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB); |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 378 | mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER); |
| 379 | mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 380 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 381 | handleError(mImplementation->initialize()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | Context::~Context() |
| 385 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 386 | mGLState.reset(); |
Geoff Lang | 2132941 | 2014-12-02 20:50:30 +0000 | [diff] [blame] | 387 | |
Corentin Wallez | 80b2411 | 2015-08-25 16:41:57 -0400 | [diff] [blame] | 388 | for (auto fence : mFenceNVMap) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 389 | { |
Corentin Wallez | 80b2411 | 2015-08-25 16:41:57 -0400 | [diff] [blame] | 390 | SafeDelete(fence.second); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 391 | } |
| 392 | |
Corentin Wallez | 80b2411 | 2015-08-25 16:41:57 -0400 | [diff] [blame] | 393 | for (auto query : mQueryMap) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 394 | { |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 395 | if (query.second != nullptr) |
| 396 | { |
| 397 | query.second->release(); |
| 398 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 399 | } |
| 400 | |
Corentin Wallez | 80b2411 | 2015-08-25 16:41:57 -0400 | [diff] [blame] | 401 | for (auto vertexArray : mVertexArrayMap) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 402 | { |
Corentin Wallez | 80b2411 | 2015-08-25 16:41:57 -0400 | [diff] [blame] | 403 | SafeDelete(vertexArray.second); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 404 | } |
| 405 | |
Corentin Wallez | 80b2411 | 2015-08-25 16:41:57 -0400 | [diff] [blame] | 406 | for (auto transformFeedback : mTransformFeedbackMap) |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 407 | { |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 408 | if (transformFeedback.second != nullptr) |
| 409 | { |
| 410 | transformFeedback.second->release(); |
| 411 | } |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 412 | } |
| 413 | |
Jamie Madill | dedd7b9 | 2014-11-05 16:30:36 -0500 | [diff] [blame] | 414 | for (auto &zeroTexture : mZeroTextures) |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 415 | { |
Jamie Madill | dedd7b9 | 2014-11-05 16:30:36 -0500 | [diff] [blame] | 416 | zeroTexture.second.set(NULL); |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 417 | } |
| 418 | mZeroTextures.clear(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 419 | |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 420 | SafeDelete(mSurfacelessFramebuffer); |
| 421 | |
Corentin Wallez | 51706ea | 2015-08-07 14:39:22 -0400 | [diff] [blame] | 422 | if (mCurrentSurface != nullptr) |
| 423 | { |
| 424 | releaseSurface(); |
| 425 | } |
| 426 | |
Geoff Lang | 492a7e4 | 2014-11-05 13:27:06 -0500 | [diff] [blame] | 427 | SafeDelete(mCompiler); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 428 | } |
| 429 | |
daniel@transgaming.com | ad62987 | 2012-11-28 19:32:06 +0000 | [diff] [blame] | 430 | void Context::makeCurrent(egl::Surface *surface) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 431 | { |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 432 | if (!mHasBeenCurrent) |
| 433 | { |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 434 | initRendererString(); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 435 | initVersionStrings(); |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 436 | initExtensionStrings(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 437 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 438 | mGLState.setViewportParams(0, 0, surface->getWidth(), surface->getHeight()); |
| 439 | mGLState.setScissorParams(0, 0, surface->getWidth(), surface->getHeight()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 440 | |
| 441 | mHasBeenCurrent = true; |
| 442 | } |
| 443 | |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 444 | // TODO(jmadill): Rework this when we support ContextImpl |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 445 | mGLState.setAllDirtyBits(); |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 446 | |
Corentin Wallez | 51706ea | 2015-08-07 14:39:22 -0400 | [diff] [blame] | 447 | if (mCurrentSurface) |
| 448 | { |
| 449 | releaseSurface(); |
| 450 | } |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 451 | |
| 452 | Framebuffer *newDefault = nullptr; |
| 453 | if (surface != nullptr) |
| 454 | { |
| 455 | surface->setIsCurrent(true); |
| 456 | mCurrentSurface = surface; |
| 457 | newDefault = surface->getDefaultFramebuffer(); |
| 458 | } |
| 459 | else |
| 460 | { |
| 461 | if (mSurfacelessFramebuffer == nullptr) |
| 462 | { |
| 463 | mSurfacelessFramebuffer = new Framebuffer(mImplementation.get()); |
| 464 | } |
| 465 | |
| 466 | newDefault = mSurfacelessFramebuffer; |
| 467 | } |
Jamie Madill | 18fdcbc | 2015-08-19 18:12:44 +0000 | [diff] [blame] | 468 | |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 469 | // Update default framebuffer, the binding of the previous default |
| 470 | // framebuffer (or lack of) will have a nullptr. |
Jamie Madill | c1c1cdc | 2015-04-30 09:42:26 -0400 | [diff] [blame] | 471 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 472 | if (mGLState.getReadFramebuffer() == nullptr) |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 473 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 474 | mGLState.setReadFramebufferBinding(newDefault); |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 475 | } |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 476 | if (mGLState.getDrawFramebuffer() == nullptr) |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 477 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 478 | mGLState.setDrawFramebufferBinding(newDefault); |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 479 | } |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame^] | 480 | mState.mFramebuffers->setDefaultFramebuffer(newDefault); |
Jamie Madill | c1c1cdc | 2015-04-30 09:42:26 -0400 | [diff] [blame] | 481 | } |
Ian Ewell | 292f005 | 2016-02-04 10:37:32 -0500 | [diff] [blame] | 482 | |
| 483 | // Notify the renderer of a context switch |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 484 | mImplementation->onMakeCurrent(mState); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 485 | } |
| 486 | |
Jamie Madill | 77a72f6 | 2015-04-14 11:18:32 -0400 | [diff] [blame] | 487 | void Context::releaseSurface() |
| 488 | { |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 489 | ASSERT(mCurrentSurface != nullptr); |
| 490 | |
| 491 | // Remove the default framebuffer |
Corentin Wallez | 51706ea | 2015-08-07 14:39:22 -0400 | [diff] [blame] | 492 | { |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 493 | Framebuffer *currentDefault = mCurrentSurface->getDefaultFramebuffer(); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 494 | if (mGLState.getReadFramebuffer() == currentDefault) |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 495 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 496 | mGLState.setReadFramebufferBinding(nullptr); |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 497 | } |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 498 | if (mGLState.getDrawFramebuffer() == currentDefault) |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 499 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 500 | mGLState.setDrawFramebufferBinding(nullptr); |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 501 | } |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame^] | 502 | mState.mFramebuffers->setDefaultFramebuffer(nullptr); |
Corentin Wallez | 51706ea | 2015-08-07 14:39:22 -0400 | [diff] [blame] | 503 | } |
| 504 | |
Corentin Wallez | 51706ea | 2015-08-07 14:39:22 -0400 | [diff] [blame] | 505 | mCurrentSurface->setIsCurrent(false); |
| 506 | mCurrentSurface = nullptr; |
Jamie Madill | 77a72f6 | 2015-04-14 11:18:32 -0400 | [diff] [blame] | 507 | } |
| 508 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 509 | GLuint Context::createBuffer() |
| 510 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 511 | return mState.mBuffers->createBuffer(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 512 | } |
| 513 | |
| 514 | GLuint Context::createProgram() |
| 515 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 516 | return mState.mShaderPrograms->createProgram(mImplementation.get()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | GLuint Context::createShader(GLenum type) |
| 520 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 521 | return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | GLuint Context::createTexture() |
| 525 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 526 | return mState.mTextures->createTexture(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 527 | } |
| 528 | |
| 529 | GLuint Context::createRenderbuffer() |
| 530 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 531 | return mState.mRenderbuffers->createRenderbuffer(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 532 | } |
| 533 | |
Geoff Lang | 882033e | 2014-09-30 11:26:07 -0400 | [diff] [blame] | 534 | GLsync Context::createFenceSync() |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame] | 535 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 536 | GLuint handle = mState.mFenceSyncs->createFenceSync(mImplementation.get()); |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame] | 537 | |
Cooper Partin | d8e62a3 | 2015-01-29 15:21:25 -0800 | [diff] [blame] | 538 | return reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle)); |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame] | 539 | } |
| 540 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 541 | GLuint Context::createPaths(GLsizei range) |
| 542 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 543 | auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 544 | if (resultOrError.isError()) |
| 545 | { |
| 546 | handleError(resultOrError.getError()); |
| 547 | return 0; |
| 548 | } |
| 549 | return resultOrError.getResult(); |
| 550 | } |
| 551 | |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 552 | GLuint Context::createVertexArray() |
| 553 | { |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 554 | GLuint vertexArray = mVertexArrayHandleAllocator.allocate(); |
| 555 | mVertexArrayMap[vertexArray] = nullptr; |
| 556 | return vertexArray; |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 557 | } |
| 558 | |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 559 | GLuint Context::createSampler() |
| 560 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 561 | return mState.mSamplers->createSampler(); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 562 | } |
| 563 | |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 564 | GLuint Context::createTransformFeedback() |
| 565 | { |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 566 | GLuint transformFeedback = mTransformFeedbackAllocator.allocate(); |
| 567 | mTransformFeedbackMap[transformFeedback] = nullptr; |
| 568 | return transformFeedback; |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 569 | } |
| 570 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 571 | // Returns an unused framebuffer name |
| 572 | GLuint Context::createFramebuffer() |
| 573 | { |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame^] | 574 | return mState.mFramebuffers->createFramebuffer(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 575 | } |
| 576 | |
Jamie Madill | 33dc843 | 2013-07-26 11:55:05 -0400 | [diff] [blame] | 577 | GLuint Context::createFenceNV() |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 578 | { |
Jamie Madill | 33dc843 | 2013-07-26 11:55:05 -0400 | [diff] [blame] | 579 | GLuint handle = mFenceNVHandleAllocator.allocate(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 580 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 581 | mFenceNVMap[handle] = new FenceNV(mImplementation->createFenceNV()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 582 | |
| 583 | return handle; |
| 584 | } |
| 585 | |
| 586 | // Returns an unused query name |
| 587 | GLuint Context::createQuery() |
| 588 | { |
| 589 | GLuint handle = mQueryHandleAllocator.allocate(); |
| 590 | |
| 591 | mQueryMap[handle] = NULL; |
| 592 | |
| 593 | return handle; |
| 594 | } |
| 595 | |
| 596 | void Context::deleteBuffer(GLuint buffer) |
| 597 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 598 | if (mState.mBuffers->getBuffer(buffer)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 599 | { |
| 600 | detachBuffer(buffer); |
| 601 | } |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 602 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 603 | mState.mBuffers->deleteBuffer(buffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 604 | } |
| 605 | |
| 606 | void Context::deleteShader(GLuint shader) |
| 607 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 608 | mState.mShaderPrograms->deleteShader(shader); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | void Context::deleteProgram(GLuint program) |
| 612 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 613 | mState.mShaderPrograms->deleteProgram(program); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | void Context::deleteTexture(GLuint texture) |
| 617 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 618 | if (mState.mTextures->getTexture(texture)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 619 | { |
| 620 | detachTexture(texture); |
| 621 | } |
| 622 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 623 | mState.mTextures->deleteTexture(texture); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | void Context::deleteRenderbuffer(GLuint renderbuffer) |
| 627 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 628 | if (mState.mRenderbuffers->getRenderbuffer(renderbuffer)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 629 | { |
| 630 | detachRenderbuffer(renderbuffer); |
| 631 | } |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 632 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 633 | mState.mRenderbuffers->deleteRenderbuffer(renderbuffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 634 | } |
| 635 | |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame] | 636 | void Context::deleteFenceSync(GLsync fenceSync) |
| 637 | { |
| 638 | // The spec specifies the underlying Fence object is not deleted until all current |
| 639 | // wait commands finish. However, since the name becomes invalid, we cannot query the fence, |
| 640 | // and since our API is currently designed for being called from a single thread, we can delete |
| 641 | // the fence immediately. |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 642 | mState.mFenceSyncs->deleteFenceSync( |
| 643 | static_cast<GLuint>(reinterpret_cast<uintptr_t>(fenceSync))); |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame] | 644 | } |
| 645 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 646 | void Context::deletePaths(GLuint first, GLsizei range) |
| 647 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 648 | mState.mPaths->deletePaths(first, range); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | bool Context::hasPathData(GLuint path) const |
| 652 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 653 | const auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 654 | if (pathObj == nullptr) |
| 655 | return false; |
| 656 | |
| 657 | return pathObj->hasPathData(); |
| 658 | } |
| 659 | |
| 660 | bool Context::hasPath(GLuint path) const |
| 661 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 662 | return mState.mPaths->hasPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | void Context::setPathCommands(GLuint path, |
| 666 | GLsizei numCommands, |
| 667 | const GLubyte *commands, |
| 668 | GLsizei numCoords, |
| 669 | GLenum coordType, |
| 670 | const void *coords) |
| 671 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 672 | auto *pathObject = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 673 | |
| 674 | handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords)); |
| 675 | } |
| 676 | |
| 677 | void Context::setPathParameterf(GLuint path, GLenum pname, GLfloat value) |
| 678 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 679 | auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 680 | |
| 681 | switch (pname) |
| 682 | { |
| 683 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 684 | pathObj->setStrokeWidth(value); |
| 685 | break; |
| 686 | case GL_PATH_END_CAPS_CHROMIUM: |
| 687 | pathObj->setEndCaps(static_cast<GLenum>(value)); |
| 688 | break; |
| 689 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 690 | pathObj->setJoinStyle(static_cast<GLenum>(value)); |
| 691 | break; |
| 692 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 693 | pathObj->setMiterLimit(value); |
| 694 | break; |
| 695 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 696 | pathObj->setStrokeBound(value); |
| 697 | break; |
| 698 | default: |
| 699 | UNREACHABLE(); |
| 700 | break; |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value) const |
| 705 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 706 | const auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 707 | |
| 708 | switch (pname) |
| 709 | { |
| 710 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 711 | *value = pathObj->getStrokeWidth(); |
| 712 | break; |
| 713 | case GL_PATH_END_CAPS_CHROMIUM: |
| 714 | *value = static_cast<GLfloat>(pathObj->getEndCaps()); |
| 715 | break; |
| 716 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 717 | *value = static_cast<GLfloat>(pathObj->getJoinStyle()); |
| 718 | break; |
| 719 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 720 | *value = pathObj->getMiterLimit(); |
| 721 | break; |
| 722 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 723 | *value = pathObj->getStrokeBound(); |
| 724 | break; |
| 725 | default: |
| 726 | UNREACHABLE(); |
| 727 | break; |
| 728 | } |
| 729 | } |
| 730 | |
| 731 | void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask) |
| 732 | { |
| 733 | mGLState.setPathStencilFunc(func, ref, mask); |
| 734 | } |
| 735 | |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 736 | void Context::deleteVertexArray(GLuint vertexArray) |
| 737 | { |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 738 | auto iter = mVertexArrayMap.find(vertexArray); |
| 739 | if (iter != mVertexArrayMap.end()) |
Geoff Lang | 50b3fe8 | 2015-12-08 14:49:12 +0000 | [diff] [blame] | 740 | { |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 741 | VertexArray *vertexArrayObject = iter->second; |
| 742 | if (vertexArrayObject != nullptr) |
| 743 | { |
| 744 | detachVertexArray(vertexArray); |
| 745 | delete vertexArrayObject; |
| 746 | } |
Geoff Lang | 50b3fe8 | 2015-12-08 14:49:12 +0000 | [diff] [blame] | 747 | |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 748 | mVertexArrayMap.erase(iter); |
| 749 | mVertexArrayHandleAllocator.release(vertexArray); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 750 | } |
| 751 | } |
| 752 | |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 753 | void Context::deleteSampler(GLuint sampler) |
| 754 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 755 | if (mState.mSamplers->getSampler(sampler)) |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 756 | { |
| 757 | detachSampler(sampler); |
| 758 | } |
| 759 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 760 | mState.mSamplers->deleteSampler(sampler); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 761 | } |
| 762 | |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 763 | void Context::deleteTransformFeedback(GLuint transformFeedback) |
| 764 | { |
Jamie Madill | 5fd0b2d | 2015-01-05 13:38:44 -0500 | [diff] [blame] | 765 | auto iter = mTransformFeedbackMap.find(transformFeedback); |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 766 | if (iter != mTransformFeedbackMap.end()) |
| 767 | { |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 768 | TransformFeedback *transformFeedbackObject = iter->second; |
| 769 | if (transformFeedbackObject != nullptr) |
| 770 | { |
| 771 | detachTransformFeedback(transformFeedback); |
| 772 | transformFeedbackObject->release(); |
| 773 | } |
| 774 | |
Geoff Lang | 50b3fe8 | 2015-12-08 14:49:12 +0000 | [diff] [blame] | 775 | mTransformFeedbackMap.erase(iter); |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 776 | mTransformFeedbackAllocator.release(transformFeedback); |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 777 | } |
| 778 | } |
| 779 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 780 | void Context::deleteFramebuffer(GLuint framebuffer) |
| 781 | { |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame^] | 782 | if (mState.mFramebuffers->getFramebuffer(framebuffer)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 783 | { |
| 784 | detachFramebuffer(framebuffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 785 | } |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame^] | 786 | |
| 787 | mState.mFramebuffers->deleteFramebuffer(framebuffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 788 | } |
| 789 | |
Jamie Madill | 33dc843 | 2013-07-26 11:55:05 -0400 | [diff] [blame] | 790 | void Context::deleteFenceNV(GLuint fence) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 791 | { |
Jamie Madill | 4e25a0d | 2016-03-08 13:53:03 -0500 | [diff] [blame] | 792 | auto fenceObject = mFenceNVMap.find(fence); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 793 | |
Jamie Madill | 33dc843 | 2013-07-26 11:55:05 -0400 | [diff] [blame] | 794 | if (fenceObject != mFenceNVMap.end()) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 795 | { |
Jamie Madill | 33dc843 | 2013-07-26 11:55:05 -0400 | [diff] [blame] | 796 | mFenceNVHandleAllocator.release(fenceObject->first); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 797 | delete fenceObject->second; |
Jamie Madill | 33dc843 | 2013-07-26 11:55:05 -0400 | [diff] [blame] | 798 | mFenceNVMap.erase(fenceObject); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 799 | } |
| 800 | } |
| 801 | |
| 802 | void Context::deleteQuery(GLuint query) |
| 803 | { |
Jamie Madill | 4e25a0d | 2016-03-08 13:53:03 -0500 | [diff] [blame] | 804 | auto queryObject = mQueryMap.find(query); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 805 | if (queryObject != mQueryMap.end()) |
| 806 | { |
| 807 | mQueryHandleAllocator.release(queryObject->first); |
| 808 | if (queryObject->second) |
| 809 | { |
| 810 | queryObject->second->release(); |
| 811 | } |
| 812 | mQueryMap.erase(queryObject); |
| 813 | } |
| 814 | } |
| 815 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 816 | Buffer *Context::getBuffer(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.mBuffers->getBuffer(handle); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 819 | } |
| 820 | |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 821 | Texture *Context::getTexture(GLuint handle) const |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 822 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 823 | return mState.mTextures->getTexture(handle); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 824 | } |
| 825 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 826 | Renderbuffer *Context::getRenderbuffer(GLuint handle) const |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 827 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 828 | return mState.mRenderbuffers->getRenderbuffer(handle); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 829 | } |
| 830 | |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame] | 831 | FenceSync *Context::getFenceSync(GLsync handle) const |
| 832 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 833 | return mState.mFenceSyncs->getFenceSync( |
| 834 | static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle))); |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame] | 835 | } |
| 836 | |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 837 | VertexArray *Context::getVertexArray(GLuint handle) const |
| 838 | { |
| 839 | auto vertexArray = mVertexArrayMap.find(handle); |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 840 | return (vertexArray != mVertexArrayMap.end()) ? vertexArray->second : nullptr; |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 841 | } |
| 842 | |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 843 | Sampler *Context::getSampler(GLuint handle) const |
| 844 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 845 | return mState.mSamplers->getSampler(handle); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 846 | } |
| 847 | |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 848 | TransformFeedback *Context::getTransformFeedback(GLuint handle) const |
| 849 | { |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 850 | auto iter = mTransformFeedbackMap.find(handle); |
| 851 | return (iter != mTransformFeedbackMap.end()) ? iter->second : nullptr; |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 852 | } |
| 853 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 854 | LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const |
| 855 | { |
| 856 | switch (identifier) |
| 857 | { |
| 858 | case GL_BUFFER: |
| 859 | return getBuffer(name); |
| 860 | case GL_SHADER: |
| 861 | return getShader(name); |
| 862 | case GL_PROGRAM: |
| 863 | return getProgram(name); |
| 864 | case GL_VERTEX_ARRAY: |
| 865 | return getVertexArray(name); |
| 866 | case GL_QUERY: |
| 867 | return getQuery(name); |
| 868 | case GL_TRANSFORM_FEEDBACK: |
| 869 | return getTransformFeedback(name); |
| 870 | case GL_SAMPLER: |
| 871 | return getSampler(name); |
| 872 | case GL_TEXTURE: |
| 873 | return getTexture(name); |
| 874 | case GL_RENDERBUFFER: |
| 875 | return getRenderbuffer(name); |
| 876 | case GL_FRAMEBUFFER: |
| 877 | return getFramebuffer(name); |
| 878 | default: |
| 879 | UNREACHABLE(); |
| 880 | return nullptr; |
| 881 | } |
| 882 | } |
| 883 | |
| 884 | LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const |
| 885 | { |
| 886 | return getFenceSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr))); |
| 887 | } |
| 888 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 889 | void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label) |
| 890 | { |
| 891 | LabeledObject *object = getLabeledObject(identifier, name); |
| 892 | ASSERT(object != nullptr); |
| 893 | |
| 894 | std::string labelName = GetObjectLabelFromPointer(length, label); |
| 895 | object->setLabel(labelName); |
| 896 | } |
| 897 | |
| 898 | void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label) |
| 899 | { |
| 900 | LabeledObject *object = getLabeledObjectFromPtr(ptr); |
| 901 | ASSERT(object != nullptr); |
| 902 | |
| 903 | std::string labelName = GetObjectLabelFromPointer(length, label); |
| 904 | object->setLabel(labelName); |
| 905 | } |
| 906 | |
| 907 | void Context::getObjectLabel(GLenum identifier, |
| 908 | GLuint name, |
| 909 | GLsizei bufSize, |
| 910 | GLsizei *length, |
| 911 | GLchar *label) const |
| 912 | { |
| 913 | LabeledObject *object = getLabeledObject(identifier, name); |
| 914 | ASSERT(object != nullptr); |
| 915 | |
| 916 | const std::string &objectLabel = object->getLabel(); |
| 917 | GetObjectLabelBase(objectLabel, bufSize, length, label); |
| 918 | } |
| 919 | |
| 920 | void Context::getObjectPtrLabel(const void *ptr, |
| 921 | GLsizei bufSize, |
| 922 | GLsizei *length, |
| 923 | GLchar *label) const |
| 924 | { |
| 925 | LabeledObject *object = getLabeledObjectFromPtr(ptr); |
| 926 | ASSERT(object != nullptr); |
| 927 | |
| 928 | const std::string &objectLabel = object->getLabel(); |
| 929 | GetObjectLabelBase(objectLabel, bufSize, length, label); |
| 930 | } |
| 931 | |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 932 | bool Context::isSampler(GLuint samplerName) const |
| 933 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 934 | return mState.mSamplers->isSampler(samplerName); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 935 | } |
| 936 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 937 | void Context::bindArrayBuffer(GLuint bufferHandle) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 938 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 939 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 940 | mGLState.setArrayBufferBinding(buffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 941 | } |
| 942 | |
Jiajia Qin | 9d7d0b1 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 943 | void Context::bindDrawIndirectBuffer(GLuint bufferHandle) |
| 944 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 945 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jiajia Qin | 9d7d0b1 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 946 | mGLState.setDrawIndirectBufferBinding(buffer); |
| 947 | } |
| 948 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 949 | void Context::bindElementArrayBuffer(GLuint bufferHandle) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 950 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 951 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 952 | mGLState.getVertexArray()->setElementArrayBuffer(buffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 953 | } |
| 954 | |
Jamie Madill | dedd7b9 | 2014-11-05 16:30:36 -0500 | [diff] [blame] | 955 | void Context::bindTexture(GLenum target, GLuint handle) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 956 | { |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 957 | Texture *texture = nullptr; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 958 | |
Jamie Madill | dedd7b9 | 2014-11-05 16:30:36 -0500 | [diff] [blame] | 959 | if (handle == 0) |
| 960 | { |
| 961 | texture = mZeroTextures[target].get(); |
| 962 | } |
| 963 | else |
| 964 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 965 | texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target); |
Jamie Madill | dedd7b9 | 2014-11-05 16:30:36 -0500 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | ASSERT(texture); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 969 | mGLState.setSamplerTexture(target, texture); |
shannon.woods%transgaming.com@gtempaccount.com | 90dbc44 | 2013-04-13 03:46:14 +0000 | [diff] [blame] | 970 | } |
| 971 | |
Jamie Madill | 5bf9ff4 | 2016-02-01 11:13:03 -0500 | [diff] [blame] | 972 | void Context::bindReadFramebuffer(GLuint framebufferHandle) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 973 | { |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame^] | 974 | Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation( |
| 975 | mImplementation.get(), mCaps, framebufferHandle); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 976 | mGLState.setReadFramebufferBinding(framebuffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 977 | } |
| 978 | |
Jamie Madill | 5bf9ff4 | 2016-02-01 11:13:03 -0500 | [diff] [blame] | 979 | void Context::bindDrawFramebuffer(GLuint framebufferHandle) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 980 | { |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame^] | 981 | Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation( |
| 982 | mImplementation.get(), mCaps, framebufferHandle); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 983 | mGLState.setDrawFramebufferBinding(framebuffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 984 | } |
| 985 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 986 | void Context::bindVertexArray(GLuint vertexArrayHandle) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 987 | { |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 988 | VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 989 | mGLState.setVertexArrayBinding(vertexArray); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 990 | } |
| 991 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 992 | void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle) |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 993 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 994 | ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits); |
Jamie Madill | 901b379 | 2016-05-26 09:20:40 -0400 | [diff] [blame] | 995 | Sampler *sampler = |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 996 | mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 997 | mGLState.setSamplerBinding(textureUnit, sampler); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 998 | } |
| 999 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 1000 | void Context::bindGenericUniformBuffer(GLuint bufferHandle) |
shannon.woods%transgaming.com@gtempaccount.com | 667a29c | 2013-04-13 03:39:04 +0000 | [diff] [blame] | 1001 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1002 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1003 | mGLState.setGenericUniformBufferBinding(buffer); |
shannon.woods%transgaming.com@gtempaccount.com | 667a29c | 2013-04-13 03:39:04 +0000 | [diff] [blame] | 1004 | } |
| 1005 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 1006 | void Context::bindIndexedUniformBuffer(GLuint bufferHandle, |
| 1007 | GLuint index, |
| 1008 | GLintptr offset, |
| 1009 | GLsizeiptr size) |
shannon.woods%transgaming.com@gtempaccount.com | 3408935 | 2013-04-13 03:36:57 +0000 | [diff] [blame] | 1010 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1011 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1012 | mGLState.setIndexedUniformBufferBinding(index, buffer, offset, size); |
shannon.woods%transgaming.com@gtempaccount.com | 3408935 | 2013-04-13 03:36:57 +0000 | [diff] [blame] | 1013 | } |
| 1014 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 1015 | void Context::bindGenericTransformFeedbackBuffer(GLuint bufferHandle) |
shannon.woods%transgaming.com@gtempaccount.com | 667a29c | 2013-04-13 03:39:04 +0000 | [diff] [blame] | 1016 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1017 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1018 | mGLState.getCurrentTransformFeedback()->bindGenericBuffer(buffer); |
shannon.woods%transgaming.com@gtempaccount.com | 667a29c | 2013-04-13 03:39:04 +0000 | [diff] [blame] | 1019 | } |
| 1020 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 1021 | void Context::bindIndexedTransformFeedbackBuffer(GLuint bufferHandle, |
| 1022 | GLuint index, |
| 1023 | GLintptr offset, |
| 1024 | GLsizeiptr size) |
shannon.woods%transgaming.com@gtempaccount.com | 3408935 | 2013-04-13 03:36:57 +0000 | [diff] [blame] | 1025 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1026 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1027 | mGLState.getCurrentTransformFeedback()->bindIndexedBuffer(index, buffer, offset, size); |
shannon.woods%transgaming.com@gtempaccount.com | 3408935 | 2013-04-13 03:36:57 +0000 | [diff] [blame] | 1028 | } |
| 1029 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 1030 | void Context::bindCopyReadBuffer(GLuint bufferHandle) |
shannon.woods%transgaming.com@gtempaccount.com | 5117188 | 2013-04-13 03:39:10 +0000 | [diff] [blame] | 1031 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1032 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1033 | mGLState.setCopyReadBufferBinding(buffer); |
shannon.woods%transgaming.com@gtempaccount.com | 5117188 | 2013-04-13 03:39:10 +0000 | [diff] [blame] | 1034 | } |
| 1035 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 1036 | void Context::bindCopyWriteBuffer(GLuint bufferHandle) |
shannon.woods%transgaming.com@gtempaccount.com | 5117188 | 2013-04-13 03:39:10 +0000 | [diff] [blame] | 1037 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1038 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1039 | mGLState.setCopyWriteBufferBinding(buffer); |
shannon.woods%transgaming.com@gtempaccount.com | 5117188 | 2013-04-13 03:39:10 +0000 | [diff] [blame] | 1040 | } |
| 1041 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 1042 | void Context::bindPixelPackBuffer(GLuint bufferHandle) |
shannon.woods%transgaming.com@gtempaccount.com | c926e5f | 2013-04-13 03:39:18 +0000 | [diff] [blame] | 1043 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1044 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1045 | mGLState.setPixelPackBufferBinding(buffer); |
shannon.woods%transgaming.com@gtempaccount.com | c926e5f | 2013-04-13 03:39:18 +0000 | [diff] [blame] | 1046 | } |
| 1047 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 1048 | void Context::bindPixelUnpackBuffer(GLuint bufferHandle) |
shannon.woods%transgaming.com@gtempaccount.com | c926e5f | 2013-04-13 03:39:18 +0000 | [diff] [blame] | 1049 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1050 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1051 | mGLState.setPixelUnpackBufferBinding(buffer); |
shannon.woods%transgaming.com@gtempaccount.com | c926e5f | 2013-04-13 03:39:18 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1054 | void Context::useProgram(GLuint program) |
| 1055 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1056 | mGLState.setProgram(getProgram(program)); |
daniel@transgaming.com | 95d2942 | 2012-07-24 18:36:10 +0000 | [diff] [blame] | 1057 | } |
| 1058 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 1059 | void Context::bindTransformFeedback(GLuint transformFeedbackHandle) |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 1060 | { |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 1061 | TransformFeedback *transformFeedback = |
| 1062 | checkTransformFeedbackAllocation(transformFeedbackHandle); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1063 | mGLState.setTransformFeedbackBinding(transformFeedback); |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 1064 | } |
| 1065 | |
Geoff Lang | 5aad967 | 2014-09-08 11:10:42 -0400 | [diff] [blame] | 1066 | Error Context::beginQuery(GLenum target, GLuint query) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1067 | { |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1068 | Query *queryObject = getQuery(query, true, target); |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1069 | ASSERT(queryObject); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1070 | |
Geoff Lang | 5aad967 | 2014-09-08 11:10:42 -0400 | [diff] [blame] | 1071 | // begin query |
| 1072 | Error error = queryObject->begin(); |
| 1073 | if (error.isError()) |
| 1074 | { |
| 1075 | return error; |
| 1076 | } |
| 1077 | |
| 1078 | // set query as active for specified target only if begin succeeded |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1079 | mGLState.setActiveQuery(target, queryObject); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1080 | |
He Yunchao | acd1898 | 2017-01-04 10:46:42 +0800 | [diff] [blame] | 1081 | return NoError(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
Geoff Lang | 5aad967 | 2014-09-08 11:10:42 -0400 | [diff] [blame] | 1084 | Error Context::endQuery(GLenum target) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1085 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1086 | Query *queryObject = mGLState.getActiveQuery(target); |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1087 | ASSERT(queryObject); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1088 | |
Geoff Lang | 5aad967 | 2014-09-08 11:10:42 -0400 | [diff] [blame] | 1089 | gl::Error error = queryObject->end(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1090 | |
Geoff Lang | 5aad967 | 2014-09-08 11:10:42 -0400 | [diff] [blame] | 1091 | // Always unbind the query, even if there was an error. This may delete the query object. |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1092 | mGLState.setActiveQuery(target, NULL); |
Geoff Lang | 5aad967 | 2014-09-08 11:10:42 -0400 | [diff] [blame] | 1093 | |
| 1094 | return error; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1095 | } |
| 1096 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1097 | Error Context::queryCounter(GLuint id, GLenum target) |
| 1098 | { |
| 1099 | ASSERT(target == GL_TIMESTAMP_EXT); |
| 1100 | |
| 1101 | Query *queryObject = getQuery(id, true, target); |
| 1102 | ASSERT(queryObject); |
| 1103 | |
| 1104 | return queryObject->queryCounter(); |
| 1105 | } |
| 1106 | |
| 1107 | void Context::getQueryiv(GLenum target, GLenum pname, GLint *params) |
| 1108 | { |
| 1109 | switch (pname) |
| 1110 | { |
| 1111 | case GL_CURRENT_QUERY_EXT: |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1112 | params[0] = mGLState.getActiveQueryId(target); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1113 | break; |
| 1114 | case GL_QUERY_COUNTER_BITS_EXT: |
| 1115 | switch (target) |
| 1116 | { |
| 1117 | case GL_TIME_ELAPSED_EXT: |
| 1118 | params[0] = getExtensions().queryCounterBitsTimeElapsed; |
| 1119 | break; |
| 1120 | case GL_TIMESTAMP_EXT: |
| 1121 | params[0] = getExtensions().queryCounterBitsTimestamp; |
| 1122 | break; |
| 1123 | default: |
| 1124 | UNREACHABLE(); |
| 1125 | params[0] = 0; |
| 1126 | break; |
| 1127 | } |
| 1128 | break; |
| 1129 | default: |
| 1130 | UNREACHABLE(); |
| 1131 | return; |
| 1132 | } |
| 1133 | } |
| 1134 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1135 | void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1136 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1137 | handleError(GetQueryObjectParameter(getQuery(id), pname, params)); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1138 | } |
| 1139 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1140 | void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1141 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1142 | handleError(GetQueryObjectParameter(getQuery(id), pname, params)); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1143 | } |
| 1144 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1145 | void Context::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1146 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1147 | handleError(GetQueryObjectParameter(getQuery(id), pname, params)); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1148 | } |
| 1149 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1150 | void Context::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1151 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1152 | handleError(GetQueryObjectParameter(getQuery(id), pname, params)); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1153 | } |
| 1154 | |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame^] | 1155 | Framebuffer *Context::getFramebuffer(GLuint handle) const |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1156 | { |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame^] | 1157 | return mState.mFramebuffers->getFramebuffer(handle); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1158 | } |
| 1159 | |
Jamie Madill | 33dc843 | 2013-07-26 11:55:05 -0400 | [diff] [blame] | 1160 | FenceNV *Context::getFenceNV(unsigned int handle) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1161 | { |
Jamie Madill | 4e25a0d | 2016-03-08 13:53:03 -0500 | [diff] [blame] | 1162 | auto fence = mFenceNVMap.find(handle); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1163 | |
Jamie Madill | 33dc843 | 2013-07-26 11:55:05 -0400 | [diff] [blame] | 1164 | if (fence == mFenceNVMap.end()) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1165 | { |
| 1166 | return NULL; |
| 1167 | } |
| 1168 | else |
| 1169 | { |
| 1170 | return fence->second; |
| 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | Query *Context::getQuery(unsigned int handle, bool create, GLenum type) |
| 1175 | { |
Jamie Madill | 4e25a0d | 2016-03-08 13:53:03 -0500 | [diff] [blame] | 1176 | auto query = mQueryMap.find(handle); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1177 | |
| 1178 | if (query == mQueryMap.end()) |
| 1179 | { |
| 1180 | return NULL; |
| 1181 | } |
| 1182 | else |
| 1183 | { |
| 1184 | if (!query->second && create) |
| 1185 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 1186 | query->second = new Query(mImplementation->createQuery(type), handle); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1187 | query->second->addRef(); |
| 1188 | } |
| 1189 | return query->second; |
| 1190 | } |
| 1191 | } |
| 1192 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1193 | Query *Context::getQuery(GLuint handle) const |
| 1194 | { |
| 1195 | auto iter = mQueryMap.find(handle); |
| 1196 | return (iter != mQueryMap.end()) ? iter->second : nullptr; |
| 1197 | } |
| 1198 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1199 | Texture *Context::getTargetTexture(GLenum target) const |
| 1200 | { |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 1201 | ASSERT(ValidTextureTarget(this, target) || ValidTextureExternalTarget(this, target)); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1202 | return mGLState.getTargetTexture(target); |
shannon.woods%transgaming.com@gtempaccount.com | c926e5f | 2013-04-13 03:39:18 +0000 | [diff] [blame] | 1203 | } |
| 1204 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 1205 | Texture *Context::getSamplerTexture(unsigned int sampler, GLenum type) const |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1206 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1207 | return mGLState.getSamplerTexture(sampler, type); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1208 | } |
| 1209 | |
Geoff Lang | 492a7e4 | 2014-11-05 13:27:06 -0500 | [diff] [blame] | 1210 | Compiler *Context::getCompiler() const |
| 1211 | { |
| 1212 | return mCompiler; |
| 1213 | } |
| 1214 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1215 | void Context::getBooleanv(GLenum pname, GLboolean *params) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1216 | { |
| 1217 | switch (pname) |
| 1218 | { |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 1219 | case GL_SHADER_COMPILER: *params = GL_TRUE; break; |
daniel@transgaming.com | f39967e | 2012-11-28 19:35:56 +0000 | [diff] [blame] | 1220 | case GL_CONTEXT_ROBUST_ACCESS_EXT: *params = mRobustAccess ? GL_TRUE : GL_FALSE; break; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1221 | default: |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1222 | mGLState.getBooleanv(pname, params); |
| 1223 | break; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1224 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1225 | } |
| 1226 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1227 | void Context::getFloatv(GLenum pname, GLfloat *params) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1228 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1229 | // Queries about context capabilities and maximums are answered by Context. |
| 1230 | // Queries about current GL state values are answered by State. |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1231 | switch (pname) |
| 1232 | { |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1233 | case GL_ALIASED_LINE_WIDTH_RANGE: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1234 | params[0] = mCaps.minAliasedLineWidth; |
| 1235 | params[1] = mCaps.maxAliasedLineWidth; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1236 | break; |
| 1237 | case GL_ALIASED_POINT_SIZE_RANGE: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1238 | params[0] = mCaps.minAliasedPointSize; |
| 1239 | params[1] = mCaps.maxAliasedPointSize; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1240 | break; |
daniel@transgaming.com | 07ab841 | 2012-07-12 15:17:09 +0000 | [diff] [blame] | 1241 | case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1242 | ASSERT(mExtensions.textureFilterAnisotropic); |
| 1243 | *params = mExtensions.maxTextureAnisotropy; |
daniel@transgaming.com | 07ab841 | 2012-07-12 15:17:09 +0000 | [diff] [blame] | 1244 | break; |
Geoff Lang | e6d4e12 | 2015-06-29 13:33:55 -0400 | [diff] [blame] | 1245 | case GL_MAX_TEXTURE_LOD_BIAS: |
| 1246 | *params = mCaps.maxLODBias; |
| 1247 | break; |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1248 | |
| 1249 | case GL_PATH_MODELVIEW_MATRIX_CHROMIUM: |
| 1250 | case GL_PATH_PROJECTION_MATRIX_CHROMIUM: |
| 1251 | { |
| 1252 | ASSERT(mExtensions.pathRendering); |
| 1253 | const GLfloat *m = mGLState.getPathRenderingMatrix(pname); |
| 1254 | memcpy(params, m, 16 * sizeof(GLfloat)); |
| 1255 | } |
| 1256 | break; |
| 1257 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1258 | default: |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1259 | mGLState.getFloatv(pname, params); |
| 1260 | break; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1261 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1262 | } |
| 1263 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1264 | void Context::getIntegerv(GLenum pname, GLint *params) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1265 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1266 | // Queries about context capabilities and maximums are answered by Context. |
| 1267 | // 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] | 1268 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1269 | switch (pname) |
| 1270 | { |
Geoff Lang | 301d161 | 2014-07-09 10:34:37 -0400 | [diff] [blame] | 1271 | case GL_MAX_VERTEX_ATTRIBS: *params = mCaps.maxVertexAttributes; break; |
| 1272 | case GL_MAX_VERTEX_UNIFORM_VECTORS: *params = mCaps.maxVertexUniformVectors; break; |
| 1273 | case GL_MAX_VERTEX_UNIFORM_COMPONENTS: *params = mCaps.maxVertexUniformComponents; break; |
Geoff Lang | 3a61c32 | 2014-07-10 13:01:54 -0400 | [diff] [blame] | 1274 | case GL_MAX_VARYING_VECTORS: *params = mCaps.maxVaryingVectors; break; |
| 1275 | case GL_MAX_VARYING_COMPONENTS: *params = mCaps.maxVertexOutputComponents; break; |
| 1276 | case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: *params = mCaps.maxCombinedTextureImageUnits; break; |
Geoff Lang | 301d161 | 2014-07-09 10:34:37 -0400 | [diff] [blame] | 1277 | case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS: *params = mCaps.maxVertexTextureImageUnits; break; |
| 1278 | case GL_MAX_TEXTURE_IMAGE_UNITS: *params = mCaps.maxTextureImageUnits; break; |
| 1279 | case GL_MAX_FRAGMENT_UNIFORM_VECTORS: *params = mCaps.maxFragmentUniformVectors; break; |
Geoff Lang | e746890 | 2015-10-02 10:46:24 -0400 | [diff] [blame] | 1280 | case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS: *params = mCaps.maxFragmentUniformComponents; break; |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1281 | case GL_MAX_RENDERBUFFER_SIZE: *params = mCaps.maxRenderbufferSize; break; |
| 1282 | case GL_MAX_COLOR_ATTACHMENTS_EXT: *params = mCaps.maxColorAttachments; break; |
| 1283 | case GL_MAX_DRAW_BUFFERS_EXT: *params = mCaps.maxDrawBuffers; break; |
Jamie Madill | 1caff07 | 2013-07-19 16:36:56 -0400 | [diff] [blame] | 1284 | //case GL_FRAMEBUFFER_BINDING: // now equivalent to GL_DRAW_FRAMEBUFFER_BINDING_ANGLE |
Jamie Madill | 1caff07 | 2013-07-19 16:36:56 -0400 | [diff] [blame] | 1285 | case GL_SUBPIXEL_BITS: *params = 4; break; |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1286 | case GL_MAX_TEXTURE_SIZE: *params = mCaps.max2DTextureSize; break; |
| 1287 | case GL_MAX_CUBE_MAP_TEXTURE_SIZE: *params = mCaps.maxCubeMapTextureSize; break; |
| 1288 | case GL_MAX_3D_TEXTURE_SIZE: *params = mCaps.max3DTextureSize; break; |
| 1289 | case GL_MAX_ARRAY_TEXTURE_LAYERS: *params = mCaps.maxArrayTextureLayers; break; |
Geoff Lang | 3a61c32 | 2014-07-10 13:01:54 -0400 | [diff] [blame] | 1290 | case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT: *params = mCaps.uniformBufferOffsetAlignment; break; |
| 1291 | case GL_MAX_UNIFORM_BUFFER_BINDINGS: *params = mCaps.maxUniformBufferBindings; break; |
Geoff Lang | 301d161 | 2014-07-09 10:34:37 -0400 | [diff] [blame] | 1292 | case GL_MAX_VERTEX_UNIFORM_BLOCKS: *params = mCaps.maxVertexUniformBlocks; break; |
| 1293 | case GL_MAX_FRAGMENT_UNIFORM_BLOCKS: *params = mCaps.maxFragmentUniformBlocks; break; |
Geoff Lang | 3a61c32 | 2014-07-10 13:01:54 -0400 | [diff] [blame] | 1294 | case GL_MAX_COMBINED_UNIFORM_BLOCKS: *params = mCaps.maxCombinedTextureImageUnits; break; |
Geoff Lang | e6d4e12 | 2015-06-29 13:33:55 -0400 | [diff] [blame] | 1295 | case GL_MAX_VERTEX_OUTPUT_COMPONENTS: *params = mCaps.maxVertexOutputComponents; break; |
| 1296 | case GL_MAX_FRAGMENT_INPUT_COMPONENTS: *params = mCaps.maxFragmentInputComponents; break; |
| 1297 | case GL_MIN_PROGRAM_TEXEL_OFFSET: *params = mCaps.minProgramTexelOffset; break; |
| 1298 | case GL_MAX_PROGRAM_TEXEL_OFFSET: *params = mCaps.maxProgramTexelOffset; break; |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1299 | case GL_MAJOR_VERSION: |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 1300 | *params = getClientVersion().major; |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1301 | break; |
| 1302 | case GL_MINOR_VERSION: |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 1303 | *params = getClientVersion().minor; |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 1304 | break; |
Geoff Lang | 900013c | 2014-07-07 11:32:19 -0400 | [diff] [blame] | 1305 | case GL_MAX_ELEMENTS_INDICES: *params = mCaps.maxElementsIndices; break; |
| 1306 | case GL_MAX_ELEMENTS_VERTICES: *params = mCaps.maxElementsVertices; break; |
Geoff Lang | 05881a0 | 2014-07-10 14:05:30 -0400 | [diff] [blame] | 1307 | case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS: *params = mCaps.maxTransformFeedbackInterleavedComponents; break; |
| 1308 | case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS: *params = mCaps.maxTransformFeedbackSeparateAttributes; break; |
| 1309 | case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS: *params = mCaps.maxTransformFeedbackSeparateComponents; break; |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1310 | case GL_NUM_COMPRESSED_TEXTURE_FORMATS: |
| 1311 | *params = static_cast<GLint>(mCaps.compressedTextureFormats.size()); |
| 1312 | break; |
Geoff Lang | def624b | 2015-04-13 10:46:56 -0400 | [diff] [blame] | 1313 | case GL_MAX_SAMPLES_ANGLE: *params = mCaps.maxSamples; break; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1314 | case GL_MAX_VIEWPORT_DIMS: |
| 1315 | { |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1316 | params[0] = mCaps.maxViewportWidth; |
| 1317 | params[1] = mCaps.maxViewportHeight; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1318 | } |
| 1319 | break; |
| 1320 | case GL_COMPRESSED_TEXTURE_FORMATS: |
Geoff Lang | 900013c | 2014-07-07 11:32:19 -0400 | [diff] [blame] | 1321 | std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(), params); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1322 | break; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1323 | case GL_RESET_NOTIFICATION_STRATEGY_EXT: |
| 1324 | *params = mResetStrategy; |
| 1325 | break; |
Geoff Lang | 900013c | 2014-07-07 11:32:19 -0400 | [diff] [blame] | 1326 | case GL_NUM_SHADER_BINARY_FORMATS: |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1327 | *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1328 | break; |
Geoff Lang | 900013c | 2014-07-07 11:32:19 -0400 | [diff] [blame] | 1329 | case GL_SHADER_BINARY_FORMATS: |
| 1330 | std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params); |
| 1331 | break; |
| 1332 | case GL_NUM_PROGRAM_BINARY_FORMATS: |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1333 | *params = static_cast<GLint>(mCaps.programBinaryFormats.size()); |
Geoff Lang | 900013c | 2014-07-07 11:32:19 -0400 | [diff] [blame] | 1334 | break; |
| 1335 | case GL_PROGRAM_BINARY_FORMATS: |
| 1336 | std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1337 | break; |
Geoff Lang | 23c8169 | 2013-08-12 10:46:58 -0400 | [diff] [blame] | 1338 | case GL_NUM_EXTENSIONS: |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 1339 | *params = static_cast<GLint>(mExtensionStrings.size()); |
Geoff Lang | 23c8169 | 2013-08-12 10:46:58 -0400 | [diff] [blame] | 1340 | break; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1341 | |
| 1342 | // GL_KHR_debug |
| 1343 | case GL_MAX_DEBUG_MESSAGE_LENGTH: |
| 1344 | *params = mExtensions.maxDebugMessageLength; |
| 1345 | break; |
| 1346 | case GL_MAX_DEBUG_LOGGED_MESSAGES: |
| 1347 | *params = mExtensions.maxDebugLoggedMessages; |
| 1348 | break; |
| 1349 | case GL_MAX_DEBUG_GROUP_STACK_DEPTH: |
| 1350 | *params = mExtensions.maxDebugGroupStackDepth; |
| 1351 | break; |
| 1352 | case GL_MAX_LABEL_LENGTH: |
| 1353 | *params = mExtensions.maxLabelLength; |
| 1354 | break; |
| 1355 | |
Ian Ewell | 53f59f4 | 2016-01-28 17:36:55 -0500 | [diff] [blame] | 1356 | // GL_EXT_disjoint_timer_query |
| 1357 | case GL_GPU_DISJOINT_EXT: |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 1358 | *params = mImplementation->getGPUDisjoint(); |
Ian Ewell | 53f59f4 | 2016-01-28 17:36:55 -0500 | [diff] [blame] | 1359 | break; |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1360 | case GL_MAX_FRAMEBUFFER_WIDTH: |
| 1361 | *params = mCaps.maxFramebufferWidth; |
| 1362 | break; |
| 1363 | case GL_MAX_FRAMEBUFFER_HEIGHT: |
| 1364 | *params = mCaps.maxFramebufferHeight; |
| 1365 | break; |
| 1366 | case GL_MAX_FRAMEBUFFER_SAMPLES: |
| 1367 | *params = mCaps.maxFramebufferSamples; |
| 1368 | break; |
| 1369 | case GL_MAX_SAMPLE_MASK_WORDS: |
| 1370 | *params = mCaps.maxSampleMaskWords; |
| 1371 | break; |
| 1372 | case GL_MAX_COLOR_TEXTURE_SAMPLES: |
| 1373 | *params = mCaps.maxColorTextureSamples; |
| 1374 | break; |
| 1375 | case GL_MAX_DEPTH_TEXTURE_SAMPLES: |
| 1376 | *params = mCaps.maxDepthTextureSamples; |
| 1377 | break; |
| 1378 | case GL_MAX_INTEGER_SAMPLES: |
| 1379 | *params = mCaps.maxIntegerSamples; |
| 1380 | break; |
| 1381 | case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET: |
| 1382 | *params = mCaps.maxVertexAttribRelativeOffset; |
| 1383 | break; |
| 1384 | case GL_MAX_VERTEX_ATTRIB_BINDINGS: |
| 1385 | *params = mCaps.maxVertexAttribBindings; |
| 1386 | break; |
| 1387 | case GL_MAX_VERTEX_ATTRIB_STRIDE: |
| 1388 | *params = mCaps.maxVertexAttribStride; |
| 1389 | break; |
| 1390 | case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS: |
| 1391 | *params = mCaps.maxVertexAtomicCounterBuffers; |
| 1392 | break; |
| 1393 | case GL_MAX_VERTEX_ATOMIC_COUNTERS: |
| 1394 | *params = mCaps.maxVertexAtomicCounters; |
| 1395 | break; |
| 1396 | case GL_MAX_VERTEX_IMAGE_UNIFORMS: |
| 1397 | *params = mCaps.maxVertexImageUniforms; |
| 1398 | break; |
| 1399 | case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS: |
| 1400 | *params = mCaps.maxVertexShaderStorageBlocks; |
| 1401 | break; |
| 1402 | case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS: |
| 1403 | *params = mCaps.maxFragmentAtomicCounterBuffers; |
| 1404 | break; |
| 1405 | case GL_MAX_FRAGMENT_ATOMIC_COUNTERS: |
| 1406 | *params = mCaps.maxFragmentAtomicCounters; |
| 1407 | break; |
| 1408 | case GL_MAX_FRAGMENT_IMAGE_UNIFORMS: |
| 1409 | *params = mCaps.maxFragmentImageUniforms; |
| 1410 | break; |
| 1411 | case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS: |
| 1412 | *params = mCaps.maxFragmentShaderStorageBlocks; |
| 1413 | break; |
| 1414 | case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET: |
| 1415 | *params = mCaps.minProgramTextureGatherOffset; |
| 1416 | break; |
| 1417 | case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET: |
| 1418 | *params = mCaps.maxProgramTextureGatherOffset; |
| 1419 | break; |
| 1420 | case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS: |
| 1421 | *params = mCaps.maxComputeWorkGroupInvocations; |
| 1422 | break; |
| 1423 | case GL_MAX_COMPUTE_UNIFORM_BLOCKS: |
| 1424 | *params = mCaps.maxComputeUniformBlocks; |
| 1425 | break; |
| 1426 | case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS: |
| 1427 | *params = mCaps.maxComputeTextureImageUnits; |
| 1428 | break; |
| 1429 | case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE: |
| 1430 | *params = mCaps.maxComputeSharedMemorySize; |
| 1431 | break; |
| 1432 | case GL_MAX_COMPUTE_UNIFORM_COMPONENTS: |
| 1433 | *params = mCaps.maxComputeUniformComponents; |
| 1434 | break; |
| 1435 | case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS: |
| 1436 | *params = mCaps.maxComputeAtomicCounterBuffers; |
| 1437 | break; |
| 1438 | case GL_MAX_COMPUTE_ATOMIC_COUNTERS: |
| 1439 | *params = mCaps.maxComputeAtomicCounters; |
| 1440 | break; |
| 1441 | case GL_MAX_COMPUTE_IMAGE_UNIFORMS: |
| 1442 | *params = mCaps.maxComputeImageUniforms; |
| 1443 | break; |
| 1444 | case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS: |
| 1445 | *params = mCaps.maxCombinedComputeUniformComponents; |
| 1446 | break; |
| 1447 | case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS: |
| 1448 | *params = mCaps.maxComputeShaderStorageBlocks; |
| 1449 | break; |
| 1450 | case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES: |
| 1451 | *params = mCaps.maxCombinedShaderOutputResources; |
| 1452 | break; |
| 1453 | case GL_MAX_UNIFORM_LOCATIONS: |
| 1454 | *params = mCaps.maxUniformLocations; |
| 1455 | break; |
| 1456 | case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS: |
| 1457 | *params = mCaps.maxAtomicCounterBufferBindings; |
| 1458 | break; |
| 1459 | case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE: |
| 1460 | *params = mCaps.maxAtomicCounterBufferSize; |
| 1461 | break; |
| 1462 | case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS: |
| 1463 | *params = mCaps.maxCombinedAtomicCounterBuffers; |
| 1464 | break; |
| 1465 | case GL_MAX_COMBINED_ATOMIC_COUNTERS: |
| 1466 | *params = mCaps.maxCombinedAtomicCounters; |
| 1467 | break; |
| 1468 | case GL_MAX_IMAGE_UNITS: |
| 1469 | *params = mCaps.maxImageUnits; |
| 1470 | break; |
| 1471 | case GL_MAX_COMBINED_IMAGE_UNIFORMS: |
| 1472 | *params = mCaps.maxCombinedImageUniforms; |
| 1473 | break; |
| 1474 | case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS: |
| 1475 | *params = mCaps.maxShaderStorageBufferBindings; |
| 1476 | break; |
| 1477 | case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS: |
| 1478 | *params = mCaps.maxCombinedShaderStorageBlocks; |
| 1479 | break; |
| 1480 | case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT: |
| 1481 | *params = mCaps.shaderStorageBufferOffsetAlignment; |
| 1482 | break; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1483 | default: |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1484 | mGLState.getIntegerv(mState, pname, params); |
| 1485 | break; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1486 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1487 | } |
| 1488 | |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1489 | void Context::getInteger64v(GLenum pname, GLint64 *params) |
Jamie Madill | 0fda986 | 2013-07-19 16:36:55 -0400 | [diff] [blame] | 1490 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1491 | // Queries about context capabilities and maximums are answered by Context. |
| 1492 | // Queries about current GL state values are answered by State. |
Jamie Madill | 0fda986 | 2013-07-19 16:36:55 -0400 | [diff] [blame] | 1493 | switch (pname) |
| 1494 | { |
| 1495 | case GL_MAX_ELEMENT_INDEX: |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1496 | *params = mCaps.maxElementIndex; |
Jamie Madill | 0fda986 | 2013-07-19 16:36:55 -0400 | [diff] [blame] | 1497 | break; |
| 1498 | case GL_MAX_UNIFORM_BLOCK_SIZE: |
Geoff Lang | 3a61c32 | 2014-07-10 13:01:54 -0400 | [diff] [blame] | 1499 | *params = mCaps.maxUniformBlockSize; |
Jamie Madill | 0fda986 | 2013-07-19 16:36:55 -0400 | [diff] [blame] | 1500 | break; |
| 1501 | case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS: |
Geoff Lang | 3a61c32 | 2014-07-10 13:01:54 -0400 | [diff] [blame] | 1502 | *params = mCaps.maxCombinedVertexUniformComponents; |
Jamie Madill | 0fda986 | 2013-07-19 16:36:55 -0400 | [diff] [blame] | 1503 | break; |
| 1504 | case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS: |
Geoff Lang | 3a61c32 | 2014-07-10 13:01:54 -0400 | [diff] [blame] | 1505 | *params = mCaps.maxCombinedFragmentUniformComponents; |
Jamie Madill | 0fda986 | 2013-07-19 16:36:55 -0400 | [diff] [blame] | 1506 | break; |
| 1507 | case GL_MAX_SERVER_WAIT_TIMEOUT: |
Geoff Lang | 900013c | 2014-07-07 11:32:19 -0400 | [diff] [blame] | 1508 | *params = mCaps.maxServerWaitTimeout; |
Jamie Madill | 0fda986 | 2013-07-19 16:36:55 -0400 | [diff] [blame] | 1509 | break; |
Ian Ewell | 53f59f4 | 2016-01-28 17:36:55 -0500 | [diff] [blame] | 1510 | |
| 1511 | // GL_EXT_disjoint_timer_query |
| 1512 | case GL_TIMESTAMP_EXT: |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 1513 | *params = mImplementation->getTimestamp(); |
Ian Ewell | 53f59f4 | 2016-01-28 17:36:55 -0500 | [diff] [blame] | 1514 | break; |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1515 | |
| 1516 | case GL_MAX_SHADER_STORAGE_BLOCK_SIZE: |
| 1517 | *params = mCaps.maxShaderStorageBlockSize; |
| 1518 | break; |
Jamie Madill | 0fda986 | 2013-07-19 16:36:55 -0400 | [diff] [blame] | 1519 | default: |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 1520 | UNREACHABLE(); |
| 1521 | break; |
Jamie Madill | 0fda986 | 2013-07-19 16:36:55 -0400 | [diff] [blame] | 1522 | } |
Jamie Madill | 0fda986 | 2013-07-19 16:36:55 -0400 | [diff] [blame] | 1523 | } |
| 1524 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1525 | void Context::getPointerv(GLenum pname, void **params) const |
| 1526 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1527 | mGLState.getPointerv(pname, params); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1528 | } |
| 1529 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1530 | void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data) |
Shannon Woods | 1b2fb85 | 2013-08-19 14:28:48 -0400 | [diff] [blame] | 1531 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1532 | // Queries about context capabilities and maximums are answered by Context. |
| 1533 | // Queries about current GL state values are answered by State. |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1534 | |
| 1535 | GLenum nativeType; |
| 1536 | unsigned int numParams; |
| 1537 | bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams); |
| 1538 | ASSERT(queryStatus); |
| 1539 | |
| 1540 | if (nativeType == GL_INT) |
| 1541 | { |
| 1542 | switch (target) |
| 1543 | { |
| 1544 | case GL_MAX_COMPUTE_WORK_GROUP_COUNT: |
| 1545 | ASSERT(index < 3u); |
| 1546 | *data = mCaps.maxComputeWorkGroupCount[index]; |
| 1547 | break; |
| 1548 | case GL_MAX_COMPUTE_WORK_GROUP_SIZE: |
| 1549 | ASSERT(index < 3u); |
| 1550 | *data = mCaps.maxComputeWorkGroupSize[index]; |
| 1551 | break; |
| 1552 | default: |
| 1553 | mGLState.getIntegeri_v(target, index, data); |
| 1554 | } |
| 1555 | } |
| 1556 | else |
| 1557 | { |
| 1558 | CastIndexedStateValues(this, nativeType, target, index, numParams, data); |
| 1559 | } |
Shannon Woods | 1b2fb85 | 2013-08-19 14:28:48 -0400 | [diff] [blame] | 1560 | } |
| 1561 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1562 | void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data) |
Shannon Woods | 1b2fb85 | 2013-08-19 14:28:48 -0400 | [diff] [blame] | 1563 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1564 | // Queries about context capabilities and maximums are answered by Context. |
| 1565 | // Queries about current GL state values are answered by State. |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1566 | |
| 1567 | GLenum nativeType; |
| 1568 | unsigned int numParams; |
| 1569 | bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams); |
| 1570 | ASSERT(queryStatus); |
| 1571 | |
| 1572 | if (nativeType == GL_INT_64_ANGLEX) |
| 1573 | { |
| 1574 | mGLState.getInteger64i_v(target, index, data); |
| 1575 | } |
| 1576 | else |
| 1577 | { |
| 1578 | CastIndexedStateValues(this, nativeType, target, index, numParams, data); |
| 1579 | } |
| 1580 | } |
| 1581 | |
| 1582 | void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data) |
| 1583 | { |
| 1584 | // Queries about context capabilities and maximums are answered by Context. |
| 1585 | // Queries about current GL state values are answered by State. |
| 1586 | |
| 1587 | GLenum nativeType; |
| 1588 | unsigned int numParams; |
| 1589 | bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams); |
| 1590 | ASSERT(queryStatus); |
| 1591 | |
| 1592 | if (nativeType == GL_BOOL) |
| 1593 | { |
| 1594 | mGLState.getBooleani_v(target, index, data); |
| 1595 | } |
| 1596 | else |
| 1597 | { |
| 1598 | CastIndexedStateValues(this, nativeType, target, index, numParams, data); |
| 1599 | } |
Shannon Woods | 1b2fb85 | 2013-08-19 14:28:48 -0400 | [diff] [blame] | 1600 | } |
| 1601 | |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1602 | void Context::drawArrays(GLenum mode, GLint first, GLsizei count) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1603 | { |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1604 | syncRendererState(); |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1605 | auto error = mImplementation->drawArrays(mode, first, count); |
| 1606 | handleError(error); |
| 1607 | if (!error.isError()) |
| 1608 | { |
| 1609 | MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback()); |
| 1610 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1611 | } |
| 1612 | |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1613 | void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount) |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 1614 | { |
| 1615 | syncRendererState(); |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1616 | auto error = mImplementation->drawArraysInstanced(mode, first, count, instanceCount); |
| 1617 | handleError(error); |
| 1618 | if (!error.isError()) |
| 1619 | { |
| 1620 | MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback()); |
| 1621 | } |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 1622 | } |
| 1623 | |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1624 | void Context::drawElements(GLenum mode, |
| 1625 | GLsizei count, |
| 1626 | GLenum type, |
| 1627 | const GLvoid *indices, |
| 1628 | const IndexRange &indexRange) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1629 | { |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1630 | syncRendererState(); |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1631 | handleError(mImplementation->drawElements(mode, count, type, indices, indexRange)); |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 1632 | } |
| 1633 | |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1634 | void Context::drawElementsInstanced(GLenum mode, |
| 1635 | GLsizei count, |
| 1636 | GLenum type, |
| 1637 | const GLvoid *indices, |
| 1638 | GLsizei instances, |
| 1639 | const IndexRange &indexRange) |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 1640 | { |
| 1641 | syncRendererState(); |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1642 | handleError( |
| 1643 | mImplementation->drawElementsInstanced(mode, count, type, indices, instances, indexRange)); |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 1644 | } |
| 1645 | |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1646 | void Context::drawRangeElements(GLenum mode, |
| 1647 | GLuint start, |
| 1648 | GLuint end, |
| 1649 | GLsizei count, |
| 1650 | GLenum type, |
| 1651 | const GLvoid *indices, |
| 1652 | const IndexRange &indexRange) |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 1653 | { |
| 1654 | syncRendererState(); |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1655 | handleError( |
| 1656 | mImplementation->drawRangeElements(mode, start, end, count, type, indices, indexRange)); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1657 | } |
| 1658 | |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1659 | void Context::drawArraysIndirect(GLenum mode, const GLvoid *indirect) |
| 1660 | { |
| 1661 | syncRendererState(); |
| 1662 | handleError(mImplementation->drawArraysIndirect(mode, indirect)); |
| 1663 | } |
| 1664 | |
| 1665 | void Context::drawElementsIndirect(GLenum mode, GLenum type, const GLvoid *indirect) |
| 1666 | { |
| 1667 | syncRendererState(); |
| 1668 | handleError(mImplementation->drawElementsIndirect(mode, type, indirect)); |
| 1669 | } |
| 1670 | |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1671 | void Context::flush() |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1672 | { |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1673 | handleError(mImplementation->flush()); |
Geoff Lang | 129753a | 2015-01-09 16:52:09 -0500 | [diff] [blame] | 1674 | } |
| 1675 | |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1676 | void Context::finish() |
Geoff Lang | 129753a | 2015-01-09 16:52:09 -0500 | [diff] [blame] | 1677 | { |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1678 | handleError(mImplementation->finish()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1679 | } |
| 1680 | |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 1681 | void Context::insertEventMarker(GLsizei length, const char *marker) |
| 1682 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 1683 | ASSERT(mImplementation); |
| 1684 | mImplementation->insertEventMarker(length, marker); |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 1685 | } |
| 1686 | |
| 1687 | void Context::pushGroupMarker(GLsizei length, const char *marker) |
| 1688 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 1689 | ASSERT(mImplementation); |
| 1690 | mImplementation->pushGroupMarker(length, marker); |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 1691 | } |
| 1692 | |
| 1693 | void Context::popGroupMarker() |
| 1694 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 1695 | ASSERT(mImplementation); |
| 1696 | mImplementation->popGroupMarker(); |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 1697 | } |
| 1698 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 1699 | void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name) |
| 1700 | { |
| 1701 | Program *programObject = getProgram(program); |
| 1702 | ASSERT(programObject); |
| 1703 | |
| 1704 | programObject->bindUniformLocation(location, name); |
| 1705 | } |
| 1706 | |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 1707 | void Context::setCoverageModulation(GLenum components) |
| 1708 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1709 | mGLState.setCoverageModulation(components); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 1710 | } |
| 1711 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1712 | void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix) |
| 1713 | { |
| 1714 | mGLState.loadPathRenderingMatrix(matrixMode, matrix); |
| 1715 | } |
| 1716 | |
| 1717 | void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode) |
| 1718 | { |
| 1719 | GLfloat I[16]; |
| 1720 | angle::Matrix<GLfloat>::setToIdentity(I); |
| 1721 | |
| 1722 | mGLState.loadPathRenderingMatrix(matrixMode, I); |
| 1723 | } |
| 1724 | |
| 1725 | void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask) |
| 1726 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1727 | const auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1728 | if (!pathObj) |
| 1729 | return; |
| 1730 | |
| 1731 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1732 | syncRendererState(); |
| 1733 | |
| 1734 | mImplementation->stencilFillPath(pathObj, fillMode, mask); |
| 1735 | } |
| 1736 | |
| 1737 | void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask) |
| 1738 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1739 | const auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1740 | if (!pathObj) |
| 1741 | return; |
| 1742 | |
| 1743 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1744 | syncRendererState(); |
| 1745 | |
| 1746 | mImplementation->stencilStrokePath(pathObj, reference, mask); |
| 1747 | } |
| 1748 | |
| 1749 | void Context::coverFillPath(GLuint path, GLenum coverMode) |
| 1750 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1751 | const auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1752 | if (!pathObj) |
| 1753 | return; |
| 1754 | |
| 1755 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1756 | syncRendererState(); |
| 1757 | |
| 1758 | mImplementation->coverFillPath(pathObj, coverMode); |
| 1759 | } |
| 1760 | |
| 1761 | void Context::coverStrokePath(GLuint path, GLenum coverMode) |
| 1762 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1763 | const auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1764 | if (!pathObj) |
| 1765 | return; |
| 1766 | |
| 1767 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1768 | syncRendererState(); |
| 1769 | |
| 1770 | mImplementation->coverStrokePath(pathObj, coverMode); |
| 1771 | } |
| 1772 | |
| 1773 | void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode) |
| 1774 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1775 | const auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1776 | if (!pathObj) |
| 1777 | return; |
| 1778 | |
| 1779 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1780 | syncRendererState(); |
| 1781 | |
| 1782 | mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode); |
| 1783 | } |
| 1784 | |
| 1785 | void Context::stencilThenCoverStrokePath(GLuint path, |
| 1786 | GLint reference, |
| 1787 | GLuint mask, |
| 1788 | GLenum coverMode) |
| 1789 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1790 | const auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1791 | if (!pathObj) |
| 1792 | return; |
| 1793 | |
| 1794 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1795 | syncRendererState(); |
| 1796 | |
| 1797 | mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode); |
| 1798 | } |
| 1799 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1800 | void Context::coverFillPathInstanced(GLsizei numPaths, |
| 1801 | GLenum pathNameType, |
| 1802 | const void *paths, |
| 1803 | GLuint pathBase, |
| 1804 | GLenum coverMode, |
| 1805 | GLenum transformType, |
| 1806 | const GLfloat *transformValues) |
| 1807 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1808 | const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1809 | |
| 1810 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1811 | syncRendererState(); |
| 1812 | |
| 1813 | mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues); |
| 1814 | } |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1815 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1816 | void Context::coverStrokePathInstanced(GLsizei numPaths, |
| 1817 | GLenum pathNameType, |
| 1818 | const void *paths, |
| 1819 | GLuint pathBase, |
| 1820 | GLenum coverMode, |
| 1821 | GLenum transformType, |
| 1822 | const GLfloat *transformValues) |
| 1823 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1824 | const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1825 | |
| 1826 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1827 | syncRendererState(); |
| 1828 | |
| 1829 | mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType, |
| 1830 | transformValues); |
| 1831 | } |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1832 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1833 | void Context::stencilFillPathInstanced(GLsizei numPaths, |
| 1834 | GLenum pathNameType, |
| 1835 | const void *paths, |
| 1836 | GLuint pathBase, |
| 1837 | GLenum fillMode, |
| 1838 | GLuint mask, |
| 1839 | GLenum transformType, |
| 1840 | const GLfloat *transformValues) |
| 1841 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1842 | const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1843 | |
| 1844 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1845 | syncRendererState(); |
| 1846 | |
| 1847 | mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType, |
| 1848 | transformValues); |
| 1849 | } |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1850 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1851 | void Context::stencilStrokePathInstanced(GLsizei numPaths, |
| 1852 | GLenum pathNameType, |
| 1853 | const void *paths, |
| 1854 | GLuint pathBase, |
| 1855 | GLint reference, |
| 1856 | GLuint mask, |
| 1857 | GLenum transformType, |
| 1858 | const GLfloat *transformValues) |
| 1859 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1860 | const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1861 | |
| 1862 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1863 | syncRendererState(); |
| 1864 | |
| 1865 | mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType, |
| 1866 | transformValues); |
| 1867 | } |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1868 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1869 | void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths, |
| 1870 | GLenum pathNameType, |
| 1871 | const void *paths, |
| 1872 | GLuint pathBase, |
| 1873 | GLenum fillMode, |
| 1874 | GLuint mask, |
| 1875 | GLenum coverMode, |
| 1876 | GLenum transformType, |
| 1877 | const GLfloat *transformValues) |
| 1878 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1879 | const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1880 | |
| 1881 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1882 | syncRendererState(); |
| 1883 | |
| 1884 | mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask, |
| 1885 | transformType, transformValues); |
| 1886 | } |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1887 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1888 | void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths, |
| 1889 | GLenum pathNameType, |
| 1890 | const void *paths, |
| 1891 | GLuint pathBase, |
| 1892 | GLint reference, |
| 1893 | GLuint mask, |
| 1894 | GLenum coverMode, |
| 1895 | GLenum transformType, |
| 1896 | const GLfloat *transformValues) |
| 1897 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1898 | const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1899 | |
| 1900 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1901 | syncRendererState(); |
| 1902 | |
| 1903 | mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask, |
| 1904 | transformType, transformValues); |
| 1905 | } |
| 1906 | |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1907 | void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name) |
| 1908 | { |
| 1909 | auto *programObject = getProgram(program); |
| 1910 | |
| 1911 | programObject->bindFragmentInputLocation(location, name); |
| 1912 | } |
| 1913 | |
| 1914 | void Context::programPathFragmentInputGen(GLuint program, |
| 1915 | GLint location, |
| 1916 | GLenum genMode, |
| 1917 | GLint components, |
| 1918 | const GLfloat *coeffs) |
| 1919 | { |
| 1920 | auto *programObject = getProgram(program); |
| 1921 | |
| 1922 | programObject->pathFragmentInputGen(location, genMode, components, coeffs); |
| 1923 | } |
| 1924 | |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 1925 | void Context::handleError(const Error &error) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1926 | { |
Geoff Lang | da5777c | 2014-07-11 09:52:58 -0400 | [diff] [blame] | 1927 | if (error.isError()) |
| 1928 | { |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 1929 | GLenum code = error.getCode(); |
| 1930 | mErrors.insert(code); |
| 1931 | if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory) |
| 1932 | { |
| 1933 | markContextLost(); |
| 1934 | } |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1935 | |
| 1936 | if (!error.getMessage().empty()) |
| 1937 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1938 | auto *debug = &mGLState.getDebug(); |
| 1939 | debug->insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(), |
| 1940 | GL_DEBUG_SEVERITY_HIGH, error.getMessage()); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1941 | } |
Geoff Lang | da5777c | 2014-07-11 09:52:58 -0400 | [diff] [blame] | 1942 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | // Get one of the recorded errors and clear its flag, if any. |
| 1946 | // [OpenGL ES 2.0.24] section 2.5 page 13. |
| 1947 | GLenum Context::getError() |
| 1948 | { |
Geoff Lang | da5777c | 2014-07-11 09:52:58 -0400 | [diff] [blame] | 1949 | if (mErrors.empty()) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1950 | { |
Geoff Lang | da5777c | 2014-07-11 09:52:58 -0400 | [diff] [blame] | 1951 | return GL_NO_ERROR; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1952 | } |
Geoff Lang | da5777c | 2014-07-11 09:52:58 -0400 | [diff] [blame] | 1953 | else |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1954 | { |
Geoff Lang | da5777c | 2014-07-11 09:52:58 -0400 | [diff] [blame] | 1955 | GLenum error = *mErrors.begin(); |
| 1956 | mErrors.erase(mErrors.begin()); |
| 1957 | return error; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1958 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1959 | } |
| 1960 | |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 1961 | // NOTE: this function should not assume that this context is current! |
| 1962 | void Context::markContextLost() |
| 1963 | { |
| 1964 | if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT) |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 1965 | { |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 1966 | mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT; |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 1967 | mContextLostForced = true; |
| 1968 | } |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 1969 | mContextLost = true; |
| 1970 | } |
| 1971 | |
| 1972 | bool Context::isContextLost() |
| 1973 | { |
| 1974 | return mContextLost; |
| 1975 | } |
| 1976 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1977 | GLenum Context::getResetStatus() |
| 1978 | { |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 1979 | // Even if the application doesn't want to know about resets, we want to know |
| 1980 | // as it will allow us to skip all the calls. |
| 1981 | if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1982 | { |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 1983 | if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR) |
Jamie Madill | 9dd0cf0 | 2014-11-24 11:38:51 -0500 | [diff] [blame] | 1984 | { |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 1985 | mContextLost = true; |
Jamie Madill | 9dd0cf0 | 2014-11-24 11:38:51 -0500 | [diff] [blame] | 1986 | } |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 1987 | |
| 1988 | // EXT_robustness, section 2.6: If the reset notification behavior is |
| 1989 | // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of |
| 1990 | // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR. |
| 1991 | return GL_NO_ERROR; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1992 | } |
| 1993 | |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 1994 | // The GL_EXT_robustness spec says that if a reset is encountered, a reset |
| 1995 | // status should be returned at least once, and GL_NO_ERROR should be returned |
| 1996 | // once the device has finished resetting. |
| 1997 | if (!mContextLost) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1998 | { |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 1999 | ASSERT(mResetStatus == GL_NO_ERROR); |
| 2000 | mResetStatus = mImplementation->getResetStatus(); |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 2001 | |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2002 | if (mResetStatus != GL_NO_ERROR) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2003 | { |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2004 | mContextLost = true; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2005 | } |
| 2006 | } |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 2007 | else if (!mContextLostForced && mResetStatus != GL_NO_ERROR) |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2008 | { |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 2009 | // If markContextLost was used to mark the context lost then |
| 2010 | // assume that is not recoverable, and continue to report the |
| 2011 | // lost reset status for the lifetime of this context. |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2012 | mResetStatus = mImplementation->getResetStatus(); |
| 2013 | } |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2014 | |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2015 | return mResetStatus; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | bool Context::isResetNotificationEnabled() |
| 2019 | { |
| 2020 | return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT); |
| 2021 | } |
| 2022 | |
Corentin Wallez | e3b10e8 | 2015-05-20 11:06:25 -0400 | [diff] [blame] | 2023 | const egl::Config *Context::getConfig() const |
Régis Fénéon | 8310797 | 2015-02-05 12:57:44 +0100 | [diff] [blame] | 2024 | { |
Corentin Wallez | e3b10e8 | 2015-05-20 11:06:25 -0400 | [diff] [blame] | 2025 | return mConfig; |
Régis Fénéon | 8310797 | 2015-02-05 12:57:44 +0100 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | EGLenum Context::getClientType() const |
| 2029 | { |
| 2030 | return mClientType; |
| 2031 | } |
| 2032 | |
| 2033 | EGLenum Context::getRenderBuffer() const |
| 2034 | { |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame^] | 2035 | const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0); |
| 2036 | if (framebuffer == nullptr) |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 2037 | { |
| 2038 | return EGL_NONE; |
| 2039 | } |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame^] | 2040 | |
| 2041 | const FramebufferAttachment *backAttachment = framebuffer->getAttachment(GL_BACK); |
| 2042 | ASSERT(backAttachment != nullptr); |
| 2043 | return backAttachment->getSurface()->getRenderBuffer(); |
Régis Fénéon | 8310797 | 2015-02-05 12:57:44 +0100 | [diff] [blame] | 2044 | } |
| 2045 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 2046 | VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle) |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2047 | { |
Jamie Madill | 5bf9ff4 | 2016-02-01 11:13:03 -0500 | [diff] [blame] | 2048 | // Only called after a prior call to Gen. |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 2049 | VertexArray *vertexArray = getVertexArray(vertexArrayHandle); |
| 2050 | if (!vertexArray) |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2051 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 2052 | vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle, MAX_VERTEX_ATTRIBS); |
| 2053 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 2054 | mVertexArrayMap[vertexArrayHandle] = vertexArray; |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2055 | } |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 2056 | |
| 2057 | return vertexArray; |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2058 | } |
| 2059 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 2060 | TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle) |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2061 | { |
Jamie Madill | 5bf9ff4 | 2016-02-01 11:13:03 -0500 | [diff] [blame] | 2062 | // Only called after a prior call to Gen. |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 2063 | TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle); |
| 2064 | if (!transformFeedback) |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2065 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 2066 | transformFeedback = |
| 2067 | new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps); |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 2068 | transformFeedback->addRef(); |
| 2069 | mTransformFeedbackMap[transformFeedbackHandle] = transformFeedback; |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2070 | } |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 2071 | |
| 2072 | return transformFeedback; |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2073 | } |
| 2074 | |
| 2075 | bool Context::isVertexArrayGenerated(GLuint vertexArray) |
| 2076 | { |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 2077 | ASSERT(mVertexArrayMap.find(0) != mVertexArrayMap.end()); |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2078 | return mVertexArrayMap.find(vertexArray) != mVertexArrayMap.end(); |
| 2079 | } |
| 2080 | |
| 2081 | bool Context::isTransformFeedbackGenerated(GLuint transformFeedback) |
| 2082 | { |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 2083 | ASSERT(mTransformFeedbackMap.find(0) != mTransformFeedbackMap.end()); |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2084 | return mTransformFeedbackMap.find(transformFeedback) != mTransformFeedbackMap.end(); |
| 2085 | } |
| 2086 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2087 | void Context::detachTexture(GLuint texture) |
| 2088 | { |
| 2089 | // Simple pass-through to State's detachTexture method, as textures do not require |
| 2090 | // allocation map management either here or in the resource manager at detach time. |
| 2091 | // Zero textures are held by the Context, and we don't attempt to request them from |
| 2092 | // the State. |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2093 | mGLState.detachTexture(mZeroTextures, texture); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2094 | } |
| 2095 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2096 | void Context::detachBuffer(GLuint buffer) |
| 2097 | { |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 2098 | // Simple pass-through to State's detachBuffer method, since |
| 2099 | // only buffer attachments to container objects that are bound to the current context |
| 2100 | // should be detached. And all those are available in State. |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2101 | |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 2102 | // [OpenGL ES 3.2] section 5.1.2 page 45: |
| 2103 | // Attachments to unbound container objects, such as |
| 2104 | // deletion of a buffer attached to a vertex array object which is not bound to the context, |
| 2105 | // are not affected and continue to act as references on the deleted object |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2106 | mGLState.detachBuffer(buffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2107 | } |
| 2108 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2109 | void Context::detachFramebuffer(GLuint framebuffer) |
| 2110 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2111 | // Framebuffer detachment is handled by Context, because 0 is a valid |
| 2112 | // Framebuffer object, and a pointer to it must be passed from Context |
| 2113 | // to State at binding time. |
| 2114 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2115 | // [OpenGL ES 2.0.24] section 4.4 page 107: |
| 2116 | // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as though |
| 2117 | // BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of zero. |
| 2118 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2119 | if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2120 | { |
| 2121 | bindReadFramebuffer(0); |
| 2122 | } |
| 2123 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2124 | if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2125 | { |
| 2126 | bindDrawFramebuffer(0); |
| 2127 | } |
| 2128 | } |
| 2129 | |
| 2130 | void Context::detachRenderbuffer(GLuint renderbuffer) |
| 2131 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2132 | mGLState.detachRenderbuffer(renderbuffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2133 | } |
| 2134 | |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 2135 | void Context::detachVertexArray(GLuint vertexArray) |
| 2136 | { |
Jamie Madill | 77a72f6 | 2015-04-14 11:18:32 -0400 | [diff] [blame] | 2137 | // Vertex array detachment is handled by Context, because 0 is a valid |
| 2138 | // 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] | 2139 | // binding time. |
| 2140 | |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 2141 | // [OpenGL ES 3.0.2] section 2.10 page 43: |
| 2142 | // If a vertex array object that is currently bound is deleted, the binding |
| 2143 | // 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] | 2144 | if (mGLState.removeVertexArrayBinding(vertexArray)) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 2145 | { |
| 2146 | bindVertexArray(0); |
| 2147 | } |
| 2148 | } |
| 2149 | |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 2150 | void Context::detachTransformFeedback(GLuint transformFeedback) |
| 2151 | { |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 2152 | // Transform feedback detachment is handled by Context, because 0 is a valid |
| 2153 | // transform feedback, and a pointer to it must be passed from Context to State at |
| 2154 | // binding time. |
| 2155 | |
| 2156 | // The OpenGL specification doesn't mention what should happen when the currently bound |
| 2157 | // transform feedback object is deleted. Since it is a container object, we treat it like |
| 2158 | // VAOs and FBOs and set the current bound transform feedback back to 0. |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2159 | if (mGLState.removeTransformFeedbackBinding(transformFeedback)) |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 2160 | { |
| 2161 | bindTransformFeedback(0); |
| 2162 | } |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 2163 | } |
| 2164 | |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 2165 | void Context::detachSampler(GLuint sampler) |
| 2166 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2167 | mGLState.detachSampler(sampler); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 2168 | } |
| 2169 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2170 | void Context::setVertexAttribDivisor(GLuint index, GLuint divisor) |
| 2171 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2172 | mGLState.setVertexAttribDivisor(index, divisor); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2173 | } |
| 2174 | |
Jamie Madill | e29d167 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 2175 | void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param) |
| 2176 | { |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2177 | Sampler *samplerObject = |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 2178 | mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2179 | SetSamplerParameteri(samplerObject, pname, param); |
| 2180 | } |
Jamie Madill | e29d167 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 2181 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2182 | void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param) |
| 2183 | { |
| 2184 | Sampler *samplerObject = |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 2185 | mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2186 | SetSamplerParameteriv(samplerObject, pname, param); |
Jamie Madill | e29d167 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 2187 | } |
| 2188 | |
| 2189 | void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param) |
| 2190 | { |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2191 | Sampler *samplerObject = |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 2192 | mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2193 | SetSamplerParameterf(samplerObject, pname, param); |
Jamie Madill | e29d167 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 2194 | } |
| 2195 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2196 | void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param) |
Jamie Madill | 9675b80 | 2013-07-19 16:36:59 -0400 | [diff] [blame] | 2197 | { |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2198 | Sampler *samplerObject = |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 2199 | mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2200 | SetSamplerParameterfv(samplerObject, pname, param); |
Jamie Madill | 9675b80 | 2013-07-19 16:36:59 -0400 | [diff] [blame] | 2201 | } |
| 2202 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2203 | void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params) |
Jamie Madill | 9675b80 | 2013-07-19 16:36:59 -0400 | [diff] [blame] | 2204 | { |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2205 | const Sampler *samplerObject = |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 2206 | mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2207 | QuerySamplerParameteriv(samplerObject, pname, params); |
| 2208 | } |
Jamie Madill | 9675b80 | 2013-07-19 16:36:59 -0400 | [diff] [blame] | 2209 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2210 | void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params) |
| 2211 | { |
| 2212 | const Sampler *samplerObject = |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 2213 | mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2214 | QuerySamplerParameterfv(samplerObject, pname, params); |
Jamie Madill | 9675b80 | 2013-07-19 16:36:59 -0400 | [diff] [blame] | 2215 | } |
| 2216 | |
Olli Etuaho | f0fee07 | 2016-03-30 15:11:58 +0300 | [diff] [blame] | 2217 | void Context::programParameteri(GLuint program, GLenum pname, GLint value) |
| 2218 | { |
| 2219 | gl::Program *programObject = getProgram(program); |
| 2220 | ASSERT(programObject != nullptr); |
| 2221 | |
| 2222 | ASSERT(pname == GL_PROGRAM_BINARY_RETRIEVABLE_HINT); |
| 2223 | programObject->setBinaryRetrievableHint(value != GL_FALSE); |
| 2224 | } |
| 2225 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2226 | void Context::initRendererString() |
| 2227 | { |
daniel@transgaming.com | ca1ac1f | 2013-01-11 04:13:05 +0000 | [diff] [blame] | 2228 | std::ostringstream rendererString; |
| 2229 | rendererString << "ANGLE ("; |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 2230 | rendererString << mImplementation->getRendererDescription(); |
daniel@transgaming.com | ca1ac1f | 2013-01-11 04:13:05 +0000 | [diff] [blame] | 2231 | rendererString << ")"; |
| 2232 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2233 | mRendererString = MakeStaticString(rendererString.str()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2234 | } |
| 2235 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2236 | void Context::initVersionStrings() |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2237 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2238 | const Version &clientVersion = getClientVersion(); |
| 2239 | |
| 2240 | std::ostringstream versionString; |
| 2241 | versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE " |
| 2242 | << ANGLE_VERSION_STRING << ")"; |
| 2243 | mVersionString = MakeStaticString(versionString.str()); |
| 2244 | |
| 2245 | std::ostringstream shadingLanguageVersionString; |
| 2246 | shadingLanguageVersionString << "OpenGL ES GLSL ES " |
| 2247 | << (clientVersion.major == 2 ? 1 : clientVersion.major) << "." |
| 2248 | << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING |
| 2249 | << ")"; |
| 2250 | mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2251 | } |
| 2252 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2253 | void Context::initExtensionStrings() |
| 2254 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2255 | auto mergeExtensionStrings = [](const std::vector<const char *> &strings) { |
| 2256 | std::ostringstream combinedStringStream; |
| 2257 | std::copy(strings.begin(), strings.end(), |
| 2258 | std::ostream_iterator<const char *>(combinedStringStream, " ")); |
| 2259 | return MakeStaticString(combinedStringStream.str()); |
| 2260 | }; |
| 2261 | |
| 2262 | mExtensionStrings.clear(); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 2263 | for (const auto &extensionString : mExtensions.getStrings()) |
| 2264 | { |
| 2265 | mExtensionStrings.push_back(MakeStaticString(extensionString)); |
| 2266 | } |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2267 | mExtensionString = mergeExtensionStrings(mExtensionStrings); |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2268 | |
Bryan Bernhart | 5880656 | 2017-01-05 13:09:31 -0800 | [diff] [blame] | 2269 | const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions(); |
| 2270 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2271 | mRequestableExtensionStrings.clear(); |
| 2272 | for (const auto &extensionInfo : GetExtensionInfoMap()) |
| 2273 | { |
| 2274 | if (extensionInfo.second.Requestable && |
Bryan Bernhart | 5880656 | 2017-01-05 13:09:31 -0800 | [diff] [blame] | 2275 | !(mExtensions.*(extensionInfo.second.ExtensionsMember)) && |
| 2276 | nativeExtensions.*(extensionInfo.second.ExtensionsMember)) |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2277 | { |
| 2278 | mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first)); |
| 2279 | } |
| 2280 | } |
| 2281 | mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings); |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2282 | } |
| 2283 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2284 | const GLubyte *Context::getString(GLenum name) const |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2285 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2286 | switch (name) |
| 2287 | { |
| 2288 | case GL_VENDOR: |
| 2289 | return reinterpret_cast<const GLubyte *>("Google Inc."); |
| 2290 | |
| 2291 | case GL_RENDERER: |
| 2292 | return reinterpret_cast<const GLubyte *>(mRendererString); |
| 2293 | |
| 2294 | case GL_VERSION: |
| 2295 | return reinterpret_cast<const GLubyte *>(mVersionString); |
| 2296 | |
| 2297 | case GL_SHADING_LANGUAGE_VERSION: |
| 2298 | return reinterpret_cast<const GLubyte *>(mShadingLanguageString); |
| 2299 | |
| 2300 | case GL_EXTENSIONS: |
| 2301 | return reinterpret_cast<const GLubyte *>(mExtensionString); |
| 2302 | |
| 2303 | case GL_REQUESTABLE_EXTENSIONS_ANGLE: |
| 2304 | return reinterpret_cast<const GLubyte *>(mRequestableExtensionString); |
| 2305 | |
| 2306 | default: |
| 2307 | UNREACHABLE(); |
| 2308 | return nullptr; |
| 2309 | } |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2310 | } |
| 2311 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2312 | const GLubyte *Context::getStringi(GLenum name, GLuint index) const |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2313 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2314 | switch (name) |
| 2315 | { |
| 2316 | case GL_EXTENSIONS: |
| 2317 | return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]); |
| 2318 | |
| 2319 | case GL_REQUESTABLE_EXTENSIONS_ANGLE: |
| 2320 | return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]); |
| 2321 | |
| 2322 | default: |
| 2323 | UNREACHABLE(); |
| 2324 | return nullptr; |
| 2325 | } |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2326 | } |
| 2327 | |
| 2328 | size_t Context::getExtensionStringCount() const |
| 2329 | { |
| 2330 | return mExtensionStrings.size(); |
| 2331 | } |
| 2332 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2333 | void Context::requestExtension(const char *name) |
| 2334 | { |
| 2335 | const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap(); |
| 2336 | ASSERT(extensionInfos.find(name) != extensionInfos.end()); |
| 2337 | const auto &extension = extensionInfos.at(name); |
| 2338 | ASSERT(extension.Requestable); |
| 2339 | |
| 2340 | if (mExtensions.*(extension.ExtensionsMember)) |
| 2341 | { |
| 2342 | // Extension already enabled |
| 2343 | return; |
| 2344 | } |
| 2345 | |
| 2346 | mExtensions.*(extension.ExtensionsMember) = true; |
| 2347 | updateCaps(); |
| 2348 | initExtensionStrings(); |
Bryan Bernhart | 5880656 | 2017-01-05 13:09:31 -0800 | [diff] [blame] | 2349 | |
| 2350 | // Re-create the compiler with the requested extensions enabled. |
| 2351 | SafeDelete(mCompiler); |
| 2352 | mCompiler = new Compiler(mImplementation.get(), mState); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2353 | } |
| 2354 | |
| 2355 | size_t Context::getRequestableExtensionStringCount() const |
| 2356 | { |
| 2357 | return mRequestableExtensionStrings.size(); |
| 2358 | } |
| 2359 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2360 | void Context::beginTransformFeedback(GLenum primitiveMode) |
| 2361 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2362 | TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback(); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2363 | ASSERT(transformFeedback != nullptr); |
| 2364 | ASSERT(!transformFeedback->isPaused()); |
| 2365 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2366 | transformFeedback->begin(primitiveMode, mGLState.getProgram()); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2367 | } |
| 2368 | |
| 2369 | bool Context::hasActiveTransformFeedback(GLuint program) const |
| 2370 | { |
| 2371 | for (auto pair : mTransformFeedbackMap) |
| 2372 | { |
| 2373 | if (pair.second != nullptr && pair.second->hasBoundProgram(program)) |
| 2374 | { |
| 2375 | return true; |
| 2376 | } |
| 2377 | } |
| 2378 | return false; |
| 2379 | } |
| 2380 | |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 2381 | void Context::initCaps(bool webGLContext) |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2382 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 2383 | mCaps = mImplementation->getNativeCaps(); |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2384 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 2385 | mExtensions = mImplementation->getNativeExtensions(); |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2386 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 2387 | mLimitations = mImplementation->getNativeLimitations(); |
Austin Kinross | 02df796 | 2015-07-01 10:03:42 -0700 | [diff] [blame] | 2388 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2389 | if (getClientVersion() < Version(3, 0)) |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2390 | { |
| 2391 | // Disable ES3+ extensions |
| 2392 | mExtensions.colorBufferFloat = false; |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 2393 | mExtensions.eglImageExternalEssl3 = false; |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 2394 | mExtensions.textureNorm16 = false; |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2395 | } |
| 2396 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2397 | if (getClientVersion() > Version(2, 0)) |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2398 | { |
| 2399 | // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts |
| 2400 | //mExtensions.sRGB = false; |
| 2401 | } |
| 2402 | |
Jamie Madill | 00ed7a1 | 2016-05-19 13:13:38 -0400 | [diff] [blame] | 2403 | // Some extensions are always available because they are implemented in the GL layer. |
| 2404 | mExtensions.bindUniformLocation = true; |
| 2405 | mExtensions.vertexArrayObject = true; |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 2406 | mExtensions.bindGeneratesResource = true; |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2407 | mExtensions.requestExtension = true; |
Jamie Madill | 00ed7a1 | 2016-05-19 13:13:38 -0400 | [diff] [blame] | 2408 | |
| 2409 | // Enable the no error extension if the context was created with the flag. |
| 2410 | mExtensions.noError = mSkipValidation; |
| 2411 | |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 2412 | // Enable surfaceless to advertise we'll have the correct behavior when there is no default FBO |
| 2413 | mExtensions.surfacelessContext = true; |
| 2414 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2415 | // Explicitly enable GL_KHR_debug |
| 2416 | mExtensions.debug = true; |
| 2417 | mExtensions.maxDebugMessageLength = 1024; |
| 2418 | mExtensions.maxDebugLoggedMessages = 1024; |
| 2419 | mExtensions.maxDebugGroupStackDepth = 1024; |
| 2420 | mExtensions.maxLabelLength = 1024; |
| 2421 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2422 | // Explicitly enable GL_ANGLE_robust_client_memory |
| 2423 | mExtensions.robustClientMemory = true; |
| 2424 | |
Geoff Lang | 301d161 | 2014-07-09 10:34:37 -0400 | [diff] [blame] | 2425 | // Apply implementation limits |
| 2426 | mCaps.maxVertexAttributes = std::min<GLuint>(mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS); |
Geoff Lang | 301d161 | 2014-07-09 10:34:37 -0400 | [diff] [blame] | 2427 | mCaps.maxVertexUniformBlocks = std::min<GLuint>(mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS); |
| 2428 | mCaps.maxVertexOutputComponents = std::min<GLuint>(mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4); |
| 2429 | |
| 2430 | mCaps.maxFragmentInputComponents = std::min<GLuint>(mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4); |
Geoff Lang | 3a61c32 | 2014-07-10 13:01:54 -0400 | [diff] [blame] | 2431 | |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 2432 | // WebGL compatibility |
| 2433 | mExtensions.webglCompatibility = webGLContext; |
| 2434 | for (const auto &extensionInfo : GetExtensionInfoMap()) |
| 2435 | { |
| 2436 | // If this context is for WebGL, disable all enableable extensions |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2437 | if (webGLContext && extensionInfo.second.Requestable) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 2438 | { |
| 2439 | mExtensions.*(extensionInfo.second.ExtensionsMember) = false; |
| 2440 | } |
| 2441 | } |
| 2442 | |
| 2443 | // Generate texture caps |
| 2444 | updateCaps(); |
| 2445 | } |
| 2446 | |
| 2447 | void Context::updateCaps() |
| 2448 | { |
Geoff Lang | 900013c | 2014-07-07 11:32:19 -0400 | [diff] [blame] | 2449 | mCaps.compressedTextureFormats.clear(); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 2450 | mTextureCaps.clear(); |
Geoff Lang | 900013c | 2014-07-07 11:32:19 -0400 | [diff] [blame] | 2451 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 2452 | const TextureCapsMap &rendererFormats = mImplementation->getNativeTextureCaps(); |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2453 | for (TextureCapsMap::const_iterator i = rendererFormats.begin(); i != rendererFormats.end(); i++) |
| 2454 | { |
| 2455 | GLenum format = i->first; |
| 2456 | TextureCaps formatCaps = i->second; |
| 2457 | |
Geoff Lang | 5d60138 | 2014-07-22 15:14:06 -0400 | [diff] [blame] | 2458 | const InternalFormat &formatInfo = GetInternalFormatInfo(format); |
Geoff Lang | d87878e | 2014-09-19 15:42:59 -0400 | [diff] [blame] | 2459 | |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 2460 | // Update the format caps based on the client version and extensions. |
| 2461 | // Caps are AND'd with the renderer caps because some core formats are still unsupported in |
| 2462 | // ES3. |
| 2463 | formatCaps.texturable = |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2464 | formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions); |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 2465 | formatCaps.renderable = |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2466 | formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions); |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 2467 | formatCaps.filterable = |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2468 | formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions); |
Geoff Lang | d87878e | 2014-09-19 15:42:59 -0400 | [diff] [blame] | 2469 | |
He Yunchao | ccd8c9b | 2017-01-18 17:36:14 +0800 | [diff] [blame] | 2470 | // OpenGL ES does not support multisampling with non-rendererable formats |
| 2471 | // OpenGL ES 3.0 or prior does not support multisampling with integer formats |
| 2472 | if (!formatInfo.renderSupport || |
| 2473 | (getClientVersion() < ES_3_1 && |
| 2474 | (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT))) |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2475 | { |
Geoff Lang | d87878e | 2014-09-19 15:42:59 -0400 | [diff] [blame] | 2476 | formatCaps.sampleCounts.clear(); |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2477 | } |
Geoff Lang | d87878e | 2014-09-19 15:42:59 -0400 | [diff] [blame] | 2478 | |
| 2479 | if (formatCaps.texturable && formatInfo.compressed) |
| 2480 | { |
| 2481 | mCaps.compressedTextureFormats.push_back(format); |
| 2482 | } |
| 2483 | |
| 2484 | mTextureCaps.insert(format, formatCaps); |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2485 | } |
| 2486 | } |
| 2487 | |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 2488 | void Context::initWorkarounds() |
| 2489 | { |
| 2490 | // Lose the context upon out of memory error if the application is |
| 2491 | // expecting to watch for those events. |
| 2492 | mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT); |
| 2493 | } |
| 2494 | |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 2495 | void Context::syncRendererState() |
| 2496 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2497 | const State::DirtyBits &dirtyBits = mGLState.getDirtyBits(); |
| 2498 | mImplementation->syncState(mGLState, dirtyBits); |
| 2499 | mGLState.clearDirtyBits(); |
| 2500 | mGLState.syncDirtyObjects(); |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 2501 | } |
| 2502 | |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2503 | void Context::syncRendererState(const State::DirtyBits &bitMask, |
| 2504 | const State::DirtyObjects &objectMask) |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 2505 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2506 | const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask); |
| 2507 | mImplementation->syncState(mGLState, dirtyBits); |
| 2508 | mGLState.clearDirtyBits(dirtyBits); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2509 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2510 | mGLState.syncDirtyObjects(objectMask); |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 2511 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2512 | |
| 2513 | void Context::blitFramebuffer(GLint srcX0, |
| 2514 | GLint srcY0, |
| 2515 | GLint srcX1, |
| 2516 | GLint srcY1, |
| 2517 | GLint dstX0, |
| 2518 | GLint dstY0, |
| 2519 | GLint dstX1, |
| 2520 | GLint dstY1, |
| 2521 | GLbitfield mask, |
| 2522 | GLenum filter) |
| 2523 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2524 | Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2525 | ASSERT(drawFramebuffer); |
| 2526 | |
| 2527 | Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0); |
| 2528 | Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0); |
| 2529 | |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2530 | syncStateForBlit(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2531 | |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 2532 | handleError(drawFramebuffer->blit(mImplementation.get(), srcArea, dstArea, mask, filter)); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2533 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2534 | |
| 2535 | void Context::clear(GLbitfield mask) |
| 2536 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2537 | syncStateForClear(); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2538 | handleError(mGLState.getDrawFramebuffer()->clear(mImplementation.get(), mask)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2539 | } |
| 2540 | |
| 2541 | void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values) |
| 2542 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2543 | syncStateForClear(); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2544 | handleError(mGLState.getDrawFramebuffer()->clearBufferfv(mImplementation.get(), buffer, |
| 2545 | drawbuffer, values)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2546 | } |
| 2547 | |
| 2548 | void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values) |
| 2549 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2550 | syncStateForClear(); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2551 | handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(mImplementation.get(), buffer, |
| 2552 | drawbuffer, values)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2553 | } |
| 2554 | |
| 2555 | void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values) |
| 2556 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2557 | syncStateForClear(); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2558 | handleError(mGLState.getDrawFramebuffer()->clearBufferiv(mImplementation.get(), buffer, |
| 2559 | drawbuffer, values)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2560 | } |
| 2561 | |
| 2562 | void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil) |
| 2563 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2564 | Framebuffer *framebufferObject = mGLState.getDrawFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2565 | ASSERT(framebufferObject); |
| 2566 | |
| 2567 | // If a buffer is not present, the clear has no effect |
| 2568 | if (framebufferObject->getDepthbuffer() == nullptr && |
| 2569 | framebufferObject->getStencilbuffer() == nullptr) |
| 2570 | { |
| 2571 | return; |
| 2572 | } |
| 2573 | |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2574 | syncStateForClear(); |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 2575 | handleError(framebufferObject->clearBufferfi(mImplementation.get(), buffer, drawbuffer, depth, |
| 2576 | stencil)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2577 | } |
| 2578 | |
| 2579 | void Context::readPixels(GLint x, |
| 2580 | GLint y, |
| 2581 | GLsizei width, |
| 2582 | GLsizei height, |
| 2583 | GLenum format, |
| 2584 | GLenum type, |
| 2585 | GLvoid *pixels) |
| 2586 | { |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 2587 | if (width == 0 || height == 0) |
| 2588 | { |
| 2589 | return; |
| 2590 | } |
| 2591 | |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2592 | syncStateForReadPixels(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2593 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2594 | Framebuffer *framebufferObject = mGLState.getReadFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2595 | ASSERT(framebufferObject); |
| 2596 | |
| 2597 | Rectangle area(x, y, width, height); |
Jamie Madill | 8415b5f | 2016-04-26 13:41:39 -0400 | [diff] [blame] | 2598 | handleError(framebufferObject->readPixels(mImplementation.get(), area, format, type, pixels)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2599 | } |
| 2600 | |
| 2601 | void Context::copyTexImage2D(GLenum target, |
| 2602 | GLint level, |
| 2603 | GLenum internalformat, |
| 2604 | GLint x, |
| 2605 | GLint y, |
| 2606 | GLsizei width, |
| 2607 | GLsizei height, |
| 2608 | GLint border) |
| 2609 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2610 | // Only sync the read FBO |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2611 | mGLState.syncDirtyObject(GL_READ_FRAMEBUFFER); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2612 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2613 | Rectangle sourceArea(x, y, width, height); |
| 2614 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2615 | const Framebuffer *framebuffer = mGLState.getReadFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2616 | Texture *texture = |
| 2617 | getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2618 | handleError(texture->copyImage(target, level, sourceArea, internalformat, framebuffer)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2619 | } |
| 2620 | |
| 2621 | void Context::copyTexSubImage2D(GLenum target, |
| 2622 | GLint level, |
| 2623 | GLint xoffset, |
| 2624 | GLint yoffset, |
| 2625 | GLint x, |
| 2626 | GLint y, |
| 2627 | GLsizei width, |
| 2628 | GLsizei height) |
| 2629 | { |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 2630 | if (width == 0 || height == 0) |
| 2631 | { |
| 2632 | return; |
| 2633 | } |
| 2634 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2635 | // Only sync the read FBO |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2636 | mGLState.syncDirtyObject(GL_READ_FRAMEBUFFER); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2637 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2638 | Offset destOffset(xoffset, yoffset, 0); |
| 2639 | Rectangle sourceArea(x, y, width, height); |
| 2640 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2641 | const Framebuffer *framebuffer = mGLState.getReadFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2642 | Texture *texture = |
| 2643 | getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2644 | handleError(texture->copySubImage(target, level, destOffset, sourceArea, framebuffer)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2645 | } |
| 2646 | |
| 2647 | void Context::copyTexSubImage3D(GLenum target, |
| 2648 | GLint level, |
| 2649 | GLint xoffset, |
| 2650 | GLint yoffset, |
| 2651 | GLint zoffset, |
| 2652 | GLint x, |
| 2653 | GLint y, |
| 2654 | GLsizei width, |
| 2655 | GLsizei height) |
| 2656 | { |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 2657 | if (width == 0 || height == 0) |
| 2658 | { |
| 2659 | return; |
| 2660 | } |
| 2661 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2662 | // Only sync the read FBO |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2663 | mGLState.syncDirtyObject(GL_READ_FRAMEBUFFER); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2664 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2665 | Offset destOffset(xoffset, yoffset, zoffset); |
| 2666 | Rectangle sourceArea(x, y, width, height); |
| 2667 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2668 | const Framebuffer *framebuffer = mGLState.getReadFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2669 | Texture *texture = getTargetTexture(target); |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2670 | handleError(texture->copySubImage(target, level, destOffset, sourceArea, framebuffer)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2671 | } |
| 2672 | |
| 2673 | void Context::framebufferTexture2D(GLenum target, |
| 2674 | GLenum attachment, |
| 2675 | GLenum textarget, |
| 2676 | GLuint texture, |
| 2677 | GLint level) |
| 2678 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2679 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2680 | ASSERT(framebuffer); |
| 2681 | |
| 2682 | if (texture != 0) |
| 2683 | { |
| 2684 | Texture *textureObj = getTexture(texture); |
| 2685 | |
| 2686 | ImageIndex index = ImageIndex::MakeInvalid(); |
| 2687 | |
| 2688 | if (textarget == GL_TEXTURE_2D) |
| 2689 | { |
| 2690 | index = ImageIndex::Make2D(level); |
| 2691 | } |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 2692 | else if (textarget == GL_TEXTURE_2D_MULTISAMPLE) |
| 2693 | { |
| 2694 | ASSERT(level == 0); |
| 2695 | index = ImageIndex::Make2DMultisample(); |
| 2696 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2697 | else |
| 2698 | { |
| 2699 | ASSERT(IsCubeMapTextureTarget(textarget)); |
| 2700 | index = ImageIndex::MakeCube(textarget, level); |
| 2701 | } |
| 2702 | |
| 2703 | framebuffer->setAttachment(GL_TEXTURE, attachment, index, textureObj); |
| 2704 | } |
| 2705 | else |
| 2706 | { |
| 2707 | framebuffer->resetAttachment(attachment); |
| 2708 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2709 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2710 | mGLState.setObjectDirty(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2711 | } |
| 2712 | |
| 2713 | void Context::framebufferRenderbuffer(GLenum target, |
| 2714 | GLenum attachment, |
| 2715 | GLenum renderbuffertarget, |
| 2716 | GLuint renderbuffer) |
| 2717 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2718 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2719 | ASSERT(framebuffer); |
| 2720 | |
| 2721 | if (renderbuffer != 0) |
| 2722 | { |
| 2723 | Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer); |
| 2724 | framebuffer->setAttachment(GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(), |
| 2725 | renderbufferObject); |
| 2726 | } |
| 2727 | else |
| 2728 | { |
| 2729 | framebuffer->resetAttachment(attachment); |
| 2730 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2731 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2732 | mGLState.setObjectDirty(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2733 | } |
| 2734 | |
| 2735 | void Context::framebufferTextureLayer(GLenum target, |
| 2736 | GLenum attachment, |
| 2737 | GLuint texture, |
| 2738 | GLint level, |
| 2739 | GLint layer) |
| 2740 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2741 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2742 | ASSERT(framebuffer); |
| 2743 | |
| 2744 | if (texture != 0) |
| 2745 | { |
| 2746 | Texture *textureObject = getTexture(texture); |
| 2747 | |
| 2748 | ImageIndex index = ImageIndex::MakeInvalid(); |
| 2749 | |
| 2750 | if (textureObject->getTarget() == GL_TEXTURE_3D) |
| 2751 | { |
| 2752 | index = ImageIndex::Make3D(level, layer); |
| 2753 | } |
| 2754 | else |
| 2755 | { |
| 2756 | ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY); |
| 2757 | index = ImageIndex::Make2DArray(level, layer); |
| 2758 | } |
| 2759 | |
| 2760 | framebuffer->setAttachment(GL_TEXTURE, attachment, index, textureObject); |
| 2761 | } |
| 2762 | else |
| 2763 | { |
| 2764 | framebuffer->resetAttachment(attachment); |
| 2765 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2766 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2767 | mGLState.setObjectDirty(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2768 | } |
| 2769 | |
| 2770 | void Context::drawBuffers(GLsizei n, const GLenum *bufs) |
| 2771 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2772 | Framebuffer *framebuffer = mGLState.getDrawFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2773 | ASSERT(framebuffer); |
| 2774 | framebuffer->setDrawBuffers(n, bufs); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2775 | mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2776 | } |
| 2777 | |
| 2778 | void Context::readBuffer(GLenum mode) |
| 2779 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2780 | Framebuffer *readFBO = mGLState.getReadFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2781 | readFBO->setReadBuffer(mode); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2782 | mGLState.setObjectDirty(GL_READ_FRAMEBUFFER); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2783 | } |
| 2784 | |
| 2785 | void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments) |
| 2786 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2787 | // Only sync the FBO |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2788 | mGLState.syncDirtyObject(target); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2789 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2790 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2791 | ASSERT(framebuffer); |
| 2792 | |
| 2793 | // The specification isn't clear what should be done when the framebuffer isn't complete. |
| 2794 | // We leave it up to the framebuffer implementation to decide what to do. |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2795 | handleError(framebuffer->discard(numAttachments, attachments)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2796 | } |
| 2797 | |
| 2798 | void Context::invalidateFramebuffer(GLenum target, |
| 2799 | GLsizei numAttachments, |
| 2800 | const GLenum *attachments) |
| 2801 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2802 | // Only sync the FBO |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2803 | mGLState.syncDirtyObject(target); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2804 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2805 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2806 | ASSERT(framebuffer); |
| 2807 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2808 | if (framebuffer->checkStatus(mState) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2809 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2810 | return; |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2811 | } |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2812 | |
| 2813 | handleError(framebuffer->invalidate(numAttachments, attachments)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2814 | } |
| 2815 | |
| 2816 | void Context::invalidateSubFramebuffer(GLenum target, |
| 2817 | GLsizei numAttachments, |
| 2818 | const GLenum *attachments, |
| 2819 | GLint x, |
| 2820 | GLint y, |
| 2821 | GLsizei width, |
| 2822 | GLsizei height) |
| 2823 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2824 | // Only sync the FBO |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2825 | mGLState.syncDirtyObject(target); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2826 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2827 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2828 | ASSERT(framebuffer); |
| 2829 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2830 | if (framebuffer->checkStatus(mState) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2831 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2832 | return; |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2833 | } |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2834 | |
| 2835 | Rectangle area(x, y, width, height); |
| 2836 | handleError(framebuffer->invalidateSub(numAttachments, attachments, area)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2837 | } |
| 2838 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2839 | void Context::texImage2D(GLenum target, |
| 2840 | GLint level, |
| 2841 | GLint internalformat, |
| 2842 | GLsizei width, |
| 2843 | GLsizei height, |
| 2844 | GLint border, |
| 2845 | GLenum format, |
| 2846 | GLenum type, |
| 2847 | const GLvoid *pixels) |
| 2848 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2849 | syncStateForTexImage(); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2850 | |
| 2851 | Extents size(width, height, 1); |
| 2852 | Texture *texture = |
| 2853 | getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2854 | handleError(texture->setImage(mGLState.getUnpackState(), target, level, internalformat, size, |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2855 | format, type, reinterpret_cast<const uint8_t *>(pixels))); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2856 | } |
| 2857 | |
| 2858 | void Context::texImage3D(GLenum target, |
| 2859 | GLint level, |
| 2860 | GLint internalformat, |
| 2861 | GLsizei width, |
| 2862 | GLsizei height, |
| 2863 | GLsizei depth, |
| 2864 | GLint border, |
| 2865 | GLenum format, |
| 2866 | GLenum type, |
| 2867 | const GLvoid *pixels) |
| 2868 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2869 | syncStateForTexImage(); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2870 | |
| 2871 | Extents size(width, height, depth); |
| 2872 | Texture *texture = getTargetTexture(target); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2873 | handleError(texture->setImage(mGLState.getUnpackState(), target, level, internalformat, size, |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2874 | format, type, reinterpret_cast<const uint8_t *>(pixels))); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2875 | } |
| 2876 | |
| 2877 | void Context::texSubImage2D(GLenum target, |
| 2878 | GLint level, |
| 2879 | GLint xoffset, |
| 2880 | GLint yoffset, |
| 2881 | GLsizei width, |
| 2882 | GLsizei height, |
| 2883 | GLenum format, |
| 2884 | GLenum type, |
| 2885 | const GLvoid *pixels) |
| 2886 | { |
| 2887 | // Zero sized uploads are valid but no-ops |
| 2888 | if (width == 0 || height == 0) |
| 2889 | { |
| 2890 | return; |
| 2891 | } |
| 2892 | |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2893 | syncStateForTexImage(); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2894 | |
| 2895 | Box area(xoffset, yoffset, 0, width, height, 1); |
| 2896 | Texture *texture = |
| 2897 | getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2898 | handleError(texture->setSubImage(mGLState.getUnpackState(), target, level, area, format, type, |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2899 | reinterpret_cast<const uint8_t *>(pixels))); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2900 | } |
| 2901 | |
| 2902 | void Context::texSubImage3D(GLenum target, |
| 2903 | GLint level, |
| 2904 | GLint xoffset, |
| 2905 | GLint yoffset, |
| 2906 | GLint zoffset, |
| 2907 | GLsizei width, |
| 2908 | GLsizei height, |
| 2909 | GLsizei depth, |
| 2910 | GLenum format, |
| 2911 | GLenum type, |
| 2912 | const GLvoid *pixels) |
| 2913 | { |
| 2914 | // Zero sized uploads are valid but no-ops |
| 2915 | if (width == 0 || height == 0 || depth == 0) |
| 2916 | { |
| 2917 | return; |
| 2918 | } |
| 2919 | |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2920 | syncStateForTexImage(); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2921 | |
| 2922 | Box area(xoffset, yoffset, zoffset, width, height, depth); |
| 2923 | Texture *texture = getTargetTexture(target); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2924 | handleError(texture->setSubImage(mGLState.getUnpackState(), target, level, area, format, type, |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2925 | reinterpret_cast<const uint8_t *>(pixels))); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2926 | } |
| 2927 | |
| 2928 | void Context::compressedTexImage2D(GLenum target, |
| 2929 | GLint level, |
| 2930 | GLenum internalformat, |
| 2931 | GLsizei width, |
| 2932 | GLsizei height, |
| 2933 | GLint border, |
| 2934 | GLsizei imageSize, |
| 2935 | const GLvoid *data) |
| 2936 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2937 | syncStateForTexImage(); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2938 | |
| 2939 | Extents size(width, height, 1); |
| 2940 | Texture *texture = |
| 2941 | getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2942 | handleError(texture->setCompressedImage(mGLState.getUnpackState(), target, level, |
| 2943 | internalformat, size, imageSize, |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2944 | reinterpret_cast<const uint8_t *>(data))); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2945 | } |
| 2946 | |
| 2947 | void Context::compressedTexImage3D(GLenum target, |
| 2948 | GLint level, |
| 2949 | GLenum internalformat, |
| 2950 | GLsizei width, |
| 2951 | GLsizei height, |
| 2952 | GLsizei depth, |
| 2953 | GLint border, |
| 2954 | GLsizei imageSize, |
| 2955 | const GLvoid *data) |
| 2956 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2957 | syncStateForTexImage(); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2958 | |
| 2959 | Extents size(width, height, depth); |
| 2960 | Texture *texture = getTargetTexture(target); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2961 | handleError(texture->setCompressedImage(mGLState.getUnpackState(), target, level, |
| 2962 | internalformat, size, imageSize, |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 2963 | reinterpret_cast<const uint8_t *>(data))); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2964 | } |
| 2965 | |
| 2966 | void Context::compressedTexSubImage2D(GLenum target, |
| 2967 | GLint level, |
| 2968 | GLint xoffset, |
| 2969 | GLint yoffset, |
| 2970 | GLsizei width, |
| 2971 | GLsizei height, |
| 2972 | GLenum format, |
| 2973 | GLsizei imageSize, |
| 2974 | const GLvoid *data) |
| 2975 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2976 | syncStateForTexImage(); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2977 | |
| 2978 | Box area(xoffset, yoffset, 0, width, height, 1); |
| 2979 | Texture *texture = |
| 2980 | getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2981 | handleError(texture->setCompressedSubImage(mGLState.getUnpackState(), target, level, area, |
| 2982 | format, imageSize, |
| 2983 | reinterpret_cast<const uint8_t *>(data))); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 2984 | } |
| 2985 | |
| 2986 | void Context::compressedTexSubImage3D(GLenum target, |
| 2987 | GLint level, |
| 2988 | GLint xoffset, |
| 2989 | GLint yoffset, |
| 2990 | GLint zoffset, |
| 2991 | GLsizei width, |
| 2992 | GLsizei height, |
| 2993 | GLsizei depth, |
| 2994 | GLenum format, |
| 2995 | GLsizei imageSize, |
| 2996 | const GLvoid *data) |
| 2997 | { |
| 2998 | // Zero sized uploads are valid but no-ops |
| 2999 | if (width == 0 || height == 0) |
| 3000 | { |
| 3001 | return; |
| 3002 | } |
| 3003 | |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 3004 | syncStateForTexImage(); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3005 | |
| 3006 | Box area(xoffset, yoffset, zoffset, width, height, depth); |
| 3007 | Texture *texture = getTargetTexture(target); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3008 | handleError(texture->setCompressedSubImage(mGLState.getUnpackState(), target, level, area, |
| 3009 | format, imageSize, |
| 3010 | reinterpret_cast<const uint8_t *>(data))); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3011 | } |
| 3012 | |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 3013 | void Context::generateMipmap(GLenum target) |
| 3014 | { |
| 3015 | Texture *texture = getTargetTexture(target); |
| 3016 | handleError(texture->generateMipmap()); |
| 3017 | } |
| 3018 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3019 | void Context::copyTextureCHROMIUM(GLuint sourceId, |
| 3020 | GLuint destId, |
| 3021 | GLint internalFormat, |
| 3022 | GLenum destType, |
| 3023 | GLboolean unpackFlipY, |
| 3024 | GLboolean unpackPremultiplyAlpha, |
| 3025 | GLboolean unpackUnmultiplyAlpha) |
| 3026 | { |
| 3027 | syncStateForTexImage(); |
| 3028 | |
| 3029 | gl::Texture *sourceTexture = getTexture(sourceId); |
| 3030 | gl::Texture *destTexture = getTexture(destId); |
| 3031 | handleError(destTexture->copyTexture(internalFormat, destType, unpackFlipY == GL_TRUE, |
| 3032 | unpackPremultiplyAlpha == GL_TRUE, |
| 3033 | unpackUnmultiplyAlpha == GL_TRUE, sourceTexture)); |
| 3034 | } |
| 3035 | |
| 3036 | void Context::copySubTextureCHROMIUM(GLuint sourceId, |
| 3037 | GLuint destId, |
| 3038 | GLint xoffset, |
| 3039 | GLint yoffset, |
| 3040 | GLint x, |
| 3041 | GLint y, |
| 3042 | GLsizei width, |
| 3043 | GLsizei height, |
| 3044 | GLboolean unpackFlipY, |
| 3045 | GLboolean unpackPremultiplyAlpha, |
| 3046 | GLboolean unpackUnmultiplyAlpha) |
| 3047 | { |
| 3048 | // Zero sized copies are valid but no-ops |
| 3049 | if (width == 0 || height == 0) |
| 3050 | { |
| 3051 | return; |
| 3052 | } |
| 3053 | |
| 3054 | syncStateForTexImage(); |
| 3055 | |
| 3056 | gl::Texture *sourceTexture = getTexture(sourceId); |
| 3057 | gl::Texture *destTexture = getTexture(destId); |
| 3058 | Offset offset(xoffset, yoffset, 0); |
| 3059 | Rectangle area(x, y, width, height); |
| 3060 | handleError(destTexture->copySubTexture(offset, area, unpackFlipY == GL_TRUE, |
| 3061 | unpackPremultiplyAlpha == GL_TRUE, |
| 3062 | unpackUnmultiplyAlpha == GL_TRUE, sourceTexture)); |
| 3063 | } |
| 3064 | |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 3065 | void Context::compressedCopyTextureCHROMIUM(GLuint sourceId, GLuint destId) |
| 3066 | { |
| 3067 | syncStateForTexImage(); |
| 3068 | |
| 3069 | gl::Texture *sourceTexture = getTexture(sourceId); |
| 3070 | gl::Texture *destTexture = getTexture(destId); |
| 3071 | handleError(destTexture->copyCompressedTexture(sourceTexture)); |
| 3072 | } |
| 3073 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3074 | void Context::getBufferPointerv(GLenum target, GLenum pname, void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3075 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3076 | Buffer *buffer = mGLState.getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3077 | ASSERT(buffer); |
| 3078 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3079 | QueryBufferPointerv(buffer, pname, params); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3080 | } |
| 3081 | |
| 3082 | GLvoid *Context::mapBuffer(GLenum target, GLenum access) |
| 3083 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3084 | Buffer *buffer = mGLState.getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3085 | ASSERT(buffer); |
| 3086 | |
| 3087 | Error error = buffer->map(access); |
| 3088 | if (error.isError()) |
| 3089 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3090 | handleError(error); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3091 | return nullptr; |
| 3092 | } |
| 3093 | |
| 3094 | return buffer->getMapPointer(); |
| 3095 | } |
| 3096 | |
| 3097 | GLboolean Context::unmapBuffer(GLenum target) |
| 3098 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3099 | Buffer *buffer = mGLState.getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3100 | ASSERT(buffer); |
| 3101 | |
| 3102 | GLboolean result; |
| 3103 | Error error = buffer->unmap(&result); |
| 3104 | if (error.isError()) |
| 3105 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3106 | handleError(error); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3107 | return GL_FALSE; |
| 3108 | } |
| 3109 | |
| 3110 | return result; |
| 3111 | } |
| 3112 | |
| 3113 | GLvoid *Context::mapBufferRange(GLenum target, |
| 3114 | GLintptr offset, |
| 3115 | GLsizeiptr length, |
| 3116 | GLbitfield access) |
| 3117 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3118 | Buffer *buffer = mGLState.getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3119 | ASSERT(buffer); |
| 3120 | |
| 3121 | Error error = buffer->mapRange(offset, length, access); |
| 3122 | if (error.isError()) |
| 3123 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3124 | handleError(error); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3125 | return nullptr; |
| 3126 | } |
| 3127 | |
| 3128 | return buffer->getMapPointer(); |
| 3129 | } |
| 3130 | |
| 3131 | void Context::flushMappedBufferRange(GLenum /*target*/, GLintptr /*offset*/, GLsizeiptr /*length*/) |
| 3132 | { |
| 3133 | // We do not currently support a non-trivial implementation of FlushMappedBufferRange |
| 3134 | } |
| 3135 | |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 3136 | void Context::syncStateForReadPixels() |
| 3137 | { |
| 3138 | syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects); |
| 3139 | } |
| 3140 | |
| 3141 | void Context::syncStateForTexImage() |
| 3142 | { |
| 3143 | syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects); |
| 3144 | } |
| 3145 | |
| 3146 | void Context::syncStateForClear() |
| 3147 | { |
| 3148 | syncRendererState(mClearDirtyBits, mClearDirtyObjects); |
| 3149 | } |
| 3150 | |
| 3151 | void Context::syncStateForBlit() |
| 3152 | { |
| 3153 | syncRendererState(mBlitDirtyBits, mBlitDirtyObjects); |
| 3154 | } |
| 3155 | |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3156 | void Context::activeTexture(GLenum texture) |
| 3157 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3158 | mGLState.setActiveSampler(texture - GL_TEXTURE0); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3159 | } |
| 3160 | |
| 3161 | void Context::blendColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) |
| 3162 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3163 | mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha)); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3164 | } |
| 3165 | |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 3166 | void Context::blendEquation(GLenum mode) |
| 3167 | { |
| 3168 | mGLState.setBlendEquation(mode, mode); |
| 3169 | } |
| 3170 | |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3171 | void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha) |
| 3172 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3173 | mGLState.setBlendEquation(modeRGB, modeAlpha); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3174 | } |
| 3175 | |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 3176 | void Context::blendFunc(GLenum sfactor, GLenum dfactor) |
| 3177 | { |
| 3178 | mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor); |
| 3179 | } |
| 3180 | |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3181 | void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) |
| 3182 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3183 | mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3184 | } |
| 3185 | |
| 3186 | void Context::clearColor(GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha) |
| 3187 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3188 | mGLState.setColorClearValue(red, green, blue, alpha); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3189 | } |
| 3190 | |
| 3191 | void Context::clearDepthf(GLclampf depth) |
| 3192 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3193 | mGLState.setDepthClearValue(depth); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3194 | } |
| 3195 | |
| 3196 | void Context::clearStencil(GLint s) |
| 3197 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3198 | mGLState.setStencilClearValue(s); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3199 | } |
| 3200 | |
| 3201 | void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) |
| 3202 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3203 | mGLState.setColorMask(red == GL_TRUE, green == GL_TRUE, blue == GL_TRUE, alpha == GL_TRUE); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3204 | } |
| 3205 | |
| 3206 | void Context::cullFace(GLenum mode) |
| 3207 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3208 | mGLState.setCullMode(mode); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3209 | } |
| 3210 | |
| 3211 | void Context::depthFunc(GLenum func) |
| 3212 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3213 | mGLState.setDepthFunc(func); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3214 | } |
| 3215 | |
| 3216 | void Context::depthMask(GLboolean flag) |
| 3217 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3218 | mGLState.setDepthMask(flag != GL_FALSE); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3219 | } |
| 3220 | |
| 3221 | void Context::depthRangef(GLclampf zNear, GLclampf zFar) |
| 3222 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3223 | mGLState.setDepthRange(zNear, zFar); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3224 | } |
| 3225 | |
| 3226 | void Context::disable(GLenum cap) |
| 3227 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3228 | mGLState.setEnableFeature(cap, false); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3229 | } |
| 3230 | |
| 3231 | void Context::disableVertexAttribArray(GLuint index) |
| 3232 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3233 | mGLState.setEnableVertexAttribArray(index, false); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3234 | } |
| 3235 | |
| 3236 | void Context::enable(GLenum cap) |
| 3237 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3238 | mGLState.setEnableFeature(cap, true); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3239 | } |
| 3240 | |
| 3241 | void Context::enableVertexAttribArray(GLuint index) |
| 3242 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3243 | mGLState.setEnableVertexAttribArray(index, true); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3244 | } |
| 3245 | |
| 3246 | void Context::frontFace(GLenum mode) |
| 3247 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3248 | mGLState.setFrontFace(mode); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3249 | } |
| 3250 | |
| 3251 | void Context::hint(GLenum target, GLenum mode) |
| 3252 | { |
| 3253 | switch (target) |
| 3254 | { |
| 3255 | case GL_GENERATE_MIPMAP_HINT: |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3256 | mGLState.setGenerateMipmapHint(mode); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3257 | break; |
| 3258 | |
| 3259 | case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3260 | mGLState.setFragmentShaderDerivativeHint(mode); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3261 | break; |
| 3262 | |
| 3263 | default: |
| 3264 | UNREACHABLE(); |
| 3265 | return; |
| 3266 | } |
| 3267 | } |
| 3268 | |
| 3269 | void Context::lineWidth(GLfloat width) |
| 3270 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3271 | mGLState.setLineWidth(width); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3272 | } |
| 3273 | |
| 3274 | void Context::pixelStorei(GLenum pname, GLint param) |
| 3275 | { |
| 3276 | switch (pname) |
| 3277 | { |
| 3278 | case GL_UNPACK_ALIGNMENT: |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3279 | mGLState.setUnpackAlignment(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3280 | break; |
| 3281 | |
| 3282 | case GL_PACK_ALIGNMENT: |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3283 | mGLState.setPackAlignment(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3284 | break; |
| 3285 | |
| 3286 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3287 | mGLState.setPackReverseRowOrder(param != 0); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3288 | break; |
| 3289 | |
| 3290 | case GL_UNPACK_ROW_LENGTH: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3291 | ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3292 | mGLState.setUnpackRowLength(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3293 | break; |
| 3294 | |
| 3295 | case GL_UNPACK_IMAGE_HEIGHT: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3296 | ASSERT(getClientMajorVersion() >= 3); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3297 | mGLState.setUnpackImageHeight(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3298 | break; |
| 3299 | |
| 3300 | case GL_UNPACK_SKIP_IMAGES: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3301 | ASSERT(getClientMajorVersion() >= 3); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3302 | mGLState.setUnpackSkipImages(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3303 | break; |
| 3304 | |
| 3305 | case GL_UNPACK_SKIP_ROWS: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3306 | ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3307 | mGLState.setUnpackSkipRows(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3308 | break; |
| 3309 | |
| 3310 | case GL_UNPACK_SKIP_PIXELS: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3311 | ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3312 | mGLState.setUnpackSkipPixels(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3313 | break; |
| 3314 | |
| 3315 | case GL_PACK_ROW_LENGTH: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3316 | ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3317 | mGLState.setPackRowLength(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3318 | break; |
| 3319 | |
| 3320 | case GL_PACK_SKIP_ROWS: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3321 | ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3322 | mGLState.setPackSkipRows(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3323 | break; |
| 3324 | |
| 3325 | case GL_PACK_SKIP_PIXELS: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3326 | ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3327 | mGLState.setPackSkipPixels(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3328 | break; |
| 3329 | |
| 3330 | default: |
| 3331 | UNREACHABLE(); |
| 3332 | return; |
| 3333 | } |
| 3334 | } |
| 3335 | |
| 3336 | void Context::polygonOffset(GLfloat factor, GLfloat units) |
| 3337 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3338 | mGLState.setPolygonOffsetParams(factor, units); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3339 | } |
| 3340 | |
| 3341 | void Context::sampleCoverage(GLclampf value, GLboolean invert) |
| 3342 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3343 | mGLState.setSampleCoverageParams(clamp01(value), invert == GL_TRUE); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3344 | } |
| 3345 | |
| 3346 | void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height) |
| 3347 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3348 | mGLState.setScissorParams(x, y, width, height); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3349 | } |
| 3350 | |
| 3351 | void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask) |
| 3352 | { |
| 3353 | if (face == GL_FRONT || face == GL_FRONT_AND_BACK) |
| 3354 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3355 | mGLState.setStencilParams(func, ref, mask); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3356 | } |
| 3357 | |
| 3358 | if (face == GL_BACK || face == GL_FRONT_AND_BACK) |
| 3359 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3360 | mGLState.setStencilBackParams(func, ref, mask); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3361 | } |
| 3362 | } |
| 3363 | |
| 3364 | void Context::stencilMaskSeparate(GLenum face, GLuint mask) |
| 3365 | { |
| 3366 | if (face == GL_FRONT || face == GL_FRONT_AND_BACK) |
| 3367 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3368 | mGLState.setStencilWritemask(mask); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3369 | } |
| 3370 | |
| 3371 | if (face == GL_BACK || face == GL_FRONT_AND_BACK) |
| 3372 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3373 | mGLState.setStencilBackWritemask(mask); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3374 | } |
| 3375 | } |
| 3376 | |
| 3377 | void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass) |
| 3378 | { |
| 3379 | if (face == GL_FRONT || face == GL_FRONT_AND_BACK) |
| 3380 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3381 | mGLState.setStencilOperations(fail, zfail, zpass); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3382 | } |
| 3383 | |
| 3384 | if (face == GL_BACK || face == GL_FRONT_AND_BACK) |
| 3385 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3386 | mGLState.setStencilBackOperations(fail, zfail, zpass); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3387 | } |
| 3388 | } |
| 3389 | |
| 3390 | void Context::vertexAttrib1f(GLuint index, GLfloat x) |
| 3391 | { |
| 3392 | GLfloat vals[4] = {x, 0, 0, 1}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3393 | mGLState.setVertexAttribf(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3394 | } |
| 3395 | |
| 3396 | void Context::vertexAttrib1fv(GLuint index, const GLfloat *values) |
| 3397 | { |
| 3398 | GLfloat vals[4] = {values[0], 0, 0, 1}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3399 | mGLState.setVertexAttribf(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3400 | } |
| 3401 | |
| 3402 | void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y) |
| 3403 | { |
| 3404 | GLfloat vals[4] = {x, y, 0, 1}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3405 | mGLState.setVertexAttribf(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3406 | } |
| 3407 | |
| 3408 | void Context::vertexAttrib2fv(GLuint index, const GLfloat *values) |
| 3409 | { |
| 3410 | GLfloat vals[4] = {values[0], values[1], 0, 1}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3411 | mGLState.setVertexAttribf(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3412 | } |
| 3413 | |
| 3414 | void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z) |
| 3415 | { |
| 3416 | GLfloat vals[4] = {x, y, z, 1}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3417 | mGLState.setVertexAttribf(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3418 | } |
| 3419 | |
| 3420 | void Context::vertexAttrib3fv(GLuint index, const GLfloat *values) |
| 3421 | { |
| 3422 | GLfloat vals[4] = {values[0], values[1], values[2], 1}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3423 | mGLState.setVertexAttribf(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3424 | } |
| 3425 | |
| 3426 | void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) |
| 3427 | { |
| 3428 | GLfloat vals[4] = {x, y, z, w}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3429 | mGLState.setVertexAttribf(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3430 | } |
| 3431 | |
| 3432 | void Context::vertexAttrib4fv(GLuint index, const GLfloat *values) |
| 3433 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3434 | mGLState.setVertexAttribf(index, values); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3435 | } |
| 3436 | |
| 3437 | void Context::vertexAttribPointer(GLuint index, |
| 3438 | GLint size, |
| 3439 | GLenum type, |
| 3440 | GLboolean normalized, |
| 3441 | GLsizei stride, |
| 3442 | const GLvoid *ptr) |
| 3443 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3444 | mGLState.setVertexAttribState(index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size, type, |
| 3445 | normalized == GL_TRUE, false, stride, ptr); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3446 | } |
| 3447 | |
| 3448 | void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height) |
| 3449 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3450 | mGLState.setViewportParams(x, y, width, height); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3451 | } |
| 3452 | |
| 3453 | void Context::vertexAttribIPointer(GLuint index, |
| 3454 | GLint size, |
| 3455 | GLenum type, |
| 3456 | GLsizei stride, |
| 3457 | const GLvoid *pointer) |
| 3458 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3459 | mGLState.setVertexAttribState(index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size, type, |
| 3460 | false, true, stride, pointer); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3461 | } |
| 3462 | |
| 3463 | void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w) |
| 3464 | { |
| 3465 | GLint vals[4] = {x, y, z, w}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3466 | mGLState.setVertexAttribi(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3467 | } |
| 3468 | |
| 3469 | void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w) |
| 3470 | { |
| 3471 | GLuint vals[4] = {x, y, z, w}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3472 | mGLState.setVertexAttribu(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3473 | } |
| 3474 | |
| 3475 | void Context::vertexAttribI4iv(GLuint index, const GLint *v) |
| 3476 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3477 | mGLState.setVertexAttribi(index, v); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3478 | } |
| 3479 | |
| 3480 | void Context::vertexAttribI4uiv(GLuint index, const GLuint *v) |
| 3481 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3482 | mGLState.setVertexAttribu(index, v); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3483 | } |
| 3484 | |
| 3485 | void Context::debugMessageControl(GLenum source, |
| 3486 | GLenum type, |
| 3487 | GLenum severity, |
| 3488 | GLsizei count, |
| 3489 | const GLuint *ids, |
| 3490 | GLboolean enabled) |
| 3491 | { |
| 3492 | std::vector<GLuint> idVector(ids, ids + count); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3493 | mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector), |
| 3494 | (enabled != GL_FALSE)); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3495 | } |
| 3496 | |
| 3497 | void Context::debugMessageInsert(GLenum source, |
| 3498 | GLenum type, |
| 3499 | GLuint id, |
| 3500 | GLenum severity, |
| 3501 | GLsizei length, |
| 3502 | const GLchar *buf) |
| 3503 | { |
| 3504 | 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] | 3505 | mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg)); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3506 | } |
| 3507 | |
| 3508 | void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam) |
| 3509 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3510 | mGLState.getDebug().setCallback(callback, userParam); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3511 | } |
| 3512 | |
| 3513 | GLuint Context::getDebugMessageLog(GLuint count, |
| 3514 | GLsizei bufSize, |
| 3515 | GLenum *sources, |
| 3516 | GLenum *types, |
| 3517 | GLuint *ids, |
| 3518 | GLenum *severities, |
| 3519 | GLsizei *lengths, |
| 3520 | GLchar *messageLog) |
| 3521 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3522 | return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids, |
| 3523 | severities, lengths, messageLog)); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3524 | } |
| 3525 | |
| 3526 | void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message) |
| 3527 | { |
| 3528 | 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] | 3529 | mGLState.getDebug().pushGroup(source, id, std::move(msg)); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3530 | } |
| 3531 | |
| 3532 | void Context::popDebugGroup() |
| 3533 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3534 | mGLState.getDebug().popGroup(); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3535 | } |
| 3536 | |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 3537 | void Context::bufferData(GLenum target, GLsizeiptr size, const GLvoid *data, GLenum usage) |
| 3538 | { |
| 3539 | Buffer *buffer = mGLState.getTargetBuffer(target); |
| 3540 | ASSERT(buffer); |
Jamie Madill | b8353b0 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 3541 | handleError(buffer->bufferData(this, target, data, size, usage)); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 3542 | } |
| 3543 | |
| 3544 | void Context::bufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const GLvoid *data) |
| 3545 | { |
| 3546 | if (data == nullptr) |
| 3547 | { |
| 3548 | return; |
| 3549 | } |
| 3550 | |
| 3551 | Buffer *buffer = mGLState.getTargetBuffer(target); |
| 3552 | ASSERT(buffer); |
Jamie Madill | b8353b0 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 3553 | handleError(buffer->bufferSubData(this, target, data, size, offset)); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 3554 | } |
| 3555 | |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 3556 | void Context::attachShader(GLuint program, GLuint shader) |
| 3557 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 3558 | auto programObject = mState.mShaderPrograms->getProgram(program); |
| 3559 | auto shaderObject = mState.mShaderPrograms->getShader(shader); |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 3560 | ASSERT(programObject && shaderObject); |
| 3561 | programObject->attachShader(shaderObject); |
| 3562 | } |
| 3563 | |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 3564 | const Workarounds &Context::getWorkarounds() const |
| 3565 | { |
| 3566 | return mWorkarounds; |
| 3567 | } |
| 3568 | |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 3569 | void Context::copyBufferSubData(GLenum readTarget, |
| 3570 | GLenum writeTarget, |
| 3571 | GLintptr readOffset, |
| 3572 | GLintptr writeOffset, |
| 3573 | GLsizeiptr size) |
| 3574 | { |
| 3575 | // if size is zero, the copy is a successful no-op |
| 3576 | if (size == 0) |
| 3577 | { |
| 3578 | return; |
| 3579 | } |
| 3580 | |
| 3581 | // TODO(jmadill): cache these. |
| 3582 | Buffer *readBuffer = mGLState.getTargetBuffer(readTarget); |
| 3583 | Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget); |
| 3584 | |
| 3585 | handleError(writeBuffer->copyBufferSubData(readBuffer, readOffset, writeOffset, size)); |
| 3586 | } |
| 3587 | |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 3588 | void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name) |
| 3589 | { |
| 3590 | Program *programObject = getProgram(program); |
| 3591 | // TODO(jmadill): Re-use this from the validation if possible. |
| 3592 | ASSERT(programObject); |
| 3593 | programObject->bindAttributeLocation(index, name); |
| 3594 | } |
| 3595 | |
| 3596 | void Context::bindBuffer(GLenum target, GLuint buffer) |
| 3597 | { |
| 3598 | switch (target) |
| 3599 | { |
| 3600 | case GL_ARRAY_BUFFER: |
| 3601 | bindArrayBuffer(buffer); |
| 3602 | break; |
| 3603 | case GL_ELEMENT_ARRAY_BUFFER: |
| 3604 | bindElementArrayBuffer(buffer); |
| 3605 | break; |
| 3606 | case GL_COPY_READ_BUFFER: |
| 3607 | bindCopyReadBuffer(buffer); |
| 3608 | break; |
| 3609 | case GL_COPY_WRITE_BUFFER: |
| 3610 | bindCopyWriteBuffer(buffer); |
| 3611 | break; |
| 3612 | case GL_PIXEL_PACK_BUFFER: |
| 3613 | bindPixelPackBuffer(buffer); |
| 3614 | break; |
| 3615 | case GL_PIXEL_UNPACK_BUFFER: |
| 3616 | bindPixelUnpackBuffer(buffer); |
| 3617 | break; |
| 3618 | case GL_UNIFORM_BUFFER: |
| 3619 | bindGenericUniformBuffer(buffer); |
| 3620 | break; |
| 3621 | case GL_TRANSFORM_FEEDBACK_BUFFER: |
| 3622 | bindGenericTransformFeedbackBuffer(buffer); |
| 3623 | break; |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 3624 | case GL_ATOMIC_COUNTER_BUFFER: |
Geoff Lang | 9f09037 | 2016-12-02 10:20:43 -0500 | [diff] [blame] | 3625 | if (buffer != 0) |
| 3626 | { |
| 3627 | // Binding buffers to this binding point is not implemented yet. |
| 3628 | UNIMPLEMENTED(); |
| 3629 | } |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 3630 | break; |
| 3631 | case GL_SHADER_STORAGE_BUFFER: |
Geoff Lang | 9f09037 | 2016-12-02 10:20:43 -0500 | [diff] [blame] | 3632 | if (buffer != 0) |
| 3633 | { |
| 3634 | // Binding buffers to this binding point is not implemented yet. |
| 3635 | UNIMPLEMENTED(); |
| 3636 | } |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 3637 | break; |
| 3638 | case GL_DRAW_INDIRECT_BUFFER: |
Jiajia Qin | 9d7d0b1 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 3639 | bindDrawIndirectBuffer(buffer); |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 3640 | break; |
| 3641 | case GL_DISPATCH_INDIRECT_BUFFER: |
Geoff Lang | 9f09037 | 2016-12-02 10:20:43 -0500 | [diff] [blame] | 3642 | if (buffer != 0) |
| 3643 | { |
| 3644 | // Binding buffers to this binding point is not implemented yet. |
| 3645 | UNIMPLEMENTED(); |
| 3646 | } |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 3647 | break; |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 3648 | |
| 3649 | default: |
| 3650 | UNREACHABLE(); |
| 3651 | break; |
| 3652 | } |
| 3653 | } |
| 3654 | |
| 3655 | void Context::bindFramebuffer(GLenum target, GLuint framebuffer) |
| 3656 | { |
| 3657 | if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER) |
| 3658 | { |
| 3659 | bindReadFramebuffer(framebuffer); |
| 3660 | } |
| 3661 | |
| 3662 | if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER) |
| 3663 | { |
| 3664 | bindDrawFramebuffer(framebuffer); |
| 3665 | } |
| 3666 | } |
| 3667 | |
| 3668 | void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer) |
| 3669 | { |
| 3670 | ASSERT(target == GL_RENDERBUFFER); |
| 3671 | Renderbuffer *object = |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 3672 | mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 3673 | mGLState.setRenderbufferBinding(object); |
| 3674 | } |
| 3675 | |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 3676 | void Context::texStorage2DMultisample(GLenum target, |
| 3677 | GLsizei samples, |
| 3678 | GLenum internalformat, |
| 3679 | GLsizei width, |
| 3680 | GLsizei height, |
| 3681 | GLboolean fixedsamplelocations) |
| 3682 | { |
| 3683 | Extents size(width, height, 1); |
| 3684 | Texture *texture = getTargetTexture(target); |
| 3685 | handleError(texture->setStorageMultisample(target, samples, internalformat, size, |
| 3686 | fixedsamplelocations)); |
| 3687 | } |
| 3688 | |
| 3689 | void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val) |
| 3690 | { |
| 3691 | mGLState.syncDirtyObject(GL_READ_FRAMEBUFFER); |
| 3692 | const Framebuffer *framebuffer = mGLState.getReadFramebuffer(); |
| 3693 | |
| 3694 | switch (pname) |
| 3695 | { |
| 3696 | case GL_SAMPLE_POSITION: |
| 3697 | handleError(framebuffer->getSamplePosition(index, val)); |
| 3698 | break; |
| 3699 | default: |
| 3700 | UNREACHABLE(); |
| 3701 | } |
| 3702 | } |
| 3703 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3704 | } // namespace gl |