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