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