OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/vr_shell_gl.h" | 5 #include "chrome/browser/android/vr_shell/vr_shell_gl.h" |
6 | 6 |
7 #include <chrono> | 7 #include <chrono> |
8 #include <limits> | 8 #include <limits> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 static constexpr float kLaserWidth = 0.01f; | 49 static constexpr float kLaserWidth = 0.01f; |
50 | 50 |
51 // Angle (radians) the beam down from the controller axis, for wrist comfort. | 51 // Angle (radians) the beam down from the controller axis, for wrist comfort. |
52 static constexpr float kErgoAngleOffset = 0.26f; | 52 static constexpr float kErgoAngleOffset = 0.26f; |
53 | 53 |
54 static constexpr gvr::Vec3f kOrigin = {0.0f, 0.0f, 0.0f}; | 54 static constexpr gvr::Vec3f kOrigin = {0.0f, 0.0f, 0.0f}; |
55 | 55 |
56 // In lieu of an elbow model, we assume a position for the user's hand. | 56 // In lieu of an elbow model, we assume a position for the user's hand. |
57 // TODO(mthiesse): Handedness options. | 57 // TODO(mthiesse): Handedness options. |
58 static constexpr gvr::Vec3f kHandPosition = {0.2f, -0.5f, -0.2f}; | 58 static constexpr gvr::Vec3f kHandPosition = {0.2f, -0.5f, -0.2f}; |
59 static constexpr gvr::Vec3f kControllerPosition = {0.2f, -0.5f, -0.15f}; | |
59 | 60 |
60 // Fraction of the distance to the object the cursor is drawn at to avoid | 61 // Fraction of the distance to the object the cursor is drawn at to avoid |
61 // rounding errors drawing the cursor behind the object. | 62 // rounding errors drawing the cursor behind the object. |
62 static constexpr float kReticleOffset = 0.99f; | 63 static constexpr float kReticleOffset = 0.99f; |
63 | 64 |
64 // GVR buffer indices for use with viewport->SetSourceBufferIndex | 65 // GVR buffer indices for use with viewport->SetSourceBufferIndex |
65 // or frame.BindBuffer. We use one for world content (with reprojection) | 66 // or frame.BindBuffer. We use one for world content (with reprojection) |
66 // including main VrShell and WebVR content plus world-space UI. | 67 // including main VrShell and WebVR content plus world-space UI. |
67 // The headlocked buffer is for UI that should not use reprojection. | 68 // The headlocked buffer is for UI that should not use reprojection. |
68 static constexpr int kFramePrimaryBuffer = 0; | 69 static constexpr int kFramePrimaryBuffer = 0; |
(...skipping 859 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
928 pixel_rect.top - pixel_rect.bottom); | 929 pixel_rect.top - pixel_rect.bottom); |
929 | 930 |
930 const gvr::Mat4f render_matrix = | 931 const gvr::Mat4f render_matrix = |
931 MatrixMul(PerspectiveMatrixFromView(buffer_viewport_->GetSourceFov(), | 932 MatrixMul(PerspectiveMatrixFromView(buffer_viewport_->GetSourceFov(), |
932 kZNear, kZFar), | 933 kZNear, kZFar), |
933 eye_view_matrix); | 934 eye_view_matrix); |
934 | 935 |
935 DrawElements(render_matrix, elementsInDrawOrder); | 936 DrawElements(render_matrix, elementsInDrawOrder); |
936 if (draw_cursor) { | 937 if (draw_cursor) { |
937 DrawCursor(render_matrix); | 938 DrawCursor(render_matrix); |
939 DrawController(render_matrix); | |
938 } | 940 } |
939 } | 941 } |
940 } | 942 } |
941 | 943 |
942 void VrShellGl::DrawElements( | 944 void VrShellGl::DrawElements( |
943 const gvr::Mat4f& view_proj_matrix, | 945 const gvr::Mat4f& view_proj_matrix, |
944 const std::vector<const ContentRectangle*>& elements) { | 946 const std::vector<const ContentRectangle*>& elements) { |
945 for (const auto* rect : elements) { | 947 for (const auto* rect : elements) { |
946 gvr::Mat4f transform = MatrixMul(view_proj_matrix, rect->TransformMatrix()); | 948 gvr::Mat4f transform = MatrixMul(view_proj_matrix, rect->TransformMatrix()); |
947 | 949 |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1088 | 1090 |
1089 // Move the beam origin to the hand. | 1091 // Move the beam origin to the hand. |
1090 TranslateM(face_transform, face_transform, kHandPosition.x, kHandPosition.y, | 1092 TranslateM(face_transform, face_transform, kHandPosition.x, kHandPosition.y, |
1091 kHandPosition.z); | 1093 kHandPosition.z); |
1092 | 1094 |
1093 transform = MatrixMul(render_matrix, face_transform); | 1095 transform = MatrixMul(render_matrix, face_transform); |
1094 vr_shell_renderer_->GetLaserRenderer()->Draw(transform); | 1096 vr_shell_renderer_->GetLaserRenderer()->Draw(transform); |
1095 } | 1097 } |
1096 } | 1098 } |
1097 | 1099 |
1100 void VrShellGl::DrawController(const gvr::Mat4f& view_proj_matrix) { | |
1101 if (!controller_model_) | |
1102 return; | |
1103 gvr::Mat4f mat; | |
1104 SetIdentityM(mat); | |
1105 // TODO(acondor): Placing controller in temporary position before | |
cjgrant
2017/03/29 13:20:54
Maybe I'm missing something, but in addition to pu
acondor_
2017/03/29 20:13:26
Done. It will be changed to the elbow model soon,
cjgrant
2017/03/29 20:22:37
Thanks. From a live demo, this looks really good
| |
1106 // implementing the elbow model. | |
1107 TranslateM(mat, mat, kControllerPosition.x, kControllerPosition.y, | |
1108 kControllerPosition.z); | |
1109 | |
1110 auto transform = MatrixMul(view_proj_matrix, mat); | |
1111 | |
1112 VrControllerModel::State state = VrControllerModel::IDLE; | |
cjgrant
2017/03/29 13:20:54
- Volume buttons?
- Can multiple buttons be presse
acondor_
2017/03/29 20:13:26
I'm not sure if they can, but the textures provide
| |
1113 if (controller_->ButtonState( | |
1114 gvr::ControllerButton::GVR_CONTROLLER_BUTTON_CLICK)) | |
1115 state = VrControllerModel::TOUCHPAD; | |
1116 else if (controller_->ButtonState( | |
1117 gvr::ControllerButton::GVR_CONTROLLER_BUTTON_APP)) | |
1118 state = VrControllerModel::APP; | |
1119 else if (controller_->ButtonState( | |
1120 gvr::ControllerButton::GVR_CONTROLLER_BUTTON_HOME)) | |
1121 state = VrControllerModel::SYSTEM; | |
1122 | |
1123 vr_shell_renderer_->GetControllerRenderer()->Draw(*controller_model_, state, | |
1124 transform); | |
1125 } | |
1126 | |
1098 bool VrShellGl::ShouldDrawWebVr() { | 1127 bool VrShellGl::ShouldDrawWebVr() { |
1099 return web_vr_mode_ && scene_->GetWebVrRenderingEnabled(); | 1128 return web_vr_mode_ && scene_->GetWebVrRenderingEnabled(); |
1100 } | 1129 } |
1101 | 1130 |
1102 void VrShellGl::DrawWebVr() { | 1131 void VrShellGl::DrawWebVr() { |
1103 TRACE_EVENT0("gpu", "VrShellGl::DrawWebVr"); | 1132 TRACE_EVENT0("gpu", "VrShellGl::DrawWebVr"); |
1104 // Don't need face culling, depth testing, blending, etc. Turn it all off. | 1133 // Don't need face culling, depth testing, blending, etc. Turn it all off. |
1105 glDisable(GL_CULL_FACE); | 1134 glDisable(GL_CULL_FACE); |
1106 glDepthMask(GL_FALSE); | 1135 glDepthMask(GL_FALSE); |
1107 glDisable(GL_DEPTH_TEST); | 1136 glDisable(GL_DEPTH_TEST); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1182 if (ui_surface_texture_.get()) | 1211 if (ui_surface_texture_.get()) |
1183 ui_surface_texture_->SetDefaultBufferSize(width, height); | 1212 ui_surface_texture_->SetDefaultBufferSize(width, height); |
1184 ui_tex_physical_size_.width = width; | 1213 ui_tex_physical_size_.width = width; |
1185 ui_tex_physical_size_.height = height; | 1214 ui_tex_physical_size_.height = height; |
1186 } | 1215 } |
1187 | 1216 |
1188 base::WeakPtr<VrShellGl> VrShellGl::GetWeakPtr() { | 1217 base::WeakPtr<VrShellGl> VrShellGl::GetWeakPtr() { |
1189 return weak_ptr_factory_.GetWeakPtr(); | 1218 return weak_ptr_factory_.GetWeakPtr(); |
1190 } | 1219 } |
1191 | 1220 |
1221 void VrShellGl::SetControllerModel(std::unique_ptr<VrControllerModel> model) { | |
1222 controller_model_ = std::move(model); | |
1223 vr_shell_renderer_->GetControllerRenderer()->SetUp(*controller_model_); | |
1224 controller_model_->Free(); | |
cjgrant
2017/03/29 13:20:54
Michael already commented on this Free() approach.
acondor_
2017/03/29 20:13:26
The new approach is that the renderer gathers all
| |
1225 } | |
1226 | |
1192 void VrShellGl::OnVSync() { | 1227 void VrShellGl::OnVSync() { |
1193 while (premature_received_frames_ > 0) { | 1228 while (premature_received_frames_ > 0) { |
1194 TRACE_EVENT0("gpu", "VrShellGl::OnWebVRFrameAvailableRetry"); | 1229 TRACE_EVENT0("gpu", "VrShellGl::OnWebVRFrameAvailableRetry"); |
1195 --premature_received_frames_; | 1230 --premature_received_frames_; |
1196 OnWebVRFrameAvailable(); | 1231 OnWebVRFrameAvailable(); |
1197 } | 1232 } |
1198 | 1233 |
1199 base::TimeTicks now = base::TimeTicks::Now(); | 1234 base::TimeTicks now = base::TimeTicks::Now(); |
1200 base::TimeTicks target; | 1235 base::TimeTicks target; |
1201 | 1236 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1291 // appropriate recommended render resolution as the default size during | 1326 // appropriate recommended render resolution as the default size during |
1292 // InitializeGl. Revisit if the initialization order changes. | 1327 // InitializeGl. Revisit if the initialization order changes. |
1293 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo( | 1328 device::mojom::VRDisplayInfoPtr info = VrShell::CreateVRDisplayInfo( |
1294 gvr_api_.get(), webvr_surface_size_, device_id); | 1329 gvr_api_.get(), webvr_surface_size_, device_id); |
1295 main_thread_task_runner_->PostTask( | 1330 main_thread_task_runner_->PostTask( |
1296 FROM_HERE, | 1331 FROM_HERE, |
1297 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); | 1332 base::Bind(&RunVRDisplayInfoCallback, callback, base::Passed(&info))); |
1298 } | 1333 } |
1299 | 1334 |
1300 } // namespace vr_shell | 1335 } // namespace vr_shell |
OLD | NEW |