Debian Codegraph @

build-system/integration-test/test-projects/ndkSanAngeles2/src/main/java/com/example/SanAngeles/DemoActivity.java

raw
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 android.app.Activity;
45 import android.content.Context;
46 import android.opengl.GLSurfaceView;
47 import android.os.Bundle;
48 import android.view.MotionEvent;
49
50 import javax.microedition.khronos.egl.EGLConfig;
51 import javax.microedition.khronos.opengles.GL10;
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 nativeTogglePauseResume();
90 }
91 return true;
92 }
93
94 @Override
95 public void onPause() {
96 super.onPause();
97 nativePause();
98 }
99
100 @Override
101 public void onResume() {
102 super.onResume();
103 nativeResume();
104 }
105
106
107 DemoRenderer mRenderer;
108
109 private static native void nativePause();
110 private static native void nativeResume();
111 private static native void nativeTogglePauseResume();
112 }
113
114 class DemoRenderer implements GLSurfaceView.Renderer {
115 public void onSurfaceCreated(GL10 gl, EGLConfig config) {
116 nativeInit();
117 }
118
119 public void onSurfaceChanged(GL10 gl, int w, int h) {
120 //gl.glViewport(0, 0, w, h);
121 nativeResize(w, h);
122 }
123
124 public void onDrawFrame(GL10 gl) {
125 nativeRender();
126 }
127
128 private static native void nativeInit();
129 private static native void nativeResize(int w, int h);
130 private static native void nativeRender();
131 private static native void nativeDone();
132 }