OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 EXAMPLES_TUMBLER_CUBE_H_ | 5 #ifndef EXAMPLES_TUMBLER_CUBE_H_ |
6 #define EXAMPLES_TUMBLER_CUBE_H_ | 6 #define EXAMPLES_TUMBLER_CUBE_H_ |
7 | 7 |
8 #include <GLES2/gl2.h> | 8 #include <GLES2/gl2.h> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 } | 56 } |
57 void SetOrientation(const std::vector<float>& orientation) { | 57 void SetOrientation(const std::vector<float>& orientation) { |
58 orientation_[0] = static_cast<GLfloat>(orientation[0]); | 58 orientation_[0] = static_cast<GLfloat>(orientation[0]); |
59 orientation_[1] = static_cast<GLfloat>(orientation[1]); | 59 orientation_[1] = static_cast<GLfloat>(orientation[1]); |
60 orientation_[2] = static_cast<GLfloat>(orientation[2]); | 60 orientation_[2] = static_cast<GLfloat>(orientation[2]); |
61 orientation_[3] = static_cast<GLfloat>(orientation[3]); | 61 orientation_[3] = static_cast<GLfloat>(orientation[3]); |
62 } | 62 } |
63 | 63 |
64 private: | 64 private: |
65 // Create the shaders used to draw the cube, and link them into a program. | 65 // Create the shaders used to draw the cube, and link them into a program. |
66 // Initializes |shader_progam_object_|, |position_loction_| and | 66 // Initializes |shader_program_object_|, |position_location_| and |
67 // |mvp_location_|. | 67 // |mvp_location_|. |
68 bool CreateShaders(); | 68 bool CreateShaders(); |
69 | 69 |
70 // Generates a cube as a series of GL_TRIANGLE_STRIPs, and initializes | 70 // Generates a cube as a series of GL_TRIANGLE_STRIPs, and initializes |
71 // |index_count_| to the number of indices in the index list used as a VBO. | 71 // |index_count_| to the number of indices in the index list used as a VBO. |
72 // Creates the |vbo_ids_| required for the vertex and index data and uploads | 72 // Creates the |vbo_ids_| required for the vertex and index data and uploads |
73 // the the VBO data. | 73 // the VBO data. |
74 void CreateCube(); | 74 void CreateCube(); |
75 | 75 |
76 // Build up the model-view transform from the eye and orienation properties. | 76 // Build up the model-view transform from the eye and orientation properties. |
77 // Assumes that |model_view| is a 4x4 matrix. | 77 // Assumes that |model_view| is a 4x4 matrix. |
78 void ComputeModelViewTransform(GLfloat* model_view); | 78 void ComputeModelViewTransform(GLfloat* model_view); |
79 | 79 |
80 SharedOpenGLContext opengl_context_; | 80 SharedOpenGLContext opengl_context_; |
81 int width_; | 81 int width_; |
82 int height_; | 82 int height_; |
83 GLuint shader_program_object_; // The compiled shaders. | 83 GLuint shader_program_object_; // The compiled shaders. |
84 GLint position_location_; // The position attribute location. | 84 GLint position_location_; // The position attribute location. |
85 GLint color_location_; // The color attribute location. | 85 GLint color_location_; // The color attribute location. |
86 GLint mvp_location_; // The Model-View-Projection composite matrix. | 86 GLint mvp_location_; // The Model-View-Projection composite matrix. |
87 GLuint cube_vbos_[3]; | 87 GLuint cube_vbos_[3]; |
88 GLfloat eye_[3]; // The eye point of the virtual camera. | 88 GLfloat eye_[3]; // The eye point of the virtual camera. |
89 // The orientation of the virtual camera stored as a quaternion. The | 89 // The orientation of the virtual camera stored as a quaternion. The |
90 // quaternion is laid out as {{x, y, z}, w}. | 90 // quaternion is laid out as {{x, y, z}, w}. |
91 GLfloat orientation_[4]; | 91 GLfloat orientation_[4]; |
92 GLfloat perspective_proj_[16]; | 92 GLfloat perspective_proj_[16]; |
93 GLfloat mvp_matrix_[16]; | 93 GLfloat mvp_matrix_[16]; |
94 }; | 94 }; |
95 | 95 |
96 } // namespace tumbler | 96 } // namespace tumbler |
97 | 97 |
98 #endif // EXAMPLES_TUMBLER_CUBE_H_ | 98 #endif // EXAMPLES_TUMBLER_CUBE_H_ |
99 | 99 |
OLD | NEW |