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