Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.diamondtools.opengl;
- import javax.microedition.khronos.egl.EGLConfig;
- import javax.microedition.khronos.opengles.GL10;
- import android.app.Activity;
- import android.content.pm.ApplicationInfo;
- import android.content.pm.PackageManager.NameNotFoundException;
- import android.opengl.GLSurfaceView;
- import android.os.Bundle;
- import android.view.Window;
- import android.view.WindowManager;
- public class MainActivity extends Activity {
- static {
- System.loadLibrary("DiamondTools");
- }
- private native int Activity_Pause();
- private native int Activity_DrawFrame();
- private native int Activity_SurfaceChange(int width, int height);
- private native int Activity_SurfaceCreate(String filePath);
- class EngineRenderer implements GLSurfaceView.Renderer {
- public void Destroy() {
- Activity_Pause(); // Destroys and cleans up textures + native objects
- }
- @Override
- public void onDrawFrame(GL10 gl) {
- Activity_DrawFrame(); // Calls GLES draw routines
- }
- @Override
- public void onSurfaceChanged(GL10 gl, int width, int height) {
- Activity_SurfaceChange(width, height); // Set viewport, rebuilds camera matrix
- }
- @Override
- public void onSurfaceCreated(GL10 gl, EGLConfig config) {
- ApplicationInfo ai = null;
- try {
- ai = getPackageManager()
- .getApplicationInfo(getPackageName(), 0);
- } catch (NameNotFoundException e) {
- e.printStackTrace();
- }
- if (ai != null) {
- Activity_SurfaceCreate(ai.sourceDir); // Create native objects with path to APK for resources
- }
- }
- }
- private GLSurfaceView glSurfaceView = null;
- private EngineRenderer renderer = null;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- glSurfaceView = new GLSurfaceView(this);
- renderer = new EngineRenderer();
- glSurfaceView.setEGLContextClientVersion(2);
- glSurfaceView.setRenderer(renderer);
- glSurfaceView.setPreserveEGLContextOnPause(true); // Does nothing at all...
- setContentView(glSurfaceView);
- }
- @Override
- public void onPause() {
- super.onPause();
- if (renderer != null) {
- glSurfaceView.onPause();
- renderer.Destroy(); // Deconstruct the native objects + gl textures
- }
- }
- @Override
- public void onResume() {
- super.onResume();
- if (renderer != null) {
- glSurfaceView.onResume();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement