OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "gpu/command_buffer/client/vertex_array_object_manager.h" | 5 #include "gpu/command_buffer/client/vertex_array_object_manager.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "gpu/command_buffer/client/gles2_cmd_helper.h" | 8 #include "gpu/command_buffer/client/gles2_cmd_helper.h" |
9 #include "gpu/command_buffer/client/gles2_implementation.h" | 9 #include "gpu/command_buffer/client/gles2_implementation.h" |
10 | 10 |
(...skipping 29 matching lines...) Expand all Loading... |
40 class VertexAttrib { | 40 class VertexAttrib { |
41 public: | 41 public: |
42 VertexAttrib() | 42 VertexAttrib() |
43 : enabled_(false), | 43 : enabled_(false), |
44 buffer_id_(0), | 44 buffer_id_(0), |
45 size_(4), | 45 size_(4), |
46 type_(GL_FLOAT), | 46 type_(GL_FLOAT), |
47 normalized_(GL_FALSE), | 47 normalized_(GL_FALSE), |
48 pointer_(NULL), | 48 pointer_(NULL), |
49 gl_stride_(0), | 49 gl_stride_(0), |
50 divisor_(0) { | 50 divisor_(0), |
| 51 integer_(GL_FALSE) { |
51 } | 52 } |
52 | 53 |
53 bool enabled() const { | 54 bool enabled() const { |
54 return enabled_; | 55 return enabled_; |
55 } | 56 } |
56 | 57 |
57 void set_enabled(bool enabled) { | 58 void set_enabled(bool enabled) { |
58 enabled_ = enabled; | 59 enabled_ = enabled; |
59 } | 60 } |
60 | 61 |
(...skipping 26 matching lines...) Expand all Loading... |
87 } | 88 } |
88 | 89 |
89 bool IsClientSide() const { | 90 bool IsClientSide() const { |
90 return buffer_id_ == 0; | 91 return buffer_id_ == 0; |
91 } | 92 } |
92 | 93 |
93 GLuint divisor() const { | 94 GLuint divisor() const { |
94 return divisor_; | 95 return divisor_; |
95 } | 96 } |
96 | 97 |
| 98 GLboolean integer() const { |
| 99 return integer_; |
| 100 } |
| 101 |
97 void SetInfo( | 102 void SetInfo( |
98 GLuint buffer_id, | 103 GLuint buffer_id, |
99 GLint size, | 104 GLint size, |
100 GLenum type, | 105 GLenum type, |
101 GLboolean normalized, | 106 GLboolean normalized, |
102 GLsizei gl_stride, | 107 GLsizei gl_stride, |
103 const GLvoid* pointer) { | 108 const GLvoid* pointer, |
| 109 GLboolean integer) { |
104 buffer_id_ = buffer_id; | 110 buffer_id_ = buffer_id; |
105 size_ = size; | 111 size_ = size; |
106 type_ = type; | 112 type_ = type; |
107 normalized_ = normalized; | 113 normalized_ = normalized; |
108 gl_stride_ = gl_stride; | 114 gl_stride_ = gl_stride; |
109 pointer_ = pointer; | 115 pointer_ = pointer; |
| 116 integer_ = integer; |
110 } | 117 } |
111 | 118 |
112 void SetDivisor(GLuint divisor) { | 119 void SetDivisor(GLuint divisor) { |
113 divisor_ = divisor; | 120 divisor_ = divisor; |
114 } | 121 } |
115 | 122 |
116 private: | 123 private: |
117 // Whether or not this attribute is enabled. | 124 // Whether or not this attribute is enabled. |
118 bool enabled_; | 125 bool enabled_; |
119 | 126 |
(...skipping 11 matching lines...) Expand all Loading... |
131 | 138 |
132 // The pointer/offset into the buffer. | 139 // The pointer/offset into the buffer. |
133 const GLvoid* pointer_; | 140 const GLvoid* pointer_; |
134 | 141 |
135 // The stride that will be used to access the buffer. This is the bogus GL | 142 // The stride that will be used to access the buffer. This is the bogus GL |
136 // stride where 0 = compute the stride based on size and type. | 143 // stride where 0 = compute the stride based on size and type. |
137 GLsizei gl_stride_; | 144 GLsizei gl_stride_; |
138 | 145 |
139 // Divisor, for geometry instancing. | 146 // Divisor, for geometry instancing. |
140 GLuint divisor_; | 147 GLuint divisor_; |
| 148 |
| 149 GLboolean integer_; |
141 }; | 150 }; |
142 | 151 |
143 typedef std::vector<VertexAttrib> VertexAttribs; | 152 typedef std::vector<VertexAttrib> VertexAttribs; |
144 | 153 |
145 explicit VertexArrayObject(GLuint max_vertex_attribs); | 154 explicit VertexArrayObject(GLuint max_vertex_attribs); |
146 | 155 |
147 void UnbindBuffer(GLuint id); | 156 void UnbindBuffer(GLuint id); |
148 | 157 |
149 bool BindElementArray(GLuint id); | 158 bool BindElementArray(GLuint id); |
150 | 159 |
151 bool HaveEnabledClientSideBuffers() const; | 160 bool HaveEnabledClientSideBuffers() const; |
152 | 161 |
153 void SetAttribEnable(GLuint index, bool enabled); | 162 void SetAttribEnable(GLuint index, bool enabled); |
154 | 163 |
155 void SetAttribPointer( | 164 void SetAttribPointer( |
156 GLuint buffer_id, | 165 GLuint buffer_id, |
157 GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, | 166 GLuint index, GLint size, GLenum type, GLboolean normalized, GLsizei stride, |
158 const void* ptr); | 167 const void* ptr, GLboolean integer); |
159 | 168 |
160 bool GetVertexAttrib( | 169 bool GetVertexAttrib( |
161 GLuint index, GLenum pname, uint32* param) const; | 170 GLuint index, GLenum pname, uint32* param) const; |
162 | 171 |
163 void SetAttribDivisor(GLuint index, GLuint divisor); | 172 void SetAttribDivisor(GLuint index, GLuint divisor); |
164 | 173 |
165 bool GetAttribPointer(GLuint index, GLenum pname, void** ptr) const; | 174 bool GetAttribPointer(GLuint index, GLenum pname, void** ptr) const; |
166 | 175 |
167 const VertexAttribs& vertex_attribs() const { | 176 const VertexAttribs& vertex_attribs() const { |
168 return vertex_attribs_; | 177 return vertex_attribs_; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 } | 242 } |
234 } | 243 } |
235 | 244 |
236 void VertexArrayObject::SetAttribPointer( | 245 void VertexArrayObject::SetAttribPointer( |
237 GLuint buffer_id, | 246 GLuint buffer_id, |
238 GLuint index, | 247 GLuint index, |
239 GLint size, | 248 GLint size, |
240 GLenum type, | 249 GLenum type, |
241 GLboolean normalized, | 250 GLboolean normalized, |
242 GLsizei stride, | 251 GLsizei stride, |
243 const void* ptr) { | 252 const void* ptr, |
| 253 GLboolean integer) { |
244 if (index < vertex_attribs_.size()) { | 254 if (index < vertex_attribs_.size()) { |
245 VertexAttrib& attrib = vertex_attribs_[index]; | 255 VertexAttrib& attrib = vertex_attribs_[index]; |
246 if (attrib.IsClientSide() && attrib.enabled()) { | 256 if (attrib.IsClientSide() && attrib.enabled()) { |
247 --num_client_side_pointers_enabled_; | 257 --num_client_side_pointers_enabled_; |
248 DCHECK_GE(num_client_side_pointers_enabled_, 0); | 258 DCHECK_GE(num_client_side_pointers_enabled_, 0); |
249 } | 259 } |
250 | 260 |
251 attrib.SetInfo(buffer_id, size, type, normalized, stride, ptr); | 261 attrib.SetInfo(buffer_id, size, type, normalized, stride, ptr, integer); |
252 | 262 |
253 if (attrib.IsClientSide() && attrib.enabled()) { | 263 if (attrib.IsClientSide() && attrib.enabled()) { |
254 ++num_client_side_pointers_enabled_; | 264 ++num_client_side_pointers_enabled_; |
255 } | 265 } |
256 } | 266 } |
257 } | 267 } |
258 | 268 |
259 bool VertexArrayObject::GetVertexAttrib( | 269 bool VertexArrayObject::GetVertexAttrib( |
260 GLuint index, GLenum pname, uint32* param) const { | 270 GLuint index, GLenum pname, uint32* param) const { |
261 const VertexAttrib* attrib = GetAttrib(index); | 271 const VertexAttrib* attrib = GetAttrib(index); |
(...skipping 14 matching lines...) Expand all Loading... |
276 case GL_VERTEX_ATTRIB_ARRAY_STRIDE: | 286 case GL_VERTEX_ATTRIB_ARRAY_STRIDE: |
277 *param = attrib->stride(); | 287 *param = attrib->stride(); |
278 break; | 288 break; |
279 case GL_VERTEX_ATTRIB_ARRAY_TYPE: | 289 case GL_VERTEX_ATTRIB_ARRAY_TYPE: |
280 *param = attrib->type(); | 290 *param = attrib->type(); |
281 break; | 291 break; |
282 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: | 292 case GL_VERTEX_ATTRIB_ARRAY_NORMALIZED: |
283 *param = attrib->normalized(); | 293 *param = attrib->normalized(); |
284 break; | 294 break; |
285 case GL_VERTEX_ATTRIB_ARRAY_INTEGER: | 295 case GL_VERTEX_ATTRIB_ARRAY_INTEGER: |
286 // TODO(zmo): cache this on the client side. | 296 *param = attrib->integer(); |
287 return false; | 297 break; |
288 default: | 298 default: |
289 return false; // pass through to service side. | 299 return false; // pass through to service side. |
290 } | 300 } |
291 return true; | 301 return true; |
292 } | 302 } |
293 | 303 |
294 void VertexArrayObject::SetAttribDivisor(GLuint index, GLuint divisor) { | 304 void VertexArrayObject::SetAttribDivisor(GLuint index, GLuint divisor) { |
295 if (index < vertex_attribs_.size()) { | 305 if (index < vertex_attribs_.size()) { |
296 VertexAttrib& attrib = vertex_attribs_[index]; | 306 VertexAttrib& attrib = vertex_attribs_[index]; |
297 attrib.SetDivisor(divisor); | 307 attrib.SetDivisor(divisor); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 return bound_vertex_array_object_->GetAttribPointer(index, pname, ptr); | 434 return bound_vertex_array_object_->GetAttribPointer(index, pname, ptr); |
425 } | 435 } |
426 | 436 |
427 bool VertexArrayObjectManager::SetAttribPointer( | 437 bool VertexArrayObjectManager::SetAttribPointer( |
428 GLuint buffer_id, | 438 GLuint buffer_id, |
429 GLuint index, | 439 GLuint index, |
430 GLint size, | 440 GLint size, |
431 GLenum type, | 441 GLenum type, |
432 GLboolean normalized, | 442 GLboolean normalized, |
433 GLsizei stride, | 443 GLsizei stride, |
434 const void* ptr) { | 444 const void* ptr, |
| 445 GLboolean integer) { |
435 // Client side arrays are not allowed in vaos. | 446 // Client side arrays are not allowed in vaos. |
436 if (buffer_id == 0 && !IsDefaultVAOBound()) { | 447 if (buffer_id == 0 && !IsDefaultVAOBound()) { |
437 return false; | 448 return false; |
438 } | 449 } |
439 bound_vertex_array_object_->SetAttribPointer( | 450 bound_vertex_array_object_->SetAttribPointer( |
440 buffer_id, index, size, type, normalized, stride, ptr); | 451 buffer_id, index, size, type, normalized, stride, ptr, integer); |
441 return true; | 452 return true; |
442 } | 453 } |
443 | 454 |
444 void VertexArrayObjectManager::SetAttribDivisor(GLuint index, GLuint divisor) { | 455 void VertexArrayObjectManager::SetAttribDivisor(GLuint index, GLuint divisor) { |
445 bound_vertex_array_object_->SetAttribDivisor(index, divisor); | 456 bound_vertex_array_object_->SetAttribDivisor(index, divisor); |
446 } | 457 } |
447 | 458 |
448 // Collects the data into the collection buffer and returns the number of | 459 // Collects the data into the collection buffer and returns the number of |
449 // bytes collected. | 460 // bytes collected. |
450 GLsizei VertexArrayObjectManager::CollectData( | 461 GLsizei VertexArrayObjectManager::CollectData( |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 function_name, gl, gl_helper, num_elements, primcount, | 638 function_name, gl, gl_helper, num_elements, primcount, |
628 &simulated_client_side_buffers); | 639 &simulated_client_side_buffers); |
629 *simulated = *simulated || simulated_client_side_buffers; | 640 *simulated = *simulated || simulated_client_side_buffers; |
630 return true; | 641 return true; |
631 } | 642 } |
632 | 643 |
633 } // namespace gles2 | 644 } // namespace gles2 |
634 } // namespace gpu | 645 } // namespace gpu |
635 | 646 |
636 | 647 |
OLD | NEW |