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