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