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