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