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