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

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

Issue 2775283004: Rendering Daydream controller in a fixed position. (Closed)
Patch Set: Moving code to more appropriate locations. 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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 "chrome/browser/android/vr_shell/gltf_asset.h" 5 #include "chrome/browser/android/vr_shell/gltf_asset.h"
6 6
7 #include <unordered_map> 7 #include <unordered_map>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
11 namespace vr_shell { 11 namespace vr_shell {
12 12
13 namespace gltf { 13 namespace gltf {
14 14
15 namespace {
16
15 const std::unordered_map<std::string, Type> kTypeMap = { 17 const std::unordered_map<std::string, Type> kTypeMap = {
16 {"SCALAR", SCALAR}, {"VEC2", VEC2}, {"VEC3", VEC3}, {"VEC4", VEC4}, 18 {"SCALAR", SCALAR}, {"VEC2", VEC2}, {"VEC3", VEC3}, {"VEC4", VEC4},
17 {"MAT2", MAT2}, {"MAT3", MAT3}, {"MAT4", MAT4}, 19 {"MAT2", MAT2}, {"MAT3", MAT3}, {"MAT4", MAT4},
18 }; 20 };
19 21
22 const std::vector<int> kTypeComponents = {
23 0,
24 1, // SCALAR
25 2, // VEC2
26 3, // VEC3
27 4, // VEC4
28 4, // MAT2
29 9, // MAT3
30 16, // MAT4
31 };
32
33 } // namespace
34
20 Type GetType(const std::string& type) { 35 Type GetType(const std::string& type) {
21 auto it = kTypeMap.find(type); 36 auto it = kTypeMap.find(type);
22 if (it == kTypeMap.end()) 37 if (it == kTypeMap.end())
23 return UNKNOWN; 38 return UNKNOWN;
24 return it->second; 39 return it->second;
25 } 40 }
26 41
42 GLint GetTypeComponents(Type type) {
43 return kTypeComponents[type];
44 }
45
27 Mesh::Primitive::Primitive() : indices(nullptr), mode(4) {} 46 Mesh::Primitive::Primitive() : indices(nullptr), mode(4) {}
28 47
29 Mesh::Primitive::~Primitive() = default; 48 Mesh::Primitive::~Primitive() = default;
30 49
31 Mesh::Mesh() {} 50 Mesh::Mesh() {}
32 51
33 Mesh::~Mesh() = default; 52 Mesh::~Mesh() = default;
34 53
35 Node::Node() {} 54 Node::Node() {}
36 55
37 Node::~Node() = default; 56 Node::~Node() = default;
38 57
39 Scene::Scene() {} 58 Scene::Scene() {}
40 59
41 Scene::~Scene() = default; 60 Scene::~Scene() = default;
42 61
43 Asset::Asset() : scene_(nullptr) {} 62 Asset::Asset() : scene_(nullptr) {}
44 63
45 Asset::~Asset() = default; 64 Asset::~Asset() = default;
46 65
47 std::size_t Asset::AddBuffer(std::unique_ptr<Buffer> buffer) {
48 auto index = buffers_.size();
49 buffers_.push_back(std::move(buffer));
50 return index;
51 }
52
53 std::size_t Asset::AddBufferView(std::unique_ptr<BufferView> buffer_view) { 66 std::size_t Asset::AddBufferView(std::unique_ptr<BufferView> buffer_view) {
54 auto index = buffer_views_.size(); 67 auto index = buffer_views_.size();
55 buffer_views_.push_back(std::move(buffer_view)); 68 buffer_views_.push_back(std::move(buffer_view));
56 return index; 69 return index;
57 } 70 }
58 71
59 std::size_t Asset::AddAccessor(std::unique_ptr<Accessor> accessor) { 72 std::size_t Asset::AddAccessor(std::unique_ptr<Accessor> accessor) {
60 auto index = accessors_.size(); 73 auto index = accessors_.size();
61 accessors_.push_back(std::move(accessor)); 74 accessors_.push_back(std::move(accessor));
62 return index; 75 return index;
(...skipping 10 matching lines...) Expand all
73 nodes_.push_back(std::move(node)); 86 nodes_.push_back(std::move(node));
74 return index; 87 return index;
75 } 88 }
76 89
77 std::size_t Asset::AddScene(std::unique_ptr<Scene> scene) { 90 std::size_t Asset::AddScene(std::unique_ptr<Scene> scene) {
78 auto index = scenes_.size(); 91 auto index = scenes_.size();
79 scenes_.push_back(std::move(scene)); 92 scenes_.push_back(std::move(scene));
80 return index; 93 return index;
81 } 94 }
82 95
83 const Buffer* Asset::GetBuffer(std::size_t id) const {
84 return id < buffers_.size() ? buffers_[id].get() : nullptr;
85 }
86
87 const BufferView* Asset::GetBufferView(std::size_t id) const { 96 const BufferView* Asset::GetBufferView(std::size_t id) const {
88 return id < buffer_views_.size() ? buffer_views_[id].get() : nullptr; 97 return id < buffer_views_.size() ? buffer_views_[id].get() : nullptr;
89 } 98 }
90 99
91 const Accessor* Asset::GetAccessor(std::size_t id) const { 100 const Accessor* Asset::GetAccessor(std::size_t id) const {
92 return id < accessors_.size() ? accessors_[id].get() : nullptr; 101 return id < accessors_.size() ? accessors_[id].get() : nullptr;
93 } 102 }
94 103
95 const Mesh* Asset::GetMesh(std::size_t id) const { 104 const Mesh* Asset::GetMesh(std::size_t id) const {
96 return id < meshes_.size() ? meshes_[id].get() : nullptr; 105 return id < meshes_.size() ? meshes_[id].get() : nullptr;
97 } 106 }
98 107
99 const Node* Asset::GetNode(std::size_t id) const { 108 const Node* Asset::GetNode(std::size_t id) const {
100 return id < nodes_.size() ? nodes_[id].get() : nullptr; 109 return id < nodes_.size() ? nodes_[id].get() : nullptr;
101 } 110 }
102 111
103 const Scene* Asset::GetScene(std::size_t id) const { 112 const Scene* Asset::GetScene(std::size_t id) const {
104 return id < scenes_.size() ? scenes_[id].get() : nullptr; 113 return id < scenes_.size() ? scenes_[id].get() : nullptr;
105 } 114 }
106 115
107 } // namespace gltf 116 } // namespace gltf
108 117
109 } // namespace vr_shell 118 } // namespace vr_shell
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/gltf_asset.h ('k') | chrome/browser/android/vr_shell/gltf_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698