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