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