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