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