Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2014 The ANGLE Project Authors. All rights reserved. |
| 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 | // State.cpp: Implements the State class, encapsulating raw GL state. |
| 8 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 9 | #include "libANGLE/State.h" |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 10 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 11 | #include <limits> |
| 12 | #include <string.h> |
| 13 | |
Jamie Madill | 20e005b | 2017-04-07 14:19:22 -0400 | [diff] [blame] | 14 | #include "common/bitset_utils.h" |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 15 | #include "common/matrix_utils.h" |
| 16 | #include "common/mathutil.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 17 | #include "libANGLE/Context.h" |
| 18 | #include "libANGLE/Caps.h" |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 19 | #include "libANGLE/Debug.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 20 | #include "libANGLE/Framebuffer.h" |
| 21 | #include "libANGLE/FramebufferAttachment.h" |
| 22 | #include "libANGLE/Query.h" |
| 23 | #include "libANGLE/VertexArray.h" |
| 24 | #include "libANGLE/formatutils.h" |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 25 | |
Olli Etuaho | bbf1c10 | 2016-06-28 13:31:33 +0300 | [diff] [blame] | 26 | namespace |
| 27 | { |
| 28 | |
| 29 | GLenum ActiveQueryType(const GLenum type) |
| 30 | { |
| 31 | return (type == GL_ANY_SAMPLES_PASSED_CONSERVATIVE) ? GL_ANY_SAMPLES_PASSED : type; |
| 32 | } |
| 33 | |
| 34 | } // anonymous namepace |
| 35 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 36 | namespace gl |
| 37 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 38 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 39 | State::State() |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 40 | : mMaxDrawBuffers(0), |
| 41 | mMaxCombinedTextureImageUnits(0), |
| 42 | mDepthClearValue(0), |
| 43 | mStencilClearValue(0), |
| 44 | mScissorTest(false), |
| 45 | mSampleCoverage(false), |
| 46 | mSampleCoverageValue(0), |
| 47 | mSampleCoverageInvert(false), |
| 48 | mStencilRef(0), |
| 49 | mStencilBackRef(0), |
| 50 | mLineWidth(0), |
| 51 | mGenerateMipmapHint(GL_NONE), |
| 52 | mFragmentShaderDerivativeHint(GL_NONE), |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 53 | mBindGeneratesResource(true), |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 54 | mClientArraysEnabled(true), |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 55 | mNearZ(0), |
| 56 | mFarZ(0), |
| 57 | mReadFramebuffer(nullptr), |
| 58 | mDrawFramebuffer(nullptr), |
| 59 | mProgram(nullptr), |
| 60 | mVertexArray(nullptr), |
| 61 | mActiveSampler(0), |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 62 | mPrimitiveRestart(false), |
| 63 | mMultiSampling(false), |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 64 | mSampleAlphaToOne(false), |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 65 | mFramebufferSRGB(true), |
| 66 | mRobustResourceInit(false) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 67 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | State::~State() |
| 71 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 72 | } |
| 73 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 74 | void State::initialize(const Caps &caps, |
| 75 | const Extensions &extensions, |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 76 | const Version &clientVersion, |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 77 | bool debug, |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 78 | bool bindGeneratesResource, |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 79 | bool clientArraysEnabled, |
| 80 | bool robustResourceInit) |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 81 | { |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 82 | mMaxDrawBuffers = caps.maxDrawBuffers; |
| 83 | mMaxCombinedTextureImageUnits = caps.maxCombinedTextureImageUnits; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 84 | |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 85 | setColorClearValue(0.0f, 0.0f, 0.0f, 0.0f); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 86 | |
| 87 | mDepthClearValue = 1.0f; |
| 88 | mStencilClearValue = 0; |
| 89 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 90 | mScissorTest = false; |
| 91 | mScissor.x = 0; |
| 92 | mScissor.y = 0; |
| 93 | mScissor.width = 0; |
| 94 | mScissor.height = 0; |
| 95 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 96 | mBlendColor.red = 0; |
| 97 | mBlendColor.green = 0; |
| 98 | mBlendColor.blue = 0; |
| 99 | mBlendColor.alpha = 0; |
| 100 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 101 | mStencilRef = 0; |
| 102 | mStencilBackRef = 0; |
| 103 | |
| 104 | mSampleCoverage = false; |
| 105 | mSampleCoverageValue = 1.0f; |
| 106 | mSampleCoverageInvert = false; |
| 107 | mGenerateMipmapHint = GL_DONT_CARE; |
| 108 | mFragmentShaderDerivativeHint = GL_DONT_CARE; |
| 109 | |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 110 | mBindGeneratesResource = bindGeneratesResource; |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 111 | mClientArraysEnabled = clientArraysEnabled; |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 112 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 113 | mLineWidth = 1.0f; |
| 114 | |
| 115 | mViewport.x = 0; |
| 116 | mViewport.y = 0; |
| 117 | mViewport.width = 0; |
| 118 | mViewport.height = 0; |
| 119 | mNearZ = 0.0f; |
| 120 | mFarZ = 1.0f; |
| 121 | |
| 122 | mBlend.colorMaskRed = true; |
| 123 | mBlend.colorMaskGreen = true; |
| 124 | mBlend.colorMaskBlue = true; |
| 125 | mBlend.colorMaskAlpha = true; |
| 126 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 127 | mActiveSampler = 0; |
| 128 | |
Shannon Woods | 23e0500 | 2014-09-22 19:07:27 -0400 | [diff] [blame] | 129 | mVertexAttribCurrentValues.resize(caps.maxVertexAttributes); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 130 | |
Geoff Lang | 4dc3af0 | 2016-11-18 14:09:27 -0500 | [diff] [blame] | 131 | mUniformBuffers.resize(caps.maxUniformBufferBindings); |
Shannon Woods | f3acaf9 | 2014-09-23 18:07:11 -0400 | [diff] [blame] | 132 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 133 | mSamplerTextures[GL_TEXTURE_2D].resize(caps.maxCombinedTextureImageUnits); |
| 134 | mSamplerTextures[GL_TEXTURE_CUBE_MAP].resize(caps.maxCombinedTextureImageUnits); |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 135 | if (clientVersion >= Version(3, 0)) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 136 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 137 | // TODO: These could also be enabled via extension |
| 138 | mSamplerTextures[GL_TEXTURE_2D_ARRAY].resize(caps.maxCombinedTextureImageUnits); |
| 139 | mSamplerTextures[GL_TEXTURE_3D].resize(caps.maxCombinedTextureImageUnits); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 140 | } |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 141 | if (clientVersion >= Version(3, 1)) |
| 142 | { |
| 143 | mSamplerTextures[GL_TEXTURE_2D_MULTISAMPLE].resize(caps.maxCombinedTextureImageUnits); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 144 | |
| 145 | mAtomicCounterBuffers.resize(caps.maxAtomicCounterBufferBindings); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 146 | mShaderStorageBuffers.resize(caps.maxShaderStorageBufferBindings); |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 147 | } |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 148 | if (extensions.eglImageExternal || extensions.eglStreamConsumerExternal) |
| 149 | { |
| 150 | mSamplerTextures[GL_TEXTURE_EXTERNAL_OES].resize(caps.maxCombinedTextureImageUnits); |
| 151 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 152 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 153 | mSamplers.resize(caps.maxCombinedTextureImageUnits); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 154 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 155 | mActiveQueries[GL_ANY_SAMPLES_PASSED].set(nullptr); |
| 156 | mActiveQueries[GL_ANY_SAMPLES_PASSED_CONSERVATIVE].set(nullptr); |
| 157 | mActiveQueries[GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN].set(nullptr); |
| 158 | mActiveQueries[GL_TIME_ELAPSED_EXT].set(nullptr); |
Geoff Lang | 2b4ce80 | 2016-04-28 13:34:50 -0400 | [diff] [blame] | 159 | mActiveQueries[GL_COMMANDS_COMPLETED_CHROMIUM].set(nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 160 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 161 | mProgram = nullptr; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 162 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 163 | mReadFramebuffer = nullptr; |
| 164 | mDrawFramebuffer = nullptr; |
Jamie Madill | b4b53c5 | 2015-02-03 15:22:48 -0500 | [diff] [blame] | 165 | |
| 166 | mPrimitiveRestart = false; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 167 | |
| 168 | mDebug.setOutputEnabled(debug); |
| 169 | mDebug.setMaxLoggedMessages(extensions.maxDebugLoggedMessages); |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 170 | |
| 171 | if (extensions.framebufferMultisample) |
| 172 | { |
| 173 | mMultiSampling = true; |
| 174 | mSampleAlphaToOne = false; |
| 175 | } |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 176 | |
| 177 | mCoverageModulation = GL_NONE; |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 178 | |
| 179 | angle::Matrix<GLfloat>::setToIdentity(mPathMatrixProj); |
| 180 | angle::Matrix<GLfloat>::setToIdentity(mPathMatrixMV); |
| 181 | mPathStencilFunc = GL_ALWAYS; |
| 182 | mPathStencilRef = 0; |
| 183 | mPathStencilMask = std::numeric_limits<GLuint>::max(); |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 184 | |
| 185 | mRobustResourceInit = robustResourceInit; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 186 | } |
| 187 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 188 | void State::reset(const Context *context) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 189 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 190 | for (TextureBindingMap::iterator bindingVec = mSamplerTextures.begin(); bindingVec != mSamplerTextures.end(); bindingVec++) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 191 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 192 | TextureBindingVector &textureVector = bindingVec->second; |
| 193 | for (size_t textureIdx = 0; textureIdx < textureVector.size(); textureIdx++) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 194 | { |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 195 | textureVector[textureIdx].set(nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 196 | } |
| 197 | } |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 198 | for (size_t samplerIdx = 0; samplerIdx < mSamplers.size(); samplerIdx++) |
| 199 | { |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 200 | mSamplers[samplerIdx].set(nullptr); |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 201 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 202 | |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 203 | mArrayBuffer.set(nullptr); |
| 204 | mDrawIndirectBuffer.set(nullptr); |
| 205 | mRenderbuffer.set(nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 206 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 207 | if (mProgram) |
| 208 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 209 | mProgram->release(context); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 210 | } |
Yunchao He | d7297bf | 2017-04-19 15:27:10 +0800 | [diff] [blame] | 211 | mProgram = nullptr; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 212 | |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 213 | mTransformFeedback.set(nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 214 | |
| 215 | for (State::ActiveQueryMap::iterator i = mActiveQueries.begin(); i != mActiveQueries.end(); i++) |
| 216 | { |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 217 | i->second.set(nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 218 | } |
| 219 | |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 220 | mGenericUniformBuffer.set(nullptr); |
Shannon Woods | 8299bb0 | 2014-09-26 18:55:43 -0400 | [diff] [blame] | 221 | for (BufferVector::iterator bufItr = mUniformBuffers.begin(); bufItr != mUniformBuffers.end(); ++bufItr) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 222 | { |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 223 | bufItr->set(nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 224 | } |
| 225 | |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 226 | mCopyReadBuffer.set(nullptr); |
| 227 | mCopyWriteBuffer.set(nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 228 | |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 229 | mPack.pixelBuffer.set(nullptr); |
| 230 | mUnpack.pixelBuffer.set(nullptr); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 231 | |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 232 | mGenericAtomicCounterBuffer.set(nullptr); |
| 233 | for (auto &buf : mAtomicCounterBuffers) |
| 234 | { |
| 235 | buf.set(nullptr); |
| 236 | } |
| 237 | |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 238 | mGenericShaderStorageBuffer.set(nullptr); |
| 239 | for (auto &buf : mShaderStorageBuffers) |
| 240 | { |
| 241 | buf.set(nullptr); |
| 242 | } |
| 243 | |
Yunchao He | d7297bf | 2017-04-19 15:27:10 +0800 | [diff] [blame] | 244 | mProgram = nullptr; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 245 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 246 | angle::Matrix<GLfloat>::setToIdentity(mPathMatrixProj); |
| 247 | angle::Matrix<GLfloat>::setToIdentity(mPathMatrixMV); |
| 248 | mPathStencilFunc = GL_ALWAYS; |
| 249 | mPathStencilRef = 0; |
| 250 | mPathStencilMask = std::numeric_limits<GLuint>::max(); |
| 251 | |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 252 | // TODO(jmadill): Is this necessary? |
| 253 | setAllDirtyBits(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | const RasterizerState &State::getRasterizerState() const |
| 257 | { |
| 258 | return mRasterizer; |
| 259 | } |
| 260 | |
| 261 | const BlendState &State::getBlendState() const |
| 262 | { |
| 263 | return mBlend; |
| 264 | } |
| 265 | |
| 266 | const DepthStencilState &State::getDepthStencilState() const |
| 267 | { |
| 268 | return mDepthStencil; |
| 269 | } |
| 270 | |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 271 | void State::setColorClearValue(float red, float green, float blue, float alpha) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 272 | { |
| 273 | mColorClearValue.red = red; |
| 274 | mColorClearValue.green = green; |
| 275 | mColorClearValue.blue = blue; |
| 276 | mColorClearValue.alpha = alpha; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 277 | mDirtyBits.set(DIRTY_BIT_CLEAR_COLOR); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 278 | } |
| 279 | |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 280 | void State::setDepthClearValue(float depth) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 281 | { |
| 282 | mDepthClearValue = depth; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 283 | mDirtyBits.set(DIRTY_BIT_CLEAR_DEPTH); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 284 | } |
| 285 | |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 286 | void State::setStencilClearValue(int stencil) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 287 | { |
| 288 | mStencilClearValue = stencil; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 289 | mDirtyBits.set(DIRTY_BIT_CLEAR_STENCIL); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 290 | } |
| 291 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 292 | void State::setColorMask(bool red, bool green, bool blue, bool alpha) |
| 293 | { |
| 294 | mBlend.colorMaskRed = red; |
| 295 | mBlend.colorMaskGreen = green; |
| 296 | mBlend.colorMaskBlue = blue; |
| 297 | mBlend.colorMaskAlpha = alpha; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 298 | mDirtyBits.set(DIRTY_BIT_COLOR_MASK); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | void State::setDepthMask(bool mask) |
| 302 | { |
| 303 | mDepthStencil.depthMask = mask; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 304 | mDirtyBits.set(DIRTY_BIT_DEPTH_MASK); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | bool State::isRasterizerDiscardEnabled() const |
| 308 | { |
| 309 | return mRasterizer.rasterizerDiscard; |
| 310 | } |
| 311 | |
| 312 | void State::setRasterizerDiscard(bool enabled) |
| 313 | { |
| 314 | mRasterizer.rasterizerDiscard = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 315 | mDirtyBits.set(DIRTY_BIT_RASTERIZER_DISCARD_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | bool State::isCullFaceEnabled() const |
| 319 | { |
| 320 | return mRasterizer.cullFace; |
| 321 | } |
| 322 | |
| 323 | void State::setCullFace(bool enabled) |
| 324 | { |
| 325 | mRasterizer.cullFace = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 326 | mDirtyBits.set(DIRTY_BIT_CULL_FACE_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | void State::setCullMode(GLenum mode) |
| 330 | { |
| 331 | mRasterizer.cullMode = mode; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 332 | mDirtyBits.set(DIRTY_BIT_CULL_FACE); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | void State::setFrontFace(GLenum front) |
| 336 | { |
| 337 | mRasterizer.frontFace = front; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 338 | mDirtyBits.set(DIRTY_BIT_FRONT_FACE); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | bool State::isDepthTestEnabled() const |
| 342 | { |
| 343 | return mDepthStencil.depthTest; |
| 344 | } |
| 345 | |
| 346 | void State::setDepthTest(bool enabled) |
| 347 | { |
| 348 | mDepthStencil.depthTest = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 349 | mDirtyBits.set(DIRTY_BIT_DEPTH_TEST_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | void State::setDepthFunc(GLenum depthFunc) |
| 353 | { |
| 354 | mDepthStencil.depthFunc = depthFunc; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 355 | mDirtyBits.set(DIRTY_BIT_DEPTH_FUNC); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | void State::setDepthRange(float zNear, float zFar) |
| 359 | { |
| 360 | mNearZ = zNear; |
| 361 | mFarZ = zFar; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 362 | mDirtyBits.set(DIRTY_BIT_DEPTH_RANGE); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 363 | } |
| 364 | |
Geoff Lang | d42f5b8 | 2015-04-16 14:03:29 -0400 | [diff] [blame] | 365 | float State::getNearPlane() const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 366 | { |
Geoff Lang | d42f5b8 | 2015-04-16 14:03:29 -0400 | [diff] [blame] | 367 | return mNearZ; |
| 368 | } |
| 369 | |
| 370 | float State::getFarPlane() const |
| 371 | { |
| 372 | return mFarZ; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | bool State::isBlendEnabled() const |
| 376 | { |
| 377 | return mBlend.blend; |
| 378 | } |
| 379 | |
| 380 | void State::setBlend(bool enabled) |
| 381 | { |
| 382 | mBlend.blend = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 383 | mDirtyBits.set(DIRTY_BIT_BLEND_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | void State::setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha) |
| 387 | { |
| 388 | mBlend.sourceBlendRGB = sourceRGB; |
| 389 | mBlend.destBlendRGB = destRGB; |
| 390 | mBlend.sourceBlendAlpha = sourceAlpha; |
| 391 | mBlend.destBlendAlpha = destAlpha; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 392 | mDirtyBits.set(DIRTY_BIT_BLEND_FUNCS); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | void State::setBlendColor(float red, float green, float blue, float alpha) |
| 396 | { |
| 397 | mBlendColor.red = red; |
| 398 | mBlendColor.green = green; |
| 399 | mBlendColor.blue = blue; |
| 400 | mBlendColor.alpha = alpha; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 401 | mDirtyBits.set(DIRTY_BIT_BLEND_COLOR); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | void State::setBlendEquation(GLenum rgbEquation, GLenum alphaEquation) |
| 405 | { |
| 406 | mBlend.blendEquationRGB = rgbEquation; |
| 407 | mBlend.blendEquationAlpha = alphaEquation; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 408 | mDirtyBits.set(DIRTY_BIT_BLEND_EQUATIONS); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | const ColorF &State::getBlendColor() const |
| 412 | { |
| 413 | return mBlendColor; |
| 414 | } |
| 415 | |
| 416 | bool State::isStencilTestEnabled() const |
| 417 | { |
| 418 | return mDepthStencil.stencilTest; |
| 419 | } |
| 420 | |
| 421 | void State::setStencilTest(bool enabled) |
| 422 | { |
| 423 | mDepthStencil.stencilTest = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 424 | mDirtyBits.set(DIRTY_BIT_STENCIL_TEST_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | void State::setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask) |
| 428 | { |
| 429 | mDepthStencil.stencilFunc = stencilFunc; |
| 430 | mStencilRef = (stencilRef > 0) ? stencilRef : 0; |
| 431 | mDepthStencil.stencilMask = stencilMask; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 432 | mDirtyBits.set(DIRTY_BIT_STENCIL_FUNCS_FRONT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | void State::setStencilBackParams(GLenum stencilBackFunc, GLint stencilBackRef, GLuint stencilBackMask) |
| 436 | { |
| 437 | mDepthStencil.stencilBackFunc = stencilBackFunc; |
| 438 | mStencilBackRef = (stencilBackRef > 0) ? stencilBackRef : 0; |
| 439 | mDepthStencil.stencilBackMask = stencilBackMask; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 440 | mDirtyBits.set(DIRTY_BIT_STENCIL_FUNCS_BACK); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | void State::setStencilWritemask(GLuint stencilWritemask) |
| 444 | { |
| 445 | mDepthStencil.stencilWritemask = stencilWritemask; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 446 | mDirtyBits.set(DIRTY_BIT_STENCIL_WRITEMASK_FRONT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | void State::setStencilBackWritemask(GLuint stencilBackWritemask) |
| 450 | { |
| 451 | mDepthStencil.stencilBackWritemask = stencilBackWritemask; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 452 | mDirtyBits.set(DIRTY_BIT_STENCIL_WRITEMASK_BACK); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | void State::setStencilOperations(GLenum stencilFail, GLenum stencilPassDepthFail, GLenum stencilPassDepthPass) |
| 456 | { |
| 457 | mDepthStencil.stencilFail = stencilFail; |
| 458 | mDepthStencil.stencilPassDepthFail = stencilPassDepthFail; |
| 459 | mDepthStencil.stencilPassDepthPass = stencilPassDepthPass; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 460 | mDirtyBits.set(DIRTY_BIT_STENCIL_OPS_FRONT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | void State::setStencilBackOperations(GLenum stencilBackFail, GLenum stencilBackPassDepthFail, GLenum stencilBackPassDepthPass) |
| 464 | { |
| 465 | mDepthStencil.stencilBackFail = stencilBackFail; |
| 466 | mDepthStencil.stencilBackPassDepthFail = stencilBackPassDepthFail; |
| 467 | mDepthStencil.stencilBackPassDepthPass = stencilBackPassDepthPass; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 468 | mDirtyBits.set(DIRTY_BIT_STENCIL_OPS_BACK); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | GLint State::getStencilRef() const |
| 472 | { |
| 473 | return mStencilRef; |
| 474 | } |
| 475 | |
| 476 | GLint State::getStencilBackRef() const |
| 477 | { |
| 478 | return mStencilBackRef; |
| 479 | } |
| 480 | |
| 481 | bool State::isPolygonOffsetFillEnabled() const |
| 482 | { |
| 483 | return mRasterizer.polygonOffsetFill; |
| 484 | } |
| 485 | |
| 486 | void State::setPolygonOffsetFill(bool enabled) |
| 487 | { |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 488 | mRasterizer.polygonOffsetFill = enabled; |
| 489 | mDirtyBits.set(DIRTY_BIT_POLYGON_OFFSET_FILL_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | void State::setPolygonOffsetParams(GLfloat factor, GLfloat units) |
| 493 | { |
| 494 | // An application can pass NaN values here, so handle this gracefully |
| 495 | mRasterizer.polygonOffsetFactor = factor != factor ? 0.0f : factor; |
| 496 | mRasterizer.polygonOffsetUnits = units != units ? 0.0f : units; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 497 | mDirtyBits.set(DIRTY_BIT_POLYGON_OFFSET); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 498 | } |
| 499 | |
| 500 | bool State::isSampleAlphaToCoverageEnabled() const |
| 501 | { |
| 502 | return mBlend.sampleAlphaToCoverage; |
| 503 | } |
| 504 | |
| 505 | void State::setSampleAlphaToCoverage(bool enabled) |
| 506 | { |
| 507 | mBlend.sampleAlphaToCoverage = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 508 | mDirtyBits.set(DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | bool State::isSampleCoverageEnabled() const |
| 512 | { |
| 513 | return mSampleCoverage; |
| 514 | } |
| 515 | |
| 516 | void State::setSampleCoverage(bool enabled) |
| 517 | { |
| 518 | mSampleCoverage = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 519 | mDirtyBits.set(DIRTY_BIT_SAMPLE_COVERAGE_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 520 | } |
| 521 | |
| 522 | void State::setSampleCoverageParams(GLclampf value, bool invert) |
| 523 | { |
| 524 | mSampleCoverageValue = value; |
| 525 | mSampleCoverageInvert = invert; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 526 | mDirtyBits.set(DIRTY_BIT_SAMPLE_COVERAGE); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 527 | } |
| 528 | |
Geoff Lang | 0fbb600 | 2015-04-16 11:11:53 -0400 | [diff] [blame] | 529 | GLclampf State::getSampleCoverageValue() const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 530 | { |
Geoff Lang | 0fbb600 | 2015-04-16 11:11:53 -0400 | [diff] [blame] | 531 | return mSampleCoverageValue; |
| 532 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 533 | |
Geoff Lang | 0fbb600 | 2015-04-16 11:11:53 -0400 | [diff] [blame] | 534 | bool State::getSampleCoverageInvert() const |
| 535 | { |
| 536 | return mSampleCoverageInvert; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 537 | } |
| 538 | |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 539 | void State::setSampleAlphaToOne(bool enabled) |
| 540 | { |
| 541 | mSampleAlphaToOne = enabled; |
| 542 | mDirtyBits.set(DIRTY_BIT_SAMPLE_ALPHA_TO_ONE); |
| 543 | } |
| 544 | |
| 545 | bool State::isSampleAlphaToOneEnabled() const |
| 546 | { |
| 547 | return mSampleAlphaToOne; |
| 548 | } |
| 549 | |
| 550 | void State::setMultisampling(bool enabled) |
| 551 | { |
| 552 | mMultiSampling = enabled; |
| 553 | mDirtyBits.set(DIRTY_BIT_MULTISAMPLING); |
| 554 | } |
| 555 | |
| 556 | bool State::isMultisamplingEnabled() const |
| 557 | { |
| 558 | return mMultiSampling; |
| 559 | } |
| 560 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 561 | bool State::isScissorTestEnabled() const |
| 562 | { |
| 563 | return mScissorTest; |
| 564 | } |
| 565 | |
| 566 | void State::setScissorTest(bool enabled) |
| 567 | { |
| 568 | mScissorTest = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 569 | mDirtyBits.set(DIRTY_BIT_SCISSOR_TEST_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | void State::setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height) |
| 573 | { |
| 574 | mScissor.x = x; |
| 575 | mScissor.y = y; |
| 576 | mScissor.width = width; |
| 577 | mScissor.height = height; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 578 | mDirtyBits.set(DIRTY_BIT_SCISSOR); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 579 | } |
| 580 | |
| 581 | const Rectangle &State::getScissor() const |
| 582 | { |
| 583 | return mScissor; |
| 584 | } |
| 585 | |
| 586 | bool State::isDitherEnabled() const |
| 587 | { |
| 588 | return mBlend.dither; |
| 589 | } |
| 590 | |
| 591 | void State::setDither(bool enabled) |
| 592 | { |
| 593 | mBlend.dither = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 594 | mDirtyBits.set(DIRTY_BIT_DITHER_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 595 | } |
| 596 | |
Jamie Madill | b4b53c5 | 2015-02-03 15:22:48 -0500 | [diff] [blame] | 597 | bool State::isPrimitiveRestartEnabled() const |
| 598 | { |
| 599 | return mPrimitiveRestart; |
| 600 | } |
| 601 | |
| 602 | void State::setPrimitiveRestart(bool enabled) |
| 603 | { |
| 604 | mPrimitiveRestart = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 605 | mDirtyBits.set(DIRTY_BIT_PRIMITIVE_RESTART_ENABLED); |
Jamie Madill | b4b53c5 | 2015-02-03 15:22:48 -0500 | [diff] [blame] | 606 | } |
| 607 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 608 | void State::setEnableFeature(GLenum feature, bool enabled) |
| 609 | { |
| 610 | switch (feature) |
| 611 | { |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 612 | case GL_MULTISAMPLE_EXT: setMultisampling(enabled); break; |
| 613 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: setSampleAlphaToOne(enabled); break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 614 | case GL_CULL_FACE: setCullFace(enabled); break; |
| 615 | case GL_POLYGON_OFFSET_FILL: setPolygonOffsetFill(enabled); break; |
| 616 | case GL_SAMPLE_ALPHA_TO_COVERAGE: setSampleAlphaToCoverage(enabled); break; |
| 617 | case GL_SAMPLE_COVERAGE: setSampleCoverage(enabled); break; |
| 618 | case GL_SCISSOR_TEST: setScissorTest(enabled); break; |
| 619 | case GL_STENCIL_TEST: setStencilTest(enabled); break; |
| 620 | case GL_DEPTH_TEST: setDepthTest(enabled); break; |
| 621 | case GL_BLEND: setBlend(enabled); break; |
| 622 | case GL_DITHER: setDither(enabled); break; |
Jamie Madill | b4b53c5 | 2015-02-03 15:22:48 -0500 | [diff] [blame] | 623 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: setPrimitiveRestart(enabled); break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 624 | case GL_RASTERIZER_DISCARD: setRasterizerDiscard(enabled); break; |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 625 | case GL_SAMPLE_MASK: |
Geoff Lang | 9f09037 | 2016-12-02 10:20:43 -0500 | [diff] [blame] | 626 | if (enabled) |
| 627 | { |
| 628 | // Enabling this feature is not implemented yet. |
| 629 | UNIMPLEMENTED(); |
| 630 | } |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 631 | break; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 632 | case GL_DEBUG_OUTPUT_SYNCHRONOUS: |
| 633 | mDebug.setOutputSynchronous(enabled); |
| 634 | break; |
| 635 | case GL_DEBUG_OUTPUT: |
| 636 | mDebug.setOutputEnabled(enabled); |
| 637 | break; |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 638 | case GL_FRAMEBUFFER_SRGB_EXT: |
| 639 | setFramebufferSRGB(enabled); |
| 640 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 641 | default: UNREACHABLE(); |
| 642 | } |
| 643 | } |
| 644 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 645 | bool State::getEnableFeature(GLenum feature) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 646 | { |
| 647 | switch (feature) |
| 648 | { |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 649 | case GL_MULTISAMPLE_EXT: return isMultisamplingEnabled(); |
| 650 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: return isSampleAlphaToOneEnabled(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 651 | case GL_CULL_FACE: return isCullFaceEnabled(); |
| 652 | case GL_POLYGON_OFFSET_FILL: return isPolygonOffsetFillEnabled(); |
| 653 | case GL_SAMPLE_ALPHA_TO_COVERAGE: return isSampleAlphaToCoverageEnabled(); |
| 654 | case GL_SAMPLE_COVERAGE: return isSampleCoverageEnabled(); |
| 655 | case GL_SCISSOR_TEST: return isScissorTestEnabled(); |
| 656 | case GL_STENCIL_TEST: return isStencilTestEnabled(); |
| 657 | case GL_DEPTH_TEST: return isDepthTestEnabled(); |
| 658 | case GL_BLEND: return isBlendEnabled(); |
| 659 | case GL_DITHER: return isDitherEnabled(); |
Jamie Madill | b4b53c5 | 2015-02-03 15:22:48 -0500 | [diff] [blame] | 660 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: return isPrimitiveRestartEnabled(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 661 | case GL_RASTERIZER_DISCARD: return isRasterizerDiscardEnabled(); |
Geoff Lang | b5e997f | 2016-12-06 10:55:34 -0500 | [diff] [blame] | 662 | case GL_SAMPLE_MASK: |
| 663 | UNIMPLEMENTED(); |
| 664 | return false; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 665 | case GL_DEBUG_OUTPUT_SYNCHRONOUS: |
| 666 | return mDebug.isOutputSynchronous(); |
| 667 | case GL_DEBUG_OUTPUT: |
| 668 | return mDebug.isOutputEnabled(); |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 669 | case GL_BIND_GENERATES_RESOURCE_CHROMIUM: |
| 670 | return isBindGeneratesResourceEnabled(); |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 671 | case GL_CLIENT_ARRAYS_ANGLE: |
| 672 | return areClientArraysEnabled(); |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 673 | case GL_FRAMEBUFFER_SRGB_EXT: |
| 674 | return getFramebufferSRGB(); |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 675 | case GL_CONTEXT_ROBUST_RESOURCE_INITIALIZATION_ANGLE: |
| 676 | return mRobustResourceInit; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 677 | default: UNREACHABLE(); return false; |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | void State::setLineWidth(GLfloat width) |
| 682 | { |
| 683 | mLineWidth = width; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 684 | mDirtyBits.set(DIRTY_BIT_LINE_WIDTH); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 685 | } |
| 686 | |
Geoff Lang | 4b3f416 | 2015-04-16 13:22:05 -0400 | [diff] [blame] | 687 | float State::getLineWidth() const |
| 688 | { |
| 689 | return mLineWidth; |
| 690 | } |
| 691 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 692 | void State::setGenerateMipmapHint(GLenum hint) |
| 693 | { |
| 694 | mGenerateMipmapHint = hint; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 695 | mDirtyBits.set(DIRTY_BIT_GENERATE_MIPMAP_HINT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 696 | } |
| 697 | |
| 698 | void State::setFragmentShaderDerivativeHint(GLenum hint) |
| 699 | { |
| 700 | mFragmentShaderDerivativeHint = hint; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 701 | mDirtyBits.set(DIRTY_BIT_SHADER_DERIVATIVE_HINT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 702 | // TODO: Propagate the hint to shader translator so we can write |
| 703 | // ddx, ddx_coarse, or ddx_fine depending on the hint. |
| 704 | // Ignore for now. It is valid for implementations to ignore hint. |
| 705 | } |
| 706 | |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 707 | bool State::isBindGeneratesResourceEnabled() const |
| 708 | { |
| 709 | return mBindGeneratesResource; |
| 710 | } |
| 711 | |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 712 | bool State::areClientArraysEnabled() const |
| 713 | { |
| 714 | return mClientArraysEnabled; |
| 715 | } |
| 716 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 717 | void State::setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height) |
| 718 | { |
| 719 | mViewport.x = x; |
| 720 | mViewport.y = y; |
| 721 | mViewport.width = width; |
| 722 | mViewport.height = height; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 723 | mDirtyBits.set(DIRTY_BIT_VIEWPORT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 724 | } |
| 725 | |
| 726 | const Rectangle &State::getViewport() const |
| 727 | { |
| 728 | return mViewport; |
| 729 | } |
| 730 | |
| 731 | void State::setActiveSampler(unsigned int active) |
| 732 | { |
| 733 | mActiveSampler = active; |
| 734 | } |
| 735 | |
| 736 | unsigned int State::getActiveSampler() const |
| 737 | { |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 738 | return static_cast<unsigned int>(mActiveSampler); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 739 | } |
| 740 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 741 | void State::setSamplerTexture(GLenum type, Texture *texture) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 742 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 743 | mSamplerTextures[type][mActiveSampler].set(texture); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 744 | } |
| 745 | |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 746 | Texture *State::getTargetTexture(GLenum target) const |
| 747 | { |
| 748 | return getSamplerTexture(static_cast<unsigned int>(mActiveSampler), target); |
| 749 | } |
| 750 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 751 | Texture *State::getSamplerTexture(unsigned int sampler, GLenum type) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 752 | { |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 753 | const auto it = mSamplerTextures.find(type); |
| 754 | ASSERT(it != mSamplerTextures.end()); |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 755 | ASSERT(sampler < it->second.size()); |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 756 | return it->second[sampler].get(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 757 | } |
| 758 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 759 | GLuint State::getSamplerTextureId(unsigned int sampler, GLenum type) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 760 | { |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 761 | const auto it = mSamplerTextures.find(type); |
| 762 | ASSERT(it != mSamplerTextures.end()); |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 763 | ASSERT(sampler < it->second.size()); |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 764 | return it->second[sampler].id(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 765 | } |
| 766 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 767 | void State::detachTexture(const Context *context, const TextureMap &zeroTextures, GLuint texture) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 768 | { |
| 769 | // Textures have a detach method on State rather than a simple |
| 770 | // removeBinding, because the zero/null texture objects are managed |
| 771 | // separately, and don't have to go through the Context's maps or |
| 772 | // the ResourceManager. |
| 773 | |
| 774 | // [OpenGL ES 2.0.24] section 3.8 page 84: |
| 775 | // If a texture object is deleted, it is as if all texture units which are bound to that texture object are |
| 776 | // rebound to texture object zero |
| 777 | |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 778 | for (auto &bindingVec : mSamplerTextures) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 779 | { |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 780 | GLenum textureType = bindingVec.first; |
| 781 | TextureBindingVector &textureVector = bindingVec.second; |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 782 | for (size_t textureIdx = 0; textureIdx < textureVector.size(); textureIdx++) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 783 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 784 | BindingPointer<Texture> &binding = textureVector[textureIdx]; |
| 785 | if (binding.id() == texture) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 786 | { |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 787 | auto it = zeroTextures.find(textureType); |
| 788 | ASSERT(it != zeroTextures.end()); |
Jamie Madill | e6382c3 | 2014-11-07 15:05:26 -0500 | [diff] [blame] | 789 | // Zero textures are the "default" textures instead of NULL |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 790 | binding.set(it->second.get()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 791 | } |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | // [OpenGL ES 2.0.24] section 4.4 page 112: |
| 796 | // If a texture object is deleted while its image is attached to the currently bound framebuffer, then it is |
| 797 | // as if Texture2DAttachment had been called, with a texture of 0, for each attachment point to which this |
| 798 | // image was attached in the currently bound framebuffer. |
| 799 | |
| 800 | if (mReadFramebuffer) |
| 801 | { |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 802 | mReadFramebuffer->detachTexture(context, texture); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | if (mDrawFramebuffer) |
| 806 | { |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 807 | mDrawFramebuffer->detachTexture(context, texture); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 808 | } |
| 809 | } |
| 810 | |
Jamie Madill | e6382c3 | 2014-11-07 15:05:26 -0500 | [diff] [blame] | 811 | void State::initializeZeroTextures(const TextureMap &zeroTextures) |
| 812 | { |
| 813 | for (const auto &zeroTexture : zeroTextures) |
| 814 | { |
| 815 | auto &samplerTextureArray = mSamplerTextures[zeroTexture.first]; |
| 816 | |
| 817 | for (size_t textureUnit = 0; textureUnit < samplerTextureArray.size(); ++textureUnit) |
| 818 | { |
| 819 | samplerTextureArray[textureUnit].set(zeroTexture.second.get()); |
| 820 | } |
| 821 | } |
| 822 | } |
| 823 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 824 | void State::setSamplerBinding(GLuint textureUnit, Sampler *sampler) |
| 825 | { |
| 826 | mSamplers[textureUnit].set(sampler); |
| 827 | } |
| 828 | |
| 829 | GLuint State::getSamplerId(GLuint textureUnit) const |
| 830 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 831 | ASSERT(textureUnit < mSamplers.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 832 | return mSamplers[textureUnit].id(); |
| 833 | } |
| 834 | |
| 835 | Sampler *State::getSampler(GLuint textureUnit) const |
| 836 | { |
| 837 | return mSamplers[textureUnit].get(); |
| 838 | } |
| 839 | |
| 840 | void State::detachSampler(GLuint sampler) |
| 841 | { |
| 842 | // [OpenGL ES 3.0.2] section 3.8.2 pages 123-124: |
| 843 | // If a sampler object that is currently bound to one or more texture units is |
| 844 | // deleted, it is as though BindSampler is called once for each texture unit to |
| 845 | // which the sampler is bound, with unit set to the texture unit and sampler set to zero. |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 846 | for (size_t textureUnit = 0; textureUnit < mSamplers.size(); textureUnit++) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 847 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 848 | BindingPointer<Sampler> &samplerBinding = mSamplers[textureUnit]; |
| 849 | if (samplerBinding.id() == sampler) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 850 | { |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 851 | samplerBinding.set(nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 852 | } |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | void State::setRenderbufferBinding(Renderbuffer *renderbuffer) |
| 857 | { |
| 858 | mRenderbuffer.set(renderbuffer); |
| 859 | } |
| 860 | |
| 861 | GLuint State::getRenderbufferId() const |
| 862 | { |
| 863 | return mRenderbuffer.id(); |
| 864 | } |
| 865 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 866 | Renderbuffer *State::getCurrentRenderbuffer() const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 867 | { |
| 868 | return mRenderbuffer.get(); |
| 869 | } |
| 870 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 871 | void State::detachRenderbuffer(const Context *context, GLuint renderbuffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 872 | { |
| 873 | // [OpenGL ES 2.0.24] section 4.4 page 109: |
| 874 | // If a renderbuffer that is currently bound to RENDERBUFFER is deleted, it is as though BindRenderbuffer |
| 875 | // had been executed with the target RENDERBUFFER and name of zero. |
| 876 | |
| 877 | if (mRenderbuffer.id() == renderbuffer) |
| 878 | { |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 879 | mRenderbuffer.set(nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | // [OpenGL ES 2.0.24] section 4.4 page 111: |
| 883 | // If a renderbuffer object is deleted while its image is attached to the currently bound framebuffer, |
| 884 | // then it is as if FramebufferRenderbuffer had been called, with a renderbuffer of 0, for each attachment |
| 885 | // point to which this image was attached in the currently bound framebuffer. |
| 886 | |
| 887 | Framebuffer *readFramebuffer = mReadFramebuffer; |
| 888 | Framebuffer *drawFramebuffer = mDrawFramebuffer; |
| 889 | |
| 890 | if (readFramebuffer) |
| 891 | { |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 892 | readFramebuffer->detachRenderbuffer(context, renderbuffer); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | if (drawFramebuffer && drawFramebuffer != readFramebuffer) |
| 896 | { |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 897 | drawFramebuffer->detachRenderbuffer(context, renderbuffer); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 898 | } |
| 899 | |
| 900 | } |
| 901 | |
| 902 | void State::setReadFramebufferBinding(Framebuffer *framebuffer) |
| 903 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 904 | if (mReadFramebuffer == framebuffer) |
| 905 | return; |
| 906 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 907 | mReadFramebuffer = framebuffer; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 908 | mDirtyBits.set(DIRTY_BIT_READ_FRAMEBUFFER_BINDING); |
| 909 | |
| 910 | if (mReadFramebuffer && mReadFramebuffer->hasAnyDirtyBit()) |
| 911 | { |
| 912 | mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
| 913 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | void State::setDrawFramebufferBinding(Framebuffer *framebuffer) |
| 917 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 918 | if (mDrawFramebuffer == framebuffer) |
| 919 | return; |
| 920 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 921 | mDrawFramebuffer = framebuffer; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 922 | mDirtyBits.set(DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING); |
| 923 | |
| 924 | if (mDrawFramebuffer && mDrawFramebuffer->hasAnyDirtyBit()) |
| 925 | { |
| 926 | mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
| 927 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | Framebuffer *State::getTargetFramebuffer(GLenum target) const |
| 931 | { |
| 932 | switch (target) |
| 933 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 934 | case GL_READ_FRAMEBUFFER_ANGLE: |
| 935 | return mReadFramebuffer; |
| 936 | case GL_DRAW_FRAMEBUFFER_ANGLE: |
| 937 | case GL_FRAMEBUFFER: |
| 938 | return mDrawFramebuffer; |
| 939 | default: |
| 940 | UNREACHABLE(); |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 941 | return nullptr; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 942 | } |
| 943 | } |
| 944 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 945 | Framebuffer *State::getReadFramebuffer() const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 946 | { |
| 947 | return mReadFramebuffer; |
| 948 | } |
| 949 | |
Jamie Madill | 51f40ec | 2016-06-15 14:06:00 -0400 | [diff] [blame] | 950 | Framebuffer *State::getDrawFramebuffer() const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 951 | { |
| 952 | return mDrawFramebuffer; |
| 953 | } |
| 954 | |
| 955 | bool State::removeReadFramebufferBinding(GLuint framebuffer) |
| 956 | { |
Jamie Madill | 77a72f6 | 2015-04-14 11:18:32 -0400 | [diff] [blame] | 957 | if (mReadFramebuffer != nullptr && |
| 958 | mReadFramebuffer->id() == framebuffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 959 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 960 | setReadFramebufferBinding(nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 961 | return true; |
| 962 | } |
| 963 | |
| 964 | return false; |
| 965 | } |
| 966 | |
| 967 | bool State::removeDrawFramebufferBinding(GLuint framebuffer) |
| 968 | { |
Jamie Madill | 77a72f6 | 2015-04-14 11:18:32 -0400 | [diff] [blame] | 969 | if (mReadFramebuffer != nullptr && |
| 970 | mDrawFramebuffer->id() == framebuffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 971 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 972 | setDrawFramebufferBinding(nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 973 | return true; |
| 974 | } |
| 975 | |
| 976 | return false; |
| 977 | } |
| 978 | |
| 979 | void State::setVertexArrayBinding(VertexArray *vertexArray) |
| 980 | { |
| 981 | mVertexArray = vertexArray; |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 982 | mDirtyBits.set(DIRTY_BIT_VERTEX_ARRAY_BINDING); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 983 | |
| 984 | if (mVertexArray && mVertexArray->hasAnyDirtyBit()) |
| 985 | { |
| 986 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 987 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | GLuint State::getVertexArrayId() const |
| 991 | { |
Yunchao He | 4f28544 | 2017-04-21 12:15:49 +0800 | [diff] [blame] | 992 | ASSERT(mVertexArray != nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 993 | return mVertexArray->id(); |
| 994 | } |
| 995 | |
| 996 | VertexArray *State::getVertexArray() const |
| 997 | { |
Yunchao He | 4f28544 | 2017-04-21 12:15:49 +0800 | [diff] [blame] | 998 | ASSERT(mVertexArray != nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 999 | return mVertexArray; |
| 1000 | } |
| 1001 | |
| 1002 | bool State::removeVertexArrayBinding(GLuint vertexArray) |
| 1003 | { |
| 1004 | if (mVertexArray->id() == vertexArray) |
| 1005 | { |
Yunchao He | d7297bf | 2017-04-19 15:27:10 +0800 | [diff] [blame] | 1006 | mVertexArray = nullptr; |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 1007 | mDirtyBits.set(DIRTY_BIT_VERTEX_ARRAY_BINDING); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 1008 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1009 | return true; |
| 1010 | } |
| 1011 | |
| 1012 | return false; |
| 1013 | } |
| 1014 | |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1015 | void State::setElementArrayBuffer(Buffer *buffer) |
| 1016 | { |
| 1017 | getVertexArray()->setElementArrayBuffer(buffer); |
| 1018 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1019 | } |
| 1020 | |
| 1021 | void State::bindVertexBuffer(GLuint bindingIndex, |
| 1022 | Buffer *boundBuffer, |
| 1023 | GLintptr offset, |
| 1024 | GLsizei stride) |
| 1025 | { |
| 1026 | getVertexArray()->bindVertexBuffer(bindingIndex, boundBuffer, offset, stride); |
| 1027 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1028 | } |
| 1029 | |
| 1030 | void State::setVertexAttribBinding(GLuint attribIndex, GLuint bindingIndex) |
| 1031 | { |
| 1032 | getVertexArray()->setVertexAttribBinding(attribIndex, bindingIndex); |
| 1033 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1034 | } |
| 1035 | |
| 1036 | void State::setVertexAttribFormat(GLuint attribIndex, |
| 1037 | GLint size, |
| 1038 | GLenum type, |
| 1039 | bool normalized, |
| 1040 | bool pureInteger, |
| 1041 | GLuint relativeOffset) |
| 1042 | { |
| 1043 | getVertexArray()->setVertexAttribFormat(attribIndex, size, type, normalized, pureInteger, |
| 1044 | relativeOffset); |
| 1045 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1046 | } |
| 1047 | |
| 1048 | void State::setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor) |
| 1049 | { |
| 1050 | getVertexArray()->setVertexBindingDivisor(bindingIndex, divisor); |
| 1051 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1052 | } |
| 1053 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 1054 | void State::setProgram(const Context *context, Program *newProgram) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1055 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1056 | if (mProgram != newProgram) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1057 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1058 | if (mProgram) |
| 1059 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 1060 | mProgram->release(context); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | mProgram = newProgram; |
| 1064 | |
| 1065 | if (mProgram) |
| 1066 | { |
| 1067 | newProgram->addRef(); |
| 1068 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1069 | } |
| 1070 | } |
| 1071 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1072 | Program *State::getProgram() const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1073 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1074 | return mProgram; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1075 | } |
| 1076 | |
| 1077 | void State::setTransformFeedbackBinding(TransformFeedback *transformFeedback) |
| 1078 | { |
| 1079 | mTransformFeedback.set(transformFeedback); |
| 1080 | } |
| 1081 | |
| 1082 | TransformFeedback *State::getCurrentTransformFeedback() const |
| 1083 | { |
| 1084 | return mTransformFeedback.get(); |
| 1085 | } |
| 1086 | |
Gregoire Payen de La Garanderie | 5274202 | 2015-02-04 14:55:39 +0000 | [diff] [blame] | 1087 | bool State::isTransformFeedbackActiveUnpaused() const |
| 1088 | { |
| 1089 | gl::TransformFeedback *curTransformFeedback = getCurrentTransformFeedback(); |
Geoff Lang | bb0a0bb | 2015-03-27 12:16:57 -0400 | [diff] [blame] | 1090 | return curTransformFeedback && curTransformFeedback->isActive() && !curTransformFeedback->isPaused(); |
Gregoire Payen de La Garanderie | 5274202 | 2015-02-04 14:55:39 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 1093 | bool State::removeTransformFeedbackBinding(GLuint transformFeedback) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1094 | { |
| 1095 | if (mTransformFeedback.id() == transformFeedback) |
| 1096 | { |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 1097 | mTransformFeedback.set(nullptr); |
| 1098 | return true; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1099 | } |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 1100 | |
| 1101 | return false; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1102 | } |
| 1103 | |
Olli Etuaho | bbf1c10 | 2016-06-28 13:31:33 +0300 | [diff] [blame] | 1104 | bool State::isQueryActive(const GLenum type) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1105 | { |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1106 | for (auto &iter : mActiveQueries) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1107 | { |
Olli Etuaho | bbf1c10 | 2016-06-28 13:31:33 +0300 | [diff] [blame] | 1108 | const Query *query = iter.second.get(); |
| 1109 | if (query != nullptr && ActiveQueryType(query->getType()) == ActiveQueryType(type)) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1110 | { |
| 1111 | return true; |
| 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | return false; |
| 1116 | } |
| 1117 | |
| 1118 | bool State::isQueryActive(Query *query) const |
| 1119 | { |
| 1120 | for (auto &iter : mActiveQueries) |
| 1121 | { |
| 1122 | if (iter.second.get() == query) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1123 | { |
| 1124 | return true; |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | return false; |
| 1129 | } |
| 1130 | |
| 1131 | void State::setActiveQuery(GLenum target, Query *query) |
| 1132 | { |
| 1133 | mActiveQueries[target].set(query); |
| 1134 | } |
| 1135 | |
| 1136 | GLuint State::getActiveQueryId(GLenum target) const |
| 1137 | { |
| 1138 | const Query *query = getActiveQuery(target); |
| 1139 | return (query ? query->id() : 0u); |
| 1140 | } |
| 1141 | |
| 1142 | Query *State::getActiveQuery(GLenum target) const |
| 1143 | { |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 1144 | const auto it = mActiveQueries.find(target); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1145 | |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 1146 | // All query types should already exist in the activeQueries map |
| 1147 | ASSERT(it != mActiveQueries.end()); |
| 1148 | |
| 1149 | return it->second.get(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | void State::setArrayBufferBinding(Buffer *buffer) |
| 1153 | { |
| 1154 | mArrayBuffer.set(buffer); |
| 1155 | } |
| 1156 | |
| 1157 | GLuint State::getArrayBufferId() const |
| 1158 | { |
| 1159 | return mArrayBuffer.id(); |
| 1160 | } |
| 1161 | |
Jiajia Qin | 9d7d0b1 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1162 | void State::setDrawIndirectBufferBinding(Buffer *buffer) |
| 1163 | { |
| 1164 | mDrawIndirectBuffer.set(buffer); |
| 1165 | mDirtyBits.set(DIRTY_BIT_DRAW_INDIRECT_BUFFER_BINDING); |
| 1166 | } |
| 1167 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1168 | void State::setGenericUniformBufferBinding(Buffer *buffer) |
| 1169 | { |
| 1170 | mGenericUniformBuffer.set(buffer); |
| 1171 | } |
| 1172 | |
| 1173 | void State::setIndexedUniformBufferBinding(GLuint index, Buffer *buffer, GLintptr offset, GLsizeiptr size) |
| 1174 | { |
| 1175 | mUniformBuffers[index].set(buffer, offset, size); |
| 1176 | } |
| 1177 | |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 1178 | const OffsetBindingPointer<Buffer> &State::getIndexedUniformBuffer(size_t index) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1179 | { |
Shannon Woods | f3acaf9 | 2014-09-23 18:07:11 -0400 | [diff] [blame] | 1180 | ASSERT(static_cast<size_t>(index) < mUniformBuffers.size()); |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 1181 | return mUniformBuffers[index]; |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1182 | } |
| 1183 | |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1184 | void State::setGenericAtomicCounterBufferBinding(Buffer *buffer) |
| 1185 | { |
| 1186 | mGenericAtomicCounterBuffer.set(buffer); |
| 1187 | } |
| 1188 | |
| 1189 | void State::setIndexedAtomicCounterBufferBinding(GLuint index, |
| 1190 | Buffer *buffer, |
| 1191 | GLintptr offset, |
| 1192 | GLsizeiptr size) |
| 1193 | { |
| 1194 | ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size()); |
| 1195 | mAtomicCounterBuffers[index].set(buffer, offset, size); |
| 1196 | } |
| 1197 | |
| 1198 | const OffsetBindingPointer<Buffer> &State::getIndexedAtomicCounterBuffer(size_t index) const |
| 1199 | { |
| 1200 | ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size()); |
| 1201 | return mAtomicCounterBuffers[index]; |
| 1202 | } |
| 1203 | |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1204 | void State::setGenericShaderStorageBufferBinding(Buffer *buffer) |
| 1205 | { |
| 1206 | mGenericShaderStorageBuffer.set(buffer); |
| 1207 | } |
| 1208 | |
| 1209 | void State::setIndexedShaderStorageBufferBinding(GLuint index, |
| 1210 | Buffer *buffer, |
| 1211 | GLintptr offset, |
| 1212 | GLsizeiptr size) |
| 1213 | { |
| 1214 | ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size()); |
| 1215 | mShaderStorageBuffers[index].set(buffer, offset, size); |
| 1216 | } |
| 1217 | |
| 1218 | const OffsetBindingPointer<Buffer> &State::getIndexedShaderStorageBuffer(size_t index) const |
| 1219 | { |
| 1220 | ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size()); |
| 1221 | return mShaderStorageBuffers[index]; |
| 1222 | } |
| 1223 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1224 | void State::setCopyReadBufferBinding(Buffer *buffer) |
| 1225 | { |
| 1226 | mCopyReadBuffer.set(buffer); |
| 1227 | } |
| 1228 | |
| 1229 | void State::setCopyWriteBufferBinding(Buffer *buffer) |
| 1230 | { |
| 1231 | mCopyWriteBuffer.set(buffer); |
| 1232 | } |
| 1233 | |
| 1234 | void State::setPixelPackBufferBinding(Buffer *buffer) |
| 1235 | { |
| 1236 | mPack.pixelBuffer.set(buffer); |
Corentin Wallez | bbd663a | 2016-04-20 17:49:17 -0400 | [diff] [blame] | 1237 | mDirtyBits.set(DIRTY_BIT_PACK_BUFFER_BINDING); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1238 | } |
| 1239 | |
| 1240 | void State::setPixelUnpackBufferBinding(Buffer *buffer) |
| 1241 | { |
| 1242 | mUnpack.pixelBuffer.set(buffer); |
Corentin Wallez | bbd663a | 2016-04-20 17:49:17 -0400 | [diff] [blame] | 1243 | mDirtyBits.set(DIRTY_BIT_UNPACK_BUFFER_BINDING); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | Buffer *State::getTargetBuffer(GLenum target) const |
| 1247 | { |
| 1248 | switch (target) |
| 1249 | { |
| 1250 | case GL_ARRAY_BUFFER: return mArrayBuffer.get(); |
| 1251 | case GL_COPY_READ_BUFFER: return mCopyReadBuffer.get(); |
| 1252 | case GL_COPY_WRITE_BUFFER: return mCopyWriteBuffer.get(); |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 1253 | case GL_ELEMENT_ARRAY_BUFFER: return getVertexArray()->getElementArrayBuffer().get(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1254 | case GL_PIXEL_PACK_BUFFER: return mPack.pixelBuffer.get(); |
| 1255 | case GL_PIXEL_UNPACK_BUFFER: return mUnpack.pixelBuffer.get(); |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 1256 | case GL_TRANSFORM_FEEDBACK_BUFFER: return mTransformFeedback->getGenericBuffer().get(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1257 | case GL_UNIFORM_BUFFER: return mGenericUniformBuffer.get(); |
Geoff Lang | b5e997f | 2016-12-06 10:55:34 -0500 | [diff] [blame] | 1258 | case GL_ATOMIC_COUNTER_BUFFER: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1259 | return mGenericAtomicCounterBuffer.get(); |
Geoff Lang | b5e997f | 2016-12-06 10:55:34 -0500 | [diff] [blame] | 1260 | case GL_SHADER_STORAGE_BUFFER: |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1261 | return mGenericShaderStorageBuffer.get(); |
Geoff Lang | b5e997f | 2016-12-06 10:55:34 -0500 | [diff] [blame] | 1262 | case GL_DRAW_INDIRECT_BUFFER: |
Jiajia Qin | 9d7d0b1 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1263 | return mDrawIndirectBuffer.get(); |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 1264 | default: |
| 1265 | UNREACHABLE(); |
| 1266 | return nullptr; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1267 | } |
| 1268 | } |
| 1269 | |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 1270 | void State::detachBuffer(GLuint bufferName) |
| 1271 | { |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1272 | BindingPointer<Buffer> *buffers[] = { |
| 1273 | &mArrayBuffer, &mGenericAtomicCounterBuffer, &mCopyReadBuffer, |
| 1274 | &mCopyWriteBuffer, &mDrawIndirectBuffer, &mPack.pixelBuffer, |
| 1275 | &mUnpack.pixelBuffer, &mGenericUniformBuffer, &mGenericShaderStorageBuffer}; |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 1276 | for (auto buffer : buffers) |
| 1277 | { |
| 1278 | if (buffer->id() == bufferName) |
| 1279 | { |
| 1280 | buffer->set(nullptr); |
| 1281 | } |
| 1282 | } |
| 1283 | |
| 1284 | TransformFeedback *curTransformFeedback = getCurrentTransformFeedback(); |
| 1285 | if (curTransformFeedback) |
| 1286 | { |
| 1287 | curTransformFeedback->detachBuffer(bufferName); |
| 1288 | } |
| 1289 | |
| 1290 | getVertexArray()->detachBuffer(bufferName); |
| 1291 | } |
| 1292 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1293 | void State::setEnableVertexAttribArray(unsigned int attribNum, bool enabled) |
| 1294 | { |
| 1295 | getVertexArray()->enableAttribute(attribNum, enabled); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 1296 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1297 | } |
| 1298 | |
| 1299 | void State::setVertexAttribf(GLuint index, const GLfloat values[4]) |
| 1300 | { |
Shannon Woods | 23e0500 | 2014-09-22 19:07:27 -0400 | [diff] [blame] | 1301 | ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1302 | mVertexAttribCurrentValues[index].setFloatValues(values); |
Jamie Madill | 1e0bc3a | 2015-08-11 08:12:21 -0400 | [diff] [blame] | 1303 | mDirtyBits.set(DIRTY_BIT_CURRENT_VALUE_0 + index); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1304 | } |
| 1305 | |
| 1306 | void State::setVertexAttribu(GLuint index, const GLuint values[4]) |
| 1307 | { |
Shannon Woods | 23e0500 | 2014-09-22 19:07:27 -0400 | [diff] [blame] | 1308 | ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1309 | mVertexAttribCurrentValues[index].setUnsignedIntValues(values); |
Jamie Madill | 1e0bc3a | 2015-08-11 08:12:21 -0400 | [diff] [blame] | 1310 | mDirtyBits.set(DIRTY_BIT_CURRENT_VALUE_0 + index); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1311 | } |
| 1312 | |
| 1313 | void State::setVertexAttribi(GLuint index, const GLint values[4]) |
| 1314 | { |
Shannon Woods | 23e0500 | 2014-09-22 19:07:27 -0400 | [diff] [blame] | 1315 | ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1316 | mVertexAttribCurrentValues[index].setIntValues(values); |
Jamie Madill | 1e0bc3a | 2015-08-11 08:12:21 -0400 | [diff] [blame] | 1317 | mDirtyBits.set(DIRTY_BIT_CURRENT_VALUE_0 + index); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1318 | } |
| 1319 | |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 1320 | void State::setVertexAttribState(unsigned int attribNum, |
| 1321 | Buffer *boundBuffer, |
| 1322 | GLint size, |
| 1323 | GLenum type, |
| 1324 | bool normalized, |
| 1325 | bool pureInteger, |
| 1326 | GLsizei stride, |
| 1327 | const void *pointer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1328 | { |
| 1329 | getVertexArray()->setAttributeState(attribNum, boundBuffer, size, type, normalized, pureInteger, stride, pointer); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 1330 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 1331 | } |
| 1332 | |
| 1333 | void State::setVertexAttribDivisor(GLuint index, GLuint divisor) |
| 1334 | { |
| 1335 | getVertexArray()->setVertexAttribDivisor(index, divisor); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 1336 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1337 | } |
| 1338 | |
Jamie Madill | 6de5185 | 2017-04-12 09:53:01 -0400 | [diff] [blame] | 1339 | const VertexAttribCurrentValueData &State::getVertexAttribCurrentValue(size_t attribNum) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1340 | { |
Jamie Madill | 6de5185 | 2017-04-12 09:53:01 -0400 | [diff] [blame] | 1341 | ASSERT(attribNum < mVertexAttribCurrentValues.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1342 | return mVertexAttribCurrentValues[attribNum]; |
| 1343 | } |
| 1344 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1345 | const void *State::getVertexAttribPointer(unsigned int attribNum) const |
| 1346 | { |
| 1347 | return getVertexArray()->getVertexAttribute(attribNum).pointer; |
| 1348 | } |
| 1349 | |
| 1350 | void State::setPackAlignment(GLint alignment) |
| 1351 | { |
| 1352 | mPack.alignment = alignment; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1353 | mDirtyBits.set(DIRTY_BIT_PACK_ALIGNMENT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | GLint State::getPackAlignment() const |
| 1357 | { |
| 1358 | return mPack.alignment; |
| 1359 | } |
| 1360 | |
| 1361 | void State::setPackReverseRowOrder(bool reverseRowOrder) |
| 1362 | { |
| 1363 | mPack.reverseRowOrder = reverseRowOrder; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1364 | mDirtyBits.set(DIRTY_BIT_PACK_REVERSE_ROW_ORDER); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | bool State::getPackReverseRowOrder() const |
| 1368 | { |
| 1369 | return mPack.reverseRowOrder; |
| 1370 | } |
| 1371 | |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1372 | void State::setPackRowLength(GLint rowLength) |
| 1373 | { |
| 1374 | mPack.rowLength = rowLength; |
| 1375 | mDirtyBits.set(DIRTY_BIT_PACK_ROW_LENGTH); |
| 1376 | } |
| 1377 | |
| 1378 | GLint State::getPackRowLength() const |
| 1379 | { |
| 1380 | return mPack.rowLength; |
| 1381 | } |
| 1382 | |
| 1383 | void State::setPackSkipRows(GLint skipRows) |
| 1384 | { |
| 1385 | mPack.skipRows = skipRows; |
| 1386 | mDirtyBits.set(DIRTY_BIT_PACK_SKIP_ROWS); |
| 1387 | } |
| 1388 | |
| 1389 | GLint State::getPackSkipRows() const |
| 1390 | { |
| 1391 | return mPack.skipRows; |
| 1392 | } |
| 1393 | |
| 1394 | void State::setPackSkipPixels(GLint skipPixels) |
| 1395 | { |
| 1396 | mPack.skipPixels = skipPixels; |
| 1397 | mDirtyBits.set(DIRTY_BIT_PACK_SKIP_PIXELS); |
| 1398 | } |
| 1399 | |
| 1400 | GLint State::getPackSkipPixels() const |
| 1401 | { |
| 1402 | return mPack.skipPixels; |
| 1403 | } |
| 1404 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1405 | const PixelPackState &State::getPackState() const |
| 1406 | { |
| 1407 | return mPack; |
| 1408 | } |
| 1409 | |
Jamie Madill | 87de362 | 2015-03-16 10:41:44 -0400 | [diff] [blame] | 1410 | PixelPackState &State::getPackState() |
| 1411 | { |
| 1412 | return mPack; |
| 1413 | } |
| 1414 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1415 | void State::setUnpackAlignment(GLint alignment) |
| 1416 | { |
| 1417 | mUnpack.alignment = alignment; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1418 | mDirtyBits.set(DIRTY_BIT_UNPACK_ALIGNMENT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1419 | } |
| 1420 | |
| 1421 | GLint State::getUnpackAlignment() const |
| 1422 | { |
| 1423 | return mUnpack.alignment; |
| 1424 | } |
| 1425 | |
Minmin Gong | b8aee3b | 2015-01-27 14:42:36 -0800 | [diff] [blame] | 1426 | void State::setUnpackRowLength(GLint rowLength) |
| 1427 | { |
| 1428 | mUnpack.rowLength = rowLength; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1429 | mDirtyBits.set(DIRTY_BIT_UNPACK_ROW_LENGTH); |
Minmin Gong | b8aee3b | 2015-01-27 14:42:36 -0800 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | GLint State::getUnpackRowLength() const |
| 1433 | { |
| 1434 | return mUnpack.rowLength; |
| 1435 | } |
| 1436 | |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1437 | void State::setUnpackImageHeight(GLint imageHeight) |
| 1438 | { |
| 1439 | mUnpack.imageHeight = imageHeight; |
| 1440 | mDirtyBits.set(DIRTY_BIT_UNPACK_IMAGE_HEIGHT); |
| 1441 | } |
| 1442 | |
| 1443 | GLint State::getUnpackImageHeight() const |
| 1444 | { |
| 1445 | return mUnpack.imageHeight; |
| 1446 | } |
| 1447 | |
| 1448 | void State::setUnpackSkipImages(GLint skipImages) |
| 1449 | { |
| 1450 | mUnpack.skipImages = skipImages; |
| 1451 | mDirtyBits.set(DIRTY_BIT_UNPACK_SKIP_IMAGES); |
| 1452 | } |
| 1453 | |
| 1454 | GLint State::getUnpackSkipImages() const |
| 1455 | { |
| 1456 | return mUnpack.skipImages; |
| 1457 | } |
| 1458 | |
| 1459 | void State::setUnpackSkipRows(GLint skipRows) |
| 1460 | { |
| 1461 | mUnpack.skipRows = skipRows; |
| 1462 | mDirtyBits.set(DIRTY_BIT_UNPACK_SKIP_ROWS); |
| 1463 | } |
| 1464 | |
| 1465 | GLint State::getUnpackSkipRows() const |
| 1466 | { |
| 1467 | return mUnpack.skipRows; |
| 1468 | } |
| 1469 | |
| 1470 | void State::setUnpackSkipPixels(GLint skipPixels) |
| 1471 | { |
| 1472 | mUnpack.skipPixels = skipPixels; |
| 1473 | mDirtyBits.set(DIRTY_BIT_UNPACK_SKIP_PIXELS); |
| 1474 | } |
| 1475 | |
| 1476 | GLint State::getUnpackSkipPixels() const |
| 1477 | { |
| 1478 | return mUnpack.skipPixels; |
| 1479 | } |
| 1480 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1481 | const PixelUnpackState &State::getUnpackState() const |
| 1482 | { |
| 1483 | return mUnpack; |
| 1484 | } |
| 1485 | |
Jamie Madill | 67102f0 | 2015-03-16 10:41:42 -0400 | [diff] [blame] | 1486 | PixelUnpackState &State::getUnpackState() |
| 1487 | { |
| 1488 | return mUnpack; |
| 1489 | } |
| 1490 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1491 | const Debug &State::getDebug() const |
| 1492 | { |
| 1493 | return mDebug; |
| 1494 | } |
| 1495 | |
| 1496 | Debug &State::getDebug() |
| 1497 | { |
| 1498 | return mDebug; |
| 1499 | } |
| 1500 | |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 1501 | void State::setCoverageModulation(GLenum components) |
| 1502 | { |
| 1503 | mCoverageModulation = components; |
| 1504 | mDirtyBits.set(DIRTY_BIT_COVERAGE_MODULATION); |
| 1505 | } |
| 1506 | |
| 1507 | GLenum State::getCoverageModulation() const |
| 1508 | { |
| 1509 | return mCoverageModulation; |
| 1510 | } |
| 1511 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1512 | void State::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix) |
| 1513 | { |
| 1514 | if (matrixMode == GL_PATH_MODELVIEW_CHROMIUM) |
| 1515 | { |
| 1516 | memcpy(mPathMatrixMV, matrix, 16 * sizeof(GLfloat)); |
| 1517 | mDirtyBits.set(DIRTY_BIT_PATH_RENDERING_MATRIX_MV); |
| 1518 | } |
| 1519 | else if (matrixMode == GL_PATH_PROJECTION_CHROMIUM) |
| 1520 | { |
| 1521 | memcpy(mPathMatrixProj, matrix, 16 * sizeof(GLfloat)); |
| 1522 | mDirtyBits.set(DIRTY_BIT_PATH_RENDERING_MATRIX_PROJ); |
| 1523 | } |
| 1524 | else |
| 1525 | { |
| 1526 | UNREACHABLE(); |
| 1527 | } |
| 1528 | } |
| 1529 | |
| 1530 | const GLfloat *State::getPathRenderingMatrix(GLenum which) const |
| 1531 | { |
| 1532 | if (which == GL_PATH_MODELVIEW_MATRIX_CHROMIUM) |
| 1533 | { |
| 1534 | return mPathMatrixMV; |
| 1535 | } |
| 1536 | else if (which == GL_PATH_PROJECTION_MATRIX_CHROMIUM) |
| 1537 | { |
| 1538 | return mPathMatrixProj; |
| 1539 | } |
| 1540 | |
| 1541 | UNREACHABLE(); |
| 1542 | return nullptr; |
| 1543 | } |
| 1544 | |
| 1545 | void State::setPathStencilFunc(GLenum func, GLint ref, GLuint mask) |
| 1546 | { |
| 1547 | mPathStencilFunc = func; |
| 1548 | mPathStencilRef = ref; |
| 1549 | mPathStencilMask = mask; |
| 1550 | mDirtyBits.set(DIRTY_BIT_PATH_RENDERING_STENCIL_STATE); |
| 1551 | } |
| 1552 | |
| 1553 | GLenum State::getPathStencilFunc() const |
| 1554 | { |
| 1555 | return mPathStencilFunc; |
| 1556 | } |
| 1557 | |
| 1558 | GLint State::getPathStencilRef() const |
| 1559 | { |
| 1560 | return mPathStencilRef; |
| 1561 | } |
| 1562 | |
| 1563 | GLuint State::getPathStencilMask() const |
| 1564 | { |
| 1565 | return mPathStencilMask; |
| 1566 | } |
| 1567 | |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 1568 | void State::setFramebufferSRGB(bool sRGB) |
| 1569 | { |
| 1570 | mFramebufferSRGB = sRGB; |
| 1571 | mDirtyBits.set(DIRTY_BIT_FRAMEBUFFER_SRGB); |
| 1572 | } |
| 1573 | |
| 1574 | bool State::getFramebufferSRGB() const |
| 1575 | { |
| 1576 | return mFramebufferSRGB; |
| 1577 | } |
| 1578 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1579 | void State::getBooleanv(GLenum pname, GLboolean *params) |
| 1580 | { |
| 1581 | switch (pname) |
| 1582 | { |
| 1583 | case GL_SAMPLE_COVERAGE_INVERT: *params = mSampleCoverageInvert; break; |
| 1584 | case GL_DEPTH_WRITEMASK: *params = mDepthStencil.depthMask; break; |
| 1585 | case GL_COLOR_WRITEMASK: |
| 1586 | params[0] = mBlend.colorMaskRed; |
| 1587 | params[1] = mBlend.colorMaskGreen; |
| 1588 | params[2] = mBlend.colorMaskBlue; |
| 1589 | params[3] = mBlend.colorMaskAlpha; |
| 1590 | break; |
| 1591 | case GL_CULL_FACE: *params = mRasterizer.cullFace; break; |
| 1592 | case GL_POLYGON_OFFSET_FILL: *params = mRasterizer.polygonOffsetFill; break; |
| 1593 | case GL_SAMPLE_ALPHA_TO_COVERAGE: *params = mBlend.sampleAlphaToCoverage; break; |
| 1594 | case GL_SAMPLE_COVERAGE: *params = mSampleCoverage; break; |
| 1595 | case GL_SCISSOR_TEST: *params = mScissorTest; break; |
| 1596 | case GL_STENCIL_TEST: *params = mDepthStencil.stencilTest; break; |
| 1597 | case GL_DEPTH_TEST: *params = mDepthStencil.depthTest; break; |
| 1598 | case GL_BLEND: *params = mBlend.blend; break; |
| 1599 | case GL_DITHER: *params = mBlend.dither; break; |
Geoff Lang | bb0a0bb | 2015-03-27 12:16:57 -0400 | [diff] [blame] | 1600 | case GL_TRANSFORM_FEEDBACK_ACTIVE: *params = getCurrentTransformFeedback()->isActive() ? GL_TRUE : GL_FALSE; break; |
| 1601 | case GL_TRANSFORM_FEEDBACK_PAUSED: *params = getCurrentTransformFeedback()->isPaused() ? GL_TRUE : GL_FALSE; break; |
Jamie Madill | e2cd53d | 2015-10-27 11:15:46 -0400 | [diff] [blame] | 1602 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: |
| 1603 | *params = mPrimitiveRestart; |
| 1604 | break; |
Geoff Lang | ab831f0 | 2015-12-01 09:39:10 -0500 | [diff] [blame] | 1605 | case GL_RASTERIZER_DISCARD: |
| 1606 | *params = isRasterizerDiscardEnabled() ? GL_TRUE : GL_FALSE; |
| 1607 | break; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1608 | case GL_DEBUG_OUTPUT_SYNCHRONOUS: |
| 1609 | *params = mDebug.isOutputSynchronous() ? GL_TRUE : GL_FALSE; |
| 1610 | break; |
| 1611 | case GL_DEBUG_OUTPUT: |
| 1612 | *params = mDebug.isOutputEnabled() ? GL_TRUE : GL_FALSE; |
| 1613 | break; |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 1614 | case GL_MULTISAMPLE_EXT: |
| 1615 | *params = mMultiSampling; |
| 1616 | break; |
| 1617 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: |
| 1618 | *params = mSampleAlphaToOne; |
| 1619 | break; |
Geoff Lang | f41a715 | 2016-09-19 15:11:17 -0400 | [diff] [blame] | 1620 | case GL_BIND_GENERATES_RESOURCE_CHROMIUM: |
| 1621 | *params = isBindGeneratesResourceEnabled() ? GL_TRUE : GL_FALSE; |
| 1622 | break; |
Geoff Lang | feb8c68 | 2017-02-13 16:07:35 -0500 | [diff] [blame] | 1623 | case GL_CLIENT_ARRAYS_ANGLE: |
| 1624 | *params = areClientArraysEnabled() ? GL_TRUE : GL_FALSE; |
| 1625 | break; |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 1626 | case GL_FRAMEBUFFER_SRGB_EXT: |
| 1627 | *params = getFramebufferSRGB() ? GL_TRUE : GL_FALSE; |
| 1628 | break; |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 1629 | case GL_CONTEXT_ROBUST_RESOURCE_INITIALIZATION_ANGLE: |
| 1630 | *params = mRobustResourceInit ? GL_TRUE : GL_FALSE; |
| 1631 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1632 | default: |
| 1633 | UNREACHABLE(); |
| 1634 | break; |
| 1635 | } |
| 1636 | } |
| 1637 | |
| 1638 | void State::getFloatv(GLenum pname, GLfloat *params) |
| 1639 | { |
| 1640 | // Please note: DEPTH_CLEAR_VALUE is included in our internal getFloatv implementation |
| 1641 | // because it is stored as a float, despite the fact that the GL ES 2.0 spec names |
| 1642 | // GetIntegerv as its native query function. As it would require conversion in any |
| 1643 | // case, this should make no difference to the calling application. |
| 1644 | switch (pname) |
| 1645 | { |
| 1646 | case GL_LINE_WIDTH: *params = mLineWidth; break; |
| 1647 | case GL_SAMPLE_COVERAGE_VALUE: *params = mSampleCoverageValue; break; |
| 1648 | case GL_DEPTH_CLEAR_VALUE: *params = mDepthClearValue; break; |
| 1649 | case GL_POLYGON_OFFSET_FACTOR: *params = mRasterizer.polygonOffsetFactor; break; |
| 1650 | case GL_POLYGON_OFFSET_UNITS: *params = mRasterizer.polygonOffsetUnits; break; |
| 1651 | case GL_DEPTH_RANGE: |
| 1652 | params[0] = mNearZ; |
| 1653 | params[1] = mFarZ; |
| 1654 | break; |
| 1655 | case GL_COLOR_CLEAR_VALUE: |
| 1656 | params[0] = mColorClearValue.red; |
| 1657 | params[1] = mColorClearValue.green; |
| 1658 | params[2] = mColorClearValue.blue; |
| 1659 | params[3] = mColorClearValue.alpha; |
| 1660 | break; |
| 1661 | case GL_BLEND_COLOR: |
| 1662 | params[0] = mBlendColor.red; |
| 1663 | params[1] = mBlendColor.green; |
| 1664 | params[2] = mBlendColor.blue; |
| 1665 | params[3] = mBlendColor.alpha; |
| 1666 | break; |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 1667 | case GL_MULTISAMPLE_EXT: |
| 1668 | *params = static_cast<GLfloat>(mMultiSampling); |
| 1669 | break; |
| 1670 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: |
| 1671 | *params = static_cast<GLfloat>(mSampleAlphaToOne); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 1672 | case GL_COVERAGE_MODULATION_CHROMIUM: |
Jamie Madill | e2e406c | 2016-06-02 13:04:10 -0400 | [diff] [blame] | 1673 | params[0] = static_cast<GLfloat>(mCoverageModulation); |
| 1674 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1675 | default: |
| 1676 | UNREACHABLE(); |
| 1677 | break; |
| 1678 | } |
| 1679 | } |
| 1680 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1681 | void State::getIntegerv(const Context *context, GLenum pname, GLint *params) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1682 | { |
| 1683 | if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT) |
| 1684 | { |
| 1685 | unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0_EXT); |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 1686 | ASSERT(colorAttachment < mMaxDrawBuffers); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1687 | Framebuffer *framebuffer = mDrawFramebuffer; |
| 1688 | *params = framebuffer->getDrawBufferState(colorAttachment); |
| 1689 | return; |
| 1690 | } |
| 1691 | |
| 1692 | // Please note: DEPTH_CLEAR_VALUE is not included in our internal getIntegerv implementation |
| 1693 | // because it is stored as a float, despite the fact that the GL ES 2.0 spec names |
| 1694 | // GetIntegerv as its native query function. As it would require conversion in any |
| 1695 | // case, this should make no difference to the calling application. You may find it in |
| 1696 | // State::getFloatv. |
| 1697 | switch (pname) |
| 1698 | { |
| 1699 | case GL_ARRAY_BUFFER_BINDING: *params = mArrayBuffer.id(); break; |
Jiajia Qin | 9d7d0b1 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1700 | case GL_DRAW_INDIRECT_BUFFER_BINDING: |
| 1701 | *params = mDrawIndirectBuffer.id(); |
| 1702 | break; |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 1703 | case GL_ELEMENT_ARRAY_BUFFER_BINDING: *params = getVertexArray()->getElementArrayBuffer().id(); break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1704 | //case GL_FRAMEBUFFER_BINDING: // now equivalent to GL_DRAW_FRAMEBUFFER_BINDING_ANGLE |
| 1705 | case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE: *params = mDrawFramebuffer->id(); break; |
| 1706 | case GL_READ_FRAMEBUFFER_BINDING_ANGLE: *params = mReadFramebuffer->id(); break; |
| 1707 | case GL_RENDERBUFFER_BINDING: *params = mRenderbuffer.id(); break; |
| 1708 | case GL_VERTEX_ARRAY_BINDING: *params = mVertexArray->id(); break; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1709 | case GL_CURRENT_PROGRAM: *params = mProgram ? mProgram->id() : 0; break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1710 | case GL_PACK_ALIGNMENT: *params = mPack.alignment; break; |
| 1711 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: *params = mPack.reverseRowOrder; break; |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1712 | case GL_PACK_ROW_LENGTH: |
| 1713 | *params = mPack.rowLength; |
| 1714 | break; |
| 1715 | case GL_PACK_SKIP_ROWS: |
| 1716 | *params = mPack.skipRows; |
| 1717 | break; |
| 1718 | case GL_PACK_SKIP_PIXELS: |
| 1719 | *params = mPack.skipPixels; |
| 1720 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1721 | case GL_UNPACK_ALIGNMENT: *params = mUnpack.alignment; break; |
Minmin Gong | b8aee3b | 2015-01-27 14:42:36 -0800 | [diff] [blame] | 1722 | case GL_UNPACK_ROW_LENGTH: *params = mUnpack.rowLength; break; |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1723 | case GL_UNPACK_IMAGE_HEIGHT: |
| 1724 | *params = mUnpack.imageHeight; |
| 1725 | break; |
| 1726 | case GL_UNPACK_SKIP_IMAGES: |
| 1727 | *params = mUnpack.skipImages; |
| 1728 | break; |
| 1729 | case GL_UNPACK_SKIP_ROWS: |
| 1730 | *params = mUnpack.skipRows; |
| 1731 | break; |
| 1732 | case GL_UNPACK_SKIP_PIXELS: |
| 1733 | *params = mUnpack.skipPixels; |
| 1734 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1735 | case GL_GENERATE_MIPMAP_HINT: *params = mGenerateMipmapHint; break; |
| 1736 | case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: *params = mFragmentShaderDerivativeHint; break; |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1737 | case GL_ACTIVE_TEXTURE: |
| 1738 | *params = (static_cast<GLint>(mActiveSampler) + GL_TEXTURE0); |
| 1739 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1740 | case GL_STENCIL_FUNC: *params = mDepthStencil.stencilFunc; break; |
| 1741 | case GL_STENCIL_REF: *params = mStencilRef; break; |
| 1742 | case GL_STENCIL_VALUE_MASK: *params = clampToInt(mDepthStencil.stencilMask); break; |
| 1743 | case GL_STENCIL_BACK_FUNC: *params = mDepthStencil.stencilBackFunc; break; |
| 1744 | case GL_STENCIL_BACK_REF: *params = mStencilBackRef; break; |
| 1745 | case GL_STENCIL_BACK_VALUE_MASK: *params = clampToInt(mDepthStencil.stencilBackMask); break; |
| 1746 | case GL_STENCIL_FAIL: *params = mDepthStencil.stencilFail; break; |
| 1747 | case GL_STENCIL_PASS_DEPTH_FAIL: *params = mDepthStencil.stencilPassDepthFail; break; |
| 1748 | case GL_STENCIL_PASS_DEPTH_PASS: *params = mDepthStencil.stencilPassDepthPass; break; |
| 1749 | case GL_STENCIL_BACK_FAIL: *params = mDepthStencil.stencilBackFail; break; |
| 1750 | case GL_STENCIL_BACK_PASS_DEPTH_FAIL: *params = mDepthStencil.stencilBackPassDepthFail; break; |
| 1751 | case GL_STENCIL_BACK_PASS_DEPTH_PASS: *params = mDepthStencil.stencilBackPassDepthPass; break; |
| 1752 | case GL_DEPTH_FUNC: *params = mDepthStencil.depthFunc; break; |
| 1753 | case GL_BLEND_SRC_RGB: *params = mBlend.sourceBlendRGB; break; |
| 1754 | case GL_BLEND_SRC_ALPHA: *params = mBlend.sourceBlendAlpha; break; |
| 1755 | case GL_BLEND_DST_RGB: *params = mBlend.destBlendRGB; break; |
| 1756 | case GL_BLEND_DST_ALPHA: *params = mBlend.destBlendAlpha; break; |
| 1757 | case GL_BLEND_EQUATION_RGB: *params = mBlend.blendEquationRGB; break; |
| 1758 | case GL_BLEND_EQUATION_ALPHA: *params = mBlend.blendEquationAlpha; break; |
| 1759 | case GL_STENCIL_WRITEMASK: *params = clampToInt(mDepthStencil.stencilWritemask); break; |
| 1760 | case GL_STENCIL_BACK_WRITEMASK: *params = clampToInt(mDepthStencil.stencilBackWritemask); break; |
| 1761 | case GL_STENCIL_CLEAR_VALUE: *params = mStencilClearValue; break; |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1762 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: *params = mReadFramebuffer->getImplementationColorReadType(); break; |
| 1763 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: *params = mReadFramebuffer->getImplementationColorReadFormat(); break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1764 | case GL_SAMPLE_BUFFERS: |
| 1765 | case GL_SAMPLES: |
| 1766 | { |
| 1767 | gl::Framebuffer *framebuffer = mDrawFramebuffer; |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1768 | if (framebuffer->checkStatus(context) == GL_FRAMEBUFFER_COMPLETE) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1769 | { |
| 1770 | switch (pname) |
| 1771 | { |
| 1772 | case GL_SAMPLE_BUFFERS: |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1773 | if (framebuffer->getSamples(context) != 0) |
| 1774 | { |
| 1775 | *params = 1; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1776 | } |
| 1777 | else |
| 1778 | { |
| 1779 | *params = 0; |
| 1780 | } |
| 1781 | break; |
| 1782 | case GL_SAMPLES: |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 1783 | *params = framebuffer->getSamples(context); |
| 1784 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1785 | } |
| 1786 | } |
| 1787 | else |
| 1788 | { |
| 1789 | *params = 0; |
| 1790 | } |
| 1791 | } |
| 1792 | break; |
| 1793 | case GL_VIEWPORT: |
| 1794 | params[0] = mViewport.x; |
| 1795 | params[1] = mViewport.y; |
| 1796 | params[2] = mViewport.width; |
| 1797 | params[3] = mViewport.height; |
| 1798 | break; |
| 1799 | case GL_SCISSOR_BOX: |
| 1800 | params[0] = mScissor.x; |
| 1801 | params[1] = mScissor.y; |
| 1802 | params[2] = mScissor.width; |
| 1803 | params[3] = mScissor.height; |
| 1804 | break; |
| 1805 | case GL_CULL_FACE_MODE: *params = mRasterizer.cullMode; break; |
| 1806 | case GL_FRONT_FACE: *params = mRasterizer.frontFace; break; |
| 1807 | case GL_RED_BITS: |
| 1808 | case GL_GREEN_BITS: |
| 1809 | case GL_BLUE_BITS: |
| 1810 | case GL_ALPHA_BITS: |
| 1811 | { |
| 1812 | gl::Framebuffer *framebuffer = getDrawFramebuffer(); |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 1813 | const gl::FramebufferAttachment *colorbuffer = framebuffer->getFirstColorbuffer(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1814 | |
| 1815 | if (colorbuffer) |
| 1816 | { |
| 1817 | switch (pname) |
| 1818 | { |
| 1819 | case GL_RED_BITS: *params = colorbuffer->getRedSize(); break; |
| 1820 | case GL_GREEN_BITS: *params = colorbuffer->getGreenSize(); break; |
| 1821 | case GL_BLUE_BITS: *params = colorbuffer->getBlueSize(); break; |
| 1822 | case GL_ALPHA_BITS: *params = colorbuffer->getAlphaSize(); break; |
| 1823 | } |
| 1824 | } |
| 1825 | else |
| 1826 | { |
| 1827 | *params = 0; |
| 1828 | } |
| 1829 | } |
| 1830 | break; |
| 1831 | case GL_DEPTH_BITS: |
| 1832 | { |
Jamie Madill | e3ef715 | 2015-04-28 16:55:17 +0000 | [diff] [blame] | 1833 | const gl::Framebuffer *framebuffer = getDrawFramebuffer(); |
| 1834 | const gl::FramebufferAttachment *depthbuffer = framebuffer->getDepthbuffer(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1835 | |
| 1836 | if (depthbuffer) |
| 1837 | { |
| 1838 | *params = depthbuffer->getDepthSize(); |
| 1839 | } |
| 1840 | else |
| 1841 | { |
| 1842 | *params = 0; |
| 1843 | } |
| 1844 | } |
| 1845 | break; |
| 1846 | case GL_STENCIL_BITS: |
| 1847 | { |
Jamie Madill | e3ef715 | 2015-04-28 16:55:17 +0000 | [diff] [blame] | 1848 | const gl::Framebuffer *framebuffer = getDrawFramebuffer(); |
| 1849 | const gl::FramebufferAttachment *stencilbuffer = framebuffer->getStencilbuffer(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1850 | |
| 1851 | if (stencilbuffer) |
| 1852 | { |
| 1853 | *params = stencilbuffer->getStencilSize(); |
| 1854 | } |
| 1855 | else |
| 1856 | { |
| 1857 | *params = 0; |
| 1858 | } |
| 1859 | } |
| 1860 | break; |
| 1861 | case GL_TEXTURE_BINDING_2D: |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 1862 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1863 | *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_2D); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1864 | break; |
| 1865 | case GL_TEXTURE_BINDING_CUBE_MAP: |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 1866 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1867 | *params = |
| 1868 | getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_CUBE_MAP); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1869 | break; |
| 1870 | case GL_TEXTURE_BINDING_3D: |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 1871 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1872 | *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_3D); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1873 | break; |
| 1874 | case GL_TEXTURE_BINDING_2D_ARRAY: |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 1875 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1876 | *params = |
| 1877 | getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_2D_ARRAY); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1878 | break; |
John Bauman | 1831918 | 2016-09-28 14:22:27 -0700 | [diff] [blame] | 1879 | case GL_TEXTURE_BINDING_EXTERNAL_OES: |
| 1880 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
| 1881 | *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), |
| 1882 | GL_TEXTURE_EXTERNAL_OES); |
| 1883 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1884 | case GL_UNIFORM_BUFFER_BINDING: |
| 1885 | *params = mGenericUniformBuffer.id(); |
| 1886 | break; |
Frank Henigman | 22581ff | 2015-11-06 14:25:54 -0500 | [diff] [blame] | 1887 | case GL_TRANSFORM_FEEDBACK_BINDING: |
Frank Henigman | b0f0b81 | 2015-11-21 17:49:29 -0500 | [diff] [blame] | 1888 | *params = mTransformFeedback.id(); |
Frank Henigman | 22581ff | 2015-11-06 14:25:54 -0500 | [diff] [blame] | 1889 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1890 | case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 1891 | *params = mTransformFeedback->getGenericBuffer().id(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1892 | break; |
| 1893 | case GL_COPY_READ_BUFFER_BINDING: |
| 1894 | *params = mCopyReadBuffer.id(); |
| 1895 | break; |
| 1896 | case GL_COPY_WRITE_BUFFER_BINDING: |
| 1897 | *params = mCopyWriteBuffer.id(); |
| 1898 | break; |
| 1899 | case GL_PIXEL_PACK_BUFFER_BINDING: |
| 1900 | *params = mPack.pixelBuffer.id(); |
| 1901 | break; |
| 1902 | case GL_PIXEL_UNPACK_BUFFER_BINDING: |
| 1903 | *params = mUnpack.pixelBuffer.id(); |
| 1904 | break; |
Olli Etuaho | 86821db | 2016-03-04 12:05:47 +0200 | [diff] [blame] | 1905 | case GL_READ_BUFFER: |
| 1906 | *params = mReadFramebuffer->getReadBufferState(); |
| 1907 | break; |
| 1908 | case GL_SAMPLER_BINDING: |
| 1909 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
| 1910 | *params = getSamplerId(static_cast<GLuint>(mActiveSampler)); |
| 1911 | break; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1912 | case GL_DEBUG_LOGGED_MESSAGES: |
| 1913 | *params = static_cast<GLint>(mDebug.getMessageCount()); |
| 1914 | break; |
| 1915 | case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH: |
| 1916 | *params = static_cast<GLint>(mDebug.getNextMessageLength()); |
| 1917 | break; |
| 1918 | case GL_DEBUG_GROUP_STACK_DEPTH: |
| 1919 | *params = static_cast<GLint>(mDebug.getGroupStackDepth()); |
| 1920 | break; |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 1921 | case GL_MULTISAMPLE_EXT: |
| 1922 | *params = static_cast<GLint>(mMultiSampling); |
| 1923 | break; |
| 1924 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: |
| 1925 | *params = static_cast<GLint>(mSampleAlphaToOne); |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 1926 | case GL_COVERAGE_MODULATION_CHROMIUM: |
| 1927 | *params = static_cast<GLint>(mCoverageModulation); |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 1928 | break; |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1929 | case GL_ATOMIC_COUNTER_BUFFER_BINDING: |
| 1930 | *params = mGenericAtomicCounterBuffer.id(); |
| 1931 | break; |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1932 | case GL_SHADER_STORAGE_BUFFER_BINDING: |
| 1933 | *params = mGenericShaderStorageBuffer.id(); |
| 1934 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1935 | default: |
| 1936 | UNREACHABLE(); |
| 1937 | break; |
| 1938 | } |
| 1939 | } |
| 1940 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 1941 | void State::getPointerv(GLenum pname, void **params) const |
| 1942 | { |
| 1943 | switch (pname) |
| 1944 | { |
| 1945 | case GL_DEBUG_CALLBACK_FUNCTION: |
| 1946 | *params = reinterpret_cast<void *>(mDebug.getCallback()); |
| 1947 | break; |
| 1948 | case GL_DEBUG_CALLBACK_USER_PARAM: |
| 1949 | *params = const_cast<void *>(mDebug.getUserParam()); |
| 1950 | break; |
| 1951 | default: |
| 1952 | UNREACHABLE(); |
| 1953 | break; |
| 1954 | } |
| 1955 | } |
| 1956 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1957 | void State::getIntegeri_v(GLenum target, GLuint index, GLint *data) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1958 | { |
| 1959 | switch (target) |
| 1960 | { |
| 1961 | case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1962 | ASSERT(static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount()); |
| 1963 | *data = mTransformFeedback->getIndexedBuffer(index).id(); |
| 1964 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1965 | case GL_UNIFORM_BUFFER_BINDING: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1966 | ASSERT(static_cast<size_t>(index) < mUniformBuffers.size()); |
| 1967 | *data = mUniformBuffers[index].id(); |
| 1968 | break; |
| 1969 | case GL_ATOMIC_COUNTER_BUFFER_BINDING: |
| 1970 | ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size()); |
| 1971 | *data = mAtomicCounterBuffers[index].id(); |
| 1972 | break; |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1973 | case GL_SHADER_STORAGE_BUFFER_BINDING: |
| 1974 | ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size()); |
| 1975 | *data = mShaderStorageBuffers[index].id(); |
| 1976 | break; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1977 | case GL_VERTEX_BINDING_BUFFER: |
| 1978 | ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings()); |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame^] | 1979 | *data = mVertexArray->getVertexBinding(index).getBuffer().id(); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1980 | break; |
| 1981 | case GL_VERTEX_BINDING_DIVISOR: |
| 1982 | ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings()); |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame^] | 1983 | *data = mVertexArray->getVertexBinding(index).getDivisor(); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1984 | break; |
| 1985 | case GL_VERTEX_BINDING_OFFSET: |
| 1986 | ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings()); |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame^] | 1987 | *data = static_cast<GLuint>(mVertexArray->getVertexBinding(index).getOffset()); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1988 | break; |
| 1989 | case GL_VERTEX_BINDING_STRIDE: |
| 1990 | ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings()); |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame^] | 1991 | *data = mVertexArray->getVertexBinding(index).getStride(); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1992 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1993 | default: |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1994 | UNREACHABLE(); |
| 1995 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1996 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1997 | } |
| 1998 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 1999 | void State::getInteger64i_v(GLenum target, GLuint index, GLint64 *data) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2000 | { |
| 2001 | switch (target) |
| 2002 | { |
| 2003 | case GL_TRANSFORM_FEEDBACK_BUFFER_START: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2004 | ASSERT(static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount()); |
| 2005 | *data = mTransformFeedback->getIndexedBuffer(index).getOffset(); |
| 2006 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2007 | case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2008 | ASSERT(static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount()); |
| 2009 | *data = mTransformFeedback->getIndexedBuffer(index).getSize(); |
| 2010 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2011 | case GL_UNIFORM_BUFFER_START: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2012 | ASSERT(static_cast<size_t>(index) < mUniformBuffers.size()); |
| 2013 | *data = mUniformBuffers[index].getOffset(); |
| 2014 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2015 | case GL_UNIFORM_BUFFER_SIZE: |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 2016 | ASSERT(static_cast<size_t>(index) < mUniformBuffers.size()); |
| 2017 | *data = mUniformBuffers[index].getSize(); |
| 2018 | break; |
| 2019 | case GL_ATOMIC_COUNTER_BUFFER_START: |
| 2020 | ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size()); |
| 2021 | *data = mAtomicCounterBuffers[index].getOffset(); |
| 2022 | break; |
| 2023 | case GL_ATOMIC_COUNTER_BUFFER_SIZE: |
| 2024 | ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size()); |
| 2025 | *data = mAtomicCounterBuffers[index].getSize(); |
| 2026 | break; |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 2027 | case GL_SHADER_STORAGE_BUFFER_START: |
| 2028 | ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size()); |
| 2029 | *data = mShaderStorageBuffers[index].getOffset(); |
| 2030 | break; |
| 2031 | case GL_SHADER_STORAGE_BUFFER_SIZE: |
| 2032 | ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size()); |
| 2033 | *data = mShaderStorageBuffers[index].getSize(); |
| 2034 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2035 | default: |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2036 | UNREACHABLE(); |
| 2037 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2038 | } |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2039 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2040 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2041 | void State::getBooleani_v(GLenum target, GLuint index, GLboolean *data) |
| 2042 | { |
| 2043 | UNREACHABLE(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2044 | } |
| 2045 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2046 | bool State::hasMappedBuffer(GLenum target) const |
| 2047 | { |
| 2048 | if (target == GL_ARRAY_BUFFER) |
| 2049 | { |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 2050 | const VertexArray *vao = getVertexArray(); |
Jamie Madill | eea3a6e | 2015-04-15 10:02:48 -0400 | [diff] [blame] | 2051 | const auto &vertexAttribs = vao->getVertexAttributes(); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 2052 | const auto &vertexBindings = vao->getVertexBindings(); |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 2053 | size_t maxEnabledAttrib = vao->getMaxEnabledAttribute(); |
Jamie Madill | aebf9dd | 2015-04-28 12:39:07 -0400 | [diff] [blame] | 2054 | for (size_t attribIndex = 0; attribIndex < maxEnabledAttrib; attribIndex++) |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2055 | { |
Jamie Madill | eea3a6e | 2015-04-15 10:02:48 -0400 | [diff] [blame] | 2056 | const gl::VertexAttribute &vertexAttrib = vertexAttribs[attribIndex]; |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame^] | 2057 | auto *boundBuffer = vertexBindings[vertexAttrib.bindingIndex].getBuffer().get(); |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 2058 | if (vertexAttrib.enabled && boundBuffer && boundBuffer->isMapped()) |
| 2059 | { |
| 2060 | return true; |
| 2061 | } |
| 2062 | } |
| 2063 | |
| 2064 | return false; |
| 2065 | } |
| 2066 | else |
| 2067 | { |
| 2068 | Buffer *buffer = getTargetBuffer(target); |
| 2069 | return (buffer && buffer->isMapped()); |
| 2070 | } |
| 2071 | } |
| 2072 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2073 | void State::syncDirtyObjects(const Context *context) |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2074 | { |
| 2075 | if (!mDirtyObjects.any()) |
| 2076 | return; |
| 2077 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2078 | syncDirtyObjects(context, mDirtyObjects); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2079 | } |
| 2080 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2081 | void State::syncDirtyObjects(const Context *context, const DirtyObjects &bitset) |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2082 | { |
Jamie Madill | 6de5185 | 2017-04-12 09:53:01 -0400 | [diff] [blame] | 2083 | for (auto dirtyObject : bitset) |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2084 | { |
| 2085 | switch (dirtyObject) |
| 2086 | { |
| 2087 | case DIRTY_OBJECT_READ_FRAMEBUFFER: |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2088 | ASSERT(mReadFramebuffer); |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2089 | mReadFramebuffer->syncState(context); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2090 | break; |
| 2091 | case DIRTY_OBJECT_DRAW_FRAMEBUFFER: |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2092 | ASSERT(mDrawFramebuffer); |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2093 | mDrawFramebuffer->syncState(context); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2094 | break; |
| 2095 | case DIRTY_OBJECT_VERTEX_ARRAY: |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2096 | ASSERT(mVertexArray); |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2097 | mVertexArray->syncImplState(context); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2098 | break; |
| 2099 | case DIRTY_OBJECT_PROGRAM: |
| 2100 | // TODO(jmadill): implement this |
| 2101 | break; |
| 2102 | default: |
| 2103 | UNREACHABLE(); |
| 2104 | break; |
| 2105 | } |
| 2106 | } |
| 2107 | |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2108 | mDirtyObjects &= ~bitset; |
| 2109 | } |
| 2110 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2111 | void State::syncDirtyObject(const Context *context, GLenum target) |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2112 | { |
| 2113 | DirtyObjects localSet; |
| 2114 | |
| 2115 | switch (target) |
| 2116 | { |
| 2117 | case GL_READ_FRAMEBUFFER: |
| 2118 | localSet.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
| 2119 | break; |
| 2120 | case GL_DRAW_FRAMEBUFFER: |
| 2121 | localSet.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
| 2122 | break; |
| 2123 | case GL_FRAMEBUFFER: |
| 2124 | localSet.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
| 2125 | localSet.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
| 2126 | break; |
| 2127 | case GL_VERTEX_ARRAY: |
| 2128 | localSet.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 2129 | break; |
| 2130 | case GL_PROGRAM: |
| 2131 | localSet.set(DIRTY_OBJECT_PROGRAM); |
| 2132 | break; |
| 2133 | } |
| 2134 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 2135 | syncDirtyObjects(context, localSet); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2136 | } |
| 2137 | |
| 2138 | void State::setObjectDirty(GLenum target) |
| 2139 | { |
| 2140 | switch (target) |
| 2141 | { |
| 2142 | case GL_READ_FRAMEBUFFER: |
| 2143 | mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
| 2144 | break; |
| 2145 | case GL_DRAW_FRAMEBUFFER: |
| 2146 | mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
| 2147 | break; |
| 2148 | case GL_FRAMEBUFFER: |
| 2149 | mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
| 2150 | mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
| 2151 | break; |
| 2152 | case GL_VERTEX_ARRAY: |
| 2153 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 2154 | break; |
| 2155 | case GL_PROGRAM: |
| 2156 | mDirtyObjects.set(DIRTY_OBJECT_PROGRAM); |
| 2157 | break; |
| 2158 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2159 | } |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2160 | |
| 2161 | } // namespace gl |