Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/android/vr_shell/vr_controller_model.h" | |
| 6 | |
| 7 namespace vr_shell { | |
| 8 | |
| 9 namespace { | |
| 10 | |
| 11 enum { | |
| 12 ELEMENTS_BUFFER_ID = 0, | |
| 13 INDICES_BUFFER_ID = 1, | |
| 14 }; | |
| 15 | |
| 16 constexpr char kPosition[] = "POSITION"; | |
| 17 constexpr char kTextCoord[] = "TEXCOORD_0"; | |
| 18 | |
| 19 } // namespace | |
| 20 | |
| 21 constexpr char const VrControllerModel::kComponentName[]; | |
| 22 constexpr char const VrControllerModel::kDefaultVersion[]; | |
| 23 constexpr char const VrControllerModel::kModelsDirectory[]; | |
| 24 constexpr char const VrControllerModel::kModelFilename[]; | |
| 25 constexpr char const VrControllerModel::kTexturesDirectory[]; | |
| 26 constexpr char const* VrControllerModel::kTextureFilenames[]; | |
| 27 | |
| 28 VrControllerModel::VrControllerModel(std::unique_ptr<gltf::Asset> gltf_asset) | |
| 29 : gltf_asset_(std::move(gltf_asset)), | |
| 30 texture_bitmaps_(State::STATE_COUNT) {} | |
| 31 | |
| 32 VrControllerModel::~VrControllerModel() = default; | |
| 33 | |
| 34 const GLvoid* VrControllerModel::ElementsBuffer() const { | |
| 35 const gltf::BufferView* buffer_view = | |
|
bajones
2017/03/29 17:38:58
The elements buffer and indices buffer are somethi
acondor_
2017/03/29 20:13:26
Actually, they are used just once (during SetUp ca
| |
| 36 gltf_asset_->GetBufferView(ELEMENTS_BUFFER_ID); | |
| 37 DCHECK(buffer_view && buffer_view->target == GL_ARRAY_BUFFER); | |
| 38 return Buffer() + buffer_view->byte_offset; | |
| 39 } | |
| 40 | |
| 41 GLsizeiptr VrControllerModel::ElementsBufferSize() const { | |
| 42 const gltf::BufferView* buffer_view = | |
| 43 gltf_asset_->GetBufferView(ELEMENTS_BUFFER_ID); | |
| 44 DCHECK(buffer_view && buffer_view->target == GL_ARRAY_BUFFER); | |
| 45 return buffer_view->byte_length; | |
| 46 } | |
| 47 | |
| 48 const GLvoid* VrControllerModel::IndicesBuffer() const { | |
| 49 const gltf::BufferView* buffer_view = | |
| 50 gltf_asset_->GetBufferView(INDICES_BUFFER_ID); | |
| 51 DCHECK(buffer_view && buffer_view->target == GL_ELEMENT_ARRAY_BUFFER); | |
| 52 return Buffer() + buffer_view->byte_offset; | |
| 53 } | |
| 54 | |
| 55 GLsizeiptr VrControllerModel::IndicesBufferSize() const { | |
| 56 const gltf::BufferView* buffer_view = | |
| 57 gltf_asset_->GetBufferView(INDICES_BUFFER_ID); | |
| 58 DCHECK(buffer_view && buffer_view->target == GL_ELEMENT_ARRAY_BUFFER); | |
| 59 return buffer_view->byte_length; | |
| 60 } | |
| 61 | |
| 62 GLenum VrControllerModel::DrawMode() const { | |
| 63 const gltf::Mesh* mesh = gltf_asset_->GetMesh(0); | |
| 64 DCHECK(mesh && mesh->primitives.size()); | |
| 65 return mesh->primitives[0]->mode; | |
| 66 } | |
| 67 | |
| 68 const gltf::Accessor* VrControllerModel::IndicesAccessor() const { | |
| 69 const gltf::Mesh* mesh = gltf_asset_->GetMesh(0); | |
| 70 DCHECK(mesh && mesh->primitives.size()); | |
| 71 return mesh->primitives[0]->indices; | |
| 72 } | |
| 73 | |
| 74 const gltf::Accessor* VrControllerModel::PositionAccessor() const { | |
| 75 return Accessor(kPosition); | |
| 76 } | |
| 77 | |
| 78 const gltf::Accessor* VrControllerModel::TextureCoordinateAccessor() const { | |
| 79 return Accessor(kTextCoord); | |
| 80 } | |
| 81 | |
| 82 void VrControllerModel::SetTexture(int state, | |
| 83 std::unique_ptr<SkBitmap> bitmap) { | |
| 84 DCHECK(state >= 0 && state < STATE_COUNT); | |
| 85 texture_bitmaps_[state] = std::move(bitmap); | |
| 86 } | |
| 87 | |
| 88 const SkBitmap* VrControllerModel::GetTexture(int state) const { | |
| 89 DCHECK(state >= 0 && state < STATE_COUNT); | |
| 90 return texture_bitmaps_[state].get(); | |
| 91 } | |
| 92 | |
| 93 void VrControllerModel::Free() { | |
| 94 gltf_asset_->FreeBuffers(); | |
| 95 texture_bitmaps_.clear(); | |
| 96 } | |
| 97 | |
| 98 const char* VrControllerModel::Buffer() const { | |
| 99 const gltf::Buffer* buffer = gltf_asset_->GetBuffer(0); | |
| 100 DCHECK(buffer); | |
| 101 return buffer->data(); | |
| 102 } | |
| 103 | |
| 104 const gltf::Accessor* VrControllerModel::Accessor( | |
| 105 const std::string& key) const { | |
| 106 const gltf::Mesh* mesh = gltf_asset_->GetMesh(0); | |
| 107 DCHECK(mesh && mesh->primitives.size()); | |
| 108 auto it = mesh->primitives[0]->attributes.find(key); | |
|
bajones
2017/03/29 17:38:58
Same goes for the accessor, but even more so. Doin
acondor_
2017/03/29 20:13:26
No need with the new approach on the Renderer.
| |
| 109 DCHECK(it != mesh->primitives[0]->attributes.begin()); | |
| 110 return it->second; | |
| 111 } | |
| 112 | |
| 113 } // namespace vr_shell | |
| OLD | NEW |