• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017 Google Inc. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef C_ARCORE_HELLOE_AR_PLANE_RENDERER_H_
18 #define C_ARCORE_HELLOE_AR_PLANE_RENDERER_H_
19 
20 #include <GLES2/gl2.h>
21 #include <GLES2/gl2ext.h>
22 #include <android/asset_manager.h>
23 #include <array>
24 #include <cstdint>
25 #include <cstdlib>
26 #include <string>
27 #include <vector>
28 
29 #include "arcore_c_api.h"
30 #include "platform_tools/android/apps/arcore/src/main/cpp/glm.h"
31 
32 namespace hello_ar {
33 
34 // PlaneRenderer renders ARCore plane type.
35     class PlaneRenderer {
36     public:
37         PlaneRenderer() = default;
38 
39         ~PlaneRenderer() = default;
40 
41         // Sets up OpenGL state used by the plane renderer.  Must be called on the
42         // OpenGL thread.
43         void InitializeGlContent(AAssetManager *asset_manager);
44 
45         // Draws the provided plane.
46         void Draw(const glm::mat4 &projection_mat, const glm::mat4 &view_mat,
47                   const ArSession *ar_session, const ArPlane *ar_plane,
48                   const glm::vec3 &color);
49 
50     private:
51         void UpdateForPlane(const ArSession *ar_session, const ArPlane *ar_plane);
52 
53         std::vector<glm::vec3> vertices_;
54         std::vector<GLushort> triangles_;
55         glm::mat4 model_mat_ = glm::mat4(1.0f);
56         glm::vec3 normal_vec_ = glm::vec3(0.0f);
57 
58         GLuint texture_id_;
59 
60         GLuint shader_program_;
61         GLint attri_vertices_;
62         GLint uniform_mvp_mat_;
63         GLint uniform_texture_;
64         GLint uniform_model_mat_;
65         GLint uniform_normal_vec_;
66         GLint uniform_color_;
67     };
68 }  // namespace hello_ar
69 
70 #endif  // C_ARCORE_HELLOE_AR_PLANE_RENDERER_H_
71