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