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