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