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