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