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