This source file includes following definitions.
- onSurfaceCreated
- getUrlToLoad
- onSurfaceChanged
- onDrawFrame
- getInstance
package com.gpac.Osmo4;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import android.util.Log;
public class Osmo4Renderer implements GLSurfaceView.Renderer {
private final GpacConfig gpacConfig;
private final static String LOG_RENDERER = Osmo4Renderer.class.getSimpleName();
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
if (instance == null) {
try {
Log.i(LOG_RENDERER, "Creating instance from thread " + Thread.currentThread());
instance = new GPACInstance(callback, 320, 430, gpacConfig, urlToLoad);
} catch (com.gpac.Osmo4.GPACInstanceInterface.GpacInstanceException e) {
Log.e(LOG_RENDERER, "Failed to create new GPAC instance !");
instance = null;
callback.onGPACError(e);
return;
}
if (callback != null)
callback.onGPACReady();
}
}
private GPACInstance instance = null;
private final String urlToLoad;
public synchronized String getUrlToLoad() {
return urlToLoad;
}
public Osmo4Renderer(GpacCallback callback, GpacConfig gpacConfig, String urlToLoad) {
this.callback = callback;
this.urlToLoad = urlToLoad;
this.gpacConfig = gpacConfig;
}
private final GpacCallback callback;
@Override
public void onSurfaceChanged(GL10 gl, int w, int h) {
if (instance != null) {
Log.i(LOG_RENDERER, "Surface changed from thread " + Thread.currentThread());
instance.resize(w, h);
}
}
private int frames;
private long startFrame = System.currentTimeMillis();
@Override
public void onDrawFrame(GL10 gl) {
if (instance != null) {
frames++;
if (frames % 1000 == 0) {
long now = System.currentTimeMillis();
Log.i(LOG_RENDERER, "Frames Per Second = " + ((now - startFrame) / 1000) + " fps");
this.startFrame = now;
}
instance.render();
}
}
synchronized GPACInstance getInstance() {
return instance;
}
}