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