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