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