Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 1 | // |
| 2 | // Copyright 2015 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 | // VertexArrayGL.cpp: Implements the class methods for VertexArrayGL. |
| 8 | |
| 9 | #include "libANGLE/renderer/gl/VertexArrayGL.h" |
| 10 | |
Jamie Madill | 20e005b | 2017-04-07 14:19:22 -0400 | [diff] [blame] | 11 | #include "common/bitset_utils.h" |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 12 | #include "common/debug.h" |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 13 | #include "common/mathutil.h" |
Geoff Lang | 831b195 | 2015-05-05 11:02:27 -0400 | [diff] [blame] | 14 | #include "common/utilities.h" |
Geoff Lang | 6ae6efc | 2015-03-09 14:42:35 -0400 | [diff] [blame] | 15 | #include "libANGLE/Buffer.h" |
Geoff Lang | ba4c4a8 | 2015-02-24 12:38:46 -0500 | [diff] [blame] | 16 | #include "libANGLE/angletypes.h" |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 17 | #include "libANGLE/formatutils.h" |
Geoff Lang | ba4c4a8 | 2015-02-24 12:38:46 -0500 | [diff] [blame] | 18 | #include "libANGLE/renderer/gl/BufferGL.h" |
| 19 | #include "libANGLE/renderer/gl/FunctionsGL.h" |
Geoff Lang | b2ebb5e | 2016-06-08 18:17:55 +0000 | [diff] [blame] | 20 | #include "libANGLE/renderer/gl/renderergl_utils.h" |
Geoff Lang | ba4c4a8 | 2015-02-24 12:38:46 -0500 | [diff] [blame] | 21 | #include "libANGLE/renderer/gl/StateManagerGL.h" |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 22 | |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 23 | using namespace gl; |
| 24 | |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 25 | namespace rx |
| 26 | { |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 27 | namespace |
| 28 | { |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 29 | // Warning: you should ensure binding really matches attrib.bindingIndex before using this function. |
| 30 | bool AttributeNeedsStreaming(const VertexAttribute &attrib, const VertexBinding &binding) |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 31 | { |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 32 | return (attrib.enabled && binding.buffer.get() == nullptr); |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 33 | } |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 34 | } // anonymous namespace |
| 35 | |
Jamie Madill | 3f57268 | 2016-04-26 13:41:36 -0400 | [diff] [blame] | 36 | VertexArrayGL::VertexArrayGL(const VertexArrayState &state, |
Jamie Madill | 77a90c2 | 2015-08-11 16:33:17 -0400 | [diff] [blame] | 37 | const FunctionsGL *functions, |
| 38 | StateManagerGL *stateManager) |
Jamie Madill | 3f57268 | 2016-04-26 13:41:36 -0400 | [diff] [blame] | 39 | : VertexArrayImpl(state), |
Geoff Lang | ba4c4a8 | 2015-02-24 12:38:46 -0500 | [diff] [blame] | 40 | mFunctions(functions), |
| 41 | mStateManager(stateManager), |
| 42 | mVertexArrayID(0), |
Jamie Madill | 77a90c2 | 2015-08-11 16:33:17 -0400 | [diff] [blame] | 43 | mAppliedElementArrayBuffer(), |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 44 | mAppliedBindings(state.getMaxBindings()), |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 45 | mStreamingElementArrayBufferSize(0), |
| 46 | mStreamingElementArrayBuffer(0), |
| 47 | mStreamingArrayBufferSize(0), |
| 48 | mStreamingArrayBuffer(0) |
Geoff Lang | ba4c4a8 | 2015-02-24 12:38:46 -0500 | [diff] [blame] | 49 | { |
| 50 | ASSERT(mFunctions); |
| 51 | ASSERT(mStateManager); |
| 52 | mFunctions->genVertexArrays(1, &mVertexArrayID); |
| 53 | |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 54 | // Set the cached vertex attribute array and vertex attribute binding array size |
| 55 | GLuint maxVertexAttribs = static_cast<GLuint>(state.getMaxAttribs()); |
| 56 | for (GLuint i = 0; i < maxVertexAttribs; i++) |
| 57 | { |
| 58 | mAppliedAttributes.emplace_back(i); |
| 59 | } |
Geoff Lang | ba4c4a8 | 2015-02-24 12:38:46 -0500 | [diff] [blame] | 60 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 61 | |
| 62 | VertexArrayGL::~VertexArrayGL() |
Geoff Lang | ba4c4a8 | 2015-02-24 12:38:46 -0500 | [diff] [blame] | 63 | { |
Geoff Lang | 1eb708e | 2015-05-04 14:58:23 -0400 | [diff] [blame] | 64 | mStateManager->deleteVertexArray(mVertexArrayID); |
| 65 | mVertexArrayID = 0; |
Geoff Lang | ba4c4a8 | 2015-02-24 12:38:46 -0500 | [diff] [blame] | 66 | |
Geoff Lang | 1eb708e | 2015-05-04 14:58:23 -0400 | [diff] [blame] | 67 | mStateManager->deleteBuffer(mStreamingElementArrayBuffer); |
| 68 | mStreamingElementArrayBufferSize = 0; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 69 | mStreamingElementArrayBuffer = 0; |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 70 | |
Geoff Lang | 1eb708e | 2015-05-04 14:58:23 -0400 | [diff] [blame] | 71 | mStateManager->deleteBuffer(mStreamingArrayBuffer); |
| 72 | mStreamingArrayBufferSize = 0; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 73 | mStreamingArrayBuffer = 0; |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 74 | |
Jamie Madill | 77a90c2 | 2015-08-11 16:33:17 -0400 | [diff] [blame] | 75 | mAppliedElementArrayBuffer.set(nullptr); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 76 | for (auto &binding : mAppliedBindings) |
Geoff Lang | ba4c4a8 | 2015-02-24 12:38:46 -0500 | [diff] [blame] | 77 | { |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 78 | binding.buffer.set(nullptr); |
Geoff Lang | ba4c4a8 | 2015-02-24 12:38:46 -0500 | [diff] [blame] | 79 | } |
| 80 | } |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 81 | |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 82 | gl::Error VertexArrayGL::syncDrawArraysState(const gl::AttributesMask &activeAttributesMask, |
| 83 | GLint first, |
Geoff Lang | 3cf12ce | 2015-08-27 14:40:48 -0400 | [diff] [blame] | 84 | GLsizei count, |
| 85 | GLsizei instanceCount) const |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 86 | { |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 87 | return syncDrawState(activeAttributesMask, first, count, GL_NONE, nullptr, instanceCount, false, |
Geoff Lang | 3cf12ce | 2015-08-27 14:40:48 -0400 | [diff] [blame] | 88 | nullptr); |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 89 | } |
| 90 | |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 91 | gl::Error VertexArrayGL::syncDrawElementsState(const gl::AttributesMask &activeAttributesMask, |
| 92 | GLsizei count, |
| 93 | GLenum type, |
| 94 | const GLvoid *indices, |
Geoff Lang | 3cf12ce | 2015-08-27 14:40:48 -0400 | [diff] [blame] | 95 | GLsizei instanceCount, |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 96 | bool primitiveRestartEnabled, |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 97 | const GLvoid **outIndices) const |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 98 | { |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 99 | return syncDrawState(activeAttributesMask, 0, count, type, indices, instanceCount, |
| 100 | primitiveRestartEnabled, outIndices); |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 101 | } |
| 102 | |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 103 | gl::Error VertexArrayGL::syncElementArrayState() const |
| 104 | { |
| 105 | gl::Buffer *elementArrayBuffer = mData.getElementArrayBuffer().get(); |
| 106 | ASSERT(elementArrayBuffer); |
| 107 | if (elementArrayBuffer != mAppliedElementArrayBuffer.get()) |
| 108 | { |
| 109 | const BufferGL *bufferGL = GetImplAs<BufferGL>(elementArrayBuffer); |
| 110 | mStateManager->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferGL->getBufferID()); |
| 111 | mAppliedElementArrayBuffer.set(elementArrayBuffer); |
| 112 | } |
| 113 | |
| 114 | return gl::NoError(); |
| 115 | } |
| 116 | |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 117 | gl::Error VertexArrayGL::syncDrawState(const gl::AttributesMask &activeAttributesMask, |
| 118 | GLint first, |
| 119 | GLsizei count, |
| 120 | GLenum type, |
| 121 | const GLvoid *indices, |
Geoff Lang | 3cf12ce | 2015-08-27 14:40:48 -0400 | [diff] [blame] | 122 | GLsizei instanceCount, |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 123 | bool primitiveRestartEnabled, |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 124 | const GLvoid **outIndices) const |
Geoff Lang | 6ae6efc | 2015-03-09 14:42:35 -0400 | [diff] [blame] | 125 | { |
Jamie Madill | 77a90c2 | 2015-08-11 16:33:17 -0400 | [diff] [blame] | 126 | mStateManager->bindVertexArray(mVertexArrayID, getAppliedElementArrayBufferID()); |
Geoff Lang | 6ae6efc | 2015-03-09 14:42:35 -0400 | [diff] [blame] | 127 | |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 128 | // Check if any attributes need to be streamed, determines if the index range needs to be |
| 129 | // computed |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 130 | bool attributesNeedStreaming = mAttributesNeedStreaming.any(); |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 131 | |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 132 | // Determine if an index buffer needs to be streamed and the range of vertices that need to be |
| 133 | // copied |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 134 | IndexRange indexRange; |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 135 | if (type != GL_NONE) |
Geoff Lang | ba4c4a8 | 2015-02-24 12:38:46 -0500 | [diff] [blame] | 136 | { |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 137 | Error error = syncIndexData(count, type, indices, primitiveRestartEnabled, |
| 138 | attributesNeedStreaming, &indexRange, outIndices); |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 139 | if (error.isError()) |
| 140 | { |
| 141 | return error; |
| 142 | } |
| 143 | } |
| 144 | else |
| 145 | { |
Corentin Wallez | 2c34a4b | 2015-08-25 16:26:02 -0400 | [diff] [blame] | 146 | // Not an indexed call, set the range to [first, first + count - 1] |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 147 | indexRange.start = first; |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 148 | indexRange.end = first + count - 1; |
Geoff Lang | ba4c4a8 | 2015-02-24 12:38:46 -0500 | [diff] [blame] | 149 | } |
| 150 | |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 151 | if (attributesNeedStreaming) |
Geoff Lang | ba4c4a8 | 2015-02-24 12:38:46 -0500 | [diff] [blame] | 152 | { |
Geoff Lang | 3cf12ce | 2015-08-27 14:40:48 -0400 | [diff] [blame] | 153 | Error error = streamAttributes(activeAttributesMask, instanceCount, indexRange); |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 154 | if (error.isError()) |
| 155 | { |
| 156 | return error; |
| 157 | } |
| 158 | } |
| 159 | |
He Yunchao | acd1898 | 2017-01-04 10:46:42 +0800 | [diff] [blame] | 160 | return NoError(); |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 161 | } |
| 162 | |
Jiajia Qin | d967122 | 2016-11-29 16:30:31 +0800 | [diff] [blame] | 163 | gl::Error VertexArrayGL::syncIndexData(GLsizei count, |
| 164 | GLenum type, |
| 165 | const GLvoid *indices, |
| 166 | bool primitiveRestartEnabled, |
| 167 | bool attributesNeedStreaming, |
| 168 | IndexRange *outIndexRange, |
| 169 | const GLvoid **outIndices) const |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 170 | { |
| 171 | ASSERT(outIndices); |
| 172 | |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 173 | gl::Buffer *elementArrayBuffer = mData.getElementArrayBuffer().get(); |
| 174 | |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 175 | // Need to check the range of indices if attributes need to be streamed |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 176 | if (elementArrayBuffer != nullptr) |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 177 | { |
Jamie Madill | 77a90c2 | 2015-08-11 16:33:17 -0400 | [diff] [blame] | 178 | if (elementArrayBuffer != mAppliedElementArrayBuffer.get()) |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 179 | { |
Jamie Madill | 77a90c2 | 2015-08-11 16:33:17 -0400 | [diff] [blame] | 180 | const BufferGL *bufferGL = GetImplAs<BufferGL>(elementArrayBuffer); |
| 181 | mStateManager->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferGL->getBufferID()); |
| 182 | mAppliedElementArrayBuffer.set(elementArrayBuffer); |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | // Only compute the index range if the attributes also need to be streamed |
| 186 | if (attributesNeedStreaming) |
| 187 | { |
| 188 | ptrdiff_t elementArrayBufferOffset = reinterpret_cast<ptrdiff_t>(indices); |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 189 | Error error = mData.getElementArrayBuffer()->getIndexRange( |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 190 | type, elementArrayBufferOffset, count, primitiveRestartEnabled, outIndexRange); |
Geoff Lang | 520c4ae | 2015-05-05 13:12:36 -0400 | [diff] [blame] | 191 | if (error.isError()) |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 192 | { |
Geoff Lang | 520c4ae | 2015-05-05 13:12:36 -0400 | [diff] [blame] | 193 | return error; |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 197 | // Indices serves as an offset into the index buffer in this case, use the same value for |
| 198 | // the draw call |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 199 | *outIndices = indices; |
| 200 | } |
| 201 | else |
| 202 | { |
| 203 | // Need to stream the index buffer |
| 204 | // TODO: if GLES, nothing needs to be streamed |
| 205 | |
| 206 | // Only compute the index range if the attributes also need to be streamed |
| 207 | if (attributesNeedStreaming) |
| 208 | { |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 209 | *outIndexRange = ComputeIndexRange(type, indices, count, primitiveRestartEnabled); |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | // Allocate the streaming element array buffer |
| 213 | if (mStreamingElementArrayBuffer == 0) |
| 214 | { |
| 215 | mFunctions->genBuffers(1, &mStreamingElementArrayBuffer); |
| 216 | mStreamingElementArrayBufferSize = 0; |
| 217 | } |
| 218 | |
| 219 | mStateManager->bindBuffer(GL_ELEMENT_ARRAY_BUFFER, mStreamingElementArrayBuffer); |
Jamie Madill | 77a90c2 | 2015-08-11 16:33:17 -0400 | [diff] [blame] | 220 | mAppliedElementArrayBuffer.set(nullptr); |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 221 | |
| 222 | // Make sure the element array buffer is large enough |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 223 | const Type &indexTypeInfo = GetTypeInfo(type); |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 224 | size_t requiredStreamingBufferSize = indexTypeInfo.bytes * count; |
| 225 | if (requiredStreamingBufferSize > mStreamingElementArrayBufferSize) |
| 226 | { |
| 227 | // Copy the indices in while resizing the buffer |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 228 | mFunctions->bufferData(GL_ELEMENT_ARRAY_BUFFER, requiredStreamingBufferSize, indices, |
| 229 | GL_DYNAMIC_DRAW); |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 230 | mStreamingElementArrayBufferSize = requiredStreamingBufferSize; |
| 231 | } |
| 232 | else |
| 233 | { |
| 234 | // Put the indices at the beginning of the buffer |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 235 | mFunctions->bufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, requiredStreamingBufferSize, |
| 236 | indices); |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 237 | } |
| 238 | |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 239 | // Set the index offset for the draw call to zero since the supplied index pointer is to |
| 240 | // client data |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 241 | *outIndices = nullptr; |
| 242 | } |
| 243 | |
He Yunchao | acd1898 | 2017-01-04 10:46:42 +0800 | [diff] [blame] | 244 | return NoError(); |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 245 | } |
| 246 | |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 247 | void VertexArrayGL::computeStreamingAttributeSizes(const gl::AttributesMask &activeAttributesMask, |
Geoff Lang | 3cf12ce | 2015-08-27 14:40:48 -0400 | [diff] [blame] | 248 | GLsizei instanceCount, |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 249 | const gl::IndexRange &indexRange, |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 250 | size_t *outStreamingDataSize, |
| 251 | size_t *outMaxAttributeDataSize) const |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 252 | { |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 253 | *outStreamingDataSize = 0; |
| 254 | *outMaxAttributeDataSize = 0; |
| 255 | |
| 256 | ASSERT(mAttributesNeedStreaming.any()); |
| 257 | |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 258 | const auto &attribs = mData.getVertexAttributes(); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 259 | const auto &bindings = mData.getVertexBindings(); |
Jamie Madill | 6de5185 | 2017-04-12 09:53:01 -0400 | [diff] [blame] | 260 | |
| 261 | gl::AttributesMask attribsToStream = (mAttributesNeedStreaming & activeAttributesMask); |
| 262 | |
| 263 | for (auto idx : attribsToStream) |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 264 | { |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 265 | const auto &attrib = attribs[idx]; |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 266 | const auto &binding = bindings[attrib.bindingIndex]; |
| 267 | ASSERT(AttributeNeedsStreaming(attrib, binding)); |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 268 | |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 269 | // If streaming is going to be required, compute the size of the required buffer |
| 270 | // and how much slack space at the beginning of the buffer will be required by determining |
| 271 | // the attribute with the largest data size. |
| 272 | size_t typeSize = ComputeVertexAttributeTypeSize(attrib); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 273 | *outStreamingDataSize += typeSize * ComputeVertexBindingElementCount( |
| 274 | binding, indexRange.vertexCount(), instanceCount); |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 275 | *outMaxAttributeDataSize = std::max(*outMaxAttributeDataSize, typeSize); |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | gl::Error VertexArrayGL::streamAttributes(const gl::AttributesMask &activeAttributesMask, |
Geoff Lang | 3cf12ce | 2015-08-27 14:40:48 -0400 | [diff] [blame] | 280 | GLsizei instanceCount, |
Geoff Lang | 3edfe03 | 2015-09-04 16:38:24 -0400 | [diff] [blame] | 281 | const gl::IndexRange &indexRange) const |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 282 | { |
| 283 | // Sync the vertex attribute state and track what data needs to be streamed |
| 284 | size_t streamingDataSize = 0; |
| 285 | size_t maxAttributeDataSize = 0; |
| 286 | |
Geoff Lang | 3cf12ce | 2015-08-27 14:40:48 -0400 | [diff] [blame] | 287 | computeStreamingAttributeSizes(activeAttributesMask, instanceCount, indexRange, |
| 288 | &streamingDataSize, &maxAttributeDataSize); |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 289 | |
| 290 | if (streamingDataSize == 0) |
| 291 | { |
He Yunchao | acd1898 | 2017-01-04 10:46:42 +0800 | [diff] [blame] | 292 | return gl::NoError(); |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 293 | } |
| 294 | |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 295 | if (mStreamingArrayBuffer == 0) |
| 296 | { |
| 297 | mFunctions->genBuffers(1, &mStreamingArrayBuffer); |
| 298 | mStreamingArrayBufferSize = 0; |
| 299 | } |
| 300 | |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 301 | // If first is greater than zero, a slack space needs to be left at the beginning of the buffer |
| 302 | // so that the same 'first' argument can be passed into the draw call. |
| 303 | const size_t bufferEmptySpace = maxAttributeDataSize * indexRange.start; |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 304 | const size_t requiredBufferSize = streamingDataSize + bufferEmptySpace; |
| 305 | |
| 306 | mStateManager->bindBuffer(GL_ARRAY_BUFFER, mStreamingArrayBuffer); |
| 307 | if (requiredBufferSize > mStreamingArrayBufferSize) |
| 308 | { |
| 309 | mFunctions->bufferData(GL_ARRAY_BUFFER, requiredBufferSize, nullptr, GL_DYNAMIC_DRAW); |
| 310 | mStreamingArrayBufferSize = requiredBufferSize; |
| 311 | } |
| 312 | |
| 313 | // Unmapping a buffer can return GL_FALSE to indicate that the system has corrupted the data |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 314 | // somehow (such as by a screen change), retry writing the data a few times and return |
| 315 | // OUT_OF_MEMORY if that fails. |
| 316 | GLboolean unmapResult = GL_FALSE; |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 317 | size_t unmapRetryAttempts = 5; |
| 318 | while (unmapResult != GL_TRUE && --unmapRetryAttempts > 0) |
| 319 | { |
Geoff Lang | b2ebb5e | 2016-06-08 18:17:55 +0000 | [diff] [blame] | 320 | uint8_t *bufferPointer = MapBufferRangeWithFallback(mFunctions, GL_ARRAY_BUFFER, 0, |
| 321 | requiredBufferSize, GL_MAP_WRITE_BIT); |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 322 | size_t curBufferOffset = bufferEmptySpace; |
| 323 | |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 324 | const auto &attribs = mData.getVertexAttributes(); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 325 | const auto &bindings = mData.getVertexBindings(); |
Jamie Madill | 6de5185 | 2017-04-12 09:53:01 -0400 | [diff] [blame] | 326 | |
| 327 | gl::AttributesMask attribsToStream = (mAttributesNeedStreaming & activeAttributesMask); |
| 328 | |
| 329 | for (auto idx : attribsToStream) |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 330 | { |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 331 | const auto &attrib = attribs[idx]; |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 332 | const auto &binding = bindings[attrib.bindingIndex]; |
| 333 | ASSERT(AttributeNeedsStreaming(attrib, binding)); |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 334 | |
Geoff Lang | 3cf12ce | 2015-08-27 14:40:48 -0400 | [diff] [blame] | 335 | const size_t streamedVertexCount = |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 336 | ComputeVertexBindingElementCount(binding, indexRange.vertexCount(), instanceCount); |
Geoff Lang | 3cf12ce | 2015-08-27 14:40:48 -0400 | [diff] [blame] | 337 | |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 338 | const size_t sourceStride = ComputeVertexAttributeStride(attrib, binding); |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 339 | const size_t destStride = ComputeVertexAttributeTypeSize(attrib); |
| 340 | |
Geoff Lang | 38a24a9 | 2017-02-15 13:53:06 -0500 | [diff] [blame] | 341 | // Vertices do not apply the 'start' offset when the divisor is non-zero even when doing |
| 342 | // a non-instanced draw call |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 343 | const size_t firstIndex = binding.divisor == 0 ? indexRange.start : 0; |
Geoff Lang | 38a24a9 | 2017-02-15 13:53:06 -0500 | [diff] [blame] | 344 | |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 345 | // Attributes using client memory ignore the VERTEX_ATTRIB_BINDING state. |
| 346 | // https://www.opengl.org/registry/specs/ARB/vertex_attrib_binding.txt |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 347 | const uint8_t *inputPointer = reinterpret_cast<const uint8_t *>(attrib.pointer); |
| 348 | |
| 349 | // Pack the data when copying it, user could have supplied a very large stride that |
| 350 | // would cause the buffer to be much larger than needed. |
| 351 | if (destStride == sourceStride) |
Jamie Madill | 8e34494 | 2015-07-09 14:22:07 -0400 | [diff] [blame] | 352 | { |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 353 | // Can copy in one go, the data is packed |
Geoff Lang | 38a24a9 | 2017-02-15 13:53:06 -0500 | [diff] [blame] | 354 | memcpy(bufferPointer + curBufferOffset, inputPointer + (sourceStride * firstIndex), |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 355 | destStride * streamedVertexCount); |
Jamie Madill | 6d51c70 | 2015-08-14 10:38:10 -0400 | [diff] [blame] | 356 | } |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 357 | else |
| 358 | { |
| 359 | // Copy each vertex individually |
Geoff Lang | 6b10ddb | 2015-09-02 15:55:10 -0400 | [diff] [blame] | 360 | for (size_t vertexIdx = 0; vertexIdx < streamedVertexCount; vertexIdx++) |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 361 | { |
Shao | 80957d9 | 2017-02-20 21:25:59 +0800 | [diff] [blame] | 362 | uint8_t *out = bufferPointer + curBufferOffset + (destStride * vertexIdx); |
Geoff Lang | 38a24a9 | 2017-02-15 13:53:06 -0500 | [diff] [blame] | 363 | const uint8_t *in = inputPointer + sourceStride * (vertexIdx + firstIndex); |
Corentin Wallez | 4d5362d | 2015-08-25 11:25:14 -0400 | [diff] [blame] | 364 | memcpy(out, in, destStride); |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | |
| 368 | // Compute where the 0-index vertex would be. |
Geoff Lang | 38a24a9 | 2017-02-15 13:53:06 -0500 | [diff] [blame] | 369 | const size_t vertexStartOffset = curBufferOffset - (firstIndex * destStride); |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 370 | |
Geoff Lang | 2b835a6 | 2015-09-10 15:58:44 -0400 | [diff] [blame] | 371 | if (attrib.pureInteger) |
| 372 | { |
| 373 | ASSERT(!attrib.normalized); |
| 374 | mFunctions->vertexAttribIPointer( |
Corentin Wallez | ca311dd | 2015-12-07 15:07:48 -0500 | [diff] [blame] | 375 | static_cast<GLuint>(idx), attrib.size, attrib.type, |
| 376 | static_cast<GLsizei>(destStride), |
Geoff Lang | 2b835a6 | 2015-09-10 15:58:44 -0400 | [diff] [blame] | 377 | reinterpret_cast<const GLvoid *>(vertexStartOffset)); |
| 378 | } |
| 379 | else |
| 380 | { |
| 381 | mFunctions->vertexAttribPointer( |
Corentin Wallez | ca311dd | 2015-12-07 15:07:48 -0500 | [diff] [blame] | 382 | static_cast<GLuint>(idx), attrib.size, attrib.type, attrib.normalized, |
Geoff Lang | 2b835a6 | 2015-09-10 15:58:44 -0400 | [diff] [blame] | 383 | static_cast<GLsizei>(destStride), |
| 384 | reinterpret_cast<const GLvoid *>(vertexStartOffset)); |
| 385 | } |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 386 | |
| 387 | curBufferOffset += destStride * streamedVertexCount; |
| 388 | |
| 389 | // Mark the applied attribute as dirty by setting an invalid size so that if it doesn't |
| 390 | // need to be streamed later, there is no chance that the caching will skip it. |
| 391 | mAppliedAttributes[idx].size = static_cast<GLuint>(-1); |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | unmapResult = mFunctions->unmapBuffer(GL_ARRAY_BUFFER); |
| 395 | } |
| 396 | |
| 397 | if (unmapResult != GL_TRUE) |
| 398 | { |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 399 | return Error(GL_OUT_OF_MEMORY, "Failed to unmap the client data streaming buffer."); |
Geoff Lang | 7c82bc4 | 2015-03-09 16:18:08 -0400 | [diff] [blame] | 400 | } |
| 401 | |
He Yunchao | acd1898 | 2017-01-04 10:46:42 +0800 | [diff] [blame] | 402 | return NoError(); |
Geoff Lang | ba4c4a8 | 2015-02-24 12:38:46 -0500 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | GLuint VertexArrayGL::getVertexArrayID() const |
| 406 | { |
| 407 | return mVertexArrayID; |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 408 | } |
| 409 | |
Geoff Lang | 294cad9 | 2015-05-26 15:11:23 -0400 | [diff] [blame] | 410 | GLuint VertexArrayGL::getAppliedElementArrayBufferID() const |
| 411 | { |
Jamie Madill | 77a90c2 | 2015-08-11 16:33:17 -0400 | [diff] [blame] | 412 | if (mAppliedElementArrayBuffer.get() == nullptr) |
| 413 | { |
| 414 | return mStreamingElementArrayBuffer; |
| 415 | } |
| 416 | |
| 417 | return GetImplAs<BufferGL>(mAppliedElementArrayBuffer.get())->getBufferID(); |
Geoff Lang | 294cad9 | 2015-05-26 15:11:23 -0400 | [diff] [blame] | 418 | } |
| 419 | |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 420 | void VertexArrayGL::updateNeedsStreaming(size_t attribIndex) |
| 421 | { |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 422 | const auto &attrib = mData.getVertexAttribute(attribIndex); |
| 423 | const auto &binding = mData.getBindingFromAttribIndex(attribIndex); |
| 424 | mAttributesNeedStreaming.set(attribIndex, AttributeNeedsStreaming(attrib, binding)); |
Geoff Lang | f9a6f08 | 2015-01-22 13:32:49 -0500 | [diff] [blame] | 425 | } |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 426 | |
| 427 | void VertexArrayGL::updateAttribEnabled(size_t attribIndex) |
| 428 | { |
| 429 | const VertexAttribute &attrib = mData.getVertexAttribute(attribIndex); |
| 430 | if (mAppliedAttributes[attribIndex].enabled == attrib.enabled) |
| 431 | { |
| 432 | return; |
| 433 | } |
| 434 | |
| 435 | updateNeedsStreaming(attribIndex); |
| 436 | |
| 437 | mStateManager->bindVertexArray(mVertexArrayID, getAppliedElementArrayBufferID()); |
| 438 | if (attrib.enabled) |
| 439 | { |
| 440 | mFunctions->enableVertexAttribArray(static_cast<GLuint>(attribIndex)); |
| 441 | } |
| 442 | else |
| 443 | { |
| 444 | mFunctions->disableVertexAttribArray(static_cast<GLuint>(attribIndex)); |
| 445 | } |
| 446 | mAppliedAttributes[attribIndex].enabled = attrib.enabled; |
| 447 | } |
| 448 | |
| 449 | void VertexArrayGL::updateAttribPointer(size_t attribIndex) |
| 450 | { |
| 451 | const VertexAttribute &attrib = mData.getVertexAttribute(attribIndex); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 452 | ASSERT(attribIndex == attrib.bindingIndex); |
| 453 | |
| 454 | GLuint bindingIndex = attrib.bindingIndex; |
| 455 | const VertexBinding &binding = mData.getVertexBinding(bindingIndex); |
| 456 | |
| 457 | if (mAppliedAttributes[attribIndex] == attrib && mAppliedBindings[bindingIndex] == binding) |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 458 | { |
| 459 | return; |
| 460 | } |
| 461 | |
| 462 | updateNeedsStreaming(attribIndex); |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 463 | |
| 464 | // If we need to stream, defer the attribPointer to the draw call. |
| 465 | if (mAttributesNeedStreaming[attribIndex]) |
| 466 | { |
| 467 | return; |
| 468 | } |
| 469 | |
Shao | 4181bc9 | 2017-03-17 14:55:25 +0800 | [diff] [blame^] | 470 | // Skip the attribute that is disabled and uses a client memory pointer. |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 471 | const Buffer *arrayBuffer = binding.buffer.get(); |
Shao | 4181bc9 | 2017-03-17 14:55:25 +0800 | [diff] [blame^] | 472 | if (arrayBuffer == nullptr) |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 473 | { |
Shao | 4181bc9 | 2017-03-17 14:55:25 +0800 | [diff] [blame^] | 474 | ASSERT(!attrib.enabled); |
| 475 | |
| 476 | // Mark the applied attribute as dirty by setting an invalid size so that if it doesn't |
| 477 | // use a client memory pointer later, there is no chance that the caching will skip it. |
| 478 | mAppliedAttributes[attribIndex].size = static_cast<GLuint>(-1); |
| 479 | return; |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 480 | } |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 481 | |
Shao | 4181bc9 | 2017-03-17 14:55:25 +0800 | [diff] [blame^] | 482 | mStateManager->bindVertexArray(mVertexArrayID, getAppliedElementArrayBufferID()); |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 483 | |
Shao | 4181bc9 | 2017-03-17 14:55:25 +0800 | [diff] [blame^] | 484 | // Since ANGLE always uses a non-zero VAO, we cannot use a client memory pointer on it: |
| 485 | // [OpenGL ES 3.0.2] Section 2.8 page 24: |
| 486 | // An INVALID_OPERATION error is generated when a non-zero vertex array object is bound, |
| 487 | // zero is bound to the ARRAY_BUFFER buffer object binding point, and the pointer argument |
| 488 | // is not NULL. |
| 489 | ASSERT(arrayBuffer != nullptr); |
| 490 | const BufferGL *arrayBufferGL = GetImplAs<BufferGL>(arrayBuffer); |
| 491 | mStateManager->bindBuffer(GL_ARRAY_BUFFER, arrayBufferGL->getBufferID()); |
| 492 | const GLvoid *inputPointer = |
| 493 | reinterpret_cast<const uint8_t *>(binding.offset + attrib.relativeOffset); |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 494 | |
| 495 | if (attrib.pureInteger) |
| 496 | { |
| 497 | mFunctions->vertexAttribIPointer(static_cast<GLuint>(attribIndex), attrib.size, attrib.type, |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 498 | binding.stride, inputPointer); |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 499 | } |
| 500 | else |
| 501 | { |
| 502 | mFunctions->vertexAttribPointer(static_cast<GLuint>(attribIndex), attrib.size, attrib.type, |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 503 | attrib.normalized, binding.stride, inputPointer); |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 504 | } |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 505 | mAppliedAttributes[attribIndex].size = attrib.size; |
| 506 | mAppliedAttributes[attribIndex].type = attrib.type; |
| 507 | mAppliedAttributes[attribIndex].normalized = attrib.normalized; |
| 508 | mAppliedAttributes[attribIndex].pureInteger = attrib.pureInteger; |
| 509 | mAppliedAttributes[attribIndex].pointer = attrib.pointer; |
| 510 | mAppliedAttributes[attribIndex].relativeOffset = attrib.relativeOffset; |
| 511 | mAppliedAttributes[attribIndex].vertexAttribArrayStride = attrib.vertexAttribArrayStride; |
| 512 | |
| 513 | mAppliedBindings[bindingIndex].stride = binding.stride; |
| 514 | mAppliedBindings[bindingIndex].offset = binding.offset; |
Shao | 4181bc9 | 2017-03-17 14:55:25 +0800 | [diff] [blame^] | 515 | mAppliedBindings[bindingIndex].buffer = binding.buffer; |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | void VertexArrayGL::updateAttribDivisor(size_t attribIndex) |
| 519 | { |
| 520 | ASSERT(attribIndex == mData.getBindingIndexFromAttribIndex(attribIndex)); |
| 521 | |
| 522 | const VertexBinding &binding = mData.getVertexBinding(attribIndex); |
| 523 | if (mAppliedBindings[attribIndex].divisor != binding.divisor) |
| 524 | { |
| 525 | mStateManager->bindVertexArray(mVertexArrayID, getAppliedElementArrayBufferID()); |
| 526 | mFunctions->vertexAttribDivisor(static_cast<GLuint>(attribIndex), binding.divisor); |
| 527 | |
| 528 | mAppliedBindings[attribIndex].divisor = binding.divisor; |
| 529 | } |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 530 | } |
| 531 | |
Jamie Madill | dd43e6c | 2017-03-24 14:18:49 -0400 | [diff] [blame] | 532 | void VertexArrayGL::syncState(ContextImpl *contextImpl, const VertexArray::DirtyBits &dirtyBits) |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 533 | { |
Jamie Madill | 6de5185 | 2017-04-12 09:53:01 -0400 | [diff] [blame] | 534 | for (size_t dirtyBit : dirtyBits) |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 535 | { |
| 536 | if (dirtyBit == VertexArray::DIRTY_BIT_ELEMENT_ARRAY_BUFFER) |
| 537 | { |
| 538 | // TODO(jmadill): Element array buffer bindings |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 539 | continue; |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 540 | } |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 541 | |
| 542 | size_t index = VertexArray::GetAttribIndex(dirtyBit); |
| 543 | if (dirtyBit >= VertexArray::DIRTY_BIT_ATTRIB_0_ENABLED && |
| 544 | dirtyBit < VertexArray::DIRTY_BIT_ATTRIB_MAX_ENABLED) |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 545 | { |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 546 | updateAttribEnabled(index); |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 547 | } |
| 548 | else if (dirtyBit >= VertexArray::DIRTY_BIT_ATTRIB_0_POINTER && |
| 549 | dirtyBit < VertexArray::DIRTY_BIT_ATTRIB_MAX_POINTER) |
| 550 | { |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 551 | updateAttribPointer(index); |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 552 | } |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 553 | else if (dirtyBit >= VertexArray::DIRTY_BIT_ATTRIB_0_FORMAT && |
| 554 | dirtyBit < VertexArray::DIRTY_BIT_BINDING_MAX_BUFFER) |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 555 | { |
Jiawei-Shao | 2597fb6 | 2016-12-09 16:38:02 +0800 | [diff] [blame] | 556 | // TODO(jiawei.shao@intel.com): Vertex Attrib Bindings |
| 557 | ASSERT(index == mData.getBindingIndexFromAttribIndex(index)); |
| 558 | } |
| 559 | else if (dirtyBit >= VertexArray::DIRTY_BIT_BINDING_0_DIVISOR && |
| 560 | dirtyBit < VertexArray::DIRTY_BIT_BINDING_MAX_DIVISOR) |
| 561 | { |
| 562 | updateAttribDivisor(index); |
Jamie Madill | 0b9e903 | 2015-08-17 11:51:52 +0000 | [diff] [blame] | 563 | } |
| 564 | else |
| 565 | UNREACHABLE(); |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | } // rx |