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()); |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 636 | ASSERT(sampler < it->second.size()); |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 637 | return it->second[sampler].get(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 638 | } |
| 639 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 640 | GLuint State::getSamplerTextureId(unsigned int sampler, GLenum type) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 641 | { |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 642 | const auto it = mSamplerTextures.find(type); |
| 643 | ASSERT(it != mSamplerTextures.end()); |
Jamie Madill | 3d3d2f2 | 2015-09-23 16:47:51 -0400 | [diff] [blame] | 644 | ASSERT(sampler < it->second.size()); |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 645 | return it->second[sampler].id(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 646 | } |
| 647 | |
Jamie Madill | e6382c3 | 2014-11-07 15:05:26 -0500 | [diff] [blame] | 648 | void State::detachTexture(const TextureMap &zeroTextures, GLuint texture) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 649 | { |
| 650 | // Textures have a detach method on State rather than a simple |
| 651 | // removeBinding, because the zero/null texture objects are managed |
| 652 | // separately, and don't have to go through the Context's maps or |
| 653 | // the ResourceManager. |
| 654 | |
| 655 | // [OpenGL ES 2.0.24] section 3.8 page 84: |
| 656 | // If a texture object is deleted, it is as if all texture units which are bound to that texture object are |
| 657 | // rebound to texture object zero |
| 658 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 659 | for (TextureBindingMap::iterator bindingVec = mSamplerTextures.begin(); bindingVec != mSamplerTextures.end(); bindingVec++) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 660 | { |
Jamie Madill | e6382c3 | 2014-11-07 15:05:26 -0500 | [diff] [blame] | 661 | GLenum textureType = bindingVec->first; |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 662 | TextureBindingVector &textureVector = bindingVec->second; |
| 663 | for (size_t textureIdx = 0; textureIdx < textureVector.size(); textureIdx++) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 664 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 665 | BindingPointer<Texture> &binding = textureVector[textureIdx]; |
| 666 | if (binding.id() == texture) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 667 | { |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 668 | auto it = zeroTextures.find(textureType); |
| 669 | ASSERT(it != zeroTextures.end()); |
Jamie Madill | e6382c3 | 2014-11-07 15:05:26 -0500 | [diff] [blame] | 670 | // Zero textures are the "default" textures instead of NULL |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 671 | binding.set(it->second.get()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 672 | } |
| 673 | } |
| 674 | } |
| 675 | |
| 676 | // [OpenGL ES 2.0.24] section 4.4 page 112: |
| 677 | // If a texture object is deleted while its image is attached to the currently bound framebuffer, then it is |
| 678 | // as if Texture2DAttachment had been called, with a texture of 0, for each attachment point to which this |
| 679 | // image was attached in the currently bound framebuffer. |
| 680 | |
| 681 | if (mReadFramebuffer) |
| 682 | { |
| 683 | mReadFramebuffer->detachTexture(texture); |
| 684 | } |
| 685 | |
| 686 | if (mDrawFramebuffer) |
| 687 | { |
| 688 | mDrawFramebuffer->detachTexture(texture); |
| 689 | } |
| 690 | } |
| 691 | |
Jamie Madill | e6382c3 | 2014-11-07 15:05:26 -0500 | [diff] [blame] | 692 | void State::initializeZeroTextures(const TextureMap &zeroTextures) |
| 693 | { |
| 694 | for (const auto &zeroTexture : zeroTextures) |
| 695 | { |
| 696 | auto &samplerTextureArray = mSamplerTextures[zeroTexture.first]; |
| 697 | |
| 698 | for (size_t textureUnit = 0; textureUnit < samplerTextureArray.size(); ++textureUnit) |
| 699 | { |
| 700 | samplerTextureArray[textureUnit].set(zeroTexture.second.get()); |
| 701 | } |
| 702 | } |
| 703 | } |
| 704 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 705 | void State::setSamplerBinding(GLuint textureUnit, Sampler *sampler) |
| 706 | { |
| 707 | mSamplers[textureUnit].set(sampler); |
| 708 | } |
| 709 | |
| 710 | GLuint State::getSamplerId(GLuint textureUnit) const |
| 711 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 712 | ASSERT(textureUnit < mSamplers.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 713 | return mSamplers[textureUnit].id(); |
| 714 | } |
| 715 | |
| 716 | Sampler *State::getSampler(GLuint textureUnit) const |
| 717 | { |
| 718 | return mSamplers[textureUnit].get(); |
| 719 | } |
| 720 | |
| 721 | void State::detachSampler(GLuint sampler) |
| 722 | { |
| 723 | // [OpenGL ES 3.0.2] section 3.8.2 pages 123-124: |
| 724 | // If a sampler object that is currently bound to one or more texture units is |
| 725 | // deleted, it is as though BindSampler is called once for each texture unit to |
| 726 | // 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] | 727 | for (size_t textureUnit = 0; textureUnit < mSamplers.size(); textureUnit++) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 728 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 729 | BindingPointer<Sampler> &samplerBinding = mSamplers[textureUnit]; |
| 730 | if (samplerBinding.id() == sampler) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 731 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 732 | samplerBinding.set(NULL); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 733 | } |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | void State::setRenderbufferBinding(Renderbuffer *renderbuffer) |
| 738 | { |
| 739 | mRenderbuffer.set(renderbuffer); |
| 740 | } |
| 741 | |
| 742 | GLuint State::getRenderbufferId() const |
| 743 | { |
| 744 | return mRenderbuffer.id(); |
| 745 | } |
| 746 | |
| 747 | Renderbuffer *State::getCurrentRenderbuffer() |
| 748 | { |
| 749 | return mRenderbuffer.get(); |
| 750 | } |
| 751 | |
| 752 | void State::detachRenderbuffer(GLuint renderbuffer) |
| 753 | { |
| 754 | // [OpenGL ES 2.0.24] section 4.4 page 109: |
| 755 | // If a renderbuffer that is currently bound to RENDERBUFFER is deleted, it is as though BindRenderbuffer |
| 756 | // had been executed with the target RENDERBUFFER and name of zero. |
| 757 | |
| 758 | if (mRenderbuffer.id() == renderbuffer) |
| 759 | { |
| 760 | mRenderbuffer.set(NULL); |
| 761 | } |
| 762 | |
| 763 | // [OpenGL ES 2.0.24] section 4.4 page 111: |
| 764 | // If a renderbuffer object is deleted while its image is attached to the currently bound framebuffer, |
| 765 | // then it is as if FramebufferRenderbuffer had been called, with a renderbuffer of 0, for each attachment |
| 766 | // point to which this image was attached in the currently bound framebuffer. |
| 767 | |
| 768 | Framebuffer *readFramebuffer = mReadFramebuffer; |
| 769 | Framebuffer *drawFramebuffer = mDrawFramebuffer; |
| 770 | |
| 771 | if (readFramebuffer) |
| 772 | { |
| 773 | readFramebuffer->detachRenderbuffer(renderbuffer); |
| 774 | } |
| 775 | |
| 776 | if (drawFramebuffer && drawFramebuffer != readFramebuffer) |
| 777 | { |
| 778 | drawFramebuffer->detachRenderbuffer(renderbuffer); |
| 779 | } |
| 780 | |
| 781 | } |
| 782 | |
| 783 | void State::setReadFramebufferBinding(Framebuffer *framebuffer) |
| 784 | { |
| 785 | mReadFramebuffer = framebuffer; |
| 786 | } |
| 787 | |
| 788 | void State::setDrawFramebufferBinding(Framebuffer *framebuffer) |
| 789 | { |
| 790 | mDrawFramebuffer = framebuffer; |
| 791 | } |
| 792 | |
| 793 | Framebuffer *State::getTargetFramebuffer(GLenum target) const |
| 794 | { |
| 795 | switch (target) |
| 796 | { |
| 797 | case GL_READ_FRAMEBUFFER_ANGLE: return mReadFramebuffer; |
| 798 | case GL_DRAW_FRAMEBUFFER_ANGLE: |
| 799 | case GL_FRAMEBUFFER: return mDrawFramebuffer; |
| 800 | default: UNREACHABLE(); return NULL; |
| 801 | } |
| 802 | } |
| 803 | |
| 804 | Framebuffer *State::getReadFramebuffer() |
| 805 | { |
| 806 | return mReadFramebuffer; |
| 807 | } |
| 808 | |
| 809 | Framebuffer *State::getDrawFramebuffer() |
| 810 | { |
| 811 | return mDrawFramebuffer; |
| 812 | } |
| 813 | |
| 814 | const Framebuffer *State::getReadFramebuffer() const |
| 815 | { |
| 816 | return mReadFramebuffer; |
| 817 | } |
| 818 | |
| 819 | const Framebuffer *State::getDrawFramebuffer() const |
| 820 | { |
| 821 | return mDrawFramebuffer; |
| 822 | } |
| 823 | |
| 824 | bool State::removeReadFramebufferBinding(GLuint framebuffer) |
| 825 | { |
Jamie Madill | 77a72f6 | 2015-04-14 11:18:32 -0400 | [diff] [blame] | 826 | if (mReadFramebuffer != nullptr && |
| 827 | mReadFramebuffer->id() == framebuffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 828 | { |
| 829 | mReadFramebuffer = NULL; |
| 830 | return true; |
| 831 | } |
| 832 | |
| 833 | return false; |
| 834 | } |
| 835 | |
| 836 | bool State::removeDrawFramebufferBinding(GLuint framebuffer) |
| 837 | { |
Jamie Madill | 77a72f6 | 2015-04-14 11:18:32 -0400 | [diff] [blame] | 838 | if (mReadFramebuffer != nullptr && |
| 839 | mDrawFramebuffer->id() == framebuffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 840 | { |
| 841 | mDrawFramebuffer = NULL; |
| 842 | return true; |
| 843 | } |
| 844 | |
| 845 | return false; |
| 846 | } |
| 847 | |
| 848 | void State::setVertexArrayBinding(VertexArray *vertexArray) |
| 849 | { |
| 850 | mVertexArray = vertexArray; |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 851 | mDirtyBits.set(DIRTY_BIT_VERTEX_ARRAY_BINDING); |
| 852 | mDirtyBits.set(DIRTY_BIT_VERTEX_ARRAY_OBJECT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 853 | } |
| 854 | |
| 855 | GLuint State::getVertexArrayId() const |
| 856 | { |
| 857 | ASSERT(mVertexArray != NULL); |
| 858 | return mVertexArray->id(); |
| 859 | } |
| 860 | |
| 861 | VertexArray *State::getVertexArray() const |
| 862 | { |
| 863 | ASSERT(mVertexArray != NULL); |
| 864 | return mVertexArray; |
| 865 | } |
| 866 | |
| 867 | bool State::removeVertexArrayBinding(GLuint vertexArray) |
| 868 | { |
| 869 | if (mVertexArray->id() == vertexArray) |
| 870 | { |
| 871 | mVertexArray = NULL; |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 872 | mDirtyBits.set(DIRTY_BIT_VERTEX_ARRAY_BINDING); |
| 873 | mDirtyBits.set(DIRTY_BIT_VERTEX_ARRAY_OBJECT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 874 | return true; |
| 875 | } |
| 876 | |
| 877 | return false; |
| 878 | } |
| 879 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 880 | void State::setProgram(Program *newProgram) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 881 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 882 | if (mProgram != newProgram) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 883 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 884 | if (mProgram) |
| 885 | { |
| 886 | mProgram->release(); |
| 887 | } |
| 888 | |
| 889 | mProgram = newProgram; |
| 890 | |
| 891 | if (mProgram) |
| 892 | { |
| 893 | newProgram->addRef(); |
| 894 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 895 | } |
| 896 | } |
| 897 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 898 | Program *State::getProgram() const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 899 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 900 | return mProgram; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | void State::setTransformFeedbackBinding(TransformFeedback *transformFeedback) |
| 904 | { |
| 905 | mTransformFeedback.set(transformFeedback); |
| 906 | } |
| 907 | |
| 908 | TransformFeedback *State::getCurrentTransformFeedback() const |
| 909 | { |
| 910 | return mTransformFeedback.get(); |
| 911 | } |
| 912 | |
Gregoire Payen de La Garanderie | 5274202 | 2015-02-04 14:55:39 +0000 | [diff] [blame] | 913 | bool State::isTransformFeedbackActiveUnpaused() const |
| 914 | { |
| 915 | gl::TransformFeedback *curTransformFeedback = getCurrentTransformFeedback(); |
Geoff Lang | bb0a0bb | 2015-03-27 12:16:57 -0400 | [diff] [blame] | 916 | return curTransformFeedback && curTransformFeedback->isActive() && !curTransformFeedback->isPaused(); |
Gregoire Payen de La Garanderie | 5274202 | 2015-02-04 14:55:39 +0000 | [diff] [blame] | 917 | } |
| 918 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 919 | void State::detachTransformFeedback(GLuint transformFeedback) |
| 920 | { |
| 921 | if (mTransformFeedback.id() == transformFeedback) |
| 922 | { |
| 923 | mTransformFeedback.set(NULL); |
| 924 | } |
| 925 | } |
| 926 | |
| 927 | bool State::isQueryActive() const |
| 928 | { |
| 929 | for (State::ActiveQueryMap::const_iterator i = mActiveQueries.begin(); |
| 930 | i != mActiveQueries.end(); i++) |
| 931 | { |
| 932 | if (i->second.get() != NULL) |
| 933 | { |
| 934 | return true; |
| 935 | } |
| 936 | } |
| 937 | |
| 938 | return false; |
| 939 | } |
| 940 | |
| 941 | void State::setActiveQuery(GLenum target, Query *query) |
| 942 | { |
| 943 | mActiveQueries[target].set(query); |
| 944 | } |
| 945 | |
| 946 | GLuint State::getActiveQueryId(GLenum target) const |
| 947 | { |
| 948 | const Query *query = getActiveQuery(target); |
| 949 | return (query ? query->id() : 0u); |
| 950 | } |
| 951 | |
| 952 | Query *State::getActiveQuery(GLenum target) const |
| 953 | { |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 954 | const auto it = mActiveQueries.find(target); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 955 | |
Jamie Madill | 5864ac2 | 2015-01-12 14:43:07 -0500 | [diff] [blame] | 956 | // All query types should already exist in the activeQueries map |
| 957 | ASSERT(it != mActiveQueries.end()); |
| 958 | |
| 959 | return it->second.get(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | void State::setArrayBufferBinding(Buffer *buffer) |
| 963 | { |
| 964 | mArrayBuffer.set(buffer); |
| 965 | } |
| 966 | |
| 967 | GLuint State::getArrayBufferId() const |
| 968 | { |
| 969 | return mArrayBuffer.id(); |
| 970 | } |
| 971 | |
| 972 | bool State::removeArrayBufferBinding(GLuint buffer) |
| 973 | { |
| 974 | if (mArrayBuffer.id() == buffer) |
| 975 | { |
| 976 | mArrayBuffer.set(NULL); |
| 977 | return true; |
| 978 | } |
| 979 | |
| 980 | return false; |
| 981 | } |
| 982 | |
| 983 | void State::setGenericUniformBufferBinding(Buffer *buffer) |
| 984 | { |
| 985 | mGenericUniformBuffer.set(buffer); |
| 986 | } |
| 987 | |
| 988 | void State::setIndexedUniformBufferBinding(GLuint index, Buffer *buffer, GLintptr offset, GLsizeiptr size) |
| 989 | { |
| 990 | mUniformBuffers[index].set(buffer, offset, size); |
| 991 | } |
| 992 | |
| 993 | GLuint State::getIndexedUniformBufferId(GLuint index) const |
| 994 | { |
Shannon Woods | f3acaf9 | 2014-09-23 18:07:11 -0400 | [diff] [blame] | 995 | ASSERT(static_cast<size_t>(index) < mUniformBuffers.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 996 | |
| 997 | return mUniformBuffers[index].id(); |
| 998 | } |
| 999 | |
| 1000 | Buffer *State::getIndexedUniformBuffer(GLuint index) const |
| 1001 | { |
Shannon Woods | f3acaf9 | 2014-09-23 18:07:11 -0400 | [diff] [blame] | 1002 | ASSERT(static_cast<size_t>(index) < mUniformBuffers.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1003 | |
| 1004 | return mUniformBuffers[index].get(); |
| 1005 | } |
| 1006 | |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1007 | GLintptr State::getIndexedUniformBufferOffset(GLuint index) const |
| 1008 | { |
| 1009 | ASSERT(static_cast<size_t>(index) < mUniformBuffers.size()); |
| 1010 | |
| 1011 | return mUniformBuffers[index].getOffset(); |
| 1012 | } |
| 1013 | |
| 1014 | GLsizeiptr State::getIndexedUniformBufferSize(GLuint index) const |
| 1015 | { |
| 1016 | ASSERT(static_cast<size_t>(index) < mUniformBuffers.size()); |
| 1017 | |
| 1018 | return mUniformBuffers[index].getSize(); |
| 1019 | } |
| 1020 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1021 | void State::setCopyReadBufferBinding(Buffer *buffer) |
| 1022 | { |
| 1023 | mCopyReadBuffer.set(buffer); |
| 1024 | } |
| 1025 | |
| 1026 | void State::setCopyWriteBufferBinding(Buffer *buffer) |
| 1027 | { |
| 1028 | mCopyWriteBuffer.set(buffer); |
| 1029 | } |
| 1030 | |
| 1031 | void State::setPixelPackBufferBinding(Buffer *buffer) |
| 1032 | { |
| 1033 | mPack.pixelBuffer.set(buffer); |
| 1034 | } |
| 1035 | |
| 1036 | void State::setPixelUnpackBufferBinding(Buffer *buffer) |
| 1037 | { |
| 1038 | mUnpack.pixelBuffer.set(buffer); |
| 1039 | } |
| 1040 | |
| 1041 | Buffer *State::getTargetBuffer(GLenum target) const |
| 1042 | { |
| 1043 | switch (target) |
| 1044 | { |
| 1045 | case GL_ARRAY_BUFFER: return mArrayBuffer.get(); |
| 1046 | case GL_COPY_READ_BUFFER: return mCopyReadBuffer.get(); |
| 1047 | case GL_COPY_WRITE_BUFFER: return mCopyWriteBuffer.get(); |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 1048 | case GL_ELEMENT_ARRAY_BUFFER: return getVertexArray()->getElementArrayBuffer().get(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1049 | case GL_PIXEL_PACK_BUFFER: return mPack.pixelBuffer.get(); |
| 1050 | case GL_PIXEL_UNPACK_BUFFER: return mUnpack.pixelBuffer.get(); |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 1051 | case GL_TRANSFORM_FEEDBACK_BUFFER: return mTransformFeedback->getGenericBuffer().get(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1052 | case GL_UNIFORM_BUFFER: return mGenericUniformBuffer.get(); |
| 1053 | default: UNREACHABLE(); return NULL; |
| 1054 | } |
| 1055 | } |
| 1056 | |
| 1057 | void State::setEnableVertexAttribArray(unsigned int attribNum, bool enabled) |
| 1058 | { |
| 1059 | getVertexArray()->enableAttribute(attribNum, enabled); |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 1060 | mDirtyBits.set(DIRTY_BIT_VERTEX_ARRAY_OBJECT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | void State::setVertexAttribf(GLuint index, const GLfloat 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].setFloatValues(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::setVertexAttribu(GLuint index, const GLuint 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].setUnsignedIntValues(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::setVertexAttribi(GLuint index, const GLint values[4]) |
| 1078 | { |
Shannon Woods | 23e0500 | 2014-09-22 19:07:27 -0400 | [diff] [blame] | 1079 | ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1080 | mVertexAttribCurrentValues[index].setIntValues(values); |
Jamie Madill | 1e0bc3a | 2015-08-11 08:12:21 -0400 | [diff] [blame] | 1081 | mDirtyBits.set(DIRTY_BIT_CURRENT_VALUE_0 + index); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1082 | } |
| 1083 | |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 1084 | void State::setVertexAttribState(unsigned int attribNum, |
| 1085 | Buffer *boundBuffer, |
| 1086 | GLint size, |
| 1087 | GLenum type, |
| 1088 | bool normalized, |
| 1089 | bool pureInteger, |
| 1090 | GLsizei stride, |
| 1091 | const void *pointer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1092 | { |
| 1093 | getVertexArray()->setAttributeState(attribNum, boundBuffer, size, type, normalized, pureInteger, stride, pointer); |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 1094 | mDirtyBits.set(DIRTY_BIT_VERTEX_ARRAY_OBJECT); |
| 1095 | } |
| 1096 | |
| 1097 | void State::setVertexAttribDivisor(GLuint index, GLuint divisor) |
| 1098 | { |
| 1099 | getVertexArray()->setVertexAttribDivisor(index, divisor); |
| 1100 | mDirtyBits.set(DIRTY_BIT_VERTEX_ARRAY_OBJECT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1101 | } |
| 1102 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1103 | const VertexAttribCurrentValueData &State::getVertexAttribCurrentValue(unsigned int attribNum) const |
| 1104 | { |
Shannon Woods | 23e0500 | 2014-09-22 19:07:27 -0400 | [diff] [blame] | 1105 | ASSERT(static_cast<size_t>(attribNum) < mVertexAttribCurrentValues.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1106 | return mVertexAttribCurrentValues[attribNum]; |
| 1107 | } |
| 1108 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1109 | const void *State::getVertexAttribPointer(unsigned int attribNum) const |
| 1110 | { |
| 1111 | return getVertexArray()->getVertexAttribute(attribNum).pointer; |
| 1112 | } |
| 1113 | |
| 1114 | void State::setPackAlignment(GLint alignment) |
| 1115 | { |
| 1116 | mPack.alignment = alignment; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1117 | mDirtyBits.set(DIRTY_BIT_PACK_ALIGNMENT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | GLint State::getPackAlignment() const |
| 1121 | { |
| 1122 | return mPack.alignment; |
| 1123 | } |
| 1124 | |
| 1125 | void State::setPackReverseRowOrder(bool reverseRowOrder) |
| 1126 | { |
| 1127 | mPack.reverseRowOrder = reverseRowOrder; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1128 | mDirtyBits.set(DIRTY_BIT_PACK_REVERSE_ROW_ORDER); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | bool State::getPackReverseRowOrder() const |
| 1132 | { |
| 1133 | return mPack.reverseRowOrder; |
| 1134 | } |
| 1135 | |
| 1136 | const PixelPackState &State::getPackState() const |
| 1137 | { |
| 1138 | return mPack; |
| 1139 | } |
| 1140 | |
Jamie Madill | 87de362 | 2015-03-16 10:41:44 -0400 | [diff] [blame] | 1141 | PixelPackState &State::getPackState() |
| 1142 | { |
| 1143 | return mPack; |
| 1144 | } |
| 1145 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1146 | void State::setUnpackAlignment(GLint alignment) |
| 1147 | { |
| 1148 | mUnpack.alignment = alignment; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1149 | mDirtyBits.set(DIRTY_BIT_UNPACK_ALIGNMENT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1150 | } |
| 1151 | |
| 1152 | GLint State::getUnpackAlignment() const |
| 1153 | { |
| 1154 | return mUnpack.alignment; |
| 1155 | } |
| 1156 | |
Minmin Gong | b8aee3b | 2015-01-27 14:42:36 -0800 | [diff] [blame] | 1157 | void State::setUnpackRowLength(GLint rowLength) |
| 1158 | { |
| 1159 | mUnpack.rowLength = rowLength; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1160 | mDirtyBits.set(DIRTY_BIT_UNPACK_ROW_LENGTH); |
Minmin Gong | b8aee3b | 2015-01-27 14:42:36 -0800 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | GLint State::getUnpackRowLength() const |
| 1164 | { |
| 1165 | return mUnpack.rowLength; |
| 1166 | } |
| 1167 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1168 | const PixelUnpackState &State::getUnpackState() const |
| 1169 | { |
| 1170 | return mUnpack; |
| 1171 | } |
| 1172 | |
Jamie Madill | 67102f0 | 2015-03-16 10:41:42 -0400 | [diff] [blame] | 1173 | PixelUnpackState &State::getUnpackState() |
| 1174 | { |
| 1175 | return mUnpack; |
| 1176 | } |
| 1177 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1178 | void State::getBooleanv(GLenum pname, GLboolean *params) |
| 1179 | { |
| 1180 | switch (pname) |
| 1181 | { |
| 1182 | case GL_SAMPLE_COVERAGE_INVERT: *params = mSampleCoverageInvert; break; |
| 1183 | case GL_DEPTH_WRITEMASK: *params = mDepthStencil.depthMask; break; |
| 1184 | case GL_COLOR_WRITEMASK: |
| 1185 | params[0] = mBlend.colorMaskRed; |
| 1186 | params[1] = mBlend.colorMaskGreen; |
| 1187 | params[2] = mBlend.colorMaskBlue; |
| 1188 | params[3] = mBlend.colorMaskAlpha; |
| 1189 | break; |
| 1190 | case GL_CULL_FACE: *params = mRasterizer.cullFace; break; |
| 1191 | case GL_POLYGON_OFFSET_FILL: *params = mRasterizer.polygonOffsetFill; break; |
| 1192 | case GL_SAMPLE_ALPHA_TO_COVERAGE: *params = mBlend.sampleAlphaToCoverage; break; |
| 1193 | case GL_SAMPLE_COVERAGE: *params = mSampleCoverage; break; |
| 1194 | case GL_SCISSOR_TEST: *params = mScissorTest; break; |
| 1195 | case GL_STENCIL_TEST: *params = mDepthStencil.stencilTest; break; |
| 1196 | case GL_DEPTH_TEST: *params = mDepthStencil.depthTest; break; |
| 1197 | case GL_BLEND: *params = mBlend.blend; break; |
| 1198 | case GL_DITHER: *params = mBlend.dither; break; |
Geoff Lang | bb0a0bb | 2015-03-27 12:16:57 -0400 | [diff] [blame] | 1199 | case GL_TRANSFORM_FEEDBACK_ACTIVE: *params = getCurrentTransformFeedback()->isActive() ? GL_TRUE : GL_FALSE; break; |
| 1200 | 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] | 1201 | default: |
| 1202 | UNREACHABLE(); |
| 1203 | break; |
| 1204 | } |
| 1205 | } |
| 1206 | |
| 1207 | void State::getFloatv(GLenum pname, GLfloat *params) |
| 1208 | { |
| 1209 | // Please note: DEPTH_CLEAR_VALUE is included in our internal getFloatv implementation |
| 1210 | // because it is stored as a float, despite the fact that the GL ES 2.0 spec names |
| 1211 | // GetIntegerv as its native query function. As it would require conversion in any |
| 1212 | // case, this should make no difference to the calling application. |
| 1213 | switch (pname) |
| 1214 | { |
| 1215 | case GL_LINE_WIDTH: *params = mLineWidth; break; |
| 1216 | case GL_SAMPLE_COVERAGE_VALUE: *params = mSampleCoverageValue; break; |
| 1217 | case GL_DEPTH_CLEAR_VALUE: *params = mDepthClearValue; break; |
| 1218 | case GL_POLYGON_OFFSET_FACTOR: *params = mRasterizer.polygonOffsetFactor; break; |
| 1219 | case GL_POLYGON_OFFSET_UNITS: *params = mRasterizer.polygonOffsetUnits; break; |
| 1220 | case GL_DEPTH_RANGE: |
| 1221 | params[0] = mNearZ; |
| 1222 | params[1] = mFarZ; |
| 1223 | break; |
| 1224 | case GL_COLOR_CLEAR_VALUE: |
| 1225 | params[0] = mColorClearValue.red; |
| 1226 | params[1] = mColorClearValue.green; |
| 1227 | params[2] = mColorClearValue.blue; |
| 1228 | params[3] = mColorClearValue.alpha; |
| 1229 | break; |
| 1230 | case GL_BLEND_COLOR: |
| 1231 | params[0] = mBlendColor.red; |
| 1232 | params[1] = mBlendColor.green; |
| 1233 | params[2] = mBlendColor.blue; |
| 1234 | params[3] = mBlendColor.alpha; |
| 1235 | break; |
| 1236 | default: |
| 1237 | UNREACHABLE(); |
| 1238 | break; |
| 1239 | } |
| 1240 | } |
| 1241 | |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1242 | void State::getIntegerv(const gl::Data &data, GLenum pname, GLint *params) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1243 | { |
| 1244 | if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT) |
| 1245 | { |
| 1246 | unsigned int colorAttachment = (pname - GL_DRAW_BUFFER0_EXT); |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 1247 | ASSERT(colorAttachment < mMaxDrawBuffers); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1248 | Framebuffer *framebuffer = mDrawFramebuffer; |
| 1249 | *params = framebuffer->getDrawBufferState(colorAttachment); |
| 1250 | return; |
| 1251 | } |
| 1252 | |
| 1253 | // Please note: DEPTH_CLEAR_VALUE is not included in our internal getIntegerv implementation |
| 1254 | // because it is stored as a float, despite the fact that the GL ES 2.0 spec names |
| 1255 | // GetIntegerv as its native query function. As it would require conversion in any |
| 1256 | // case, this should make no difference to the calling application. You may find it in |
| 1257 | // State::getFloatv. |
| 1258 | switch (pname) |
| 1259 | { |
| 1260 | case GL_ARRAY_BUFFER_BINDING: *params = mArrayBuffer.id(); break; |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 1261 | case GL_ELEMENT_ARRAY_BUFFER_BINDING: *params = getVertexArray()->getElementArrayBuffer().id(); break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1262 | //case GL_FRAMEBUFFER_BINDING: // now equivalent to GL_DRAW_FRAMEBUFFER_BINDING_ANGLE |
| 1263 | case GL_DRAW_FRAMEBUFFER_BINDING_ANGLE: *params = mDrawFramebuffer->id(); break; |
| 1264 | case GL_READ_FRAMEBUFFER_BINDING_ANGLE: *params = mReadFramebuffer->id(); break; |
| 1265 | case GL_RENDERBUFFER_BINDING: *params = mRenderbuffer.id(); break; |
| 1266 | case GL_VERTEX_ARRAY_BINDING: *params = mVertexArray->id(); break; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1267 | case GL_CURRENT_PROGRAM: *params = mProgram ? mProgram->id() : 0; break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1268 | case GL_PACK_ALIGNMENT: *params = mPack.alignment; break; |
| 1269 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: *params = mPack.reverseRowOrder; break; |
| 1270 | case GL_UNPACK_ALIGNMENT: *params = mUnpack.alignment; break; |
Minmin Gong | b8aee3b | 2015-01-27 14:42:36 -0800 | [diff] [blame] | 1271 | case GL_UNPACK_ROW_LENGTH: *params = mUnpack.rowLength; break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1272 | case GL_GENERATE_MIPMAP_HINT: *params = mGenerateMipmapHint; break; |
| 1273 | case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: *params = mFragmentShaderDerivativeHint; break; |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1274 | case GL_ACTIVE_TEXTURE: |
| 1275 | *params = (static_cast<GLint>(mActiveSampler) + GL_TEXTURE0); |
| 1276 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1277 | case GL_STENCIL_FUNC: *params = mDepthStencil.stencilFunc; break; |
| 1278 | case GL_STENCIL_REF: *params = mStencilRef; break; |
| 1279 | case GL_STENCIL_VALUE_MASK: *params = clampToInt(mDepthStencil.stencilMask); break; |
| 1280 | case GL_STENCIL_BACK_FUNC: *params = mDepthStencil.stencilBackFunc; break; |
| 1281 | case GL_STENCIL_BACK_REF: *params = mStencilBackRef; break; |
| 1282 | case GL_STENCIL_BACK_VALUE_MASK: *params = clampToInt(mDepthStencil.stencilBackMask); break; |
| 1283 | case GL_STENCIL_FAIL: *params = mDepthStencil.stencilFail; break; |
| 1284 | case GL_STENCIL_PASS_DEPTH_FAIL: *params = mDepthStencil.stencilPassDepthFail; break; |
| 1285 | case GL_STENCIL_PASS_DEPTH_PASS: *params = mDepthStencil.stencilPassDepthPass; break; |
| 1286 | case GL_STENCIL_BACK_FAIL: *params = mDepthStencil.stencilBackFail; break; |
| 1287 | case GL_STENCIL_BACK_PASS_DEPTH_FAIL: *params = mDepthStencil.stencilBackPassDepthFail; break; |
| 1288 | case GL_STENCIL_BACK_PASS_DEPTH_PASS: *params = mDepthStencil.stencilBackPassDepthPass; break; |
| 1289 | case GL_DEPTH_FUNC: *params = mDepthStencil.depthFunc; break; |
| 1290 | case GL_BLEND_SRC_RGB: *params = mBlend.sourceBlendRGB; break; |
| 1291 | case GL_BLEND_SRC_ALPHA: *params = mBlend.sourceBlendAlpha; break; |
| 1292 | case GL_BLEND_DST_RGB: *params = mBlend.destBlendRGB; break; |
| 1293 | case GL_BLEND_DST_ALPHA: *params = mBlend.destBlendAlpha; break; |
| 1294 | case GL_BLEND_EQUATION_RGB: *params = mBlend.blendEquationRGB; break; |
| 1295 | case GL_BLEND_EQUATION_ALPHA: *params = mBlend.blendEquationAlpha; break; |
| 1296 | case GL_STENCIL_WRITEMASK: *params = clampToInt(mDepthStencil.stencilWritemask); break; |
| 1297 | case GL_STENCIL_BACK_WRITEMASK: *params = clampToInt(mDepthStencil.stencilBackWritemask); break; |
| 1298 | case GL_STENCIL_CLEAR_VALUE: *params = mStencilClearValue; break; |
Geoff Lang | bce529e | 2014-12-01 12:48:41 -0500 | [diff] [blame] | 1299 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: *params = mReadFramebuffer->getImplementationColorReadType(); break; |
| 1300 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: *params = mReadFramebuffer->getImplementationColorReadFormat(); break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1301 | case GL_SAMPLE_BUFFERS: |
| 1302 | case GL_SAMPLES: |
| 1303 | { |
| 1304 | gl::Framebuffer *framebuffer = mDrawFramebuffer; |
Geoff Lang | 748f74e | 2014-12-01 11:25:34 -0500 | [diff] [blame] | 1305 | if (framebuffer->checkStatus(data) == GL_FRAMEBUFFER_COMPLETE) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1306 | { |
| 1307 | switch (pname) |
| 1308 | { |
| 1309 | case GL_SAMPLE_BUFFERS: |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1310 | if (framebuffer->getSamples(data) != 0) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1311 | { |
| 1312 | *params = 1; |
| 1313 | } |
| 1314 | else |
| 1315 | { |
| 1316 | *params = 0; |
| 1317 | } |
| 1318 | break; |
| 1319 | case GL_SAMPLES: |
Jamie Madill | 48faf80 | 2014-11-06 15:27:22 -0500 | [diff] [blame] | 1320 | *params = framebuffer->getSamples(data); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1321 | break; |
| 1322 | } |
| 1323 | } |
| 1324 | else |
| 1325 | { |
| 1326 | *params = 0; |
| 1327 | } |
| 1328 | } |
| 1329 | break; |
| 1330 | case GL_VIEWPORT: |
| 1331 | params[0] = mViewport.x; |
| 1332 | params[1] = mViewport.y; |
| 1333 | params[2] = mViewport.width; |
| 1334 | params[3] = mViewport.height; |
| 1335 | break; |
| 1336 | case GL_SCISSOR_BOX: |
| 1337 | params[0] = mScissor.x; |
| 1338 | params[1] = mScissor.y; |
| 1339 | params[2] = mScissor.width; |
| 1340 | params[3] = mScissor.height; |
| 1341 | break; |
| 1342 | case GL_CULL_FACE_MODE: *params = mRasterizer.cullMode; break; |
| 1343 | case GL_FRONT_FACE: *params = mRasterizer.frontFace; break; |
| 1344 | case GL_RED_BITS: |
| 1345 | case GL_GREEN_BITS: |
| 1346 | case GL_BLUE_BITS: |
| 1347 | case GL_ALPHA_BITS: |
| 1348 | { |
| 1349 | gl::Framebuffer *framebuffer = getDrawFramebuffer(); |
Jamie Madill | b6bda4a | 2015-04-20 12:53:26 -0400 | [diff] [blame] | 1350 | const gl::FramebufferAttachment *colorbuffer = framebuffer->getFirstColorbuffer(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1351 | |
| 1352 | if (colorbuffer) |
| 1353 | { |
| 1354 | switch (pname) |
| 1355 | { |
| 1356 | case GL_RED_BITS: *params = colorbuffer->getRedSize(); break; |
| 1357 | case GL_GREEN_BITS: *params = colorbuffer->getGreenSize(); break; |
| 1358 | case GL_BLUE_BITS: *params = colorbuffer->getBlueSize(); break; |
| 1359 | case GL_ALPHA_BITS: *params = colorbuffer->getAlphaSize(); break; |
| 1360 | } |
| 1361 | } |
| 1362 | else |
| 1363 | { |
| 1364 | *params = 0; |
| 1365 | } |
| 1366 | } |
| 1367 | break; |
| 1368 | case GL_DEPTH_BITS: |
| 1369 | { |
Jamie Madill | e3ef715 | 2015-04-28 16:55:17 +0000 | [diff] [blame] | 1370 | const gl::Framebuffer *framebuffer = getDrawFramebuffer(); |
| 1371 | const gl::FramebufferAttachment *depthbuffer = framebuffer->getDepthbuffer(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1372 | |
| 1373 | if (depthbuffer) |
| 1374 | { |
| 1375 | *params = depthbuffer->getDepthSize(); |
| 1376 | } |
| 1377 | else |
| 1378 | { |
| 1379 | *params = 0; |
| 1380 | } |
| 1381 | } |
| 1382 | break; |
| 1383 | case GL_STENCIL_BITS: |
| 1384 | { |
Jamie Madill | e3ef715 | 2015-04-28 16:55:17 +0000 | [diff] [blame] | 1385 | const gl::Framebuffer *framebuffer = getDrawFramebuffer(); |
| 1386 | const gl::FramebufferAttachment *stencilbuffer = framebuffer->getStencilbuffer(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1387 | |
| 1388 | if (stencilbuffer) |
| 1389 | { |
| 1390 | *params = stencilbuffer->getStencilSize(); |
| 1391 | } |
| 1392 | else |
| 1393 | { |
| 1394 | *params = 0; |
| 1395 | } |
| 1396 | } |
| 1397 | break; |
| 1398 | case GL_TEXTURE_BINDING_2D: |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 1399 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1400 | *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_2D); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1401 | break; |
| 1402 | case GL_TEXTURE_BINDING_CUBE_MAP: |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 1403 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1404 | *params = |
| 1405 | getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_CUBE_MAP); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1406 | break; |
| 1407 | case GL_TEXTURE_BINDING_3D: |
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 = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_3D); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1410 | break; |
| 1411 | case GL_TEXTURE_BINDING_2D_ARRAY: |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 1412 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
Cooper Partin | 4d61f7e | 2015-08-12 10:56:50 -0700 | [diff] [blame] | 1413 | *params = |
| 1414 | getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), GL_TEXTURE_2D_ARRAY); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1415 | break; |
| 1416 | case GL_UNIFORM_BUFFER_BINDING: |
| 1417 | *params = mGenericUniformBuffer.id(); |
| 1418 | break; |
| 1419 | case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 1420 | *params = mTransformFeedback->getGenericBuffer().id(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1421 | break; |
| 1422 | case GL_COPY_READ_BUFFER_BINDING: |
| 1423 | *params = mCopyReadBuffer.id(); |
| 1424 | break; |
| 1425 | case GL_COPY_WRITE_BUFFER_BINDING: |
| 1426 | *params = mCopyWriteBuffer.id(); |
| 1427 | break; |
| 1428 | case GL_PIXEL_PACK_BUFFER_BINDING: |
| 1429 | *params = mPack.pixelBuffer.id(); |
| 1430 | break; |
| 1431 | case GL_PIXEL_UNPACK_BUFFER_BINDING: |
| 1432 | *params = mUnpack.pixelBuffer.id(); |
| 1433 | break; |
| 1434 | default: |
| 1435 | UNREACHABLE(); |
| 1436 | break; |
| 1437 | } |
| 1438 | } |
| 1439 | |
| 1440 | bool State::getIndexedIntegerv(GLenum target, GLuint index, GLint *data) |
| 1441 | { |
| 1442 | switch (target) |
| 1443 | { |
| 1444 | case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 1445 | if (static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount()) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1446 | { |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 1447 | *data = mTransformFeedback->getIndexedBuffer(index).id(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1448 | } |
| 1449 | break; |
| 1450 | case GL_UNIFORM_BUFFER_BINDING: |
Shannon Woods | f3acaf9 | 2014-09-23 18:07:11 -0400 | [diff] [blame] | 1451 | if (static_cast<size_t>(index) < mUniformBuffers.size()) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1452 | { |
| 1453 | *data = mUniformBuffers[index].id(); |
| 1454 | } |
| 1455 | break; |
| 1456 | default: |
| 1457 | return false; |
| 1458 | } |
| 1459 | |
| 1460 | return true; |
| 1461 | } |
| 1462 | |
| 1463 | bool State::getIndexedInteger64v(GLenum target, GLuint index, GLint64 *data) |
| 1464 | { |
| 1465 | switch (target) |
| 1466 | { |
| 1467 | case GL_TRANSFORM_FEEDBACK_BUFFER_START: |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 1468 | if (static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount()) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1469 | { |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 1470 | *data = mTransformFeedback->getIndexedBuffer(index).getOffset(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1471 | } |
| 1472 | break; |
| 1473 | case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE: |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 1474 | if (static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount()) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1475 | { |
Geoff Lang | 045536b | 2015-03-27 15:17:18 -0400 | [diff] [blame] | 1476 | *data = mTransformFeedback->getIndexedBuffer(index).getSize(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1477 | } |
| 1478 | break; |
| 1479 | case GL_UNIFORM_BUFFER_START: |
Shannon Woods | f3acaf9 | 2014-09-23 18:07:11 -0400 | [diff] [blame] | 1480 | if (static_cast<size_t>(index) < mUniformBuffers.size()) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1481 | { |
| 1482 | *data = mUniformBuffers[index].getOffset(); |
| 1483 | } |
| 1484 | break; |
| 1485 | case GL_UNIFORM_BUFFER_SIZE: |
Shannon Woods | f3acaf9 | 2014-09-23 18:07:11 -0400 | [diff] [blame] | 1486 | if (static_cast<size_t>(index) < mUniformBuffers.size()) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1487 | { |
| 1488 | *data = mUniformBuffers[index].getSize(); |
| 1489 | } |
| 1490 | break; |
| 1491 | default: |
| 1492 | return false; |
| 1493 | } |
| 1494 | |
| 1495 | return true; |
| 1496 | } |
| 1497 | |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1498 | bool State::hasMappedBuffer(GLenum target) const |
| 1499 | { |
| 1500 | if (target == GL_ARRAY_BUFFER) |
| 1501 | { |
Geoff Lang | 5ead927 | 2015-03-25 12:27:43 -0400 | [diff] [blame] | 1502 | const VertexArray *vao = getVertexArray(); |
Jamie Madill | eea3a6e | 2015-04-15 10:02:48 -0400 | [diff] [blame] | 1503 | const auto &vertexAttribs = vao->getVertexAttributes(); |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 1504 | size_t maxEnabledAttrib = vao->getMaxEnabledAttribute(); |
Jamie Madill | aebf9dd | 2015-04-28 12:39:07 -0400 | [diff] [blame] | 1505 | for (size_t attribIndex = 0; attribIndex < maxEnabledAttrib; attribIndex++) |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1506 | { |
Jamie Madill | eea3a6e | 2015-04-15 10:02:48 -0400 | [diff] [blame] | 1507 | const gl::VertexAttribute &vertexAttrib = vertexAttribs[attribIndex]; |
Jamie Madill | d9ba4f7 | 2014-08-04 10:47:59 -0400 | [diff] [blame] | 1508 | gl::Buffer *boundBuffer = vertexAttrib.buffer.get(); |
| 1509 | if (vertexAttrib.enabled && boundBuffer && boundBuffer->isMapped()) |
| 1510 | { |
| 1511 | return true; |
| 1512 | } |
| 1513 | } |
| 1514 | |
| 1515 | return false; |
| 1516 | } |
| 1517 | else |
| 1518 | { |
| 1519 | Buffer *buffer = getTargetBuffer(target); |
| 1520 | return (buffer && buffer->isMapped()); |
| 1521 | } |
| 1522 | } |
| 1523 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1524 | } |