Home | History | Annotate | Download | only in jni
      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 // MoreTeapotsRenderer.h
     19 // Renderer for teapots
     20 //--------------------------------------------------------------------------------
     21 #ifndef _MoreTeapotsRenderer_H
     22 #define _MoreTeapotsRenderer_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/moreteapotss/MoreTeapotsApplication"
     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_COLOR, 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 specular_color[4];
     74     float ambient_color[3];
     75 };
     76 
     77 class MoreTeapotsRenderer
     78 {
     79     int32_t num_indices_;
     80     int32_t num_vertices_;
     81     GLuint ibo_;
     82     GLuint vbo_;
     83     GLuint ubo_;
     84 
     85     SHADER_PARAMS shader_param_;
     86     bool LoadShaders( SHADER_PARAMS* params,
     87             const char* strVsh,
     88             const char* strFsh );
     89     bool LoadShadersES3( SHADER_PARAMS* params,
     90             const char* strVsh,
     91             const char* strFsh,
     92             std::map<std::string, std::string>&shaderParameters );
     93 
     94     ndk_helper::Mat4 mat_projection_;
     95     ndk_helper::Mat4 mat_view_;
     96     std::vector<ndk_helper::Mat4> vec_mat_models_;
     97     std::vector<ndk_helper::Vec3> vec_colors_;
     98     std::vector<ndk_helper::Vec2> vec_rotations_;
     99     std::vector<ndk_helper::Vec2> vec_current_rotations_;
    100 
    101     ndk_helper::TapCamera* camera_;
    102 
    103     int32_t teapot_x_;
    104     int32_t teapot_y_;
    105     int32_t teapot_z_;
    106     int32_t ubo_matrix_stride_;
    107     int32_t ubo_vector_stride_;
    108     bool geometry_instancing_support_;
    109     bool arb_support_;
    110 
    111     std::string ToString( const int32_t i );
    112 public:
    113     MoreTeapotsRenderer();
    114     virtual ~MoreTeapotsRenderer();
    115     void Init( const int32_t numX,
    116             const int32_t numY,
    117             const int32_t numZ );
    118     void Render();
    119     void Update( float dTime );
    120     bool Bind( ndk_helper::TapCamera* camera );
    121     void Unload();
    122     void UpdateViewport();
    123 };
    124 
    125 #endif
    126 
    127