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