1 /* 2 * Copyright 2013 The Android Open Source Project 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 //-------------------------------------------------------------------------------- 18 // Teapot Renderer.h 19 // Renderer for teapots 20 //-------------------------------------------------------------------------------- 21 #ifndef _TEAPOTRENDERER_H 22 #define _TEAPOTRENDERER_H 23 24 //-------------------------------------------------------------------------------- 25 // Include files 26 //-------------------------------------------------------------------------------- 27 #include <jni.h> 28 #include <errno.h> 29 30 #include <vector> 31 32 #include <EGL/egl.h> 33 #include <GLES/gl.h> 34 35 #include <android/sensor.h> 36 #include <android/log.h> 37 #include <android_native_app_glue.h> 38 #include <android/native_window_jni.h> 39 #include <cpu-features.h> 40 41 #define CLASS_NAME "android/app/NativeActivity" 42 #define APPLICATION_CLASS_NAME "com/sample/teapot/TeapotApplication" 43 44 #include "NDKHelper.h" 45 46 #define BUFFER_OFFSET(i) ((char *)NULL + (i)) 47 48 struct TEAPOT_VERTEX 49 { 50 float pos[3]; 51 float normal[3]; 52 }; 53 54 enum SHADER_ATTRIBUTES 55 { 56 ATTRIB_VERTEX, ATTRIB_NORMAL, ATTRIB_UV, 57 }; 58 59 struct SHADER_PARAMS 60 { 61 GLuint program_; 62 GLuint light0_; 63 GLuint material_diffuse_; 64 GLuint material_ambient_; 65 GLuint material_specular_; 66 67 GLuint matrix_projection_; 68 GLuint matrix_view_; 69 }; 70 71 struct TEAPOT_MATERIALS 72 { 73 float diffuse_color[3]; 74 float specular_color[4]; 75 float ambient_color[3]; 76 }; 77 78 class TeapotRenderer 79 { 80 int32_t num_indices_; 81 int32_t num_vertices_; 82 GLuint ibo_; 83 GLuint vbo_; 84 85 SHADER_PARAMS shader_param_; 86 bool LoadShaders( SHADER_PARAMS* params, const char* strVsh, const char* strFsh ); 87 88 ndk_helper::Mat4 mat_projection_; 89 ndk_helper::Mat4 mat_view_; 90 ndk_helper::Mat4 mat_model_; 91 92 ndk_helper::TapCamera* camera_; 93 public: 94 TeapotRenderer(); 95 virtual ~TeapotRenderer(); 96 void Init(); 97 void Render(); 98 void Update( float dTime ); 99 bool Bind( ndk_helper::TapCamera* camera ); 100 void Unload(); 101 void UpdateViewport(); 102 }; 103 104 #endif 105 106