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_HELLO_AR_BACKGROUND_RENDERER_H_ 18 #define C_ARCORE_HELLO_AR_BACKGROUND_RENDERER_H_ 19 20 #include <GLES2/gl2.h> 21 #include <GLES2/gl2ext.h> 22 #include <cstdlib> 23 24 #include "arcore_c_api.h" 25 #include "platform_tools/android/apps/arcore/src/main/cpp/util.h" 26 27 namespace hello_ar { 28 29 // This class renders the passthrough camera image into the OpenGL frame. 30 class BackgroundRenderer { 31 public: 32 BackgroundRenderer() = default; 33 34 ~BackgroundRenderer() = default; 35 36 // Sets up OpenGL state. Must be called on the OpenGL thread and before any 37 // other methods below. 38 void InitializeGlContent(); 39 40 // Draws the background image. This methods must be called for every ArFrame 41 // returned by ArSession_update() to catch display geometry change events. 42 void Draw(const ArSession *session, const ArFrame *frame); 43 44 // Returns the generated texture name for the GL_TEXTURE_EXTERNAL_OES target. 45 GLuint GetTextureId() const; 46 47 private: 48 static constexpr int kNumVertices = 4; 49 50 GLuint shader_program_; 51 GLuint texture_id_; 52 53 GLuint attribute_vertices_; 54 GLuint attribute_uvs_; 55 GLuint uniform_texture_; 56 57 float transformed_uvs_[kNumVertices * 2]; 58 bool uvs_initialized_ = false; 59 }; 60 } // namespace hello_ar 61 #endif // C_ARCORE_HELLO_AR_BACKGROUND_RENDERER_H_ 62