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