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_gl_util.h" | 5 #include "chrome/browser/android/vr_shell/vr_gl_util.h" |
6 | 6 |
7 namespace vr_shell { | 7 namespace vr_shell { |
8 | 8 |
9 // This code is adapted from the GVR Treasure Hunt demo source. | 9 // This code is adapted from the GVR Treasure Hunt demo source. |
10 std::array<float, 16> MatrixToGLArray(const gvr::Mat4f& matrix) { | 10 std::array<float, 16> MatrixToGLArray(const vr::Mat4f& matrix) { |
11 // Note that this performs a *transpose* to a column-major matrix array, as | 11 // Note that this performs a *transpose* to a column-major matrix array, as |
12 // expected by GL. The input matrix has translation components at [i][3] for | 12 // expected by GL. The input matrix has translation components at [i][3] for |
13 // use with row vectors and premultiplied transforms. In the output, the | 13 // use with row vectors and premultiplied transforms. In the output, the |
14 // translation elements are at the end at positions 3*4+i. | 14 // translation elements are at the end at positions 3*4+i. |
15 std::array<float, 16> result; | 15 std::array<float, 16> result; |
16 for (int i = 0; i < 4; ++i) { | 16 for (int i = 0; i < 4; ++i) { |
17 for (int j = 0; j < 4; ++j) { | 17 for (int j = 0; j < 4; ++j) { |
18 result[j * 4 + i] = matrix.m[i][j]; | 18 result[j * 4 + i] = matrix[i][j]; |
19 } | 19 } |
20 } | 20 } |
21 return result; | 21 return result; |
22 } | 22 } |
23 | 23 |
24 // This code is adapted from the GVR Treasure Hunt demo source. | 24 // This code is adapted from the GVR Treasure Hunt demo source. |
25 gvr::Rectf ModulateRect(const gvr::Rectf& rect, float width, float height) { | 25 gfx::Rect CalculatePixelSpaceRect(const gfx::Size& texture_size, |
26 gvr::Rectf result = {rect.left * width, rect.right * width, | 26 const gfx::RectF& texture_rect) { |
27 rect.bottom * height, rect.top * height}; | 27 const gfx::RectF rect = |
28 return result; | 28 ScaleRect(texture_rect, static_cast<float>(texture_size.width()), |
29 } | 29 static_cast<float>(texture_size.height())); |
30 | 30 return gfx::Rect(rect.x(), rect.y(), rect.width(), rect.height()); |
31 // This code is adapted from the GVR Treasure Hunt demo source. | |
32 gvr::Recti CalculatePixelSpaceRect(const gvr::Sizei& texture_size, | |
33 const gvr::Rectf& texture_rect) { | |
34 float width = static_cast<float>(texture_size.width); | |
35 float height = static_cast<float>(texture_size.height); | |
36 gvr::Rectf rect = ModulateRect(texture_rect, width, height); | |
37 gvr::Recti result = { | |
38 static_cast<int>(rect.left), static_cast<int>(rect.right), | |
39 static_cast<int>(rect.bottom), static_cast<int>(rect.top)}; | |
40 return result; | |
41 } | 31 } |
42 | 32 |
43 GLuint CompileShader(GLenum shader_type, | 33 GLuint CompileShader(GLenum shader_type, |
44 const GLchar* shader_source, | 34 const GLchar* shader_source, |
45 std::string& error) { | 35 std::string& error) { |
46 GLuint shader_handle = glCreateShader(shader_type); | 36 GLuint shader_handle = glCreateShader(shader_type); |
47 if (shader_handle != 0) { | 37 if (shader_handle != 0) { |
48 // Pass in the shader source. | 38 // Pass in the shader source. |
49 int len = strlen(shader_source); | 39 int len = strlen(shader_source); |
50 glShaderSource(shader_handle, 1, &shader_source, &len); | 40 glShaderSource(shader_handle, 1, &shader_source, &len); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 delete[] str_info_log; | 91 delete[] str_info_log; |
102 glDeleteProgram(program_handle); | 92 glDeleteProgram(program_handle); |
103 program_handle = 0; | 93 program_handle = 0; |
104 } | 94 } |
105 } | 95 } |
106 | 96 |
107 return program_handle; | 97 return program_handle; |
108 } | 98 } |
109 | 99 |
110 } // namespace vr_shell | 100 } // namespace vr_shell |
OLD | NEW |