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 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_RENDERER_H_ | 5 #ifndef CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_RENDERER_H_ |
6 #define CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_RENDERER_H_ | 6 #define CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_RENDERER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "third_party/gvr-android-sdk/src/ndk-beta/include/vr/gvr/capi/include/g
vr.h" | 13 #include "third_party/gvr-android-sdk/src/ndk-beta/include/vr/gvr/capi/include/g
vr.h" |
14 #include "third_party/gvr-android-sdk/src/ndk-beta/include/vr/gvr/capi/include/g
vr_types.h" | 14 #include "third_party/gvr-android-sdk/src/ndk-beta/include/vr/gvr/capi/include/g
vr_types.h" |
15 | 15 |
16 namespace vr_shell { | 16 namespace vr_shell { |
17 | 17 |
18 typedef unsigned int GLuint; | 18 typedef unsigned int GLuint; |
19 | 19 |
20 enum ShaderID { | 20 enum ShaderID { |
21 SHADER_UNRECOGNIZED = 0, | 21 SHADER_UNRECOGNIZED = 0, |
22 TEXTURE_QUAD_VERTEX_SHADER, | 22 TEXTURE_QUAD_VERTEX_SHADER, |
23 TEXTURE_QUAD_FRAGMENT_SHADER, | 23 TEXTURE_QUAD_FRAGMENT_SHADER, |
| 24 WEBVR_VERTEX_SHADER, |
| 25 WEBVR_FRAGMENT_SHADER, |
24 SHADER_ID_MAX | 26 SHADER_ID_MAX |
25 }; | 27 }; |
26 | 28 |
27 class TexturedQuadRenderer { | 29 class TexturedQuadRenderer { |
28 public: | 30 public: |
29 TexturedQuadRenderer(); | 31 TexturedQuadRenderer(); |
30 ~TexturedQuadRenderer(); | 32 ~TexturedQuadRenderer(); |
31 | 33 |
32 // Draw the content rect in the texture quad. | 34 // Draw the content rect in the texture quad. |
33 void Draw(int texture_data_handle, const gvr::Mat4f& combined_matrix); | 35 void Draw(int texture_data_handle, const gvr::Mat4f& combined_matrix); |
34 | 36 |
35 private: | 37 private: |
36 GLuint vertex_shader_handle_; | 38 GLuint vertex_shader_handle_; |
37 GLuint fragment_shader_handle_; | 39 GLuint fragment_shader_handle_; |
38 GLuint program_handle_; | 40 GLuint program_handle_; |
39 GLuint combined_matrix_handle_; | 41 GLuint combined_matrix_handle_; |
40 GLuint texture_uniform_handle_; | 42 GLuint texture_uniform_handle_; |
41 GLuint position_handle_; | 43 GLuint position_handle_; |
42 GLuint texture_coordinate_handle_; | 44 GLuint texture_coordinate_handle_; |
43 | 45 |
44 DISALLOW_COPY_AND_ASSIGN(TexturedQuadRenderer); | 46 DISALLOW_COPY_AND_ASSIGN(TexturedQuadRenderer); |
45 }; | 47 }; |
46 | 48 |
| 49 // Renders a page-generated stereo VR view. |
| 50 class WebVrRenderer { |
| 51 public: |
| 52 WebVrRenderer(); |
| 53 ~WebVrRenderer(); |
| 54 |
| 55 void Draw(int texture_handle); |
| 56 |
| 57 void UpdateTextureBounds(int eye, const gvr::Rectf& bounds); |
| 58 |
| 59 private: |
| 60 static constexpr size_t VERTEX_STRIDE = sizeof(float) * 4; |
| 61 static constexpr size_t POSITION_ELEMENTS = 2; |
| 62 static constexpr size_t TEXCOORD_ELEMENTS = 2; |
| 63 static constexpr size_t POSITION_OFFSET = 0; |
| 64 static constexpr size_t TEXCOORD_OFFSET = sizeof(float) * 2; |
| 65 |
| 66 GLuint program_handle_; |
| 67 GLuint tex_uniform_handle_; |
| 68 GLuint src_rect_uniform_handle_; |
| 69 GLuint position_handle_; |
| 70 GLuint texcoord_handle_; |
| 71 GLuint vertex_buffer_; |
| 72 |
| 73 gvr::Rectf left_bounds_; |
| 74 gvr::Rectf right_bounds_; |
| 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(WebVrRenderer); |
| 77 }; |
| 78 |
47 class VrShellRenderer { | 79 class VrShellRenderer { |
48 public: | 80 public: |
49 VrShellRenderer(); | 81 VrShellRenderer(); |
50 ~VrShellRenderer(); | 82 ~VrShellRenderer(); |
51 | 83 |
52 TexturedQuadRenderer* GetTexturedQuadRenderer() { | 84 TexturedQuadRenderer* GetTexturedQuadRenderer() { |
53 return textured_quad_renderer_.get(); | 85 return textured_quad_renderer_.get(); |
54 } | 86 } |
55 | 87 |
| 88 WebVrRenderer* GetWebVrRenderer() { |
| 89 return webvr_renderer_.get(); |
| 90 } |
| 91 |
56 private: | 92 private: |
57 std::unique_ptr<TexturedQuadRenderer> textured_quad_renderer_; | 93 std::unique_ptr<TexturedQuadRenderer> textured_quad_renderer_; |
| 94 std::unique_ptr<WebVrRenderer> webvr_renderer_; |
58 DISALLOW_COPY_AND_ASSIGN(VrShellRenderer); | 95 DISALLOW_COPY_AND_ASSIGN(VrShellRenderer); |
59 }; | 96 }; |
60 | 97 |
61 } // namespace vr_shell | 98 } // namespace vr_shell |
62 | 99 |
63 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_RENDERER_H_ | 100 #endif // CHROME_BROWSER_ANDROID_VR_SHELL_VR_SHELL_RENDERER_H_ |
OLD | NEW |