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