Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2013 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 | // Implementation of the state class for mananging GLES 3 Vertex Array Objects. |
| 7 | // |
| 8 | |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 9 | #include "libANGLE/VertexArray.h" |
| 10 | #include "libANGLE/Buffer.h" |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 11 | #include "libANGLE/Context.h" |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 12 | #include "libANGLE/renderer/BufferImpl.h" |
Jamie Madill | 7aea7e0 | 2016-05-10 10:39:45 -0400 | [diff] [blame] | 13 | #include "libANGLE/renderer/GLImplFactory.h" |
Geoff Lang | 2b5420c | 2014-11-19 14:20:15 -0500 | [diff] [blame] | 14 | #include "libANGLE/renderer/VertexArrayImpl.h" |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 15 | |
| 16 | namespace gl |
| 17 | { |
Jamie Madill | bcef322 | 2018-04-13 15:19:11 -0400 | [diff] [blame^] | 18 | // VertexArrayState implementation. |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 19 | VertexArrayState::VertexArrayState(size_t maxAttribs, size_t maxAttribBindings) |
Jamie Madill | d078c68 | 2018-01-02 11:50:24 -0500 | [diff] [blame] | 20 | : mLabel(), mVertexBindings(maxAttribBindings) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 21 | { |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 22 | ASSERT(maxAttribs <= maxAttribBindings); |
| 23 | |
| 24 | for (size_t i = 0; i < maxAttribs; i++) |
| 25 | { |
| 26 | mVertexAttributes.emplace_back(static_cast<GLuint>(i)); |
| 27 | } |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 28 | } |
| 29 | |
Jamie Madill | 3f57268 | 2016-04-26 13:41:36 -0400 | [diff] [blame] | 30 | VertexArrayState::~VertexArrayState() |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 31 | { |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 32 | } |
| 33 | |
Jamie Madill | bcef322 | 2018-04-13 15:19:11 -0400 | [diff] [blame^] | 34 | gl::AttributesMask VertexArrayState::getEnabledClientMemoryAttribsMask() const |
| 35 | { |
| 36 | return (mClientMemoryAttribsMask & mEnabledAttributesMask); |
| 37 | } |
| 38 | |
| 39 | // VertexArray implementation. |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 40 | VertexArray::VertexArray(rx::GLImplFactory *factory, |
| 41 | GLuint id, |
| 42 | size_t maxAttribs, |
| 43 | size_t maxAttribBindings) |
| 44 | : mId(id), |
| 45 | mState(maxAttribs, maxAttribBindings), |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 46 | mVertexArray(factory->createVertexArray(mState)), |
| 47 | mElementArrayBufferObserverBinding(this, maxAttribBindings) |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 48 | { |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 49 | for (size_t attribIndex = 0; attribIndex < maxAttribBindings; ++attribIndex) |
| 50 | { |
| 51 | mArrayBufferObserverBindings.emplace_back(this, attribIndex); |
| 52 | } |
Jamie Madill | 004a6f9 | 2013-07-10 15:13:38 -0400 | [diff] [blame] | 53 | } |
| 54 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 55 | void VertexArray::onDestroy(const Context *context) |
| 56 | { |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 57 | bool isBound = context->isCurrentVertexArray(this); |
Jamie Madill | bcef322 | 2018-04-13 15:19:11 -0400 | [diff] [blame^] | 58 | for (VertexBinding &binding : mState.mVertexBindings) |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 59 | { |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 60 | binding.setBuffer(context, nullptr, isBound); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 61 | } |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 62 | if (isBound && mState.mElementArrayBuffer.get()) |
| 63 | mState.mElementArrayBuffer->onBindingChanged(false, BufferBinding::ElementArray); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 64 | mState.mElementArrayBuffer.set(context, nullptr); |
| 65 | mVertexArray->destroy(context); |
| 66 | SafeDelete(mVertexArray); |
| 67 | delete this; |
| 68 | } |
| 69 | |
Jamie Madill | 004a6f9 | 2013-07-10 15:13:38 -0400 | [diff] [blame] | 70 | VertexArray::~VertexArray() |
| 71 | { |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 72 | ASSERT(!mVertexArray); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 73 | } |
| 74 | |
Shannon Woods | aa2ab7d | 2014-06-24 17:51:51 -0400 | [diff] [blame] | 75 | GLuint VertexArray::id() const |
| 76 | { |
| 77 | return mId; |
| 78 | } |
| 79 | |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 80 | void VertexArray::setLabel(const std::string &label) |
| 81 | { |
Jamie Madill | 3f57268 | 2016-04-26 13:41:36 -0400 | [diff] [blame] | 82 | mState.mLabel = label; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | const std::string &VertexArray::getLabel() const |
| 86 | { |
Jamie Madill | 3f57268 | 2016-04-26 13:41:36 -0400 | [diff] [blame] | 87 | return mState.mLabel; |
Geoff Lang | 70d0f49 | 2015-12-10 17:45:46 -0500 | [diff] [blame] | 88 | } |
| 89 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 90 | void VertexArray::detachBuffer(const Context *context, GLuint bufferName) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 91 | { |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 92 | bool isBound = context->isCurrentVertexArray(this); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 93 | for (auto &binding : mState.mVertexBindings) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 94 | { |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 95 | if (binding.getBuffer().id() == bufferName) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 96 | { |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 97 | binding.setBuffer(context, nullptr, isBound); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | |
Jamie Madill | 3f57268 | 2016-04-26 13:41:36 -0400 | [diff] [blame] | 101 | if (mState.mElementArrayBuffer.id() == bufferName) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 102 | { |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 103 | if (isBound && mState.mElementArrayBuffer.get()) |
| 104 | mState.mElementArrayBuffer->onBindingChanged(false, BufferBinding::Array); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 105 | mState.mElementArrayBuffer.set(context, nullptr); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 109 | const VertexAttribute &VertexArray::getVertexAttribute(size_t attribIndex) const |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 110 | { |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 111 | ASSERT(attribIndex < getMaxAttribs()); |
| 112 | return mState.mVertexAttributes[attribIndex]; |
| 113 | } |
| 114 | |
| 115 | const VertexBinding &VertexArray::getVertexBinding(size_t bindingIndex) const |
| 116 | { |
| 117 | ASSERT(bindingIndex < getMaxBindings()); |
| 118 | return mState.mVertexBindings[bindingIndex]; |
| 119 | } |
| 120 | |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 121 | size_t VertexArray::GetVertexIndexFromDirtyBit(size_t dirtyBit) |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 122 | { |
| 123 | static_assert(gl::MAX_VERTEX_ATTRIBS == gl::MAX_VERTEX_ATTRIB_BINDINGS, |
| 124 | "The stride of vertex attributes should equal to that of vertex bindings."); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 125 | ASSERT(dirtyBit > DIRTY_BIT_ELEMENT_ARRAY_BUFFER); |
Jamie Madill | e858cb1 | 2018-03-27 09:44:32 -0400 | [diff] [blame] | 126 | return (dirtyBit - DIRTY_BIT_ATTRIB_0) % gl::MAX_VERTEX_ATTRIBS; |
| 127 | } |
| 128 | |
| 129 | void VertexArray::setDirtyAttribBit(size_t attribIndex, DirtyAttribBitType dirtyAttribBit) |
| 130 | { |
| 131 | mDirtyBits.set(DIRTY_BIT_ATTRIB_0 + attribIndex); |
| 132 | mDirtyAttribBits[attribIndex].set(dirtyAttribBit); |
| 133 | } |
| 134 | |
| 135 | void VertexArray::setDirtyBindingBit(size_t bindingIndex, DirtyBindingBitType dirtyBindingBit) |
| 136 | { |
| 137 | mDirtyBits.set(DIRTY_BIT_BINDING_0 + bindingIndex); |
| 138 | mDirtyBindingBits[bindingIndex].set(dirtyBindingBit); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 139 | } |
| 140 | |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 141 | void VertexArray::bindVertexBufferImpl(const Context *context, |
| 142 | size_t bindingIndex, |
| 143 | Buffer *boundBuffer, |
| 144 | GLintptr offset, |
| 145 | GLsizei stride) |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 146 | { |
| 147 | ASSERT(bindingIndex < getMaxBindings()); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 148 | bool isBound = context->isCurrentVertexArray(this); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 149 | |
| 150 | VertexBinding *binding = &mState.mVertexBindings[bindingIndex]; |
| 151 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 152 | binding->setBuffer(context, boundBuffer, isBound); |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 153 | binding->setOffset(offset); |
| 154 | binding->setStride(stride); |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 155 | |
| 156 | updateObserverBinding(bindingIndex); |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | void VertexArray::bindVertexBuffer(const Context *context, |
| 160 | size_t bindingIndex, |
| 161 | Buffer *boundBuffer, |
| 162 | GLintptr offset, |
| 163 | GLsizei stride) |
| 164 | { |
| 165 | bindVertexBufferImpl(context, bindingIndex, boundBuffer, offset, stride); |
Jamie Madill | e858cb1 | 2018-03-27 09:44:32 -0400 | [diff] [blame] | 166 | setDirtyBindingBit(bindingIndex, DIRTY_BINDING_BUFFER); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 167 | } |
| 168 | |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 169 | void VertexArray::setVertexAttribBinding(const Context *context, |
| 170 | size_t attribIndex, |
| 171 | GLuint bindingIndex) |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 172 | { |
| 173 | ASSERT(attribIndex < getMaxAttribs() && bindingIndex < getMaxBindings()); |
| 174 | |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 175 | if (mState.mVertexAttributes[attribIndex].bindingIndex != bindingIndex) |
| 176 | { |
| 177 | // In ES 3.0 contexts, the binding cannot change, hence the code below is unreachable. |
| 178 | ASSERT(context->getClientVersion() >= ES_3_1); |
| 179 | mState.mVertexAttributes[attribIndex].bindingIndex = bindingIndex; |
| 180 | |
Jamie Madill | e858cb1 | 2018-03-27 09:44:32 -0400 | [diff] [blame] | 181 | setDirtyAttribBit(attribIndex, DIRTY_ATTRIB_BINDING); |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 182 | } |
Jamie Madill | e858cb1 | 2018-03-27 09:44:32 -0400 | [diff] [blame] | 183 | mState.mVertexAttributes[attribIndex].bindingIndex = static_cast<GLuint>(bindingIndex); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | void VertexArray::setVertexBindingDivisor(size_t bindingIndex, GLuint divisor) |
| 187 | { |
| 188 | ASSERT(bindingIndex < getMaxBindings()); |
| 189 | |
Martin Radev | dd5f27e | 2017-06-07 10:17:09 +0300 | [diff] [blame] | 190 | mState.mVertexBindings[bindingIndex].setDivisor(divisor); |
Jamie Madill | e858cb1 | 2018-03-27 09:44:32 -0400 | [diff] [blame] | 191 | setDirtyBindingBit(bindingIndex, DIRTY_BINDING_DIVISOR); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 192 | } |
| 193 | |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 194 | void VertexArray::setVertexAttribFormatImpl(size_t attribIndex, |
| 195 | GLint size, |
| 196 | GLenum type, |
| 197 | bool normalized, |
| 198 | bool pureInteger, |
| 199 | GLuint relativeOffset) |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 200 | { |
| 201 | ASSERT(attribIndex < getMaxAttribs()); |
| 202 | |
| 203 | VertexAttribute *attrib = &mState.mVertexAttributes[attribIndex]; |
| 204 | |
| 205 | attrib->size = size; |
| 206 | attrib->type = type; |
| 207 | attrib->normalized = normalized; |
| 208 | attrib->pureInteger = pureInteger; |
| 209 | attrib->relativeOffset = relativeOffset; |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 210 | mState.mVertexAttributesTypeMask.setIndex(GetVertexAttributeBaseType(*attrib), attribIndex); |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | void VertexArray::setVertexAttribFormat(size_t attribIndex, |
| 214 | GLint size, |
| 215 | GLenum type, |
| 216 | bool normalized, |
| 217 | bool pureInteger, |
| 218 | GLuint relativeOffset) |
| 219 | { |
| 220 | setVertexAttribFormatImpl(attribIndex, size, type, normalized, pureInteger, relativeOffset); |
Jamie Madill | e858cb1 | 2018-03-27 09:44:32 -0400 | [diff] [blame] | 221 | setDirtyAttribBit(attribIndex, DIRTY_ATTRIB_FORMAT); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 222 | } |
| 223 | |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 224 | void VertexArray::setVertexAttribDivisor(const Context *context, size_t attribIndex, GLuint divisor) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 225 | { |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 226 | ASSERT(attribIndex < getMaxAttribs()); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 227 | |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 228 | setVertexAttribBinding(context, attribIndex, static_cast<GLuint>(attribIndex)); |
| 229 | setVertexBindingDivisor(attribIndex, divisor); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 230 | } |
| 231 | |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 232 | void VertexArray::enableAttribute(size_t attribIndex, bool enabledState) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 233 | { |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 234 | ASSERT(attribIndex < getMaxAttribs()); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 235 | |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 236 | mState.mVertexAttributes[attribIndex].enabled = enabledState; |
Brandon Jones | c405ae7 | 2017-12-06 14:15:03 -0800 | [diff] [blame] | 237 | mState.mVertexAttributesTypeMask.setIndex( |
| 238 | GetVertexAttributeBaseType(mState.mVertexAttributes[attribIndex]), attribIndex); |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 239 | |
Jamie Madill | e858cb1 | 2018-03-27 09:44:32 -0400 | [diff] [blame] | 240 | setDirtyAttribBit(attribIndex, DIRTY_ATTRIB_ENABLED); |
Jamie Madill | aebf9dd | 2015-04-28 12:39:07 -0400 | [diff] [blame] | 241 | |
| 242 | // Update state cache |
Jamie Madill | d078c68 | 2018-01-02 11:50:24 -0500 | [diff] [blame] | 243 | mState.mEnabledAttributesMask.set(attribIndex, enabledState); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 244 | } |
| 245 | |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 246 | void VertexArray::setVertexAttribPointer(const Context *context, |
| 247 | size_t attribIndex, |
| 248 | gl::Buffer *boundBuffer, |
| 249 | GLint size, |
| 250 | GLenum type, |
| 251 | bool normalized, |
| 252 | bool pureInteger, |
| 253 | GLsizei stride, |
| 254 | const void *pointer) |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 255 | { |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 256 | ASSERT(attribIndex < getMaxAttribs()); |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 257 | |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 258 | GLintptr offset = boundBuffer ? reinterpret_cast<GLintptr>(pointer) : 0; |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 259 | |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 260 | setVertexAttribFormatImpl(attribIndex, size, type, normalized, pureInteger, 0); |
| 261 | setVertexAttribBinding(context, attribIndex, static_cast<GLuint>(attribIndex)); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 262 | |
| 263 | VertexAttribute &attrib = mState.mVertexAttributes[attribIndex]; |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 264 | |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 265 | GLsizei effectiveStride = |
| 266 | stride != 0 ? stride : static_cast<GLsizei>(ComputeVertexAttributeTypeSize(attrib)); |
| 267 | attrib.pointer = pointer; |
| 268 | attrib.vertexAttribArrayStride = stride; |
| 269 | |
Shao | dde78e8 | 2017-05-22 14:13:27 +0800 | [diff] [blame] | 270 | bindVertexBufferImpl(context, attribIndex, boundBuffer, offset, effectiveStride); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 271 | |
Jamie Madill | e858cb1 | 2018-03-27 09:44:32 -0400 | [diff] [blame] | 272 | setDirtyAttribBit(attribIndex, DIRTY_ATTRIB_POINTER); |
Jamie Madill | bcef322 | 2018-04-13 15:19:11 -0400 | [diff] [blame^] | 273 | |
| 274 | mState.mClientMemoryAttribsMask.set(attribIndex, boundBuffer == nullptr); |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 277 | void VertexArray::setElementArrayBuffer(const Context *context, Buffer *buffer) |
Brandon Jones | 5bf9829 | 2014-06-06 17:19:38 -0700 | [diff] [blame] | 278 | { |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 279 | bool isBound = context->isCurrentVertexArray(this); |
| 280 | if (isBound && mState.mElementArrayBuffer.get()) |
| 281 | mState.mElementArrayBuffer->onBindingChanged(false, BufferBinding::ElementArray); |
Jamie Madill | 4928b7c | 2017-06-20 12:57:39 -0400 | [diff] [blame] | 282 | mState.mElementArrayBuffer.set(context, buffer); |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 283 | if (isBound && mState.mElementArrayBuffer.get()) |
| 284 | mState.mElementArrayBuffer->onBindingChanged(true, BufferBinding::ElementArray); |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 285 | mElementArrayBufferObserverBinding.bind(buffer ? buffer->getImplementation() : nullptr); |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 286 | mDirtyBits.set(DIRTY_BIT_ELEMENT_ARRAY_BUFFER); |
| 287 | } |
| 288 | |
Frank Henigman | 0af5b86 | 2018-03-27 20:19:33 -0400 | [diff] [blame] | 289 | gl::Error VertexArray::syncState(const Context *context) |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 290 | { |
| 291 | if (mDirtyBits.any()) |
| 292 | { |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 293 | mDirtyBitsGuard = mDirtyBits; |
Frank Henigman | 0af5b86 | 2018-03-27 20:19:33 -0400 | [diff] [blame] | 294 | ANGLE_TRY( |
| 295 | mVertexArray->syncState(context, mDirtyBits, mDirtyAttribBits, mDirtyBindingBits)); |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 296 | mDirtyBits.reset(); |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 297 | mDirtyBitsGuard.reset(); |
Jamie Madill | e858cb1 | 2018-03-27 09:44:32 -0400 | [diff] [blame] | 298 | |
| 299 | // This is a bit of an implementation hack - but since we know the implementation |
| 300 | // details of the dirty bit class it should always have the same effect as iterating |
| 301 | // individual attribs. We could also look into schemes where iterating the dirty |
| 302 | // bit set also resets it as you pass through it. |
| 303 | memset(&mDirtyAttribBits, 0, sizeof(mDirtyAttribBits)); |
| 304 | memset(&mDirtyBindingBits, 0, sizeof(mDirtyBindingBits)); |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 305 | } |
Frank Henigman | 0af5b86 | 2018-03-27 20:19:33 -0400 | [diff] [blame] | 306 | return gl::NoError(); |
Jamie Madill | 57a8972 | 2013-07-02 11:57:03 -0400 | [diff] [blame] | 307 | } |
| 308 | |
James Darpinian | e8a93c6 | 2018-01-04 18:02:24 -0800 | [diff] [blame] | 309 | void VertexArray::onBindingChanged(bool bound) |
| 310 | { |
| 311 | if (mState.mElementArrayBuffer.get()) |
| 312 | mState.mElementArrayBuffer->onBindingChanged(bound, BufferBinding::ElementArray); |
| 313 | for (auto &binding : mState.mVertexBindings) |
| 314 | { |
| 315 | binding.onContainerBindingChanged(bound); |
| 316 | } |
| 317 | } |
| 318 | |
Jamie Madill | 0946393 | 2018-04-04 05:26:59 -0400 | [diff] [blame] | 319 | VertexArray::DirtyBitType VertexArray::getDirtyBitFromIndex(bool contentsChanged, |
| 320 | angle::SubjectIndex index) const |
| 321 | { |
| 322 | if (index == mArrayBufferObserverBindings.size()) |
| 323 | { |
| 324 | return contentsChanged ? DIRTY_BIT_ELEMENT_ARRAY_BUFFER_DATA |
| 325 | : DIRTY_BIT_ELEMENT_ARRAY_BUFFER; |
| 326 | } |
| 327 | else |
| 328 | { |
| 329 | // Note: this currently just gets the top-level dirty bit. |
| 330 | ASSERT(index < mArrayBufferObserverBindings.size()); |
| 331 | return static_cast<DirtyBitType>( |
| 332 | (contentsChanged ? DIRTY_BIT_BUFFER_DATA_0 : DIRTY_BIT_BINDING_0) + index); |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | void VertexArray::onSubjectStateChange(const gl::Context *context, |
| 337 | angle::SubjectIndex index, |
| 338 | angle::SubjectMessage message) |
| 339 | { |
| 340 | bool contentsChanged = (message == angle::SubjectMessage::CONTENTS_CHANGED); |
| 341 | DirtyBitType dirtyBit = getDirtyBitFromIndex(contentsChanged, index); |
| 342 | ASSERT(!mDirtyBitsGuard.valid() || mDirtyBitsGuard.value().test(dirtyBit)); |
| 343 | mDirtyBits.set(dirtyBit); |
| 344 | context->getGLState().setVertexArrayDirty(this); |
| 345 | } |
| 346 | |
| 347 | void VertexArray::updateObserverBinding(size_t bindingIndex) |
| 348 | { |
| 349 | Buffer *boundBuffer = mState.mVertexBindings[bindingIndex].getBuffer().get(); |
| 350 | mArrayBufferObserverBindings[bindingIndex].bind(boundBuffer ? boundBuffer->getImplementation() |
| 351 | : nullptr); |
| 352 | } |
| 353 | |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 354 | } // namespace gl |