Chromium Code Reviews| 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) { | |
|
asimjour1
2017/03/29 20:40:44
I think this method also doesn't belong here. it s
| |
| 1101 if (!vr_shell_renderer_->GetControllerRenderer()->IsSetUp()) | |
| 1102 return; | |
| 1103 // TODO(acondor): Placing the controller in a fixed position before | |
|
amp
2017/03/29 20:54:56
Format the TODO's as what needs to be done next, n
acondor_
2017/03/29 22:46:44
Done.
| |
| 1104 // implementing the elbow model. | |
| 1105 gvr::Mat4f mat; | |
| 1106 SetIdentityM(mat); | |
| 1107 // Changing rotation point. | |
| 1108 TranslateM(mat, mat, 0, 0, 0.05); | |
|
cjgrant
2017/03/29 20:22:38
Normally you'd want a constant for 0.05, but assum
acondor_
2017/03/29 22:46:45
Acknowledged.
| |
| 1109 mat = MatrixMul(QuatToMatrix(controller_->Orientation()), mat); | |
| 1110 TranslateM(mat, mat, kControllerPosition.x, kControllerPosition.y, | |
| 1111 kControllerPosition.z - 0.05); | |
| 1112 | |
| 1113 auto transform = MatrixMul(view_proj_matrix, mat); | |
| 1114 | |
| 1115 VrControllerModel::State state = VrControllerModel::IDLE; | |
| 1116 if (controller_->ButtonState( | |
| 1117 gvr::ControllerButton::GVR_CONTROLLER_BUTTON_CLICK)) | |
| 1118 state = VrControllerModel::TOUCHPAD; | |
| 1119 else if (controller_->ButtonState( | |
| 1120 gvr::ControllerButton::GVR_CONTROLLER_BUTTON_APP)) | |
| 1121 state = VrControllerModel::APP; | |
| 1122 else if (controller_->ButtonState( | |
| 1123 gvr::ControllerButton::GVR_CONTROLLER_BUTTON_HOME)) | |
| 1124 state = VrControllerModel::SYSTEM; | |
| 1125 | |
| 1126 vr_shell_renderer_->GetControllerRenderer()->Draw(state, transform); | |
| 1127 } | |
| 1128 | |
| 1098 bool VrShellGl::ShouldDrawWebVr() { | 1129 bool VrShellGl::ShouldDrawWebVr() { |
| 1099 return web_vr_mode_ && scene_->GetWebVrRenderingEnabled(); | 1130 return web_vr_mode_ && scene_->GetWebVrRenderingEnabled(); |
| 1100 } | 1131 } |
| 1101 | 1132 |
| 1102 void VrShellGl::DrawWebVr() { | 1133 void VrShellGl::DrawWebVr() { |
| 1103 TRACE_EVENT0("gpu", "VrShellGl::DrawWebVr"); | 1134 TRACE_EVENT0("gpu", "VrShellGl::DrawWebVr"); |
| 1104 // Don't need face culling, depth testing, blending, etc. Turn it all off. | 1135 // Don't need face culling, depth testing, blending, etc. Turn it all off. |
| 1105 glDisable(GL_CULL_FACE); | 1136 glDisable(GL_CULL_FACE); |
| 1106 glDepthMask(GL_FALSE); | 1137 glDepthMask(GL_FALSE); |
| 1107 glDisable(GL_DEPTH_TEST); | 1138 glDisable(GL_DEPTH_TEST); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1182 if (ui_surface_texture_.get()) | 1213 if (ui_surface_texture_.get()) |
| 1183 ui_surface_texture_->SetDefaultBufferSize(width, height); | 1214 ui_surface_texture_->SetDefaultBufferSize(width, height); |
| 1184 ui_tex_physical_size_.width = width; | 1215 ui_tex_physical_size_.width = width; |
| 1185 ui_tex_physical_size_.height = height; | 1216 ui_tex_physical_size_.height = height; |
| 1186 } | 1217 } |
| 1187 | 1218 |
| 1188 base::WeakPtr<VrShellGl> VrShellGl::GetWeakPtr() { | 1219 base::WeakPtr<VrShellGl> VrShellGl::GetWeakPtr() { |
| 1189 return weak_ptr_factory_.GetWeakPtr(); | 1220 return weak_ptr_factory_.GetWeakPtr(); |
| 1190 } | 1221 } |
| 1191 | 1222 |
| 1223 void VrShellGl::SetControllerModel(std::unique_ptr<VrControllerModel> model) { | |
| 1224 vr_shell_renderer_->GetControllerRenderer()->SetUp(std::move(model)); | |
| 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 |