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

Side by Side Diff: chrome/browser/android/vr_shell/vr_controller_model.cc

Issue 2775283004: Rendering Daydream controller in a fixed position. (Closed)
Patch Set: Removing ownership of Buffers from the gltf asset Created 3 years, 8 months 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
(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 kTexCoord[] = "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(
29 std::unique_ptr<gltf::Asset> gltf_asset,
30 std::vector<std::unique_ptr<gltf::Buffer>> buffers)
31 : gltf_asset_(std::move(gltf_asset)),
32 texture_bitmaps_(State::STATE_COUNT),
33 buffers_(std::move(buffers)) {}
34
35 VrControllerModel::~VrControllerModel() = default;
36
37 const GLvoid* VrControllerModel::ElementsBuffer() const {
38 const gltf::BufferView* buffer_view =
39 gltf_asset_->GetBufferView(ELEMENTS_BUFFER_ID);
40 DCHECK(buffer_view && buffer_view->target == GL_ARRAY_BUFFER);
41 const char* buffer = Buffer();
42 return buffer ? buffer + buffer_view->byte_offset : nullptr;
43 }
44
45 GLsizeiptr VrControllerModel::ElementsBufferSize() const {
46 const gltf::BufferView* buffer_view =
47 gltf_asset_->GetBufferView(ELEMENTS_BUFFER_ID);
48 DCHECK(buffer_view && buffer_view->target == GL_ARRAY_BUFFER);
49 return buffer_view->byte_length;
50 }
51
52 const GLvoid* VrControllerModel::IndicesBuffer() const {
53 const gltf::BufferView* buffer_view =
54 gltf_asset_->GetBufferView(INDICES_BUFFER_ID);
55 DCHECK(buffer_view && buffer_view->target == GL_ELEMENT_ARRAY_BUFFER);
56 const char* buffer = Buffer();
57 return buffer ? buffer + buffer_view->byte_offset : nullptr;
58 }
59
60 GLsizeiptr VrControllerModel::IndicesBufferSize() const {
61 const gltf::BufferView* buffer_view =
62 gltf_asset_->GetBufferView(INDICES_BUFFER_ID);
63 DCHECK(buffer_view && buffer_view->target == GL_ELEMENT_ARRAY_BUFFER);
64 return buffer_view->byte_length;
65 }
66
67 GLenum VrControllerModel::DrawMode() const {
68 const gltf::Mesh* mesh = gltf_asset_->GetMesh(0);
69 DCHECK(mesh && mesh->primitives.size());
70 return mesh->primitives[0]->mode;
71 }
72
73 const gltf::Accessor* VrControllerModel::IndicesAccessor() const {
74 const gltf::Mesh* mesh = gltf_asset_->GetMesh(0);
75 DCHECK(mesh && mesh->primitives.size());
76 return mesh->primitives[0]->indices;
77 }
78
79 const gltf::Accessor* VrControllerModel::PositionAccessor() const {
80 return Accessor(kPosition);
81 }
82
83 const gltf::Accessor* VrControllerModel::TextureCoordinateAccessor() const {
84 return Accessor(kTexCoord);
85 }
86
87 void VrControllerModel::SetTexture(int state,
88 std::unique_ptr<SkBitmap> bitmap) {
89 DCHECK(state >= 0 && state < STATE_COUNT);
90 texture_bitmaps_[state] = std::move(bitmap);
91 }
92
93 const SkBitmap* VrControllerModel::GetTexture(int state) const {
94 DCHECK(state >= 0 && state < STATE_COUNT);
95 return texture_bitmaps_[state].get();
96 }
97
98 const char* VrControllerModel::Buffer() const {
99 if (buffers_.empty())
100 return nullptr;
101 return buffers_[0]->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);
109 DCHECK(it != mesh->primitives[0]->attributes.begin());
110 return it->second;
111 }
112
113 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698