1 /* 2 * Copyright (C) 2009 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 * This is a small port of the "San Angeles Observation" demo 17 * program for OpenGL ES 1.x. For more details, see: 18 * 19 * http://jet.ro/visuals/san-angeles-observation/ 20 * 21 * This program demonstrates how to use a GLSurfaceView from Java 22 * along with native OpenGL calls to perform frame rendering. 23 * 24 * Touching the screen will start/stop the animation. 25 * 26 * Note that the demo runs much faster on the emulator than on 27 * real devices, this is mainly due to the following facts: 28 * 29 * - the demo sends bazillions of polygons to OpenGL without 30 * even trying to do culling. Most of them are clearly out 31 * of view. 32 * 33 * - on a real device, the GPU bus is the real bottleneck 34 * that prevent the demo from getting acceptable performance. 35 * 36 * - the software OpenGL engine used in the emulator uses 37 * the system bus instead, and its code rocks :-) 38 * 39 * Fixing the program to send less polygons to the GPU is left 40 * as an exercise to the reader. As always, patches welcomed :-) 41 */ 42 package com.example.SanAngeles; 43 44 import javax.microedition.khronos.egl.EGLConfig; 45 import javax.microedition.khronos.opengles.GL10; 46 47 import android.app.Activity; 48 import android.content.Context; 49 import android.opengl.GLSurfaceView; 50 import android.os.Bundle; 51 import android.view.MotionEvent; 52 53 public class DemoActivity extends Activity { 54 @Override 55 protected void onCreate(Bundle savedInstanceState) { 56 super.onCreate(savedInstanceState); 57 mGLView = new DemoGLSurfaceView(this); 58 setContentView(mGLView); 59 } 60 61 @Override 62 protected void onPause() { 63 super.onPause(); 64 mGLView.onPause(); 65 } 66 67 @Override 68 protected void onResume() { 69 super.onResume(); 70 mGLView.onResume(); 71 } 72 73 private GLSurfaceView mGLView; 74 75 static { 76 System.loadLibrary("sanangeles"); 77 } 78 } 79 80 class DemoGLSurfaceView extends GLSurfaceView { 81 public DemoGLSurfaceView(Context context) { 82 super(context); 83 mRenderer = new DemoRenderer(); 84 setRenderer(mRenderer); 85 } 86 87 public boolean onTouchEvent(final MotionEvent event) { 88 if (event.getAction() == MotionEvent.ACTION_DOWN) { 89 nativePause(); 90 } 91 return true; 92 } 93 94 DemoRenderer mRenderer; 95 96 private static native void nativePause(); 97 } 98 99 class DemoRenderer implements GLSurfaceView.Renderer { 100 public void onSurfaceCreated(GL10 gl, EGLConfig config) { 101 nativeInit(); 102 } 103 104 public void onSurfaceChanged(GL10 gl, int w, int h) { 105 //gl.glViewport(0, 0, w, h); 106 nativeResize(w, h); 107 } 108 109 public void onDrawFrame(GL10 gl) { 110 nativeRender(); 111 } 112 113 private static native void nativeInit(); 114 private static native void nativeResize(int w, int h); 115 private static native void nativeRender(); 116 private static native void nativeDone(); 117 } 118