| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2009, Google Inc. | 2 * Copyright 2009, Google Inc. |
| 3 * All rights reserved. | 3 * All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 { UByteNField::GetApparentClass(), UByteNField::Create, | 93 { UByteNField::GetApparentClass(), UByteNField::Create, |
| 94 UByteNField::kRequiredComponentMultiple, }, | 94 UByteNField::kRequiredComponentMultiple, }, |
| 95 }; | 95 }; |
| 96 | 96 |
| 97 } // anonymouse namespace. | 97 } // anonymouse namespace. |
| 98 | 98 |
| 99 // Buffer --------------- | 99 // Buffer --------------- |
| 100 Buffer::Buffer(ServiceLocator* service_locator) | 100 Buffer::Buffer(ServiceLocator* service_locator) |
| 101 : NamedObject(service_locator), | 101 : NamedObject(service_locator), |
| 102 features_(service_locator->GetService<Features>()), | 102 features_(service_locator->GetService<Features>()), |
| 103 access_mode_(NONE), | |
| 104 field_change_count_(0), | 103 field_change_count_(0), |
| 105 total_components_(0), | 104 total_components_(0), |
| 106 stride_(0), | 105 stride_(0), |
| 107 num_elements_(0), | 106 num_elements_(0), |
| 107 access_mode_(NONE), |
| 108 lock_count_(0) { | 108 lock_count_(0) { |
| 109 } | 109 } |
| 110 | 110 |
| 111 Buffer::~Buffer() { | 111 Buffer::~Buffer() { |
| 112 AdjustBufferMemoryInfo(false); | 112 AdjustBufferMemoryInfo(false); |
| 113 for (unsigned ii = 0; ii < fields_.size(); ++ii) { | 113 for (unsigned ii = 0; ii < fields_.size(); ++ii) { |
| 114 if (!fields_[ii].IsNull()) { | 114 if (!fields_[ii].IsNull()) { |
| 115 fields_[ii]->ClearBuffer(); | 115 fields_[ii]->ClearBuffer(); |
| 116 } | 116 } |
| 117 } | 117 } |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 int32 num_elements = stream.ReadLittleEndianInt32(); | 467 int32 num_elements = stream.ReadLittleEndianInt32(); |
| 468 if (!AllocateElements(num_elements)) { | 468 if (!AllocateElements(num_elements)) { |
| 469 O3D_ERROR(service_locator()) << "could not allocate buffer elements"; | 469 O3D_ERROR(service_locator()) << "could not allocate buffer elements"; |
| 470 return false; | 470 return false; |
| 471 } | 471 } |
| 472 | 472 |
| 473 { | 473 { |
| 474 // Lock before reading in all the fields to avoid locking/unlocking | 474 // Lock before reading in all the fields to avoid locking/unlocking |
| 475 // for each field which would be slower | 475 // for each field which would be slower |
| 476 o3d::BufferLockHelper helper(this); | 476 o3d::BufferLockHelper helper(this); |
| 477 void *buffer_data = helper.GetData(o3d::Buffer::WRITE_ONLY); | 477 helper.GetData(o3d::Buffer::WRITE_ONLY); |
| 478 | 478 |
| 479 // Read each field | 479 // Read each field |
| 480 for (int32 ff = 0; ff < num_fields; ++ff) { | 480 for (int32 ff = 0; ff < num_fields; ++ff) { |
| 481 Field *field = fields()[ff]; | 481 Field *field = fields()[ff]; |
| 482 if (!field->SetFromMemoryStream(&stream)) { | 482 if (!field->SetFromMemoryStream(&stream)) { |
| 483 O3D_ERROR(service_locator()) << | 483 O3D_ERROR(service_locator()) << |
| 484 "unexpected end of buffer field data"; | 484 "unexpected end of buffer field data"; |
| 485 return false; | 485 return false; |
| 486 } | 486 } |
| 487 } | 487 } |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 locked_ = buffer_->Lock(access_mode, &data_); | 597 locked_ = buffer_->Lock(access_mode, &data_); |
| 598 if (!locked_) { | 598 if (!locked_) { |
| 599 O3D_ERROR(buffer_->service_locator()) | 599 O3D_ERROR(buffer_->service_locator()) |
| 600 << "Unable to lock buffer '" << buffer_->name() << "'"; | 600 << "Unable to lock buffer '" << buffer_->name() << "'"; |
| 601 } | 601 } |
| 602 } | 602 } |
| 603 return data_; | 603 return data_; |
| 604 } | 604 } |
| 605 | 605 |
| 606 } // namespace o3d | 606 } // namespace o3d |
| OLD | NEW |