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