21 package com.arm.malideveloper.openglessdk.multisampledfbo;
23 import javax.microedition.khronos.egl.EGLConfig;
24 import javax.microedition.khronos.opengles.GL10;
26 import android.content.Context;
27 import android.opengl.GLSurfaceView;
28 import android.os.Bundle;
29 import android.util.Log;
30 import android.view.GestureDetector;
31 import android.view.KeyEvent;
32 import android.view.MotionEvent;
33 import android.view.ScaleGestureDetector;
34 import android.view.Window;
35 import android.view.WindowManager;
37 import com.arm.malideveloper.openglessdk.*;
39 class MultisampledFBOView
extends MaliSamplesView implements GestureDetector.OnGestureListener, ScaleGestureDetector.OnScaleGestureListener
41 private static final String TAG = MultisampledFBOView.class.getSimpleName();
42 private boolean initOk =
false;
44 private GestureDetector gestureDetector;
45 private ScaleGestureDetector scaleGestureDetector;
47 private float scaleFactor = 1.0f;
49 public MultisampledFBOView(Context context)
52 super(context, GlesVersion.GLES3);
54 gestureDetector =
new GestureDetector(context,
this);
55 scaleGestureDetector =
new ScaleGestureDetector(context,
this);
58 @Override
protected void setRendererCallback()
60 setRenderer(
new Renderer());
63 @Override
protected void destroyContextCallback()
65 MultisampledFBO.uninit();
68 @Override
public boolean onTouchEvent(MotionEvent ev)
70 this.gestureDetector.onTouchEvent(ev);
71 this.scaleGestureDetector.onTouchEvent(ev);
79 if (initOk) MultisampledFBO.step();
86 Log.d(TAG,
"Initialization complete.");
88 Log.e(TAG,
"Initialization FAILED!");
96 @Override
public boolean onDown(MotionEvent e)
101 @Override
public boolean onFling(MotionEvent e1, MotionEvent e2,
float velocityX,
float velocityY)
106 @Override
public void onLongPress(MotionEvent e)
108 MultisampledFBO.switchColor();
111 @Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX,
float distanceY)
113 if (e2.getAction() == MotionEvent.ACTION_MOVE)
114 MultisampledFBO.setDragRotation(distanceX, distanceY);
118 @Override
public void onShowPress(MotionEvent e)
122 @Override
public boolean onSingleTapUp(MotionEvent e)
124 MultisampledFBO.toggleAnim();
128 @Override
public boolean onScale(ScaleGestureDetector scaleGestureDetector)
130 scaleFactor *= scaleGestureDetector.getScaleFactor();
131 scaleFactor = Math.max(0.1f, Math.min(scaleFactor, 2.0f));
132 MultisampledFBO.setScaleFactor(scaleFactor);
136 @Override
public boolean onScaleBegin(ScaleGestureDetector arg0)
141 @Override
public void onScaleEnd(ScaleGestureDetector arg0)
148 boolean volUpInLongPress =
false;
149 boolean volDownInLongPress =
false;
151 MultisampledFBOView mView;
154 public static native
void step();
163 public static native
void uninit();
165 @Override
protected void onCreate(Bundle savedInstanceState)
167 super.onCreate(savedInstanceState);
169 this.requestWindowFeature(Window.FEATURE_NO_TITLE);
170 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
171 WindowManager.LayoutParams.FLAG_FULLSCREEN);
173 mView =
new MultisampledFBOView(getApplication());
174 setContentView(mView);
196 int action = event.getAction();
197 int keyCode = event.getKeyCode();
201 case KeyEvent.KEYCODE_VOLUME_UP:
202 if (action == KeyEvent.ACTION_DOWN && event.isLongPress())
204 volUpInLongPress =
true;
207 mView.queueEvent(
new Runnable()
217 if (action == KeyEvent.ACTION_UP)
219 if (!volUpInLongPress)
221 mView.queueEvent(
new Runnable()
232 volUpInLongPress =
false;
237 case KeyEvent.KEYCODE_VOLUME_DOWN:
238 if (action == KeyEvent.ACTION_DOWN && event.isLongPress())
240 volDownInLongPress =
true;
241 mView.queueEvent(
new Runnable()
250 if (action == KeyEvent.ACTION_UP)
252 if(!volDownInLongPress)
254 mView.queueEvent(
new Runnable()
265 volDownInLongPress =
false;
271 return super.dispatchKeyEvent(event);
278 System.loadLibrary(
"Native");
static native void step()
static native void setDragRotation(float rotationX, float rotationY)
static native void toggleTextureFiltering()
static native boolean init(int width, int height)
void onSurfaceCreated(GL10 gl, EGLConfig config)
static native void switchColor()
GLint GLsizei GLsizei height
void onSurfaceChanged(GL10 gl, int width, int height)
static native void setScaleFactor(float scaleFactor)
static native void uninit()
static native void switchSamples()
void onCreate(Bundle savedInstanceState)
static native void toggleAnim()
static native void switchTextureFormat()
static native void switchTextureSize()
void onDrawFrame(GL10 gl)
boolean dispatchKeyEvent(KeyEvent event)