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

Unified Diff: chrome/browser/android/vr_shell/vr_controller_model.cc

Issue 2775283004: Rendering Daydream controller in a fixed position. (Closed)
Patch Set: Using textures for corresponding button states. Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/vr_shell/vr_controller_model.cc
diff --git a/chrome/browser/android/vr_shell/vr_controller_model.cc b/chrome/browser/android/vr_shell/vr_controller_model.cc
new file mode 100644
index 0000000000000000000000000000000000000000..abb4b76132847a0c60dec99dfe6743f7555d9b7d
--- /dev/null
+++ b/chrome/browser/android/vr_shell/vr_controller_model.cc
@@ -0,0 +1,113 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/android/vr_shell/vr_controller_model.h"
+
+namespace vr_shell {
+
+namespace {
+
+enum {
+ ELEMENTS_BUFFER_ID = 0,
+ INDICES_BUFFER_ID = 1,
+};
+
+constexpr char kPosition[] = "POSITION";
+constexpr char kTextCoord[] = "TEXCOORD_0";
+
+} // namespace
+
+constexpr char const VrControllerModel::kComponentName[];
+constexpr char const VrControllerModel::kDefaultVersion[];
+constexpr char const VrControllerModel::kModelsDirectory[];
+constexpr char const VrControllerModel::kModelFilename[];
+constexpr char const VrControllerModel::kTexturesDirectory[];
+constexpr char const* VrControllerModel::kTextureFilenames[];
+
+VrControllerModel::VrControllerModel(std::unique_ptr<gltf::Asset> gltf_asset)
+ : gltf_asset_(std::move(gltf_asset)),
+ texture_bitmaps_(State::STATE_COUNT) {}
+
+VrControllerModel::~VrControllerModel() = default;
+
+const GLvoid* VrControllerModel::ElementsBuffer() const {
+ 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
+ gltf_asset_->GetBufferView(ELEMENTS_BUFFER_ID);
+ DCHECK(buffer_view && buffer_view->target == GL_ARRAY_BUFFER);
+ return Buffer() + buffer_view->byte_offset;
+}
+
+GLsizeiptr VrControllerModel::ElementsBufferSize() const {
+ const gltf::BufferView* buffer_view =
+ gltf_asset_->GetBufferView(ELEMENTS_BUFFER_ID);
+ DCHECK(buffer_view && buffer_view->target == GL_ARRAY_BUFFER);
+ return buffer_view->byte_length;
+}
+
+const GLvoid* VrControllerModel::IndicesBuffer() const {
+ const gltf::BufferView* buffer_view =
+ gltf_asset_->GetBufferView(INDICES_BUFFER_ID);
+ DCHECK(buffer_view && buffer_view->target == GL_ELEMENT_ARRAY_BUFFER);
+ return Buffer() + buffer_view->byte_offset;
+}
+
+GLsizeiptr VrControllerModel::IndicesBufferSize() const {
+ const gltf::BufferView* buffer_view =
+ gltf_asset_->GetBufferView(INDICES_BUFFER_ID);
+ DCHECK(buffer_view && buffer_view->target == GL_ELEMENT_ARRAY_BUFFER);
+ return buffer_view->byte_length;
+}
+
+GLenum VrControllerModel::DrawMode() const {
+ const gltf::Mesh* mesh = gltf_asset_->GetMesh(0);
+ DCHECK(mesh && mesh->primitives.size());
+ return mesh->primitives[0]->mode;
+}
+
+const gltf::Accessor* VrControllerModel::IndicesAccessor() const {
+ const gltf::Mesh* mesh = gltf_asset_->GetMesh(0);
+ DCHECK(mesh && mesh->primitives.size());
+ return mesh->primitives[0]->indices;
+}
+
+const gltf::Accessor* VrControllerModel::PositionAccessor() const {
+ return Accessor(kPosition);
+}
+
+const gltf::Accessor* VrControllerModel::TextureCoordinateAccessor() const {
+ return Accessor(kTextCoord);
+}
+
+void VrControllerModel::SetTexture(int state,
+ std::unique_ptr<SkBitmap> bitmap) {
+ DCHECK(state >= 0 && state < STATE_COUNT);
+ texture_bitmaps_[state] = std::move(bitmap);
+}
+
+const SkBitmap* VrControllerModel::GetTexture(int state) const {
+ DCHECK(state >= 0 && state < STATE_COUNT);
+ return texture_bitmaps_[state].get();
+}
+
+void VrControllerModel::Free() {
+ gltf_asset_->FreeBuffers();
+ texture_bitmaps_.clear();
+}
+
+const char* VrControllerModel::Buffer() const {
+ const gltf::Buffer* buffer = gltf_asset_->GetBuffer(0);
+ DCHECK(buffer);
+ return buffer->data();
+}
+
+const gltf::Accessor* VrControllerModel::Accessor(
+ const std::string& key) const {
+ const gltf::Mesh* mesh = gltf_asset_->GetMesh(0);
+ DCHECK(mesh && mesh->primitives.size());
+ 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.
+ DCHECK(it != mesh->primitives[0]->attributes.begin());
+ return it->second;
+}
+
+} // namespace vr_shell

Powered by Google App Engine
This is Rietveld 408576698