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