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