Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: gpu/command_buffer/client/vertex_array_object_manager.cc

Issue 702493002: PepperGL: Enable client side arrays support. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 #if defined(__native_client__) && !defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS)
12 #define GLES2_SUPPORT_CLIENT_SIDE_ARRAYS
13 #endif
14
15 namespace gpu { 11 namespace gpu {
16 namespace gles2 { 12 namespace gles2 {
17 13
18 #if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS)
19
20 static GLsizei RoundUpToMultipleOf4(GLsizei size) { 14 static GLsizei RoundUpToMultipleOf4(GLsizei size) {
21 return (size + 3) & ~3; 15 return (size + 3) & ~3;
22 } 16 }
23 17
24 #endif // defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS)
25
26 // A 32-bit and 64-bit compatible way of converting a pointer to a GLuint. 18 // A 32-bit and 64-bit compatible way of converting a pointer to a GLuint.
27 static GLuint ToGLuint(const void* ptr) { 19 static GLuint ToGLuint(const void* ptr) {
28 return static_cast<GLuint>(reinterpret_cast<size_t>(ptr)); 20 return static_cast<GLuint>(reinterpret_cast<size_t>(ptr));
29 } 21 }
30 22
31 // This class tracks VertexAttribPointers and helps emulate client side buffers. 23 // This class tracks VertexAttribPointers and helps emulate client side buffers.
32 // 24 //
33 // The way client side buffers work is we shadow all the Vertex Attribs so we 25 // The way client side buffers work is we shadow all the Vertex Attribs so we
34 // know which ones are pointing to client side buffers. 26 // know which ones are pointing to client side buffers.
35 // 27 //
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 if (index < vertex_attribs_.size()) { 314 if (index < vertex_attribs_.size()) {
323 const VertexAttrib* attrib = &vertex_attribs_[index]; 315 const VertexAttrib* attrib = &vertex_attribs_[index];
324 return attrib; 316 return attrib;
325 } 317 }
326 return NULL; 318 return NULL;
327 } 319 }
328 320
329 VertexArrayObjectManager::VertexArrayObjectManager( 321 VertexArrayObjectManager::VertexArrayObjectManager(
330 GLuint max_vertex_attribs, 322 GLuint max_vertex_attribs,
331 GLuint array_buffer_id, 323 GLuint array_buffer_id,
332 GLuint element_array_buffer_id) 324 GLuint element_array_buffer_id,
325 bool support_client_side_arrays)
333 : max_vertex_attribs_(max_vertex_attribs), 326 : max_vertex_attribs_(max_vertex_attribs),
334 array_buffer_id_(array_buffer_id), 327 array_buffer_id_(array_buffer_id),
335 array_buffer_size_(0), 328 array_buffer_size_(0),
336 array_buffer_offset_(0), 329 array_buffer_offset_(0),
337 element_array_buffer_id_(element_array_buffer_id), 330 element_array_buffer_id_(element_array_buffer_id),
338 element_array_buffer_size_(0), 331 element_array_buffer_size_(0),
339 collection_buffer_size_(0), 332 collection_buffer_size_(0),
340 default_vertex_array_object_(new VertexArrayObject(max_vertex_attribs)), 333 default_vertex_array_object_(new VertexArrayObject(max_vertex_attribs)),
341 bound_vertex_array_object_(default_vertex_array_object_) { 334 bound_vertex_array_object_(default_vertex_array_object_),
335 support_client_side_arrays_(support_client_side_arrays) {
342 } 336 }
343 337
344 VertexArrayObjectManager::~VertexArrayObjectManager() { 338 VertexArrayObjectManager::~VertexArrayObjectManager() {
345 for (VertexArrayObjectMap::iterator it = vertex_array_objects_.begin(); 339 for (VertexArrayObjectMap::iterator it = vertex_array_objects_.begin();
346 it != vertex_array_objects_.end(); ++it) { 340 it != vertex_array_objects_.end(); ++it) {
347 delete it->second; 341 delete it->second;
348 } 342 }
349 delete default_vertex_array_object_; 343 delete default_vertex_array_object_;
350 } 344 }
351 345
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 470
477 // Returns true if buffers were setup. 471 // Returns true if buffers were setup.
478 bool VertexArrayObjectManager::SetupSimulatedClientSideBuffers( 472 bool VertexArrayObjectManager::SetupSimulatedClientSideBuffers(
479 const char* function_name, 473 const char* function_name,
480 GLES2Implementation* gl, 474 GLES2Implementation* gl,
481 GLES2CmdHelper* gl_helper, 475 GLES2CmdHelper* gl_helper,
482 GLsizei num_elements, 476 GLsizei num_elements,
483 GLsizei primcount, 477 GLsizei primcount,
484 bool* simulated) { 478 bool* simulated) {
485 *simulated = false; 479 *simulated = false;
486 #if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) 480 if (!support_client_side_arrays_)
481 return true;
487 if (!bound_vertex_array_object_->HaveEnabledClientSideBuffers()) { 482 if (!bound_vertex_array_object_->HaveEnabledClientSideBuffers()) {
488 return true; 483 return true;
489 } 484 }
490 if (!IsDefaultVAOBound()) { 485 if (!IsDefaultVAOBound()) {
491 gl->SetGLError( 486 gl->SetGLError(
492 GL_INVALID_OPERATION, function_name, 487 GL_INVALID_OPERATION, function_name,
493 "client side arrays not allowed with vertex array object"); 488 "client side arrays not allowed with vertex array object");
494 return false; 489 return false;
495 } 490 }
496 *simulated = true; 491 *simulated = true;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 gl->BufferSubDataHelper( 525 gl->BufferSubDataHelper(
531 GL_ARRAY_BUFFER, array_buffer_offset_, bytes_collected, 526 GL_ARRAY_BUFFER, array_buffer_offset_, bytes_collected,
532 collection_buffer_.get()); 527 collection_buffer_.get());
533 gl_helper->VertexAttribPointer( 528 gl_helper->VertexAttribPointer(
534 ii, attrib.size(), attrib.type(), attrib.normalized(), 0, 529 ii, attrib.size(), attrib.type(), attrib.normalized(), 0,
535 array_buffer_offset_); 530 array_buffer_offset_);
536 array_buffer_offset_ += RoundUpToMultipleOf4(bytes_collected); 531 array_buffer_offset_ += RoundUpToMultipleOf4(bytes_collected);
537 DCHECK_LE(array_buffer_offset_, array_buffer_size_); 532 DCHECK_LE(array_buffer_offset_, array_buffer_size_);
538 } 533 }
539 } 534 }
540 #endif // defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS)
541 return true; 535 return true;
542 } 536 }
543 537
544 // Copies in indices to the service and returns the highest index accessed + 1 538 // Copies in indices to the service and returns the highest index accessed + 1
545 bool VertexArrayObjectManager::SetupSimulatedIndexAndClientSideBuffers( 539 bool VertexArrayObjectManager::SetupSimulatedIndexAndClientSideBuffers(
546 const char* function_name, 540 const char* function_name,
547 GLES2Implementation* gl, 541 GLES2Implementation* gl,
548 GLES2CmdHelper* gl_helper, 542 GLES2CmdHelper* gl_helper,
549 GLsizei count, 543 GLsizei count,
550 GLenum type, 544 GLenum type,
551 GLsizei primcount, 545 GLsizei primcount,
552 const void* indices, 546 const void* indices,
553 GLuint* offset, 547 GLuint* offset,
554 bool* simulated) { 548 bool* simulated) {
555 *simulated = false; 549 *simulated = false;
556 *offset = ToGLuint(indices); 550 *offset = ToGLuint(indices);
557 #if defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS) 551 if (!support_client_side_arrays_)
552 return true;
558 GLsizei num_elements = 0; 553 GLsizei num_elements = 0;
559 if (bound_vertex_array_object_->bound_element_array_buffer() == 0) { 554 if (bound_vertex_array_object_->bound_element_array_buffer() == 0) {
560 *simulated = true; 555 *simulated = true;
561 *offset = 0; 556 *offset = 0;
562 GLsizei max_index = -1; 557 GLsizei max_index = -1;
563 switch (type) { 558 switch (type) {
564 case GL_UNSIGNED_BYTE: { 559 case GL_UNSIGNED_BYTE: {
565 const uint8* src = static_cast<const uint8*>(indices); 560 const uint8* src = static_cast<const uint8*>(indices);
566 for (GLsizei ii = 0; ii < count; ++ii) { 561 for (GLsizei ii = 0; ii < count; ++ii) {
567 if (src[ii] > max_index) { 562 if (src[ii] > max_index) {
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 num_elements = gl->GetMaxValueInBufferCHROMIUMHelper( 618 num_elements = gl->GetMaxValueInBufferCHROMIUMHelper(
624 bound_vertex_array_object_->bound_element_array_buffer(), 619 bound_vertex_array_object_->bound_element_array_buffer(),
625 count, type, ToGLuint(indices)) + 1; 620 count, type, ToGLuint(indices)) + 1;
626 } 621 }
627 622
628 bool simulated_client_side_buffers = false; 623 bool simulated_client_side_buffers = false;
629 SetupSimulatedClientSideBuffers( 624 SetupSimulatedClientSideBuffers(
630 function_name, gl, gl_helper, num_elements, primcount, 625 function_name, gl, gl_helper, num_elements, primcount,
631 &simulated_client_side_buffers); 626 &simulated_client_side_buffers);
632 *simulated = *simulated || simulated_client_side_buffers; 627 *simulated = *simulated || simulated_client_side_buffers;
633 #endif // defined(GLES2_SUPPORT_CLIENT_SIDE_ARRAYS)
634 return true; 628 return true;
635 } 629 }
636 630
637 } // namespace gles2 631 } // namespace gles2
638 } // namespace gpu 632 } // namespace gpu
639 633
640 634
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698