OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "modules/webgl/WebGLVertexArrayObjectBase.h" | 5 #include "modules/webgl/WebGLVertexArrayObjectBase.h" |
6 | 6 |
7 #include "modules/webgl/WebGLRenderingContextBase.h" | 7 #include "modules/webgl/WebGLRenderingContextBase.h" |
8 | 8 |
9 namespace blink { | 9 namespace blink { |
10 | 10 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 WebGLVertexArrayObjectBase::VertexAttribState* WebGLVertexArrayObjectBase::getVe
rtexAttribState(size_t index) | 81 WebGLVertexArrayObjectBase::VertexAttribState* WebGLVertexArrayObjectBase::getVe
rtexAttribState(size_t index) |
82 { | 82 { |
83 ASSERT(index < context()->maxVertexAttribs()); | 83 ASSERT(index < context()->maxVertexAttribs()); |
84 // Lazily create the vertex attribute states. | 84 // Lazily create the vertex attribute states. |
85 for (size_t i = m_vertexAttribState.size(); i <= index; i++) | 85 for (size_t i = m_vertexAttribState.size(); i <= index; i++) |
86 m_vertexAttribState.append(new VertexAttribState); | 86 m_vertexAttribState.append(new VertexAttribState); |
87 return m_vertexAttribState[index].get(); | 87 return m_vertexAttribState[index].get(); |
88 } | 88 } |
89 | 89 |
90 void WebGLVertexArrayObjectBase::setVertexAttribState( | 90 void WebGLVertexArrayObjectBase::setVertexAttribState( |
91 GLuint index, GLsizei bytesPerElement, GLint size, GLenum type, GLboolean no
rmalized, GLsizei stride, GLintptr offset, WebGLBuffer* buffer) | 91 GLuint index, WebGLBuffer* buffer) |
92 { | 92 { |
93 GLsizei validatedStride = stride ? stride : bytesPerElement; | |
94 VertexAttribState* state = getVertexAttribState(index); | 93 VertexAttribState* state = getVertexAttribState(index); |
95 | 94 |
96 if (buffer) | 95 if (buffer) |
97 buffer->onAttached(); | 96 buffer->onAttached(); |
98 if (state->bufferBinding) | 97 if (state->bufferBinding) |
99 state->bufferBinding->onDetached(context()->webContext()); | 98 state->bufferBinding->onDetached(context()->webContext()); |
100 | 99 |
101 state->bufferBinding = buffer; | 100 state->bufferBinding = buffer; |
102 state->bytesPerElement = bytesPerElement; | |
103 state->size = size; | |
104 state->type = type; | |
105 state->normalized = normalized; | |
106 state->stride = validatedStride; | |
107 state->originalStride = stride; | |
108 state->offset = offset; | |
109 } | 101 } |
110 | 102 |
111 void WebGLVertexArrayObjectBase::unbindBuffer(WebGLBuffer* buffer) | 103 void WebGLVertexArrayObjectBase::unbindBuffer(WebGLBuffer* buffer) |
112 { | 104 { |
113 if (m_boundElementArrayBuffer == buffer) { | 105 if (m_boundElementArrayBuffer == buffer) { |
114 m_boundElementArrayBuffer->onDetached(context()->webContext()); | 106 m_boundElementArrayBuffer->onDetached(context()->webContext()); |
115 m_boundElementArrayBuffer = nullptr; | 107 m_boundElementArrayBuffer = nullptr; |
116 } | 108 } |
117 | 109 |
118 for (size_t i = 0; i < m_vertexAttribState.size(); ++i) { | 110 for (size_t i = 0; i < m_vertexAttribState.size(); ++i) { |
119 VertexAttribState* state = m_vertexAttribState[i]; | 111 VertexAttribState* state = m_vertexAttribState[i]; |
120 if (state->bufferBinding == buffer) { | 112 if (state->bufferBinding == buffer) { |
121 buffer->onDetached(context()->webContext()); | 113 buffer->onDetached(context()->webContext()); |
122 state->bufferBinding = nullptr; | 114 state->bufferBinding = nullptr; |
123 } | 115 } |
124 } | 116 } |
125 } | 117 } |
126 | 118 |
127 void WebGLVertexArrayObjectBase::setVertexAttribDivisor(GLuint index, GLuint div
isor) | |
128 { | |
129 VertexAttribState* state = getVertexAttribState(index); | |
130 state->divisor = divisor; | |
131 } | |
132 | |
133 DEFINE_TRACE(WebGLVertexArrayObjectBase::VertexAttribState) | 119 DEFINE_TRACE(WebGLVertexArrayObjectBase::VertexAttribState) |
134 { | 120 { |
135 visitor->trace(bufferBinding); | 121 visitor->trace(bufferBinding); |
136 } | 122 } |
137 | 123 |
138 DEFINE_TRACE(WebGLVertexArrayObjectBase) | 124 DEFINE_TRACE(WebGLVertexArrayObjectBase) |
139 { | 125 { |
140 visitor->trace(m_boundElementArrayBuffer); | 126 visitor->trace(m_boundElementArrayBuffer); |
141 visitor->trace(m_vertexAttribState); | 127 visitor->trace(m_vertexAttribState); |
142 WebGLContextObject::trace(visitor); | 128 WebGLContextObject::trace(visitor); |
143 } | 129 } |
144 | 130 |
145 } // namespace blink | 131 } // namespace blink |
OLD | NEW |