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