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