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 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 11 | #include <string.h> |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 12 | #include <limits> |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 13 | |
Jamie Madill | 20e005b | 2017-04-07 14:19:22 -0400 | [diff] [blame] | 14 | #include "common/bitset_utils.h" |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 15 | #include "common/mathutil.h" |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 16 | #include "common/matrix_utils.h" |
Jamie Madill | cd0a0a3 | 2018-10-18 18:41:57 -0400 | [diff] [blame] | 17 | #include "libANGLE/Buffer.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 18 | #include "libANGLE/Caps.h" |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 19 | #include "libANGLE/Context.h" |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 20 | #include "libANGLE/Debug.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 21 | #include "libANGLE/Framebuffer.h" |
| 22 | #include "libANGLE/FramebufferAttachment.h" |
| 23 | #include "libANGLE/Query.h" |
| 24 | #include "libANGLE/VertexArray.h" |
| 25 | #include "libANGLE/formatutils.h" |
jchen10 | a99ed55 | 2017-09-22 08:10:32 +0800 | [diff] [blame] | 26 | #include "libANGLE/queryconversions.h" |
Lingfeng Yang | abb09f1 | 2018-04-16 10:43:53 -0700 | [diff] [blame] | 27 | #include "libANGLE/queryutils.h" |
Geoff Lang | 4751aab | 2017-10-30 15:14:52 -0400 | [diff] [blame] | 28 | #include "libANGLE/renderer/ContextImpl.h" |
Jamie Madill | f668a4b | 2018-09-23 17:01:20 -0400 | [diff] [blame] | 29 | #include "libANGLE/renderer/TextureImpl.h" |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 30 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 31 | namespace gl |
| 32 | { |
| 33 | |
Olli Etuaho | bbf1c10 | 2016-06-28 13:31:33 +0300 | [diff] [blame] | 34 | namespace |
| 35 | { |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 36 | bool GetAlternativeQueryType(QueryType type, QueryType *alternativeType) |
Olli Etuaho | bbf1c10 | 2016-06-28 13:31:33 +0300 | [diff] [blame] | 37 | { |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 38 | switch (type) |
| 39 | { |
| 40 | case QueryType::AnySamples: |
| 41 | *alternativeType = QueryType::AnySamplesConservative; |
| 42 | return true; |
| 43 | case QueryType::AnySamplesConservative: |
| 44 | *alternativeType = QueryType::AnySamples; |
| 45 | return true; |
| 46 | default: |
| 47 | return false; |
| 48 | } |
Olli Etuaho | bbf1c10 | 2016-06-28 13:31:33 +0300 | [diff] [blame] | 49 | } |
| 50 | |
Jamie Madill | ca8eda4 | 2018-10-18 18:41:56 -0400 | [diff] [blame] | 51 | // Mapping from a buffer binding type to a dirty bit type. |
| 52 | constexpr angle::PackedEnumMap<BufferBinding, size_t> kBufferBindingDirtyBits = {{ |
Jamie Madill | 752d220 | 2018-11-27 13:29:48 -0500 | [diff] [blame] | 53 | {BufferBinding::AtomicCounter, State::DIRTY_BIT_ATOMIC_COUNTER_BUFFER_BINDING}, |
| 54 | {BufferBinding::DispatchIndirect, State::DIRTY_BIT_DISPATCH_INDIRECT_BUFFER_BINDING}, |
| 55 | {BufferBinding::DrawIndirect, State::DIRTY_BIT_DRAW_INDIRECT_BUFFER_BINDING}, |
| 56 | {BufferBinding::PixelPack, State::DIRTY_BIT_PACK_BUFFER_BINDING}, |
| 57 | {BufferBinding::PixelUnpack, State::DIRTY_BIT_UNPACK_BUFFER_BINDING}, |
| 58 | {BufferBinding::ShaderStorage, State::DIRTY_BIT_SHADER_STORAGE_BUFFER_BINDING}, |
| 59 | {BufferBinding::Uniform, State::DIRTY_BIT_UNIFORM_BUFFER_BINDINGS}, |
Jamie Madill | ca8eda4 | 2018-10-18 18:41:56 -0400 | [diff] [blame] | 60 | }}; |
| 61 | |
| 62 | // Returns a buffer binding function depending on if a dirty bit is set. |
| 63 | template <BufferBinding Target> |
Jamie Madill | 752d220 | 2018-11-27 13:29:48 -0500 | [diff] [blame] | 64 | constexpr std::pair<BufferBinding, State::BufferBindingSetter> GetBufferBindingSetter() |
Jamie Madill | ca8eda4 | 2018-10-18 18:41:56 -0400 | [diff] [blame] | 65 | { |
Jamie Madill | 752d220 | 2018-11-27 13:29:48 -0500 | [diff] [blame] | 66 | return std::make_pair(Target, kBufferBindingDirtyBits[Target] != 0 |
| 67 | ? &State::setGenericBufferBindingWithBit<Target> |
| 68 | : &State::setGenericBufferBinding<Target>); |
Jamie Madill | ca8eda4 | 2018-10-18 18:41:56 -0400 | [diff] [blame] | 69 | } |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 70 | |
| 71 | template <typename T> |
| 72 | using ContextStateMember = T *(State::*); |
| 73 | |
| 74 | template <typename T> |
| 75 | T *AllocateOrGetSharedResourceManager(const State *shareContextState, ContextStateMember<T> member) |
| 76 | { |
| 77 | if (shareContextState) |
| 78 | { |
| 79 | T *resourceManager = (*shareContextState).*member; |
| 80 | resourceManager->addRef(); |
| 81 | return resourceManager; |
| 82 | } |
| 83 | else |
| 84 | { |
| 85 | return new T(); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | TextureManager *AllocateOrGetSharedTextureManager(const State *shareContextState, |
| 90 | TextureManager *shareTextures, |
| 91 | ContextStateMember<TextureManager> member) |
| 92 | { |
| 93 | if (shareContextState) |
| 94 | { |
| 95 | TextureManager *textureManager = (*shareContextState).*member; |
| 96 | ASSERT(shareTextures == nullptr || textureManager == shareTextures); |
| 97 | textureManager->addRef(); |
| 98 | return textureManager; |
| 99 | } |
| 100 | else if (shareTextures) |
| 101 | { |
| 102 | TextureManager *textureManager = shareTextures; |
| 103 | textureManager->addRef(); |
| 104 | return textureManager; |
| 105 | } |
| 106 | else |
| 107 | { |
| 108 | return new TextureManager(); |
| 109 | } |
| 110 | } |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 111 | } // namespace |
Olli Etuaho | bbf1c10 | 2016-06-28 13:31:33 +0300 | [diff] [blame] | 112 | |
Jamie Madill | bf5177d | 2018-08-21 12:58:20 -0400 | [diff] [blame] | 113 | template <typename BindingT, typename... ArgsT> |
Jamie Madill | ca8eda4 | 2018-10-18 18:41:56 -0400 | [diff] [blame] | 114 | ANGLE_INLINE void UpdateNonTFBufferBinding(const Context *context, |
| 115 | BindingT *binding, |
| 116 | Buffer *buffer, |
| 117 | ArgsT... args) |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 118 | { |
Jamie Madill | ca8eda4 | 2018-10-18 18:41:56 -0400 | [diff] [blame] | 119 | Buffer *oldBuffer = binding->get(); |
| 120 | if (oldBuffer) |
| 121 | { |
| 122 | oldBuffer->onNonTFBindingChanged(-1); |
| 123 | oldBuffer->release(context); |
| 124 | } |
| 125 | binding->assign(buffer, args...); |
| 126 | if (buffer) |
| 127 | { |
| 128 | buffer->addRef(); |
| 129 | buffer->onNonTFBindingChanged(1); |
| 130 | } |
Jamie Madill | bf5177d | 2018-08-21 12:58:20 -0400 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | template <typename BindingT, typename... ArgsT> |
| 134 | void UpdateTFBufferBinding(const Context *context, BindingT *binding, bool indexed, ArgsT... args) |
| 135 | { |
| 136 | if (binding->get()) |
| 137 | (*binding)->onTFBindingChanged(context, false, indexed); |
| 138 | binding->set(context, args...); |
| 139 | if (binding->get()) |
| 140 | (*binding)->onTFBindingChanged(context, true, indexed); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | void UpdateBufferBinding(const Context *context, |
Jamie Madill | bf5177d | 2018-08-21 12:58:20 -0400 | [diff] [blame] | 144 | BindingPointer<Buffer> *binding, |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 145 | Buffer *buffer, |
Jamie Madill | bf5177d | 2018-08-21 12:58:20 -0400 | [diff] [blame] | 146 | BufferBinding target) |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 147 | { |
Jamie Madill | bf5177d | 2018-08-21 12:58:20 -0400 | [diff] [blame] | 148 | if (target == BufferBinding::TransformFeedback) |
| 149 | { |
| 150 | UpdateTFBufferBinding(context, binding, false, buffer); |
| 151 | } |
| 152 | else |
| 153 | { |
| 154 | UpdateNonTFBufferBinding(context, binding, buffer); |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | void UpdateIndexedBufferBinding(const Context *context, |
| 159 | OffsetBindingPointer<Buffer> *binding, |
| 160 | Buffer *buffer, |
| 161 | BufferBinding target, |
| 162 | GLintptr offset, |
| 163 | GLsizeiptr size) |
| 164 | { |
| 165 | if (target == BufferBinding::TransformFeedback) |
| 166 | { |
| 167 | UpdateTFBufferBinding(context, binding, true, buffer, offset, size); |
| 168 | } |
| 169 | else |
| 170 | { |
| 171 | UpdateNonTFBufferBinding(context, binding, buffer, offset, size); |
| 172 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 173 | } |
| 174 | |
Jamie Madill | ca8eda4 | 2018-10-18 18:41:56 -0400 | [diff] [blame] | 175 | // These template functions must be defined before they are instantiated in kBufferSetters. |
| 176 | template <BufferBinding Target> |
| 177 | void State::setGenericBufferBindingWithBit(const Context *context, Buffer *buffer) |
| 178 | { |
| 179 | UpdateNonTFBufferBinding(context, &mBoundBuffers[Target], buffer); |
| 180 | mDirtyBits.set(kBufferBindingDirtyBits[Target]); |
| 181 | } |
| 182 | |
| 183 | template <BufferBinding Target> |
| 184 | void State::setGenericBufferBinding(const Context *context, Buffer *buffer) |
| 185 | { |
| 186 | UpdateNonTFBufferBinding(context, &mBoundBuffers[Target], buffer); |
| 187 | } |
| 188 | |
| 189 | template <> |
| 190 | void State::setGenericBufferBinding<BufferBinding::TransformFeedback>(const Context *context, |
| 191 | Buffer *buffer) |
| 192 | { |
| 193 | UpdateTFBufferBinding(context, &mBoundBuffers[BufferBinding::TransformFeedback], false, buffer); |
| 194 | } |
| 195 | |
| 196 | template <> |
| 197 | void State::setGenericBufferBinding<BufferBinding::ElementArray>(const Context *context, |
| 198 | Buffer *buffer) |
| 199 | { |
| 200 | Buffer *oldBuffer = mVertexArray->mState.mElementArrayBuffer.get(); |
| 201 | if (oldBuffer) |
| 202 | { |
Jamie Madill | cd0a0a3 | 2018-10-18 18:41:57 -0400 | [diff] [blame] | 203 | oldBuffer->removeObserver(&mVertexArray->mState.mElementArrayBuffer); |
Jamie Madill | ca8eda4 | 2018-10-18 18:41:56 -0400 | [diff] [blame] | 204 | oldBuffer->onNonTFBindingChanged(-1); |
| 205 | oldBuffer->release(context); |
| 206 | } |
| 207 | mVertexArray->mState.mElementArrayBuffer.assign(buffer); |
| 208 | if (buffer) |
| 209 | { |
Jamie Madill | cd0a0a3 | 2018-10-18 18:41:57 -0400 | [diff] [blame] | 210 | buffer->addObserver(&mVertexArray->mState.mElementArrayBuffer); |
Jamie Madill | ca8eda4 | 2018-10-18 18:41:56 -0400 | [diff] [blame] | 211 | buffer->onNonTFBindingChanged(1); |
| 212 | buffer->addRef(); |
| 213 | } |
Jamie Madill | ca8eda4 | 2018-10-18 18:41:56 -0400 | [diff] [blame] | 214 | mVertexArray->mDirtyBits.set(VertexArray::DIRTY_BIT_ELEMENT_ARRAY_BUFFER); |
Jamie Madill | c1fd737 | 2018-10-26 22:48:39 -0400 | [diff] [blame] | 215 | mVertexArray->mIndexRangeCache.invalidate(); |
Jamie Madill | ca8eda4 | 2018-10-18 18:41:56 -0400 | [diff] [blame] | 216 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 217 | } |
| 218 | |
| 219 | const angle::PackedEnumMap<BufferBinding, State::BufferBindingSetter> State::kBufferSetters = {{ |
| 220 | GetBufferBindingSetter<BufferBinding::Array>(), |
| 221 | GetBufferBindingSetter<BufferBinding::AtomicCounter>(), |
| 222 | GetBufferBindingSetter<BufferBinding::CopyRead>(), |
| 223 | GetBufferBindingSetter<BufferBinding::CopyWrite>(), |
| 224 | GetBufferBindingSetter<BufferBinding::DispatchIndirect>(), |
| 225 | GetBufferBindingSetter<BufferBinding::DrawIndirect>(), |
| 226 | GetBufferBindingSetter<BufferBinding::ElementArray>(), |
| 227 | GetBufferBindingSetter<BufferBinding::PixelPack>(), |
| 228 | GetBufferBindingSetter<BufferBinding::PixelUnpack>(), |
| 229 | GetBufferBindingSetter<BufferBinding::ShaderStorage>(), |
| 230 | GetBufferBindingSetter<BufferBinding::TransformFeedback>(), |
| 231 | GetBufferBindingSetter<BufferBinding::Uniform>(), |
| 232 | }}; |
| 233 | |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 234 | State::State(ContextID contextIn, |
| 235 | const State *shareContextState, |
| 236 | TextureManager *shareTextures, |
| 237 | const Version &clientVersion, |
| 238 | bool debug, |
Geoff Lang | 4fb8a8b | 2018-06-01 16:47:57 -0400 | [diff] [blame] | 239 | bool bindGeneratesResource, |
| 240 | bool clientArraysEnabled, |
| 241 | bool robustResourceInit, |
| 242 | bool programBinaryCacheEnabled) |
Jamie Madill | c3dc5d4 | 2018-12-30 12:12:04 -0500 | [diff] [blame] | 243 | : mClientVersion(clientVersion), |
| 244 | mContext(contextIn), |
| 245 | mBufferManager(AllocateOrGetSharedResourceManager(shareContextState, &State::mBufferManager)), |
| 246 | mShaderProgramManager( |
| 247 | AllocateOrGetSharedResourceManager(shareContextState, &State::mShaderProgramManager)), |
| 248 | mTextureManager(AllocateOrGetSharedTextureManager(shareContextState, |
| 249 | shareTextures, |
| 250 | &State::mTextureManager)), |
| 251 | mRenderbufferManager( |
| 252 | AllocateOrGetSharedResourceManager(shareContextState, &State::mRenderbufferManager)), |
| 253 | mSamplerManager( |
| 254 | AllocateOrGetSharedResourceManager(shareContextState, &State::mSamplerManager)), |
| 255 | mSyncManager(AllocateOrGetSharedResourceManager(shareContextState, &State::mSyncManager)), |
| 256 | mPathManager(AllocateOrGetSharedResourceManager(shareContextState, &State::mPathManager)), |
| 257 | mFramebufferManager(new FramebufferManager()), |
| 258 | mProgramPipelineManager(new ProgramPipelineManager()), |
| 259 | mMaxDrawBuffers(0), |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 260 | mMaxCombinedTextureImageUnits(0), |
| 261 | mDepthClearValue(0), |
| 262 | mStencilClearValue(0), |
| 263 | mScissorTest(false), |
| 264 | mSampleCoverage(false), |
| 265 | mSampleCoverageValue(0), |
| 266 | mSampleCoverageInvert(false), |
Jiawei Shao | db34227 | 2017-09-27 10:21:45 +0800 | [diff] [blame] | 267 | mSampleMask(false), |
| 268 | mMaxSampleMaskWords(0), |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 269 | mStencilRef(0), |
| 270 | mStencilBackRef(0), |
| 271 | mLineWidth(0), |
| 272 | mGenerateMipmapHint(GL_NONE), |
| 273 | mFragmentShaderDerivativeHint(GL_NONE), |
Geoff Lang | 4fb8a8b | 2018-06-01 16:47:57 -0400 | [diff] [blame] | 274 | mBindGeneratesResource(bindGeneratesResource), |
| 275 | mClientArraysEnabled(clientArraysEnabled), |
Jamie Madill | e79b1e1 | 2015-11-04 16:36:37 -0500 | [diff] [blame] | 276 | mNearZ(0), |
| 277 | mFarZ(0), |
| 278 | mReadFramebuffer(nullptr), |
| 279 | mDrawFramebuffer(nullptr), |
| 280 | mProgram(nullptr), |
| 281 | mVertexArray(nullptr), |
| 282 | mActiveSampler(0), |
Jamie Madill | 4787d70 | 2018-08-08 15:49:26 -0400 | [diff] [blame] | 283 | mActiveTexturesCache{}, |
James Darpinian | e4109f2 | 2018-12-13 16:25:53 -0800 | [diff] [blame] | 284 | mTexturesIncompatibleWithSamplers(0), |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 285 | mPrimitiveRestart(false), |
Geoff Lang | 4fb8a8b | 2018-06-01 16:47:57 -0400 | [diff] [blame] | 286 | mDebug(debug), |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 287 | mMultiSampling(false), |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 288 | mSampleAlphaToOne(false), |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 289 | mFramebufferSRGB(true), |
Geoff Lang | 4fb8a8b | 2018-06-01 16:47:57 -0400 | [diff] [blame] | 290 | mRobustResourceInit(robustResourceInit), |
jchen10 | 82af620 | 2018-06-22 10:59:52 +0800 | [diff] [blame] | 291 | mProgramBinaryCacheEnabled(programBinaryCacheEnabled), |
| 292 | mMaxShaderCompilerThreads(std::numeric_limits<GLuint>::max()) |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 293 | {} |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 294 | |
Jamie Madill | b980c56 | 2018-11-27 11:34:27 -0500 | [diff] [blame] | 295 | State::~State() {} |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 296 | |
Jamie Madill | 6c43a01 | 2018-08-08 15:49:27 -0400 | [diff] [blame] | 297 | void State::initialize(Context *context) |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 298 | { |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 299 | const Caps &caps = context->getCaps(); |
| 300 | const Extensions &extensions = context->getExtensions(); |
Geoff Lang | 4751aab | 2017-10-30 15:14:52 -0400 | [diff] [blame] | 301 | const Extensions &nativeExtensions = context->getImplementation()->getNativeExtensions(); |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 302 | const Version &clientVersion = context->getClientVersion(); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 303 | |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 304 | mMaxDrawBuffers = caps.maxDrawBuffers; |
Shannon Woods | 2df6a60 | 2014-09-26 16:12:07 -0400 | [diff] [blame] | 305 | mMaxCombinedTextureImageUnits = caps.maxCombinedTextureImageUnits; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 306 | |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 307 | setColorClearValue(0.0f, 0.0f, 0.0f, 0.0f); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 308 | |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 309 | mDepthClearValue = 1.0f; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 310 | mStencilClearValue = 0; |
| 311 | |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 312 | mScissorTest = false; |
| 313 | mScissor.x = 0; |
| 314 | mScissor.y = 0; |
| 315 | mScissor.width = 0; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 316 | mScissor.height = 0; |
| 317 | |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 318 | mBlendColor.red = 0; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 319 | mBlendColor.green = 0; |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 320 | mBlendColor.blue = 0; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 321 | mBlendColor.alpha = 0; |
| 322 | |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 323 | mStencilRef = 0; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 324 | mStencilBackRef = 0; |
| 325 | |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 326 | mSampleCoverage = false; |
| 327 | mSampleCoverageValue = 1.0f; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 328 | mSampleCoverageInvert = false; |
Jiawei Shao | db34227 | 2017-09-27 10:21:45 +0800 | [diff] [blame] | 329 | |
| 330 | mMaxSampleMaskWords = caps.maxSampleMaskWords; |
| 331 | mSampleMask = false; |
| 332 | mSampleMaskValues.fill(~GLbitfield(0)); |
| 333 | |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 334 | mGenerateMipmapHint = GL_DONT_CARE; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 335 | mFragmentShaderDerivativeHint = GL_DONT_CARE; |
| 336 | |
| 337 | mLineWidth = 1.0f; |
| 338 | |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 339 | mViewport.x = 0; |
| 340 | mViewport.y = 0; |
| 341 | mViewport.width = 0; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 342 | mViewport.height = 0; |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 343 | mNearZ = 0.0f; |
| 344 | mFarZ = 1.0f; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 345 | |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 346 | mBlend.colorMaskRed = true; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 347 | mBlend.colorMaskGreen = true; |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 348 | mBlend.colorMaskBlue = true; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 349 | mBlend.colorMaskAlpha = true; |
| 350 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 351 | mActiveSampler = 0; |
| 352 | |
Shannon Woods | 23e0500 | 2014-09-22 19:07:27 -0400 | [diff] [blame] | 353 | mVertexAttribCurrentValues.resize(caps.maxVertexAttributes); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 354 | |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 355 | // Set all indexes in state attributes type mask to float (default) |
| 356 | for (int i = 0; i < MAX_VERTEX_ATTRIBS; i++) |
| 357 | { |
| 358 | mCurrentValuesTypeMask.setIndex(GL_FLOAT, i); |
| 359 | } |
| 360 | |
Geoff Lang | 4dc3af0 | 2016-11-18 14:09:27 -0500 | [diff] [blame] | 361 | mUniformBuffers.resize(caps.maxUniformBufferBindings); |
Shannon Woods | f3acaf9 | 2014-09-23 18:07:11 -0400 | [diff] [blame] | 362 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 363 | mSamplerTextures[TextureType::_2D].resize(caps.maxCombinedTextureImageUnits); |
| 364 | mSamplerTextures[TextureType::CubeMap].resize(caps.maxCombinedTextureImageUnits); |
Geoff Lang | eb66a6e | 2016-10-31 13:06:12 -0400 | [diff] [blame] | 365 | if (clientVersion >= Version(3, 0)) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 366 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 367 | // TODO: These could also be enabled via extension |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 368 | mSamplerTextures[TextureType::_2DArray].resize(caps.maxCombinedTextureImageUnits); |
| 369 | mSamplerTextures[TextureType::_3D].resize(caps.maxCombinedTextureImageUnits); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 370 | } |
Yizhou Jiang | 7818a85 | 2018-09-06 15:02:04 +0800 | [diff] [blame] | 371 | if (clientVersion >= Version(3, 1) || nativeExtensions.textureMultisample) |
| 372 | { |
| 373 | mSamplerTextures[TextureType::_2DMultisample].resize(caps.maxCombinedTextureImageUnits); |
| 374 | } |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 375 | if (clientVersion >= Version(3, 1)) |
| 376 | { |
Olli Etuaho | d310a43 | 2018-08-24 15:40:23 +0300 | [diff] [blame] | 377 | mSamplerTextures[TextureType::_2DMultisampleArray].resize( |
| 378 | caps.maxCombinedTextureImageUnits); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 379 | |
| 380 | mAtomicCounterBuffers.resize(caps.maxAtomicCounterBufferBindings); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 381 | mShaderStorageBuffers.resize(caps.maxShaderStorageBufferBindings); |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 382 | mImageUnits.resize(caps.maxImageUnits); |
Geoff Lang | 3b57361 | 2016-10-31 14:08:10 -0400 | [diff] [blame] | 383 | } |
Geoff Lang | 4751aab | 2017-10-30 15:14:52 -0400 | [diff] [blame] | 384 | if (nativeExtensions.textureRectangle) |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 385 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 386 | mSamplerTextures[TextureType::Rectangle].resize(caps.maxCombinedTextureImageUnits); |
Corentin Wallez | 13c0dd4 | 2017-07-04 18:27:01 -0400 | [diff] [blame] | 387 | } |
Geoff Lang | 4751aab | 2017-10-30 15:14:52 -0400 | [diff] [blame] | 388 | if (nativeExtensions.eglImageExternal || nativeExtensions.eglStreamConsumerExternal) |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 389 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 390 | mSamplerTextures[TextureType::External].resize(caps.maxCombinedTextureImageUnits); |
Ian Ewell | bda7559 | 2016-04-18 17:25:54 -0400 | [diff] [blame] | 391 | } |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 392 | mCompleteTextureBindings.reserve(caps.maxCombinedTextureImageUnits); |
| 393 | for (uint32_t textureIndex = 0; textureIndex < caps.maxCombinedTextureImageUnits; |
| 394 | ++textureIndex) |
| 395 | { |
Jamie Madill | 6c43a01 | 2018-08-08 15:49:27 -0400 | [diff] [blame] | 396 | mCompleteTextureBindings.emplace_back(context, textureIndex); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 397 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 398 | |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 399 | mSamplers.resize(caps.maxCombinedTextureImageUnits); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 400 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 401 | for (QueryType type : angle::AllEnums<QueryType>()) |
| 402 | { |
| 403 | mActiveQueries[type].set(context, nullptr); |
| 404 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 405 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 406 | mProgram = nullptr; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 407 | |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 408 | mReadFramebuffer = nullptr; |
| 409 | mDrawFramebuffer = nullptr; |
Jamie Madill | b4b53c5 | 2015-02-03 15:22:48 -0500 | [diff] [blame] | 410 | |
| 411 | mPrimitiveRestart = false; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 412 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 413 | mDebug.setMaxLoggedMessages(extensions.maxDebugLoggedMessages); |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 414 | |
Geoff Lang | 488130e | 2017-09-27 13:53:11 -0400 | [diff] [blame] | 415 | mMultiSampling = true; |
| 416 | mSampleAlphaToOne = false; |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 417 | |
| 418 | mCoverageModulation = GL_NONE; |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 419 | |
| 420 | angle::Matrix<GLfloat>::setToIdentity(mPathMatrixProj); |
| 421 | angle::Matrix<GLfloat>::setToIdentity(mPathMatrixMV); |
| 422 | mPathStencilFunc = GL_ALWAYS; |
| 423 | mPathStencilRef = 0; |
| 424 | mPathStencilMask = std::numeric_limits<GLuint>::max(); |
Jamie Madill | e08a1d3 | 2017-03-07 17:24:06 -0500 | [diff] [blame] | 425 | |
Lingfeng Yang | dbb9c53 | 2018-02-25 19:58:24 -0800 | [diff] [blame] | 426 | // GLES1 emulation: Initialize state for GLES1 if version |
| 427 | // applies |
| 428 | if (clientVersion < Version(2, 0)) |
| 429 | { |
Lingfeng Yang | e547aac | 2018-04-05 09:39:20 -0700 | [diff] [blame] | 430 | mGLES1State.initialize(context, this); |
Lingfeng Yang | dbb9c53 | 2018-02-25 19:58:24 -0800 | [diff] [blame] | 431 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 432 | } |
| 433 | |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 434 | void State::reset(const Context *context) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 435 | { |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 436 | for (auto &bindingVec : mSamplerTextures) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 437 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 438 | for (size_t textureIdx = 0; textureIdx < bindingVec.size(); textureIdx++) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 439 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 440 | bindingVec[textureIdx].set(context, nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 441 | } |
| 442 | } |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 443 | for (size_t samplerIdx = 0; samplerIdx < mSamplers.size(); samplerIdx++) |
| 444 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 445 | mSamplers[samplerIdx].set(context, nullptr); |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 446 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 447 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 448 | for (auto &imageUnit : mImageUnits) |
| 449 | { |
| 450 | imageUnit.texture.set(context, nullptr); |
| 451 | imageUnit.level = 0; |
| 452 | imageUnit.layered = false; |
| 453 | imageUnit.layer = 0; |
| 454 | imageUnit.access = GL_READ_ONLY; |
| 455 | imageUnit.format = GL_R32UI; |
| 456 | } |
| 457 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 458 | mRenderbuffer.set(context, nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 459 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 460 | for (auto type : angle::AllEnums<BufferBinding>()) |
| 461 | { |
Jamie Madill | bf5177d | 2018-08-21 12:58:20 -0400 | [diff] [blame] | 462 | UpdateBufferBinding(context, &mBoundBuffers[type], nullptr, type); |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 463 | } |
| 464 | |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 465 | if (mProgram) |
| 466 | { |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 467 | mProgram->release(context); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 468 | } |
Yunchao He | d7297bf | 2017-04-19 15:27:10 +0800 | [diff] [blame] | 469 | mProgram = nullptr; |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 470 | |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 471 | mProgramPipeline.set(context, nullptr); |
| 472 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 473 | if (mTransformFeedback.get()) |
Jamie Madill | 7267aa6 | 2018-04-17 15:28:21 -0400 | [diff] [blame] | 474 | mTransformFeedback->onBindingChanged(context, false); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 475 | mTransformFeedback.set(context, nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 476 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 477 | for (QueryType type : angle::AllEnums<QueryType>()) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 478 | { |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 479 | mActiveQueries[type].set(context, nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 480 | } |
| 481 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 482 | for (auto &buf : mUniformBuffers) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 483 | { |
Jamie Madill | bf5177d | 2018-08-21 12:58:20 -0400 | [diff] [blame] | 484 | UpdateIndexedBufferBinding(context, &buf, nullptr, BufferBinding::Uniform, 0, 0); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 485 | } |
| 486 | |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 487 | for (auto &buf : mAtomicCounterBuffers) |
| 488 | { |
Jamie Madill | bf5177d | 2018-08-21 12:58:20 -0400 | [diff] [blame] | 489 | UpdateIndexedBufferBinding(context, &buf, nullptr, BufferBinding::AtomicCounter, 0, 0); |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 490 | } |
| 491 | |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 492 | for (auto &buf : mShaderStorageBuffers) |
| 493 | { |
Jamie Madill | bf5177d | 2018-08-21 12:58:20 -0400 | [diff] [blame] | 494 | UpdateIndexedBufferBinding(context, &buf, nullptr, BufferBinding::ShaderStorage, 0, 0); |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 495 | } |
| 496 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 497 | angle::Matrix<GLfloat>::setToIdentity(mPathMatrixProj); |
| 498 | angle::Matrix<GLfloat>::setToIdentity(mPathMatrixMV); |
| 499 | mPathStencilFunc = GL_ALWAYS; |
| 500 | mPathStencilRef = 0; |
| 501 | mPathStencilMask = std::numeric_limits<GLuint>::max(); |
| 502 | |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 503 | setAllDirtyBits(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 504 | } |
| 505 | |
Jamie Madill | e3bb6b7 | 2018-10-03 17:51:15 -0400 | [diff] [blame] | 506 | ANGLE_INLINE void State::unsetActiveTextures(ActiveTextureMask textureMask) |
| 507 | { |
| 508 | // Unset any relevant bound textures. |
| 509 | for (size_t textureIndex : mProgram->getActiveSamplersMask()) |
| 510 | { |
| 511 | mActiveTexturesCache[textureIndex] = nullptr; |
| 512 | mCompleteTextureBindings[textureIndex].reset(); |
| 513 | } |
| 514 | } |
| 515 | |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 516 | ANGLE_INLINE void State::updateActiveTextureState(const Context *context, |
| 517 | size_t textureIndex, |
| 518 | const Sampler *sampler, |
| 519 | Texture *texture) |
| 520 | { |
| 521 | if (!texture->isSamplerComplete(context, sampler)) |
| 522 | { |
| 523 | mActiveTexturesCache[textureIndex] = nullptr; |
| 524 | } |
| 525 | else |
| 526 | { |
| 527 | mActiveTexturesCache[textureIndex] = texture; |
| 528 | |
| 529 | if (texture->hasAnyDirtyBit()) |
| 530 | { |
| 531 | setTextureDirty(textureIndex); |
| 532 | } |
| 533 | |
Jamie Madill | 132d15c | 2018-11-30 15:25:38 -0500 | [diff] [blame] | 534 | if (mRobustResourceInit && texture->initState() == InitState::MayNeedInit) |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 535 | { |
Jamie Madill | 132d15c | 2018-11-30 15:25:38 -0500 | [diff] [blame] | 536 | mDirtyObjects.set(DIRTY_OBJECT_TEXTURES_INIT); |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 537 | } |
| 538 | } |
| 539 | |
James Darpinian | e4109f2 | 2018-12-13 16:25:53 -0800 | [diff] [blame] | 540 | mTexturesIncompatibleWithSamplers[textureIndex] = |
| 541 | !texture->getTextureState().compatibleWithSamplerFormat( |
| 542 | mProgram->getState().getSamplerFormatForTextureUnitIndex(textureIndex)); |
| 543 | |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 544 | mDirtyBits.set(DIRTY_BIT_TEXTURE_BINDINGS); |
| 545 | } |
| 546 | |
| 547 | ANGLE_INLINE void State::updateActiveTexture(const Context *context, |
| 548 | size_t textureIndex, |
| 549 | Texture *texture) |
Jamie Madill | e3bb6b7 | 2018-10-03 17:51:15 -0400 | [diff] [blame] | 550 | { |
| 551 | const Sampler *sampler = mSamplers[textureIndex].get(); |
| 552 | |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 553 | mCompleteTextureBindings[textureIndex].bind(texture); |
| 554 | |
Jamie Madill | e3bb6b7 | 2018-10-03 17:51:15 -0400 | [diff] [blame] | 555 | if (!texture) |
| 556 | { |
| 557 | mActiveTexturesCache[textureIndex] = nullptr; |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 558 | mDirtyBits.set(DIRTY_BIT_TEXTURE_BINDINGS); |
| 559 | return; |
Jamie Madill | e3bb6b7 | 2018-10-03 17:51:15 -0400 | [diff] [blame] | 560 | } |
| 561 | |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 562 | updateActiveTextureState(context, textureIndex, sampler, texture); |
Jamie Madill | e3bb6b7 | 2018-10-03 17:51:15 -0400 | [diff] [blame] | 563 | } |
| 564 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 565 | const RasterizerState &State::getRasterizerState() const |
| 566 | { |
| 567 | return mRasterizer; |
| 568 | } |
| 569 | |
| 570 | const BlendState &State::getBlendState() const |
| 571 | { |
| 572 | return mBlend; |
| 573 | } |
| 574 | |
| 575 | const DepthStencilState &State::getDepthStencilState() const |
| 576 | { |
| 577 | return mDepthStencil; |
| 578 | } |
| 579 | |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 580 | void State::setColorClearValue(float red, float green, float blue, float alpha) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 581 | { |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 582 | mColorClearValue.red = red; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 583 | mColorClearValue.green = green; |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 584 | mColorClearValue.blue = blue; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 585 | mColorClearValue.alpha = alpha; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 586 | mDirtyBits.set(DIRTY_BIT_CLEAR_COLOR); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 587 | } |
| 588 | |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 589 | void State::setDepthClearValue(float depth) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 590 | { |
| 591 | mDepthClearValue = depth; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 592 | mDirtyBits.set(DIRTY_BIT_CLEAR_DEPTH); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 593 | } |
| 594 | |
Jamie Madill | f75ab35 | 2015-03-16 10:46:52 -0400 | [diff] [blame] | 595 | void State::setStencilClearValue(int stencil) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 596 | { |
| 597 | mStencilClearValue = stencil; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 598 | mDirtyBits.set(DIRTY_BIT_CLEAR_STENCIL); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 599 | } |
| 600 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 601 | void State::setColorMask(bool red, bool green, bool blue, bool alpha) |
| 602 | { |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 603 | mBlend.colorMaskRed = red; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 604 | mBlend.colorMaskGreen = green; |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 605 | mBlend.colorMaskBlue = blue; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 606 | mBlend.colorMaskAlpha = alpha; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 607 | mDirtyBits.set(DIRTY_BIT_COLOR_MASK); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | void State::setDepthMask(bool mask) |
| 611 | { |
| 612 | mDepthStencil.depthMask = mask; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 613 | mDirtyBits.set(DIRTY_BIT_DEPTH_MASK); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 614 | } |
| 615 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 616 | void State::setRasterizerDiscard(bool enabled) |
| 617 | { |
| 618 | mRasterizer.rasterizerDiscard = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 619 | mDirtyBits.set(DIRTY_BIT_RASTERIZER_DISCARD_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 620 | } |
| 621 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 622 | void State::setCullFace(bool enabled) |
| 623 | { |
| 624 | mRasterizer.cullFace = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 625 | mDirtyBits.set(DIRTY_BIT_CULL_FACE_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 626 | } |
| 627 | |
Corentin Wallez | 2e568cf | 2017-09-18 17:05:22 -0400 | [diff] [blame] | 628 | void State::setCullMode(CullFaceMode mode) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 629 | { |
| 630 | mRasterizer.cullMode = mode; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 631 | mDirtyBits.set(DIRTY_BIT_CULL_FACE); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | void State::setFrontFace(GLenum front) |
| 635 | { |
| 636 | mRasterizer.frontFace = front; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 637 | mDirtyBits.set(DIRTY_BIT_FRONT_FACE); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 638 | } |
| 639 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 640 | void State::setDepthTest(bool enabled) |
| 641 | { |
| 642 | mDepthStencil.depthTest = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 643 | mDirtyBits.set(DIRTY_BIT_DEPTH_TEST_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | void State::setDepthFunc(GLenum depthFunc) |
| 647 | { |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 648 | mDepthStencil.depthFunc = depthFunc; |
| 649 | mDirtyBits.set(DIRTY_BIT_DEPTH_FUNC); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | void State::setDepthRange(float zNear, float zFar) |
| 653 | { |
| 654 | mNearZ = zNear; |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 655 | mFarZ = zFar; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 656 | mDirtyBits.set(DIRTY_BIT_DEPTH_RANGE); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 657 | } |
| 658 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 659 | void State::setBlend(bool enabled) |
| 660 | { |
| 661 | mBlend.blend = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 662 | mDirtyBits.set(DIRTY_BIT_BLEND_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 663 | } |
| 664 | |
| 665 | void State::setBlendFactors(GLenum sourceRGB, GLenum destRGB, GLenum sourceAlpha, GLenum destAlpha) |
| 666 | { |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 667 | mBlend.sourceBlendRGB = sourceRGB; |
| 668 | mBlend.destBlendRGB = destRGB; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 669 | mBlend.sourceBlendAlpha = sourceAlpha; |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 670 | mBlend.destBlendAlpha = destAlpha; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 671 | mDirtyBits.set(DIRTY_BIT_BLEND_FUNCS); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | void State::setBlendColor(float red, float green, float blue, float alpha) |
| 675 | { |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 676 | mBlendColor.red = red; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 677 | mBlendColor.green = green; |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 678 | mBlendColor.blue = blue; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 679 | mBlendColor.alpha = alpha; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 680 | mDirtyBits.set(DIRTY_BIT_BLEND_COLOR); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | void State::setBlendEquation(GLenum rgbEquation, GLenum alphaEquation) |
| 684 | { |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 685 | mBlend.blendEquationRGB = rgbEquation; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 686 | mBlend.blendEquationAlpha = alphaEquation; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 687 | mDirtyBits.set(DIRTY_BIT_BLEND_EQUATIONS); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 688 | } |
| 689 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 690 | void State::setStencilTest(bool enabled) |
| 691 | { |
| 692 | mDepthStencil.stencilTest = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 693 | mDirtyBits.set(DIRTY_BIT_STENCIL_TEST_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | void State::setStencilParams(GLenum stencilFunc, GLint stencilRef, GLuint stencilMask) |
| 697 | { |
| 698 | mDepthStencil.stencilFunc = stencilFunc; |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 699 | mStencilRef = (stencilRef > 0) ? stencilRef : 0; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 700 | mDepthStencil.stencilMask = stencilMask; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 701 | mDirtyBits.set(DIRTY_BIT_STENCIL_FUNCS_FRONT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 702 | } |
| 703 | |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 704 | void State::setStencilBackParams(GLenum stencilBackFunc, |
| 705 | GLint stencilBackRef, |
| 706 | GLuint stencilBackMask) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 707 | { |
| 708 | mDepthStencil.stencilBackFunc = stencilBackFunc; |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 709 | mStencilBackRef = (stencilBackRef > 0) ? stencilBackRef : 0; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 710 | mDepthStencil.stencilBackMask = stencilBackMask; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 711 | mDirtyBits.set(DIRTY_BIT_STENCIL_FUNCS_BACK); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | void State::setStencilWritemask(GLuint stencilWritemask) |
| 715 | { |
| 716 | mDepthStencil.stencilWritemask = stencilWritemask; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 717 | mDirtyBits.set(DIRTY_BIT_STENCIL_WRITEMASK_FRONT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | void State::setStencilBackWritemask(GLuint stencilBackWritemask) |
| 721 | { |
| 722 | mDepthStencil.stencilBackWritemask = stencilBackWritemask; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 723 | mDirtyBits.set(DIRTY_BIT_STENCIL_WRITEMASK_BACK); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 724 | } |
| 725 | |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 726 | void State::setStencilOperations(GLenum stencilFail, |
| 727 | GLenum stencilPassDepthFail, |
| 728 | GLenum stencilPassDepthPass) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 729 | { |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 730 | mDepthStencil.stencilFail = stencilFail; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 731 | mDepthStencil.stencilPassDepthFail = stencilPassDepthFail; |
| 732 | mDepthStencil.stencilPassDepthPass = stencilPassDepthPass; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 733 | mDirtyBits.set(DIRTY_BIT_STENCIL_OPS_FRONT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 734 | } |
| 735 | |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 736 | void State::setStencilBackOperations(GLenum stencilBackFail, |
| 737 | GLenum stencilBackPassDepthFail, |
| 738 | GLenum stencilBackPassDepthPass) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 739 | { |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 740 | mDepthStencil.stencilBackFail = stencilBackFail; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 741 | mDepthStencil.stencilBackPassDepthFail = stencilBackPassDepthFail; |
| 742 | mDepthStencil.stencilBackPassDepthPass = stencilBackPassDepthPass; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 743 | mDirtyBits.set(DIRTY_BIT_STENCIL_OPS_BACK); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 744 | } |
| 745 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 746 | void State::setPolygonOffsetFill(bool enabled) |
| 747 | { |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 748 | mRasterizer.polygonOffsetFill = enabled; |
| 749 | mDirtyBits.set(DIRTY_BIT_POLYGON_OFFSET_FILL_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | void State::setPolygonOffsetParams(GLfloat factor, GLfloat units) |
| 753 | { |
| 754 | // An application can pass NaN values here, so handle this gracefully |
| 755 | mRasterizer.polygonOffsetFactor = factor != factor ? 0.0f : factor; |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 756 | mRasterizer.polygonOffsetUnits = units != units ? 0.0f : units; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 757 | mDirtyBits.set(DIRTY_BIT_POLYGON_OFFSET); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 758 | } |
| 759 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 760 | void State::setSampleAlphaToCoverage(bool enabled) |
| 761 | { |
| 762 | mBlend.sampleAlphaToCoverage = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 763 | mDirtyBits.set(DIRTY_BIT_SAMPLE_ALPHA_TO_COVERAGE_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 764 | } |
| 765 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 766 | void State::setSampleCoverage(bool enabled) |
| 767 | { |
| 768 | mSampleCoverage = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 769 | mDirtyBits.set(DIRTY_BIT_SAMPLE_COVERAGE_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | void State::setSampleCoverageParams(GLclampf value, bool invert) |
| 773 | { |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 774 | mSampleCoverageValue = value; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 775 | mSampleCoverageInvert = invert; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 776 | mDirtyBits.set(DIRTY_BIT_SAMPLE_COVERAGE); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 777 | } |
| 778 | |
Jiawei Shao | db34227 | 2017-09-27 10:21:45 +0800 | [diff] [blame] | 779 | void State::setSampleMaskEnabled(bool enabled) |
| 780 | { |
| 781 | mSampleMask = enabled; |
| 782 | mDirtyBits.set(DIRTY_BIT_SAMPLE_MASK_ENABLED); |
| 783 | } |
| 784 | |
| 785 | void State::setSampleMaskParams(GLuint maskNumber, GLbitfield mask) |
| 786 | { |
| 787 | ASSERT(maskNumber < mMaxSampleMaskWords); |
| 788 | mSampleMaskValues[maskNumber] = mask; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 789 | // TODO(jmadill): Use a child dirty bit if we ever use more than two words. |
| 790 | mDirtyBits.set(DIRTY_BIT_SAMPLE_MASK); |
Jiawei Shao | db34227 | 2017-09-27 10:21:45 +0800 | [diff] [blame] | 791 | } |
| 792 | |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 793 | void State::setSampleAlphaToOne(bool enabled) |
| 794 | { |
| 795 | mSampleAlphaToOne = enabled; |
| 796 | mDirtyBits.set(DIRTY_BIT_SAMPLE_ALPHA_TO_ONE); |
| 797 | } |
| 798 | |
Sami Väisänen | 74c2347 | 2016-05-09 17:30:30 +0300 | [diff] [blame] | 799 | void State::setMultisampling(bool enabled) |
| 800 | { |
| 801 | mMultiSampling = enabled; |
| 802 | mDirtyBits.set(DIRTY_BIT_MULTISAMPLING); |
| 803 | } |
| 804 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 805 | void State::setScissorTest(bool enabled) |
| 806 | { |
| 807 | mScissorTest = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 808 | mDirtyBits.set(DIRTY_BIT_SCISSOR_TEST_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | void State::setScissorParams(GLint x, GLint y, GLsizei width, GLsizei height) |
| 812 | { |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 813 | mScissor.x = x; |
| 814 | mScissor.y = y; |
| 815 | mScissor.width = width; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 816 | mScissor.height = height; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 817 | mDirtyBits.set(DIRTY_BIT_SCISSOR); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 818 | } |
| 819 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 820 | void State::setDither(bool enabled) |
| 821 | { |
| 822 | mBlend.dither = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 823 | mDirtyBits.set(DIRTY_BIT_DITHER_ENABLED); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 824 | } |
| 825 | |
Jamie Madill | b4b53c5 | 2015-02-03 15:22:48 -0500 | [diff] [blame] | 826 | void State::setPrimitiveRestart(bool enabled) |
| 827 | { |
| 828 | mPrimitiveRestart = enabled; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 829 | mDirtyBits.set(DIRTY_BIT_PRIMITIVE_RESTART_ENABLED); |
Jamie Madill | b4b53c5 | 2015-02-03 15:22:48 -0500 | [diff] [blame] | 830 | } |
| 831 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 832 | void State::setEnableFeature(GLenum feature, bool enabled) |
| 833 | { |
| 834 | switch (feature) |
| 835 | { |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 836 | case GL_MULTISAMPLE_EXT: |
| 837 | setMultisampling(enabled); |
| 838 | break; |
| 839 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: |
| 840 | setSampleAlphaToOne(enabled); |
| 841 | break; |
| 842 | case GL_CULL_FACE: |
| 843 | setCullFace(enabled); |
| 844 | break; |
| 845 | case GL_POLYGON_OFFSET_FILL: |
| 846 | setPolygonOffsetFill(enabled); |
| 847 | break; |
| 848 | case GL_SAMPLE_ALPHA_TO_COVERAGE: |
| 849 | setSampleAlphaToCoverage(enabled); |
| 850 | break; |
| 851 | case GL_SAMPLE_COVERAGE: |
| 852 | setSampleCoverage(enabled); |
| 853 | break; |
| 854 | case GL_SCISSOR_TEST: |
| 855 | setScissorTest(enabled); |
| 856 | break; |
| 857 | case GL_STENCIL_TEST: |
| 858 | setStencilTest(enabled); |
| 859 | break; |
| 860 | case GL_DEPTH_TEST: |
| 861 | setDepthTest(enabled); |
| 862 | break; |
| 863 | case GL_BLEND: |
| 864 | setBlend(enabled); |
| 865 | break; |
| 866 | case GL_DITHER: |
| 867 | setDither(enabled); |
| 868 | break; |
| 869 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: |
| 870 | setPrimitiveRestart(enabled); |
| 871 | break; |
| 872 | case GL_RASTERIZER_DISCARD: |
| 873 | setRasterizerDiscard(enabled); |
| 874 | break; |
| 875 | case GL_SAMPLE_MASK: |
| 876 | setSampleMaskEnabled(enabled); |
| 877 | break; |
| 878 | case GL_DEBUG_OUTPUT_SYNCHRONOUS: |
| 879 | mDebug.setOutputSynchronous(enabled); |
| 880 | break; |
| 881 | case GL_DEBUG_OUTPUT: |
| 882 | mDebug.setOutputEnabled(enabled); |
| 883 | break; |
| 884 | case GL_FRAMEBUFFER_SRGB_EXT: |
| 885 | setFramebufferSRGB(enabled); |
| 886 | break; |
Lingfeng Yang | 13b708f | 2018-03-21 12:14:10 -0700 | [diff] [blame] | 887 | |
| 888 | // GLES1 emulation |
| 889 | case GL_ALPHA_TEST: |
| 890 | mGLES1State.mAlphaTestEnabled = enabled; |
| 891 | break; |
Lingfeng Yang | 23dc90b | 2018-04-23 09:01:49 -0700 | [diff] [blame] | 892 | case GL_TEXTURE_2D: |
| 893 | mGLES1State.mTexUnitEnables[mActiveSampler].set(TextureType::_2D, enabled); |
| 894 | break; |
| 895 | case GL_TEXTURE_CUBE_MAP: |
| 896 | mGLES1State.mTexUnitEnables[mActiveSampler].set(TextureType::CubeMap, enabled); |
| 897 | break; |
Lingfeng Yang | d0febe7 | 2018-05-17 22:36:52 -0700 | [diff] [blame] | 898 | case GL_LIGHTING: |
| 899 | mGLES1State.mLightingEnabled = enabled; |
| 900 | break; |
| 901 | case GL_LIGHT0: |
| 902 | case GL_LIGHT1: |
| 903 | case GL_LIGHT2: |
| 904 | case GL_LIGHT3: |
| 905 | case GL_LIGHT4: |
| 906 | case GL_LIGHT5: |
| 907 | case GL_LIGHT6: |
| 908 | case GL_LIGHT7: |
| 909 | mGLES1State.mLights[feature - GL_LIGHT0].enabled = enabled; |
| 910 | break; |
| 911 | case GL_NORMALIZE: |
| 912 | mGLES1State.mNormalizeEnabled = enabled; |
| 913 | break; |
| 914 | case GL_RESCALE_NORMAL: |
| 915 | mGLES1State.mRescaleNormalEnabled = enabled; |
| 916 | break; |
| 917 | case GL_COLOR_MATERIAL: |
| 918 | mGLES1State.mColorMaterialEnabled = enabled; |
| 919 | break; |
Lingfeng Yang | 060088a | 2018-05-30 20:40:57 -0700 | [diff] [blame] | 920 | case GL_CLIP_PLANE0: |
| 921 | case GL_CLIP_PLANE1: |
| 922 | case GL_CLIP_PLANE2: |
| 923 | case GL_CLIP_PLANE3: |
| 924 | case GL_CLIP_PLANE4: |
| 925 | case GL_CLIP_PLANE5: |
| 926 | mGLES1State.mClipPlanes[feature - GL_CLIP_PLANE0].enabled = enabled; |
| 927 | break; |
Lingfeng Yang | 7ba3f42 | 2018-06-01 09:43:04 -0700 | [diff] [blame] | 928 | case GL_FOG: |
| 929 | mGLES1State.mFogEnabled = enabled; |
| 930 | break; |
Lingfeng Yang | 9c4c092 | 2018-06-13 09:29:00 -0700 | [diff] [blame] | 931 | case GL_POINT_SMOOTH: |
| 932 | mGLES1State.mPointSmoothEnabled = enabled; |
| 933 | break; |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 934 | case GL_LINE_SMOOTH: |
| 935 | mGLES1State.mLineSmoothEnabled = enabled; |
| 936 | break; |
Lingfeng Yang | 9c4c092 | 2018-06-13 09:29:00 -0700 | [diff] [blame] | 937 | case GL_POINT_SPRITE_OES: |
| 938 | mGLES1State.mPointSpriteEnabled = enabled; |
| 939 | break; |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 940 | case GL_COLOR_LOGIC_OP: |
| 941 | mGLES1State.mLogicOpEnabled = enabled; |
| 942 | break; |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 943 | default: |
| 944 | UNREACHABLE(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 945 | } |
| 946 | } |
| 947 | |
Jamie Madill | dfde6ab | 2016-06-09 07:07:18 -0700 | [diff] [blame] | 948 | bool State::getEnableFeature(GLenum feature) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 949 | { |
| 950 | switch (feature) |
| 951 | { |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 952 | case GL_MULTISAMPLE_EXT: |
| 953 | return isMultisamplingEnabled(); |
| 954 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: |
| 955 | return isSampleAlphaToOneEnabled(); |
| 956 | case GL_CULL_FACE: |
| 957 | return isCullFaceEnabled(); |
| 958 | case GL_POLYGON_OFFSET_FILL: |
| 959 | return isPolygonOffsetFillEnabled(); |
| 960 | case GL_SAMPLE_ALPHA_TO_COVERAGE: |
| 961 | return isSampleAlphaToCoverageEnabled(); |
| 962 | case GL_SAMPLE_COVERAGE: |
| 963 | return isSampleCoverageEnabled(); |
| 964 | case GL_SCISSOR_TEST: |
| 965 | return isScissorTestEnabled(); |
| 966 | case GL_STENCIL_TEST: |
| 967 | return isStencilTestEnabled(); |
| 968 | case GL_DEPTH_TEST: |
| 969 | return isDepthTestEnabled(); |
| 970 | case GL_BLEND: |
| 971 | return isBlendEnabled(); |
| 972 | case GL_DITHER: |
| 973 | return isDitherEnabled(); |
| 974 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: |
| 975 | return isPrimitiveRestartEnabled(); |
| 976 | case GL_RASTERIZER_DISCARD: |
| 977 | return isRasterizerDiscardEnabled(); |
| 978 | case GL_SAMPLE_MASK: |
| 979 | return isSampleMaskEnabled(); |
| 980 | case GL_DEBUG_OUTPUT_SYNCHRONOUS: |
| 981 | return mDebug.isOutputSynchronous(); |
| 982 | case GL_DEBUG_OUTPUT: |
| 983 | return mDebug.isOutputEnabled(); |
| 984 | case GL_BIND_GENERATES_RESOURCE_CHROMIUM: |
| 985 | return isBindGeneratesResourceEnabled(); |
| 986 | case GL_CLIENT_ARRAYS_ANGLE: |
| 987 | return areClientArraysEnabled(); |
| 988 | case GL_FRAMEBUFFER_SRGB_EXT: |
| 989 | return getFramebufferSRGB(); |
| 990 | case GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE: |
| 991 | return mRobustResourceInit; |
| 992 | case GL_PROGRAM_CACHE_ENABLED_ANGLE: |
| 993 | return mProgramBinaryCacheEnabled; |
Jamie Madill | c43be72 | 2017-07-13 16:22:14 -0400 | [diff] [blame] | 994 | |
Lingfeng Yang | 13b708f | 2018-03-21 12:14:10 -0700 | [diff] [blame] | 995 | // GLES1 emulation |
| 996 | case GL_ALPHA_TEST: |
| 997 | return mGLES1State.mAlphaTestEnabled; |
Lingfeng Yang | 0107443 | 2018-04-16 10:19:51 -0700 | [diff] [blame] | 998 | case GL_VERTEX_ARRAY: |
| 999 | return mGLES1State.mVertexArrayEnabled; |
| 1000 | case GL_NORMAL_ARRAY: |
| 1001 | return mGLES1State.mNormalArrayEnabled; |
| 1002 | case GL_COLOR_ARRAY: |
| 1003 | return mGLES1State.mColorArrayEnabled; |
| 1004 | case GL_POINT_SIZE_ARRAY_OES: |
| 1005 | return mGLES1State.mPointSizeArrayEnabled; |
| 1006 | case GL_TEXTURE_COORD_ARRAY: |
| 1007 | return mGLES1State.mTexCoordArrayEnabled[mGLES1State.mClientActiveTexture]; |
Lingfeng Yang | 23dc90b | 2018-04-23 09:01:49 -0700 | [diff] [blame] | 1008 | case GL_TEXTURE_2D: |
| 1009 | return mGLES1State.mTexUnitEnables[mActiveSampler].test(TextureType::_2D); |
| 1010 | case GL_TEXTURE_CUBE_MAP: |
| 1011 | return mGLES1State.mTexUnitEnables[mActiveSampler].test(TextureType::CubeMap); |
Lingfeng Yang | d0febe7 | 2018-05-17 22:36:52 -0700 | [diff] [blame] | 1012 | case GL_LIGHTING: |
| 1013 | return mGLES1State.mLightingEnabled; |
| 1014 | case GL_LIGHT0: |
| 1015 | case GL_LIGHT1: |
| 1016 | case GL_LIGHT2: |
| 1017 | case GL_LIGHT3: |
| 1018 | case GL_LIGHT4: |
| 1019 | case GL_LIGHT5: |
| 1020 | case GL_LIGHT6: |
| 1021 | case GL_LIGHT7: |
| 1022 | return mGLES1State.mLights[feature - GL_LIGHT0].enabled; |
| 1023 | case GL_NORMALIZE: |
| 1024 | return mGLES1State.mNormalizeEnabled; |
| 1025 | case GL_RESCALE_NORMAL: |
| 1026 | return mGLES1State.mRescaleNormalEnabled; |
| 1027 | case GL_COLOR_MATERIAL: |
| 1028 | return mGLES1State.mColorMaterialEnabled; |
Lingfeng Yang | 060088a | 2018-05-30 20:40:57 -0700 | [diff] [blame] | 1029 | case GL_CLIP_PLANE0: |
| 1030 | case GL_CLIP_PLANE1: |
| 1031 | case GL_CLIP_PLANE2: |
| 1032 | case GL_CLIP_PLANE3: |
| 1033 | case GL_CLIP_PLANE4: |
| 1034 | case GL_CLIP_PLANE5: |
| 1035 | return mGLES1State.mClipPlanes[feature - GL_CLIP_PLANE0].enabled; |
Lingfeng Yang | 7ba3f42 | 2018-06-01 09:43:04 -0700 | [diff] [blame] | 1036 | case GL_FOG: |
| 1037 | return mGLES1State.mFogEnabled; |
Lingfeng Yang | 9c4c092 | 2018-06-13 09:29:00 -0700 | [diff] [blame] | 1038 | case GL_POINT_SMOOTH: |
| 1039 | return mGLES1State.mPointSmoothEnabled; |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 1040 | case GL_LINE_SMOOTH: |
| 1041 | return mGLES1State.mLineSmoothEnabled; |
Lingfeng Yang | 9c4c092 | 2018-06-13 09:29:00 -0700 | [diff] [blame] | 1042 | case GL_POINT_SPRITE_OES: |
| 1043 | return mGLES1State.mPointSpriteEnabled; |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 1044 | case GL_COLOR_LOGIC_OP: |
| 1045 | return mGLES1State.mLogicOpEnabled; |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 1046 | default: |
| 1047 | UNREACHABLE(); |
| 1048 | return false; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | void State::setLineWidth(GLfloat width) |
| 1053 | { |
| 1054 | mLineWidth = width; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1055 | mDirtyBits.set(DIRTY_BIT_LINE_WIDTH); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1056 | } |
| 1057 | |
| 1058 | void State::setGenerateMipmapHint(GLenum hint) |
| 1059 | { |
| 1060 | mGenerateMipmapHint = hint; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1061 | mDirtyBits.set(DIRTY_BIT_GENERATE_MIPMAP_HINT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1062 | } |
| 1063 | |
| 1064 | void State::setFragmentShaderDerivativeHint(GLenum hint) |
| 1065 | { |
| 1066 | mFragmentShaderDerivativeHint = hint; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1067 | mDirtyBits.set(DIRTY_BIT_SHADER_DERIVATIVE_HINT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1068 | // TODO: Propagate the hint to shader translator so we can write |
| 1069 | // ddx, ddx_coarse, or ddx_fine depending on the hint. |
| 1070 | // Ignore for now. It is valid for implementations to ignore hint. |
| 1071 | } |
| 1072 | |
| 1073 | void State::setViewportParams(GLint x, GLint y, GLsizei width, GLsizei height) |
| 1074 | { |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 1075 | mViewport.x = x; |
| 1076 | mViewport.y = y; |
| 1077 | mViewport.width = width; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1078 | mViewport.height = height; |
Jamie Madill | 1b94d43 | 2015-08-07 13:23:23 -0400 | [diff] [blame] | 1079 | mDirtyBits.set(DIRTY_BIT_VIEWPORT); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1080 | } |
| 1081 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1082 | void State::setActiveSampler(unsigned int active) |
| 1083 | { |
| 1084 | mActiveSampler = active; |
| 1085 | } |
| 1086 | |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 1087 | void State::setSamplerTexture(const Context *context, TextureType type, Texture *texture) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1088 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1089 | mSamplerTextures[type][mActiveSampler].set(context, texture); |
Jamie Madill | 1424681 | 2018-10-03 17:51:16 -0400 | [diff] [blame] | 1090 | |
| 1091 | if (mProgram && mProgram->getActiveSamplersMask()[mActiveSampler] && |
| 1092 | mProgram->getActiveSamplerTypes()[mActiveSampler] == type) |
| 1093 | { |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 1094 | updateActiveTexture(context, mActiveSampler, texture); |
Jamie Madill | 1424681 | 2018-10-03 17:51:16 -0400 | [diff] [blame] | 1095 | } |
| 1096 | |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1097 | mDirtyBits.set(DIRTY_BIT_TEXTURE_BINDINGS); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1098 | } |
| 1099 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1100 | Texture *State::getTargetTexture(TextureType type) const |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1101 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1102 | return getSamplerTexture(static_cast<unsigned int>(mActiveSampler), type); |
Jamie Madill | c29968b | 2016-01-20 11:17:23 -0500 | [diff] [blame] | 1103 | } |
| 1104 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1105 | GLuint State::getSamplerTextureId(unsigned int sampler, TextureType type) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1106 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1107 | ASSERT(sampler < mSamplerTextures[type].size()); |
| 1108 | return mSamplerTextures[type][sampler].id(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1109 | } |
| 1110 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1111 | void State::detachTexture(const Context *context, const TextureMap &zeroTextures, GLuint texture) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1112 | { |
| 1113 | // Textures have a detach method on State rather than a simple |
| 1114 | // removeBinding, because the zero/null texture objects are managed |
| 1115 | // separately, and don't have to go through the Context's maps or |
| 1116 | // the ResourceManager. |
| 1117 | |
| 1118 | // [OpenGL ES 2.0.24] section 3.8 page 84: |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 1119 | // If a texture object is deleted, it is as if all texture units which are bound to that texture |
| 1120 | // object are rebound to texture object zero |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1121 | |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1122 | for (TextureType type : angle::AllEnums<TextureType>()) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1123 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1124 | TextureBindingVector &textureVector = mSamplerTextures[type]; |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1125 | for (BindingPointer<Texture> &binding : textureVector) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1126 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 1127 | if (binding.id() == texture) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1128 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1129 | Texture *zeroTexture = zeroTextures[type].get(); |
| 1130 | ASSERT(zeroTexture != nullptr); |
Jamie Madill | e6382c3 | 2014-11-07 15:05:26 -0500 | [diff] [blame] | 1131 | // Zero textures are the "default" textures instead of NULL |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1132 | binding.set(context, zeroTexture); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1133 | mDirtyBits.set(DIRTY_BIT_TEXTURE_BINDINGS); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1134 | } |
| 1135 | } |
| 1136 | } |
| 1137 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 1138 | for (auto &bindingImageUnit : mImageUnits) |
| 1139 | { |
| 1140 | if (bindingImageUnit.texture.id() == texture) |
| 1141 | { |
| 1142 | bindingImageUnit.texture.set(context, nullptr); |
| 1143 | bindingImageUnit.level = 0; |
| 1144 | bindingImageUnit.layered = false; |
| 1145 | bindingImageUnit.layer = 0; |
| 1146 | bindingImageUnit.access = GL_READ_ONLY; |
| 1147 | bindingImageUnit.format = GL_R32UI; |
| 1148 | break; |
| 1149 | } |
| 1150 | } |
| 1151 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1152 | // [OpenGL ES 2.0.24] section 4.4 page 112: |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 1153 | // If a texture object is deleted while its image is attached to the currently bound |
| 1154 | // framebuffer, then it is as if Texture2DAttachment had been called, with a texture of 0, for |
| 1155 | // each attachment point to which this image was attached in the currently bound framebuffer. |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1156 | |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 1157 | if (mReadFramebuffer && mReadFramebuffer->detachTexture(context, texture)) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1158 | { |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 1159 | mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1160 | } |
| 1161 | |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 1162 | if (mDrawFramebuffer && mDrawFramebuffer->detachTexture(context, texture)) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1163 | { |
Jamie Madill | ef9fcd9 | 2018-11-28 14:03:59 -0500 | [diff] [blame] | 1164 | setDrawFramebufferDirty(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1165 | } |
| 1166 | } |
| 1167 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1168 | void State::initializeZeroTextures(const Context *context, const TextureMap &zeroTextures) |
Jamie Madill | e6382c3 | 2014-11-07 15:05:26 -0500 | [diff] [blame] | 1169 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1170 | for (TextureType type : angle::AllEnums<TextureType>()) |
Jamie Madill | e6382c3 | 2014-11-07 15:05:26 -0500 | [diff] [blame] | 1171 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1172 | for (size_t textureUnit = 0; textureUnit < mSamplerTextures[type].size(); ++textureUnit) |
Jamie Madill | e6382c3 | 2014-11-07 15:05:26 -0500 | [diff] [blame] | 1173 | { |
Corentin Wallez | f0e89be | 2017-11-08 14:00:32 -0800 | [diff] [blame] | 1174 | mSamplerTextures[type][textureUnit].set(context, zeroTextures[type].get()); |
Jamie Madill | e6382c3 | 2014-11-07 15:05:26 -0500 | [diff] [blame] | 1175 | } |
| 1176 | } |
| 1177 | } |
| 1178 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1179 | void State::setSamplerBinding(const Context *context, GLuint textureUnit, Sampler *sampler) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1180 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1181 | mSamplers[textureUnit].set(context, sampler); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1182 | mDirtyBits.set(DIRTY_BIT_SAMPLER_BINDINGS); |
Jamie Madill | e25b800 | 2018-09-20 13:39:49 -0400 | [diff] [blame] | 1183 | // This is overly conservative as it assumes the sampler has never been bound. |
| 1184 | setSamplerDirty(textureUnit); |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 1185 | onActiveTextureChange(context, textureUnit); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1186 | } |
| 1187 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1188 | void State::detachSampler(const Context *context, GLuint sampler) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1189 | { |
| 1190 | // [OpenGL ES 3.0.2] section 3.8.2 pages 123-124: |
| 1191 | // If a sampler object that is currently bound to one or more texture units is |
| 1192 | // deleted, it is as though BindSampler is called once for each texture unit to |
| 1193 | // which the sampler is bound, with unit set to the texture unit and sampler set to zero. |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1194 | for (BindingPointer<Sampler> &samplerBinding : mSamplers) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1195 | { |
Geoff Lang | 76b10c9 | 2014-09-05 16:28:14 -0400 | [diff] [blame] | 1196 | if (samplerBinding.id() == sampler) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1197 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1198 | samplerBinding.set(context, nullptr); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 1199 | mDirtyBits.set(DIRTY_BIT_SAMPLER_BINDINGS); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1200 | } |
| 1201 | } |
| 1202 | } |
| 1203 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1204 | void State::setRenderbufferBinding(const Context *context, Renderbuffer *renderbuffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1205 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1206 | mRenderbuffer.set(context, renderbuffer); |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 1207 | mDirtyBits.set(DIRTY_BIT_RENDERBUFFER_BINDING); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1208 | } |
| 1209 | |
Jamie Madill | a02315b | 2017-02-23 14:14:47 -0500 | [diff] [blame] | 1210 | void State::detachRenderbuffer(const Context *context, GLuint renderbuffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1211 | { |
| 1212 | // [OpenGL ES 2.0.24] section 4.4 page 109: |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 1213 | // If a renderbuffer that is currently bound to RENDERBUFFER is deleted, it is as though |
| 1214 | // BindRenderbuffer had been executed with the target RENDERBUFFER and name of zero. |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1215 | |
| 1216 | if (mRenderbuffer.id() == renderbuffer) |
| 1217 | { |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 1218 | setRenderbufferBinding(context, nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1219 | } |
| 1220 | |
| 1221 | // [OpenGL ES 2.0.24] section 4.4 page 111: |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 1222 | // If a renderbuffer object is deleted while its image is attached to the currently bound |
| 1223 | // framebuffer, then it is as if FramebufferRenderbuffer had been called, with a renderbuffer of |
| 1224 | // 0, for each attachment point to which this image was attached in the currently bound |
| 1225 | // framebuffer. |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1226 | |
| 1227 | Framebuffer *readFramebuffer = mReadFramebuffer; |
| 1228 | Framebuffer *drawFramebuffer = mDrawFramebuffer; |
| 1229 | |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 1230 | if (readFramebuffer && readFramebuffer->detachRenderbuffer(context, renderbuffer)) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1231 | { |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 1232 | mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | if (drawFramebuffer && drawFramebuffer != readFramebuffer) |
| 1236 | { |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 1237 | if (drawFramebuffer->detachRenderbuffer(context, renderbuffer)) |
| 1238 | { |
Jamie Madill | ef9fcd9 | 2018-11-28 14:03:59 -0500 | [diff] [blame] | 1239 | setDrawFramebufferDirty(); |
Jamie Madill | 8693bdb | 2017-09-02 15:32:14 -0400 | [diff] [blame] | 1240 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1241 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | void State::setReadFramebufferBinding(Framebuffer *framebuffer) |
| 1245 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1246 | if (mReadFramebuffer == framebuffer) |
| 1247 | return; |
| 1248 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1249 | mReadFramebuffer = framebuffer; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1250 | mDirtyBits.set(DIRTY_BIT_READ_FRAMEBUFFER_BINDING); |
| 1251 | |
| 1252 | if (mReadFramebuffer && mReadFramebuffer->hasAnyDirtyBit()) |
| 1253 | { |
| 1254 | mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
| 1255 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1256 | } |
| 1257 | |
| 1258 | void State::setDrawFramebufferBinding(Framebuffer *framebuffer) |
| 1259 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1260 | if (mDrawFramebuffer == framebuffer) |
| 1261 | return; |
| 1262 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1263 | mDrawFramebuffer = framebuffer; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1264 | mDirtyBits.set(DIRTY_BIT_DRAW_FRAMEBUFFER_BINDING); |
| 1265 | |
Jamie Madill | ef9fcd9 | 2018-11-28 14:03:59 -0500 | [diff] [blame] | 1266 | if (mDrawFramebuffer) |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1267 | { |
Jamie Madill | ef9fcd9 | 2018-11-28 14:03:59 -0500 | [diff] [blame] | 1268 | if (mDrawFramebuffer->hasAnyDirtyBit()) |
| 1269 | { |
| 1270 | mDirtyObjects.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
| 1271 | } |
| 1272 | |
| 1273 | if (mRobustResourceInit && mDrawFramebuffer->hasResourceThatNeedsInit()) |
| 1274 | { |
| 1275 | mDirtyObjects.set(DIRTY_OBJECT_DRAW_ATTACHMENTS); |
| 1276 | } |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1277 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | Framebuffer *State::getTargetFramebuffer(GLenum target) const |
| 1281 | { |
| 1282 | switch (target) |
| 1283 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1284 | case GL_READ_FRAMEBUFFER_ANGLE: |
| 1285 | return mReadFramebuffer; |
| 1286 | case GL_DRAW_FRAMEBUFFER_ANGLE: |
| 1287 | case GL_FRAMEBUFFER: |
| 1288 | return mDrawFramebuffer; |
| 1289 | default: |
| 1290 | UNREACHABLE(); |
Yunchao He | f81ce4a | 2017-04-24 10:49:17 +0800 | [diff] [blame] | 1291 | return nullptr; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1292 | } |
| 1293 | } |
| 1294 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1295 | bool State::removeReadFramebufferBinding(GLuint framebuffer) |
| 1296 | { |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 1297 | if (mReadFramebuffer != nullptr && mReadFramebuffer->id() == framebuffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1298 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1299 | setReadFramebufferBinding(nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1300 | return true; |
| 1301 | } |
| 1302 | |
| 1303 | return false; |
| 1304 | } |
| 1305 | |
| 1306 | bool State::removeDrawFramebufferBinding(GLuint framebuffer) |
| 1307 | { |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 1308 | if (mReadFramebuffer != nullptr && mDrawFramebuffer->id() == framebuffer) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1309 | { |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 1310 | setDrawFramebufferBinding(nullptr); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1311 | return true; |
| 1312 | } |
| 1313 | |
| 1314 | return false; |
| 1315 | } |
| 1316 | |
Jamie Madill | 7267aa6 | 2018-04-17 15:28:21 -0400 | [diff] [blame] | 1317 | void State::setVertexArrayBinding(const Context *context, VertexArray *vertexArray) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1318 | { |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 1319 | if (mVertexArray == vertexArray) |
| 1320 | return; |
| 1321 | if (mVertexArray) |
Jamie Madill | bf5177d | 2018-08-21 12:58:20 -0400 | [diff] [blame] | 1322 | mVertexArray->onBindingChanged(context, -1); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1323 | mVertexArray = vertexArray; |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 1324 | if (vertexArray) |
Jamie Madill | bf5177d | 2018-08-21 12:58:20 -0400 | [diff] [blame] | 1325 | vertexArray->onBindingChanged(context, 1); |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 1326 | mDirtyBits.set(DIRTY_BIT_VERTEX_ARRAY_BINDING); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 1327 | |
| 1328 | if (mVertexArray && mVertexArray->hasAnyDirtyBit()) |
| 1329 | { |
| 1330 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1331 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1332 | } |
| 1333 | |
Jamie Madill | 7267aa6 | 2018-04-17 15:28:21 -0400 | [diff] [blame] | 1334 | bool State::removeVertexArrayBinding(const Context *context, GLuint vertexArray) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1335 | { |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 1336 | if (mVertexArray && mVertexArray->id() == vertexArray) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1337 | { |
Jamie Madill | bf5177d | 2018-08-21 12:58:20 -0400 | [diff] [blame] | 1338 | mVertexArray->onBindingChanged(context, -1); |
Yunchao He | d7297bf | 2017-04-19 15:27:10 +0800 | [diff] [blame] | 1339 | mVertexArray = nullptr; |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 1340 | mDirtyBits.set(DIRTY_BIT_VERTEX_ARRAY_BINDING); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 1341 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1342 | return true; |
| 1343 | } |
| 1344 | |
| 1345 | return false; |
| 1346 | } |
| 1347 | |
Markus Tavenrath | 774fe56 | 2018-11-18 14:14:49 +0100 | [diff] [blame] | 1348 | GLuint State::getVertexArrayId() const |
| 1349 | { |
| 1350 | ASSERT(mVertexArray != nullptr); |
| 1351 | return mVertexArray->id(); |
| 1352 | } |
| 1353 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1354 | void State::bindVertexBuffer(const Context *context, |
| 1355 | GLuint bindingIndex, |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1356 | Buffer *boundBuffer, |
| 1357 | GLintptr offset, |
| 1358 | GLsizei stride) |
| 1359 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1360 | getVertexArray()->bindVertexBuffer(context, bindingIndex, boundBuffer, offset, stride); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1361 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1362 | } |
| 1363 | |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 1364 | void State::setVertexAttribBinding(const Context *context, GLuint attribIndex, GLuint bindingIndex) |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1365 | { |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 1366 | getVertexArray()->setVertexAttribBinding(context, attribIndex, bindingIndex); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1367 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1368 | } |
| 1369 | |
| 1370 | void State::setVertexAttribFormat(GLuint attribIndex, |
| 1371 | GLint size, |
Jamie Madill | dd34b3b | 2019-01-16 09:59:54 -0500 | [diff] [blame^] | 1372 | VertexAttribType type, |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 1373 | bool normalized, |
| 1374 | bool pureInteger, |
| 1375 | GLuint relativeOffset) |
| 1376 | { |
| 1377 | getVertexArray()->setVertexAttribFormat(attribIndex, size, type, normalized, pureInteger, |
| 1378 | relativeOffset); |
| 1379 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1380 | } |
| 1381 | |
| 1382 | void State::setVertexBindingDivisor(GLuint bindingIndex, GLuint divisor) |
| 1383 | { |
| 1384 | getVertexArray()->setVertexBindingDivisor(bindingIndex, divisor); |
| 1385 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 1386 | } |
| 1387 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 1388 | angle::Result State::setProgram(const Context *context, Program *newProgram) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1389 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1390 | if (mProgram != newProgram) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1391 | { |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1392 | if (mProgram) |
| 1393 | { |
Jamie Madill | e3bb6b7 | 2018-10-03 17:51:15 -0400 | [diff] [blame] | 1394 | unsetActiveTextures(mProgram->getActiveSamplersMask()); |
Jamie Madill | 6c1f671 | 2017-02-14 19:08:04 -0500 | [diff] [blame] | 1395 | mProgram->release(context); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | mProgram = newProgram; |
| 1399 | |
| 1400 | if (mProgram) |
| 1401 | { |
| 1402 | newProgram->addRef(); |
Jamie Madill | e3bb6b7 | 2018-10-03 17:51:15 -0400 | [diff] [blame] | 1403 | ANGLE_TRY(onProgramExecutableChange(context, newProgram)); |
Geoff Lang | 7dd2e10 | 2014-11-10 15:19:26 -0500 | [diff] [blame] | 1404 | } |
Jamie Madill | df836ff | 2018-10-01 10:36:24 -0400 | [diff] [blame] | 1405 | |
| 1406 | // Note that rendering is undefined if glUseProgram(0) is called. But ANGLE will generate |
| 1407 | // an error if the app tries to draw in this case. |
| 1408 | |
Jamie Madill | a779b61 | 2017-07-24 11:46:05 -0400 | [diff] [blame] | 1409 | mDirtyBits.set(DIRTY_BIT_PROGRAM_BINDING); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1410 | } |
Jamie Madill | e3bb6b7 | 2018-10-03 17:51:15 -0400 | [diff] [blame] | 1411 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1412 | return angle::Result::Continue; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1413 | } |
| 1414 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1415 | void State::setTransformFeedbackBinding(const Context *context, |
| 1416 | TransformFeedback *transformFeedback) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1417 | { |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 1418 | if (transformFeedback == mTransformFeedback.get()) |
| 1419 | return; |
| 1420 | if (mTransformFeedback.get()) |
Jamie Madill | 7267aa6 | 2018-04-17 15:28:21 -0400 | [diff] [blame] | 1421 | mTransformFeedback->onBindingChanged(context, false); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1422 | mTransformFeedback.set(context, transformFeedback); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 1423 | if (mTransformFeedback.get()) |
Jamie Madill | 7267aa6 | 2018-04-17 15:28:21 -0400 | [diff] [blame] | 1424 | mTransformFeedback->onBindingChanged(context, true); |
Geoff Lang | ded7923 | 2017-11-28 15:21:11 -0500 | [diff] [blame] | 1425 | mDirtyBits.set(DIRTY_BIT_TRANSFORM_FEEDBACK_BINDING); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1426 | } |
| 1427 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1428 | bool State::removeTransformFeedbackBinding(const Context *context, GLuint transformFeedback) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1429 | { |
| 1430 | if (mTransformFeedback.id() == transformFeedback) |
| 1431 | { |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 1432 | if (mTransformFeedback.get()) |
Jamie Madill | 7267aa6 | 2018-04-17 15:28:21 -0400 | [diff] [blame] | 1433 | mTransformFeedback->onBindingChanged(context, false); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1434 | mTransformFeedback.set(context, nullptr); |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 1435 | return true; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1436 | } |
Corentin Wallez | a2257da | 2016-04-19 16:43:12 -0400 | [diff] [blame] | 1437 | |
| 1438 | return false; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1439 | } |
| 1440 | |
Yunchao He | a336b90 | 2017-08-02 16:05:21 +0800 | [diff] [blame] | 1441 | void State::setProgramPipelineBinding(const Context *context, ProgramPipeline *pipeline) |
| 1442 | { |
| 1443 | mProgramPipeline.set(context, pipeline); |
| 1444 | } |
| 1445 | |
| 1446 | void State::detachProgramPipeline(const Context *context, GLuint pipeline) |
| 1447 | { |
| 1448 | mProgramPipeline.set(context, nullptr); |
| 1449 | } |
| 1450 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1451 | bool State::isQueryActive(QueryType type) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1452 | { |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1453 | const Query *query = mActiveQueries[type].get(); |
| 1454 | if (query != nullptr) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1455 | { |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1456 | return true; |
| 1457 | } |
| 1458 | |
| 1459 | QueryType alternativeType; |
| 1460 | if (GetAlternativeQueryType(type, &alternativeType)) |
| 1461 | { |
| 1462 | query = mActiveQueries[alternativeType].get(); |
| 1463 | return query != nullptr; |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1464 | } |
| 1465 | |
| 1466 | return false; |
| 1467 | } |
| 1468 | |
| 1469 | bool State::isQueryActive(Query *query) const |
| 1470 | { |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1471 | for (auto &queryPointer : mActiveQueries) |
Ian Ewell | 3ffd78b | 2016-01-22 16:09:42 -0500 | [diff] [blame] | 1472 | { |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1473 | if (queryPointer.get() == query) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1474 | { |
| 1475 | return true; |
| 1476 | } |
| 1477 | } |
| 1478 | |
| 1479 | return false; |
| 1480 | } |
| 1481 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1482 | void State::setActiveQuery(const Context *context, QueryType type, Query *query) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1483 | { |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1484 | mActiveQueries[type].set(context, query); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1485 | } |
| 1486 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1487 | GLuint State::getActiveQueryId(QueryType type) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1488 | { |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1489 | const Query *query = getActiveQuery(type); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1490 | return (query ? query->id() : 0u); |
| 1491 | } |
| 1492 | |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1493 | Query *State::getActiveQuery(QueryType type) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1494 | { |
Corentin Wallez | ad3ae90 | 2018-03-09 13:40:42 -0500 | [diff] [blame] | 1495 | return mActiveQueries[type].get(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1496 | } |
| 1497 | |
Geoff Lang | 9100226 | 2018-12-12 16:05:24 -0500 | [diff] [blame] | 1498 | angle::Result State::setIndexedBufferBinding(const Context *context, |
| 1499 | BufferBinding target, |
| 1500 | GLuint index, |
| 1501 | Buffer *buffer, |
| 1502 | GLintptr offset, |
| 1503 | GLsizeiptr size) |
Jiajia Qin | 9d7d0b1 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1504 | { |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 1505 | setBufferBinding(context, target, buffer); |
Jiajia Qin | 9d7d0b1 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 1506 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 1507 | switch (target) |
| 1508 | { |
| 1509 | case BufferBinding::TransformFeedback: |
Geoff Lang | 9100226 | 2018-12-12 16:05:24 -0500 | [diff] [blame] | 1510 | ANGLE_TRY(mTransformFeedback->bindIndexedBuffer(context, index, buffer, offset, size)); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 1511 | setBufferBinding(context, target, buffer); |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 1512 | break; |
| 1513 | case BufferBinding::Uniform: |
Jamie Madill | bf5177d | 2018-08-21 12:58:20 -0400 | [diff] [blame] | 1514 | UpdateIndexedBufferBinding(context, &mUniformBuffers[index], buffer, target, offset, |
| 1515 | size); |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 1516 | break; |
| 1517 | case BufferBinding::AtomicCounter: |
Jamie Madill | bf5177d | 2018-08-21 12:58:20 -0400 | [diff] [blame] | 1518 | UpdateIndexedBufferBinding(context, &mAtomicCounterBuffers[index], buffer, target, |
| 1519 | offset, size); |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 1520 | break; |
| 1521 | case BufferBinding::ShaderStorage: |
Jamie Madill | bf5177d | 2018-08-21 12:58:20 -0400 | [diff] [blame] | 1522 | UpdateIndexedBufferBinding(context, &mShaderStorageBuffers[index], buffer, target, |
| 1523 | offset, size); |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 1524 | break; |
| 1525 | default: |
| 1526 | UNREACHABLE(); |
| 1527 | break; |
| 1528 | } |
Geoff Lang | 9100226 | 2018-12-12 16:05:24 -0500 | [diff] [blame] | 1529 | |
| 1530 | return angle::Result::Continue; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1531 | } |
| 1532 | |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 1533 | const OffsetBindingPointer<Buffer> &State::getIndexedUniformBuffer(size_t index) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1534 | { |
Shannon Woods | f3acaf9 | 2014-09-23 18:07:11 -0400 | [diff] [blame] | 1535 | ASSERT(static_cast<size_t>(index) < mUniformBuffers.size()); |
Geoff Lang | 5d124a6 | 2015-09-15 13:03:27 -0400 | [diff] [blame] | 1536 | return mUniformBuffers[index]; |
Gregoire Payen de La Garanderie | 68694e9 | 2015-03-24 14:03:37 +0000 | [diff] [blame] | 1537 | } |
| 1538 | |
Jiajia Qin | 6eafb04 | 2016-12-27 17:04:07 +0800 | [diff] [blame] | 1539 | const OffsetBindingPointer<Buffer> &State::getIndexedAtomicCounterBuffer(size_t index) const |
| 1540 | { |
| 1541 | ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size()); |
| 1542 | return mAtomicCounterBuffers[index]; |
| 1543 | } |
| 1544 | |
Jiajia Qin | f546e7d | 2017-03-27 14:12:59 +0800 | [diff] [blame] | 1545 | const OffsetBindingPointer<Buffer> &State::getIndexedShaderStorageBuffer(size_t index) const |
| 1546 | { |
| 1547 | ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size()); |
| 1548 | return mShaderStorageBuffers[index]; |
| 1549 | } |
| 1550 | |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 1551 | Buffer *State::getTargetBuffer(BufferBinding target) const |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1552 | { |
| 1553 | switch (target) |
| 1554 | { |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 1555 | case BufferBinding::ElementArray: |
Jamie Madill | cd0a0a3 | 2018-10-18 18:41:57 -0400 | [diff] [blame] | 1556 | return getVertexArray()->getElementArrayBuffer(); |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 1557 | default: |
| 1558 | return mBoundBuffers[target].get(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1559 | } |
| 1560 | } |
| 1561 | |
Geoff Lang | 9100226 | 2018-12-12 16:05:24 -0500 | [diff] [blame] | 1562 | angle::Result State::detachBuffer(const Context *context, const Buffer *buffer) |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 1563 | { |
James Darpinian | 4d9d483 | 2018-03-13 12:43:28 -0700 | [diff] [blame] | 1564 | if (!buffer->isBound()) |
| 1565 | { |
Geoff Lang | 9100226 | 2018-12-12 16:05:24 -0500 | [diff] [blame] | 1566 | return angle::Result::Continue; |
James Darpinian | 4d9d483 | 2018-03-13 12:43:28 -0700 | [diff] [blame] | 1567 | } |
| 1568 | GLuint bufferName = buffer->id(); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 1569 | for (auto target : angle::AllEnums<BufferBinding>()) |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 1570 | { |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 1571 | if (mBoundBuffers[target].id() == bufferName) |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 1572 | { |
Jamie Madill | bf5177d | 2018-08-21 12:58:20 -0400 | [diff] [blame] | 1573 | UpdateBufferBinding(context, &mBoundBuffers[target], nullptr, target); |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 1574 | } |
| 1575 | } |
| 1576 | |
| 1577 | TransformFeedback *curTransformFeedback = getCurrentTransformFeedback(); |
| 1578 | if (curTransformFeedback) |
| 1579 | { |
Geoff Lang | 9100226 | 2018-12-12 16:05:24 -0500 | [diff] [blame] | 1580 | ANGLE_TRY(curTransformFeedback->detachBuffer(context, bufferName)); |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 1581 | } |
| 1582 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 1583 | getVertexArray()->detachBuffer(context, bufferName); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 1584 | |
| 1585 | for (auto &buf : mUniformBuffers) |
| 1586 | { |
| 1587 | if (buf.id() == bufferName) |
| 1588 | { |
Jamie Madill | bf5177d | 2018-08-21 12:58:20 -0400 | [diff] [blame] | 1589 | UpdateIndexedBufferBinding(context, &buf, nullptr, BufferBinding::Uniform, 0, 0); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 1590 | } |
| 1591 | } |
| 1592 | |
| 1593 | for (auto &buf : mAtomicCounterBuffers) |
| 1594 | { |
| 1595 | if (buf.id() == bufferName) |
| 1596 | { |
Jamie Madill | bf5177d | 2018-08-21 12:58:20 -0400 | [diff] [blame] | 1597 | UpdateIndexedBufferBinding(context, &buf, nullptr, BufferBinding::AtomicCounter, 0, 0); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 1598 | } |
| 1599 | } |
| 1600 | |
| 1601 | for (auto &buf : mShaderStorageBuffers) |
| 1602 | { |
| 1603 | if (buf.id() == bufferName) |
| 1604 | { |
Jamie Madill | bf5177d | 2018-08-21 12:58:20 -0400 | [diff] [blame] | 1605 | UpdateIndexedBufferBinding(context, &buf, nullptr, BufferBinding::ShaderStorage, 0, 0); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 1606 | } |
| 1607 | } |
Geoff Lang | 9100226 | 2018-12-12 16:05:24 -0500 | [diff] [blame] | 1608 | |
| 1609 | return angle::Result::Continue; |
Yuly Novikov | 5807a53 | 2015-12-03 13:01:22 -0500 | [diff] [blame] | 1610 | } |
| 1611 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1612 | void State::setEnableVertexAttribArray(unsigned int attribNum, bool enabled) |
| 1613 | { |
| 1614 | getVertexArray()->enableAttribute(attribNum, enabled); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 1615 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | void State::setVertexAttribf(GLuint index, const GLfloat values[4]) |
| 1619 | { |
Shannon Woods | 23e0500 | 2014-09-22 19:07:27 -0400 | [diff] [blame] | 1620 | ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1621 | mVertexAttribCurrentValues[index].setFloatValues(values); |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1622 | mDirtyBits.set(DIRTY_BIT_CURRENT_VALUES); |
| 1623 | mDirtyCurrentValues.set(index); |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 1624 | mCurrentValuesTypeMask.setIndex(GL_FLOAT, index); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1625 | } |
| 1626 | |
| 1627 | void State::setVertexAttribu(GLuint index, const GLuint values[4]) |
| 1628 | { |
Shannon Woods | 23e0500 | 2014-09-22 19:07:27 -0400 | [diff] [blame] | 1629 | ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1630 | mVertexAttribCurrentValues[index].setUnsignedIntValues(values); |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1631 | mDirtyBits.set(DIRTY_BIT_CURRENT_VALUES); |
| 1632 | mDirtyCurrentValues.set(index); |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 1633 | mCurrentValuesTypeMask.setIndex(GL_UNSIGNED_INT, index); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1634 | } |
| 1635 | |
| 1636 | void State::setVertexAttribi(GLuint index, const GLint values[4]) |
| 1637 | { |
Shannon Woods | 23e0500 | 2014-09-22 19:07:27 -0400 | [diff] [blame] | 1638 | ASSERT(static_cast<size_t>(index) < mVertexAttribCurrentValues.size()); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1639 | mVertexAttribCurrentValues[index].setIntValues(values); |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1640 | mDirtyBits.set(DIRTY_BIT_CURRENT_VALUES); |
| 1641 | mDirtyCurrentValues.set(index); |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 1642 | mCurrentValuesTypeMask.setIndex(GL_INT, index); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1643 | } |
| 1644 | |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 1645 | void State::setVertexAttribDivisor(const Context *context, GLuint index, GLuint divisor) |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 1646 | { |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 1647 | getVertexArray()->setVertexAttribDivisor(context, index, divisor); |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 1648 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1649 | } |
| 1650 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1651 | const void *State::getVertexAttribPointer(unsigned int attribNum) const |
| 1652 | { |
| 1653 | return getVertexArray()->getVertexAttribute(attribNum).pointer; |
| 1654 | } |
| 1655 | |
| 1656 | void State::setPackAlignment(GLint alignment) |
| 1657 | { |
| 1658 | mPack.alignment = alignment; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1659 | mDirtyBits.set(DIRTY_BIT_PACK_STATE); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1660 | } |
| 1661 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1662 | void State::setPackReverseRowOrder(bool reverseRowOrder) |
| 1663 | { |
| 1664 | mPack.reverseRowOrder = reverseRowOrder; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1665 | mDirtyBits.set(DIRTY_BIT_PACK_STATE); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1666 | } |
| 1667 | |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1668 | void State::setPackRowLength(GLint rowLength) |
| 1669 | { |
| 1670 | mPack.rowLength = rowLength; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1671 | mDirtyBits.set(DIRTY_BIT_PACK_STATE); |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1672 | } |
| 1673 | |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1674 | void State::setPackSkipRows(GLint skipRows) |
| 1675 | { |
| 1676 | mPack.skipRows = skipRows; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1677 | mDirtyBits.set(DIRTY_BIT_PACK_STATE); |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1678 | } |
| 1679 | |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1680 | void State::setPackSkipPixels(GLint skipPixels) |
| 1681 | { |
| 1682 | mPack.skipPixels = skipPixels; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1683 | mDirtyBits.set(DIRTY_BIT_PACK_STATE); |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1684 | } |
| 1685 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1686 | void State::setUnpackAlignment(GLint alignment) |
| 1687 | { |
| 1688 | mUnpack.alignment = alignment; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1689 | mDirtyBits.set(DIRTY_BIT_UNPACK_STATE); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1690 | } |
| 1691 | |
Minmin Gong | b8aee3b | 2015-01-27 14:42:36 -0800 | [diff] [blame] | 1692 | void State::setUnpackRowLength(GLint rowLength) |
| 1693 | { |
| 1694 | mUnpack.rowLength = rowLength; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1695 | mDirtyBits.set(DIRTY_BIT_UNPACK_STATE); |
Minmin Gong | b8aee3b | 2015-01-27 14:42:36 -0800 | [diff] [blame] | 1696 | } |
| 1697 | |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1698 | void State::setUnpackImageHeight(GLint imageHeight) |
| 1699 | { |
| 1700 | mUnpack.imageHeight = imageHeight; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1701 | mDirtyBits.set(DIRTY_BIT_UNPACK_STATE); |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1702 | } |
| 1703 | |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1704 | void State::setUnpackSkipImages(GLint skipImages) |
| 1705 | { |
| 1706 | mUnpack.skipImages = skipImages; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1707 | mDirtyBits.set(DIRTY_BIT_UNPACK_STATE); |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1708 | } |
| 1709 | |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1710 | void State::setUnpackSkipRows(GLint skipRows) |
| 1711 | { |
| 1712 | mUnpack.skipRows = skipRows; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1713 | mDirtyBits.set(DIRTY_BIT_UNPACK_STATE); |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1714 | } |
| 1715 | |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1716 | void State::setUnpackSkipPixels(GLint skipPixels) |
| 1717 | { |
| 1718 | mUnpack.skipPixels = skipPixels; |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 1719 | mDirtyBits.set(DIRTY_BIT_UNPACK_STATE); |
Minmin Gong | adff67b | 2015-10-14 10:34:45 -0400 | [diff] [blame] | 1720 | } |
| 1721 | |
Sami Väisänen | a797e06 | 2016-05-12 15:23:40 +0300 | [diff] [blame] | 1722 | void State::setCoverageModulation(GLenum components) |
| 1723 | { |
| 1724 | mCoverageModulation = components; |
| 1725 | mDirtyBits.set(DIRTY_BIT_COVERAGE_MODULATION); |
| 1726 | } |
| 1727 | |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1728 | void State::loadPathRenderingMatrix(GLenum matrixMode, const GLfloat *matrix) |
| 1729 | { |
| 1730 | if (matrixMode == GL_PATH_MODELVIEW_CHROMIUM) |
| 1731 | { |
| 1732 | memcpy(mPathMatrixMV, matrix, 16 * sizeof(GLfloat)); |
jchen10 | bb2f2c4 | 2018-09-16 09:47:38 +0800 | [diff] [blame] | 1733 | mDirtyBits.set(DIRTY_BIT_PATH_RENDERING); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1734 | } |
| 1735 | else if (matrixMode == GL_PATH_PROJECTION_CHROMIUM) |
| 1736 | { |
| 1737 | memcpy(mPathMatrixProj, matrix, 16 * sizeof(GLfloat)); |
jchen10 | bb2f2c4 | 2018-09-16 09:47:38 +0800 | [diff] [blame] | 1738 | mDirtyBits.set(DIRTY_BIT_PATH_RENDERING); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1739 | } |
| 1740 | else |
| 1741 | { |
| 1742 | UNREACHABLE(); |
| 1743 | } |
| 1744 | } |
| 1745 | |
| 1746 | const GLfloat *State::getPathRenderingMatrix(GLenum which) const |
| 1747 | { |
| 1748 | if (which == GL_PATH_MODELVIEW_MATRIX_CHROMIUM) |
| 1749 | { |
| 1750 | return mPathMatrixMV; |
| 1751 | } |
| 1752 | else if (which == GL_PATH_PROJECTION_MATRIX_CHROMIUM) |
| 1753 | { |
| 1754 | return mPathMatrixProj; |
| 1755 | } |
| 1756 | |
| 1757 | UNREACHABLE(); |
| 1758 | return nullptr; |
| 1759 | } |
| 1760 | |
| 1761 | void State::setPathStencilFunc(GLenum func, GLint ref, GLuint mask) |
| 1762 | { |
| 1763 | mPathStencilFunc = func; |
| 1764 | mPathStencilRef = ref; |
| 1765 | mPathStencilMask = mask; |
jchen10 | bb2f2c4 | 2018-09-16 09:47:38 +0800 | [diff] [blame] | 1766 | mDirtyBits.set(DIRTY_BIT_PATH_RENDERING); |
Sami Väisänen | e45e53b | 2016-05-25 10:36:04 +0300 | [diff] [blame] | 1767 | } |
| 1768 | |
Geoff Lang | 1d2c41d | 2016-10-19 16:14:46 -0700 | [diff] [blame] | 1769 | void State::setFramebufferSRGB(bool sRGB) |
| 1770 | { |
| 1771 | mFramebufferSRGB = sRGB; |
| 1772 | mDirtyBits.set(DIRTY_BIT_FRAMEBUFFER_SRGB); |
| 1773 | } |
| 1774 | |
jchen10 | 82af620 | 2018-06-22 10:59:52 +0800 | [diff] [blame] | 1775 | void State::setMaxShaderCompilerThreads(GLuint count) |
| 1776 | { |
| 1777 | mMaxShaderCompilerThreads = count; |
| 1778 | } |
| 1779 | |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1780 | void State::getBooleanv(GLenum pname, GLboolean *params) |
| 1781 | { |
| 1782 | switch (pname) |
| 1783 | { |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 1784 | case GL_SAMPLE_COVERAGE_INVERT: |
| 1785 | *params = mSampleCoverageInvert; |
| 1786 | break; |
| 1787 | case GL_DEPTH_WRITEMASK: |
| 1788 | *params = mDepthStencil.depthMask; |
| 1789 | break; |
| 1790 | case GL_COLOR_WRITEMASK: |
| 1791 | params[0] = mBlend.colorMaskRed; |
| 1792 | params[1] = mBlend.colorMaskGreen; |
| 1793 | params[2] = mBlend.colorMaskBlue; |
| 1794 | params[3] = mBlend.colorMaskAlpha; |
| 1795 | break; |
| 1796 | case GL_CULL_FACE: |
| 1797 | *params = mRasterizer.cullFace; |
| 1798 | break; |
| 1799 | case GL_POLYGON_OFFSET_FILL: |
| 1800 | *params = mRasterizer.polygonOffsetFill; |
| 1801 | break; |
| 1802 | case GL_SAMPLE_ALPHA_TO_COVERAGE: |
| 1803 | *params = mBlend.sampleAlphaToCoverage; |
| 1804 | break; |
| 1805 | case GL_SAMPLE_COVERAGE: |
| 1806 | *params = mSampleCoverage; |
| 1807 | break; |
| 1808 | case GL_SAMPLE_MASK: |
| 1809 | *params = mSampleMask; |
| 1810 | break; |
| 1811 | case GL_SCISSOR_TEST: |
| 1812 | *params = mScissorTest; |
| 1813 | break; |
| 1814 | case GL_STENCIL_TEST: |
| 1815 | *params = mDepthStencil.stencilTest; |
| 1816 | break; |
| 1817 | case GL_DEPTH_TEST: |
| 1818 | *params = mDepthStencil.depthTest; |
| 1819 | break; |
| 1820 | case GL_BLEND: |
| 1821 | *params = mBlend.blend; |
| 1822 | break; |
| 1823 | case GL_DITHER: |
| 1824 | *params = mBlend.dither; |
| 1825 | break; |
| 1826 | case GL_TRANSFORM_FEEDBACK_ACTIVE: |
| 1827 | *params = getCurrentTransformFeedback()->isActive() ? GL_TRUE : GL_FALSE; |
| 1828 | break; |
| 1829 | case GL_TRANSFORM_FEEDBACK_PAUSED: |
| 1830 | *params = getCurrentTransformFeedback()->isPaused() ? GL_TRUE : GL_FALSE; |
| 1831 | break; |
| 1832 | case GL_PRIMITIVE_RESTART_FIXED_INDEX: |
| 1833 | *params = mPrimitiveRestart; |
| 1834 | break; |
| 1835 | case GL_RASTERIZER_DISCARD: |
| 1836 | *params = isRasterizerDiscardEnabled() ? GL_TRUE : GL_FALSE; |
| 1837 | break; |
| 1838 | case GL_DEBUG_OUTPUT_SYNCHRONOUS: |
| 1839 | *params = mDebug.isOutputSynchronous() ? GL_TRUE : GL_FALSE; |
| 1840 | break; |
| 1841 | case GL_DEBUG_OUTPUT: |
| 1842 | *params = mDebug.isOutputEnabled() ? GL_TRUE : GL_FALSE; |
| 1843 | break; |
| 1844 | case GL_MULTISAMPLE_EXT: |
| 1845 | *params = mMultiSampling; |
| 1846 | break; |
| 1847 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: |
| 1848 | *params = mSampleAlphaToOne; |
| 1849 | break; |
| 1850 | case GL_BIND_GENERATES_RESOURCE_CHROMIUM: |
| 1851 | *params = isBindGeneratesResourceEnabled() ? GL_TRUE : GL_FALSE; |
| 1852 | break; |
| 1853 | case GL_CLIENT_ARRAYS_ANGLE: |
| 1854 | *params = areClientArraysEnabled() ? GL_TRUE : GL_FALSE; |
| 1855 | break; |
| 1856 | case GL_FRAMEBUFFER_SRGB_EXT: |
| 1857 | *params = getFramebufferSRGB() ? GL_TRUE : GL_FALSE; |
| 1858 | break; |
| 1859 | case GL_ROBUST_RESOURCE_INITIALIZATION_ANGLE: |
| 1860 | *params = mRobustResourceInit ? GL_TRUE : GL_FALSE; |
| 1861 | break; |
| 1862 | case GL_PROGRAM_CACHE_ENABLED_ANGLE: |
| 1863 | *params = mProgramBinaryCacheEnabled ? GL_TRUE : GL_FALSE; |
| 1864 | break; |
Lingfeng Yang | d0febe7 | 2018-05-17 22:36:52 -0700 | [diff] [blame] | 1865 | case GL_LIGHT_MODEL_TWO_SIDE: |
| 1866 | *params = IsLightModelTwoSided(&mGLES1State); |
| 1867 | break; |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 1868 | default: |
| 1869 | UNREACHABLE(); |
| 1870 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1871 | } |
| 1872 | } |
| 1873 | |
| 1874 | void State::getFloatv(GLenum pname, GLfloat *params) |
| 1875 | { |
| 1876 | // Please note: DEPTH_CLEAR_VALUE is included in our internal getFloatv implementation |
| 1877 | // because it is stored as a float, despite the fact that the GL ES 2.0 spec names |
| 1878 | // GetIntegerv as its native query function. As it would require conversion in any |
| 1879 | // case, this should make no difference to the calling application. |
| 1880 | switch (pname) |
| 1881 | { |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 1882 | case GL_LINE_WIDTH: |
| 1883 | *params = mLineWidth; |
| 1884 | break; |
| 1885 | case GL_SAMPLE_COVERAGE_VALUE: |
| 1886 | *params = mSampleCoverageValue; |
| 1887 | break; |
| 1888 | case GL_DEPTH_CLEAR_VALUE: |
| 1889 | *params = mDepthClearValue; |
| 1890 | break; |
| 1891 | case GL_POLYGON_OFFSET_FACTOR: |
| 1892 | *params = mRasterizer.polygonOffsetFactor; |
| 1893 | break; |
| 1894 | case GL_POLYGON_OFFSET_UNITS: |
| 1895 | *params = mRasterizer.polygonOffsetUnits; |
| 1896 | break; |
| 1897 | case GL_DEPTH_RANGE: |
| 1898 | params[0] = mNearZ; |
| 1899 | params[1] = mFarZ; |
| 1900 | break; |
| 1901 | case GL_COLOR_CLEAR_VALUE: |
| 1902 | params[0] = mColorClearValue.red; |
| 1903 | params[1] = mColorClearValue.green; |
| 1904 | params[2] = mColorClearValue.blue; |
| 1905 | params[3] = mColorClearValue.alpha; |
| 1906 | break; |
| 1907 | case GL_BLEND_COLOR: |
| 1908 | params[0] = mBlendColor.red; |
| 1909 | params[1] = mBlendColor.green; |
| 1910 | params[2] = mBlendColor.blue; |
| 1911 | params[3] = mBlendColor.alpha; |
| 1912 | break; |
| 1913 | case GL_MULTISAMPLE_EXT: |
| 1914 | *params = static_cast<GLfloat>(mMultiSampling); |
| 1915 | break; |
| 1916 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: |
| 1917 | *params = static_cast<GLfloat>(mSampleAlphaToOne); |
| 1918 | break; |
| 1919 | case GL_COVERAGE_MODULATION_CHROMIUM: |
| 1920 | params[0] = static_cast<GLfloat>(mCoverageModulation); |
| 1921 | break; |
Lingfeng Yang | 13b708f | 2018-03-21 12:14:10 -0700 | [diff] [blame] | 1922 | case GL_ALPHA_TEST_REF: |
| 1923 | *params = mGLES1State.mAlphaTestRef; |
| 1924 | break; |
Lingfeng Yang | a43994c | 2018-03-29 07:21:41 -0700 | [diff] [blame] | 1925 | case GL_CURRENT_COLOR: |
| 1926 | { |
| 1927 | const auto &color = mGLES1State.mCurrentColor; |
| 1928 | params[0] = color.red; |
| 1929 | params[1] = color.green; |
| 1930 | params[2] = color.blue; |
| 1931 | params[3] = color.alpha; |
| 1932 | break; |
| 1933 | } |
Lingfeng Yang | 5a7e61b | 2018-03-29 16:50:32 -0700 | [diff] [blame] | 1934 | case GL_CURRENT_NORMAL: |
| 1935 | { |
| 1936 | const auto &normal = mGLES1State.mCurrentNormal; |
| 1937 | params[0] = normal[0]; |
| 1938 | params[1] = normal[1]; |
| 1939 | params[2] = normal[2]; |
| 1940 | break; |
| 1941 | } |
Lingfeng Yang | 038dd53 | 2018-03-29 17:31:52 -0700 | [diff] [blame] | 1942 | case GL_CURRENT_TEXTURE_COORDS: |
| 1943 | { |
| 1944 | const auto &texcoord = mGLES1State.mCurrentTextureCoords[mActiveSampler]; |
| 1945 | params[0] = texcoord.s; |
| 1946 | params[1] = texcoord.t; |
| 1947 | params[2] = texcoord.r; |
| 1948 | params[3] = texcoord.q; |
| 1949 | break; |
| 1950 | } |
Lingfeng Yang | 3a41af6 | 2018-04-09 07:28:56 -0700 | [diff] [blame] | 1951 | case GL_MODELVIEW_MATRIX: |
| 1952 | memcpy(params, mGLES1State.mModelviewMatrices.back().data(), 16 * sizeof(GLfloat)); |
| 1953 | break; |
| 1954 | case GL_PROJECTION_MATRIX: |
| 1955 | memcpy(params, mGLES1State.mProjectionMatrices.back().data(), 16 * sizeof(GLfloat)); |
| 1956 | break; |
| 1957 | case GL_TEXTURE_MATRIX: |
| 1958 | memcpy(params, mGLES1State.mTextureMatrices[mActiveSampler].back().data(), |
| 1959 | 16 * sizeof(GLfloat)); |
| 1960 | break; |
Lingfeng Yang | d0febe7 | 2018-05-17 22:36:52 -0700 | [diff] [blame] | 1961 | case GL_LIGHT_MODEL_AMBIENT: |
| 1962 | GetLightModelParameters(&mGLES1State, pname, params); |
| 1963 | break; |
Lingfeng Yang | 7ba3f42 | 2018-06-01 09:43:04 -0700 | [diff] [blame] | 1964 | case GL_FOG_MODE: |
| 1965 | case GL_FOG_DENSITY: |
| 1966 | case GL_FOG_START: |
| 1967 | case GL_FOG_END: |
| 1968 | case GL_FOG_COLOR: |
| 1969 | GetFogParameters(&mGLES1State, pname, params); |
| 1970 | break; |
Lingfeng Yang | 9c4c092 | 2018-06-13 09:29:00 -0700 | [diff] [blame] | 1971 | case GL_POINT_SIZE: |
| 1972 | GetPointSize(&mGLES1State, params); |
| 1973 | break; |
| 1974 | case GL_POINT_SIZE_MIN: |
| 1975 | case GL_POINT_SIZE_MAX: |
| 1976 | case GL_POINT_FADE_THRESHOLD_SIZE: |
| 1977 | case GL_POINT_DISTANCE_ATTENUATION: |
| 1978 | GetPointParameter(&mGLES1State, FromGLenum<PointParameter>(pname), params); |
| 1979 | break; |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 1980 | default: |
| 1981 | UNREACHABLE(); |
| 1982 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1983 | } |
| 1984 | } |
| 1985 | |
Jamie Madill | 526392d | 2018-11-16 09:35:14 -0500 | [diff] [blame] | 1986 | angle::Result State::getIntegerv(const Context *context, GLenum pname, GLint *params) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1987 | { |
| 1988 | if (pname >= GL_DRAW_BUFFER0_EXT && pname <= GL_DRAW_BUFFER15_EXT) |
| 1989 | { |
Geoff Lang | 3e92206 | 2018-11-15 11:26:29 -0500 | [diff] [blame] | 1990 | size_t drawBuffer = (pname - GL_DRAW_BUFFER0_EXT); |
| 1991 | ASSERT(drawBuffer < mMaxDrawBuffers); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 1992 | Framebuffer *framebuffer = mDrawFramebuffer; |
Geoff Lang | 3e92206 | 2018-11-15 11:26:29 -0500 | [diff] [blame] | 1993 | // The default framebuffer may have fewer draw buffer states than a user-created one. The |
| 1994 | // user is always allowed to query up to GL_MAX_DRAWBUFFERS so just return GL_NONE here if |
| 1995 | // the draw buffer is out of range for this framebuffer. |
| 1996 | *params = drawBuffer < framebuffer->getDrawbufferStateCount() |
| 1997 | ? framebuffer->getDrawBufferState(drawBuffer) |
| 1998 | : GL_NONE; |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 1999 | return angle::Result::Continue; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2000 | } |
| 2001 | |
| 2002 | // Please note: DEPTH_CLEAR_VALUE is not included in our internal getIntegerv implementation |
| 2003 | // because it is stored as a float, despite the fact that the GL ES 2.0 spec names |
| 2004 | // GetIntegerv as its native query function. As it would require conversion in any |
| 2005 | // case, this should make no difference to the calling application. You may find it in |
| 2006 | // State::getFloatv. |
| 2007 | switch (pname) |
| 2008 | { |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2009 | case GL_ARRAY_BUFFER_BINDING: |
| 2010 | *params = mBoundBuffers[BufferBinding::Array].id(); |
| 2011 | break; |
| 2012 | case GL_DRAW_INDIRECT_BUFFER_BINDING: |
| 2013 | *params = mBoundBuffers[BufferBinding::DrawIndirect].id(); |
| 2014 | break; |
| 2015 | case GL_ELEMENT_ARRAY_BUFFER_BINDING: |
Jamie Madill | cd0a0a3 | 2018-10-18 18:41:57 -0400 | [diff] [blame] | 2016 | { |
| 2017 | Buffer *elementArrayBuffer = getVertexArray()->getElementArrayBuffer(); |
| 2018 | *params = elementArrayBuffer ? elementArrayBuffer->id() : 0; |
Corentin Wallez | 336129f | 2017-10-17 15:55:40 -0400 | [diff] [blame] | 2019 | break; |
Jamie Madill | cd0a0a3 | 2018-10-18 18:41:57 -0400 | [diff] [blame] | 2020 | } |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 2021 | case GL_DRAW_FRAMEBUFFER_BINDING: |
| 2022 | static_assert(GL_DRAW_FRAMEBUFFER_BINDING == GL_DRAW_FRAMEBUFFER_BINDING_ANGLE, |
| 2023 | "Enum mismatch"); |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 2024 | *params = mDrawFramebuffer->id(); |
| 2025 | break; |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 2026 | case GL_READ_FRAMEBUFFER_BINDING: |
| 2027 | static_assert(GL_READ_FRAMEBUFFER_BINDING == GL_READ_FRAMEBUFFER_BINDING_ANGLE, |
| 2028 | "Enum mismatch"); |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 2029 | *params = mReadFramebuffer->id(); |
| 2030 | break; |
| 2031 | case GL_RENDERBUFFER_BINDING: |
| 2032 | *params = mRenderbuffer.id(); |
| 2033 | break; |
| 2034 | case GL_VERTEX_ARRAY_BINDING: |
| 2035 | *params = mVertexArray->id(); |
| 2036 | break; |
| 2037 | case GL_CURRENT_PROGRAM: |
| 2038 | *params = mProgram ? mProgram->id() : 0; |
| 2039 | break; |
| 2040 | case GL_PACK_ALIGNMENT: |
| 2041 | *params = mPack.alignment; |
| 2042 | break; |
| 2043 | case GL_PACK_REVERSE_ROW_ORDER_ANGLE: |
| 2044 | *params = mPack.reverseRowOrder; |
| 2045 | break; |
| 2046 | case GL_PACK_ROW_LENGTH: |
| 2047 | *params = mPack.rowLength; |
| 2048 | break; |
| 2049 | case GL_PACK_SKIP_ROWS: |
| 2050 | *params = mPack.skipRows; |
| 2051 | break; |
| 2052 | case GL_PACK_SKIP_PIXELS: |
| 2053 | *params = mPack.skipPixels; |
| 2054 | break; |
| 2055 | case GL_UNPACK_ALIGNMENT: |
| 2056 | *params = mUnpack.alignment; |
| 2057 | break; |
| 2058 | case GL_UNPACK_ROW_LENGTH: |
| 2059 | *params = mUnpack.rowLength; |
| 2060 | break; |
| 2061 | case GL_UNPACK_IMAGE_HEIGHT: |
| 2062 | *params = mUnpack.imageHeight; |
| 2063 | break; |
| 2064 | case GL_UNPACK_SKIP_IMAGES: |
| 2065 | *params = mUnpack.skipImages; |
| 2066 | break; |
| 2067 | case GL_UNPACK_SKIP_ROWS: |
| 2068 | *params = mUnpack.skipRows; |
| 2069 | break; |
| 2070 | case GL_UNPACK_SKIP_PIXELS: |
| 2071 | *params = mUnpack.skipPixels; |
| 2072 | break; |
| 2073 | case GL_GENERATE_MIPMAP_HINT: |
| 2074 | *params = mGenerateMipmapHint; |
| 2075 | break; |
| 2076 | case GL_FRAGMENT_SHADER_DERIVATIVE_HINT_OES: |
| 2077 | *params = mFragmentShaderDerivativeHint; |
| 2078 | break; |
| 2079 | case GL_ACTIVE_TEXTURE: |
| 2080 | *params = (static_cast<GLint>(mActiveSampler) + GL_TEXTURE0); |
| 2081 | break; |
| 2082 | case GL_STENCIL_FUNC: |
| 2083 | *params = mDepthStencil.stencilFunc; |
| 2084 | break; |
| 2085 | case GL_STENCIL_REF: |
| 2086 | *params = mStencilRef; |
| 2087 | break; |
| 2088 | case GL_STENCIL_VALUE_MASK: |
| 2089 | *params = CastMaskValue(context, mDepthStencil.stencilMask); |
| 2090 | break; |
| 2091 | case GL_STENCIL_BACK_FUNC: |
| 2092 | *params = mDepthStencil.stencilBackFunc; |
| 2093 | break; |
| 2094 | case GL_STENCIL_BACK_REF: |
| 2095 | *params = mStencilBackRef; |
| 2096 | break; |
| 2097 | case GL_STENCIL_BACK_VALUE_MASK: |
| 2098 | *params = CastMaskValue(context, mDepthStencil.stencilBackMask); |
| 2099 | break; |
| 2100 | case GL_STENCIL_FAIL: |
| 2101 | *params = mDepthStencil.stencilFail; |
| 2102 | break; |
| 2103 | case GL_STENCIL_PASS_DEPTH_FAIL: |
| 2104 | *params = mDepthStencil.stencilPassDepthFail; |
| 2105 | break; |
| 2106 | case GL_STENCIL_PASS_DEPTH_PASS: |
| 2107 | *params = mDepthStencil.stencilPassDepthPass; |
| 2108 | break; |
| 2109 | case GL_STENCIL_BACK_FAIL: |
| 2110 | *params = mDepthStencil.stencilBackFail; |
| 2111 | break; |
| 2112 | case GL_STENCIL_BACK_PASS_DEPTH_FAIL: |
| 2113 | *params = mDepthStencil.stencilBackPassDepthFail; |
| 2114 | break; |
| 2115 | case GL_STENCIL_BACK_PASS_DEPTH_PASS: |
| 2116 | *params = mDepthStencil.stencilBackPassDepthPass; |
| 2117 | break; |
| 2118 | case GL_DEPTH_FUNC: |
| 2119 | *params = mDepthStencil.depthFunc; |
| 2120 | break; |
| 2121 | case GL_BLEND_SRC_RGB: |
| 2122 | *params = mBlend.sourceBlendRGB; |
| 2123 | break; |
| 2124 | case GL_BLEND_SRC_ALPHA: |
| 2125 | *params = mBlend.sourceBlendAlpha; |
| 2126 | break; |
| 2127 | case GL_BLEND_DST_RGB: |
| 2128 | *params = mBlend.destBlendRGB; |
| 2129 | break; |
| 2130 | case GL_BLEND_DST_ALPHA: |
| 2131 | *params = mBlend.destBlendAlpha; |
| 2132 | break; |
| 2133 | case GL_BLEND_EQUATION_RGB: |
| 2134 | *params = mBlend.blendEquationRGB; |
| 2135 | break; |
| 2136 | case GL_BLEND_EQUATION_ALPHA: |
| 2137 | *params = mBlend.blendEquationAlpha; |
| 2138 | break; |
| 2139 | case GL_STENCIL_WRITEMASK: |
| 2140 | *params = CastMaskValue(context, mDepthStencil.stencilWritemask); |
| 2141 | break; |
| 2142 | case GL_STENCIL_BACK_WRITEMASK: |
| 2143 | *params = CastMaskValue(context, mDepthStencil.stencilBackWritemask); |
| 2144 | break; |
| 2145 | case GL_STENCIL_CLEAR_VALUE: |
| 2146 | *params = mStencilClearValue; |
| 2147 | break; |
| 2148 | case GL_IMPLEMENTATION_COLOR_READ_TYPE: |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 2149 | ANGLE_TRY(mReadFramebuffer->getImplementationColorReadType( |
| 2150 | context, reinterpret_cast<GLenum *>(params))); |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 2151 | break; |
| 2152 | case GL_IMPLEMENTATION_COLOR_READ_FORMAT: |
Jamie Madill | 690c8eb | 2018-03-12 15:20:03 -0400 | [diff] [blame] | 2153 | ANGLE_TRY(mReadFramebuffer->getImplementationColorReadFormat( |
| 2154 | context, reinterpret_cast<GLenum *>(params))); |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 2155 | break; |
| 2156 | case GL_SAMPLE_BUFFERS: |
| 2157 | case GL_SAMPLES: |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2158 | { |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2159 | Framebuffer *framebuffer = mDrawFramebuffer; |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2160 | if (framebuffer->isComplete(context)) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2161 | { |
Jamie Madill | 427064d | 2018-04-13 16:20:34 -0400 | [diff] [blame] | 2162 | GLint samples = framebuffer->getSamples(context); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2163 | switch (pname) |
| 2164 | { |
Jamie Madill | a0016b7 | 2017-07-14 14:30:46 -0400 | [diff] [blame] | 2165 | case GL_SAMPLE_BUFFERS: |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2166 | if (samples != 0) |
Jamie Madill | a0016b7 | 2017-07-14 14:30:46 -0400 | [diff] [blame] | 2167 | { |
| 2168 | *params = 1; |
| 2169 | } |
| 2170 | else |
| 2171 | { |
| 2172 | *params = 0; |
| 2173 | } |
| 2174 | break; |
| 2175 | case GL_SAMPLES: |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2176 | *params = samples; |
Jamie Madill | a0016b7 | 2017-07-14 14:30:46 -0400 | [diff] [blame] | 2177 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2178 | } |
| 2179 | } |
| 2180 | else |
| 2181 | { |
| 2182 | *params = 0; |
| 2183 | } |
| 2184 | } |
| 2185 | break; |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 2186 | case GL_VIEWPORT: |
| 2187 | params[0] = mViewport.x; |
| 2188 | params[1] = mViewport.y; |
| 2189 | params[2] = mViewport.width; |
| 2190 | params[3] = mViewport.height; |
| 2191 | break; |
| 2192 | case GL_SCISSOR_BOX: |
| 2193 | params[0] = mScissor.x; |
| 2194 | params[1] = mScissor.y; |
| 2195 | params[2] = mScissor.width; |
| 2196 | params[3] = mScissor.height; |
| 2197 | break; |
| 2198 | case GL_CULL_FACE_MODE: |
| 2199 | *params = ToGLenum(mRasterizer.cullMode); |
| 2200 | break; |
| 2201 | case GL_FRONT_FACE: |
| 2202 | *params = mRasterizer.frontFace; |
| 2203 | break; |
| 2204 | case GL_RED_BITS: |
| 2205 | case GL_GREEN_BITS: |
| 2206 | case GL_BLUE_BITS: |
| 2207 | case GL_ALPHA_BITS: |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2208 | { |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2209 | Framebuffer *framebuffer = getDrawFramebuffer(); |
| 2210 | const FramebufferAttachment *colorbuffer = framebuffer->getFirstColorbuffer(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2211 | |
| 2212 | if (colorbuffer) |
| 2213 | { |
| 2214 | switch (pname) |
| 2215 | { |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 2216 | case GL_RED_BITS: |
| 2217 | *params = colorbuffer->getRedSize(); |
| 2218 | break; |
| 2219 | case GL_GREEN_BITS: |
| 2220 | *params = colorbuffer->getGreenSize(); |
| 2221 | break; |
| 2222 | case GL_BLUE_BITS: |
| 2223 | *params = colorbuffer->getBlueSize(); |
| 2224 | break; |
| 2225 | case GL_ALPHA_BITS: |
| 2226 | *params = colorbuffer->getAlphaSize(); |
| 2227 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2228 | } |
| 2229 | } |
| 2230 | else |
| 2231 | { |
| 2232 | *params = 0; |
| 2233 | } |
| 2234 | } |
| 2235 | break; |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 2236 | case GL_DEPTH_BITS: |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2237 | { |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2238 | const Framebuffer *framebuffer = getDrawFramebuffer(); |
| 2239 | const FramebufferAttachment *depthbuffer = framebuffer->getDepthbuffer(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2240 | |
| 2241 | if (depthbuffer) |
| 2242 | { |
| 2243 | *params = depthbuffer->getDepthSize(); |
| 2244 | } |
| 2245 | else |
| 2246 | { |
| 2247 | *params = 0; |
| 2248 | } |
| 2249 | } |
| 2250 | break; |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 2251 | case GL_STENCIL_BITS: |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2252 | { |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2253 | const Framebuffer *framebuffer = getDrawFramebuffer(); |
| 2254 | const FramebufferAttachment *stencilbuffer = framebuffer->getStencilbuffer(); |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2255 | |
| 2256 | if (stencilbuffer) |
| 2257 | { |
| 2258 | *params = stencilbuffer->getStencilSize(); |
| 2259 | } |
| 2260 | else |
| 2261 | { |
| 2262 | *params = 0; |
| 2263 | } |
| 2264 | } |
| 2265 | break; |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 2266 | case GL_TEXTURE_BINDING_2D: |
| 2267 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
| 2268 | *params = |
| 2269 | getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), TextureType::_2D); |
| 2270 | break; |
| 2271 | case GL_TEXTURE_BINDING_RECTANGLE_ANGLE: |
| 2272 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
| 2273 | *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), |
| 2274 | TextureType::Rectangle); |
| 2275 | break; |
| 2276 | case GL_TEXTURE_BINDING_CUBE_MAP: |
| 2277 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
| 2278 | *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), |
| 2279 | TextureType::CubeMap); |
| 2280 | break; |
| 2281 | case GL_TEXTURE_BINDING_3D: |
| 2282 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
| 2283 | *params = |
| 2284 | getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), TextureType::_3D); |
| 2285 | break; |
| 2286 | case GL_TEXTURE_BINDING_2D_ARRAY: |
| 2287 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
| 2288 | *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), |
| 2289 | TextureType::_2DArray); |
| 2290 | break; |
| 2291 | case GL_TEXTURE_BINDING_2D_MULTISAMPLE: |
| 2292 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
| 2293 | *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), |
| 2294 | TextureType::_2DMultisample); |
| 2295 | break; |
Olli Etuaho | dff32a0 | 2018-08-28 14:35:50 +0300 | [diff] [blame] | 2296 | case GL_TEXTURE_BINDING_2D_MULTISAMPLE_ARRAY: |
| 2297 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
| 2298 | *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), |
| 2299 | TextureType::_2DMultisampleArray); |
| 2300 | break; |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 2301 | case GL_TEXTURE_BINDING_EXTERNAL_OES: |
| 2302 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
| 2303 | *params = getSamplerTextureId(static_cast<unsigned int>(mActiveSampler), |
| 2304 | TextureType::External); |
| 2305 | break; |
| 2306 | case GL_UNIFORM_BUFFER_BINDING: |
| 2307 | *params = mBoundBuffers[BufferBinding::Uniform].id(); |
| 2308 | break; |
| 2309 | case GL_TRANSFORM_FEEDBACK_BINDING: |
| 2310 | *params = mTransformFeedback.id(); |
| 2311 | break; |
| 2312 | case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: |
| 2313 | *params = mBoundBuffers[BufferBinding::TransformFeedback].id(); |
| 2314 | break; |
| 2315 | case GL_COPY_READ_BUFFER_BINDING: |
| 2316 | *params = mBoundBuffers[BufferBinding::CopyRead].id(); |
| 2317 | break; |
| 2318 | case GL_COPY_WRITE_BUFFER_BINDING: |
| 2319 | *params = mBoundBuffers[BufferBinding::CopyWrite].id(); |
| 2320 | break; |
| 2321 | case GL_PIXEL_PACK_BUFFER_BINDING: |
| 2322 | *params = mBoundBuffers[BufferBinding::PixelPack].id(); |
| 2323 | break; |
| 2324 | case GL_PIXEL_UNPACK_BUFFER_BINDING: |
| 2325 | *params = mBoundBuffers[BufferBinding::PixelUnpack].id(); |
| 2326 | break; |
| 2327 | case GL_READ_BUFFER: |
| 2328 | *params = mReadFramebuffer->getReadBufferState(); |
| 2329 | break; |
| 2330 | case GL_SAMPLER_BINDING: |
| 2331 | ASSERT(mActiveSampler < mMaxCombinedTextureImageUnits); |
| 2332 | *params = getSamplerId(static_cast<GLuint>(mActiveSampler)); |
| 2333 | break; |
| 2334 | case GL_DEBUG_LOGGED_MESSAGES: |
| 2335 | *params = static_cast<GLint>(mDebug.getMessageCount()); |
| 2336 | break; |
| 2337 | case GL_DEBUG_NEXT_LOGGED_MESSAGE_LENGTH: |
| 2338 | *params = static_cast<GLint>(mDebug.getNextMessageLength()); |
| 2339 | break; |
| 2340 | case GL_DEBUG_GROUP_STACK_DEPTH: |
| 2341 | *params = static_cast<GLint>(mDebug.getGroupStackDepth()); |
| 2342 | break; |
| 2343 | case GL_MULTISAMPLE_EXT: |
| 2344 | *params = static_cast<GLint>(mMultiSampling); |
| 2345 | break; |
| 2346 | case GL_SAMPLE_ALPHA_TO_ONE_EXT: |
| 2347 | *params = static_cast<GLint>(mSampleAlphaToOne); |
| 2348 | break; |
| 2349 | case GL_COVERAGE_MODULATION_CHROMIUM: |
| 2350 | *params = static_cast<GLint>(mCoverageModulation); |
| 2351 | break; |
| 2352 | case GL_ATOMIC_COUNTER_BUFFER_BINDING: |
| 2353 | *params = mBoundBuffers[BufferBinding::AtomicCounter].id(); |
| 2354 | break; |
| 2355 | case GL_SHADER_STORAGE_BUFFER_BINDING: |
| 2356 | *params = mBoundBuffers[BufferBinding::ShaderStorage].id(); |
| 2357 | break; |
| 2358 | case GL_DISPATCH_INDIRECT_BUFFER_BINDING: |
| 2359 | *params = mBoundBuffers[BufferBinding::DispatchIndirect].id(); |
| 2360 | break; |
Lingfeng Yang | 13b708f | 2018-03-21 12:14:10 -0700 | [diff] [blame] | 2361 | case GL_ALPHA_TEST_FUNC: |
| 2362 | *params = ToGLenum(mGLES1State.mAlphaTestFunc); |
| 2363 | break; |
Lingfeng Yang | 96310cd | 2018-03-28 11:56:28 -0700 | [diff] [blame] | 2364 | case GL_CLIENT_ACTIVE_TEXTURE: |
| 2365 | *params = mGLES1State.mClientActiveTexture + GL_TEXTURE0; |
| 2366 | break; |
Lingfeng Yang | d2488ab | 2018-04-04 09:25:48 -0700 | [diff] [blame] | 2367 | case GL_MATRIX_MODE: |
| 2368 | *params = ToGLenum(mGLES1State.mMatrixMode); |
| 2369 | break; |
Lingfeng Yang | a0cfa87 | 2018-05-30 21:12:17 -0700 | [diff] [blame] | 2370 | case GL_SHADE_MODEL: |
| 2371 | *params = ToGLenum(mGLES1State.mShadeModel); |
| 2372 | break; |
Lingfeng Yang | 6e5bf36 | 2018-08-15 09:53:17 -0700 | [diff] [blame] | 2373 | case GL_MODELVIEW_STACK_DEPTH: |
| 2374 | case GL_PROJECTION_STACK_DEPTH: |
| 2375 | case GL_TEXTURE_STACK_DEPTH: |
| 2376 | *params = mGLES1State.getCurrentMatrixStackDepth(pname); |
| 2377 | break; |
| 2378 | case GL_LOGIC_OP_MODE: |
| 2379 | *params = ToGLenum(mGLES1State.mLogicOp); |
| 2380 | break; |
| 2381 | case GL_BLEND_SRC: |
| 2382 | *params = mBlend.sourceBlendRGB; |
| 2383 | break; |
| 2384 | case GL_BLEND_DST: |
| 2385 | *params = mBlend.destBlendRGB; |
| 2386 | break; |
| 2387 | case GL_PERSPECTIVE_CORRECTION_HINT: |
| 2388 | case GL_POINT_SMOOTH_HINT: |
| 2389 | case GL_LINE_SMOOTH_HINT: |
| 2390 | case GL_FOG_HINT: |
| 2391 | *params = mGLES1State.getHint(pname); |
| 2392 | break; |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 2393 | default: |
| 2394 | UNREACHABLE(); |
| 2395 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2396 | } |
Jamie Madill | e98b1b5 | 2018-03-08 09:47:23 -0500 | [diff] [blame] | 2397 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2398 | return angle::Result::Continue; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2399 | } |
| 2400 | |
Lingfeng Yang | abb09f1 | 2018-04-16 10:43:53 -0700 | [diff] [blame] | 2401 | void State::getPointerv(const Context *context, GLenum pname, void **params) const |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2402 | { |
| 2403 | switch (pname) |
| 2404 | { |
| 2405 | case GL_DEBUG_CALLBACK_FUNCTION: |
| 2406 | *params = reinterpret_cast<void *>(mDebug.getCallback()); |
| 2407 | break; |
| 2408 | case GL_DEBUG_CALLBACK_USER_PARAM: |
| 2409 | *params = const_cast<void *>(mDebug.getUserParam()); |
| 2410 | break; |
Lingfeng Yang | abb09f1 | 2018-04-16 10:43:53 -0700 | [diff] [blame] | 2411 | case GL_VERTEX_ARRAY_POINTER: |
| 2412 | case GL_NORMAL_ARRAY_POINTER: |
| 2413 | case GL_COLOR_ARRAY_POINTER: |
| 2414 | case GL_TEXTURE_COORD_ARRAY_POINTER: |
| 2415 | case GL_POINT_SIZE_ARRAY_POINTER_OES: |
| 2416 | QueryVertexAttribPointerv(getVertexArray()->getVertexAttribute( |
| 2417 | context->vertexArrayIndex(ParamToVertexArrayType(pname))), |
| 2418 | GL_VERTEX_ATTRIB_ARRAY_POINTER, params); |
| 2419 | return; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 2420 | default: |
| 2421 | UNREACHABLE(); |
| 2422 | break; |
| 2423 | } |
| 2424 | } |
| 2425 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2426 | void State::getIntegeri_v(GLenum target, GLuint index, GLint *data) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2427 | { |
| 2428 | switch (target) |
| 2429 | { |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 2430 | case GL_TRANSFORM_FEEDBACK_BUFFER_BINDING: |
| 2431 | ASSERT(static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount()); |
| 2432 | *data = mTransformFeedback->getIndexedBuffer(index).id(); |
| 2433 | break; |
| 2434 | case GL_UNIFORM_BUFFER_BINDING: |
| 2435 | ASSERT(static_cast<size_t>(index) < mUniformBuffers.size()); |
| 2436 | *data = mUniformBuffers[index].id(); |
| 2437 | break; |
| 2438 | case GL_ATOMIC_COUNTER_BUFFER_BINDING: |
| 2439 | ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size()); |
| 2440 | *data = mAtomicCounterBuffers[index].id(); |
| 2441 | break; |
| 2442 | case GL_SHADER_STORAGE_BUFFER_BINDING: |
| 2443 | ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size()); |
| 2444 | *data = mShaderStorageBuffers[index].id(); |
| 2445 | break; |
| 2446 | case GL_VERTEX_BINDING_BUFFER: |
| 2447 | ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings()); |
| 2448 | *data = mVertexArray->getVertexBinding(index).getBuffer().id(); |
| 2449 | break; |
| 2450 | case GL_VERTEX_BINDING_DIVISOR: |
| 2451 | ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings()); |
| 2452 | *data = mVertexArray->getVertexBinding(index).getDivisor(); |
| 2453 | break; |
| 2454 | case GL_VERTEX_BINDING_OFFSET: |
| 2455 | ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings()); |
| 2456 | *data = static_cast<GLuint>(mVertexArray->getVertexBinding(index).getOffset()); |
| 2457 | break; |
| 2458 | case GL_VERTEX_BINDING_STRIDE: |
| 2459 | ASSERT(static_cast<size_t>(index) < mVertexArray->getMaxBindings()); |
| 2460 | *data = mVertexArray->getVertexBinding(index).getStride(); |
| 2461 | break; |
| 2462 | case GL_SAMPLE_MASK_VALUE: |
| 2463 | ASSERT(static_cast<size_t>(index) < mSampleMaskValues.size()); |
| 2464 | *data = mSampleMaskValues[index]; |
| 2465 | break; |
| 2466 | case GL_IMAGE_BINDING_NAME: |
| 2467 | ASSERT(static_cast<size_t>(index) < mImageUnits.size()); |
| 2468 | *data = mImageUnits[index].texture.id(); |
| 2469 | break; |
| 2470 | case GL_IMAGE_BINDING_LEVEL: |
| 2471 | ASSERT(static_cast<size_t>(index) < mImageUnits.size()); |
| 2472 | *data = mImageUnits[index].level; |
| 2473 | break; |
| 2474 | case GL_IMAGE_BINDING_LAYER: |
| 2475 | ASSERT(static_cast<size_t>(index) < mImageUnits.size()); |
| 2476 | *data = mImageUnits[index].layer; |
| 2477 | break; |
| 2478 | case GL_IMAGE_BINDING_ACCESS: |
| 2479 | ASSERT(static_cast<size_t>(index) < mImageUnits.size()); |
| 2480 | *data = mImageUnits[index].access; |
| 2481 | break; |
| 2482 | case GL_IMAGE_BINDING_FORMAT: |
| 2483 | ASSERT(static_cast<size_t>(index) < mImageUnits.size()); |
| 2484 | *data = mImageUnits[index].format; |
| 2485 | break; |
| 2486 | default: |
| 2487 | UNREACHABLE(); |
| 2488 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2489 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2490 | } |
| 2491 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2492 | void State::getInteger64i_v(GLenum target, GLuint index, GLint64 *data) |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2493 | { |
| 2494 | switch (target) |
| 2495 | { |
Lingfeng Yang | 54ef3ad | 2018-03-12 08:31:12 -0700 | [diff] [blame] | 2496 | case GL_TRANSFORM_FEEDBACK_BUFFER_START: |
| 2497 | ASSERT(static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount()); |
| 2498 | *data = mTransformFeedback->getIndexedBuffer(index).getOffset(); |
| 2499 | break; |
| 2500 | case GL_TRANSFORM_FEEDBACK_BUFFER_SIZE: |
| 2501 | ASSERT(static_cast<size_t>(index) < mTransformFeedback->getIndexedBufferCount()); |
| 2502 | *data = mTransformFeedback->getIndexedBuffer(index).getSize(); |
| 2503 | break; |
| 2504 | case GL_UNIFORM_BUFFER_START: |
| 2505 | ASSERT(static_cast<size_t>(index) < mUniformBuffers.size()); |
| 2506 | *data = mUniformBuffers[index].getOffset(); |
| 2507 | break; |
| 2508 | case GL_UNIFORM_BUFFER_SIZE: |
| 2509 | ASSERT(static_cast<size_t>(index) < mUniformBuffers.size()); |
| 2510 | *data = mUniformBuffers[index].getSize(); |
| 2511 | break; |
| 2512 | case GL_ATOMIC_COUNTER_BUFFER_START: |
| 2513 | ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size()); |
| 2514 | *data = mAtomicCounterBuffers[index].getOffset(); |
| 2515 | break; |
| 2516 | case GL_ATOMIC_COUNTER_BUFFER_SIZE: |
| 2517 | ASSERT(static_cast<size_t>(index) < mAtomicCounterBuffers.size()); |
| 2518 | *data = mAtomicCounterBuffers[index].getSize(); |
| 2519 | break; |
| 2520 | case GL_SHADER_STORAGE_BUFFER_START: |
| 2521 | ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size()); |
| 2522 | *data = mShaderStorageBuffers[index].getOffset(); |
| 2523 | break; |
| 2524 | case GL_SHADER_STORAGE_BUFFER_SIZE: |
| 2525 | ASSERT(static_cast<size_t>(index) < mShaderStorageBuffers.size()); |
| 2526 | *data = mShaderStorageBuffers[index].getSize(); |
| 2527 | break; |
| 2528 | default: |
| 2529 | UNREACHABLE(); |
| 2530 | break; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2531 | } |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2532 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2533 | |
Martin Radev | 66fb820 | 2016-07-28 11:45:20 +0300 | [diff] [blame] | 2534 | void State::getBooleani_v(GLenum target, GLuint index, GLboolean *data) |
| 2535 | { |
Xinghua Cao | 9c8e1a3 | 2017-12-06 17:59:58 +0800 | [diff] [blame] | 2536 | switch (target) |
| 2537 | { |
| 2538 | case GL_IMAGE_BINDING_LAYERED: |
| 2539 | ASSERT(static_cast<size_t>(index) < mImageUnits.size()); |
| 2540 | *data = mImageUnits[index].layered; |
| 2541 | break; |
| 2542 | default: |
| 2543 | UNREACHABLE(); |
| 2544 | break; |
| 2545 | } |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2546 | } |
| 2547 | |
Markus Tavenrath | f7f8c51 | 2018-11-18 15:56:45 +0100 | [diff] [blame] | 2548 | angle::Result State::syncReadFramebuffer(const Context *context) |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2549 | { |
Markus Tavenrath | f7f8c51 | 2018-11-18 15:56:45 +0100 | [diff] [blame] | 2550 | ASSERT(mReadFramebuffer); |
| 2551 | return mReadFramebuffer->syncState(context); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2552 | } |
| 2553 | |
Jamie Madill | ef9fcd9 | 2018-11-28 14:03:59 -0500 | [diff] [blame] | 2554 | angle::Result State::syncDrawFramebuffer(const Context *context) |
Markus Tavenrath | f7f8c51 | 2018-11-18 15:56:45 +0100 | [diff] [blame] | 2555 | { |
| 2556 | ASSERT(mDrawFramebuffer); |
| 2557 | return mDrawFramebuffer->syncState(context); |
| 2558 | } |
| 2559 | |
Jamie Madill | ef9fcd9 | 2018-11-28 14:03:59 -0500 | [diff] [blame] | 2560 | angle::Result State::syncDrawAttachments(const Context *context) |
| 2561 | { |
| 2562 | ASSERT(mDrawFramebuffer); |
| 2563 | ASSERT(!mDrawFramebuffer->hasAnyDirtyBit()); |
| 2564 | ASSERT(mRobustResourceInit); |
| 2565 | return mDrawFramebuffer->ensureDrawAttachmentsInitialized(context); |
| 2566 | } |
| 2567 | |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 2568 | angle::Result State::syncTextures(const Context *context) |
Markus Tavenrath | f7f8c51 | 2018-11-18 15:56:45 +0100 | [diff] [blame] | 2569 | { |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 2570 | if (mDirtyTextures.none()) |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2571 | return angle::Result::Continue; |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 2572 | |
| 2573 | for (size_t textureIndex : mDirtyTextures) |
| 2574 | { |
| 2575 | Texture *texture = mActiveTexturesCache[textureIndex]; |
| 2576 | if (texture && texture->hasAnyDirtyBit()) |
| 2577 | { |
| 2578 | ANGLE_TRY(texture->syncState(context)); |
| 2579 | } |
| 2580 | } |
| 2581 | |
| 2582 | mDirtyTextures.reset(); |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2583 | return angle::Result::Continue; |
Markus Tavenrath | f7f8c51 | 2018-11-18 15:56:45 +0100 | [diff] [blame] | 2584 | } |
| 2585 | |
Markus Tavenrath | f7f8c51 | 2018-11-18 15:56:45 +0100 | [diff] [blame] | 2586 | angle::Result State::syncSamplers(const Context *context) |
Jamie Madill | e25b800 | 2018-09-20 13:39:49 -0400 | [diff] [blame] | 2587 | { |
| 2588 | if (mDirtySamplers.none()) |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2589 | return angle::Result::Continue; |
Jamie Madill | e25b800 | 2018-09-20 13:39:49 -0400 | [diff] [blame] | 2590 | |
Jamie Madill | e25b800 | 2018-09-20 13:39:49 -0400 | [diff] [blame] | 2591 | for (size_t samplerIndex : mDirtySamplers) |
| 2592 | { |
| 2593 | BindingPointer<Sampler> &sampler = mSamplers[samplerIndex]; |
| 2594 | if (sampler.get()) |
| 2595 | { |
| 2596 | sampler->syncState(context); |
| 2597 | } |
| 2598 | } |
| 2599 | |
| 2600 | mDirtySamplers.reset(); |
Markus Tavenrath | f7f8c51 | 2018-11-18 15:56:45 +0100 | [diff] [blame] | 2601 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2602 | return angle::Result::Continue; |
Jamie Madill | e25b800 | 2018-09-20 13:39:49 -0400 | [diff] [blame] | 2603 | } |
| 2604 | |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 2605 | angle::Result State::syncVertexArray(const Context *context) |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2606 | { |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 2607 | ASSERT(mVertexArray); |
| 2608 | return mVertexArray->syncState(context); |
| 2609 | } |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2610 | |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 2611 | angle::Result State::syncProgram(const Context *context) |
| 2612 | { |
| 2613 | return mProgram->syncState(context); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2614 | } |
| 2615 | |
Jamie Madill | 132d15c | 2018-11-30 15:25:38 -0500 | [diff] [blame] | 2616 | angle::Result State::syncTexturesInit(const Context *context) |
| 2617 | { |
| 2618 | ASSERT(mRobustResourceInit); |
| 2619 | |
| 2620 | if (!mProgram) |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2621 | return angle::Result::Continue; |
Jamie Madill | 132d15c | 2018-11-30 15:25:38 -0500 | [diff] [blame] | 2622 | |
| 2623 | for (size_t textureUnitIndex : mProgram->getActiveSamplersMask()) |
| 2624 | { |
| 2625 | Texture *texture = mActiveTexturesCache[textureUnitIndex]; |
| 2626 | if (texture) |
| 2627 | { |
| 2628 | ANGLE_TRY(texture->ensureInitialized(context)); |
| 2629 | } |
| 2630 | } |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2631 | return angle::Result::Continue; |
Jamie Madill | 132d15c | 2018-11-30 15:25:38 -0500 | [diff] [blame] | 2632 | } |
| 2633 | |
| 2634 | angle::Result State::syncImagesInit(const Context *context) |
| 2635 | { |
| 2636 | ASSERT(mRobustResourceInit); |
| 2637 | ASSERT(mProgram); |
| 2638 | for (size_t imageUnitIndex : mProgram->getActiveImagesMask()) |
| 2639 | { |
| 2640 | Texture *texture = mImageUnits[imageUnitIndex].texture.get(); |
| 2641 | if (texture) |
| 2642 | { |
| 2643 | ANGLE_TRY(texture->ensureInitialized(context)); |
| 2644 | } |
| 2645 | } |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2646 | return angle::Result::Continue; |
Jamie Madill | 132d15c | 2018-11-30 15:25:38 -0500 | [diff] [blame] | 2647 | } |
| 2648 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 2649 | angle::Result State::syncDirtyObject(const Context *context, GLenum target) |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2650 | { |
| 2651 | DirtyObjects localSet; |
| 2652 | |
| 2653 | switch (target) |
| 2654 | { |
| 2655 | case GL_READ_FRAMEBUFFER: |
| 2656 | localSet.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
| 2657 | break; |
| 2658 | case GL_DRAW_FRAMEBUFFER: |
| 2659 | localSet.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
| 2660 | break; |
| 2661 | case GL_FRAMEBUFFER: |
| 2662 | localSet.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
| 2663 | localSet.set(DIRTY_OBJECT_DRAW_FRAMEBUFFER); |
| 2664 | break; |
| 2665 | case GL_VERTEX_ARRAY: |
| 2666 | localSet.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 2667 | break; |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2668 | case GL_TEXTURE: |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 2669 | localSet.set(DIRTY_OBJECT_TEXTURES); |
Jamie Madill | e25b800 | 2018-09-20 13:39:49 -0400 | [diff] [blame] | 2670 | break; |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2671 | case GL_SAMPLER: |
Jamie Madill | e25b800 | 2018-09-20 13:39:49 -0400 | [diff] [blame] | 2672 | localSet.set(DIRTY_OBJECT_SAMPLERS); |
Jamie Madill | 70aeda4 | 2018-08-20 12:17:40 -0400 | [diff] [blame] | 2673 | break; |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2674 | case GL_PROGRAM: |
Jamie Madill | 70aeda4 | 2018-08-20 12:17:40 -0400 | [diff] [blame] | 2675 | localSet.set(DIRTY_OBJECT_PROGRAM); |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2676 | break; |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2677 | } |
| 2678 | |
Jamie Madill | bc918e7 | 2018-03-08 09:47:21 -0500 | [diff] [blame] | 2679 | return syncDirtyObjects(context, localSet); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2680 | } |
| 2681 | |
| 2682 | void State::setObjectDirty(GLenum target) |
| 2683 | { |
| 2684 | switch (target) |
| 2685 | { |
| 2686 | case GL_READ_FRAMEBUFFER: |
| 2687 | mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
| 2688 | break; |
| 2689 | case GL_DRAW_FRAMEBUFFER: |
Jamie Madill | ef9fcd9 | 2018-11-28 14:03:59 -0500 | [diff] [blame] | 2690 | setDrawFramebufferDirty(); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2691 | break; |
| 2692 | case GL_FRAMEBUFFER: |
| 2693 | mDirtyObjects.set(DIRTY_OBJECT_READ_FRAMEBUFFER); |
Jamie Madill | ef9fcd9 | 2018-11-28 14:03:59 -0500 | [diff] [blame] | 2694 | setDrawFramebufferDirty(); |
Jamie Madill | 60ec6ea | 2016-01-22 15:27:19 -0500 | [diff] [blame] | 2695 | break; |
| 2696 | case GL_VERTEX_ARRAY: |
| 2697 | mDirtyObjects.set(DIRTY_OBJECT_VERTEX_ARRAY); |
| 2698 | break; |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2699 | case GL_PROGRAM: |
Jamie Madill | 70aeda4 | 2018-08-20 12:17:40 -0400 | [diff] [blame] | 2700 | mDirtyObjects.set(DIRTY_OBJECT_PROGRAM); |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 2701 | break; |
| 2702 | default: |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2703 | break; |
Jamie Madill | a779b61 | 2017-07-24 11:46:05 -0400 | [diff] [blame] | 2704 | } |
| 2705 | } |
| 2706 | |
Jamie Madill | 6f755b2 | 2018-10-09 12:48:54 -0400 | [diff] [blame] | 2707 | angle::Result State::onProgramExecutableChange(const Context *context, Program *program) |
Jamie Madill | a779b61 | 2017-07-24 11:46:05 -0400 | [diff] [blame] | 2708 | { |
| 2709 | // OpenGL Spec: |
| 2710 | // "If LinkProgram or ProgramBinary successfully re-links a program object |
| 2711 | // that was already in use as a result of a previous call to UseProgram, then the |
| 2712 | // generated executable code will be installed as part of the current rendering state." |
Jamie Madill | df836ff | 2018-10-01 10:36:24 -0400 | [diff] [blame] | 2713 | ASSERT(program->isLinked()); |
| 2714 | |
| 2715 | mDirtyBits.set(DIRTY_BIT_PROGRAM_EXECUTABLE); |
Jamie Madill | 956ab4d | 2018-10-10 16:13:03 -0400 | [diff] [blame] | 2716 | |
| 2717 | if (program->hasAnyDirtyBit()) |
| 2718 | { |
| 2719 | mDirtyObjects.set(DIRTY_OBJECT_PROGRAM); |
| 2720 | } |
Jamie Madill | e3bb6b7 | 2018-10-03 17:51:15 -0400 | [diff] [blame] | 2721 | |
| 2722 | // Set any bound textures. |
| 2723 | const ActiveTextureTypeArray &textureTypes = program->getActiveSamplerTypes(); |
| 2724 | for (size_t textureIndex : program->getActiveSamplersMask()) |
| 2725 | { |
| 2726 | TextureType type = textureTypes[textureIndex]; |
| 2727 | |
| 2728 | // This can happen if there is a conflicting texture type. |
| 2729 | if (type == TextureType::InvalidEnum) |
| 2730 | continue; |
| 2731 | |
| 2732 | Texture *texture = mSamplerTextures[type][textureIndex].get(); |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 2733 | updateActiveTexture(context, textureIndex, texture); |
Jamie Madill | e3bb6b7 | 2018-10-03 17:51:15 -0400 | [diff] [blame] | 2734 | } |
| 2735 | |
| 2736 | for (size_t imageUnitIndex : program->getActiveImagesMask()) |
| 2737 | { |
| 2738 | Texture *image = mImageUnits[imageUnitIndex].texture.get(); |
| 2739 | if (!image) |
| 2740 | continue; |
| 2741 | |
| 2742 | if (image->hasAnyDirtyBit()) |
| 2743 | { |
| 2744 | ANGLE_TRY(image->syncState(context)); |
| 2745 | } |
| 2746 | |
Jamie Madill | 132d15c | 2018-11-30 15:25:38 -0500 | [diff] [blame] | 2747 | if (mRobustResourceInit && image->initState() == InitState::MayNeedInit) |
Jamie Madill | e3bb6b7 | 2018-10-03 17:51:15 -0400 | [diff] [blame] | 2748 | { |
Jamie Madill | 132d15c | 2018-11-30 15:25:38 -0500 | [diff] [blame] | 2749 | mDirtyObjects.set(DIRTY_OBJECT_IMAGES_INIT); |
Jamie Madill | e3bb6b7 | 2018-10-03 17:51:15 -0400 | [diff] [blame] | 2750 | } |
| 2751 | } |
| 2752 | |
Jamie Madill | 7c985f5 | 2018-11-29 18:16:17 -0500 | [diff] [blame] | 2753 | return angle::Result::Continue; |
Shannon Woods | 53a94a8 | 2014-06-24 15:20:36 -0400 | [diff] [blame] | 2754 | } |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2755 | |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 2756 | void State::setTextureDirty(size_t textureUnitIndex) |
| 2757 | { |
| 2758 | mDirtyObjects.set(DIRTY_OBJECT_TEXTURES); |
| 2759 | mDirtyTextures.set(textureUnitIndex); |
| 2760 | } |
| 2761 | |
Jamie Madill | e25b800 | 2018-09-20 13:39:49 -0400 | [diff] [blame] | 2762 | void State::setSamplerDirty(size_t samplerIndex) |
| 2763 | { |
| 2764 | mDirtyObjects.set(DIRTY_OBJECT_SAMPLERS); |
| 2765 | mDirtySamplers.set(samplerIndex); |
| 2766 | } |
| 2767 | |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 2768 | void State::setImageUnit(const Context *context, |
Will Harris | 63aa0e5 | 2018-09-05 16:15:46 -0700 | [diff] [blame] | 2769 | size_t unit, |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 2770 | Texture *texture, |
| 2771 | GLint level, |
| 2772 | GLboolean layered, |
| 2773 | GLint layer, |
| 2774 | GLenum access, |
| 2775 | GLenum format) |
| 2776 | { |
| 2777 | mImageUnits[unit].texture.set(context, texture); |
| 2778 | mImageUnits[unit].level = level; |
| 2779 | mImageUnits[unit].layered = layered; |
| 2780 | mImageUnits[unit].layer = layer; |
| 2781 | mImageUnits[unit].access = access; |
| 2782 | mImageUnits[unit].format = format; |
jchen10 | 99118c1 | 2018-09-10 16:28:51 +0800 | [diff] [blame] | 2783 | mDirtyBits.set(DIRTY_BIT_IMAGE_BINDINGS); |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 2784 | |
| 2785 | onImageStateChange(context, unit); |
Xinghua Cao | 65ec0b2 | 2017-03-28 16:10:52 +0800 | [diff] [blame] | 2786 | } |
| 2787 | |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2788 | // Handle a dirty texture event. |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 2789 | void State::onActiveTextureChange(const Context *context, size_t textureUnit) |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2790 | { |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 2791 | if (mProgram) |
Geoff Lang | e51ba63 | 2017-11-21 11:45:25 -0500 | [diff] [blame] | 2792 | { |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 2793 | TextureType type = mProgram->getActiveSamplerTypes()[textureUnit]; |
| 2794 | if (type != TextureType::InvalidEnum) |
| 2795 | { |
| 2796 | Texture *activeTexture = mSamplerTextures[type][textureUnit].get(); |
| 2797 | updateActiveTexture(context, textureUnit, activeTexture); |
| 2798 | } |
| 2799 | } |
| 2800 | } |
| 2801 | |
| 2802 | void State::onActiveTextureStateChange(const Context *context, size_t textureUnit) |
| 2803 | { |
| 2804 | if (mProgram) |
| 2805 | { |
| 2806 | TextureType type = mProgram->getActiveSamplerTypes()[textureUnit]; |
| 2807 | if (type != TextureType::InvalidEnum) |
| 2808 | { |
| 2809 | Texture *activeTexture = mSamplerTextures[type][textureUnit].get(); |
| 2810 | const Sampler *sampler = mSamplers[textureUnit].get(); |
| 2811 | updateActiveTextureState(context, textureUnit, sampler, activeTexture); |
| 2812 | } |
| 2813 | } |
| 2814 | } |
| 2815 | |
| 2816 | void State::onImageStateChange(const Context *context, size_t unit) |
| 2817 | { |
| 2818 | if (mProgram) |
| 2819 | { |
| 2820 | const ImageUnit &image = mImageUnits[unit]; |
| 2821 | ASSERT(image.texture.get()); |
Jamie Madill | 132d15c | 2018-11-30 15:25:38 -0500 | [diff] [blame] | 2822 | if (mRobustResourceInit && image.texture->initState() == InitState::MayNeedInit) |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 2823 | { |
Jamie Madill | 132d15c | 2018-11-30 15:25:38 -0500 | [diff] [blame] | 2824 | mDirtyObjects.set(DIRTY_OBJECT_IMAGES_INIT); |
Jamie Madill | e3e680c | 2018-12-03 17:49:08 -0500 | [diff] [blame] | 2825 | } |
Geoff Lang | e51ba63 | 2017-11-21 11:45:25 -0500 | [diff] [blame] | 2826 | } |
Jamie Madill | 81c2e25 | 2017-09-09 23:32:46 -0400 | [diff] [blame] | 2827 | } |
| 2828 | |
Jamie Madill | 6d32cef | 2018-08-14 02:34:28 -0400 | [diff] [blame] | 2829 | void State::onUniformBufferStateChange(size_t uniformBufferIndex) |
| 2830 | { |
| 2831 | // This could be represented by a different dirty bit. Using the same one keeps it simple. |
| 2832 | mDirtyBits.set(DIRTY_BIT_UNIFORM_BUFFER_BINDINGS); |
| 2833 | } |
| 2834 | |
Jamie Madill | c67323a | 2017-11-02 23:11:41 -0400 | [diff] [blame] | 2835 | AttributesMask State::getAndResetDirtyCurrentValues() const |
| 2836 | { |
| 2837 | AttributesMask retVal = mDirtyCurrentValues; |
| 2838 | mDirtyCurrentValues.reset(); |
| 2839 | return retVal; |
| 2840 | } |
| 2841 | |
Markus Tavenrath | f7f8c51 | 2018-11-18 15:56:45 +0100 | [diff] [blame] | 2842 | constexpr State::DirtyObjectHandler State::kDirtyObjectHandlers[DIRTY_OBJECT_MAX]; |
| 2843 | |
Jamie Madill | c9d442d | 2016-01-20 11:17:24 -0500 | [diff] [blame] | 2844 | } // namespace gl |