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 | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 12 | #include <string.h> |
Jamie Madill | b929397 | 2015-02-19 11:07:54 -0500 | [diff] [blame] | 13 | #include <iterator> |
| 14 | #include <sstream> |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 15 | #include <vector> |
Jamie Madill | b929397 | 2015-02-19 11:07:54 -0500 | [diff] [blame] | 16 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 17 | #include "common/matrix_utils.h" |
Geoff Lang | 0b7eef7 | 2014-06-12 14:10:47 -0400 | [diff] [blame] | 18 | #include "common/platform.h" |
Jamie Madill | b929397 | 2015-02-19 11:07:54 -0500 | [diff] [blame] | 19 | #include "common/utilities.h" |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 20 | #include "common/version.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 21 | #include "libANGLE/Buffer.h" |
Jamie Madill | b929397 | 2015-02-19 11:07:54 -0500 | [diff] [blame] | 22 | #include "libANGLE/Compiler.h" |
Jamie Madill | 948bbe5 | 2017-06-01 13:10:42 -0400 | [diff] [blame] | 23 | #include "libANGLE/Display.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 24 | #include "libANGLE/Fence.h" |
| 25 | #include "libANGLE/Framebuffer.h" |
| 26 | #include "libANGLE/FramebufferAttachment.h" |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 27 | #include "libANGLE/Path.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 28 | #include "libANGLE/Program.h" |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame^] | 29 | #include "libANGLE/ProgramPipeline.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 30 | #include "libANGLE/Query.h" |
Jamie Madill | b929397 | 2015-02-19 11:07:54 -0500 | [diff] [blame] | 31 | #include "libANGLE/Renderbuffer.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 32 | #include "libANGLE/ResourceManager.h" |
| 33 | #include "libANGLE/Sampler.h" |
Jamie Madill | 9dd0cf0 | 2014-11-24 11:38:51 -0500 | [diff] [blame] | 34 | #include "libANGLE/Surface.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 35 | #include "libANGLE/Texture.h" |
| 36 | #include "libANGLE/TransformFeedback.h" |
| 37 | #include "libANGLE/VertexArray.h" |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 38 | #include "libANGLE/Workarounds.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 39 | #include "libANGLE/formatutils.h" |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 40 | #include "libANGLE/queryconversions.h" |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 41 | #include "libANGLE/queryutils.h" |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 42 | #include "libANGLE/renderer/ContextImpl.h" |
| 43 | #include "libANGLE/renderer/EGLImplFactory.h" |
| 44 | #include "libANGLE/validationES.h" |
shannon.woods@transgaming.com | 486d9e9 | 2013-02-28 23:15:41 +0000 | [diff] [blame] | 45 | |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 46 | namespace |
| 47 | { |
| 48 | |
Jamie Madill | b666492 | 2017-07-25 12:55:04 -0400 | [diff] [blame] | 49 | #define ANGLE_HANDLE_ERR(X) \ |
| 50 | handleError(X); \ |
| 51 | return; |
| 52 | #define ANGLE_CONTEXT_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_HANDLE_ERR); |
| 53 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 54 | template <typename T> |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 55 | std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager, |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 56 | GLsizei numPaths, |
| 57 | const void *paths, |
| 58 | GLuint pathBase) |
| 59 | { |
| 60 | std::vector<gl::Path *> ret; |
| 61 | ret.reserve(numPaths); |
| 62 | |
| 63 | const auto *nameArray = static_cast<const T *>(paths); |
| 64 | |
| 65 | for (GLsizei i = 0; i < numPaths; ++i) |
| 66 | { |
| 67 | const GLuint pathName = nameArray[i] + pathBase; |
| 68 | |
| 69 | ret.push_back(resourceManager.getPath(pathName)); |
| 70 | } |
| 71 | |
| 72 | return ret; |
| 73 | } |
| 74 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 75 | std::vector<gl::Path *> GatherPaths(gl::PathManager &resourceManager, |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 76 | GLsizei numPaths, |
| 77 | GLenum pathNameType, |
| 78 | const void *paths, |
| 79 | GLuint pathBase) |
| 80 | { |
| 81 | switch (pathNameType) |
| 82 | { |
| 83 | case GL_UNSIGNED_BYTE: |
| 84 | return GatherPaths<GLubyte>(resourceManager, numPaths, paths, pathBase); |
| 85 | |
| 86 | case GL_BYTE: |
| 87 | return GatherPaths<GLbyte>(resourceManager, numPaths, paths, pathBase); |
| 88 | |
| 89 | case GL_UNSIGNED_SHORT: |
| 90 | return GatherPaths<GLushort>(resourceManager, numPaths, paths, pathBase); |
| 91 | |
| 92 | case GL_SHORT: |
| 93 | return GatherPaths<GLshort>(resourceManager, numPaths, paths, pathBase); |
| 94 | |
| 95 | case GL_UNSIGNED_INT: |
| 96 | return GatherPaths<GLuint>(resourceManager, numPaths, paths, pathBase); |
| 97 | |
| 98 | case GL_INT: |
| 99 | return GatherPaths<GLint>(resourceManager, numPaths, paths, pathBase); |
| 100 | } |
| 101 | |
| 102 | UNREACHABLE(); |
| 103 | return std::vector<gl::Path *>(); |
| 104 | } |
| 105 | |
| 106 | template <typename T> |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 107 | gl::Error GetQueryObjectParameter(gl::Query *query, GLenum pname, T *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 108 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 109 | ASSERT(query != nullptr); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 110 | |
| 111 | switch (pname) |
| 112 | { |
| 113 | case GL_QUERY_RESULT_EXT: |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 114 | return query->getResult(params); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 115 | case GL_QUERY_RESULT_AVAILABLE_EXT: |
| 116 | { |
| 117 | bool available; |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 118 | gl::Error error = query->isResultAvailable(&available); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 119 | if (!error.isError()) |
| 120 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 121 | *params = gl::ConvertFromGLboolean<T>(available); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 122 | } |
| 123 | return error; |
| 124 | } |
| 125 | default: |
| 126 | UNREACHABLE(); |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 127 | return gl::InternalError() << "Unreachable Error"; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 131 | void MarkTransformFeedbackBufferUsage(gl::TransformFeedback *transformFeedback) |
| 132 | { |
Geoff Lang | 1a68346 | 2015-09-29 15:09:59 -0400 | [diff] [blame] | 133 | if (transformFeedback && transformFeedback->isActive() && !transformFeedback->isPaused()) |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 134 | { |
| 135 | for (size_t tfBufferIndex = 0; tfBufferIndex < transformFeedback->getIndexedBufferCount(); |
| 136 | tfBufferIndex++) |
| 137 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 138 | const gl::OffsetBindingPointer<gl::Buffer> &buffer = |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 139 | transformFeedback->getIndexedBuffer(tfBufferIndex); |
| 140 | if (buffer.get() != nullptr) |
| 141 | { |
| 142 | buffer->onTransformFeedback(); |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | } |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 147 | |
| 148 | // Attribute map queries. |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 149 | EGLint GetClientMajorVersion(const egl::AttributeMap &attribs) |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 150 | { |
Ian Ewell | ec2c0c5 | 2016-04-05 13:46:26 -0400 | [diff] [blame] | 151 | return static_cast<EGLint>(attribs.get(EGL_CONTEXT_CLIENT_VERSION, 1)); |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 152 | } |
| 153 | |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 154 | EGLint GetClientMinorVersion(const egl::AttributeMap &attribs) |
| 155 | { |
| 156 | return static_cast<EGLint>(attribs.get(EGL_CONTEXT_MINOR_VERSION, 0)); |
| 157 | } |
| 158 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 159 | gl::Version GetClientVersion(const egl::AttributeMap &attribs) |
| 160 | { |
| 161 | return gl::Version(GetClientMajorVersion(attribs), GetClientMinorVersion(attribs)); |
| 162 | } |
| 163 | |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 164 | GLenum GetResetStrategy(const egl::AttributeMap &attribs) |
| 165 | { |
Ian Ewell | ec2c0c5 | 2016-04-05 13:46:26 -0400 | [diff] [blame] | 166 | EGLAttrib attrib = attribs.get(EGL_CONTEXT_OPENGL_RESET_NOTIFICATION_STRATEGY_EXT, |
| 167 | EGL_NO_RESET_NOTIFICATION_EXT); |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 168 | switch (attrib) |
| 169 | { |
| 170 | case EGL_NO_RESET_NOTIFICATION: |
| 171 | return GL_NO_RESET_NOTIFICATION_EXT; |
| 172 | case EGL_LOSE_CONTEXT_ON_RESET: |
| 173 | return GL_LOSE_CONTEXT_ON_RESET_EXT; |
| 174 | default: |
| 175 | UNREACHABLE(); |
| 176 | return GL_NONE; |
| 177 | } |
| 178 | } |
| 179 | |
| 180 | bool GetRobustAccess(const egl::AttributeMap &attribs) |
| 181 | { |
Geoff Lang | 077f20a | 2016-11-01 10:08:02 -0400 | [diff] [blame] | 182 | return (attribs.get(EGL_CONTEXT_OPENGL_ROBUST_ACCESS_EXT, EGL_FALSE) == EGL_TRUE) || |
| 183 | ((attribs.get(EGL_CONTEXT_FLAGS_KHR, 0) & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) != |
| 184 | 0); |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | bool GetDebug(const egl::AttributeMap &attribs) |
| 188 | { |
Geoff Lang | 077f20a | 2016-11-01 10:08:02 -0400 | [diff] [blame] | 189 | return (attribs.get(EGL_CONTEXT_OPENGL_DEBUG, EGL_FALSE) == EGL_TRUE) || |
| 190 | ((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] | 191 | } |
| 192 | |
| 193 | bool GetNoError(const egl::AttributeMap &attribs) |
| 194 | { |
| 195 | return (attribs.get(EGL_CONTEXT_OPENGL_NO_ERROR_KHR, EGL_FALSE) == EGL_TRUE); |
| 196 | } |
| 197 | |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 198 | bool GetWebGLContext(const egl::AttributeMap &attribs) |
| 199 | { |
| 200 | return (attribs.get(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE, EGL_FALSE) == EGL_TRUE); |
| 201 | } |
| 202 | |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 203 | bool GetBindGeneratesResource(const egl::AttributeMap &attribs) |
| 204 | { |
| 205 | return (attribs.get(EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, EGL_TRUE) == EGL_TRUE); |
| 206 | } |
| 207 | |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 208 | bool GetClientArraysEnabled(const egl::AttributeMap &attribs) |
| 209 | { |
| 210 | return (attribs.get(EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, EGL_TRUE) == EGL_TRUE); |
| 211 | } |
| 212 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 213 | std::string GetObjectLabelFromPointer(GLsizei length, const GLchar *label) |
| 214 | { |
| 215 | std::string labelName; |
| 216 | if (label != nullptr) |
| 217 | { |
| 218 | size_t labelLength = length < 0 ? strlen(label) : length; |
| 219 | labelName = std::string(label, labelLength); |
| 220 | } |
| 221 | return labelName; |
| 222 | } |
| 223 | |
| 224 | void GetObjectLabelBase(const std::string &objectLabel, |
| 225 | GLsizei bufSize, |
| 226 | GLsizei *length, |
| 227 | GLchar *label) |
| 228 | { |
| 229 | size_t writeLength = objectLabel.length(); |
| 230 | if (label != nullptr && bufSize > 0) |
| 231 | { |
| 232 | writeLength = std::min(static_cast<size_t>(bufSize) - 1, objectLabel.length()); |
| 233 | std::copy(objectLabel.begin(), objectLabel.begin() + writeLength, label); |
| 234 | label[writeLength] = '\0'; |
| 235 | } |
| 236 | |
| 237 | if (length != nullptr) |
| 238 | { |
| 239 | *length = static_cast<GLsizei>(writeLength); |
| 240 | } |
| 241 | } |
| 242 | |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 243 | } // anonymous namespace |
| 244 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 245 | namespace gl |
| 246 | { |
daniel@transgaming.com | ca1ac1f | 2013-01-11 04:13:05 +0000 | [diff] [blame] | 247 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 248 | Context::Context(rx::EGLImplFactory *implFactory, |
| 249 | const egl::Config *config, |
Corentin Wallez | 51706ea | 2015-08-07 14:39:22 -0400 | [diff] [blame] | 250 | const Context *shareContext, |
Geoff Lang | ce02f08 | 2017-02-06 16:46:21 -0500 | [diff] [blame] | 251 | TextureManager *shareTextures, |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 252 | MemoryProgramCache *memoryProgramCache, |
Corentin Wallez | c295e51 | 2017-01-27 17:47:50 -0500 | [diff] [blame] | 253 | const egl::AttributeMap &attribs, |
Jamie Madill | 948bbe5 | 2017-06-01 13:10:42 -0400 | [diff] [blame] | 254 | const egl::DisplayExtensions &displayExtensions, |
| 255 | bool robustResourceInit) |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 256 | |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 257 | : ValidationContext(shareContext, |
Geoff Lang | ce02f08 | 2017-02-06 16:46:21 -0500 | [diff] [blame] | 258 | shareTextures, |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 259 | GetClientVersion(attribs), |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 260 | &mGLState, |
Jamie Madill | f25855c | 2015-11-03 11:06:18 -0500 | [diff] [blame] | 261 | mCaps, |
| 262 | mTextureCaps, |
| 263 | mExtensions, |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 264 | mLimitations, |
| 265 | GetNoError(attribs)), |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 266 | mImplementation(implFactory->createContext(mState)), |
Jamie Madill | 2f348d2 | 2017-06-05 10:50:59 -0400 | [diff] [blame] | 267 | mCompiler(), |
Corentin Wallez | e3b10e8 | 2015-05-20 11:06:25 -0400 | [diff] [blame] | 268 | mConfig(config), |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 269 | mClientType(EGL_OPENGL_ES_API), |
| 270 | mHasBeenCurrent(false), |
| 271 | mContextLost(false), |
| 272 | mResetStatus(GL_NO_ERROR), |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 273 | mContextLostForced(false), |
Jamie Madill | 46e6c7a | 2016-01-18 14:42:30 -0500 | [diff] [blame] | 274 | mResetStrategy(GetResetStrategy(attribs)), |
| 275 | mRobustAccess(GetRobustAccess(attribs)), |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 276 | mCurrentSurface(static_cast<egl::Surface *>(EGL_NO_SURFACE)), |
| 277 | mCurrentDisplay(static_cast<egl::Display *>(EGL_NO_DISPLAY)), |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 278 | mSurfacelessFramebuffer(nullptr), |
Jamie Madill | e14951e | 2017-03-09 18:55:16 -0500 | [diff] [blame] | 279 | mWebGLContext(GetWebGLContext(attribs)), |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 280 | mMemoryProgramCache(memoryProgramCache), |
Jamie Madill | b3f26b9 | 2017-07-19 15:07:41 -0400 | [diff] [blame] | 281 | mScratchBuffer(1000u), |
| 282 | mZeroFilledBuffer(1000u) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 283 | { |
Jamie Madill | 14bbb3f | 2017-09-12 15:23:01 -0400 | [diff] [blame] | 284 | mImplementation->setMemoryProgramCache(memoryProgramCache); |
| 285 | |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 286 | initCaps(displayExtensions); |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 287 | initWorkarounds(); |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 288 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 289 | mGLState.initialize(this, GetDebug(attribs), GetBindGeneratesResource(attribs), |
Jamie Madill | c43be72 | 2017-07-13 16:22:14 -0400 | [diff] [blame] | 290 | GetClientArraysEnabled(attribs), robustResourceInit, |
| 291 | mMemoryProgramCache != nullptr); |
Régis Fénéon | 8310797 | 2015-02-05 12:57:44 +0100 | [diff] [blame] | 292 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 293 | mFenceNVHandleAllocator.setBaseHandle(0); |
Geoff Lang | 7dca186 | 2013-07-30 16:30:46 -0400 | [diff] [blame] | 294 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 295 | // [OpenGL ES 2.0.24] section 3.7 page 83: |
| 296 | // In the initial state, TEXTURE_2D and TEXTURE_CUBE_MAP have twodimensional |
| 297 | // and cube map texture state vectors respectively associated with them. |
| 298 | // In order that access to these initial textures not be lost, they are treated as texture |
| 299 | // objects all of whose names are 0. |
| 300 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 301 | Texture *zeroTexture2D = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 302 | mZeroTextures[GL_TEXTURE_2D].set(this, zeroTexture2D); |
Jamie Madill | dedd7b9 | 2014-11-05 16:30:36 -0500 | [diff] [blame] | 303 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 304 | Texture *zeroTextureCube = new Texture(mImplementation.get(), 0, GL_TEXTURE_CUBE_MAP); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 305 | mZeroTextures[GL_TEXTURE_CUBE_MAP].set(this, zeroTextureCube); |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 306 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 307 | if (getClientVersion() >= Version(3, 0)) |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 308 | { |
| 309 | // TODO: These could also be enabled via extension |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 310 | Texture *zeroTexture3D = new Texture(mImplementation.get(), 0, GL_TEXTURE_3D); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 311 | mZeroTextures[GL_TEXTURE_3D].set(this, zeroTexture3D); |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 312 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 313 | Texture *zeroTexture2DArray = new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_ARRAY); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 314 | mZeroTextures[GL_TEXTURE_2D_ARRAY].set(this, zeroTexture2DArray); |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 315 | } |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 316 | if (getClientVersion() >= Version(3, 1)) |
| 317 | { |
| 318 | Texture *zeroTexture2DMultisample = |
| 319 | new Texture(mImplementation.get(), 0, GL_TEXTURE_2D_MULTISAMPLE); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 320 | mZeroTextures[GL_TEXTURE_2D_MULTISAMPLE].set(this, zeroTexture2DMultisample); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 321 | |
| 322 | bindGenericAtomicCounterBuffer(0); |
| 323 | for (unsigned int i = 0; i < mCaps.maxAtomicCounterBufferBindings; i++) |
| 324 | { |
| 325 | bindIndexedAtomicCounterBuffer(0, i, 0, 0); |
| 326 | } |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 327 | |
| 328 | bindGenericShaderStorageBuffer(0); |
| 329 | for (unsigned int i = 0; i < mCaps.maxShaderStorageBufferBindings; i++) |
| 330 | { |
| 331 | bindIndexedShaderStorageBuffer(0, i, 0, 0); |
| 332 | } |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 333 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 334 | |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 335 | if (mExtensions.textureRectangle) |
| 336 | { |
| 337 | Texture *zeroTextureRectangle = |
| 338 | new Texture(mImplementation.get(), 0, GL_TEXTURE_RECTANGLE_ANGLE); |
| 339 | mZeroTextures[GL_TEXTURE_RECTANGLE_ANGLE].set(this, zeroTextureRectangle); |
| 340 | } |
| 341 | |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 342 | if (mExtensions.eglImageExternal || mExtensions.eglStreamConsumerExternal) |
| 343 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 344 | Texture *zeroTextureExternal = |
| 345 | new Texture(mImplementation.get(), 0, GL_TEXTURE_EXTERNAL_OES); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 346 | mZeroTextures[GL_TEXTURE_EXTERNAL_OES].set(this, zeroTextureExternal); |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 347 | } |
| 348 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 349 | mGLState.initializeZeroTextures(this, mZeroTextures); |
Jamie Madill | e6382c3 | 2014-11-07 15:05:26 -0500 | [diff] [blame] | 350 | |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 351 | bindVertexArray(0); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 352 | bindArrayBuffer(0); |
Jiajia Qin | 9d7d0b1 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 353 | bindDrawIndirectBuffer(0); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 354 | bindElementArrayBuffer(0); |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 355 | |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 356 | bindRenderbuffer(GL_RENDERBUFFER, 0); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 357 | |
shannon.woods%transgaming.com@gtempaccount.com | 667a29c | 2013-04-13 03:39:04 +0000 | [diff] [blame] | 358 | bindGenericUniformBuffer(0); |
Geoff Lang | 4dc3af0 | 2016-11-18 14:09:27 -0500 | [diff] [blame] | 359 | 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] | 360 | { |
| 361 | bindIndexedUniformBuffer(0, i, 0, -1); |
| 362 | } |
| 363 | |
shannon.woods%transgaming.com@gtempaccount.com | 5117188 | 2013-04-13 03:39:10 +0000 | [diff] [blame] | 364 | bindCopyReadBuffer(0); |
| 365 | bindCopyWriteBuffer(0); |
shannon.woods%transgaming.com@gtempaccount.com | c926e5f | 2013-04-13 03:39:18 +0000 | [diff] [blame] | 366 | bindPixelPackBuffer(0); |
| 367 | bindPixelUnpackBuffer(0); |
shannon.woods%transgaming.com@gtempaccount.com | 5117188 | 2013-04-13 03:39:10 +0000 | [diff] [blame] | 368 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 369 | if (getClientVersion() >= Version(3, 0)) |
Geoff Lang | 1a68346 | 2015-09-29 15:09:59 -0400 | [diff] [blame] | 370 | { |
| 371 | // [OpenGL ES 3.0.2] section 2.14.1 pg 85: |
| 372 | // In the initial state, a default transform feedback object is bound and treated as |
| 373 | // a transform feedback object with a name of zero. That object is bound any time |
| 374 | // BindTransformFeedback is called with id of zero |
Jamie Madill | f0dcb8b | 2017-08-26 19:05:13 -0400 | [diff] [blame] | 375 | bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0); |
Geoff Lang | 1a68346 | 2015-09-29 15:09:59 -0400 | [diff] [blame] | 376 | } |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 377 | |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 378 | // Initialize dirty bit masks |
| 379 | // TODO(jmadill): additional ES3 state |
| 380 | mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_ALIGNMENT); |
| 381 | mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_ROW_LENGTH); |
| 382 | mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_IMAGE_HEIGHT); |
| 383 | mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_IMAGES); |
| 384 | mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_ROWS); |
| 385 | mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_SKIP_PIXELS); |
Corentin Wallez | bbd663a | 2016-04-20 17:49:17 -0400 | [diff] [blame] | 386 | mTexImageDirtyBits.set(State::DIRTY_BIT_UNPACK_BUFFER_BINDING); |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 387 | // No dirty objects. |
| 388 | |
| 389 | // Readpixels uses the pack state and read FBO |
| 390 | mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_ALIGNMENT); |
| 391 | mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_REVERSE_ROW_ORDER); |
| 392 | mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_ROW_LENGTH); |
| 393 | mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_SKIP_ROWS); |
| 394 | mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_SKIP_PIXELS); |
Corentin Wallez | bbd663a | 2016-04-20 17:49:17 -0400 | [diff] [blame] | 395 | mReadPixelsDirtyBits.set(State::DIRTY_BIT_PACK_BUFFER_BINDING); |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 396 | mReadPixelsDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER); |
| 397 | |
| 398 | mClearDirtyBits.set(State::DIRTY_BIT_RASTERIZER_DISCARD_ENABLED); |
| 399 | mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED); |
| 400 | mClearDirtyBits.set(State::DIRTY_BIT_SCISSOR); |
| 401 | mClearDirtyBits.set(State::DIRTY_BIT_VIEWPORT); |
| 402 | mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_COLOR); |
| 403 | mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_DEPTH); |
| 404 | mClearDirtyBits.set(State::DIRTY_BIT_CLEAR_STENCIL); |
| 405 | mClearDirtyBits.set(State::DIRTY_BIT_COLOR_MASK); |
| 406 | mClearDirtyBits.set(State::DIRTY_BIT_DEPTH_MASK); |
| 407 | mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_FRONT); |
| 408 | mClearDirtyBits.set(State::DIRTY_BIT_STENCIL_WRITEMASK_BACK); |
| 409 | mClearDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
| 410 | |
| 411 | mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR_TEST_ENABLED); |
| 412 | mBlitDirtyBits.set(State::DIRTY_BIT_SCISSOR); |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 413 | mBlitDirtyBits.set(State::DIRTY_BIT_FRAMEBUFFER_SRGB); |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 414 | mBlitDirtyObjects.set(State::DIRTY_OBJECT_READ_FRAMEBUFFER); |
| 415 | mBlitDirtyObjects.set(State::DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 416 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 417 | handleError(mImplementation->initialize()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 418 | } |
| 419 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 420 | egl::Error Context::onDestroy(const egl::Display *display) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 421 | { |
Corentin Wallez | 80b2411 | 2015-08-25 16:41:57 -0400 | [diff] [blame] | 422 | for (auto fence : mFenceNVMap) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 423 | { |
Corentin Wallez | 80b2411 | 2015-08-25 16:41:57 -0400 | [diff] [blame] | 424 | SafeDelete(fence.second); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 425 | } |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 426 | mFenceNVMap.clear(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 427 | |
Corentin Wallez | 80b2411 | 2015-08-25 16:41:57 -0400 | [diff] [blame] | 428 | for (auto query : mQueryMap) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 429 | { |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 430 | if (query.second != nullptr) |
| 431 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 432 | query.second->release(this); |
Geoff Lang | f0aa842 | 2015-09-29 15:08:34 -0400 | [diff] [blame] | 433 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 434 | } |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 435 | mQueryMap.clear(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 436 | |
Corentin Wallez | 80b2411 | 2015-08-25 16:41:57 -0400 | [diff] [blame] | 437 | for (auto vertexArray : mVertexArrayMap) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 438 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 439 | if (vertexArray.second) |
| 440 | { |
| 441 | vertexArray.second->onDestroy(this); |
| 442 | } |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 443 | } |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 444 | mVertexArrayMap.clear(); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 445 | |
Corentin Wallez | 80b2411 | 2015-08-25 16:41:57 -0400 | [diff] [blame] | 446 | for (auto transformFeedback : mTransformFeedbackMap) |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 447 | { |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 448 | if (transformFeedback.second != nullptr) |
| 449 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 450 | transformFeedback.second->release(this); |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 451 | } |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 452 | } |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 453 | mTransformFeedbackMap.clear(); |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 454 | |
Jamie Madill | dedd7b9 | 2014-11-05 16:30:36 -0500 | [diff] [blame] | 455 | for (auto &zeroTexture : mZeroTextures) |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 456 | { |
Jamie Madill | 71c88b3 | 2017-09-14 22:20:29 -0400 | [diff] [blame] | 457 | ANGLE_TRY(zeroTexture.second->onDestroy(this)); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 458 | zeroTexture.second.set(this, nullptr); |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 459 | } |
| 460 | mZeroTextures.clear(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 461 | |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 462 | SafeDelete(mSurfacelessFramebuffer); |
| 463 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 464 | ANGLE_TRY(releaseSurface(display)); |
Jamie Madill | 2f348d2 | 2017-06-05 10:50:59 -0400 | [diff] [blame] | 465 | releaseShaderCompiler(); |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 466 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 467 | mGLState.reset(this); |
| 468 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 469 | mState.mBuffers->release(this); |
| 470 | mState.mShaderPrograms->release(this); |
| 471 | mState.mTextures->release(this); |
| 472 | mState.mRenderbuffers->release(this); |
| 473 | mState.mSamplers->release(this); |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 474 | mState.mSyncs->release(this); |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 475 | mState.mPaths->release(this); |
| 476 | mState.mFramebuffers->release(this); |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame^] | 477 | mState.mPipelines->release(this); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 478 | |
| 479 | return egl::NoError(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 480 | } |
| 481 | |
Jamie Madill | 70ee0f6 | 2017-02-06 16:04:20 -0500 | [diff] [blame] | 482 | Context::~Context() |
| 483 | { |
| 484 | } |
| 485 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 486 | egl::Error Context::makeCurrent(egl::Display *display, egl::Surface *surface) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 487 | { |
Jamie Madill | 61e16b4 | 2017-06-19 11:13:23 -0400 | [diff] [blame] | 488 | mCurrentDisplay = display; |
| 489 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 490 | if (!mHasBeenCurrent) |
| 491 | { |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 492 | initRendererString(); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 493 | initVersionStrings(); |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 494 | initExtensionStrings(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 495 | |
Corentin Wallez | c295e51 | 2017-01-27 17:47:50 -0500 | [diff] [blame] | 496 | int width = 0; |
| 497 | int height = 0; |
| 498 | if (surface != nullptr) |
| 499 | { |
| 500 | width = surface->getWidth(); |
| 501 | height = surface->getHeight(); |
| 502 | } |
| 503 | |
| 504 | mGLState.setViewportParams(0, 0, width, height); |
| 505 | mGLState.setScissorParams(0, 0, width, height); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 506 | |
| 507 | mHasBeenCurrent = true; |
| 508 | } |
| 509 | |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 510 | // TODO(jmadill): Rework this when we support ContextImpl |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 511 | mGLState.setAllDirtyBits(); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 512 | mGLState.setAllDirtyObjects(); |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 513 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 514 | ANGLE_TRY(releaseSurface(display)); |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 515 | |
| 516 | Framebuffer *newDefault = nullptr; |
| 517 | if (surface != nullptr) |
| 518 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 519 | ANGLE_TRY(surface->setIsCurrent(this, true)); |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 520 | mCurrentSurface = surface; |
| 521 | newDefault = surface->getDefaultFramebuffer(); |
| 522 | } |
| 523 | else |
| 524 | { |
| 525 | if (mSurfacelessFramebuffer == nullptr) |
| 526 | { |
| 527 | mSurfacelessFramebuffer = new Framebuffer(mImplementation.get()); |
| 528 | } |
| 529 | |
| 530 | newDefault = mSurfacelessFramebuffer; |
| 531 | } |
Jamie Madill | 18fdcbc | 2015-08-19 18:12:44 +0000 | [diff] [blame] | 532 | |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 533 | // Update default framebuffer, the binding of the previous default |
| 534 | // framebuffer (or lack of) will have a nullptr. |
Jamie Madill | c1c1cdc | 2015-04-30 09:42:26 -0400 | [diff] [blame] | 535 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 536 | if (mGLState.getReadFramebuffer() == nullptr) |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 537 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 538 | mGLState.setReadFramebufferBinding(newDefault); |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 539 | } |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 540 | if (mGLState.getDrawFramebuffer() == nullptr) |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 541 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 542 | mGLState.setDrawFramebufferBinding(newDefault); |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 543 | } |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 544 | mState.mFramebuffers->setDefaultFramebuffer(newDefault); |
Jamie Madill | c1c1cdc | 2015-04-30 09:42:26 -0400 | [diff] [blame] | 545 | } |
Ian Ewell | 292f005 | 2016-02-04 10:37:32 -0500 | [diff] [blame] | 546 | |
| 547 | // Notify the renderer of a context switch |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 548 | mImplementation->onMakeCurrent(this); |
| 549 | return egl::NoError(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 550 | } |
| 551 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 552 | egl::Error Context::releaseSurface(const egl::Display *display) |
Jamie Madill | 77a72f6 | 2015-04-14 11:18:32 -0400 | [diff] [blame] | 553 | { |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 554 | // Remove the default framebuffer |
Corentin Wallez | c295e51 | 2017-01-27 17:47:50 -0500 | [diff] [blame] | 555 | Framebuffer *currentDefault = nullptr; |
| 556 | if (mCurrentSurface != nullptr) |
Corentin Wallez | 51706ea | 2015-08-07 14:39:22 -0400 | [diff] [blame] | 557 | { |
Corentin Wallez | c295e51 | 2017-01-27 17:47:50 -0500 | [diff] [blame] | 558 | currentDefault = mCurrentSurface->getDefaultFramebuffer(); |
| 559 | } |
| 560 | else if (mSurfacelessFramebuffer != nullptr) |
| 561 | { |
| 562 | currentDefault = mSurfacelessFramebuffer; |
Corentin Wallez | 51706ea | 2015-08-07 14:39:22 -0400 | [diff] [blame] | 563 | } |
| 564 | |
Corentin Wallez | c295e51 | 2017-01-27 17:47:50 -0500 | [diff] [blame] | 565 | if (mGLState.getReadFramebuffer() == currentDefault) |
| 566 | { |
| 567 | mGLState.setReadFramebufferBinding(nullptr); |
| 568 | } |
| 569 | if (mGLState.getDrawFramebuffer() == currentDefault) |
| 570 | { |
| 571 | mGLState.setDrawFramebufferBinding(nullptr); |
| 572 | } |
| 573 | mState.mFramebuffers->setDefaultFramebuffer(nullptr); |
| 574 | |
| 575 | if (mCurrentSurface) |
| 576 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 577 | ANGLE_TRY(mCurrentSurface->setIsCurrent(this, false)); |
Corentin Wallez | c295e51 | 2017-01-27 17:47:50 -0500 | [diff] [blame] | 578 | mCurrentSurface = nullptr; |
| 579 | } |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 580 | |
| 581 | return egl::NoError(); |
Jamie Madill | 77a72f6 | 2015-04-14 11:18:32 -0400 | [diff] [blame] | 582 | } |
| 583 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 584 | GLuint Context::createBuffer() |
| 585 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 586 | return mState.mBuffers->createBuffer(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | GLuint Context::createProgram() |
| 590 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 591 | return mState.mShaderPrograms->createProgram(mImplementation.get()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | GLuint Context::createShader(GLenum type) |
| 595 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 596 | return mState.mShaderPrograms->createShader(mImplementation.get(), mLimitations, type); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | GLuint Context::createTexture() |
| 600 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 601 | return mState.mTextures->createTexture(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | GLuint Context::createRenderbuffer() |
| 605 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 606 | return mState.mRenderbuffers->createRenderbuffer(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 607 | } |
| 608 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 609 | GLuint Context::createPaths(GLsizei range) |
| 610 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 611 | auto resultOrError = mState.mPaths->createPaths(mImplementation.get(), range); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 612 | if (resultOrError.isError()) |
| 613 | { |
| 614 | handleError(resultOrError.getError()); |
| 615 | return 0; |
| 616 | } |
| 617 | return resultOrError.getResult(); |
| 618 | } |
| 619 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 620 | // Returns an unused framebuffer name |
| 621 | GLuint Context::createFramebuffer() |
| 622 | { |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 623 | return mState.mFramebuffers->createFramebuffer(); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 624 | } |
| 625 | |
Jamie Madill | 33dc843 | 2013-07-26 11:55:05 -0400 | [diff] [blame] | 626 | GLuint Context::createFenceNV() |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 627 | { |
Jamie Madill | 33dc843 | 2013-07-26 11:55:05 -0400 | [diff] [blame] | 628 | GLuint handle = mFenceNVHandleAllocator.allocate(); |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 629 | mFenceNVMap.assign(handle, new FenceNV(mImplementation->createFenceNV())); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 630 | return handle; |
| 631 | } |
| 632 | |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame^] | 633 | GLuint Context::createProgramPipeline() |
| 634 | { |
| 635 | return mState.mPipelines->createProgramPipeline(); |
| 636 | } |
| 637 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 638 | void Context::deleteBuffer(GLuint buffer) |
| 639 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 640 | if (mState.mBuffers->getBuffer(buffer)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 641 | { |
| 642 | detachBuffer(buffer); |
| 643 | } |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 644 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 645 | mState.mBuffers->deleteObject(this, buffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | void Context::deleteShader(GLuint shader) |
| 649 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 650 | mState.mShaderPrograms->deleteShader(this, shader); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 651 | } |
| 652 | |
| 653 | void Context::deleteProgram(GLuint program) |
| 654 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 655 | mState.mShaderPrograms->deleteProgram(this, program); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 656 | } |
| 657 | |
| 658 | void Context::deleteTexture(GLuint texture) |
| 659 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 660 | if (mState.mTextures->getTexture(texture)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 661 | { |
| 662 | detachTexture(texture); |
| 663 | } |
| 664 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 665 | mState.mTextures->deleteObject(this, texture); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | void Context::deleteRenderbuffer(GLuint renderbuffer) |
| 669 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 670 | if (mState.mRenderbuffers->getRenderbuffer(renderbuffer)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 671 | { |
| 672 | detachRenderbuffer(renderbuffer); |
| 673 | } |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 674 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 675 | mState.mRenderbuffers->deleteObject(this, renderbuffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 676 | } |
| 677 | |
Jamie Madill | 7f0c5a4 | 2017-08-26 22:43:26 -0400 | [diff] [blame] | 678 | void Context::deleteSync(GLsync sync) |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame] | 679 | { |
| 680 | // The spec specifies the underlying Fence object is not deleted until all current |
| 681 | // wait commands finish. However, since the name becomes invalid, we cannot query the fence, |
| 682 | // and since our API is currently designed for being called from a single thread, we can delete |
| 683 | // the fence immediately. |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 684 | mState.mSyncs->deleteObject(this, static_cast<GLuint>(reinterpret_cast<uintptr_t>(sync))); |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame] | 685 | } |
| 686 | |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame^] | 687 | void Context::deleteProgramPipeline(GLuint pipeline) |
| 688 | { |
| 689 | if (mState.mPipelines->getProgramPipeline(pipeline)) |
| 690 | { |
| 691 | detachProgramPipeline(pipeline); |
| 692 | } |
| 693 | |
| 694 | mState.mPipelines->deleteObject(this, pipeline); |
| 695 | } |
| 696 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 697 | void Context::deletePaths(GLuint first, GLsizei range) |
| 698 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 699 | mState.mPaths->deletePaths(first, range); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | bool Context::hasPathData(GLuint path) const |
| 703 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 704 | const auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 705 | if (pathObj == nullptr) |
| 706 | return false; |
| 707 | |
| 708 | return pathObj->hasPathData(); |
| 709 | } |
| 710 | |
| 711 | bool Context::hasPath(GLuint path) const |
| 712 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 713 | return mState.mPaths->hasPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | void Context::setPathCommands(GLuint path, |
| 717 | GLsizei numCommands, |
| 718 | const GLubyte *commands, |
| 719 | GLsizei numCoords, |
| 720 | GLenum coordType, |
| 721 | const void *coords) |
| 722 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 723 | auto *pathObject = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 724 | |
| 725 | handleError(pathObject->setCommands(numCommands, commands, numCoords, coordType, coords)); |
| 726 | } |
| 727 | |
| 728 | void Context::setPathParameterf(GLuint path, GLenum pname, GLfloat value) |
| 729 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 730 | auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 731 | |
| 732 | switch (pname) |
| 733 | { |
| 734 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 735 | pathObj->setStrokeWidth(value); |
| 736 | break; |
| 737 | case GL_PATH_END_CAPS_CHROMIUM: |
| 738 | pathObj->setEndCaps(static_cast<GLenum>(value)); |
| 739 | break; |
| 740 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 741 | pathObj->setJoinStyle(static_cast<GLenum>(value)); |
| 742 | break; |
| 743 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 744 | pathObj->setMiterLimit(value); |
| 745 | break; |
| 746 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 747 | pathObj->setStrokeBound(value); |
| 748 | break; |
| 749 | default: |
| 750 | UNREACHABLE(); |
| 751 | break; |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | void Context::getPathParameterfv(GLuint path, GLenum pname, GLfloat *value) const |
| 756 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 757 | const auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 758 | |
| 759 | switch (pname) |
| 760 | { |
| 761 | case GL_PATH_STROKE_WIDTH_CHROMIUM: |
| 762 | *value = pathObj->getStrokeWidth(); |
| 763 | break; |
| 764 | case GL_PATH_END_CAPS_CHROMIUM: |
| 765 | *value = static_cast<GLfloat>(pathObj->getEndCaps()); |
| 766 | break; |
| 767 | case GL_PATH_JOIN_STYLE_CHROMIUM: |
| 768 | *value = static_cast<GLfloat>(pathObj->getJoinStyle()); |
| 769 | break; |
| 770 | case GL_PATH_MITER_LIMIT_CHROMIUM: |
| 771 | *value = pathObj->getMiterLimit(); |
| 772 | break; |
| 773 | case GL_PATH_STROKE_BOUND_CHROMIUM: |
| 774 | *value = pathObj->getStrokeBound(); |
| 775 | break; |
| 776 | default: |
| 777 | UNREACHABLE(); |
| 778 | break; |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | void Context::setPathStencilFunc(GLenum func, GLint ref, GLuint mask) |
| 783 | { |
| 784 | mGLState.setPathStencilFunc(func, ref, mask); |
| 785 | } |
| 786 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 787 | void Context::deleteFramebuffer(GLuint framebuffer) |
| 788 | { |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 789 | if (mState.mFramebuffers->getFramebuffer(framebuffer)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 790 | { |
| 791 | detachFramebuffer(framebuffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 792 | } |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 793 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 794 | mState.mFramebuffers->deleteObject(this, framebuffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 795 | } |
| 796 | |
Jamie Madill | 33dc843 | 2013-07-26 11:55:05 -0400 | [diff] [blame] | 797 | void Context::deleteFenceNV(GLuint fence) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 798 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 799 | FenceNV *fenceObject = nullptr; |
| 800 | if (mFenceNVMap.erase(fence, &fenceObject)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 801 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 802 | mFenceNVHandleAllocator.release(fence); |
| 803 | delete fenceObject; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 804 | } |
| 805 | } |
| 806 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 807 | Buffer *Context::getBuffer(GLuint handle) const |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 808 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 809 | return mState.mBuffers->getBuffer(handle); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 810 | } |
| 811 | |
Jamie Madill | 570f7c8 | 2014-07-03 10:38:54 -0400 | [diff] [blame] | 812 | Texture *Context::getTexture(GLuint handle) const |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 813 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 814 | return mState.mTextures->getTexture(handle); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 815 | } |
| 816 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 817 | Renderbuffer *Context::getRenderbuffer(GLuint handle) const |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 818 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 819 | return mState.mRenderbuffers->getRenderbuffer(handle); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 820 | } |
| 821 | |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 822 | Sync *Context::getSync(GLsync handle) const |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame] | 823 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 824 | return mState.mSyncs->getSync(static_cast<GLuint>(reinterpret_cast<uintptr_t>(handle))); |
Jamie Madill | cd055f8 | 2013-07-26 11:55:15 -0400 | [diff] [blame] | 825 | } |
| 826 | |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 827 | VertexArray *Context::getVertexArray(GLuint handle) const |
| 828 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 829 | return mVertexArrayMap.query(handle); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 830 | } |
| 831 | |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 832 | Sampler *Context::getSampler(GLuint handle) const |
| 833 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 834 | return mState.mSamplers->getSampler(handle); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 835 | } |
| 836 | |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 837 | TransformFeedback *Context::getTransformFeedback(GLuint handle) const |
| 838 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 839 | return mTransformFeedbackMap.query(handle); |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 840 | } |
| 841 | |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame^] | 842 | ProgramPipeline *Context::getProgramPipeline(GLuint handle) const |
| 843 | { |
| 844 | return mState.mPipelines->getProgramPipeline(handle); |
| 845 | } |
| 846 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 847 | LabeledObject *Context::getLabeledObject(GLenum identifier, GLuint name) const |
| 848 | { |
| 849 | switch (identifier) |
| 850 | { |
| 851 | case GL_BUFFER: |
| 852 | return getBuffer(name); |
| 853 | case GL_SHADER: |
| 854 | return getShader(name); |
| 855 | case GL_PROGRAM: |
| 856 | return getProgram(name); |
| 857 | case GL_VERTEX_ARRAY: |
| 858 | return getVertexArray(name); |
| 859 | case GL_QUERY: |
| 860 | return getQuery(name); |
| 861 | case GL_TRANSFORM_FEEDBACK: |
| 862 | return getTransformFeedback(name); |
| 863 | case GL_SAMPLER: |
| 864 | return getSampler(name); |
| 865 | case GL_TEXTURE: |
| 866 | return getTexture(name); |
| 867 | case GL_RENDERBUFFER: |
| 868 | return getRenderbuffer(name); |
| 869 | case GL_FRAMEBUFFER: |
| 870 | return getFramebuffer(name); |
| 871 | default: |
| 872 | UNREACHABLE(); |
| 873 | return nullptr; |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | LabeledObject *Context::getLabeledObjectFromPtr(const void *ptr) const |
| 878 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 879 | return getSync(reinterpret_cast<GLsync>(const_cast<void *>(ptr))); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 880 | } |
| 881 | |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 882 | void Context::objectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar *label) |
| 883 | { |
| 884 | LabeledObject *object = getLabeledObject(identifier, name); |
| 885 | ASSERT(object != nullptr); |
| 886 | |
| 887 | std::string labelName = GetObjectLabelFromPointer(length, label); |
| 888 | object->setLabel(labelName); |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 889 | |
| 890 | // TODO(jmadill): Determine if the object is dirty based on 'name'. Conservatively assume the |
| 891 | // specified object is active until we do this. |
| 892 | mGLState.setObjectDirty(identifier); |
Martin Radev | 9d90179 | 2016-07-15 15:58:58 +0300 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | void Context::objectPtrLabel(const void *ptr, GLsizei length, const GLchar *label) |
| 896 | { |
| 897 | LabeledObject *object = getLabeledObjectFromPtr(ptr); |
| 898 | ASSERT(object != nullptr); |
| 899 | |
| 900 | std::string labelName = GetObjectLabelFromPointer(length, label); |
| 901 | object->setLabel(labelName); |
| 902 | } |
| 903 | |
| 904 | void Context::getObjectLabel(GLenum identifier, |
| 905 | GLuint name, |
| 906 | GLsizei bufSize, |
| 907 | GLsizei *length, |
| 908 | GLchar *label) const |
| 909 | { |
| 910 | LabeledObject *object = getLabeledObject(identifier, name); |
| 911 | ASSERT(object != nullptr); |
| 912 | |
| 913 | const std::string &objectLabel = object->getLabel(); |
| 914 | GetObjectLabelBase(objectLabel, bufSize, length, label); |
| 915 | } |
| 916 | |
| 917 | void Context::getObjectPtrLabel(const void *ptr, |
| 918 | GLsizei bufSize, |
| 919 | GLsizei *length, |
| 920 | GLchar *label) const |
| 921 | { |
| 922 | LabeledObject *object = getLabeledObjectFromPtr(ptr); |
| 923 | ASSERT(object != nullptr); |
| 924 | |
| 925 | const std::string &objectLabel = object->getLabel(); |
| 926 | GetObjectLabelBase(objectLabel, bufSize, length, label); |
| 927 | } |
| 928 | |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 929 | bool Context::isSampler(GLuint samplerName) const |
| 930 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 931 | return mState.mSamplers->isSampler(samplerName); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 932 | } |
| 933 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 934 | void Context::bindArrayBuffer(GLuint bufferHandle) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 935 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 936 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 937 | mGLState.setArrayBufferBinding(this, buffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 938 | } |
| 939 | |
Jiajia Qin | 9d7d0b1 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 940 | void Context::bindDrawIndirectBuffer(GLuint bufferHandle) |
| 941 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 942 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 943 | mGLState.setDrawIndirectBufferBinding(this, buffer); |
Jiajia Qin | 9d7d0b1 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 944 | } |
| 945 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 946 | void Context::bindElementArrayBuffer(GLuint bufferHandle) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 947 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 948 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 949 | mGLState.setElementArrayBuffer(this, buffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 950 | } |
| 951 | |
Jamie Madill | dedd7b9 | 2014-11-05 16:30:36 -0500 | [diff] [blame] | 952 | void Context::bindTexture(GLenum target, GLuint handle) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 953 | { |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 954 | Texture *texture = nullptr; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 955 | |
Jamie Madill | dedd7b9 | 2014-11-05 16:30:36 -0500 | [diff] [blame] | 956 | if (handle == 0) |
| 957 | { |
| 958 | texture = mZeroTextures[target].get(); |
| 959 | } |
| 960 | else |
| 961 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 962 | texture = mState.mTextures->checkTextureAllocation(mImplementation.get(), handle, target); |
Jamie Madill | dedd7b9 | 2014-11-05 16:30:36 -0500 | [diff] [blame] | 963 | } |
| 964 | |
| 965 | ASSERT(texture); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 966 | mGLState.setSamplerTexture(this, target, texture); |
shannon.woods%transgaming.com@gtempaccount.com | 90dbc44 | 2013-04-13 03:46:14 +0000 | [diff] [blame] | 967 | } |
| 968 | |
Jamie Madill | 5bf9ff4 | 2016-02-01 11:13:03 -0500 | [diff] [blame] | 969 | void Context::bindReadFramebuffer(GLuint framebufferHandle) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 970 | { |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 971 | Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation( |
| 972 | mImplementation.get(), mCaps, framebufferHandle); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 973 | mGLState.setReadFramebufferBinding(framebuffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 974 | } |
| 975 | |
Jamie Madill | 5bf9ff4 | 2016-02-01 11:13:03 -0500 | [diff] [blame] | 976 | void Context::bindDrawFramebuffer(GLuint framebufferHandle) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 977 | { |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 978 | Framebuffer *framebuffer = mState.mFramebuffers->checkFramebufferAllocation( |
| 979 | mImplementation.get(), mCaps, framebufferHandle); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 980 | mGLState.setDrawFramebufferBinding(framebuffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 981 | } |
| 982 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 983 | void Context::bindVertexArray(GLuint vertexArrayHandle) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 984 | { |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 985 | VertexArray *vertexArray = checkVertexArrayAllocation(vertexArrayHandle); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 986 | mGLState.setVertexArrayBinding(vertexArray); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 987 | } |
| 988 | |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 989 | void Context::bindVertexBuffer(GLuint bindingIndex, |
| 990 | GLuint bufferHandle, |
| 991 | GLintptr offset, |
| 992 | GLsizei stride) |
| 993 | { |
| 994 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 995 | mGLState.bindVertexBuffer(this, bindingIndex, buffer, offset, stride); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 996 | } |
| 997 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 998 | void Context::bindSampler(GLuint textureUnit, GLuint samplerHandle) |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 999 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 1000 | ASSERT(textureUnit < mCaps.maxCombinedTextureImageUnits); |
Jamie Madill | 901b379 | 2016-05-26 09:20:40 -0400 | [diff] [blame] | 1001 | Sampler *sampler = |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1002 | mState.mSamplers->checkSamplerAllocation(mImplementation.get(), samplerHandle); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1003 | mGLState.setSamplerBinding(this, textureUnit, sampler); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 1004 | } |
| 1005 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 1006 | void Context::bindImageTexture(GLuint unit, |
| 1007 | GLuint texture, |
| 1008 | GLint level, |
| 1009 | GLboolean layered, |
| 1010 | GLint layer, |
| 1011 | GLenum access, |
| 1012 | GLenum format) |
| 1013 | { |
| 1014 | Texture *tex = mState.mTextures->getTexture(texture); |
| 1015 | mGLState.setImageUnit(this, unit, tex, level, layered, layer, access, format); |
| 1016 | } |
| 1017 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 1018 | void Context::bindGenericUniformBuffer(GLuint bufferHandle) |
shannon.woods%transgaming.com@gtempaccount.com | 667a29c | 2013-04-13 03:39:04 +0000 | [diff] [blame] | 1019 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1020 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1021 | mGLState.setGenericUniformBufferBinding(this, buffer); |
shannon.woods%transgaming.com@gtempaccount.com | 667a29c | 2013-04-13 03:39:04 +0000 | [diff] [blame] | 1022 | } |
| 1023 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 1024 | void Context::bindIndexedUniformBuffer(GLuint bufferHandle, |
| 1025 | GLuint index, |
| 1026 | GLintptr offset, |
| 1027 | GLsizeiptr size) |
shannon.woods%transgaming.com@gtempaccount.com | 3408935 | 2013-04-13 03:36:57 +0000 | [diff] [blame] | 1028 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1029 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1030 | mGLState.setIndexedUniformBufferBinding(this, index, buffer, offset, size); |
shannon.woods%transgaming.com@gtempaccount.com | 3408935 | 2013-04-13 03:36:57 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 1033 | void Context::bindGenericTransformFeedbackBuffer(GLuint bufferHandle) |
shannon.woods%transgaming.com@gtempaccount.com | 667a29c | 2013-04-13 03:39:04 +0000 | [diff] [blame] | 1034 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1035 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1036 | mGLState.getCurrentTransformFeedback()->bindGenericBuffer(this, buffer); |
shannon.woods%transgaming.com@gtempaccount.com | 667a29c | 2013-04-13 03:39:04 +0000 | [diff] [blame] | 1037 | } |
| 1038 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 1039 | void Context::bindIndexedTransformFeedbackBuffer(GLuint bufferHandle, |
| 1040 | GLuint index, |
| 1041 | GLintptr offset, |
| 1042 | GLsizeiptr size) |
shannon.woods%transgaming.com@gtempaccount.com | 3408935 | 2013-04-13 03:36:57 +0000 | [diff] [blame] | 1043 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1044 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1045 | mGLState.getCurrentTransformFeedback()->bindIndexedBuffer(this, index, buffer, offset, size); |
shannon.woods%transgaming.com@gtempaccount.com | 3408935 | 2013-04-13 03:36:57 +0000 | [diff] [blame] | 1046 | } |
| 1047 | |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1048 | void Context::bindGenericAtomicCounterBuffer(GLuint bufferHandle) |
| 1049 | { |
| 1050 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1051 | mGLState.setGenericAtomicCounterBufferBinding(this, buffer); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | void Context::bindIndexedAtomicCounterBuffer(GLuint bufferHandle, |
| 1055 | GLuint index, |
| 1056 | GLintptr offset, |
| 1057 | GLsizeiptr size) |
| 1058 | { |
| 1059 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1060 | mGLState.setIndexedAtomicCounterBufferBinding(this, index, buffer, offset, size); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1061 | } |
| 1062 | |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1063 | void Context::bindGenericShaderStorageBuffer(GLuint bufferHandle) |
| 1064 | { |
| 1065 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1066 | mGLState.setGenericShaderStorageBufferBinding(this, buffer); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1067 | } |
| 1068 | |
| 1069 | void Context::bindIndexedShaderStorageBuffer(GLuint bufferHandle, |
| 1070 | GLuint index, |
| 1071 | GLintptr offset, |
| 1072 | GLsizeiptr size) |
| 1073 | { |
| 1074 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1075 | mGLState.setIndexedShaderStorageBufferBinding(this, index, buffer, offset, size); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1076 | } |
| 1077 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 1078 | void Context::bindCopyReadBuffer(GLuint bufferHandle) |
shannon.woods%transgaming.com@gtempaccount.com | 5117188 | 2013-04-13 03:39:10 +0000 | [diff] [blame] | 1079 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1080 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1081 | mGLState.setCopyReadBufferBinding(this, buffer); |
shannon.woods%transgaming.com@gtempaccount.com | 5117188 | 2013-04-13 03:39:10 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 1084 | void Context::bindCopyWriteBuffer(GLuint bufferHandle) |
shannon.woods%transgaming.com@gtempaccount.com | 5117188 | 2013-04-13 03:39:10 +0000 | [diff] [blame] | 1085 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1086 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1087 | mGLState.setCopyWriteBufferBinding(this, buffer); |
shannon.woods%transgaming.com@gtempaccount.com | 5117188 | 2013-04-13 03:39:10 +0000 | [diff] [blame] | 1088 | } |
| 1089 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 1090 | void Context::bindPixelPackBuffer(GLuint bufferHandle) |
shannon.woods%transgaming.com@gtempaccount.com | c926e5f | 2013-04-13 03:39:18 +0000 | [diff] [blame] | 1091 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1092 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1093 | mGLState.setPixelPackBufferBinding(this, buffer); |
shannon.woods%transgaming.com@gtempaccount.com | c926e5f | 2013-04-13 03:39:18 +0000 | [diff] [blame] | 1094 | } |
| 1095 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 1096 | void Context::bindPixelUnpackBuffer(GLuint bufferHandle) |
shannon.woods%transgaming.com@gtempaccount.com | c926e5f | 2013-04-13 03:39:18 +0000 | [diff] [blame] | 1097 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1098 | Buffer *buffer = mState.mBuffers->checkBufferAllocation(mImplementation.get(), bufferHandle); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1099 | mGLState.setPixelUnpackBufferBinding(this, buffer); |
shannon.woods%transgaming.com@gtempaccount.com | c926e5f | 2013-04-13 03:39:18 +0000 | [diff] [blame] | 1100 | } |
| 1101 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1102 | void Context::useProgram(GLuint program) |
| 1103 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 1104 | mGLState.setProgram(this, getProgram(program)); |
daniel@transgaming.com | 95d2942 | 2012-07-24 18:36:10 +0000 | [diff] [blame] | 1105 | } |
| 1106 | |
Jamie Madill | f0dcb8b | 2017-08-26 19:05:13 -0400 | [diff] [blame] | 1107 | void Context::bindTransformFeedback(GLenum target, GLuint transformFeedbackHandle) |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 1108 | { |
Jamie Madill | f0dcb8b | 2017-08-26 19:05:13 -0400 | [diff] [blame] | 1109 | ASSERT(target == GL_TRANSFORM_FEEDBACK); |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 1110 | TransformFeedback *transformFeedback = |
| 1111 | checkTransformFeedbackAllocation(transformFeedbackHandle); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1112 | mGLState.setTransformFeedbackBinding(this, transformFeedback); |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 1113 | } |
| 1114 | |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame^] | 1115 | void Context::bindProgramPipeline(GLuint pipelineHandle) |
| 1116 | { |
| 1117 | ProgramPipeline *pipeline = |
| 1118 | mState.mPipelines->checkProgramPipelineAllocation(mImplementation.get(), pipelineHandle); |
| 1119 | mGLState.setProgramPipelineBinding(this, pipeline); |
| 1120 | } |
| 1121 | |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1122 | void Context::beginQuery(GLenum target, GLuint query) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1123 | { |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1124 | Query *queryObject = getQuery(query, true, target); |
Jamie Madill | db2f14c | 2014-05-13 13:56:30 -0400 | [diff] [blame] | 1125 | ASSERT(queryObject); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1126 | |
Geoff Lang | 5aad967 | 2014-09-08 11:10:42 -0400 | [diff] [blame] | 1127 | // begin query |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1128 | ANGLE_CONTEXT_TRY(queryObject->begin()); |
Geoff Lang | 5aad967 | 2014-09-08 11:10:42 -0400 | [diff] [blame] | 1129 | |
| 1130 | // set query as active for specified target only if begin succeeded |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1131 | mGLState.setActiveQuery(this, target, queryObject); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1132 | } |
| 1133 | |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1134 | void Context::endQuery(GLenum target) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1135 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1136 | Query *queryObject = mGLState.getActiveQuery(target); |
Jamie Madill | 45c785d | 2014-05-13 14:09:34 -0400 | [diff] [blame] | 1137 | ASSERT(queryObject); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1138 | |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1139 | handleError(queryObject->end()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1140 | |
Geoff Lang | 5aad967 | 2014-09-08 11:10:42 -0400 | [diff] [blame] | 1141 | // Always unbind the query, even if there was an error. This may delete the query object. |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1142 | mGLState.setActiveQuery(this, target, nullptr); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1143 | } |
| 1144 | |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1145 | void Context::queryCounter(GLuint id, GLenum target) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1146 | { |
| 1147 | ASSERT(target == GL_TIMESTAMP_EXT); |
| 1148 | |
| 1149 | Query *queryObject = getQuery(id, true, target); |
| 1150 | ASSERT(queryObject); |
| 1151 | |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 1152 | handleError(queryObject->queryCounter()); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1153 | } |
| 1154 | |
| 1155 | void Context::getQueryiv(GLenum target, GLenum pname, GLint *params) |
| 1156 | { |
| 1157 | switch (pname) |
| 1158 | { |
| 1159 | case GL_CURRENT_QUERY_EXT: |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1160 | params[0] = mGLState.getActiveQueryId(target); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1161 | break; |
| 1162 | case GL_QUERY_COUNTER_BITS_EXT: |
| 1163 | switch (target) |
| 1164 | { |
| 1165 | case GL_TIME_ELAPSED_EXT: |
| 1166 | params[0] = getExtensions().queryCounterBitsTimeElapsed; |
| 1167 | break; |
| 1168 | case GL_TIMESTAMP_EXT: |
| 1169 | params[0] = getExtensions().queryCounterBitsTimestamp; |
| 1170 | break; |
| 1171 | default: |
| 1172 | UNREACHABLE(); |
| 1173 | params[0] = 0; |
| 1174 | break; |
| 1175 | } |
| 1176 | break; |
| 1177 | default: |
| 1178 | UNREACHABLE(); |
| 1179 | return; |
| 1180 | } |
| 1181 | } |
| 1182 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1183 | void Context::getQueryObjectiv(GLuint id, GLenum pname, GLint *params) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1184 | { |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1185 | handleError(GetQueryObjectParameter(getQuery(id), pname, params)); |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1186 | } |
| 1187 | |
Geoff Lang | 2186c38 | 2016-10-14 10:54:54 -0400 | [diff] [blame] | 1188 | void Context::getQueryObjectuiv(GLuint id, GLenum pname, GLuint *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::getQueryObjecti64v(GLuint id, GLenum pname, GLint64 *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::getQueryObjectui64v(GLuint id, GLenum pname, GLuint64 *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 | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 1203 | Framebuffer *Context::getFramebuffer(GLuint handle) const |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1204 | { |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 1205 | return mState.mFramebuffers->getFramebuffer(handle); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1206 | } |
| 1207 | |
Jamie Madill | 2f348d2 | 2017-06-05 10:50:59 -0400 | [diff] [blame] | 1208 | FenceNV *Context::getFenceNV(GLuint handle) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1209 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 1210 | return mFenceNVMap.query(handle); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1211 | } |
| 1212 | |
Jamie Madill | 2f348d2 | 2017-06-05 10:50:59 -0400 | [diff] [blame] | 1213 | Query *Context::getQuery(GLuint handle, bool create, GLenum type) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1214 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 1215 | if (!mQueryMap.contains(handle)) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1216 | { |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 1217 | return nullptr; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1218 | } |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 1219 | |
| 1220 | Query *query = mQueryMap.query(handle); |
| 1221 | if (!query && create) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1222 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 1223 | query = new Query(mImplementation->createQuery(type), handle); |
| 1224 | query->addRef(); |
| 1225 | mQueryMap.assign(handle, query); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1226 | } |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 1227 | return query; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1228 | } |
| 1229 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1230 | Query *Context::getQuery(GLuint handle) const |
| 1231 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 1232 | return mQueryMap.query(handle); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1233 | } |
| 1234 | |
Jamie Madill | 1fc7e2c | 2014-01-21 16:47:10 -0500 | [diff] [blame] | 1235 | Texture *Context::getTargetTexture(GLenum target) const |
| 1236 | { |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 1237 | ASSERT(ValidTextureTarget(this, target) || ValidTextureExternalTarget(this, target)); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1238 | return mGLState.getTargetTexture(target); |
shannon.woods%transgaming.com@gtempaccount.com | c926e5f | 2013-04-13 03:39:18 +0000 | [diff] [blame] | 1239 | } |
| 1240 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 1241 | Texture *Context::getSamplerTexture(unsigned int sampler, GLenum type) const |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1242 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1243 | return mGLState.getSamplerTexture(sampler, type); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1244 | } |
| 1245 | |
Geoff Lang | 492a7e4 | 2014-11-05 13:27:06 -0500 | [diff] [blame] | 1246 | Compiler *Context::getCompiler() const |
| 1247 | { |
Jamie Madill | 2f348d2 | 2017-06-05 10:50:59 -0400 | [diff] [blame] | 1248 | if (mCompiler.get() == nullptr) |
| 1249 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1250 | mCompiler.set(this, new Compiler(mImplementation.get(), mState)); |
Jamie Madill | 2f348d2 | 2017-06-05 10:50:59 -0400 | [diff] [blame] | 1251 | } |
| 1252 | return mCompiler.get(); |
Geoff Lang | 492a7e4 | 2014-11-05 13:27:06 -0500 | [diff] [blame] | 1253 | } |
| 1254 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 1255 | void Context::getBooleanvImpl(GLenum pname, GLboolean *params) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1256 | { |
| 1257 | switch (pname) |
| 1258 | { |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 1259 | case GL_SHADER_COMPILER: |
| 1260 | *params = GL_TRUE; |
| 1261 | break; |
| 1262 | case GL_CONTEXT_ROBUST_ACCESS_EXT: |
| 1263 | *params = mRobustAccess ? GL_TRUE : GL_FALSE; |
| 1264 | break; |
| 1265 | default: |
| 1266 | mGLState.getBooleanv(pname, params); |
| 1267 | break; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1268 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1269 | } |
| 1270 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 1271 | void Context::getFloatvImpl(GLenum pname, GLfloat *params) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1272 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1273 | // Queries about context capabilities and maximums are answered by Context. |
| 1274 | // Queries about current GL state values are answered by State. |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1275 | switch (pname) |
| 1276 | { |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 1277 | case GL_ALIASED_LINE_WIDTH_RANGE: |
| 1278 | params[0] = mCaps.minAliasedLineWidth; |
| 1279 | params[1] = mCaps.maxAliasedLineWidth; |
| 1280 | break; |
| 1281 | case GL_ALIASED_POINT_SIZE_RANGE: |
| 1282 | params[0] = mCaps.minAliasedPointSize; |
| 1283 | params[1] = mCaps.maxAliasedPointSize; |
| 1284 | break; |
| 1285 | case GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT: |
| 1286 | ASSERT(mExtensions.textureFilterAnisotropic); |
| 1287 | *params = mExtensions.maxTextureAnisotropy; |
| 1288 | break; |
| 1289 | case GL_MAX_TEXTURE_LOD_BIAS: |
| 1290 | *params = mCaps.maxLODBias; |
| 1291 | break; |
| 1292 | |
| 1293 | case GL_PATH_MODELVIEW_MATRIX_CHROMIUM: |
| 1294 | case GL_PATH_PROJECTION_MATRIX_CHROMIUM: |
| 1295 | { |
| 1296 | ASSERT(mExtensions.pathRendering); |
| 1297 | const GLfloat *m = mGLState.getPathRenderingMatrix(pname); |
| 1298 | memcpy(params, m, 16 * sizeof(GLfloat)); |
| 1299 | } |
Geoff Lang | e6d4e12 | 2015-06-29 13:33:55 -0400 | [diff] [blame] | 1300 | break; |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1301 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 1302 | default: |
| 1303 | mGLState.getFloatv(pname, params); |
| 1304 | break; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1305 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1306 | } |
| 1307 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 1308 | void Context::getIntegervImpl(GLenum pname, GLint *params) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1309 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1310 | // Queries about context capabilities and maximums are answered by Context. |
| 1311 | // 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] | 1312 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1313 | switch (pname) |
| 1314 | { |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 1315 | case GL_MAX_VERTEX_ATTRIBS: |
| 1316 | *params = mCaps.maxVertexAttributes; |
| 1317 | break; |
| 1318 | case GL_MAX_VERTEX_UNIFORM_VECTORS: |
| 1319 | *params = mCaps.maxVertexUniformVectors; |
| 1320 | break; |
| 1321 | case GL_MAX_VERTEX_UNIFORM_COMPONENTS: |
| 1322 | *params = mCaps.maxVertexUniformComponents; |
| 1323 | break; |
| 1324 | case GL_MAX_VARYING_VECTORS: |
| 1325 | *params = mCaps.maxVaryingVectors; |
| 1326 | break; |
| 1327 | case GL_MAX_VARYING_COMPONENTS: |
| 1328 | *params = mCaps.maxVertexOutputComponents; |
| 1329 | break; |
| 1330 | case GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS: |
| 1331 | *params = mCaps.maxCombinedTextureImageUnits; |
| 1332 | break; |
| 1333 | case GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS: |
| 1334 | *params = mCaps.maxVertexTextureImageUnits; |
| 1335 | break; |
| 1336 | case GL_MAX_TEXTURE_IMAGE_UNITS: |
| 1337 | *params = mCaps.maxTextureImageUnits; |
| 1338 | break; |
| 1339 | case GL_MAX_FRAGMENT_UNIFORM_VECTORS: |
| 1340 | *params = mCaps.maxFragmentUniformVectors; |
| 1341 | break; |
| 1342 | case GL_MAX_FRAGMENT_UNIFORM_COMPONENTS: |
| 1343 | *params = mCaps.maxFragmentUniformComponents; |
| 1344 | break; |
| 1345 | case GL_MAX_RENDERBUFFER_SIZE: |
| 1346 | *params = mCaps.maxRenderbufferSize; |
| 1347 | break; |
| 1348 | case GL_MAX_COLOR_ATTACHMENTS_EXT: |
| 1349 | *params = mCaps.maxColorAttachments; |
| 1350 | break; |
| 1351 | case GL_MAX_DRAW_BUFFERS_EXT: |
| 1352 | *params = mCaps.maxDrawBuffers; |
| 1353 | break; |
| 1354 | // case GL_FRAMEBUFFER_BINDING: // now equivalent to |
| 1355 | // GL_DRAW_FRAMEBUFFER_BINDING_ANGLE |
| 1356 | case GL_SUBPIXEL_BITS: |
| 1357 | *params = 4; |
| 1358 | break; |
| 1359 | case GL_MAX_TEXTURE_SIZE: |
| 1360 | *params = mCaps.max2DTextureSize; |
| 1361 | break; |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 1362 | case GL_MAX_RECTANGLE_TEXTURE_SIZE_ANGLE: |
| 1363 | *params = mCaps.maxRectangleTextureSize; |
| 1364 | break; |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 1365 | case GL_MAX_CUBE_MAP_TEXTURE_SIZE: |
| 1366 | *params = mCaps.maxCubeMapTextureSize; |
| 1367 | break; |
| 1368 | case GL_MAX_3D_TEXTURE_SIZE: |
| 1369 | *params = mCaps.max3DTextureSize; |
| 1370 | break; |
| 1371 | case GL_MAX_ARRAY_TEXTURE_LAYERS: |
| 1372 | *params = mCaps.maxArrayTextureLayers; |
| 1373 | break; |
| 1374 | case GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT: |
| 1375 | *params = mCaps.uniformBufferOffsetAlignment; |
| 1376 | break; |
| 1377 | case GL_MAX_UNIFORM_BUFFER_BINDINGS: |
| 1378 | *params = mCaps.maxUniformBufferBindings; |
| 1379 | break; |
| 1380 | case GL_MAX_VERTEX_UNIFORM_BLOCKS: |
| 1381 | *params = mCaps.maxVertexUniformBlocks; |
| 1382 | break; |
| 1383 | case GL_MAX_FRAGMENT_UNIFORM_BLOCKS: |
| 1384 | *params = mCaps.maxFragmentUniformBlocks; |
| 1385 | break; |
| 1386 | case GL_MAX_COMBINED_UNIFORM_BLOCKS: |
| 1387 | *params = mCaps.maxCombinedTextureImageUnits; |
| 1388 | break; |
| 1389 | case GL_MAX_VERTEX_OUTPUT_COMPONENTS: |
| 1390 | *params = mCaps.maxVertexOutputComponents; |
| 1391 | break; |
| 1392 | case GL_MAX_FRAGMENT_INPUT_COMPONENTS: |
| 1393 | *params = mCaps.maxFragmentInputComponents; |
| 1394 | break; |
| 1395 | case GL_MIN_PROGRAM_TEXEL_OFFSET: |
| 1396 | *params = mCaps.minProgramTexelOffset; |
| 1397 | break; |
| 1398 | case GL_MAX_PROGRAM_TEXEL_OFFSET: |
| 1399 | *params = mCaps.maxProgramTexelOffset; |
| 1400 | break; |
| 1401 | case GL_MAJOR_VERSION: |
| 1402 | *params = getClientVersion().major; |
| 1403 | break; |
| 1404 | case GL_MINOR_VERSION: |
| 1405 | *params = getClientVersion().minor; |
| 1406 | break; |
| 1407 | case GL_MAX_ELEMENTS_INDICES: |
| 1408 | *params = mCaps.maxElementsIndices; |
| 1409 | break; |
| 1410 | case GL_MAX_ELEMENTS_VERTICES: |
| 1411 | *params = mCaps.maxElementsVertices; |
| 1412 | break; |
| 1413 | case GL_MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS: |
| 1414 | *params = mCaps.maxTransformFeedbackInterleavedComponents; |
| 1415 | break; |
| 1416 | case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS: |
| 1417 | *params = mCaps.maxTransformFeedbackSeparateAttributes; |
| 1418 | break; |
| 1419 | case GL_MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS: |
| 1420 | *params = mCaps.maxTransformFeedbackSeparateComponents; |
| 1421 | break; |
| 1422 | case GL_NUM_COMPRESSED_TEXTURE_FORMATS: |
| 1423 | *params = static_cast<GLint>(mCaps.compressedTextureFormats.size()); |
| 1424 | break; |
| 1425 | case GL_MAX_SAMPLES_ANGLE: |
| 1426 | *params = mCaps.maxSamples; |
| 1427 | break; |
| 1428 | case GL_MAX_VIEWPORT_DIMS: |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1429 | { |
Geoff Lang | c0b9ef4 | 2014-07-02 10:02:37 -0400 | [diff] [blame] | 1430 | params[0] = mCaps.maxViewportWidth; |
| 1431 | params[1] = mCaps.maxViewportHeight; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1432 | } |
| 1433 | break; |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 1434 | case GL_COMPRESSED_TEXTURE_FORMATS: |
| 1435 | std::copy(mCaps.compressedTextureFormats.begin(), mCaps.compressedTextureFormats.end(), |
| 1436 | params); |
| 1437 | break; |
| 1438 | case GL_RESET_NOTIFICATION_STRATEGY_EXT: |
| 1439 | *params = mResetStrategy; |
| 1440 | break; |
| 1441 | case GL_NUM_SHADER_BINARY_FORMATS: |
| 1442 | *params = static_cast<GLint>(mCaps.shaderBinaryFormats.size()); |
| 1443 | break; |
| 1444 | case GL_SHADER_BINARY_FORMATS: |
| 1445 | std::copy(mCaps.shaderBinaryFormats.begin(), mCaps.shaderBinaryFormats.end(), params); |
| 1446 | break; |
| 1447 | case GL_NUM_PROGRAM_BINARY_FORMATS: |
| 1448 | *params = static_cast<GLint>(mCaps.programBinaryFormats.size()); |
| 1449 | break; |
| 1450 | case GL_PROGRAM_BINARY_FORMATS: |
| 1451 | std::copy(mCaps.programBinaryFormats.begin(), mCaps.programBinaryFormats.end(), params); |
| 1452 | break; |
| 1453 | case GL_NUM_EXTENSIONS: |
| 1454 | *params = static_cast<GLint>(mExtensionStrings.size()); |
| 1455 | break; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1456 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 1457 | // GL_KHR_debug |
| 1458 | case GL_MAX_DEBUG_MESSAGE_LENGTH: |
| 1459 | *params = mExtensions.maxDebugMessageLength; |
| 1460 | break; |
| 1461 | case GL_MAX_DEBUG_LOGGED_MESSAGES: |
| 1462 | *params = mExtensions.maxDebugLoggedMessages; |
| 1463 | break; |
| 1464 | case GL_MAX_DEBUG_GROUP_STACK_DEPTH: |
| 1465 | *params = mExtensions.maxDebugGroupStackDepth; |
| 1466 | break; |
| 1467 | case GL_MAX_LABEL_LENGTH: |
| 1468 | *params = mExtensions.maxLabelLength; |
| 1469 | break; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1470 | |
Martin Radev | e5285d2 | 2017-07-14 16:23:53 +0300 | [diff] [blame] | 1471 | // GL_ANGLE_multiview |
| 1472 | case GL_MAX_VIEWS_ANGLE: |
| 1473 | *params = mExtensions.maxViews; |
| 1474 | break; |
| 1475 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 1476 | // GL_EXT_disjoint_timer_query |
| 1477 | case GL_GPU_DISJOINT_EXT: |
| 1478 | *params = mImplementation->getGPUDisjoint(); |
| 1479 | break; |
| 1480 | case GL_MAX_FRAMEBUFFER_WIDTH: |
| 1481 | *params = mCaps.maxFramebufferWidth; |
| 1482 | break; |
| 1483 | case GL_MAX_FRAMEBUFFER_HEIGHT: |
| 1484 | *params = mCaps.maxFramebufferHeight; |
| 1485 | break; |
| 1486 | case GL_MAX_FRAMEBUFFER_SAMPLES: |
| 1487 | *params = mCaps.maxFramebufferSamples; |
| 1488 | break; |
| 1489 | case GL_MAX_SAMPLE_MASK_WORDS: |
| 1490 | *params = mCaps.maxSampleMaskWords; |
| 1491 | break; |
| 1492 | case GL_MAX_COLOR_TEXTURE_SAMPLES: |
| 1493 | *params = mCaps.maxColorTextureSamples; |
| 1494 | break; |
| 1495 | case GL_MAX_DEPTH_TEXTURE_SAMPLES: |
| 1496 | *params = mCaps.maxDepthTextureSamples; |
| 1497 | break; |
| 1498 | case GL_MAX_INTEGER_SAMPLES: |
| 1499 | *params = mCaps.maxIntegerSamples; |
| 1500 | break; |
| 1501 | case GL_MAX_VERTEX_ATTRIB_RELATIVE_OFFSET: |
| 1502 | *params = mCaps.maxVertexAttribRelativeOffset; |
| 1503 | break; |
| 1504 | case GL_MAX_VERTEX_ATTRIB_BINDINGS: |
| 1505 | *params = mCaps.maxVertexAttribBindings; |
| 1506 | break; |
| 1507 | case GL_MAX_VERTEX_ATTRIB_STRIDE: |
| 1508 | *params = mCaps.maxVertexAttribStride; |
| 1509 | break; |
| 1510 | case GL_MAX_VERTEX_ATOMIC_COUNTER_BUFFERS: |
| 1511 | *params = mCaps.maxVertexAtomicCounterBuffers; |
| 1512 | break; |
| 1513 | case GL_MAX_VERTEX_ATOMIC_COUNTERS: |
| 1514 | *params = mCaps.maxVertexAtomicCounters; |
| 1515 | break; |
| 1516 | case GL_MAX_VERTEX_IMAGE_UNIFORMS: |
| 1517 | *params = mCaps.maxVertexImageUniforms; |
| 1518 | break; |
| 1519 | case GL_MAX_VERTEX_SHADER_STORAGE_BLOCKS: |
| 1520 | *params = mCaps.maxVertexShaderStorageBlocks; |
| 1521 | break; |
| 1522 | case GL_MAX_FRAGMENT_ATOMIC_COUNTER_BUFFERS: |
| 1523 | *params = mCaps.maxFragmentAtomicCounterBuffers; |
| 1524 | break; |
| 1525 | case GL_MAX_FRAGMENT_ATOMIC_COUNTERS: |
| 1526 | *params = mCaps.maxFragmentAtomicCounters; |
| 1527 | break; |
| 1528 | case GL_MAX_FRAGMENT_IMAGE_UNIFORMS: |
| 1529 | *params = mCaps.maxFragmentImageUniforms; |
| 1530 | break; |
| 1531 | case GL_MAX_FRAGMENT_SHADER_STORAGE_BLOCKS: |
| 1532 | *params = mCaps.maxFragmentShaderStorageBlocks; |
| 1533 | break; |
| 1534 | case GL_MIN_PROGRAM_TEXTURE_GATHER_OFFSET: |
| 1535 | *params = mCaps.minProgramTextureGatherOffset; |
| 1536 | break; |
| 1537 | case GL_MAX_PROGRAM_TEXTURE_GATHER_OFFSET: |
| 1538 | *params = mCaps.maxProgramTextureGatherOffset; |
| 1539 | break; |
| 1540 | case GL_MAX_COMPUTE_WORK_GROUP_INVOCATIONS: |
| 1541 | *params = mCaps.maxComputeWorkGroupInvocations; |
| 1542 | break; |
| 1543 | case GL_MAX_COMPUTE_UNIFORM_BLOCKS: |
| 1544 | *params = mCaps.maxComputeUniformBlocks; |
| 1545 | break; |
| 1546 | case GL_MAX_COMPUTE_TEXTURE_IMAGE_UNITS: |
| 1547 | *params = mCaps.maxComputeTextureImageUnits; |
| 1548 | break; |
| 1549 | case GL_MAX_COMPUTE_SHARED_MEMORY_SIZE: |
| 1550 | *params = mCaps.maxComputeSharedMemorySize; |
| 1551 | break; |
| 1552 | case GL_MAX_COMPUTE_UNIFORM_COMPONENTS: |
| 1553 | *params = mCaps.maxComputeUniformComponents; |
| 1554 | break; |
| 1555 | case GL_MAX_COMPUTE_ATOMIC_COUNTER_BUFFERS: |
| 1556 | *params = mCaps.maxComputeAtomicCounterBuffers; |
| 1557 | break; |
| 1558 | case GL_MAX_COMPUTE_ATOMIC_COUNTERS: |
| 1559 | *params = mCaps.maxComputeAtomicCounters; |
| 1560 | break; |
| 1561 | case GL_MAX_COMPUTE_IMAGE_UNIFORMS: |
| 1562 | *params = mCaps.maxComputeImageUniforms; |
| 1563 | break; |
| 1564 | case GL_MAX_COMBINED_COMPUTE_UNIFORM_COMPONENTS: |
| 1565 | *params = mCaps.maxCombinedComputeUniformComponents; |
| 1566 | break; |
| 1567 | case GL_MAX_COMPUTE_SHADER_STORAGE_BLOCKS: |
| 1568 | *params = mCaps.maxComputeShaderStorageBlocks; |
| 1569 | break; |
| 1570 | case GL_MAX_COMBINED_SHADER_OUTPUT_RESOURCES: |
| 1571 | *params = mCaps.maxCombinedShaderOutputResources; |
| 1572 | break; |
| 1573 | case GL_MAX_UNIFORM_LOCATIONS: |
| 1574 | *params = mCaps.maxUniformLocations; |
| 1575 | break; |
| 1576 | case GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS: |
| 1577 | *params = mCaps.maxAtomicCounterBufferBindings; |
| 1578 | break; |
| 1579 | case GL_MAX_ATOMIC_COUNTER_BUFFER_SIZE: |
| 1580 | *params = mCaps.maxAtomicCounterBufferSize; |
| 1581 | break; |
| 1582 | case GL_MAX_COMBINED_ATOMIC_COUNTER_BUFFERS: |
| 1583 | *params = mCaps.maxCombinedAtomicCounterBuffers; |
| 1584 | break; |
| 1585 | case GL_MAX_COMBINED_ATOMIC_COUNTERS: |
| 1586 | *params = mCaps.maxCombinedAtomicCounters; |
| 1587 | break; |
| 1588 | case GL_MAX_IMAGE_UNITS: |
| 1589 | *params = mCaps.maxImageUnits; |
| 1590 | break; |
| 1591 | case GL_MAX_COMBINED_IMAGE_UNIFORMS: |
| 1592 | *params = mCaps.maxCombinedImageUniforms; |
| 1593 | break; |
| 1594 | case GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS: |
| 1595 | *params = mCaps.maxShaderStorageBufferBindings; |
| 1596 | break; |
| 1597 | case GL_MAX_COMBINED_SHADER_STORAGE_BLOCKS: |
| 1598 | *params = mCaps.maxCombinedShaderStorageBlocks; |
| 1599 | break; |
| 1600 | case GL_SHADER_STORAGE_BUFFER_OFFSET_ALIGNMENT: |
| 1601 | *params = mCaps.shaderStorageBufferOffsetAlignment; |
| 1602 | break; |
| 1603 | default: |
| 1604 | mGLState.getIntegerv(this, pname, params); |
| 1605 | break; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1606 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1607 | } |
| 1608 | |
Jamie Madill | 7f0c5a4 | 2017-08-26 22:43:26 -0400 | [diff] [blame] | 1609 | void Context::getInteger64vImpl(GLenum pname, GLint64 *params) |
Jamie Madill | 0fda986 | 2013-07-19 16:36:55 -0400 | [diff] [blame] | 1610 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1611 | // Queries about context capabilities and maximums are answered by Context. |
| 1612 | // Queries about current GL state values are answered by State. |
Jamie Madill | 0fda986 | 2013-07-19 16:36:55 -0400 | [diff] [blame] | 1613 | switch (pname) |
| 1614 | { |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 1615 | case GL_MAX_ELEMENT_INDEX: |
| 1616 | *params = mCaps.maxElementIndex; |
| 1617 | break; |
| 1618 | case GL_MAX_UNIFORM_BLOCK_SIZE: |
| 1619 | *params = mCaps.maxUniformBlockSize; |
| 1620 | break; |
| 1621 | case GL_MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS: |
| 1622 | *params = mCaps.maxCombinedVertexUniformComponents; |
| 1623 | break; |
| 1624 | case GL_MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS: |
| 1625 | *params = mCaps.maxCombinedFragmentUniformComponents; |
| 1626 | break; |
| 1627 | case GL_MAX_SERVER_WAIT_TIMEOUT: |
| 1628 | *params = mCaps.maxServerWaitTimeout; |
| 1629 | break; |
Ian Ewell | 53f59f4 | 2016-01-28 17:36:55 -0500 | [diff] [blame] | 1630 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 1631 | // GL_EXT_disjoint_timer_query |
| 1632 | case GL_TIMESTAMP_EXT: |
| 1633 | *params = mImplementation->getTimestamp(); |
| 1634 | break; |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1635 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 1636 | case GL_MAX_SHADER_STORAGE_BLOCK_SIZE: |
| 1637 | *params = mCaps.maxShaderStorageBlockSize; |
| 1638 | break; |
| 1639 | default: |
| 1640 | UNREACHABLE(); |
| 1641 | break; |
Jamie Madill | 0fda986 | 2013-07-19 16:36:55 -0400 | [diff] [blame] | 1642 | } |
Jamie Madill | 0fda986 | 2013-07-19 16:36:55 -0400 | [diff] [blame] | 1643 | } |
| 1644 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1645 | void Context::getPointerv(GLenum pname, void **params) const |
| 1646 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1647 | mGLState.getPointerv(pname, params); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1648 | } |
| 1649 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1650 | void Context::getIntegeri_v(GLenum target, GLuint index, GLint *data) |
Shannon Woods | 1b2fb85 | 2013-08-19 14:28:48 -0400 | [diff] [blame] | 1651 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1652 | // Queries about context capabilities and maximums are answered by Context. |
| 1653 | // Queries about current GL state values are answered by State. |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1654 | |
| 1655 | GLenum nativeType; |
| 1656 | unsigned int numParams; |
| 1657 | bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams); |
| 1658 | ASSERT(queryStatus); |
| 1659 | |
| 1660 | if (nativeType == GL_INT) |
| 1661 | { |
| 1662 | switch (target) |
| 1663 | { |
| 1664 | case GL_MAX_COMPUTE_WORK_GROUP_COUNT: |
| 1665 | ASSERT(index < 3u); |
| 1666 | *data = mCaps.maxComputeWorkGroupCount[index]; |
| 1667 | break; |
| 1668 | case GL_MAX_COMPUTE_WORK_GROUP_SIZE: |
| 1669 | ASSERT(index < 3u); |
| 1670 | *data = mCaps.maxComputeWorkGroupSize[index]; |
| 1671 | break; |
| 1672 | default: |
| 1673 | mGLState.getIntegeri_v(target, index, data); |
| 1674 | } |
| 1675 | } |
| 1676 | else |
| 1677 | { |
| 1678 | CastIndexedStateValues(this, nativeType, target, index, numParams, data); |
| 1679 | } |
Shannon Woods | 1b2fb85 | 2013-08-19 14:28:48 -0400 | [diff] [blame] | 1680 | } |
| 1681 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1682 | void Context::getInteger64i_v(GLenum target, GLuint index, GLint64 *data) |
Shannon Woods | 1b2fb85 | 2013-08-19 14:28:48 -0400 | [diff] [blame] | 1683 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1684 | // Queries about context capabilities and maximums are answered by Context. |
| 1685 | // Queries about current GL state values are answered by State. |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1686 | |
| 1687 | GLenum nativeType; |
| 1688 | unsigned int numParams; |
| 1689 | bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams); |
| 1690 | ASSERT(queryStatus); |
| 1691 | |
| 1692 | if (nativeType == GL_INT_64_ANGLEX) |
| 1693 | { |
| 1694 | mGLState.getInteger64i_v(target, index, data); |
| 1695 | } |
| 1696 | else |
| 1697 | { |
| 1698 | CastIndexedStateValues(this, nativeType, target, index, numParams, data); |
| 1699 | } |
| 1700 | } |
| 1701 | |
| 1702 | void Context::getBooleani_v(GLenum target, GLuint index, GLboolean *data) |
| 1703 | { |
| 1704 | // Queries about context capabilities and maximums are answered by Context. |
| 1705 | // Queries about current GL state values are answered by State. |
| 1706 | |
| 1707 | GLenum nativeType; |
| 1708 | unsigned int numParams; |
| 1709 | bool queryStatus = getIndexedQueryParameterInfo(target, &nativeType, &numParams); |
| 1710 | ASSERT(queryStatus); |
| 1711 | |
| 1712 | if (nativeType == GL_BOOL) |
| 1713 | { |
| 1714 | mGLState.getBooleani_v(target, index, data); |
| 1715 | } |
| 1716 | else |
| 1717 | { |
| 1718 | CastIndexedStateValues(this, nativeType, target, index, numParams, data); |
| 1719 | } |
Shannon Woods | 1b2fb85 | 2013-08-19 14:28:48 -0400 | [diff] [blame] | 1720 | } |
| 1721 | |
He Yunchao | 010e4db | 2017-03-03 14:22:06 +0800 | [diff] [blame] | 1722 | void Context::getBufferParameteriv(GLenum target, GLenum pname, GLint *params) |
| 1723 | { |
| 1724 | Buffer *buffer = mGLState.getTargetBuffer(target); |
| 1725 | QueryBufferParameteriv(buffer, pname, params); |
| 1726 | } |
| 1727 | |
| 1728 | void Context::getFramebufferAttachmentParameteriv(GLenum target, |
| 1729 | GLenum attachment, |
| 1730 | GLenum pname, |
| 1731 | GLint *params) |
| 1732 | { |
| 1733 | const Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
| 1734 | QueryFramebufferAttachmentParameteriv(framebuffer, attachment, pname, params); |
| 1735 | } |
| 1736 | |
| 1737 | void Context::getRenderbufferParameteriv(GLenum target, GLenum pname, GLint *params) |
| 1738 | { |
| 1739 | Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer(); |
| 1740 | QueryRenderbufferiv(this, renderbuffer, pname, params); |
| 1741 | } |
| 1742 | |
| 1743 | void Context::getTexParameterfv(GLenum target, GLenum pname, GLfloat *params) |
| 1744 | { |
| 1745 | Texture *texture = getTargetTexture(target); |
| 1746 | QueryTexParameterfv(texture, pname, params); |
| 1747 | } |
| 1748 | |
| 1749 | void Context::getTexParameteriv(GLenum target, GLenum pname, GLint *params) |
| 1750 | { |
| 1751 | Texture *texture = getTargetTexture(target); |
| 1752 | QueryTexParameteriv(texture, pname, params); |
| 1753 | } |
| 1754 | void Context::texParameterf(GLenum target, GLenum pname, GLfloat param) |
| 1755 | { |
| 1756 | Texture *texture = getTargetTexture(target); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1757 | SetTexParameterf(this, texture, pname, param); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1758 | onTextureChange(texture); |
He Yunchao | 010e4db | 2017-03-03 14:22:06 +0800 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | void Context::texParameterfv(GLenum target, GLenum pname, const GLfloat *params) |
| 1762 | { |
| 1763 | Texture *texture = getTargetTexture(target); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1764 | SetTexParameterfv(this, texture, pname, params); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1765 | onTextureChange(texture); |
He Yunchao | 010e4db | 2017-03-03 14:22:06 +0800 | [diff] [blame] | 1766 | } |
| 1767 | |
| 1768 | void Context::texParameteri(GLenum target, GLenum pname, GLint param) |
| 1769 | { |
| 1770 | Texture *texture = getTargetTexture(target); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1771 | SetTexParameteri(this, texture, pname, param); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1772 | onTextureChange(texture); |
He Yunchao | 010e4db | 2017-03-03 14:22:06 +0800 | [diff] [blame] | 1773 | } |
| 1774 | |
| 1775 | void Context::texParameteriv(GLenum target, GLenum pname, const GLint *params) |
| 1776 | { |
| 1777 | Texture *texture = getTargetTexture(target); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1778 | SetTexParameteriv(this, texture, pname, params); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1779 | onTextureChange(texture); |
He Yunchao | 010e4db | 2017-03-03 14:22:06 +0800 | [diff] [blame] | 1780 | } |
| 1781 | |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1782 | void Context::drawArrays(GLenum mode, GLint first, GLsizei count) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1783 | { |
Jamie Madill | 14bbb3f | 2017-09-12 15:23:01 -0400 | [diff] [blame] | 1784 | syncRendererState(); |
Jamie Madill | b666492 | 2017-07-25 12:55:04 -0400 | [diff] [blame] | 1785 | ANGLE_CONTEXT_TRY(mImplementation->drawArrays(this, mode, first, count)); |
| 1786 | MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1787 | } |
| 1788 | |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1789 | void Context::drawArraysInstanced(GLenum mode, GLint first, GLsizei count, GLsizei instanceCount) |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 1790 | { |
Jamie Madill | 14bbb3f | 2017-09-12 15:23:01 -0400 | [diff] [blame] | 1791 | syncRendererState(); |
Jamie Madill | b666492 | 2017-07-25 12:55:04 -0400 | [diff] [blame] | 1792 | ANGLE_CONTEXT_TRY( |
| 1793 | mImplementation->drawArraysInstanced(this, mode, first, count, instanceCount)); |
| 1794 | MarkTransformFeedbackBufferUsage(mGLState.getCurrentTransformFeedback()); |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 1795 | } |
| 1796 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1797 | void Context::drawElements(GLenum mode, GLsizei count, GLenum type, const void *indices) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1798 | { |
Jamie Madill | 14bbb3f | 2017-09-12 15:23:01 -0400 | [diff] [blame] | 1799 | syncRendererState(); |
Jamie Madill | b666492 | 2017-07-25 12:55:04 -0400 | [diff] [blame] | 1800 | ANGLE_CONTEXT_TRY(mImplementation->drawElements(this, mode, count, type, indices)); |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 1801 | } |
| 1802 | |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1803 | void Context::drawElementsInstanced(GLenum mode, |
| 1804 | GLsizei count, |
| 1805 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1806 | const void *indices, |
Jamie Madill | 9c9b40a | 2017-04-26 16:31:57 -0400 | [diff] [blame] | 1807 | GLsizei instances) |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 1808 | { |
Jamie Madill | 14bbb3f | 2017-09-12 15:23:01 -0400 | [diff] [blame] | 1809 | syncRendererState(); |
Jamie Madill | b666492 | 2017-07-25 12:55:04 -0400 | [diff] [blame] | 1810 | ANGLE_CONTEXT_TRY( |
Qin Jiajia | 1da0065 | 2017-06-20 17:16:25 +0800 | [diff] [blame] | 1811 | mImplementation->drawElementsInstanced(this, mode, count, type, indices, instances)); |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 1812 | } |
| 1813 | |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1814 | void Context::drawRangeElements(GLenum mode, |
| 1815 | GLuint start, |
| 1816 | GLuint end, |
| 1817 | GLsizei count, |
| 1818 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1819 | const void *indices) |
Geoff Lang | f6db098 | 2015-08-25 13:04:00 -0400 | [diff] [blame] | 1820 | { |
Jamie Madill | 14bbb3f | 2017-09-12 15:23:01 -0400 | [diff] [blame] | 1821 | syncRendererState(); |
Jamie Madill | b666492 | 2017-07-25 12:55:04 -0400 | [diff] [blame] | 1822 | ANGLE_CONTEXT_TRY( |
| 1823 | mImplementation->drawRangeElements(this, mode, start, end, count, type, indices)); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1824 | } |
| 1825 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1826 | void Context::drawArraysIndirect(GLenum mode, const void *indirect) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1827 | { |
Jamie Madill | 14bbb3f | 2017-09-12 15:23:01 -0400 | [diff] [blame] | 1828 | syncRendererState(); |
Jamie Madill | b666492 | 2017-07-25 12:55:04 -0400 | [diff] [blame] | 1829 | ANGLE_CONTEXT_TRY(mImplementation->drawArraysIndirect(this, mode, indirect)); |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1830 | } |
| 1831 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 1832 | void Context::drawElementsIndirect(GLenum mode, GLenum type, const void *indirect) |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1833 | { |
Jamie Madill | 14bbb3f | 2017-09-12 15:23:01 -0400 | [diff] [blame] | 1834 | syncRendererState(); |
Jamie Madill | b666492 | 2017-07-25 12:55:04 -0400 | [diff] [blame] | 1835 | ANGLE_CONTEXT_TRY(mImplementation->drawElementsIndirect(this, mode, type, indirect)); |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1836 | } |
| 1837 | |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1838 | void Context::flush() |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1839 | { |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1840 | handleError(mImplementation->flush()); |
Geoff Lang | 129753a | 2015-01-09 16:52:09 -0500 | [diff] [blame] | 1841 | } |
| 1842 | |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1843 | void Context::finish() |
Geoff Lang | 129753a | 2015-01-09 16:52:09 -0500 | [diff] [blame] | 1844 | { |
Jamie Madill | 675fe71 | 2016-12-19 13:07:54 -0500 | [diff] [blame] | 1845 | handleError(mImplementation->finish()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 1846 | } |
| 1847 | |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 1848 | void Context::insertEventMarker(GLsizei length, const char *marker) |
| 1849 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 1850 | ASSERT(mImplementation); |
| 1851 | mImplementation->insertEventMarker(length, marker); |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 1852 | } |
| 1853 | |
| 1854 | void Context::pushGroupMarker(GLsizei length, const char *marker) |
| 1855 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 1856 | ASSERT(mImplementation); |
| 1857 | mImplementation->pushGroupMarker(length, marker); |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 1858 | } |
| 1859 | |
| 1860 | void Context::popGroupMarker() |
| 1861 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 1862 | ASSERT(mImplementation); |
| 1863 | mImplementation->popGroupMarker(); |
Austin Kinross | 6ee1e78 | 2015-05-29 17:05:37 -0700 | [diff] [blame] | 1864 | } |
| 1865 | |
Geoff Lang | d860552 | 2016-04-13 10:19:12 -0400 | [diff] [blame] | 1866 | void Context::bindUniformLocation(GLuint program, GLint location, const GLchar *name) |
| 1867 | { |
| 1868 | Program *programObject = getProgram(program); |
| 1869 | ASSERT(programObject); |
| 1870 | |
| 1871 | programObject->bindUniformLocation(location, name); |
| 1872 | } |
| 1873 | |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 1874 | void Context::setCoverageModulation(GLenum components) |
| 1875 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 1876 | mGLState.setCoverageModulation(components); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 1877 | } |
| 1878 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1879 | void Context::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix) |
| 1880 | { |
| 1881 | mGLState.loadPathRenderingMatrix(matrixMode, matrix); |
| 1882 | } |
| 1883 | |
| 1884 | void Context::loadPathRenderingIdentityMatrix(GLenum matrixMode) |
| 1885 | { |
| 1886 | GLfloat I[16]; |
| 1887 | angle::Matrix<GLfloat>::setToIdentity(I); |
| 1888 | |
| 1889 | mGLState.loadPathRenderingMatrix(matrixMode, I); |
| 1890 | } |
| 1891 | |
| 1892 | void Context::stencilFillPath(GLuint path, GLenum fillMode, GLuint mask) |
| 1893 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1894 | const auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1895 | if (!pathObj) |
| 1896 | return; |
| 1897 | |
| 1898 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1899 | syncRendererState(); |
| 1900 | |
| 1901 | mImplementation->stencilFillPath(pathObj, fillMode, mask); |
| 1902 | } |
| 1903 | |
| 1904 | void Context::stencilStrokePath(GLuint path, GLint reference, GLuint mask) |
| 1905 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1906 | const auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1907 | if (!pathObj) |
| 1908 | return; |
| 1909 | |
| 1910 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1911 | syncRendererState(); |
| 1912 | |
| 1913 | mImplementation->stencilStrokePath(pathObj, reference, mask); |
| 1914 | } |
| 1915 | |
| 1916 | void Context::coverFillPath(GLuint path, GLenum coverMode) |
| 1917 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1918 | const auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1919 | if (!pathObj) |
| 1920 | return; |
| 1921 | |
| 1922 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1923 | syncRendererState(); |
| 1924 | |
| 1925 | mImplementation->coverFillPath(pathObj, coverMode); |
| 1926 | } |
| 1927 | |
| 1928 | void Context::coverStrokePath(GLuint path, GLenum coverMode) |
| 1929 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1930 | const auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1931 | if (!pathObj) |
| 1932 | return; |
| 1933 | |
| 1934 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1935 | syncRendererState(); |
| 1936 | |
| 1937 | mImplementation->coverStrokePath(pathObj, coverMode); |
| 1938 | } |
| 1939 | |
| 1940 | void Context::stencilThenCoverFillPath(GLuint path, GLenum fillMode, GLuint mask, GLenum coverMode) |
| 1941 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1942 | const auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1943 | if (!pathObj) |
| 1944 | return; |
| 1945 | |
| 1946 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1947 | syncRendererState(); |
| 1948 | |
| 1949 | mImplementation->stencilThenCoverFillPath(pathObj, fillMode, mask, coverMode); |
| 1950 | } |
| 1951 | |
| 1952 | void Context::stencilThenCoverStrokePath(GLuint path, |
| 1953 | GLint reference, |
| 1954 | GLuint mask, |
| 1955 | GLenum coverMode) |
| 1956 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1957 | const auto *pathObj = mState.mPaths->getPath(path); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1958 | if (!pathObj) |
| 1959 | return; |
| 1960 | |
| 1961 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1962 | syncRendererState(); |
| 1963 | |
| 1964 | mImplementation->stencilThenCoverStrokePath(pathObj, reference, mask, coverMode); |
| 1965 | } |
| 1966 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1967 | void Context::coverFillPathInstanced(GLsizei numPaths, |
| 1968 | GLenum pathNameType, |
| 1969 | const void *paths, |
| 1970 | GLuint pathBase, |
| 1971 | GLenum coverMode, |
| 1972 | GLenum transformType, |
| 1973 | const GLfloat *transformValues) |
| 1974 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1975 | const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1976 | |
| 1977 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1978 | syncRendererState(); |
| 1979 | |
| 1980 | mImplementation->coverFillPathInstanced(pathObjects, coverMode, transformType, transformValues); |
| 1981 | } |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1982 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1983 | void Context::coverStrokePathInstanced(GLsizei numPaths, |
| 1984 | GLenum pathNameType, |
| 1985 | const void *paths, |
| 1986 | GLuint pathBase, |
| 1987 | GLenum coverMode, |
| 1988 | GLenum transformType, |
| 1989 | const GLfloat *transformValues) |
| 1990 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 1991 | const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 1992 | |
| 1993 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 1994 | syncRendererState(); |
| 1995 | |
| 1996 | mImplementation->coverStrokePathInstanced(pathObjects, coverMode, transformType, |
| 1997 | transformValues); |
| 1998 | } |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 1999 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 2000 | void Context::stencilFillPathInstanced(GLsizei numPaths, |
| 2001 | GLenum pathNameType, |
| 2002 | const void *paths, |
| 2003 | GLuint pathBase, |
| 2004 | GLenum fillMode, |
| 2005 | GLuint mask, |
| 2006 | GLenum transformType, |
| 2007 | const GLfloat *transformValues) |
| 2008 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 2009 | const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 2010 | |
| 2011 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 2012 | syncRendererState(); |
| 2013 | |
| 2014 | mImplementation->stencilFillPathInstanced(pathObjects, fillMode, mask, transformType, |
| 2015 | transformValues); |
| 2016 | } |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 2017 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 2018 | void Context::stencilStrokePathInstanced(GLsizei numPaths, |
| 2019 | GLenum pathNameType, |
| 2020 | const void *paths, |
| 2021 | GLuint pathBase, |
| 2022 | GLint reference, |
| 2023 | GLuint mask, |
| 2024 | GLenum transformType, |
| 2025 | const GLfloat *transformValues) |
| 2026 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 2027 | const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 2028 | |
| 2029 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 2030 | syncRendererState(); |
| 2031 | |
| 2032 | mImplementation->stencilStrokePathInstanced(pathObjects, reference, mask, transformType, |
| 2033 | transformValues); |
| 2034 | } |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 2035 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 2036 | void Context::stencilThenCoverFillPathInstanced(GLsizei numPaths, |
| 2037 | GLenum pathNameType, |
| 2038 | const void *paths, |
| 2039 | GLuint pathBase, |
| 2040 | GLenum fillMode, |
| 2041 | GLuint mask, |
| 2042 | GLenum coverMode, |
| 2043 | GLenum transformType, |
| 2044 | const GLfloat *transformValues) |
| 2045 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 2046 | const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 2047 | |
| 2048 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 2049 | syncRendererState(); |
| 2050 | |
| 2051 | mImplementation->stencilThenCoverFillPathInstanced(pathObjects, coverMode, fillMode, mask, |
| 2052 | transformType, transformValues); |
| 2053 | } |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 2054 | |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 2055 | void Context::stencilThenCoverStrokePathInstanced(GLsizei numPaths, |
| 2056 | GLenum pathNameType, |
| 2057 | const void *paths, |
| 2058 | GLuint pathBase, |
| 2059 | GLint reference, |
| 2060 | GLuint mask, |
| 2061 | GLenum coverMode, |
| 2062 | GLenum transformType, |
| 2063 | const GLfloat *transformValues) |
| 2064 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 2065 | const auto &pathObjects = GatherPaths(*mState.mPaths, numPaths, pathNameType, paths, pathBase); |
Sami Väisänen | d59ca05 | 2016-06-21 16:10:00 +0300 | [diff] [blame] | 2066 | |
| 2067 | // TODO(svaisanen@nvidia.com): maybe sync only state required for path rendering? |
| 2068 | syncRendererState(); |
| 2069 | |
| 2070 | mImplementation->stencilThenCoverStrokePathInstanced(pathObjects, coverMode, reference, mask, |
| 2071 | transformType, transformValues); |
| 2072 | } |
| 2073 | |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 2074 | void Context::bindFragmentInputLocation(GLuint program, GLint location, const GLchar *name) |
| 2075 | { |
| 2076 | auto *programObject = getProgram(program); |
| 2077 | |
| 2078 | programObject->bindFragmentInputLocation(location, name); |
| 2079 | } |
| 2080 | |
| 2081 | void Context::programPathFragmentInputGen(GLuint program, |
| 2082 | GLint location, |
| 2083 | GLenum genMode, |
| 2084 | GLint components, |
| 2085 | const GLfloat *coeffs) |
| 2086 | { |
| 2087 | auto *programObject = getProgram(program); |
| 2088 | |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 2089 | programObject->pathFragmentInputGen(this, location, genMode, components, coeffs); |
Sami Väisänen | 46eaa94 | 2016-06-29 10:26:37 +0300 | [diff] [blame] | 2090 | } |
| 2091 | |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 2092 | GLuint Context::getProgramResourceIndex(GLuint program, GLenum programInterface, const GLchar *name) |
| 2093 | { |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 2094 | const auto *programObject = getProgram(program); |
jchen10 | 15015f7 | 2017-03-16 13:54:21 +0800 | [diff] [blame] | 2095 | return QueryProgramResourceIndex(programObject, programInterface, name); |
| 2096 | } |
| 2097 | |
jchen10 | fd7c3b5 | 2017-03-21 15:36:03 +0800 | [diff] [blame] | 2098 | void Context::getProgramResourceName(GLuint program, |
| 2099 | GLenum programInterface, |
| 2100 | GLuint index, |
| 2101 | GLsizei bufSize, |
| 2102 | GLsizei *length, |
| 2103 | GLchar *name) |
| 2104 | { |
| 2105 | const auto *programObject = getProgram(program); |
| 2106 | QueryProgramResourceName(programObject, programInterface, index, bufSize, length, name); |
| 2107 | } |
| 2108 | |
jchen10 | 191381f | 2017-04-11 13:59:04 +0800 | [diff] [blame] | 2109 | GLint Context::getProgramResourceLocation(GLuint program, |
| 2110 | GLenum programInterface, |
| 2111 | const GLchar *name) |
| 2112 | { |
| 2113 | const auto *programObject = getProgram(program); |
| 2114 | return QueryProgramResourceLocation(programObject, programInterface, name); |
| 2115 | } |
| 2116 | |
jchen10 | 880683b | 2017-04-12 16:21:55 +0800 | [diff] [blame] | 2117 | void Context::getProgramResourceiv(GLuint program, |
| 2118 | GLenum programInterface, |
| 2119 | GLuint index, |
| 2120 | GLsizei propCount, |
| 2121 | const GLenum *props, |
| 2122 | GLsizei bufSize, |
| 2123 | GLsizei *length, |
| 2124 | GLint *params) |
| 2125 | { |
| 2126 | const auto *programObject = getProgram(program); |
| 2127 | QueryProgramResourceiv(programObject, programInterface, index, propCount, props, bufSize, |
| 2128 | length, params); |
| 2129 | } |
| 2130 | |
jchen10 | d9cd7b7 | 2017-08-30 15:04:25 +0800 | [diff] [blame] | 2131 | void Context::getProgramInterfaceiv(GLuint program, |
| 2132 | GLenum programInterface, |
| 2133 | GLenum pname, |
| 2134 | GLint *params) |
| 2135 | { |
| 2136 | const auto *programObject = getProgram(program); |
| 2137 | QueryProgramInterfaceiv(programObject, programInterface, pname, params); |
| 2138 | } |
| 2139 | |
Jamie Madill | 71c88b3 | 2017-09-14 22:20:29 -0400 | [diff] [blame] | 2140 | void Context::handleError(const Error &error) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2141 | { |
Geoff Lang | da5777c | 2014-07-11 09:52:58 -0400 | [diff] [blame] | 2142 | if (error.isError()) |
| 2143 | { |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 2144 | GLenum code = error.getCode(); |
| 2145 | mErrors.insert(code); |
| 2146 | if (code == GL_OUT_OF_MEMORY && getWorkarounds().loseContextOnOutOfMemory) |
| 2147 | { |
| 2148 | markContextLost(); |
| 2149 | } |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2150 | |
| 2151 | if (!error.getMessage().empty()) |
| 2152 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2153 | auto *debug = &mGLState.getDebug(); |
| 2154 | debug->insertMessage(GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, error.getID(), |
| 2155 | GL_DEBUG_SEVERITY_HIGH, error.getMessage()); |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2156 | } |
Geoff Lang | da5777c | 2014-07-11 09:52:58 -0400 | [diff] [blame] | 2157 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2158 | } |
| 2159 | |
| 2160 | // Get one of the recorded errors and clear its flag, if any. |
| 2161 | // [OpenGL ES 2.0.24] section 2.5 page 13. |
| 2162 | GLenum Context::getError() |
| 2163 | { |
Geoff Lang | da5777c | 2014-07-11 09:52:58 -0400 | [diff] [blame] | 2164 | if (mErrors.empty()) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2165 | { |
Geoff Lang | da5777c | 2014-07-11 09:52:58 -0400 | [diff] [blame] | 2166 | return GL_NO_ERROR; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2167 | } |
Geoff Lang | da5777c | 2014-07-11 09:52:58 -0400 | [diff] [blame] | 2168 | else |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2169 | { |
Geoff Lang | da5777c | 2014-07-11 09:52:58 -0400 | [diff] [blame] | 2170 | GLenum error = *mErrors.begin(); |
| 2171 | mErrors.erase(mErrors.begin()); |
| 2172 | return error; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2173 | } |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2174 | } |
| 2175 | |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2176 | // NOTE: this function should not assume that this context is current! |
| 2177 | void Context::markContextLost() |
| 2178 | { |
| 2179 | if (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT) |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 2180 | { |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 2181 | mResetStatus = GL_UNKNOWN_CONTEXT_RESET_EXT; |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 2182 | mContextLostForced = true; |
| 2183 | } |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 2184 | mContextLost = true; |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2185 | } |
| 2186 | |
| 2187 | bool Context::isContextLost() |
| 2188 | { |
| 2189 | return mContextLost; |
| 2190 | } |
| 2191 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2192 | GLenum Context::getResetStatus() |
| 2193 | { |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2194 | // Even if the application doesn't want to know about resets, we want to know |
| 2195 | // as it will allow us to skip all the calls. |
| 2196 | if (mResetStrategy == GL_NO_RESET_NOTIFICATION_EXT) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2197 | { |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2198 | if (!mContextLost && mImplementation->getResetStatus() != GL_NO_ERROR) |
Jamie Madill | 9dd0cf0 | 2014-11-24 11:38:51 -0500 | [diff] [blame] | 2199 | { |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2200 | mContextLost = true; |
Jamie Madill | 9dd0cf0 | 2014-11-24 11:38:51 -0500 | [diff] [blame] | 2201 | } |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2202 | |
| 2203 | // EXT_robustness, section 2.6: If the reset notification behavior is |
| 2204 | // NO_RESET_NOTIFICATION_EXT, then the implementation will never deliver notification of |
| 2205 | // reset events, and GetGraphicsResetStatusEXT will always return NO_ERROR. |
| 2206 | return GL_NO_ERROR; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2207 | } |
| 2208 | |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2209 | // The GL_EXT_robustness spec says that if a reset is encountered, a reset |
| 2210 | // status should be returned at least once, and GL_NO_ERROR should be returned |
| 2211 | // once the device has finished resetting. |
| 2212 | if (!mContextLost) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2213 | { |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2214 | ASSERT(mResetStatus == GL_NO_ERROR); |
| 2215 | mResetStatus = mImplementation->getResetStatus(); |
shannon.woods@transgaming.com | ddd6c80 | 2013-02-28 23:05:14 +0000 | [diff] [blame] | 2216 | |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2217 | if (mResetStatus != GL_NO_ERROR) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2218 | { |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2219 | mContextLost = true; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2220 | } |
| 2221 | } |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 2222 | else if (!mContextLostForced && mResetStatus != GL_NO_ERROR) |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2223 | { |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 2224 | // If markContextLost was used to mark the context lost then |
| 2225 | // assume that is not recoverable, and continue to report the |
| 2226 | // lost reset status for the lifetime of this context. |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2227 | mResetStatus = mImplementation->getResetStatus(); |
| 2228 | } |
Jamie Madill | 893ab08 | 2014-05-16 16:56:10 -0400 | [diff] [blame] | 2229 | |
Corentin Wallez | 87fbe1c | 2016-08-03 14:41:42 -0400 | [diff] [blame] | 2230 | return mResetStatus; |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2231 | } |
| 2232 | |
| 2233 | bool Context::isResetNotificationEnabled() |
| 2234 | { |
| 2235 | return (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT); |
| 2236 | } |
| 2237 | |
Corentin Wallez | e3b10e8 | 2015-05-20 11:06:25 -0400 | [diff] [blame] | 2238 | const egl::Config *Context::getConfig() const |
Régis Fénéon | 8310797 | 2015-02-05 12:57:44 +0100 | [diff] [blame] | 2239 | { |
Corentin Wallez | e3b10e8 | 2015-05-20 11:06:25 -0400 | [diff] [blame] | 2240 | return mConfig; |
Régis Fénéon | 8310797 | 2015-02-05 12:57:44 +0100 | [diff] [blame] | 2241 | } |
| 2242 | |
| 2243 | EGLenum Context::getClientType() const |
| 2244 | { |
| 2245 | return mClientType; |
| 2246 | } |
| 2247 | |
| 2248 | EGLenum Context::getRenderBuffer() const |
| 2249 | { |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 2250 | const Framebuffer *framebuffer = mState.mFramebuffers->getFramebuffer(0); |
| 2251 | if (framebuffer == nullptr) |
Corentin Wallez | 37c3979 | 2015-08-20 14:19:46 -0400 | [diff] [blame] | 2252 | { |
| 2253 | return EGL_NONE; |
| 2254 | } |
Geoff Lang | 3bf8e3a | 2016-12-01 17:28:52 -0500 | [diff] [blame] | 2255 | |
| 2256 | const FramebufferAttachment *backAttachment = framebuffer->getAttachment(GL_BACK); |
| 2257 | ASSERT(backAttachment != nullptr); |
| 2258 | return backAttachment->getSurface()->getRenderBuffer(); |
Régis Fénéon | 8310797 | 2015-02-05 12:57:44 +0100 | [diff] [blame] | 2259 | } |
| 2260 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 2261 | VertexArray *Context::checkVertexArrayAllocation(GLuint vertexArrayHandle) |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2262 | { |
Jamie Madill | 5bf9ff4 | 2016-02-01 11:13:03 -0500 | [diff] [blame] | 2263 | // Only called after a prior call to Gen. |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 2264 | VertexArray *vertexArray = getVertexArray(vertexArrayHandle); |
| 2265 | if (!vertexArray) |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2266 | { |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 2267 | vertexArray = new VertexArray(mImplementation.get(), vertexArrayHandle, |
| 2268 | mCaps.maxVertexAttributes, mCaps.maxVertexAttribBindings); |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 2269 | |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 2270 | mVertexArrayMap.assign(vertexArrayHandle, vertexArray); |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2271 | } |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 2272 | |
| 2273 | return vertexArray; |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2274 | } |
| 2275 | |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 2276 | TransformFeedback *Context::checkTransformFeedbackAllocation(GLuint transformFeedbackHandle) |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2277 | { |
Jamie Madill | 5bf9ff4 | 2016-02-01 11:13:03 -0500 | [diff] [blame] | 2278 | // Only called after a prior call to Gen. |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 2279 | TransformFeedback *transformFeedback = getTransformFeedback(transformFeedbackHandle); |
| 2280 | if (!transformFeedback) |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2281 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 2282 | transformFeedback = |
| 2283 | new TransformFeedback(mImplementation.get(), transformFeedbackHandle, mCaps); |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 2284 | transformFeedback->addRef(); |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 2285 | mTransformFeedbackMap.assign(transformFeedbackHandle, transformFeedback); |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2286 | } |
Jamie Madill | 3f01e6c | 2016-03-08 13:53:02 -0500 | [diff] [blame] | 2287 | |
| 2288 | return transformFeedback; |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2289 | } |
| 2290 | |
| 2291 | bool Context::isVertexArrayGenerated(GLuint vertexArray) |
| 2292 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 2293 | ASSERT(mVertexArrayMap.contains(0)); |
| 2294 | return mVertexArrayMap.contains(vertexArray); |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2295 | } |
| 2296 | |
| 2297 | bool Context::isTransformFeedbackGenerated(GLuint transformFeedback) |
| 2298 | { |
Jamie Madill | 96a483b | 2017-06-27 16:49:21 -0400 | [diff] [blame] | 2299 | ASSERT(mTransformFeedbackMap.contains(0)); |
| 2300 | return mTransformFeedbackMap.contains(transformFeedback); |
Geoff Lang | 36167ab | 2015-12-07 10:27:14 -0500 | [diff] [blame] | 2301 | } |
| 2302 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2303 | void Context::detachTexture(GLuint texture) |
| 2304 | { |
| 2305 | // Simple pass-through to State's detachTexture method, as textures do not require |
| 2306 | // allocation map management either here or in the resource manager at detach time. |
| 2307 | // Zero textures are held by the Context, and we don't attempt to request them from |
| 2308 | // the State. |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 2309 | mGLState.detachTexture(this, mZeroTextures, texture); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2310 | } |
| 2311 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2312 | void Context::detachBuffer(GLuint buffer) |
| 2313 | { |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 2314 | // Simple pass-through to State's detachBuffer method, since |
| 2315 | // only buffer attachments to container objects that are bound to the current context |
| 2316 | // should be detached. And all those are available in State. |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2317 | |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 2318 | // [OpenGL ES 3.2] section 5.1.2 page 45: |
| 2319 | // Attachments to unbound container objects, such as |
| 2320 | // deletion of a buffer attached to a vertex array object which is not bound to the context, |
| 2321 | // are not affected and continue to act as references on the deleted object |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 2322 | mGLState.detachBuffer(this, buffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2323 | } |
| 2324 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2325 | void Context::detachFramebuffer(GLuint framebuffer) |
| 2326 | { |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2327 | // Framebuffer detachment is handled by Context, because 0 is a valid |
| 2328 | // Framebuffer object, and a pointer to it must be passed from Context |
| 2329 | // to State at binding time. |
| 2330 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2331 | // [OpenGL ES 2.0.24] section 4.4 page 107: |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 2332 | // If a framebuffer that is currently bound to the target FRAMEBUFFER is deleted, it is as |
| 2333 | // though BindFramebuffer had been executed with the target of FRAMEBUFFER and framebuffer of |
| 2334 | // zero. |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2335 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2336 | if (mGLState.removeReadFramebufferBinding(framebuffer) && framebuffer != 0) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2337 | { |
| 2338 | bindReadFramebuffer(0); |
| 2339 | } |
| 2340 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2341 | if (mGLState.removeDrawFramebufferBinding(framebuffer) && framebuffer != 0) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2342 | { |
| 2343 | bindDrawFramebuffer(0); |
| 2344 | } |
| 2345 | } |
| 2346 | |
| 2347 | void Context::detachRenderbuffer(GLuint renderbuffer) |
| 2348 | { |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 2349 | mGLState.detachRenderbuffer(this, renderbuffer); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2350 | } |
| 2351 | |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 2352 | void Context::detachVertexArray(GLuint vertexArray) |
| 2353 | { |
Jamie Madill | 77a72f6 | 2015-04-14 11:18:32 -0400 | [diff] [blame] | 2354 | // Vertex array detachment is handled by Context, because 0 is a valid |
| 2355 | // 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] | 2356 | // binding time. |
| 2357 | |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 2358 | // [OpenGL ES 3.0.2] section 2.10 page 43: |
| 2359 | // If a vertex array object that is currently bound is deleted, the binding |
| 2360 | // 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] | 2361 | if (mGLState.removeVertexArrayBinding(vertexArray)) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 2362 | { |
| 2363 | bindVertexArray(0); |
| 2364 | } |
| 2365 | } |
| 2366 | |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 2367 | void Context::detachTransformFeedback(GLuint transformFeedback) |
| 2368 | { |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 2369 | // Transform feedback detachment is handled by Context, because 0 is a valid |
| 2370 | // transform feedback, and a pointer to it must be passed from Context to State at |
| 2371 | // binding time. |
| 2372 | |
| 2373 | // The OpenGL specification doesn't mention what should happen when the currently bound |
| 2374 | // transform feedback object is deleted. Since it is a container object, we treat it like |
| 2375 | // VAOs and FBOs and set the current bound transform feedback back to 0. |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 2376 | if (mGLState.removeTransformFeedbackBinding(this, transformFeedback)) |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 2377 | { |
Jamie Madill | f0dcb8b | 2017-08-26 19:05:13 -0400 | [diff] [blame] | 2378 | bindTransformFeedback(GL_TRANSFORM_FEEDBACK, 0); |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 2379 | } |
Geoff Lang | c805845 | 2014-02-03 12:04:11 -0500 | [diff] [blame] | 2380 | } |
| 2381 | |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 2382 | void Context::detachSampler(GLuint sampler) |
| 2383 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 2384 | mGLState.detachSampler(this, sampler); |
Jamie Madill | dc35604 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 2385 | } |
| 2386 | |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame^] | 2387 | void Context::detachProgramPipeline(GLuint pipeline) |
| 2388 | { |
| 2389 | mGLState.detachProgramPipeline(this, pipeline); |
| 2390 | } |
| 2391 | |
Jamie Madill | 3ef140a | 2017-08-26 23:11:21 -0400 | [diff] [blame] | 2392 | void Context::vertexAttribDivisor(GLuint index, GLuint divisor) |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2393 | { |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 2394 | mGLState.setVertexAttribDivisor(this, index, divisor); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2395 | } |
| 2396 | |
Jamie Madill | e29d167 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 2397 | void Context::samplerParameteri(GLuint sampler, GLenum pname, GLint param) |
| 2398 | { |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2399 | Sampler *samplerObject = |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 2400 | mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2401 | SetSamplerParameteri(samplerObject, pname, param); |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2402 | mGLState.setObjectDirty(GL_SAMPLER); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2403 | } |
Jamie Madill | e29d167 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 2404 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2405 | void Context::samplerParameteriv(GLuint sampler, GLenum pname, const GLint *param) |
| 2406 | { |
| 2407 | Sampler *samplerObject = |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 2408 | mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2409 | SetSamplerParameteriv(samplerObject, pname, param); |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2410 | mGLState.setObjectDirty(GL_SAMPLER); |
Jamie Madill | e29d167 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 2411 | } |
| 2412 | |
| 2413 | void Context::samplerParameterf(GLuint sampler, GLenum pname, GLfloat param) |
| 2414 | { |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2415 | Sampler *samplerObject = |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 2416 | mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2417 | SetSamplerParameterf(samplerObject, pname, param); |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2418 | mGLState.setObjectDirty(GL_SAMPLER); |
Jamie Madill | e29d167 | 2013-07-19 16:36:57 -0400 | [diff] [blame] | 2419 | } |
| 2420 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2421 | void Context::samplerParameterfv(GLuint sampler, GLenum pname, const GLfloat *param) |
Jamie Madill | 9675b80 | 2013-07-19 16:36:59 -0400 | [diff] [blame] | 2422 | { |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2423 | Sampler *samplerObject = |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 2424 | mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2425 | SetSamplerParameterfv(samplerObject, pname, param); |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2426 | mGLState.setObjectDirty(GL_SAMPLER); |
Jamie Madill | 9675b80 | 2013-07-19 16:36:59 -0400 | [diff] [blame] | 2427 | } |
| 2428 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2429 | void Context::getSamplerParameteriv(GLuint sampler, GLenum pname, GLint *params) |
Jamie Madill | 9675b80 | 2013-07-19 16:36:59 -0400 | [diff] [blame] | 2430 | { |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2431 | const Sampler *samplerObject = |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 2432 | mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2433 | QuerySamplerParameteriv(samplerObject, pname, params); |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2434 | mGLState.setObjectDirty(GL_SAMPLER); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2435 | } |
Jamie Madill | 9675b80 | 2013-07-19 16:36:59 -0400 | [diff] [blame] | 2436 | |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2437 | void Context::getSamplerParameterfv(GLuint sampler, GLenum pname, GLfloat *params) |
| 2438 | { |
| 2439 | const Sampler *samplerObject = |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 2440 | mState.mSamplers->checkSamplerAllocation(mImplementation.get(), sampler); |
Geoff Lang | c1984ed | 2016-10-07 12:41:00 -0400 | [diff] [blame] | 2441 | QuerySamplerParameterfv(samplerObject, pname, params); |
Jamie Madill | 06ef36b | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2442 | mGLState.setObjectDirty(GL_SAMPLER); |
Jamie Madill | 9675b80 | 2013-07-19 16:36:59 -0400 | [diff] [blame] | 2443 | } |
| 2444 | |
Olli Etuaho | f0fee07 | 2016-03-30 15:11:58 +0300 | [diff] [blame] | 2445 | void Context::programParameteri(GLuint program, GLenum pname, GLint value) |
| 2446 | { |
| 2447 | gl::Program *programObject = getProgram(program); |
Yunchao He | 61afff1 | 2017-03-14 15:34:03 +0800 | [diff] [blame] | 2448 | SetProgramParameteri(programObject, pname, value); |
Olli Etuaho | f0fee07 | 2016-03-30 15:11:58 +0300 | [diff] [blame] | 2449 | } |
| 2450 | |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2451 | void Context::initRendererString() |
| 2452 | { |
daniel@transgaming.com | ca1ac1f | 2013-01-11 04:13:05 +0000 | [diff] [blame] | 2453 | std::ostringstream rendererString; |
| 2454 | rendererString << "ANGLE ("; |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 2455 | rendererString << mImplementation->getRendererDescription(); |
daniel@transgaming.com | ca1ac1f | 2013-01-11 04:13:05 +0000 | [diff] [blame] | 2456 | rendererString << ")"; |
| 2457 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2458 | mRendererString = MakeStaticString(rendererString.str()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2459 | } |
| 2460 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2461 | void Context::initVersionStrings() |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2462 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2463 | const Version &clientVersion = getClientVersion(); |
| 2464 | |
| 2465 | std::ostringstream versionString; |
| 2466 | versionString << "OpenGL ES " << clientVersion.major << "." << clientVersion.minor << " (ANGLE " |
| 2467 | << ANGLE_VERSION_STRING << ")"; |
| 2468 | mVersionString = MakeStaticString(versionString.str()); |
| 2469 | |
| 2470 | std::ostringstream shadingLanguageVersionString; |
| 2471 | shadingLanguageVersionString << "OpenGL ES GLSL ES " |
| 2472 | << (clientVersion.major == 2 ? 1 : clientVersion.major) << "." |
| 2473 | << clientVersion.minor << "0 (ANGLE " << ANGLE_VERSION_STRING |
| 2474 | << ")"; |
| 2475 | mShadingLanguageString = MakeStaticString(shadingLanguageVersionString.str()); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2476 | } |
| 2477 | |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2478 | void Context::initExtensionStrings() |
| 2479 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2480 | auto mergeExtensionStrings = [](const std::vector<const char *> &strings) { |
| 2481 | std::ostringstream combinedStringStream; |
| 2482 | std::copy(strings.begin(), strings.end(), |
| 2483 | std::ostream_iterator<const char *>(combinedStringStream, " ")); |
| 2484 | return MakeStaticString(combinedStringStream.str()); |
| 2485 | }; |
| 2486 | |
| 2487 | mExtensionStrings.clear(); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 2488 | for (const auto &extensionString : mExtensions.getStrings()) |
| 2489 | { |
| 2490 | mExtensionStrings.push_back(MakeStaticString(extensionString)); |
| 2491 | } |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2492 | mExtensionString = mergeExtensionStrings(mExtensionStrings); |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2493 | |
Bryan Bernhart | 5880656 | 2017-01-05 13:09:31 -0800 | [diff] [blame] | 2494 | const gl::Extensions &nativeExtensions = mImplementation->getNativeExtensions(); |
| 2495 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2496 | mRequestableExtensionStrings.clear(); |
| 2497 | for (const auto &extensionInfo : GetExtensionInfoMap()) |
| 2498 | { |
| 2499 | if (extensionInfo.second.Requestable && |
Bryan Bernhart | 5880656 | 2017-01-05 13:09:31 -0800 | [diff] [blame] | 2500 | !(mExtensions.*(extensionInfo.second.ExtensionsMember)) && |
| 2501 | nativeExtensions.*(extensionInfo.second.ExtensionsMember)) |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2502 | { |
| 2503 | mRequestableExtensionStrings.push_back(MakeStaticString(extensionInfo.first)); |
| 2504 | } |
| 2505 | } |
| 2506 | mRequestableExtensionString = mergeExtensionStrings(mRequestableExtensionStrings); |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2507 | } |
| 2508 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2509 | const GLubyte *Context::getString(GLenum name) const |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2510 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2511 | switch (name) |
| 2512 | { |
| 2513 | case GL_VENDOR: |
| 2514 | return reinterpret_cast<const GLubyte *>("Google Inc."); |
| 2515 | |
| 2516 | case GL_RENDERER: |
| 2517 | return reinterpret_cast<const GLubyte *>(mRendererString); |
| 2518 | |
| 2519 | case GL_VERSION: |
| 2520 | return reinterpret_cast<const GLubyte *>(mVersionString); |
| 2521 | |
| 2522 | case GL_SHADING_LANGUAGE_VERSION: |
| 2523 | return reinterpret_cast<const GLubyte *>(mShadingLanguageString); |
| 2524 | |
| 2525 | case GL_EXTENSIONS: |
| 2526 | return reinterpret_cast<const GLubyte *>(mExtensionString); |
| 2527 | |
| 2528 | case GL_REQUESTABLE_EXTENSIONS_ANGLE: |
| 2529 | return reinterpret_cast<const GLubyte *>(mRequestableExtensionString); |
| 2530 | |
| 2531 | default: |
| 2532 | UNREACHABLE(); |
| 2533 | return nullptr; |
| 2534 | } |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2535 | } |
| 2536 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2537 | const GLubyte *Context::getStringi(GLenum name, GLuint index) const |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2538 | { |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2539 | switch (name) |
| 2540 | { |
| 2541 | case GL_EXTENSIONS: |
| 2542 | return reinterpret_cast<const GLubyte *>(mExtensionStrings[index]); |
| 2543 | |
| 2544 | case GL_REQUESTABLE_EXTENSIONS_ANGLE: |
| 2545 | return reinterpret_cast<const GLubyte *>(mRequestableExtensionStrings[index]); |
| 2546 | |
| 2547 | default: |
| 2548 | UNREACHABLE(); |
| 2549 | return nullptr; |
| 2550 | } |
Geoff Lang | cec3590 | 2014-04-16 10:52:36 -0400 | [diff] [blame] | 2551 | } |
| 2552 | |
| 2553 | size_t Context::getExtensionStringCount() const |
| 2554 | { |
| 2555 | return mExtensionStrings.size(); |
| 2556 | } |
| 2557 | |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2558 | void Context::requestExtension(const char *name) |
| 2559 | { |
| 2560 | const ExtensionInfoMap &extensionInfos = GetExtensionInfoMap(); |
| 2561 | ASSERT(extensionInfos.find(name) != extensionInfos.end()); |
| 2562 | const auto &extension = extensionInfos.at(name); |
| 2563 | ASSERT(extension.Requestable); |
| 2564 | |
| 2565 | if (mExtensions.*(extension.ExtensionsMember)) |
| 2566 | { |
| 2567 | // Extension already enabled |
| 2568 | return; |
| 2569 | } |
| 2570 | |
| 2571 | mExtensions.*(extension.ExtensionsMember) = true; |
| 2572 | updateCaps(); |
| 2573 | initExtensionStrings(); |
Bryan Bernhart | 5880656 | 2017-01-05 13:09:31 -0800 | [diff] [blame] | 2574 | |
Jamie Madill | 2f348d2 | 2017-06-05 10:50:59 -0400 | [diff] [blame] | 2575 | // Release the shader compiler so it will be re-created with the requested extensions enabled. |
| 2576 | releaseShaderCompiler(); |
Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 2577 | |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2578 | // Invalidate all textures and framebuffer. Some extensions make new formats renderable or |
| 2579 | // sampleable. |
| 2580 | mState.mTextures->signalAllTexturesDirty(); |
Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 2581 | for (auto &zeroTexture : mZeroTextures) |
| 2582 | { |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2583 | zeroTexture.second->signalDirty(); |
Geoff Lang | 9aded17 | 2017-04-05 11:07:56 -0400 | [diff] [blame] | 2584 | } |
| 2585 | |
| 2586 | mState.mFramebuffers->invalidateFramebufferComplenessCache(); |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2587 | } |
| 2588 | |
| 2589 | size_t Context::getRequestableExtensionStringCount() const |
| 2590 | { |
| 2591 | return mRequestableExtensionStrings.size(); |
| 2592 | } |
| 2593 | |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2594 | void Context::beginTransformFeedback(GLenum primitiveMode) |
| 2595 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2596 | TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback(); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2597 | ASSERT(transformFeedback != nullptr); |
| 2598 | ASSERT(!transformFeedback->isPaused()); |
| 2599 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 2600 | transformFeedback->begin(this, primitiveMode, mGLState.getProgram()); |
Olli Etuaho | c3e55a4 | 2016-03-09 16:29:18 +0200 | [diff] [blame] | 2601 | } |
| 2602 | |
| 2603 | bool Context::hasActiveTransformFeedback(GLuint program) const |
| 2604 | { |
| 2605 | for (auto pair : mTransformFeedbackMap) |
| 2606 | { |
| 2607 | if (pair.second != nullptr && pair.second->hasBoundProgram(program)) |
| 2608 | { |
| 2609 | return true; |
| 2610 | } |
| 2611 | } |
| 2612 | return false; |
| 2613 | } |
| 2614 | |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 2615 | void Context::initCaps(const egl::DisplayExtensions &displayExtensions) |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2616 | { |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 2617 | mCaps = mImplementation->getNativeCaps(); |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2618 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 2619 | mExtensions = mImplementation->getNativeExtensions(); |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2620 | |
Jamie Madill | 53ea9cc | 2016-05-17 10:12:52 -0400 | [diff] [blame] | 2621 | mLimitations = mImplementation->getNativeLimitations(); |
Austin Kinross | 02df796 | 2015-07-01 10:03:42 -0700 | [diff] [blame] | 2622 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2623 | if (getClientVersion() < Version(3, 0)) |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2624 | { |
| 2625 | // Disable ES3+ extensions |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 2626 | mExtensions.colorBufferFloat = false; |
Geoff Lang | b66a909 | 2016-05-16 15:59:14 -0400 | [diff] [blame] | 2627 | mExtensions.eglImageExternalEssl3 = false; |
Vincent Lang | 25ab451 | 2016-05-13 18:13:59 +0200 | [diff] [blame] | 2628 | mExtensions.textureNorm16 = false; |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 2629 | mExtensions.multiview = false; |
| 2630 | mExtensions.maxViews = 1u; |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2631 | } |
| 2632 | |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2633 | if (getClientVersion() > Version(2, 0)) |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2634 | { |
| 2635 | // FIXME(geofflang): Don't support EXT_sRGB in non-ES2 contexts |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 2636 | // mExtensions.sRGB = false; |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2637 | } |
| 2638 | |
Jamie Madill | 00ed7a1 | 2016-05-19 13:13:38 -0400 | [diff] [blame] | 2639 | // Some extensions are always available because they are implemented in the GL layer. |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 2640 | mExtensions.bindUniformLocation = true; |
| 2641 | mExtensions.vertexArrayObject = true; |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 2642 | mExtensions.bindGeneratesResource = true; |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 2643 | mExtensions.clientArrays = true; |
Geoff Lang | c339c4e | 2016-11-29 10:37:36 -0500 | [diff] [blame] | 2644 | mExtensions.requestExtension = true; |
Jamie Madill | 00ed7a1 | 2016-05-19 13:13:38 -0400 | [diff] [blame] | 2645 | |
| 2646 | // Enable the no error extension if the context was created with the flag. |
| 2647 | mExtensions.noError = mSkipValidation; |
| 2648 | |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 2649 | // 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] | 2650 | mExtensions.surfacelessContext = displayExtensions.surfacelessContext; |
Corentin Wallez | ccab69d | 2017-01-27 16:57:15 -0500 | [diff] [blame] | 2651 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2652 | // Explicitly enable GL_KHR_debug |
| 2653 | mExtensions.debug = true; |
| 2654 | mExtensions.maxDebugMessageLength = 1024; |
| 2655 | mExtensions.maxDebugLoggedMessages = 1024; |
| 2656 | mExtensions.maxDebugGroupStackDepth = 1024; |
| 2657 | mExtensions.maxLabelLength = 1024; |
| 2658 | |
Geoff Lang | ff5b2d5 | 2016-09-07 11:32:23 -0400 | [diff] [blame] | 2659 | // Explicitly enable GL_ANGLE_robust_client_memory |
| 2660 | mExtensions.robustClientMemory = true; |
| 2661 | |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 2662 | // Determine robust resource init availability from EGL. |
| 2663 | mExtensions.robustResourceInitialization = |
Jamie Madill | 948bbe5 | 2017-06-01 13:10:42 -0400 | [diff] [blame] | 2664 | egl::Display::GetClientExtensions().displayRobustResourceInitialization; |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 2665 | |
Jiajia Qin | 8a7b3a0 | 2017-08-25 16:05:48 +0800 | [diff] [blame] | 2666 | // mExtensions.robustBufferAccessBehavior is true only if robust access is true and the backend |
| 2667 | // supports it. |
| 2668 | mExtensions.robustBufferAccessBehavior = |
| 2669 | mRobustAccess && mExtensions.robustBufferAccessBehavior; |
| 2670 | |
Jamie Madill | c43be72 | 2017-07-13 16:22:14 -0400 | [diff] [blame] | 2671 | // Enable the cache control query unconditionally. |
| 2672 | mExtensions.programCacheControl = true; |
| 2673 | |
Geoff Lang | 301d161 | 2014-07-09 10:34:37 -0400 | [diff] [blame] | 2674 | // Apply implementation limits |
| 2675 | mCaps.maxVertexAttributes = std::min<GLuint>(mCaps.maxVertexAttributes, MAX_VERTEX_ATTRIBS); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 2676 | mCaps.maxVertexAttribBindings = |
| 2677 | getClientVersion() < ES_3_1 |
| 2678 | ? mCaps.maxVertexAttributes |
| 2679 | : std::min<GLuint>(mCaps.maxVertexAttribBindings, MAX_VERTEX_ATTRIB_BINDINGS); |
| 2680 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 2681 | mCaps.maxVertexUniformBlocks = std::min<GLuint>( |
| 2682 | mCaps.maxVertexUniformBlocks, IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS); |
| 2683 | mCaps.maxVertexOutputComponents = |
| 2684 | std::min<GLuint>(mCaps.maxVertexOutputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4); |
Geoff Lang | 301d161 | 2014-07-09 10:34:37 -0400 | [diff] [blame] | 2685 | |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 2686 | mCaps.maxFragmentInputComponents = |
| 2687 | std::min<GLuint>(mCaps.maxFragmentInputComponents, IMPLEMENTATION_MAX_VARYING_VECTORS * 4); |
Geoff Lang | 3a61c32 | 2014-07-10 13:01:54 -0400 | [diff] [blame] | 2688 | |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 2689 | // WebGL compatibility |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 2690 | mExtensions.webglCompatibility = mWebGLContext; |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 2691 | for (const auto &extensionInfo : GetExtensionInfoMap()) |
| 2692 | { |
| 2693 | // If this context is for WebGL, disable all enableable extensions |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 2694 | if (mWebGLContext && extensionInfo.second.Requestable) |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 2695 | { |
| 2696 | mExtensions.*(extensionInfo.second.ExtensionsMember) = false; |
| 2697 | } |
| 2698 | } |
| 2699 | |
| 2700 | // Generate texture caps |
| 2701 | updateCaps(); |
| 2702 | } |
| 2703 | |
| 2704 | void Context::updateCaps() |
| 2705 | { |
Geoff Lang | 900013c | 2014-07-07 11:32:19 -0400 | [diff] [blame] | 2706 | mCaps.compressedTextureFormats.clear(); |
Geoff Lang | c287ea6 | 2016-09-16 14:46:51 -0400 | [diff] [blame] | 2707 | mTextureCaps.clear(); |
Geoff Lang | 900013c | 2014-07-07 11:32:19 -0400 | [diff] [blame] | 2708 | |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 2709 | for (auto capsIt : mImplementation->getNativeTextureCaps()) |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2710 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2711 | GLenum sizedInternalFormat = capsIt.first; |
Jamie Madill | 231c7f5 | 2017-04-26 13:45:37 -0400 | [diff] [blame] | 2712 | TextureCaps formatCaps = capsIt.second; |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2713 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2714 | const InternalFormat &formatInfo = GetSizedInternalFormatInfo(sizedInternalFormat); |
Geoff Lang | d87878e | 2014-09-19 15:42:59 -0400 | [diff] [blame] | 2715 | |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 2716 | // Update the format caps based on the client version and extensions. |
| 2717 | // Caps are AND'd with the renderer caps because some core formats are still unsupported in |
| 2718 | // ES3. |
| 2719 | formatCaps.texturable = |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2720 | formatCaps.texturable && formatInfo.textureSupport(getClientVersion(), mExtensions); |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 2721 | formatCaps.renderable = |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2722 | formatCaps.renderable && formatInfo.renderSupport(getClientVersion(), mExtensions); |
Geoff Lang | 0d8b724 | 2015-09-09 14:56:53 -0400 | [diff] [blame] | 2723 | formatCaps.filterable = |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 2724 | formatCaps.filterable && formatInfo.filterSupport(getClientVersion(), mExtensions); |
Geoff Lang | d87878e | 2014-09-19 15:42:59 -0400 | [diff] [blame] | 2725 | |
He Yunchao | ccd8c9b | 2017-01-18 17:36:14 +0800 | [diff] [blame] | 2726 | // OpenGL ES does not support multisampling with non-rendererable formats |
| 2727 | // OpenGL ES 3.0 or prior does not support multisampling with integer formats |
Olli Etuaho | 50c562d | 2017-06-06 14:43:30 +0300 | [diff] [blame] | 2728 | if (!formatCaps.renderable || |
He Yunchao | ccd8c9b | 2017-01-18 17:36:14 +0800 | [diff] [blame] | 2729 | (getClientVersion() < ES_3_1 && |
| 2730 | (formatInfo.componentType == GL_INT || formatInfo.componentType == GL_UNSIGNED_INT))) |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2731 | { |
Geoff Lang | d87878e | 2014-09-19 15:42:59 -0400 | [diff] [blame] | 2732 | formatCaps.sampleCounts.clear(); |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2733 | } |
Olli Etuaho | 50c562d | 2017-06-06 14:43:30 +0300 | [diff] [blame] | 2734 | else |
| 2735 | { |
| 2736 | // We may have limited the max samples for some required renderbuffer formats due to |
| 2737 | // non-conformant formats. In this case MAX_SAMPLES needs to be lowered accordingly. |
| 2738 | GLuint formatMaxSamples = formatCaps.getMaxSamples(); |
| 2739 | |
| 2740 | // GLES 3.0.5 section 4.4.2.2: "Implementations must support creation of renderbuffers |
| 2741 | // in these required formats with up to the value of MAX_SAMPLES multisamples, with the |
| 2742 | // exception of signed and unsigned integer formats." |
| 2743 | if (formatInfo.componentType != GL_INT && formatInfo.componentType != GL_UNSIGNED_INT && |
| 2744 | formatInfo.isRequiredRenderbufferFormat(getClientVersion())) |
| 2745 | { |
| 2746 | ASSERT(getClientVersion() < ES_3_0 || formatMaxSamples >= 4); |
| 2747 | mCaps.maxSamples = std::min(mCaps.maxSamples, formatMaxSamples); |
| 2748 | } |
| 2749 | |
| 2750 | // Handle GLES 3.1 MAX_*_SAMPLES values similarly to MAX_SAMPLES. |
| 2751 | if (getClientVersion() >= ES_3_1) |
| 2752 | { |
| 2753 | // GLES 3.1 section 9.2.5: "Implementations must support creation of renderbuffers |
| 2754 | // in these required formats with up to the value of MAX_SAMPLES multisamples, with |
| 2755 | // the exception that the signed and unsigned integer formats are required only to |
| 2756 | // support creation of renderbuffers with up to the value of MAX_INTEGER_SAMPLES |
| 2757 | // multisamples, which must be at least one." |
| 2758 | if (formatInfo.componentType == GL_INT || |
| 2759 | formatInfo.componentType == GL_UNSIGNED_INT) |
| 2760 | { |
| 2761 | mCaps.maxIntegerSamples = std::min(mCaps.maxIntegerSamples, formatMaxSamples); |
| 2762 | } |
| 2763 | |
| 2764 | // GLES 3.1 section 19.3.1. |
| 2765 | if (formatCaps.texturable) |
| 2766 | { |
| 2767 | if (formatInfo.depthBits > 0) |
| 2768 | { |
| 2769 | mCaps.maxDepthTextureSamples = |
| 2770 | std::min(mCaps.maxDepthTextureSamples, formatMaxSamples); |
| 2771 | } |
| 2772 | else if (formatInfo.redBits > 0) |
| 2773 | { |
| 2774 | mCaps.maxColorTextureSamples = |
| 2775 | std::min(mCaps.maxColorTextureSamples, formatMaxSamples); |
| 2776 | } |
| 2777 | } |
| 2778 | } |
| 2779 | } |
Geoff Lang | d87878e | 2014-09-19 15:42:59 -0400 | [diff] [blame] | 2780 | |
| 2781 | if (formatCaps.texturable && formatInfo.compressed) |
| 2782 | { |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2783 | mCaps.compressedTextureFormats.push_back(sizedInternalFormat); |
Geoff Lang | d87878e | 2014-09-19 15:42:59 -0400 | [diff] [blame] | 2784 | } |
| 2785 | |
Geoff Lang | ca27139 | 2017-04-05 12:30:00 -0400 | [diff] [blame] | 2786 | mTextureCaps.insert(sizedInternalFormat, formatCaps); |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2787 | } |
Jamie Madill | 3244736 | 2017-06-28 14:53:52 -0400 | [diff] [blame] | 2788 | |
| 2789 | // If program binary is disabled, blank out the memory cache pointer. |
| 2790 | if (!mImplementation->getNativeExtensions().getProgramBinary) |
| 2791 | { |
| 2792 | mMemoryProgramCache = nullptr; |
| 2793 | } |
Geoff Lang | 493daf5 | 2014-07-03 13:38:44 -0400 | [diff] [blame] | 2794 | } |
| 2795 | |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 2796 | void Context::initWorkarounds() |
| 2797 | { |
Jamie Madill | 761b02c | 2017-06-23 16:27:06 -0400 | [diff] [blame] | 2798 | // Apply back-end workarounds. |
| 2799 | mImplementation->applyNativeWorkarounds(&mWorkarounds); |
| 2800 | |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 2801 | // Lose the context upon out of memory error if the application is |
| 2802 | // expecting to watch for those events. |
| 2803 | mWorkarounds.loseContextOnOutOfMemory = (mResetStrategy == GL_LOSE_CONTEXT_ON_RESET_EXT); |
| 2804 | } |
| 2805 | |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 2806 | void Context::syncRendererState() |
| 2807 | { |
Jamie Madill | 7d1f5c6 | 2017-09-02 15:32:15 -0400 | [diff] [blame] | 2808 | mGLState.syncDirtyObjects(this); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2809 | const State::DirtyBits &dirtyBits = mGLState.getDirtyBits(); |
Jamie Madill | fe54834 | 2017-06-19 11:13:24 -0400 | [diff] [blame] | 2810 | mImplementation->syncState(this, dirtyBits); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2811 | mGLState.clearDirtyBits(); |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 2812 | } |
| 2813 | |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2814 | void Context::syncRendererState(const State::DirtyBits &bitMask, |
| 2815 | const State::DirtyObjects &objectMask) |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 2816 | { |
Jamie Madill | 7d1f5c6 | 2017-09-02 15:32:15 -0400 | [diff] [blame] | 2817 | mGLState.syncDirtyObjects(this, objectMask); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2818 | const State::DirtyBits &dirtyBits = (mGLState.getDirtyBits() & bitMask); |
Jamie Madill | fe54834 | 2017-06-19 11:13:24 -0400 | [diff] [blame] | 2819 | mImplementation->syncState(this, dirtyBits); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2820 | mGLState.clearDirtyBits(dirtyBits); |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 2821 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2822 | |
| 2823 | void Context::blitFramebuffer(GLint srcX0, |
| 2824 | GLint srcY0, |
| 2825 | GLint srcX1, |
| 2826 | GLint srcY1, |
| 2827 | GLint dstX0, |
| 2828 | GLint dstY0, |
| 2829 | GLint dstX1, |
| 2830 | GLint dstY1, |
| 2831 | GLbitfield mask, |
| 2832 | GLenum filter) |
| 2833 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2834 | Framebuffer *drawFramebuffer = mGLState.getDrawFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2835 | ASSERT(drawFramebuffer); |
| 2836 | |
| 2837 | Rectangle srcArea(srcX0, srcY0, srcX1 - srcX0, srcY1 - srcY0); |
| 2838 | Rectangle dstArea(dstX0, dstY0, dstX1 - dstX0, dstY1 - dstY0); |
| 2839 | |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2840 | syncStateForBlit(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2841 | |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 2842 | handleError(drawFramebuffer->blit(this, srcArea, dstArea, mask, filter)); |
apatrick@chromium.org | 144f280 | 2012-07-12 01:42:34 +0000 | [diff] [blame] | 2843 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2844 | |
| 2845 | void Context::clear(GLbitfield mask) |
| 2846 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2847 | syncStateForClear(); |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 2848 | handleError(mGLState.getDrawFramebuffer()->clear(this, mask)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2849 | } |
| 2850 | |
| 2851 | void Context::clearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *values) |
| 2852 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2853 | syncStateForClear(); |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 2854 | handleError(mGLState.getDrawFramebuffer()->clearBufferfv(this, buffer, drawbuffer, values)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2855 | } |
| 2856 | |
| 2857 | void Context::clearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *values) |
| 2858 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2859 | syncStateForClear(); |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 2860 | handleError(mGLState.getDrawFramebuffer()->clearBufferuiv(this, buffer, drawbuffer, values)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2861 | } |
| 2862 | |
| 2863 | void Context::clearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *values) |
| 2864 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2865 | syncStateForClear(); |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 2866 | handleError(mGLState.getDrawFramebuffer()->clearBufferiv(this, buffer, drawbuffer, values)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2867 | } |
| 2868 | |
| 2869 | void Context::clearBufferfi(GLenum buffer, GLint drawbuffer, GLfloat depth, GLint stencil) |
| 2870 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2871 | Framebuffer *framebufferObject = mGLState.getDrawFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2872 | ASSERT(framebufferObject); |
| 2873 | |
| 2874 | // If a buffer is not present, the clear has no effect |
| 2875 | if (framebufferObject->getDepthbuffer() == nullptr && |
| 2876 | framebufferObject->getStencilbuffer() == nullptr) |
| 2877 | { |
| 2878 | return; |
| 2879 | } |
| 2880 | |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2881 | syncStateForClear(); |
Jamie Madill | c564c07 | 2017-06-01 12:45:42 -0400 | [diff] [blame] | 2882 | handleError(framebufferObject->clearBufferfi(this, buffer, drawbuffer, depth, stencil)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2883 | } |
| 2884 | |
| 2885 | void Context::readPixels(GLint x, |
| 2886 | GLint y, |
| 2887 | GLsizei width, |
| 2888 | GLsizei height, |
| 2889 | GLenum format, |
| 2890 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 2891 | void *pixels) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2892 | { |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 2893 | if (width == 0 || height == 0) |
| 2894 | { |
| 2895 | return; |
| 2896 | } |
| 2897 | |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 2898 | syncStateForReadPixels(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2899 | |
Jamie Madill | b666492 | 2017-07-25 12:55:04 -0400 | [diff] [blame] | 2900 | Framebuffer *readFBO = mGLState.getReadFramebuffer(); |
| 2901 | ASSERT(readFBO); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2902 | |
| 2903 | Rectangle area(x, y, width, height); |
Jamie Madill | b666492 | 2017-07-25 12:55:04 -0400 | [diff] [blame] | 2904 | handleError(readFBO->readPixels(this, area, format, type, pixels)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2905 | } |
| 2906 | |
| 2907 | void Context::copyTexImage2D(GLenum target, |
| 2908 | GLint level, |
| 2909 | GLenum internalformat, |
| 2910 | GLint x, |
| 2911 | GLint y, |
| 2912 | GLsizei width, |
| 2913 | GLsizei height, |
| 2914 | GLint border) |
| 2915 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2916 | // Only sync the read FBO |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2917 | mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2918 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2919 | Rectangle sourceArea(x, y, width, height); |
| 2920 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2921 | const Framebuffer *framebuffer = mGLState.getReadFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2922 | Texture *texture = |
| 2923 | getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 2924 | handleError(texture->copyImage(this, target, level, sourceArea, internalformat, framebuffer)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2925 | } |
| 2926 | |
| 2927 | void Context::copyTexSubImage2D(GLenum target, |
| 2928 | GLint level, |
| 2929 | GLint xoffset, |
| 2930 | GLint yoffset, |
| 2931 | GLint x, |
| 2932 | GLint y, |
| 2933 | GLsizei width, |
| 2934 | GLsizei height) |
| 2935 | { |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 2936 | if (width == 0 || height == 0) |
| 2937 | { |
| 2938 | return; |
| 2939 | } |
| 2940 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2941 | // Only sync the read FBO |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2942 | mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2943 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2944 | Offset destOffset(xoffset, yoffset, 0); |
| 2945 | Rectangle sourceArea(x, y, width, height); |
| 2946 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2947 | const Framebuffer *framebuffer = mGLState.getReadFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2948 | Texture *texture = |
| 2949 | getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 2950 | handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2951 | } |
| 2952 | |
| 2953 | void Context::copyTexSubImage3D(GLenum target, |
| 2954 | GLint level, |
| 2955 | GLint xoffset, |
| 2956 | GLint yoffset, |
| 2957 | GLint zoffset, |
| 2958 | GLint x, |
| 2959 | GLint y, |
| 2960 | GLsizei width, |
| 2961 | GLsizei height) |
| 2962 | { |
Corentin Wallez | 9a8d366 | 2016-09-22 12:18:29 -0400 | [diff] [blame] | 2963 | if (width == 0 || height == 0) |
| 2964 | { |
| 2965 | return; |
| 2966 | } |
| 2967 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2968 | // Only sync the read FBO |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2969 | mGLState.syncDirtyObject(this, GL_READ_FRAMEBUFFER); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2970 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2971 | Offset destOffset(xoffset, yoffset, zoffset); |
| 2972 | Rectangle sourceArea(x, y, width, height); |
| 2973 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2974 | const Framebuffer *framebuffer = mGLState.getReadFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2975 | Texture *texture = getTargetTexture(target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 2976 | handleError(texture->copySubImage(this, target, level, destOffset, sourceArea, framebuffer)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2977 | } |
| 2978 | |
| 2979 | void Context::framebufferTexture2D(GLenum target, |
| 2980 | GLenum attachment, |
| 2981 | GLenum textarget, |
| 2982 | GLuint texture, |
| 2983 | GLint level) |
| 2984 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 2985 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 2986 | ASSERT(framebuffer); |
| 2987 | |
| 2988 | if (texture != 0) |
| 2989 | { |
| 2990 | Texture *textureObj = getTexture(texture); |
| 2991 | |
| 2992 | ImageIndex index = ImageIndex::MakeInvalid(); |
| 2993 | |
| 2994 | if (textarget == GL_TEXTURE_2D) |
| 2995 | { |
| 2996 | index = ImageIndex::Make2D(level); |
| 2997 | } |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 2998 | else if (textarget == GL_TEXTURE_RECTANGLE_ANGLE) |
| 2999 | { |
| 3000 | index = ImageIndex::MakeRectangle(level); |
| 3001 | } |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 3002 | else if (textarget == GL_TEXTURE_2D_MULTISAMPLE) |
| 3003 | { |
| 3004 | ASSERT(level == 0); |
| 3005 | index = ImageIndex::Make2DMultisample(); |
| 3006 | } |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3007 | else |
| 3008 | { |
| 3009 | ASSERT(IsCubeMapTextureTarget(textarget)); |
| 3010 | index = ImageIndex::MakeCube(textarget, level); |
| 3011 | } |
| 3012 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 3013 | framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObj); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3014 | } |
| 3015 | else |
| 3016 | { |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 3017 | framebuffer->resetAttachment(this, attachment); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3018 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 3019 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3020 | mGLState.setObjectDirty(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3021 | } |
| 3022 | |
| 3023 | void Context::framebufferRenderbuffer(GLenum target, |
| 3024 | GLenum attachment, |
| 3025 | GLenum renderbuffertarget, |
| 3026 | GLuint renderbuffer) |
| 3027 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3028 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3029 | ASSERT(framebuffer); |
| 3030 | |
| 3031 | if (renderbuffer != 0) |
| 3032 | { |
| 3033 | Renderbuffer *renderbufferObject = getRenderbuffer(renderbuffer); |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 3034 | |
| 3035 | framebuffer->setAttachment(this, GL_RENDERBUFFER, attachment, gl::ImageIndex::MakeInvalid(), |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3036 | renderbufferObject); |
| 3037 | } |
| 3038 | else |
| 3039 | { |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 3040 | framebuffer->resetAttachment(this, attachment); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3041 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 3042 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3043 | mGLState.setObjectDirty(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3044 | } |
| 3045 | |
| 3046 | void Context::framebufferTextureLayer(GLenum target, |
| 3047 | GLenum attachment, |
| 3048 | GLuint texture, |
| 3049 | GLint level, |
| 3050 | GLint layer) |
| 3051 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3052 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3053 | ASSERT(framebuffer); |
| 3054 | |
| 3055 | if (texture != 0) |
| 3056 | { |
| 3057 | Texture *textureObject = getTexture(texture); |
| 3058 | |
| 3059 | ImageIndex index = ImageIndex::MakeInvalid(); |
| 3060 | |
| 3061 | if (textureObject->getTarget() == GL_TEXTURE_3D) |
| 3062 | { |
| 3063 | index = ImageIndex::Make3D(level, layer); |
| 3064 | } |
| 3065 | else |
| 3066 | { |
| 3067 | ASSERT(textureObject->getTarget() == GL_TEXTURE_2D_ARRAY); |
| 3068 | index = ImageIndex::Make2DArray(level, layer); |
| 3069 | } |
| 3070 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 3071 | framebuffer->setAttachment(this, GL_TEXTURE, attachment, index, textureObject); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3072 | } |
| 3073 | else |
| 3074 | { |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 3075 | framebuffer->resetAttachment(this, attachment); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3076 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 3077 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3078 | mGLState.setObjectDirty(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3079 | } |
| 3080 | |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 3081 | void Context::framebufferTextureMultiviewLayeredANGLE(GLenum target, |
| 3082 | GLenum attachment, |
| 3083 | GLuint texture, |
| 3084 | GLint level, |
| 3085 | GLint baseViewIndex, |
| 3086 | GLsizei numViews) |
| 3087 | { |
Martin Radev | 82ef774 | 2017-08-08 17:44:58 +0300 | [diff] [blame] | 3088 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
| 3089 | ASSERT(framebuffer); |
| 3090 | |
| 3091 | if (texture != 0) |
| 3092 | { |
| 3093 | Texture *textureObj = getTexture(texture); |
| 3094 | |
Martin Radev | 18b75ba | 2017-08-15 15:50:40 +0300 | [diff] [blame] | 3095 | ImageIndex index = ImageIndex::Make2DArrayRange(level, baseViewIndex, numViews); |
Martin Radev | 82ef774 | 2017-08-08 17:44:58 +0300 | [diff] [blame] | 3096 | framebuffer->setAttachmentMultiviewLayered(this, GL_TEXTURE, attachment, index, textureObj, |
| 3097 | numViews, baseViewIndex); |
| 3098 | } |
| 3099 | else |
| 3100 | { |
| 3101 | framebuffer->resetAttachment(this, attachment); |
| 3102 | } |
| 3103 | |
| 3104 | mGLState.setObjectDirty(target); |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 3105 | } |
| 3106 | |
| 3107 | void Context::framebufferTextureMultiviewSideBySideANGLE(GLenum target, |
| 3108 | GLenum attachment, |
| 3109 | GLuint texture, |
| 3110 | GLint level, |
| 3111 | GLsizei numViews, |
| 3112 | const GLint *viewportOffsets) |
| 3113 | { |
Martin Radev | 5dae57b | 2017-07-14 16:15:55 +0300 | [diff] [blame] | 3114 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
| 3115 | ASSERT(framebuffer); |
| 3116 | |
| 3117 | if (texture != 0) |
| 3118 | { |
| 3119 | Texture *textureObj = getTexture(texture); |
| 3120 | |
| 3121 | ImageIndex index = ImageIndex::Make2D(level); |
| 3122 | framebuffer->setAttachmentMultiviewSideBySide(this, GL_TEXTURE, attachment, index, |
| 3123 | textureObj, numViews, viewportOffsets); |
| 3124 | } |
| 3125 | else |
| 3126 | { |
| 3127 | framebuffer->resetAttachment(this, attachment); |
| 3128 | } |
| 3129 | |
| 3130 | mGLState.setObjectDirty(target); |
Martin Radev | 137032d | 2017-07-13 10:11:12 +0300 | [diff] [blame] | 3131 | } |
| 3132 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3133 | void Context::drawBuffers(GLsizei n, const GLenum *bufs) |
| 3134 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3135 | Framebuffer *framebuffer = mGLState.getDrawFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3136 | ASSERT(framebuffer); |
| 3137 | framebuffer->setDrawBuffers(n, bufs); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3138 | mGLState.setObjectDirty(GL_DRAW_FRAMEBUFFER); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3139 | } |
| 3140 | |
| 3141 | void Context::readBuffer(GLenum mode) |
| 3142 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3143 | Framebuffer *readFBO = mGLState.getReadFramebuffer(); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3144 | readFBO->setReadBuffer(mode); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3145 | mGLState.setObjectDirty(GL_READ_FRAMEBUFFER); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3146 | } |
| 3147 | |
| 3148 | void Context::discardFramebuffer(GLenum target, GLsizei numAttachments, const GLenum *attachments) |
| 3149 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 3150 | // Only sync the FBO |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 3151 | mGLState.syncDirtyObject(this, target); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 3152 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3153 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3154 | ASSERT(framebuffer); |
| 3155 | |
| 3156 | // The specification isn't clear what should be done when the framebuffer isn't complete. |
| 3157 | // We leave it up to the framebuffer implementation to decide what to do. |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 3158 | handleError(framebuffer->discard(this, numAttachments, attachments)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3159 | } |
| 3160 | |
| 3161 | void Context::invalidateFramebuffer(GLenum target, |
| 3162 | GLsizei numAttachments, |
| 3163 | const GLenum *attachments) |
| 3164 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 3165 | // Only sync the FBO |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 3166 | mGLState.syncDirtyObject(this, target); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 3167 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3168 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3169 | ASSERT(framebuffer); |
| 3170 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 3171 | if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3172 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3173 | return; |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3174 | } |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3175 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 3176 | handleError(framebuffer->invalidate(this, numAttachments, attachments)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3177 | } |
| 3178 | |
| 3179 | void Context::invalidateSubFramebuffer(GLenum target, |
| 3180 | GLsizei numAttachments, |
| 3181 | const GLenum *attachments, |
| 3182 | GLint x, |
| 3183 | GLint y, |
| 3184 | GLsizei width, |
| 3185 | GLsizei height) |
| 3186 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 3187 | // Only sync the FBO |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 3188 | mGLState.syncDirtyObject(this, target); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 3189 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3190 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3191 | ASSERT(framebuffer); |
| 3192 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 3193 | if (framebuffer->checkStatus(this) != GL_FRAMEBUFFER_COMPLETE) |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3194 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3195 | return; |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3196 | } |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3197 | |
| 3198 | Rectangle area(x, y, width, height); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 3199 | handleError(framebuffer->invalidateSub(this, numAttachments, attachments, area)); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 3200 | } |
| 3201 | |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3202 | void Context::texImage2D(GLenum target, |
| 3203 | GLint level, |
| 3204 | GLint internalformat, |
| 3205 | GLsizei width, |
| 3206 | GLsizei height, |
| 3207 | GLint border, |
| 3208 | GLenum format, |
| 3209 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3210 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3211 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 3212 | syncStateForTexImage(); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3213 | |
| 3214 | Extents size(width, height, 1); |
| 3215 | Texture *texture = |
| 3216 | getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 3217 | handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat, |
| 3218 | size, format, type, reinterpret_cast<const uint8_t *>(pixels))); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3219 | } |
| 3220 | |
| 3221 | void Context::texImage3D(GLenum target, |
| 3222 | GLint level, |
| 3223 | GLint internalformat, |
| 3224 | GLsizei width, |
| 3225 | GLsizei height, |
| 3226 | GLsizei depth, |
| 3227 | GLint border, |
| 3228 | GLenum format, |
| 3229 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3230 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3231 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 3232 | syncStateForTexImage(); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3233 | |
| 3234 | Extents size(width, height, depth); |
| 3235 | Texture *texture = getTargetTexture(target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 3236 | handleError(texture->setImage(this, mGLState.getUnpackState(), target, level, internalformat, |
| 3237 | size, format, type, reinterpret_cast<const uint8_t *>(pixels))); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3238 | } |
| 3239 | |
| 3240 | void Context::texSubImage2D(GLenum target, |
| 3241 | GLint level, |
| 3242 | GLint xoffset, |
| 3243 | GLint yoffset, |
| 3244 | GLsizei width, |
| 3245 | GLsizei height, |
| 3246 | GLenum format, |
| 3247 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3248 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3249 | { |
| 3250 | // Zero sized uploads are valid but no-ops |
| 3251 | if (width == 0 || height == 0) |
| 3252 | { |
| 3253 | return; |
| 3254 | } |
| 3255 | |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 3256 | syncStateForTexImage(); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3257 | |
| 3258 | Box area(xoffset, yoffset, 0, width, height, 1); |
| 3259 | Texture *texture = |
| 3260 | getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 3261 | handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format, |
| 3262 | type, reinterpret_cast<const uint8_t *>(pixels))); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3263 | } |
| 3264 | |
| 3265 | void Context::texSubImage3D(GLenum target, |
| 3266 | GLint level, |
| 3267 | GLint xoffset, |
| 3268 | GLint yoffset, |
| 3269 | GLint zoffset, |
| 3270 | GLsizei width, |
| 3271 | GLsizei height, |
| 3272 | GLsizei depth, |
| 3273 | GLenum format, |
| 3274 | GLenum type, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3275 | const void *pixels) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3276 | { |
| 3277 | // Zero sized uploads are valid but no-ops |
| 3278 | if (width == 0 || height == 0 || depth == 0) |
| 3279 | { |
| 3280 | return; |
| 3281 | } |
| 3282 | |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 3283 | syncStateForTexImage(); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3284 | |
| 3285 | Box area(xoffset, yoffset, zoffset, width, height, depth); |
| 3286 | Texture *texture = getTargetTexture(target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 3287 | handleError(texture->setSubImage(this, mGLState.getUnpackState(), target, level, area, format, |
| 3288 | type, reinterpret_cast<const uint8_t *>(pixels))); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3289 | } |
| 3290 | |
| 3291 | void Context::compressedTexImage2D(GLenum target, |
| 3292 | GLint level, |
| 3293 | GLenum internalformat, |
| 3294 | GLsizei width, |
| 3295 | GLsizei height, |
| 3296 | GLint border, |
| 3297 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3298 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3299 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 3300 | syncStateForTexImage(); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3301 | |
| 3302 | Extents size(width, height, 1); |
| 3303 | Texture *texture = |
| 3304 | getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 3305 | handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level, |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3306 | internalformat, size, imageSize, |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3307 | reinterpret_cast<const uint8_t *>(data))); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3308 | } |
| 3309 | |
| 3310 | void Context::compressedTexImage3D(GLenum target, |
| 3311 | GLint level, |
| 3312 | GLenum internalformat, |
| 3313 | GLsizei width, |
| 3314 | GLsizei height, |
| 3315 | GLsizei depth, |
| 3316 | GLint border, |
| 3317 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3318 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3319 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 3320 | syncStateForTexImage(); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3321 | |
| 3322 | Extents size(width, height, depth); |
| 3323 | Texture *texture = getTargetTexture(target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 3324 | handleError(texture->setCompressedImage(this, mGLState.getUnpackState(), target, level, |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3325 | internalformat, size, imageSize, |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3326 | reinterpret_cast<const uint8_t *>(data))); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3327 | } |
| 3328 | |
| 3329 | void Context::compressedTexSubImage2D(GLenum target, |
| 3330 | GLint level, |
| 3331 | GLint xoffset, |
| 3332 | GLint yoffset, |
| 3333 | GLsizei width, |
| 3334 | GLsizei height, |
| 3335 | GLenum format, |
| 3336 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3337 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3338 | { |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 3339 | syncStateForTexImage(); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3340 | |
| 3341 | Box area(xoffset, yoffset, 0, width, height, 1); |
| 3342 | Texture *texture = |
| 3343 | getTargetTexture(IsCubeMapTextureTarget(target) ? GL_TEXTURE_CUBE_MAP : target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 3344 | handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area, |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3345 | format, imageSize, |
| 3346 | reinterpret_cast<const uint8_t *>(data))); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3347 | } |
| 3348 | |
| 3349 | void Context::compressedTexSubImage3D(GLenum target, |
| 3350 | GLint level, |
| 3351 | GLint xoffset, |
| 3352 | GLint yoffset, |
| 3353 | GLint zoffset, |
| 3354 | GLsizei width, |
| 3355 | GLsizei height, |
| 3356 | GLsizei depth, |
| 3357 | GLenum format, |
| 3358 | GLsizei imageSize, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3359 | const void *data) |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3360 | { |
| 3361 | // Zero sized uploads are valid but no-ops |
| 3362 | if (width == 0 || height == 0) |
| 3363 | { |
| 3364 | return; |
| 3365 | } |
| 3366 | |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 3367 | syncStateForTexImage(); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3368 | |
| 3369 | Box area(xoffset, yoffset, zoffset, width, height, depth); |
| 3370 | Texture *texture = getTargetTexture(target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 3371 | handleError(texture->setCompressedSubImage(this, mGLState.getUnpackState(), target, level, area, |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3372 | format, imageSize, |
| 3373 | reinterpret_cast<const uint8_t *>(data))); |
Jamie Madill | 73a8496 | 2016-02-12 09:27:23 -0500 | [diff] [blame] | 3374 | } |
| 3375 | |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 3376 | void Context::generateMipmap(GLenum target) |
| 3377 | { |
| 3378 | Texture *texture = getTargetTexture(target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 3379 | handleError(texture->generateMipmap(this)); |
Olli Etuaho | 0f2b156 | 2016-05-13 16:15:35 +0300 | [diff] [blame] | 3380 | } |
| 3381 | |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3382 | void Context::copyTextureCHROMIUM(GLuint sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 3383 | GLint sourceLevel, |
| 3384 | GLenum destTarget, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3385 | GLuint destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 3386 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3387 | GLint internalFormat, |
| 3388 | GLenum destType, |
| 3389 | GLboolean unpackFlipY, |
| 3390 | GLboolean unpackPremultiplyAlpha, |
| 3391 | GLboolean unpackUnmultiplyAlpha) |
| 3392 | { |
| 3393 | syncStateForTexImage(); |
| 3394 | |
| 3395 | gl::Texture *sourceTexture = getTexture(sourceId); |
| 3396 | gl::Texture *destTexture = getTexture(destId); |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 3397 | handleError(destTexture->copyTexture( |
| 3398 | this, destTarget, destLevel, internalFormat, destType, sourceLevel, unpackFlipY == GL_TRUE, |
| 3399 | unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture)); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3400 | } |
| 3401 | |
| 3402 | void Context::copySubTextureCHROMIUM(GLuint sourceId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 3403 | GLint sourceLevel, |
| 3404 | GLenum destTarget, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3405 | GLuint destId, |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 3406 | GLint destLevel, |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3407 | GLint xoffset, |
| 3408 | GLint yoffset, |
| 3409 | GLint x, |
| 3410 | GLint y, |
| 3411 | GLsizei width, |
| 3412 | GLsizei height, |
| 3413 | GLboolean unpackFlipY, |
| 3414 | GLboolean unpackPremultiplyAlpha, |
| 3415 | GLboolean unpackUnmultiplyAlpha) |
| 3416 | { |
| 3417 | // Zero sized copies are valid but no-ops |
| 3418 | if (width == 0 || height == 0) |
| 3419 | { |
| 3420 | return; |
| 3421 | } |
| 3422 | |
| 3423 | syncStateForTexImage(); |
| 3424 | |
| 3425 | gl::Texture *sourceTexture = getTexture(sourceId); |
| 3426 | gl::Texture *destTexture = getTexture(destId); |
| 3427 | Offset offset(xoffset, yoffset, 0); |
| 3428 | Rectangle area(x, y, width, height); |
Geoff Lang | fc72a07 | 2017-03-24 14:52:39 -0400 | [diff] [blame] | 3429 | handleError(destTexture->copySubTexture( |
| 3430 | this, destTarget, destLevel, offset, sourceLevel, area, unpackFlipY == GL_TRUE, |
| 3431 | unpackPremultiplyAlpha == GL_TRUE, unpackUnmultiplyAlpha == GL_TRUE, sourceTexture)); |
Geoff Lang | 97073d1 | 2016-04-20 10:42:34 -0700 | [diff] [blame] | 3432 | } |
| 3433 | |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 3434 | void Context::compressedCopyTextureCHROMIUM(GLuint sourceId, GLuint destId) |
| 3435 | { |
| 3436 | syncStateForTexImage(); |
| 3437 | |
| 3438 | gl::Texture *sourceTexture = getTexture(sourceId); |
| 3439 | gl::Texture *destTexture = getTexture(destId); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 3440 | handleError(destTexture->copyCompressedTexture(this, sourceTexture)); |
Geoff Lang | 47110bf | 2016-04-20 11:13:22 -0700 | [diff] [blame] | 3441 | } |
| 3442 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3443 | void Context::getBufferPointerv(GLenum target, GLenum pname, void **params) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3444 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3445 | Buffer *buffer = mGLState.getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3446 | ASSERT(buffer); |
| 3447 | |
Geoff Lang | 496c02d | 2016-10-20 11:38:11 -0700 | [diff] [blame] | 3448 | QueryBufferPointerv(buffer, pname, params); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3449 | } |
| 3450 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3451 | void *Context::mapBuffer(GLenum target, GLenum access) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3452 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3453 | Buffer *buffer = mGLState.getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3454 | ASSERT(buffer); |
| 3455 | |
Jamie Madill | 5f56ddb | 2017-01-13 17:29:55 -0500 | [diff] [blame] | 3456 | Error error = buffer->map(this, access); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3457 | if (error.isError()) |
| 3458 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3459 | handleError(error); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3460 | return nullptr; |
| 3461 | } |
| 3462 | |
| 3463 | return buffer->getMapPointer(); |
| 3464 | } |
| 3465 | |
| 3466 | GLboolean Context::unmapBuffer(GLenum target) |
| 3467 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3468 | Buffer *buffer = mGLState.getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3469 | ASSERT(buffer); |
| 3470 | |
| 3471 | GLboolean result; |
Jamie Madill | 5f56ddb | 2017-01-13 17:29:55 -0500 | [diff] [blame] | 3472 | Error error = buffer->unmap(this, &result); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3473 | if (error.isError()) |
| 3474 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3475 | handleError(error); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3476 | return GL_FALSE; |
| 3477 | } |
| 3478 | |
| 3479 | return result; |
| 3480 | } |
| 3481 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3482 | void *Context::mapBufferRange(GLenum target, GLintptr offset, GLsizeiptr length, GLbitfield access) |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3483 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3484 | Buffer *buffer = mGLState.getTargetBuffer(target); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3485 | ASSERT(buffer); |
| 3486 | |
Jamie Madill | 5f56ddb | 2017-01-13 17:29:55 -0500 | [diff] [blame] | 3487 | Error error = buffer->mapRange(this, offset, length, access); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3488 | if (error.isError()) |
| 3489 | { |
Jamie Madill | 437fa65 | 2016-05-03 15:13:24 -0400 | [diff] [blame] | 3490 | handleError(error); |
Olli Etuaho | 4f66748 | 2016-03-30 15:56:35 +0300 | [diff] [blame] | 3491 | return nullptr; |
| 3492 | } |
| 3493 | |
| 3494 | return buffer->getMapPointer(); |
| 3495 | } |
| 3496 | |
| 3497 | void Context::flushMappedBufferRange(GLenum /*target*/, GLintptr /*offset*/, GLsizeiptr /*length*/) |
| 3498 | { |
| 3499 | // We do not currently support a non-trivial implementation of FlushMappedBufferRange |
| 3500 | } |
| 3501 | |
Jamie Madill | ad9f24e | 2016-02-12 09:27:24 -0500 | [diff] [blame] | 3502 | void Context::syncStateForReadPixels() |
| 3503 | { |
| 3504 | syncRendererState(mReadPixelsDirtyBits, mReadPixelsDirtyObjects); |
| 3505 | } |
| 3506 | |
| 3507 | void Context::syncStateForTexImage() |
| 3508 | { |
| 3509 | syncRendererState(mTexImageDirtyBits, mTexImageDirtyObjects); |
| 3510 | } |
| 3511 | |
| 3512 | void Context::syncStateForClear() |
| 3513 | { |
| 3514 | syncRendererState(mClearDirtyBits, mClearDirtyObjects); |
| 3515 | } |
| 3516 | |
| 3517 | void Context::syncStateForBlit() |
| 3518 | { |
| 3519 | syncRendererState(mBlitDirtyBits, mBlitDirtyObjects); |
| 3520 | } |
| 3521 | |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3522 | void Context::activeTexture(GLenum texture) |
| 3523 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3524 | mGLState.setActiveSampler(texture - GL_TEXTURE0); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3525 | } |
| 3526 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3527 | void Context::blendColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3528 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3529 | mGLState.setBlendColor(clamp01(red), clamp01(green), clamp01(blue), clamp01(alpha)); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3530 | } |
| 3531 | |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 3532 | void Context::blendEquation(GLenum mode) |
| 3533 | { |
| 3534 | mGLState.setBlendEquation(mode, mode); |
| 3535 | } |
| 3536 | |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3537 | void Context::blendEquationSeparate(GLenum modeRGB, GLenum modeAlpha) |
| 3538 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3539 | mGLState.setBlendEquation(modeRGB, modeAlpha); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3540 | } |
| 3541 | |
Jamie Madill | 8a9e4bc | 2016-11-13 20:02:12 -0500 | [diff] [blame] | 3542 | void Context::blendFunc(GLenum sfactor, GLenum dfactor) |
| 3543 | { |
| 3544 | mGLState.setBlendFactors(sfactor, dfactor, sfactor, dfactor); |
| 3545 | } |
| 3546 | |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3547 | void Context::blendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha) |
| 3548 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3549 | mGLState.setBlendFactors(srcRGB, dstRGB, srcAlpha, dstAlpha); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3550 | } |
| 3551 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3552 | void Context::clearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3553 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3554 | mGLState.setColorClearValue(red, green, blue, alpha); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3555 | } |
| 3556 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3557 | void Context::clearDepthf(GLfloat depth) |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3558 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3559 | mGLState.setDepthClearValue(depth); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3560 | } |
| 3561 | |
| 3562 | void Context::clearStencil(GLint s) |
| 3563 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3564 | mGLState.setStencilClearValue(s); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3565 | } |
| 3566 | |
| 3567 | void Context::colorMask(GLboolean red, GLboolean green, GLboolean blue, GLboolean alpha) |
| 3568 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3569 | 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] | 3570 | } |
| 3571 | |
| 3572 | void Context::cullFace(GLenum mode) |
| 3573 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3574 | mGLState.setCullMode(mode); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3575 | } |
| 3576 | |
| 3577 | void Context::depthFunc(GLenum func) |
| 3578 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3579 | mGLState.setDepthFunc(func); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3580 | } |
| 3581 | |
| 3582 | void Context::depthMask(GLboolean flag) |
| 3583 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3584 | mGLState.setDepthMask(flag != GL_FALSE); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3585 | } |
| 3586 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3587 | void Context::depthRangef(GLfloat zNear, GLfloat zFar) |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3588 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3589 | mGLState.setDepthRange(zNear, zFar); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3590 | } |
| 3591 | |
| 3592 | void Context::disable(GLenum cap) |
| 3593 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3594 | mGLState.setEnableFeature(cap, false); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3595 | } |
| 3596 | |
| 3597 | void Context::disableVertexAttribArray(GLuint index) |
| 3598 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3599 | mGLState.setEnableVertexAttribArray(index, false); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3600 | } |
| 3601 | |
| 3602 | void Context::enable(GLenum cap) |
| 3603 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3604 | mGLState.setEnableFeature(cap, true); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3605 | } |
| 3606 | |
| 3607 | void Context::enableVertexAttribArray(GLuint index) |
| 3608 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3609 | mGLState.setEnableVertexAttribArray(index, true); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3610 | } |
| 3611 | |
| 3612 | void Context::frontFace(GLenum mode) |
| 3613 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3614 | mGLState.setFrontFace(mode); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3615 | } |
| 3616 | |
| 3617 | void Context::hint(GLenum target, GLenum mode) |
| 3618 | { |
| 3619 | switch (target) |
| 3620 | { |
| 3621 | case GL_GENERATE_MIPMAP_HINT: |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3622 | mGLState.setGenerateMipmapHint(mode); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3623 | break; |
| 3624 | |
| 3625 | case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3626 | mGLState.setFragmentShaderDerivativeHint(mode); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3627 | break; |
| 3628 | |
| 3629 | default: |
| 3630 | UNREACHABLE(); |
| 3631 | return; |
| 3632 | } |
| 3633 | } |
| 3634 | |
| 3635 | void Context::lineWidth(GLfloat width) |
| 3636 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3637 | mGLState.setLineWidth(width); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3638 | } |
| 3639 | |
| 3640 | void Context::pixelStorei(GLenum pname, GLint param) |
| 3641 | { |
| 3642 | switch (pname) |
| 3643 | { |
| 3644 | case GL_UNPACK_ALIGNMENT: |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3645 | mGLState.setUnpackAlignment(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3646 | break; |
| 3647 | |
| 3648 | case GL_PACK_ALIGNMENT: |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3649 | mGLState.setPackAlignment(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3650 | break; |
| 3651 | |
| 3652 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3653 | mGLState.setPackReverseRowOrder(param != 0); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3654 | break; |
| 3655 | |
| 3656 | case GL_UNPACK_ROW_LENGTH: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3657 | ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3658 | mGLState.setUnpackRowLength(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3659 | break; |
| 3660 | |
| 3661 | case GL_UNPACK_IMAGE_HEIGHT: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3662 | ASSERT(getClientMajorVersion() >= 3); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3663 | mGLState.setUnpackImageHeight(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3664 | break; |
| 3665 | |
| 3666 | case GL_UNPACK_SKIP_IMAGES: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3667 | ASSERT(getClientMajorVersion() >= 3); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3668 | mGLState.setUnpackSkipImages(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3669 | break; |
| 3670 | |
| 3671 | case GL_UNPACK_SKIP_ROWS: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3672 | ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3673 | mGLState.setUnpackSkipRows(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3674 | break; |
| 3675 | |
| 3676 | case GL_UNPACK_SKIP_PIXELS: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3677 | ASSERT((getClientMajorVersion() >= 3) || getExtensions().unpackSubimage); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3678 | mGLState.setUnpackSkipPixels(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3679 | break; |
| 3680 | |
| 3681 | case GL_PACK_ROW_LENGTH: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3682 | ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3683 | mGLState.setPackRowLength(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3684 | break; |
| 3685 | |
| 3686 | case GL_PACK_SKIP_ROWS: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3687 | ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3688 | mGLState.setPackSkipRows(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3689 | break; |
| 3690 | |
| 3691 | case GL_PACK_SKIP_PIXELS: |
Martin Radev | 1be913c | 2016-07-11 17:59:16 +0300 | [diff] [blame] | 3692 | ASSERT((getClientMajorVersion() >= 3) || getExtensions().packSubimage); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3693 | mGLState.setPackSkipPixels(param); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3694 | break; |
| 3695 | |
| 3696 | default: |
| 3697 | UNREACHABLE(); |
| 3698 | return; |
| 3699 | } |
| 3700 | } |
| 3701 | |
| 3702 | void Context::polygonOffset(GLfloat factor, GLfloat units) |
| 3703 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3704 | mGLState.setPolygonOffsetParams(factor, units); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3705 | } |
| 3706 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3707 | void Context::sampleCoverage(GLfloat value, GLboolean invert) |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3708 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3709 | mGLState.setSampleCoverageParams(clamp01(value), invert == GL_TRUE); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3710 | } |
| 3711 | |
| 3712 | void Context::scissor(GLint x, GLint y, GLsizei width, GLsizei height) |
| 3713 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3714 | mGLState.setScissorParams(x, y, width, height); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3715 | } |
| 3716 | |
| 3717 | void Context::stencilFuncSeparate(GLenum face, GLenum func, GLint ref, GLuint mask) |
| 3718 | { |
| 3719 | if (face == GL_FRONT || face == GL_FRONT_AND_BACK) |
| 3720 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3721 | mGLState.setStencilParams(func, ref, mask); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3722 | } |
| 3723 | |
| 3724 | if (face == GL_BACK || face == GL_FRONT_AND_BACK) |
| 3725 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3726 | mGLState.setStencilBackParams(func, ref, mask); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3727 | } |
| 3728 | } |
| 3729 | |
| 3730 | void Context::stencilMaskSeparate(GLenum face, GLuint mask) |
| 3731 | { |
| 3732 | if (face == GL_FRONT || face == GL_FRONT_AND_BACK) |
| 3733 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3734 | mGLState.setStencilWritemask(mask); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3735 | } |
| 3736 | |
| 3737 | if (face == GL_BACK || face == GL_FRONT_AND_BACK) |
| 3738 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3739 | mGLState.setStencilBackWritemask(mask); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3740 | } |
| 3741 | } |
| 3742 | |
| 3743 | void Context::stencilOpSeparate(GLenum face, GLenum fail, GLenum zfail, GLenum zpass) |
| 3744 | { |
| 3745 | if (face == GL_FRONT || face == GL_FRONT_AND_BACK) |
| 3746 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3747 | mGLState.setStencilOperations(fail, zfail, zpass); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3748 | } |
| 3749 | |
| 3750 | if (face == GL_BACK || face == GL_FRONT_AND_BACK) |
| 3751 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3752 | mGLState.setStencilBackOperations(fail, zfail, zpass); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3753 | } |
| 3754 | } |
| 3755 | |
| 3756 | void Context::vertexAttrib1f(GLuint index, GLfloat x) |
| 3757 | { |
| 3758 | GLfloat vals[4] = {x, 0, 0, 1}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3759 | mGLState.setVertexAttribf(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3760 | } |
| 3761 | |
| 3762 | void Context::vertexAttrib1fv(GLuint index, const GLfloat *values) |
| 3763 | { |
| 3764 | GLfloat vals[4] = {values[0], 0, 0, 1}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3765 | mGLState.setVertexAttribf(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3766 | } |
| 3767 | |
| 3768 | void Context::vertexAttrib2f(GLuint index, GLfloat x, GLfloat y) |
| 3769 | { |
| 3770 | GLfloat vals[4] = {x, y, 0, 1}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3771 | mGLState.setVertexAttribf(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3772 | } |
| 3773 | |
| 3774 | void Context::vertexAttrib2fv(GLuint index, const GLfloat *values) |
| 3775 | { |
| 3776 | GLfloat vals[4] = {values[0], values[1], 0, 1}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3777 | mGLState.setVertexAttribf(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3778 | } |
| 3779 | |
| 3780 | void Context::vertexAttrib3f(GLuint index, GLfloat x, GLfloat y, GLfloat z) |
| 3781 | { |
| 3782 | GLfloat vals[4] = {x, y, z, 1}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3783 | mGLState.setVertexAttribf(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3784 | } |
| 3785 | |
| 3786 | void Context::vertexAttrib3fv(GLuint index, const GLfloat *values) |
| 3787 | { |
| 3788 | GLfloat vals[4] = {values[0], values[1], values[2], 1}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3789 | mGLState.setVertexAttribf(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3790 | } |
| 3791 | |
| 3792 | void Context::vertexAttrib4f(GLuint index, GLfloat x, GLfloat y, GLfloat z, GLfloat w) |
| 3793 | { |
| 3794 | GLfloat vals[4] = {x, y, z, w}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3795 | mGLState.setVertexAttribf(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3796 | } |
| 3797 | |
| 3798 | void Context::vertexAttrib4fv(GLuint index, const GLfloat *values) |
| 3799 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3800 | mGLState.setVertexAttribf(index, values); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3801 | } |
| 3802 | |
| 3803 | void Context::vertexAttribPointer(GLuint index, |
| 3804 | GLint size, |
| 3805 | GLenum type, |
| 3806 | GLboolean normalized, |
| 3807 | GLsizei stride, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3808 | const void *ptr) |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3809 | { |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 3810 | mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size, |
| 3811 | type, normalized == GL_TRUE, false, stride, ptr); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3812 | } |
| 3813 | |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 3814 | void Context::vertexAttribFormat(GLuint attribIndex, |
| 3815 | GLint size, |
| 3816 | GLenum type, |
| 3817 | GLboolean normalized, |
| 3818 | GLuint relativeOffset) |
| 3819 | { |
| 3820 | mGLState.setVertexAttribFormat(attribIndex, size, type, normalized == GL_TRUE, false, |
| 3821 | relativeOffset); |
| 3822 | } |
| 3823 | |
| 3824 | void Context::vertexAttribIFormat(GLuint attribIndex, |
| 3825 | GLint size, |
| 3826 | GLenum type, |
| 3827 | GLuint relativeOffset) |
| 3828 | { |
| 3829 | mGLState.setVertexAttribFormat(attribIndex, size, type, false, true, relativeOffset); |
| 3830 | } |
| 3831 | |
| 3832 | void Context::vertexAttribBinding(GLuint attribIndex, GLuint bindingIndex) |
| 3833 | { |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 3834 | mGLState.setVertexAttribBinding(this, attribIndex, bindingIndex); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 3835 | } |
| 3836 | |
| 3837 | void Context::setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor) |
| 3838 | { |
| 3839 | mGLState.setVertexBindingDivisor(bindingIndex, divisor); |
| 3840 | } |
| 3841 | |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3842 | void Context::viewport(GLint x, GLint y, GLsizei width, GLsizei height) |
| 3843 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3844 | mGLState.setViewportParams(x, y, width, height); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3845 | } |
| 3846 | |
| 3847 | void Context::vertexAttribIPointer(GLuint index, |
| 3848 | GLint size, |
| 3849 | GLenum type, |
| 3850 | GLsizei stride, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3851 | const void *pointer) |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3852 | { |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 3853 | mGLState.setVertexAttribPointer(this, index, mGLState.getTargetBuffer(GL_ARRAY_BUFFER), size, |
| 3854 | type, false, true, stride, pointer); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3855 | } |
| 3856 | |
| 3857 | void Context::vertexAttribI4i(GLuint index, GLint x, GLint y, GLint z, GLint w) |
| 3858 | { |
| 3859 | GLint vals[4] = {x, y, z, w}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3860 | mGLState.setVertexAttribi(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3861 | } |
| 3862 | |
| 3863 | void Context::vertexAttribI4ui(GLuint index, GLuint x, GLuint y, GLuint z, GLuint w) |
| 3864 | { |
| 3865 | GLuint vals[4] = {x, y, z, w}; |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3866 | mGLState.setVertexAttribu(index, vals); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3867 | } |
| 3868 | |
| 3869 | void Context::vertexAttribI4iv(GLuint index, const GLint *v) |
| 3870 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3871 | mGLState.setVertexAttribi(index, v); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3872 | } |
| 3873 | |
| 3874 | void Context::vertexAttribI4uiv(GLuint index, const GLuint *v) |
| 3875 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3876 | mGLState.setVertexAttribu(index, v); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3877 | } |
| 3878 | |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 3879 | void Context::getVertexAttribiv(GLuint index, GLenum pname, GLint *params) |
| 3880 | { |
| 3881 | const VertexAttribCurrentValueData ¤tValues = |
| 3882 | getGLState().getVertexAttribCurrentValue(index); |
| 3883 | const VertexArray *vao = getGLState().getVertexArray(); |
| 3884 | QueryVertexAttribiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index), |
| 3885 | currentValues, pname, params); |
| 3886 | } |
| 3887 | |
| 3888 | void Context::getVertexAttribfv(GLuint index, GLenum pname, GLfloat *params) |
| 3889 | { |
| 3890 | const VertexAttribCurrentValueData ¤tValues = |
| 3891 | getGLState().getVertexAttribCurrentValue(index); |
| 3892 | const VertexArray *vao = getGLState().getVertexArray(); |
| 3893 | QueryVertexAttribfv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index), |
| 3894 | currentValues, pname, params); |
| 3895 | } |
| 3896 | |
| 3897 | void Context::getVertexAttribIiv(GLuint index, GLenum pname, GLint *params) |
| 3898 | { |
| 3899 | const VertexAttribCurrentValueData ¤tValues = |
| 3900 | getGLState().getVertexAttribCurrentValue(index); |
| 3901 | const VertexArray *vao = getGLState().getVertexArray(); |
| 3902 | QueryVertexAttribIiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index), |
| 3903 | currentValues, pname, params); |
| 3904 | } |
| 3905 | |
| 3906 | void Context::getVertexAttribIuiv(GLuint index, GLenum pname, GLuint *params) |
| 3907 | { |
| 3908 | const VertexAttribCurrentValueData ¤tValues = |
| 3909 | getGLState().getVertexAttribCurrentValue(index); |
| 3910 | const VertexArray *vao = getGLState().getVertexArray(); |
| 3911 | QueryVertexAttribIuiv(vao->getVertexAttribute(index), vao->getBindingFromAttribIndex(index), |
| 3912 | currentValues, pname, params); |
| 3913 | } |
| 3914 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3915 | void Context::getVertexAttribPointerv(GLuint index, GLenum pname, void **pointer) |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 3916 | { |
| 3917 | const VertexAttribute &attrib = getGLState().getVertexArray()->getVertexAttribute(index); |
| 3918 | QueryVertexAttribPointerv(attrib, pname, pointer); |
| 3919 | } |
| 3920 | |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3921 | void Context::debugMessageControl(GLenum source, |
| 3922 | GLenum type, |
| 3923 | GLenum severity, |
| 3924 | GLsizei count, |
| 3925 | const GLuint *ids, |
| 3926 | GLboolean enabled) |
| 3927 | { |
| 3928 | std::vector<GLuint> idVector(ids, ids + count); |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3929 | mGLState.getDebug().setMessageControl(source, type, severity, std::move(idVector), |
| 3930 | (enabled != GL_FALSE)); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3931 | } |
| 3932 | |
| 3933 | void Context::debugMessageInsert(GLenum source, |
| 3934 | GLenum type, |
| 3935 | GLuint id, |
| 3936 | GLenum severity, |
| 3937 | GLsizei length, |
| 3938 | const GLchar *buf) |
| 3939 | { |
| 3940 | 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] | 3941 | mGLState.getDebug().insertMessage(source, type, id, severity, std::move(msg)); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3942 | } |
| 3943 | |
| 3944 | void Context::debugMessageCallback(GLDEBUGPROCKHR callback, const void *userParam) |
| 3945 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3946 | mGLState.getDebug().setCallback(callback, userParam); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3947 | } |
| 3948 | |
| 3949 | GLuint Context::getDebugMessageLog(GLuint count, |
| 3950 | GLsizei bufSize, |
| 3951 | GLenum *sources, |
| 3952 | GLenum *types, |
| 3953 | GLuint *ids, |
| 3954 | GLenum *severities, |
| 3955 | GLsizei *lengths, |
| 3956 | GLchar *messageLog) |
| 3957 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3958 | return static_cast<GLuint>(mGLState.getDebug().getMessages(count, bufSize, sources, types, ids, |
| 3959 | severities, lengths, messageLog)); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3960 | } |
| 3961 | |
| 3962 | void Context::pushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar *message) |
| 3963 | { |
| 3964 | 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] | 3965 | mGLState.getDebug().pushGroup(source, id, std::move(msg)); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3966 | } |
| 3967 | |
| 3968 | void Context::popDebugGroup() |
| 3969 | { |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 3970 | mGLState.getDebug().popGroup(); |
Jamie Madill | c20ab27 | 2016-06-09 07:20:46 -0700 | [diff] [blame] | 3971 | } |
| 3972 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3973 | void Context::bufferData(GLenum target, GLsizeiptr size, const void *data, GLenum usage) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 3974 | { |
| 3975 | Buffer *buffer = mGLState.getTargetBuffer(target); |
| 3976 | ASSERT(buffer); |
Jamie Madill | b8353b0 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 3977 | handleError(buffer->bufferData(this, target, data, size, usage)); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 3978 | } |
| 3979 | |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 3980 | void Context::bufferSubData(GLenum target, GLintptr offset, GLsizeiptr size, const void *data) |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 3981 | { |
| 3982 | if (data == nullptr) |
| 3983 | { |
| 3984 | return; |
| 3985 | } |
| 3986 | |
| 3987 | Buffer *buffer = mGLState.getTargetBuffer(target); |
| 3988 | ASSERT(buffer); |
Jamie Madill | b8353b0 | 2017-01-25 12:57:21 -0800 | [diff] [blame] | 3989 | handleError(buffer->bufferSubData(this, target, data, size, offset)); |
Jamie Madill | 2963985 | 2016-09-02 15:00:09 -0400 | [diff] [blame] | 3990 | } |
| 3991 | |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 3992 | void Context::attachShader(GLuint program, GLuint shader) |
| 3993 | { |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 3994 | auto programObject = mState.mShaderPrograms->getProgram(program); |
| 3995 | auto shaderObject = mState.mShaderPrograms->getShader(shader); |
Jamie Madill | ef300b1 | 2016-10-07 15:12:09 -0400 | [diff] [blame] | 3996 | ASSERT(programObject && shaderObject); |
| 3997 | programObject->attachShader(shaderObject); |
| 3998 | } |
| 3999 | |
Kenneth Russell | f2f6f65 | 2016-10-05 19:53:23 -0700 | [diff] [blame] | 4000 | const Workarounds &Context::getWorkarounds() const |
| 4001 | { |
| 4002 | return mWorkarounds; |
| 4003 | } |
| 4004 | |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 4005 | void Context::copyBufferSubData(GLenum readTarget, |
| 4006 | GLenum writeTarget, |
| 4007 | GLintptr readOffset, |
| 4008 | GLintptr writeOffset, |
| 4009 | GLsizeiptr size) |
| 4010 | { |
| 4011 | // if size is zero, the copy is a successful no-op |
| 4012 | if (size == 0) |
| 4013 | { |
| 4014 | return; |
| 4015 | } |
| 4016 | |
| 4017 | // TODO(jmadill): cache these. |
| 4018 | Buffer *readBuffer = mGLState.getTargetBuffer(readTarget); |
| 4019 | Buffer *writeBuffer = mGLState.getTargetBuffer(writeTarget); |
| 4020 | |
Jamie Madill | 5f56ddb | 2017-01-13 17:29:55 -0500 | [diff] [blame] | 4021 | handleError(writeBuffer->copyBufferSubData(this, readBuffer, readOffset, writeOffset, size)); |
Jamie Madill | b0817d1 | 2016-11-01 15:48:31 -0400 | [diff] [blame] | 4022 | } |
| 4023 | |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4024 | void Context::bindAttribLocation(GLuint program, GLuint index, const GLchar *name) |
| 4025 | { |
| 4026 | Program *programObject = getProgram(program); |
| 4027 | // TODO(jmadill): Re-use this from the validation if possible. |
| 4028 | ASSERT(programObject); |
| 4029 | programObject->bindAttributeLocation(index, name); |
| 4030 | } |
| 4031 | |
| 4032 | void Context::bindBuffer(GLenum target, GLuint buffer) |
| 4033 | { |
| 4034 | switch (target) |
| 4035 | { |
| 4036 | case GL_ARRAY_BUFFER: |
| 4037 | bindArrayBuffer(buffer); |
| 4038 | break; |
| 4039 | case GL_ELEMENT_ARRAY_BUFFER: |
| 4040 | bindElementArrayBuffer(buffer); |
| 4041 | break; |
| 4042 | case GL_COPY_READ_BUFFER: |
| 4043 | bindCopyReadBuffer(buffer); |
| 4044 | break; |
| 4045 | case GL_COPY_WRITE_BUFFER: |
| 4046 | bindCopyWriteBuffer(buffer); |
| 4047 | break; |
| 4048 | case GL_PIXEL_PACK_BUFFER: |
| 4049 | bindPixelPackBuffer(buffer); |
| 4050 | break; |
| 4051 | case GL_PIXEL_UNPACK_BUFFER: |
| 4052 | bindPixelUnpackBuffer(buffer); |
| 4053 | break; |
| 4054 | case GL_UNIFORM_BUFFER: |
| 4055 | bindGenericUniformBuffer(buffer); |
| 4056 | break; |
| 4057 | case GL_TRANSFORM_FEEDBACK_BUFFER: |
| 4058 | bindGenericTransformFeedbackBuffer(buffer); |
| 4059 | break; |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 4060 | case GL_ATOMIC_COUNTER_BUFFER: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 4061 | bindGenericAtomicCounterBuffer(buffer); |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 4062 | break; |
| 4063 | case GL_SHADER_STORAGE_BUFFER: |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 4064 | bindGenericShaderStorageBuffer(buffer); |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 4065 | break; |
| 4066 | case GL_DRAW_INDIRECT_BUFFER: |
Jiajia Qin | 9d7d0b1 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 4067 | bindDrawIndirectBuffer(buffer); |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 4068 | break; |
| 4069 | case GL_DISPATCH_INDIRECT_BUFFER: |
Geoff Lang | 9f09037 | 2016-12-02 10:20:43 -0500 | [diff] [blame] | 4070 | if (buffer != 0) |
| 4071 | { |
| 4072 | // Binding buffers to this binding point is not implemented yet. |
| 4073 | UNIMPLEMENTED(); |
| 4074 | } |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 4075 | break; |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4076 | |
| 4077 | default: |
| 4078 | UNREACHABLE(); |
| 4079 | break; |
| 4080 | } |
| 4081 | } |
| 4082 | |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 4083 | void Context::bindBufferBase(GLenum target, GLuint index, GLuint buffer) |
| 4084 | { |
| 4085 | bindBufferRange(target, index, buffer, 0, 0); |
| 4086 | } |
| 4087 | |
| 4088 | void Context::bindBufferRange(GLenum target, |
| 4089 | GLuint index, |
| 4090 | GLuint buffer, |
| 4091 | GLintptr offset, |
| 4092 | GLsizeiptr size) |
| 4093 | { |
| 4094 | switch (target) |
| 4095 | { |
| 4096 | case GL_TRANSFORM_FEEDBACK_BUFFER: |
| 4097 | bindIndexedTransformFeedbackBuffer(buffer, index, offset, size); |
| 4098 | bindGenericTransformFeedbackBuffer(buffer); |
| 4099 | break; |
| 4100 | case GL_UNIFORM_BUFFER: |
| 4101 | bindIndexedUniformBuffer(buffer, index, offset, size); |
| 4102 | bindGenericUniformBuffer(buffer); |
| 4103 | break; |
| 4104 | case GL_ATOMIC_COUNTER_BUFFER: |
| 4105 | bindIndexedAtomicCounterBuffer(buffer, index, offset, size); |
| 4106 | bindGenericAtomicCounterBuffer(buffer); |
| 4107 | break; |
| 4108 | case GL_SHADER_STORAGE_BUFFER: |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 4109 | bindIndexedShaderStorageBuffer(buffer, index, offset, size); |
| 4110 | bindGenericShaderStorageBuffer(buffer); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 4111 | break; |
| 4112 | default: |
| 4113 | UNREACHABLE(); |
| 4114 | break; |
| 4115 | } |
| 4116 | } |
| 4117 | |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4118 | void Context::bindFramebuffer(GLenum target, GLuint framebuffer) |
| 4119 | { |
| 4120 | if (target == GL_READ_FRAMEBUFFER || target == GL_FRAMEBUFFER) |
| 4121 | { |
| 4122 | bindReadFramebuffer(framebuffer); |
| 4123 | } |
| 4124 | |
| 4125 | if (target == GL_DRAW_FRAMEBUFFER || target == GL_FRAMEBUFFER) |
| 4126 | { |
| 4127 | bindDrawFramebuffer(framebuffer); |
| 4128 | } |
| 4129 | } |
| 4130 | |
| 4131 | void Context::bindRenderbuffer(GLenum target, GLuint renderbuffer) |
| 4132 | { |
| 4133 | ASSERT(target == GL_RENDERBUFFER); |
| 4134 | Renderbuffer *object = |
Geoff Lang | 4ddf5af | 2016-12-01 14:30:44 -0500 | [diff] [blame] | 4135 | mState.mRenderbuffers->checkRenderbufferAllocation(mImplementation.get(), renderbuffer); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 4136 | mGLState.setRenderbufferBinding(this, object); |
Jamie Madill | 01a80ee | 2016-11-07 12:06:18 -0500 | [diff] [blame] | 4137 | } |
| 4138 | |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 4139 | void Context::texStorage2DMultisample(GLenum target, |
| 4140 | GLsizei samples, |
| 4141 | GLenum internalformat, |
| 4142 | GLsizei width, |
| 4143 | GLsizei height, |
| 4144 | GLboolean fixedsamplelocations) |
| 4145 | { |
| 4146 | Extents size(width, height, 1); |
| 4147 | Texture *texture = getTargetTexture(target); |
Jamie Madill | 8897afa | 2017-02-06 17:17:23 -0500 | [diff] [blame] | 4148 | handleError(texture->setStorageMultisample(this, target, samples, internalformat, size, |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 4149 | fixedsamplelocations)); |
| 4150 | } |
| 4151 | |
| 4152 | void Context::getMultisamplefv(GLenum pname, GLuint index, GLfloat *val) |
| 4153 | { |
JiangYizhou | 5b03f47 | 2017-01-09 10:22:53 +0800 | [diff] [blame] | 4154 | // According to spec 3.1 Table 20.49: Framebuffer Dependent Values, |
| 4155 | // the sample position should be queried by DRAW_FRAMEBUFFER. |
| 4156 | mGLState.syncDirtyObject(this, GL_DRAW_FRAMEBUFFER); |
| 4157 | const Framebuffer *framebuffer = mGLState.getDrawFramebuffer(); |
JiangYizhou | bddc46b | 2016-12-09 09:50:51 +0800 | [diff] [blame] | 4158 | |
| 4159 | switch (pname) |
| 4160 | { |
| 4161 | case GL_SAMPLE_POSITION: |
| 4162 | handleError(framebuffer->getSamplePosition(index, val)); |
| 4163 | break; |
| 4164 | default: |
| 4165 | UNREACHABLE(); |
| 4166 | } |
| 4167 | } |
| 4168 | |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4169 | void Context::renderbufferStorage(GLenum target, |
| 4170 | GLenum internalformat, |
| 4171 | GLsizei width, |
| 4172 | GLsizei height) |
| 4173 | { |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 4174 | // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format. |
| 4175 | GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat); |
| 4176 | |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4177 | Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer(); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 4178 | handleError(renderbuffer->setStorage(this, convertedInternalFormat, width, height)); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4179 | } |
| 4180 | |
| 4181 | void Context::renderbufferStorageMultisample(GLenum target, |
| 4182 | GLsizei samples, |
| 4183 | GLenum internalformat, |
| 4184 | GLsizei width, |
| 4185 | GLsizei height) |
| 4186 | { |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 4187 | // Hack for the special WebGL 1 "DEPTH_STENCIL" internal format. |
| 4188 | GLenum convertedInternalFormat = getConvertedRenderbufferFormat(internalformat); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4189 | |
| 4190 | Renderbuffer *renderbuffer = mGLState.getCurrentRenderbuffer(); |
Jamie Madill | 4e0e6f8 | 2017-02-17 11:06:03 -0500 | [diff] [blame] | 4191 | handleError( |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 4192 | renderbuffer->setStorageMultisample(this, samples, convertedInternalFormat, width, height)); |
Jamie Madill | e8fb640 | 2017-02-14 17:56:40 -0500 | [diff] [blame] | 4193 | } |
| 4194 | |
Geoff Lang | 38f2cfb | 2017-04-11 15:23:08 -0400 | [diff] [blame] | 4195 | void Context::getSynciv(GLsync sync, GLenum pname, GLsizei bufSize, GLsizei *length, GLint *values) |
| 4196 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 4197 | const Sync *syncObject = getSync(sync); |
Geoff Lang | 82483b9 | 2017-04-11 15:33:00 -0400 | [diff] [blame] | 4198 | handleError(QuerySynciv(syncObject, pname, bufSize, length, values)); |
Geoff Lang | 38f2cfb | 2017-04-11 15:23:08 -0400 | [diff] [blame] | 4199 | } |
| 4200 | |
JiangYizhou | e18e639 | 2017-02-20 10:32:23 +0800 | [diff] [blame] | 4201 | void Context::getFramebufferParameteriv(GLenum target, GLenum pname, GLint *params) |
| 4202 | { |
| 4203 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
| 4204 | QueryFramebufferParameteriv(framebuffer, pname, params); |
| 4205 | } |
| 4206 | |
| 4207 | void Context::setFramebufferParameteri(GLenum target, GLenum pname, GLint param) |
| 4208 | { |
| 4209 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
| 4210 | SetFramebufferParameteri(framebuffer, pname, param); |
| 4211 | } |
| 4212 | |
Jamie Madill | b3f26b9 | 2017-07-19 15:07:41 -0400 | [diff] [blame] | 4213 | Error Context::getScratchBuffer(size_t requstedSizeBytes, |
| 4214 | angle::MemoryBuffer **scratchBufferOut) const |
Jamie Madill | e14951e | 2017-03-09 18:55:16 -0500 | [diff] [blame] | 4215 | { |
Jamie Madill | b3f26b9 | 2017-07-19 15:07:41 -0400 | [diff] [blame] | 4216 | if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut)) |
| 4217 | { |
| 4218 | return OutOfMemory() << "Failed to allocate internal buffer."; |
| 4219 | } |
| 4220 | return NoError(); |
| 4221 | } |
| 4222 | |
| 4223 | Error Context::getZeroFilledBuffer(size_t requstedSizeBytes, |
| 4224 | angle::MemoryBuffer **zeroBufferOut) const |
| 4225 | { |
| 4226 | if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0)) |
Jamie Madill | e14951e | 2017-03-09 18:55:16 -0500 | [diff] [blame] | 4227 | { |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4228 | return OutOfMemory() << "Failed to allocate internal buffer."; |
Jamie Madill | e14951e | 2017-03-09 18:55:16 -0500 | [diff] [blame] | 4229 | } |
Yuly Novikov | c4d18aa | 2017-03-09 18:45:02 -0500 | [diff] [blame] | 4230 | return NoError(); |
Jamie Madill | e14951e | 2017-03-09 18:55:16 -0500 | [diff] [blame] | 4231 | } |
| 4232 | |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 4233 | void Context::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ) |
| 4234 | { |
| 4235 | if (numGroupsX == 0u || numGroupsY == 0u || numGroupsZ == 0u) |
| 4236 | { |
| 4237 | return; |
| 4238 | } |
| 4239 | |
Jamie Madill | 71c88b3 | 2017-09-14 22:20:29 -0400 | [diff] [blame] | 4240 | handleError(mImplementation->dispatchCompute(this, numGroupsX, numGroupsY, numGroupsZ)); |
Xinghua Cao | 2b39659 | 2017-03-29 15:36:04 +0800 | [diff] [blame] | 4241 | } |
| 4242 | |
JiangYizhou | 165361c | 2017-06-07 14:56:57 +0800 | [diff] [blame] | 4243 | void Context::texStorage2D(GLenum target, |
| 4244 | GLsizei levels, |
| 4245 | GLenum internalFormat, |
| 4246 | GLsizei width, |
| 4247 | GLsizei height) |
| 4248 | { |
| 4249 | Extents size(width, height, 1); |
| 4250 | Texture *texture = getTargetTexture(target); |
| 4251 | handleError(texture->setStorage(this, target, levels, internalFormat, size)); |
| 4252 | } |
| 4253 | |
| 4254 | void Context::texStorage3D(GLenum target, |
| 4255 | GLsizei levels, |
| 4256 | GLenum internalFormat, |
| 4257 | GLsizei width, |
| 4258 | GLsizei height, |
| 4259 | GLsizei depth) |
| 4260 | { |
| 4261 | Extents size(width, height, depth); |
| 4262 | Texture *texture = getTargetTexture(target); |
| 4263 | handleError(texture->setStorage(this, target, levels, internalFormat, size)); |
| 4264 | } |
| 4265 | |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4266 | GLenum Context::checkFramebufferStatus(GLenum target) |
| 4267 | { |
| 4268 | Framebuffer *framebuffer = mGLState.getTargetFramebuffer(target); |
| 4269 | ASSERT(framebuffer); |
| 4270 | |
| 4271 | return framebuffer->checkStatus(this); |
| 4272 | } |
| 4273 | |
| 4274 | void Context::compileShader(GLuint shader) |
| 4275 | { |
| 4276 | Shader *shaderObject = GetValidShader(this, shader); |
| 4277 | if (!shaderObject) |
| 4278 | { |
| 4279 | return; |
| 4280 | } |
| 4281 | shaderObject->compile(this); |
| 4282 | } |
| 4283 | |
| 4284 | void Context::deleteBuffers(GLsizei n, const GLuint *buffers) |
| 4285 | { |
| 4286 | for (int i = 0; i < n; i++) |
| 4287 | { |
| 4288 | deleteBuffer(buffers[i]); |
| 4289 | } |
| 4290 | } |
| 4291 | |
| 4292 | void Context::deleteFramebuffers(GLsizei n, const GLuint *framebuffers) |
| 4293 | { |
| 4294 | for (int i = 0; i < n; i++) |
| 4295 | { |
| 4296 | if (framebuffers[i] != 0) |
| 4297 | { |
| 4298 | deleteFramebuffer(framebuffers[i]); |
| 4299 | } |
| 4300 | } |
| 4301 | } |
| 4302 | |
| 4303 | void Context::deleteRenderbuffers(GLsizei n, const GLuint *renderbuffers) |
| 4304 | { |
| 4305 | for (int i = 0; i < n; i++) |
| 4306 | { |
| 4307 | deleteRenderbuffer(renderbuffers[i]); |
| 4308 | } |
| 4309 | } |
| 4310 | |
| 4311 | void Context::deleteTextures(GLsizei n, const GLuint *textures) |
| 4312 | { |
| 4313 | for (int i = 0; i < n; i++) |
| 4314 | { |
| 4315 | if (textures[i] != 0) |
| 4316 | { |
| 4317 | deleteTexture(textures[i]); |
| 4318 | } |
| 4319 | } |
| 4320 | } |
| 4321 | |
| 4322 | void Context::detachShader(GLuint program, GLuint shader) |
| 4323 | { |
| 4324 | Program *programObject = getProgram(program); |
| 4325 | ASSERT(programObject); |
| 4326 | |
| 4327 | Shader *shaderObject = getShader(shader); |
| 4328 | ASSERT(shaderObject); |
| 4329 | |
| 4330 | programObject->detachShader(this, shaderObject); |
| 4331 | } |
| 4332 | |
| 4333 | void Context::genBuffers(GLsizei n, GLuint *buffers) |
| 4334 | { |
| 4335 | for (int i = 0; i < n; i++) |
| 4336 | { |
| 4337 | buffers[i] = createBuffer(); |
| 4338 | } |
| 4339 | } |
| 4340 | |
| 4341 | void Context::genFramebuffers(GLsizei n, GLuint *framebuffers) |
| 4342 | { |
| 4343 | for (int i = 0; i < n; i++) |
| 4344 | { |
| 4345 | framebuffers[i] = createFramebuffer(); |
| 4346 | } |
| 4347 | } |
| 4348 | |
| 4349 | void Context::genRenderbuffers(GLsizei n, GLuint *renderbuffers) |
| 4350 | { |
| 4351 | for (int i = 0; i < n; i++) |
| 4352 | { |
| 4353 | renderbuffers[i] = createRenderbuffer(); |
| 4354 | } |
| 4355 | } |
| 4356 | |
| 4357 | void Context::genTextures(GLsizei n, GLuint *textures) |
| 4358 | { |
| 4359 | for (int i = 0; i < n; i++) |
| 4360 | { |
| 4361 | textures[i] = createTexture(); |
| 4362 | } |
| 4363 | } |
| 4364 | |
| 4365 | void Context::getActiveAttrib(GLuint program, |
| 4366 | GLuint index, |
| 4367 | GLsizei bufsize, |
| 4368 | GLsizei *length, |
| 4369 | GLint *size, |
| 4370 | GLenum *type, |
| 4371 | GLchar *name) |
| 4372 | { |
| 4373 | Program *programObject = getProgram(program); |
| 4374 | ASSERT(programObject); |
| 4375 | programObject->getActiveAttribute(index, bufsize, length, size, type, name); |
| 4376 | } |
| 4377 | |
| 4378 | void Context::getActiveUniform(GLuint program, |
| 4379 | GLuint index, |
| 4380 | GLsizei bufsize, |
| 4381 | GLsizei *length, |
| 4382 | GLint *size, |
| 4383 | GLenum *type, |
| 4384 | GLchar *name) |
| 4385 | { |
| 4386 | Program *programObject = getProgram(program); |
| 4387 | ASSERT(programObject); |
| 4388 | programObject->getActiveUniform(index, bufsize, length, size, type, name); |
| 4389 | } |
| 4390 | |
| 4391 | void Context::getAttachedShaders(GLuint program, GLsizei maxcount, GLsizei *count, GLuint *shaders) |
| 4392 | { |
| 4393 | Program *programObject = getProgram(program); |
| 4394 | ASSERT(programObject); |
| 4395 | programObject->getAttachedShaders(maxcount, count, shaders); |
| 4396 | } |
| 4397 | |
| 4398 | GLint Context::getAttribLocation(GLuint program, const GLchar *name) |
| 4399 | { |
| 4400 | Program *programObject = getProgram(program); |
| 4401 | ASSERT(programObject); |
| 4402 | return programObject->getAttributeLocation(name); |
| 4403 | } |
| 4404 | |
| 4405 | void Context::getBooleanv(GLenum pname, GLboolean *params) |
| 4406 | { |
| 4407 | GLenum nativeType; |
| 4408 | unsigned int numParams = 0; |
| 4409 | getQueryParameterInfo(pname, &nativeType, &numParams); |
| 4410 | |
| 4411 | if (nativeType == GL_BOOL) |
| 4412 | { |
| 4413 | getBooleanvImpl(pname, params); |
| 4414 | } |
| 4415 | else |
| 4416 | { |
| 4417 | CastStateValues(this, nativeType, pname, numParams, params); |
| 4418 | } |
| 4419 | } |
| 4420 | |
| 4421 | void Context::getFloatv(GLenum pname, GLfloat *params) |
| 4422 | { |
| 4423 | GLenum nativeType; |
| 4424 | unsigned int numParams = 0; |
| 4425 | getQueryParameterInfo(pname, &nativeType, &numParams); |
| 4426 | |
| 4427 | if (nativeType == GL_FLOAT) |
| 4428 | { |
| 4429 | getFloatvImpl(pname, params); |
| 4430 | } |
| 4431 | else |
| 4432 | { |
| 4433 | CastStateValues(this, nativeType, pname, numParams, params); |
| 4434 | } |
| 4435 | } |
| 4436 | |
| 4437 | void Context::getIntegerv(GLenum pname, GLint *params) |
| 4438 | { |
| 4439 | GLenum nativeType; |
| 4440 | unsigned int numParams = 0; |
| 4441 | getQueryParameterInfo(pname, &nativeType, &numParams); |
| 4442 | |
| 4443 | if (nativeType == GL_INT) |
| 4444 | { |
| 4445 | getIntegervImpl(pname, params); |
| 4446 | } |
| 4447 | else |
| 4448 | { |
| 4449 | CastStateValues(this, nativeType, pname, numParams, params); |
| 4450 | } |
| 4451 | } |
| 4452 | |
| 4453 | void Context::getProgramiv(GLuint program, GLenum pname, GLint *params) |
| 4454 | { |
| 4455 | Program *programObject = getProgram(program); |
| 4456 | ASSERT(programObject); |
Jamie Madill | ffe00c0 | 2017-06-27 16:26:55 -0400 | [diff] [blame] | 4457 | QueryProgramiv(this, programObject, pname, params); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4458 | } |
| 4459 | |
Jamie Madill | be849e4 | 2017-05-02 15:49:00 -0400 | [diff] [blame] | 4460 | void Context::getProgramInfoLog(GLuint program, GLsizei bufsize, GLsizei *length, GLchar *infolog) |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4461 | { |
| 4462 | Program *programObject = getProgram(program); |
| 4463 | ASSERT(programObject); |
| 4464 | programObject->getInfoLog(bufsize, length, infolog); |
| 4465 | } |
| 4466 | |
| 4467 | void Context::getShaderiv(GLuint shader, GLenum pname, GLint *params) |
| 4468 | { |
| 4469 | Shader *shaderObject = getShader(shader); |
| 4470 | ASSERT(shaderObject); |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 4471 | QueryShaderiv(this, shaderObject, pname, params); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4472 | } |
| 4473 | |
| 4474 | void Context::getShaderInfoLog(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *infolog) |
| 4475 | { |
| 4476 | Shader *shaderObject = getShader(shader); |
| 4477 | ASSERT(shaderObject); |
Jamie Madill | bd044ed | 2017-06-05 12:59:21 -0400 | [diff] [blame] | 4478 | shaderObject->getInfoLog(this, bufsize, length, infolog); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4479 | } |
| 4480 | |
| 4481 | void Context::getShaderPrecisionFormat(GLenum shadertype, |
| 4482 | GLenum precisiontype, |
| 4483 | GLint *range, |
| 4484 | GLint *precision) |
| 4485 | { |
| 4486 | // TODO(jmadill): Compute shaders. |
| 4487 | |
| 4488 | switch (shadertype) |
| 4489 | { |
| 4490 | case GL_VERTEX_SHADER: |
| 4491 | switch (precisiontype) |
| 4492 | { |
| 4493 | case GL_LOW_FLOAT: |
| 4494 | mCaps.vertexLowpFloat.get(range, precision); |
| 4495 | break; |
| 4496 | case GL_MEDIUM_FLOAT: |
| 4497 | mCaps.vertexMediumpFloat.get(range, precision); |
| 4498 | break; |
| 4499 | case GL_HIGH_FLOAT: |
| 4500 | mCaps.vertexHighpFloat.get(range, precision); |
| 4501 | break; |
| 4502 | |
| 4503 | case GL_LOW_INT: |
| 4504 | mCaps.vertexLowpInt.get(range, precision); |
| 4505 | break; |
| 4506 | case GL_MEDIUM_INT: |
| 4507 | mCaps.vertexMediumpInt.get(range, precision); |
| 4508 | break; |
| 4509 | case GL_HIGH_INT: |
| 4510 | mCaps.vertexHighpInt.get(range, precision); |
| 4511 | break; |
| 4512 | |
| 4513 | default: |
| 4514 | UNREACHABLE(); |
| 4515 | return; |
| 4516 | } |
| 4517 | break; |
| 4518 | |
| 4519 | case GL_FRAGMENT_SHADER: |
| 4520 | switch (precisiontype) |
| 4521 | { |
| 4522 | case GL_LOW_FLOAT: |
| 4523 | mCaps.fragmentLowpFloat.get(range, precision); |
| 4524 | break; |
| 4525 | case GL_MEDIUM_FLOAT: |
| 4526 | mCaps.fragmentMediumpFloat.get(range, precision); |
| 4527 | break; |
| 4528 | case GL_HIGH_FLOAT: |
| 4529 | mCaps.fragmentHighpFloat.get(range, precision); |
| 4530 | break; |
| 4531 | |
| 4532 | case GL_LOW_INT: |
| 4533 | mCaps.fragmentLowpInt.get(range, precision); |
| 4534 | break; |
| 4535 | case GL_MEDIUM_INT: |
| 4536 | mCaps.fragmentMediumpInt.get(range, precision); |
| 4537 | break; |
| 4538 | case GL_HIGH_INT: |
| 4539 | mCaps.fragmentHighpInt.get(range, precision); |
| 4540 | break; |
| 4541 | |
| 4542 | default: |
| 4543 | UNREACHABLE(); |
| 4544 | return; |
| 4545 | } |
| 4546 | break; |
| 4547 | |
| 4548 | default: |
| 4549 | UNREACHABLE(); |
| 4550 | return; |
| 4551 | } |
| 4552 | } |
| 4553 | |
| 4554 | void Context::getShaderSource(GLuint shader, GLsizei bufsize, GLsizei *length, GLchar *source) |
| 4555 | { |
| 4556 | Shader *shaderObject = getShader(shader); |
| 4557 | ASSERT(shaderObject); |
| 4558 | shaderObject->getSource(bufsize, length, source); |
| 4559 | } |
| 4560 | |
| 4561 | void Context::getUniformfv(GLuint program, GLint location, GLfloat *params) |
| 4562 | { |
| 4563 | Program *programObject = getProgram(program); |
| 4564 | ASSERT(programObject); |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 4565 | programObject->getUniformfv(this, location, params); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4566 | } |
| 4567 | |
| 4568 | void Context::getUniformiv(GLuint program, GLint location, GLint *params) |
| 4569 | { |
| 4570 | Program *programObject = getProgram(program); |
| 4571 | ASSERT(programObject); |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 4572 | programObject->getUniformiv(this, location, params); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4573 | } |
| 4574 | |
| 4575 | GLint Context::getUniformLocation(GLuint program, const GLchar *name) |
| 4576 | { |
| 4577 | Program *programObject = getProgram(program); |
| 4578 | ASSERT(programObject); |
| 4579 | return programObject->getUniformLocation(name); |
| 4580 | } |
| 4581 | |
| 4582 | GLboolean Context::isBuffer(GLuint buffer) |
| 4583 | { |
| 4584 | if (buffer == 0) |
| 4585 | { |
| 4586 | return GL_FALSE; |
| 4587 | } |
| 4588 | |
| 4589 | return (getBuffer(buffer) ? GL_TRUE : GL_FALSE); |
| 4590 | } |
| 4591 | |
| 4592 | GLboolean Context::isEnabled(GLenum cap) |
| 4593 | { |
| 4594 | return mGLState.getEnableFeature(cap); |
| 4595 | } |
| 4596 | |
| 4597 | GLboolean Context::isFramebuffer(GLuint framebuffer) |
| 4598 | { |
| 4599 | if (framebuffer == 0) |
| 4600 | { |
| 4601 | return GL_FALSE; |
| 4602 | } |
| 4603 | |
| 4604 | return (getFramebuffer(framebuffer) ? GL_TRUE : GL_FALSE); |
| 4605 | } |
| 4606 | |
| 4607 | GLboolean Context::isProgram(GLuint program) |
| 4608 | { |
| 4609 | if (program == 0) |
| 4610 | { |
| 4611 | return GL_FALSE; |
| 4612 | } |
| 4613 | |
| 4614 | return (getProgram(program) ? GL_TRUE : GL_FALSE); |
| 4615 | } |
| 4616 | |
| 4617 | GLboolean Context::isRenderbuffer(GLuint renderbuffer) |
| 4618 | { |
| 4619 | if (renderbuffer == 0) |
| 4620 | { |
| 4621 | return GL_FALSE; |
| 4622 | } |
| 4623 | |
| 4624 | return (getRenderbuffer(renderbuffer) ? GL_TRUE : GL_FALSE); |
| 4625 | } |
| 4626 | |
| 4627 | GLboolean Context::isShader(GLuint shader) |
| 4628 | { |
| 4629 | if (shader == 0) |
| 4630 | { |
| 4631 | return GL_FALSE; |
| 4632 | } |
| 4633 | |
| 4634 | return (getShader(shader) ? GL_TRUE : GL_FALSE); |
| 4635 | } |
| 4636 | |
| 4637 | GLboolean Context::isTexture(GLuint texture) |
| 4638 | { |
| 4639 | if (texture == 0) |
| 4640 | { |
| 4641 | return GL_FALSE; |
| 4642 | } |
| 4643 | |
| 4644 | return (getTexture(texture) ? GL_TRUE : GL_FALSE); |
| 4645 | } |
| 4646 | |
| 4647 | void Context::linkProgram(GLuint program) |
| 4648 | { |
| 4649 | Program *programObject = getProgram(program); |
| 4650 | ASSERT(programObject); |
| 4651 | handleError(programObject->link(this)); |
Martin Radev | 0abb7a2 | 2017-08-28 15:34:45 +0300 | [diff] [blame] | 4652 | mGLState.onProgramExecutableChange(programObject); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4653 | } |
| 4654 | |
| 4655 | void Context::releaseShaderCompiler() |
| 4656 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 4657 | mCompiler.set(this, nullptr); |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4658 | } |
| 4659 | |
| 4660 | void Context::shaderBinary(GLsizei n, |
| 4661 | const GLuint *shaders, |
| 4662 | GLenum binaryformat, |
Jamie Madill | 876429b | 2017-04-20 15:46:24 -0400 | [diff] [blame] | 4663 | const void *binary, |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4664 | GLsizei length) |
| 4665 | { |
| 4666 | // No binary shader formats are supported. |
| 4667 | UNIMPLEMENTED(); |
| 4668 | } |
| 4669 | |
| 4670 | void Context::shaderSource(GLuint shader, |
| 4671 | GLsizei count, |
| 4672 | const GLchar *const *string, |
| 4673 | const GLint *length) |
| 4674 | { |
| 4675 | Shader *shaderObject = getShader(shader); |
| 4676 | ASSERT(shaderObject); |
| 4677 | shaderObject->setSource(count, string, length); |
| 4678 | } |
| 4679 | |
| 4680 | void Context::stencilFunc(GLenum func, GLint ref, GLuint mask) |
| 4681 | { |
| 4682 | stencilFuncSeparate(GL_FRONT_AND_BACK, func, ref, mask); |
| 4683 | } |
| 4684 | |
| 4685 | void Context::stencilMask(GLuint mask) |
| 4686 | { |
| 4687 | stencilMaskSeparate(GL_FRONT_AND_BACK, mask); |
| 4688 | } |
| 4689 | |
| 4690 | void Context::stencilOp(GLenum fail, GLenum zfail, GLenum zpass) |
| 4691 | { |
| 4692 | stencilOpSeparate(GL_FRONT_AND_BACK, fail, zfail, zpass); |
| 4693 | } |
| 4694 | |
| 4695 | void Context::uniform1f(GLint location, GLfloat x) |
| 4696 | { |
| 4697 | Program *program = mGLState.getProgram(); |
| 4698 | program->setUniform1fv(location, 1, &x); |
| 4699 | } |
| 4700 | |
| 4701 | void Context::uniform1fv(GLint location, GLsizei count, const GLfloat *v) |
| 4702 | { |
| 4703 | Program *program = mGLState.getProgram(); |
| 4704 | program->setUniform1fv(location, count, v); |
| 4705 | } |
| 4706 | |
| 4707 | void Context::uniform1i(GLint location, GLint x) |
| 4708 | { |
| 4709 | Program *program = mGLState.getProgram(); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 4710 | if (program->setUniform1iv(location, 1, &x) == Program::SetUniformResult::SamplerChanged) |
| 4711 | { |
| 4712 | mGLState.setObjectDirty(GL_PROGRAM); |
| 4713 | } |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4714 | } |
| 4715 | |
| 4716 | void Context::uniform1iv(GLint location, GLsizei count, const GLint *v) |
| 4717 | { |
| 4718 | Program *program = mGLState.getProgram(); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 4719 | if (program->setUniform1iv(location, count, v) == Program::SetUniformResult::SamplerChanged) |
| 4720 | { |
| 4721 | mGLState.setObjectDirty(GL_PROGRAM); |
| 4722 | } |
Jamie Madill | c1d770e | 2017-04-13 17:31:24 -0400 | [diff] [blame] | 4723 | } |
| 4724 | |
| 4725 | void Context::uniform2f(GLint location, GLfloat x, GLfloat y) |
| 4726 | { |
| 4727 | GLfloat xy[2] = {x, y}; |
| 4728 | Program *program = mGLState.getProgram(); |
| 4729 | program->setUniform2fv(location, 1, xy); |
| 4730 | } |
| 4731 | |
| 4732 | void Context::uniform2fv(GLint location, GLsizei count, const GLfloat *v) |
| 4733 | { |
| 4734 | Program *program = mGLState.getProgram(); |
| 4735 | program->setUniform2fv(location, count, v); |
| 4736 | } |
| 4737 | |
| 4738 | void Context::uniform2i(GLint location, GLint x, GLint y) |
| 4739 | { |
| 4740 | GLint xy[2] = {x, y}; |
| 4741 | Program *program = mGLState.getProgram(); |
| 4742 | program->setUniform2iv(location, 1, xy); |
| 4743 | } |
| 4744 | |
| 4745 | void Context::uniform2iv(GLint location, GLsizei count, const GLint *v) |
| 4746 | { |
| 4747 | Program *program = mGLState.getProgram(); |
| 4748 | program->setUniform2iv(location, count, v); |
| 4749 | } |
| 4750 | |
| 4751 | void Context::uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z) |
| 4752 | { |
| 4753 | GLfloat xyz[3] = {x, y, z}; |
| 4754 | Program *program = mGLState.getProgram(); |
| 4755 | program->setUniform3fv(location, 1, xyz); |
| 4756 | } |
| 4757 | |
| 4758 | void Context::uniform3fv(GLint location, GLsizei count, const GLfloat *v) |
| 4759 | { |
| 4760 | Program *program = mGLState.getProgram(); |
| 4761 | program->setUniform3fv(location, count, v); |
| 4762 | } |
| 4763 | |
| 4764 | void Context::uniform3i(GLint location, GLint x, GLint y, GLint z) |
| 4765 | { |
| 4766 | GLint xyz[3] = {x, y, z}; |
| 4767 | Program *program = mGLState.getProgram(); |
| 4768 | program->setUniform3iv(location, 1, xyz); |
| 4769 | } |
| 4770 | |
| 4771 | void Context::uniform3iv(GLint location, GLsizei count, const GLint *v) |
| 4772 | { |
| 4773 | Program *program = mGLState.getProgram(); |
| 4774 | program->setUniform3iv(location, count, v); |
| 4775 | } |
| 4776 | |
| 4777 | void Context::uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w) |
| 4778 | { |
| 4779 | GLfloat xyzw[4] = {x, y, z, w}; |
| 4780 | Program *program = mGLState.getProgram(); |
| 4781 | program->setUniform4fv(location, 1, xyzw); |
| 4782 | } |
| 4783 | |
| 4784 | void Context::uniform4fv(GLint location, GLsizei count, const GLfloat *v) |
| 4785 | { |
| 4786 | Program *program = mGLState.getProgram(); |
| 4787 | program->setUniform4fv(location, count, v); |
| 4788 | } |
| 4789 | |
| 4790 | void Context::uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w) |
| 4791 | { |
| 4792 | GLint xyzw[4] = {x, y, z, w}; |
| 4793 | Program *program = mGLState.getProgram(); |
| 4794 | program->setUniform4iv(location, 1, xyzw); |
| 4795 | } |
| 4796 | |
| 4797 | void Context::uniform4iv(GLint location, GLsizei count, const GLint *v) |
| 4798 | { |
| 4799 | Program *program = mGLState.getProgram(); |
| 4800 | program->setUniform4iv(location, count, v); |
| 4801 | } |
| 4802 | |
| 4803 | void Context::uniformMatrix2fv(GLint location, |
| 4804 | GLsizei count, |
| 4805 | GLboolean transpose, |
| 4806 | const GLfloat *value) |
| 4807 | { |
| 4808 | Program *program = mGLState.getProgram(); |
| 4809 | program->setUniformMatrix2fv(location, count, transpose, value); |
| 4810 | } |
| 4811 | |
| 4812 | void Context::uniformMatrix3fv(GLint location, |
| 4813 | GLsizei count, |
| 4814 | GLboolean transpose, |
| 4815 | const GLfloat *value) |
| 4816 | { |
| 4817 | Program *program = mGLState.getProgram(); |
| 4818 | program->setUniformMatrix3fv(location, count, transpose, value); |
| 4819 | } |
| 4820 | |
| 4821 | void Context::uniformMatrix4fv(GLint location, |
| 4822 | GLsizei count, |
| 4823 | GLboolean transpose, |
| 4824 | const GLfloat *value) |
| 4825 | { |
| 4826 | Program *program = mGLState.getProgram(); |
| 4827 | program->setUniformMatrix4fv(location, count, transpose, value); |
| 4828 | } |
| 4829 | |
| 4830 | void Context::validateProgram(GLuint program) |
| 4831 | { |
| 4832 | Program *programObject = getProgram(program); |
| 4833 | ASSERT(programObject); |
| 4834 | programObject->validate(mCaps); |
| 4835 | } |
| 4836 | |
Jamie Madill | d04908b | 2017-06-09 14:15:35 -0400 | [diff] [blame] | 4837 | void Context::getProgramBinary(GLuint program, |
| 4838 | GLsizei bufSize, |
| 4839 | GLsizei *length, |
| 4840 | GLenum *binaryFormat, |
| 4841 | void *binary) |
| 4842 | { |
| 4843 | Program *programObject = getProgram(program); |
| 4844 | ASSERT(programObject != nullptr); |
| 4845 | |
| 4846 | handleError(programObject->saveBinary(this, binaryFormat, binary, bufSize, length)); |
| 4847 | } |
| 4848 | |
| 4849 | void Context::programBinary(GLuint program, GLenum binaryFormat, const void *binary, GLsizei length) |
| 4850 | { |
| 4851 | Program *programObject = getProgram(program); |
| 4852 | ASSERT(programObject != nullptr); |
Jamie Madill | b666492 | 2017-07-25 12:55:04 -0400 | [diff] [blame] | 4853 | |
Jamie Madill | d04908b | 2017-06-09 14:15:35 -0400 | [diff] [blame] | 4854 | handleError(programObject->loadBinary(this, binaryFormat, binary, length)); |
| 4855 | } |
| 4856 | |
Jamie Madill | ff325f1 | 2017-08-26 15:06:05 -0400 | [diff] [blame] | 4857 | void Context::uniform1ui(GLint location, GLuint v0) |
| 4858 | { |
| 4859 | Program *program = mGLState.getProgram(); |
| 4860 | program->setUniform1uiv(location, 1, &v0); |
| 4861 | } |
| 4862 | |
| 4863 | void Context::uniform2ui(GLint location, GLuint v0, GLuint v1) |
| 4864 | { |
| 4865 | Program *program = mGLState.getProgram(); |
| 4866 | const GLuint xy[] = {v0, v1}; |
| 4867 | program->setUniform2uiv(location, 1, xy); |
| 4868 | } |
| 4869 | |
| 4870 | void Context::uniform3ui(GLint location, GLuint v0, GLuint v1, GLuint v2) |
| 4871 | { |
| 4872 | Program *program = mGLState.getProgram(); |
| 4873 | const GLuint xyz[] = {v0, v1, v2}; |
| 4874 | program->setUniform3uiv(location, 1, xyz); |
| 4875 | } |
| 4876 | |
| 4877 | void Context::uniform4ui(GLint location, GLuint v0, GLuint v1, GLuint v2, GLuint v3) |
| 4878 | { |
| 4879 | Program *program = mGLState.getProgram(); |
| 4880 | const GLuint xyzw[] = {v0, v1, v2, v3}; |
| 4881 | program->setUniform4uiv(location, 1, xyzw); |
| 4882 | } |
| 4883 | |
| 4884 | void Context::uniform1uiv(GLint location, GLsizei count, const GLuint *value) |
| 4885 | { |
| 4886 | Program *program = mGLState.getProgram(); |
| 4887 | program->setUniform1uiv(location, count, value); |
| 4888 | } |
| 4889 | void Context::uniform2uiv(GLint location, GLsizei count, const GLuint *value) |
| 4890 | { |
| 4891 | Program *program = mGLState.getProgram(); |
| 4892 | program->setUniform2uiv(location, count, value); |
| 4893 | } |
| 4894 | |
| 4895 | void Context::uniform3uiv(GLint location, GLsizei count, const GLuint *value) |
| 4896 | { |
| 4897 | Program *program = mGLState.getProgram(); |
| 4898 | program->setUniform3uiv(location, count, value); |
| 4899 | } |
| 4900 | |
| 4901 | void Context::uniform4uiv(GLint location, GLsizei count, const GLuint *value) |
| 4902 | { |
| 4903 | Program *program = mGLState.getProgram(); |
| 4904 | program->setUniform4uiv(location, count, value); |
| 4905 | } |
| 4906 | |
Jamie Madill | f0e0449 | 2017-08-26 15:28:42 -0400 | [diff] [blame] | 4907 | void Context::genQueries(GLsizei n, GLuint *ids) |
| 4908 | { |
| 4909 | for (GLsizei i = 0; i < n; i++) |
| 4910 | { |
| 4911 | GLuint handle = mQueryHandleAllocator.allocate(); |
| 4912 | mQueryMap.assign(handle, nullptr); |
| 4913 | ids[i] = handle; |
| 4914 | } |
| 4915 | } |
| 4916 | |
| 4917 | void Context::deleteQueries(GLsizei n, const GLuint *ids) |
| 4918 | { |
| 4919 | for (int i = 0; i < n; i++) |
| 4920 | { |
| 4921 | GLuint query = ids[i]; |
| 4922 | |
| 4923 | Query *queryObject = nullptr; |
| 4924 | if (mQueryMap.erase(query, &queryObject)) |
| 4925 | { |
| 4926 | mQueryHandleAllocator.release(query); |
| 4927 | if (queryObject) |
| 4928 | { |
| 4929 | queryObject->release(this); |
| 4930 | } |
| 4931 | } |
| 4932 | } |
| 4933 | } |
| 4934 | |
| 4935 | GLboolean Context::isQuery(GLuint id) |
| 4936 | { |
| 4937 | return (getQuery(id, false, GL_NONE) != nullptr) ? GL_TRUE : GL_FALSE; |
| 4938 | } |
| 4939 | |
Jamie Madill | c8c9581 | 2017-08-26 18:40:09 -0400 | [diff] [blame] | 4940 | void Context::uniformMatrix2x3fv(GLint location, |
| 4941 | GLsizei count, |
| 4942 | GLboolean transpose, |
| 4943 | const GLfloat *value) |
| 4944 | { |
| 4945 | Program *program = mGLState.getProgram(); |
| 4946 | program->setUniformMatrix2x3fv(location, count, transpose, value); |
| 4947 | } |
| 4948 | |
| 4949 | void Context::uniformMatrix3x2fv(GLint location, |
| 4950 | GLsizei count, |
| 4951 | GLboolean transpose, |
| 4952 | const GLfloat *value) |
| 4953 | { |
| 4954 | Program *program = mGLState.getProgram(); |
| 4955 | program->setUniformMatrix3x2fv(location, count, transpose, value); |
| 4956 | } |
| 4957 | |
| 4958 | void Context::uniformMatrix2x4fv(GLint location, |
| 4959 | GLsizei count, |
| 4960 | GLboolean transpose, |
| 4961 | const GLfloat *value) |
| 4962 | { |
| 4963 | Program *program = mGLState.getProgram(); |
| 4964 | program->setUniformMatrix2x4fv(location, count, transpose, value); |
| 4965 | } |
| 4966 | |
| 4967 | void Context::uniformMatrix4x2fv(GLint location, |
| 4968 | GLsizei count, |
| 4969 | GLboolean transpose, |
| 4970 | const GLfloat *value) |
| 4971 | { |
| 4972 | Program *program = mGLState.getProgram(); |
| 4973 | program->setUniformMatrix4x2fv(location, count, transpose, value); |
| 4974 | } |
| 4975 | |
| 4976 | void Context::uniformMatrix3x4fv(GLint location, |
| 4977 | GLsizei count, |
| 4978 | GLboolean transpose, |
| 4979 | const GLfloat *value) |
| 4980 | { |
| 4981 | Program *program = mGLState.getProgram(); |
| 4982 | program->setUniformMatrix3x4fv(location, count, transpose, value); |
| 4983 | } |
| 4984 | |
| 4985 | void Context::uniformMatrix4x3fv(GLint location, |
| 4986 | GLsizei count, |
| 4987 | GLboolean transpose, |
| 4988 | const GLfloat *value) |
| 4989 | { |
| 4990 | Program *program = mGLState.getProgram(); |
| 4991 | program->setUniformMatrix4x3fv(location, count, transpose, value); |
| 4992 | } |
| 4993 | |
Jamie Madill | d757673 | 2017-08-26 18:49:50 -0400 | [diff] [blame] | 4994 | void Context::deleteVertexArrays(GLsizei n, const GLuint *arrays) |
| 4995 | { |
| 4996 | for (int arrayIndex = 0; arrayIndex < n; arrayIndex++) |
| 4997 | { |
| 4998 | GLuint vertexArray = arrays[arrayIndex]; |
| 4999 | |
| 5000 | if (arrays[arrayIndex] != 0) |
| 5001 | { |
| 5002 | VertexArray *vertexArrayObject = nullptr; |
| 5003 | if (mVertexArrayMap.erase(vertexArray, &vertexArrayObject)) |
| 5004 | { |
| 5005 | if (vertexArrayObject != nullptr) |
| 5006 | { |
| 5007 | detachVertexArray(vertexArray); |
| 5008 | vertexArrayObject->onDestroy(this); |
| 5009 | } |
| 5010 | |
| 5011 | mVertexArrayHandleAllocator.release(vertexArray); |
| 5012 | } |
| 5013 | } |
| 5014 | } |
| 5015 | } |
| 5016 | |
| 5017 | void Context::genVertexArrays(GLsizei n, GLuint *arrays) |
| 5018 | { |
| 5019 | for (int arrayIndex = 0; arrayIndex < n; arrayIndex++) |
| 5020 | { |
| 5021 | GLuint vertexArray = mVertexArrayHandleAllocator.allocate(); |
| 5022 | mVertexArrayMap.assign(vertexArray, nullptr); |
| 5023 | arrays[arrayIndex] = vertexArray; |
| 5024 | } |
| 5025 | } |
| 5026 | |
| 5027 | bool Context::isVertexArray(GLuint array) |
| 5028 | { |
| 5029 | if (array == 0) |
| 5030 | { |
| 5031 | return GL_FALSE; |
| 5032 | } |
| 5033 | |
| 5034 | VertexArray *vao = getVertexArray(array); |
| 5035 | return (vao != nullptr ? GL_TRUE : GL_FALSE); |
| 5036 | } |
| 5037 | |
Jamie Madill | f0dcb8b | 2017-08-26 19:05:13 -0400 | [diff] [blame] | 5038 | void Context::endTransformFeedback() |
| 5039 | { |
| 5040 | TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback(); |
| 5041 | transformFeedback->end(this); |
| 5042 | } |
| 5043 | |
| 5044 | void Context::transformFeedbackVaryings(GLuint program, |
| 5045 | GLsizei count, |
| 5046 | const GLchar *const *varyings, |
| 5047 | GLenum bufferMode) |
| 5048 | { |
| 5049 | Program *programObject = getProgram(program); |
| 5050 | ASSERT(programObject); |
| 5051 | programObject->setTransformFeedbackVaryings(count, varyings, bufferMode); |
| 5052 | } |
| 5053 | |
| 5054 | void Context::getTransformFeedbackVarying(GLuint program, |
| 5055 | GLuint index, |
| 5056 | GLsizei bufSize, |
| 5057 | GLsizei *length, |
| 5058 | GLsizei *size, |
| 5059 | GLenum *type, |
| 5060 | GLchar *name) |
| 5061 | { |
| 5062 | Program *programObject = getProgram(program); |
| 5063 | ASSERT(programObject); |
| 5064 | programObject->getTransformFeedbackVarying(index, bufSize, length, size, type, name); |
| 5065 | } |
| 5066 | |
| 5067 | void Context::deleteTransformFeedbacks(GLsizei n, const GLuint *ids) |
| 5068 | { |
| 5069 | for (int i = 0; i < n; i++) |
| 5070 | { |
| 5071 | GLuint transformFeedback = ids[i]; |
| 5072 | if (transformFeedback == 0) |
| 5073 | { |
| 5074 | continue; |
| 5075 | } |
| 5076 | |
| 5077 | TransformFeedback *transformFeedbackObject = nullptr; |
| 5078 | if (mTransformFeedbackMap.erase(transformFeedback, &transformFeedbackObject)) |
| 5079 | { |
| 5080 | if (transformFeedbackObject != nullptr) |
| 5081 | { |
| 5082 | detachTransformFeedback(transformFeedback); |
| 5083 | transformFeedbackObject->release(this); |
| 5084 | } |
| 5085 | |
| 5086 | mTransformFeedbackHandleAllocator.release(transformFeedback); |
| 5087 | } |
| 5088 | } |
| 5089 | } |
| 5090 | |
| 5091 | void Context::genTransformFeedbacks(GLsizei n, GLuint *ids) |
| 5092 | { |
| 5093 | for (int i = 0; i < n; i++) |
| 5094 | { |
| 5095 | GLuint transformFeedback = mTransformFeedbackHandleAllocator.allocate(); |
| 5096 | mTransformFeedbackMap.assign(transformFeedback, nullptr); |
| 5097 | ids[i] = transformFeedback; |
| 5098 | } |
| 5099 | } |
| 5100 | |
| 5101 | bool Context::isTransformFeedback(GLuint id) |
| 5102 | { |
| 5103 | if (id == 0) |
| 5104 | { |
| 5105 | // The 3.0.4 spec [section 6.1.11] states that if ID is zero, IsTransformFeedback |
| 5106 | // returns FALSE |
| 5107 | return GL_FALSE; |
| 5108 | } |
| 5109 | |
| 5110 | const TransformFeedback *transformFeedback = getTransformFeedback(id); |
| 5111 | return ((transformFeedback != nullptr) ? GL_TRUE : GL_FALSE); |
| 5112 | } |
| 5113 | |
| 5114 | void Context::pauseTransformFeedback() |
| 5115 | { |
| 5116 | TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback(); |
| 5117 | transformFeedback->pause(); |
| 5118 | } |
| 5119 | |
| 5120 | void Context::resumeTransformFeedback() |
| 5121 | { |
| 5122 | TransformFeedback *transformFeedback = mGLState.getCurrentTransformFeedback(); |
| 5123 | transformFeedback->resume(); |
| 5124 | } |
| 5125 | |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 5126 | void Context::getUniformuiv(GLuint program, GLint location, GLuint *params) |
| 5127 | { |
| 5128 | const Program *programObject = getProgram(program); |
Jamie Madill | 54164b0 | 2017-08-28 15:17:37 -0400 | [diff] [blame] | 5129 | programObject->getUniformuiv(this, location, params); |
Jamie Madill | 12e957f | 2017-08-26 21:42:26 -0400 | [diff] [blame] | 5130 | } |
| 5131 | |
| 5132 | GLint Context::getFragDataLocation(GLuint program, const GLchar *name) |
| 5133 | { |
| 5134 | const Program *programObject = getProgram(program); |
| 5135 | return programObject->getFragDataLocation(name); |
| 5136 | } |
| 5137 | |
| 5138 | void Context::getUniformIndices(GLuint program, |
| 5139 | GLsizei uniformCount, |
| 5140 | const GLchar *const *uniformNames, |
| 5141 | GLuint *uniformIndices) |
| 5142 | { |
| 5143 | const Program *programObject = getProgram(program); |
| 5144 | if (!programObject->isLinked()) |
| 5145 | { |
| 5146 | for (int uniformId = 0; uniformId < uniformCount; uniformId++) |
| 5147 | { |
| 5148 | uniformIndices[uniformId] = GL_INVALID_INDEX; |
| 5149 | } |
| 5150 | } |
| 5151 | else |
| 5152 | { |
| 5153 | for (int uniformId = 0; uniformId < uniformCount; uniformId++) |
| 5154 | { |
| 5155 | uniformIndices[uniformId] = programObject->getUniformIndex(uniformNames[uniformId]); |
| 5156 | } |
| 5157 | } |
| 5158 | } |
| 5159 | |
| 5160 | void Context::getActiveUniformsiv(GLuint program, |
| 5161 | GLsizei uniformCount, |
| 5162 | const GLuint *uniformIndices, |
| 5163 | GLenum pname, |
| 5164 | GLint *params) |
| 5165 | { |
| 5166 | const Program *programObject = getProgram(program); |
| 5167 | for (int uniformId = 0; uniformId < uniformCount; uniformId++) |
| 5168 | { |
| 5169 | const GLuint index = uniformIndices[uniformId]; |
| 5170 | params[uniformId] = programObject->getActiveUniformi(index, pname); |
| 5171 | } |
| 5172 | } |
| 5173 | |
| 5174 | GLuint Context::getUniformBlockIndex(GLuint program, const GLchar *uniformBlockName) |
| 5175 | { |
| 5176 | const Program *programObject = getProgram(program); |
| 5177 | return programObject->getUniformBlockIndex(uniformBlockName); |
| 5178 | } |
| 5179 | |
| 5180 | void Context::getActiveUniformBlockiv(GLuint program, |
| 5181 | GLuint uniformBlockIndex, |
| 5182 | GLenum pname, |
| 5183 | GLint *params) |
| 5184 | { |
| 5185 | const Program *programObject = getProgram(program); |
| 5186 | QueryActiveUniformBlockiv(programObject, uniformBlockIndex, pname, params); |
| 5187 | } |
| 5188 | |
| 5189 | void Context::getActiveUniformBlockName(GLuint program, |
| 5190 | GLuint uniformBlockIndex, |
| 5191 | GLsizei bufSize, |
| 5192 | GLsizei *length, |
| 5193 | GLchar *uniformBlockName) |
| 5194 | { |
| 5195 | const Program *programObject = getProgram(program); |
| 5196 | programObject->getActiveUniformBlockName(uniformBlockIndex, bufSize, length, uniformBlockName); |
| 5197 | } |
| 5198 | |
| 5199 | void Context::uniformBlockBinding(GLuint program, |
| 5200 | GLuint uniformBlockIndex, |
| 5201 | GLuint uniformBlockBinding) |
| 5202 | { |
| 5203 | Program *programObject = getProgram(program); |
| 5204 | programObject->bindUniformBlock(uniformBlockIndex, uniformBlockBinding); |
| 5205 | } |
| 5206 | |
Jamie Madill | 7f0c5a4 | 2017-08-26 22:43:26 -0400 | [diff] [blame] | 5207 | GLsync Context::fenceSync(GLenum condition, GLbitfield flags) |
| 5208 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 5209 | GLuint handle = mState.mSyncs->createSync(mImplementation.get()); |
| 5210 | GLsync syncHandle = reinterpret_cast<GLsync>(static_cast<uintptr_t>(handle)); |
Jamie Madill | 7f0c5a4 | 2017-08-26 22:43:26 -0400 | [diff] [blame] | 5211 | |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 5212 | Sync *syncObject = getSync(syncHandle); |
| 5213 | Error error = syncObject->set(condition, flags); |
Jamie Madill | 7f0c5a4 | 2017-08-26 22:43:26 -0400 | [diff] [blame] | 5214 | if (error.isError()) |
| 5215 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 5216 | deleteSync(syncHandle); |
Jamie Madill | 7f0c5a4 | 2017-08-26 22:43:26 -0400 | [diff] [blame] | 5217 | handleError(error); |
| 5218 | return nullptr; |
| 5219 | } |
| 5220 | |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 5221 | return syncHandle; |
Jamie Madill | 7f0c5a4 | 2017-08-26 22:43:26 -0400 | [diff] [blame] | 5222 | } |
| 5223 | |
| 5224 | GLboolean Context::isSync(GLsync sync) |
| 5225 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 5226 | return (getSync(sync) != nullptr); |
Jamie Madill | 7f0c5a4 | 2017-08-26 22:43:26 -0400 | [diff] [blame] | 5227 | } |
| 5228 | |
| 5229 | GLenum Context::clientWaitSync(GLsync sync, GLbitfield flags, GLuint64 timeout) |
| 5230 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 5231 | Sync *syncObject = getSync(sync); |
Jamie Madill | 7f0c5a4 | 2017-08-26 22:43:26 -0400 | [diff] [blame] | 5232 | |
| 5233 | GLenum result = GL_WAIT_FAILED; |
| 5234 | handleError(syncObject->clientWait(flags, timeout, &result)); |
| 5235 | return result; |
| 5236 | } |
| 5237 | |
| 5238 | void Context::waitSync(GLsync sync, GLbitfield flags, GLuint64 timeout) |
| 5239 | { |
Jamie Madill | 70b5bb0 | 2017-08-28 13:32:37 -0400 | [diff] [blame] | 5240 | Sync *syncObject = getSync(sync); |
Jamie Madill | 7f0c5a4 | 2017-08-26 22:43:26 -0400 | [diff] [blame] | 5241 | handleError(syncObject->serverWait(flags, timeout)); |
| 5242 | } |
| 5243 | |
| 5244 | void Context::getInteger64v(GLenum pname, GLint64 *params) |
| 5245 | { |
| 5246 | GLenum nativeType = GL_NONE; |
| 5247 | unsigned int numParams = 0; |
| 5248 | getQueryParameterInfo(pname, &nativeType, &numParams); |
| 5249 | |
| 5250 | if (nativeType == GL_INT_64_ANGLEX) |
| 5251 | { |
| 5252 | getInteger64vImpl(pname, params); |
| 5253 | } |
| 5254 | else |
| 5255 | { |
| 5256 | CastStateValues(this, nativeType, pname, numParams, params); |
| 5257 | } |
| 5258 | } |
| 5259 | |
Jamie Madill | 3ef140a | 2017-08-26 23:11:21 -0400 | [diff] [blame] | 5260 | void Context::getBufferParameteri64v(GLenum target, GLenum pname, GLint64 *params) |
| 5261 | { |
| 5262 | Buffer *buffer = mGLState.getTargetBuffer(target); |
| 5263 | QueryBufferParameteri64v(buffer, pname, params); |
| 5264 | } |
| 5265 | |
| 5266 | void Context::genSamplers(GLsizei count, GLuint *samplers) |
| 5267 | { |
| 5268 | for (int i = 0; i < count; i++) |
| 5269 | { |
| 5270 | samplers[i] = mState.mSamplers->createSampler(); |
| 5271 | } |
| 5272 | } |
| 5273 | |
| 5274 | void Context::deleteSamplers(GLsizei count, const GLuint *samplers) |
| 5275 | { |
| 5276 | for (int i = 0; i < count; i++) |
| 5277 | { |
| 5278 | GLuint sampler = samplers[i]; |
| 5279 | |
| 5280 | if (mState.mSamplers->getSampler(sampler)) |
| 5281 | { |
| 5282 | detachSampler(sampler); |
| 5283 | } |
| 5284 | |
| 5285 | mState.mSamplers->deleteObject(this, sampler); |
| 5286 | } |
| 5287 | } |
| 5288 | |
| 5289 | void Context::getInternalformativ(GLenum target, |
| 5290 | GLenum internalformat, |
| 5291 | GLenum pname, |
| 5292 | GLsizei bufSize, |
| 5293 | GLint *params) |
| 5294 | { |
| 5295 | const TextureCaps &formatCaps = mTextureCaps.get(internalformat); |
| 5296 | QueryInternalFormativ(formatCaps, pname, bufSize, params); |
| 5297 | } |
| 5298 | |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 5299 | void Context::programUniform1iv(GLuint program, GLint location, GLsizei count, const GLint *value) |
| 5300 | { |
| 5301 | Program *programObject = getProgram(program); |
| 5302 | ASSERT(programObject); |
| 5303 | if (programObject->setUniform1iv(location, count, value) == |
| 5304 | Program::SetUniformResult::SamplerChanged) |
| 5305 | { |
| 5306 | mGLState.setObjectDirty(GL_PROGRAM); |
| 5307 | } |
| 5308 | } |
| 5309 | |
| 5310 | void Context::onTextureChange(const Texture *texture) |
| 5311 | { |
| 5312 | // Conservatively assume all textures are dirty. |
| 5313 | // TODO(jmadill): More fine-grained update. |
| 5314 | mGLState.setObjectDirty(GL_TEXTURE); |
| 5315 | } |
| 5316 | |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame^] | 5317 | void Context::genProgramPipelines(GLsizei count, GLuint *pipelines) |
| 5318 | { |
| 5319 | for (int i = 0; i < count; i++) |
| 5320 | { |
| 5321 | pipelines[i] = createProgramPipeline(); |
| 5322 | } |
| 5323 | } |
| 5324 | |
| 5325 | void Context::deleteProgramPipelines(GLsizei count, const GLuint *pipelines) |
| 5326 | { |
| 5327 | for (int i = 0; i < count; i++) |
| 5328 | { |
| 5329 | if (pipelines[i] != 0) |
| 5330 | { |
| 5331 | deleteProgramPipeline(pipelines[i]); |
| 5332 | } |
| 5333 | } |
| 5334 | } |
| 5335 | |
| 5336 | GLboolean Context::isProgramPipeline(GLuint pipeline) |
| 5337 | { |
| 5338 | if (pipeline == 0) |
| 5339 | { |
| 5340 | return GL_FALSE; |
| 5341 | } |
| 5342 | |
| 5343 | return (getProgramPipeline(pipeline) ? GL_TRUE : GL_FALSE); |
| 5344 | } |
| 5345 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 5346 | } // namespace gl |