[DEV] android multiple instance testing
This commit is contained in:
parent
8fd060fd03
commit
547c9c4d65
@ -12,55 +12,158 @@ import android.app.Activity;
|
|||||||
import android.service.wallpaper.WallpaperService;
|
import android.service.wallpaper.WallpaperService;
|
||||||
import android.service.wallpaper.WallpaperService.Engine;
|
import android.service.wallpaper.WallpaperService.Engine;
|
||||||
|
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
public class Ewol {
|
public class Ewol {
|
||||||
public static final Ewol EWOL = getInstance();
|
private static int counterInstance = -1; // Global instance increment at eveny new instance
|
||||||
private static Ewol instance = null;
|
private int instanceID = -1; // local and private instance ID
|
||||||
|
|
||||||
/* Default constructor (why not ?)*/
|
/* Default constructor (why not ?)*/
|
||||||
private Ewol() {}
|
public Ewol()
|
||||||
/* Use singleton */
|
{
|
||||||
public static Ewol getInstance() {
|
// TODO : Set an unique intance ID
|
||||||
if(instance == null)
|
counterInstance ++;
|
||||||
instance = new Ewol();
|
instanceID = counterInstance;
|
||||||
return instance;
|
Log.d("Ewol", "new " + counterInstance + " : " + instanceID);
|
||||||
|
}
|
||||||
|
// internal Acces not at the native function ...
|
||||||
|
|
||||||
|
public <T extends Activity & EwolCallback> void setJavaVirtualMachineStart(T activityInstance)
|
||||||
|
{
|
||||||
|
// TODO : Get the instance ID here ...
|
||||||
|
EWsetJavaVirtualMachineStart(activityInstance);
|
||||||
|
}
|
||||||
|
public <T extends WallpaperService & EwolCallback> void setJavaVirtualMachineStartWallpaperEngine(T serviceInstance)
|
||||||
|
{
|
||||||
|
// TODO : Get the instance ID here ...
|
||||||
|
EWsetJavaVirtualMachineStartWallpaperEngine(serviceInstance);
|
||||||
|
}
|
||||||
|
public void setJavaVirtualMachineStop()
|
||||||
|
{
|
||||||
|
EWsetJavaVirtualMachineStop(instanceID);
|
||||||
|
}
|
||||||
|
public void paramSetArchiveDir(int mode, String myString)
|
||||||
|
{
|
||||||
|
Log.d("Ewol", "call : " + instanceID);
|
||||||
|
EWparamSetArchiveDir(instanceID, mode, myString);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static native <T extends Activity & EwolCallback> void setJavaVirtualMachineStart(T activityInstance);
|
|
||||||
public static native <T extends WallpaperService & EwolCallback> void setJavaVirtualMachineStartWallpaperEngine(T serviceInstance);
|
|
||||||
public static native void setJavaVirtualMachineStop();
|
|
||||||
public static native void paramSetArchiveDir(int mode, String myString);
|
|
||||||
|
|
||||||
public native void touchEvent();
|
|
||||||
// activity status
|
// activity status
|
||||||
public native void onCreate();
|
public void onCreate() { EWonCreate(instanceID); }
|
||||||
public native void onStart();
|
public void onStart() { EWonStart(instanceID); }
|
||||||
public native void onReStart();
|
public void onReStart() { EWonReStart(instanceID); }
|
||||||
public native void onResume();
|
public void onResume() { EWonResume(instanceID); }
|
||||||
public native void onPause();
|
public void onPause() { EWonPause(instanceID); }
|
||||||
public native void onStop();
|
public void onStop() { EWonStop(instanceID); }
|
||||||
public native void onDestroy();
|
public void onDestroy() { EWonDestroy(instanceID); }
|
||||||
// set display properties :
|
// set display properties :
|
||||||
public native void displayPropertyMetrics(float ratioX, float ratioY);
|
public void displayPropertyMetrics(float ratioX, float ratioY)
|
||||||
|
{
|
||||||
|
Log.d("Ewol", "call : " + instanceID);
|
||||||
|
EWdisplayPropertyMetrics(instanceID, ratioX, ratioY);
|
||||||
|
}
|
||||||
// IO native function :
|
// IO native function :
|
||||||
// Specific for the type of input : TOOL_TYPE_FINGER and TOOL_TYPE_STYLUS (work as the same)
|
// Specific for the type of input : TOOL_TYPE_FINGER and TOOL_TYPE_STYLUS (work as the same)
|
||||||
public native void inputEventMotion(int pointerID, float x, float y);
|
public void inputEventMotion(int pointerID, float x, float y)
|
||||||
public native void inputEventState(int pointerID, boolean isDown, float x, float y);
|
{
|
||||||
|
Log.d("Ewol", "call : " + instanceID);
|
||||||
|
EWinputEventMotion(instanceID, pointerID, x, y);
|
||||||
|
}
|
||||||
|
public void inputEventState(int pointerID, boolean isDown, float x, float y)
|
||||||
|
{
|
||||||
|
Log.d("Ewol", "call : " + instanceID);
|
||||||
|
EWinputEventState(instanceID, pointerID, isDown, x, y);
|
||||||
|
}
|
||||||
// Specific for the type of input : TOOL_TYPE_MOUSE
|
// Specific for the type of input : TOOL_TYPE_MOUSE
|
||||||
public native void mouseEventMotion(int pointerID, float x, float y);
|
public void mouseEventMotion(int pointerID, float x, float y)
|
||||||
public native void mouseEventState(int pointerID, boolean isDown, float x, float y);
|
{
|
||||||
|
Log.d("Ewol", "call : " + instanceID);
|
||||||
|
EWmouseEventMotion(instanceID, pointerID, x, y);
|
||||||
|
}
|
||||||
|
public void mouseEventState(int pointerID, boolean isDown, float x, float y)
|
||||||
|
{
|
||||||
|
Log.d("Ewol", "call : " + instanceID);
|
||||||
|
EWmouseEventState(instanceID, pointerID, isDown, x, y);
|
||||||
|
}
|
||||||
// other unknow event ...
|
// other unknow event ...
|
||||||
public native void unknowEvent(int eventID);
|
public void unknowEvent(int eventID)
|
||||||
|
{
|
||||||
|
Log.d("Ewol", "call : " + instanceID);
|
||||||
|
EWunknowEvent(instanceID, eventID);
|
||||||
|
}
|
||||||
|
|
||||||
public native void keyboardEventMove(int type, boolean isDown);
|
public void keyboardEventMove(int type, boolean isDown)
|
||||||
public native void keyboardEventKey(int uniChar, boolean isDown);
|
{
|
||||||
|
EWkeyboardEventMove(instanceID, type, isDown);
|
||||||
|
}
|
||||||
|
public void keyboardEventKey(int uniChar, boolean isDown)
|
||||||
|
{
|
||||||
|
EWkeyboardEventKey(instanceID, uniChar, isDown);
|
||||||
|
}
|
||||||
|
|
||||||
// Audio section ...
|
// Audio section ...
|
||||||
public native void audioPlayback(short[] bufferData, int frames, int nbChannels);
|
public void audioPlayback(short[] bufferData, int frames, int nbChannels)
|
||||||
|
{
|
||||||
|
EWaudioPlayback(instanceID, bufferData, frames, nbChannels);
|
||||||
|
}
|
||||||
|
|
||||||
public native void keyboardEventKeySystem(int keyVal, boolean isDown);
|
public void keyboardEventKeySystem(int keyVal, boolean isDown)
|
||||||
|
{
|
||||||
|
EWkeyboardEventKeySystem(instanceID, keyVal, isDown);
|
||||||
|
}
|
||||||
// renderer Event :
|
// renderer Event :
|
||||||
public native void renderInit();
|
public void renderInit()
|
||||||
public native void renderResize(int w, int h);
|
{
|
||||||
public native void renderDraw();
|
Log.d("Ewol", "call : " + instanceID);
|
||||||
|
EWrenderInit(instanceID);
|
||||||
|
}
|
||||||
|
public void renderResize(int w, int h)
|
||||||
|
{
|
||||||
|
Log.d("Ewol", "call : " + instanceID);
|
||||||
|
EWrenderResize(instanceID, w, h);
|
||||||
|
}
|
||||||
|
public void renderDraw()
|
||||||
|
{
|
||||||
|
Log.d("Ewol", "call : " + instanceID);
|
||||||
|
EWrenderDraw(instanceID);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private native <T extends Activity & EwolCallback> void EWsetJavaVirtualMachineStart(T activityInstance);
|
||||||
|
private native <T extends WallpaperService & EwolCallback> void EWsetJavaVirtualMachineStartWallpaperEngine(T serviceInstance);
|
||||||
|
private native void EWsetJavaVirtualMachineStop(int instanceId);
|
||||||
|
private native void EWparamSetArchiveDir(int instanceId, int mode, String myString);
|
||||||
|
|
||||||
|
// activity status
|
||||||
|
private native void EWonCreate(int instanceId);
|
||||||
|
private native void EWonStart(int instanceId);
|
||||||
|
private native void EWonReStart(int instanceId);
|
||||||
|
private native void EWonResume(int instanceId);
|
||||||
|
private native void EWonPause(int instanceId);
|
||||||
|
private native void EWonStop(int instanceId);
|
||||||
|
private native void EWonDestroy(int instanceId);
|
||||||
|
// set display properties :
|
||||||
|
private native void EWdisplayPropertyMetrics(int instanceId, float ratioX, float ratioY);
|
||||||
|
// IO native function :
|
||||||
|
// Specific for the type of input : TOOL_TYPE_FINGER and TOOL_TYPE_STYLUS (work as the same)
|
||||||
|
private native void EWinputEventMotion(int instanceId, int pointerID, float x, float y);
|
||||||
|
private native void EWinputEventState(int instanceId, int pointerID, boolean isDown, float x, float y);
|
||||||
|
// Specific for the type of input : TOOL_TYPE_MOUSE
|
||||||
|
private native void EWmouseEventMotion(int instanceId, int pointerID, float x, float y);
|
||||||
|
private native void EWmouseEventState(int instanceId, int pointerID, boolean isDown, float x, float y);
|
||||||
|
// other unknow event ...
|
||||||
|
private native void EWunknowEvent(int instanceId, int eventID);
|
||||||
|
|
||||||
|
private native void EWkeyboardEventMove(int instanceId, int type, boolean isDown);
|
||||||
|
private native void EWkeyboardEventKey(int instanceId, int uniChar, boolean isDown);
|
||||||
|
|
||||||
|
// Audio section ...
|
||||||
|
public native void EWaudioPlayback(int instanceId, short[] bufferData, int frames, int nbChannels);
|
||||||
|
|
||||||
|
private native void EWkeyboardEventKeySystem(int instanceId, int keyVal, boolean isDown);
|
||||||
|
// renderer Event :
|
||||||
|
private native void EWrenderInit(int instanceId);
|
||||||
|
private native void EWrenderResize(int instanceId, int w, int h);
|
||||||
|
private native void EWrenderDraw(int instanceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,21 +39,27 @@ import android.util.DisplayMetrics;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.ewol.Ewol.EWOL;
|
import org.ewol.Ewol;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Class :
|
* @brief Class :
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public abstract class EwolActivity extends Activity implements EwolCallback, EwolConstants{
|
public abstract class EwolActivity extends Activity implements EwolCallback, EwolConstants
|
||||||
|
{
|
||||||
private EwolSurfaceViewGL mGLView;
|
private EwolSurfaceViewGL mGLView;
|
||||||
private EwolAudioTask mStreams;
|
private EwolAudioTask mStreams;
|
||||||
private Thread mAudioThread;
|
private Thread mAudioThread;
|
||||||
|
private Ewol EWOL;
|
||||||
static {
|
static {
|
||||||
System.loadLibrary("ewol");
|
System.loadLibrary("ewol");
|
||||||
}
|
}
|
||||||
|
public EwolActivity()
|
||||||
|
{
|
||||||
|
EWOL = new Ewol();
|
||||||
|
// set the java evironement in the C sources :
|
||||||
|
EWOL.setJavaVirtualMachineStart(this);
|
||||||
|
}
|
||||||
|
|
||||||
protected void initApkPath(String org, String vendor, String project) {
|
protected void initApkPath(String org, String vendor, String project) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
@ -70,19 +76,16 @@ public abstract class EwolActivity extends Activity implements EwolCallback, Ewo
|
|||||||
throw new RuntimeException("Unable to locate assets, aborting...");
|
throw new RuntimeException("Unable to locate assets, aborting...");
|
||||||
}
|
}
|
||||||
apkFilePath = appInfo.sourceDir;
|
apkFilePath = appInfo.sourceDir;
|
||||||
Ewol.paramSetArchiveDir(0, apkFilePath);
|
EWOL.paramSetArchiveDir(0, apkFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void onCreate(Bundle savedInstanceState)
|
@Override protected void onCreate(Bundle savedInstanceState)
|
||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
// set the java evironement in the C sources :
|
|
||||||
Ewol.setJavaVirtualMachineStart(this);
|
|
||||||
|
|
||||||
// Load the application directory
|
// Load the application directory
|
||||||
Ewol.paramSetArchiveDir(1, getFilesDir().toString());
|
EWOL.paramSetArchiveDir(1, getFilesDir().toString());
|
||||||
Ewol.paramSetArchiveDir(2, getCacheDir().toString());
|
EWOL.paramSetArchiveDir(2, getCacheDir().toString());
|
||||||
// to enable extarnal storage: add in the manifest the restriction needed ...
|
// to enable extarnal storage: add in the manifest the restriction needed ...
|
||||||
//packageManager.checkPermission("android.permission.READ_SMS", myPackage) == PERMISSION_GRANTED;
|
//packageManager.checkPermission("android.permission.READ_SMS", myPackage) == PERMISSION_GRANTED;
|
||||||
//Ewol.paramSetArchiveDir(3, getExternalCacheDir().toString());
|
//Ewol.paramSetArchiveDir(3, getExternalCacheDir().toString());
|
||||||
@ -104,10 +107,10 @@ public abstract class EwolActivity extends Activity implements EwolCallback, Ewo
|
|||||||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
|
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
|
||||||
|
|
||||||
// create bsurface system
|
// create bsurface system
|
||||||
mGLView = new EwolSurfaceViewGL(this);
|
mGLView = new EwolSurfaceViewGL(this, EWOL);
|
||||||
|
|
||||||
// create element audio ...
|
// create element audio ...
|
||||||
mStreams = new EwolAudioTask();
|
mStreams = new EwolAudioTask(EWOL);
|
||||||
|
|
||||||
setContentView(mGLView);
|
setContentView(mGLView);
|
||||||
}
|
}
|
||||||
@ -166,7 +169,7 @@ public abstract class EwolActivity extends Activity implements EwolCallback, Ewo
|
|||||||
// call C
|
// call C
|
||||||
EWOL.onDestroy();
|
EWOL.onDestroy();
|
||||||
// Remove the java Virtual machine pointer form the C code
|
// Remove the java Virtual machine pointer form the C code
|
||||||
Ewol.setJavaVirtualMachineStop();
|
EWOL.setJavaVirtualMachineStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override protected void finalize() throws Throwable
|
@Override protected void finalize() throws Throwable
|
||||||
@ -194,8 +197,7 @@ public abstract class EwolActivity extends Activity implements EwolCallback, Ewo
|
|||||||
|
|
||||||
public void eventNotifier(String[] args)
|
public void eventNotifier(String[] args)
|
||||||
{
|
{
|
||||||
// just for the test ...
|
// TODO : ...
|
||||||
EWOL.touchEvent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void orientationUpdate(int screenMode)
|
public void orientationUpdate(int screenMode)
|
||||||
@ -211,6 +213,11 @@ public abstract class EwolActivity extends Activity implements EwolCallback, Ewo
|
|||||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void titleSet(String value)
|
||||||
|
{
|
||||||
|
setTitle(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ import android.media.AudioRecord;
|
|||||||
/* no need in same package... */
|
/* no need in same package... */
|
||||||
//import org.ewol.NativeInterface;
|
//import org.ewol.NativeInterface;
|
||||||
|
|
||||||
import static org.ewol.Ewol.EWOL;
|
import org.ewol.Ewol;
|
||||||
|
|
||||||
|
|
||||||
public class EwolAudioTask implements Runnable, EwolConstants
|
public class EwolAudioTask implements Runnable, EwolConstants
|
||||||
@ -25,12 +25,13 @@ public class EwolAudioTask implements Runnable, EwolConstants
|
|||||||
public static final int SAMPLE_FREQ_44100 = 44100;
|
public static final int SAMPLE_FREQ_44100 = 44100;
|
||||||
private boolean m_stopAudioThreads = false;
|
private boolean m_stopAudioThreads = false;
|
||||||
private AudioTrack m_musicTrack = null;
|
private AudioTrack m_musicTrack = null;
|
||||||
|
private Ewol EWOL;
|
||||||
|
|
||||||
// constructor :
|
// constructor :
|
||||||
public EwolAudioTask()
|
public EwolAudioTask(Ewol ewolInstance)
|
||||||
{
|
{
|
||||||
// nothing to do ...
|
EWOL = ewolInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
|
@ -13,5 +13,6 @@ public interface EwolCallback {
|
|||||||
public void keyboardUpdate(boolean show);
|
public void keyboardUpdate(boolean show);
|
||||||
public void eventNotifier(String[] args);
|
public void eventNotifier(String[] args);
|
||||||
public void orientationUpdate(int screenMode);
|
public void orientationUpdate(int screenMode);
|
||||||
|
public void titleSet(String value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ import android.opengl.GLSurfaceView;
|
|||||||
/* no need in same package... */
|
/* no need in same package... */
|
||||||
//import org.ewol.Ewol;
|
//import org.ewol.Ewol;
|
||||||
|
|
||||||
import static org.ewol.Ewol.EWOL;
|
import org.ewol.Ewol;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Class :
|
* @brief Class :
|
||||||
@ -25,6 +25,12 @@ import static org.ewol.Ewol.EWOL;
|
|||||||
*/
|
*/
|
||||||
public class EwolRendererGL implements GLSurfaceView.Renderer
|
public class EwolRendererGL implements GLSurfaceView.Renderer
|
||||||
{
|
{
|
||||||
|
private Ewol EWOL;
|
||||||
|
|
||||||
|
public EwolRendererGL(Ewol ewolInstance)
|
||||||
|
{
|
||||||
|
EWOL = ewolInstance;
|
||||||
|
}
|
||||||
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
||||||
EWOL.renderInit();
|
EWOL.renderInit();
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ import android.os.Bundle;
|
|||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
|
||||||
import static org.ewol.Ewol.EWOL;
|
import org.ewol.Ewol;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Class :
|
* @brief Class :
|
||||||
@ -32,10 +32,12 @@ public class EwolSurfaceViewGL extends GLSurfaceView implements EwolConstants {
|
|||||||
private boolean inputDown1 = false;
|
private boolean inputDown1 = false;
|
||||||
private boolean inputDown2 = false;
|
private boolean inputDown2 = false;
|
||||||
private boolean inputDown3 = false;
|
private boolean inputDown3 = false;
|
||||||
|
private Ewol EWOL;
|
||||||
|
|
||||||
public EwolSurfaceViewGL(Context context) {
|
public EwolSurfaceViewGL(Context context, Ewol ewolInstance) {
|
||||||
// super must be first statement in constructor
|
// super must be first statement in constructor
|
||||||
super(context);
|
super(context);
|
||||||
|
EWOL = ewolInstance;
|
||||||
/*
|
/*
|
||||||
List of the Android API :
|
List of the Android API :
|
||||||
Android 4.1, 4.1.1 16 JELLY_BEAN Platform Highlights
|
Android 4.1, 4.1.1 16 JELLY_BEAN Platform Highlights
|
||||||
@ -62,7 +64,7 @@ public class EwolSurfaceViewGL extends GLSurfaceView implements EwolConstants {
|
|||||||
setEGLContextClientVersion(2);
|
setEGLContextClientVersion(2);
|
||||||
|
|
||||||
// je n'ai pas compris ...
|
// je n'ai pas compris ...
|
||||||
m_ewolDrawer = new EwolRendererGL();
|
m_ewolDrawer = new EwolRendererGL(EWOL);
|
||||||
setRenderer(m_ewolDrawer);
|
setRenderer(m_ewolDrawer);
|
||||||
|
|
||||||
// Can get the focus ==> get keyboard from JAVA :
|
// Can get the focus ==> get keyboard from JAVA :
|
||||||
|
@ -22,11 +22,12 @@ import android.view.SurfaceHolder;
|
|||||||
import org.ewol.EwolSurfaceViewGL;
|
import org.ewol.EwolSurfaceViewGL;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
import static org.ewol.Ewol.EWOL;
|
import org.ewol.Ewol;
|
||||||
|
|
||||||
public abstract class EwolWallpaper extends WallpaperService implements EwolCallback, EwolConstants
|
public abstract class EwolWallpaper extends WallpaperService implements EwolCallback, EwolConstants
|
||||||
{
|
{
|
||||||
private GLEngine mGLView;
|
private GLEngine mGLView;
|
||||||
|
private Ewol EWOL;
|
||||||
static {
|
static {
|
||||||
System.loadLibrary("ewol");
|
System.loadLibrary("ewol");
|
||||||
}
|
}
|
||||||
@ -46,17 +47,18 @@ public abstract class EwolWallpaper extends WallpaperService implements EwolCall
|
|||||||
throw new RuntimeException("Unable to locate assets, aborting...");
|
throw new RuntimeException("Unable to locate assets, aborting...");
|
||||||
}
|
}
|
||||||
apkFilePath = appInfo.sourceDir;
|
apkFilePath = appInfo.sourceDir;
|
||||||
Ewol.paramSetArchiveDir(0, apkFilePath);
|
EWOL.paramSetArchiveDir(0, apkFilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public Engine onCreateEngine() {
|
@Override public Engine onCreateEngine() {
|
||||||
|
|
||||||
|
EWOL = new Ewol();
|
||||||
// set the java evironement in the C sources :
|
// set the java evironement in the C sources :
|
||||||
Ewol.setJavaVirtualMachineStartWallpaperEngine(this);
|
EWOL.setJavaVirtualMachineStartWallpaperEngine(this);
|
||||||
|
|
||||||
// Load the application directory
|
// Load the application directory
|
||||||
Ewol.paramSetArchiveDir(1, getFilesDir().toString());
|
EWOL.paramSetArchiveDir(1, getFilesDir().toString());
|
||||||
Ewol.paramSetArchiveDir(2, getCacheDir().toString());
|
EWOL.paramSetArchiveDir(2, getCacheDir().toString());
|
||||||
// to enable extarnal storage: add in the manifest the restriction needed ...
|
// to enable extarnal storage: add in the manifest the restriction needed ...
|
||||||
//packageManager.checkPermission("android.permission.READ_SMS", myPackage) == PERMISSION_GRANTED;
|
//packageManager.checkPermission("android.permission.READ_SMS", myPackage) == PERMISSION_GRANTED;
|
||||||
//Ewol.paramSetArchiveDir(3, getExternalCacheDir().toString());
|
//Ewol.paramSetArchiveDir(3, getExternalCacheDir().toString());
|
||||||
@ -70,7 +72,7 @@ public abstract class EwolWallpaper extends WallpaperService implements EwolCall
|
|||||||
EWOL.onCreate();
|
EWOL.onCreate();
|
||||||
|
|
||||||
// create bsurface system
|
// create bsurface system
|
||||||
mGLView = new GLEngine();
|
mGLView = new GLEngine(EWOL);
|
||||||
|
|
||||||
return mGLView;
|
return mGLView;
|
||||||
}
|
}
|
||||||
@ -79,12 +81,18 @@ public abstract class EwolWallpaper extends WallpaperService implements EwolCall
|
|||||||
|
|
||||||
public class GLEngine extends Engine
|
public class GLEngine extends Engine
|
||||||
{
|
{
|
||||||
|
private Ewol EWOL;
|
||||||
|
public GLEngine(Ewol ewolInstance)
|
||||||
|
{
|
||||||
|
EWOL = ewolInstance;
|
||||||
|
}
|
||||||
|
|
||||||
class WallpaperGLSurfaceView extends EwolSurfaceViewGL
|
class WallpaperGLSurfaceView extends EwolSurfaceViewGL
|
||||||
{
|
{
|
||||||
private static final String TAG = "WallpaperGLSurfaceView";
|
private static final String TAG = "WallpaperGLSurfaceView";
|
||||||
WallpaperGLSurfaceView(Context context)
|
WallpaperGLSurfaceView(Context context, Ewol ewolInstance)
|
||||||
{
|
{
|
||||||
super(context);
|
super(context, ewolInstance);
|
||||||
Log.d(TAG, "WallpaperGLSurfaceView(" + context + ")");
|
Log.d(TAG, "WallpaperGLSurfaceView(" + context + ")");
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
@ -108,7 +116,7 @@ public abstract class EwolWallpaper extends WallpaperService implements EwolCall
|
|||||||
Log.d(TAG, "onCreate(" + surfaceHolder + ")");
|
Log.d(TAG, "onCreate(" + surfaceHolder + ")");
|
||||||
super.onCreate(surfaceHolder);
|
super.onCreate(surfaceHolder);
|
||||||
|
|
||||||
glSurfaceView = new WallpaperGLSurfaceView(EwolWallpaper.this);
|
glSurfaceView = new WallpaperGLSurfaceView(EwolWallpaper.this, EWOL);
|
||||||
|
|
||||||
// Check if the system supports OpenGL ES 2.0.
|
// Check if the system supports OpenGL ES 2.0.
|
||||||
final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
||||||
@ -181,12 +189,16 @@ public abstract class EwolWallpaper extends WallpaperService implements EwolCall
|
|||||||
public void eventNotifier(String[] args)
|
public void eventNotifier(String[] args)
|
||||||
{
|
{
|
||||||
// just for the test ...
|
// just for the test ...
|
||||||
EWOL.touchEvent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void orientationUpdate(int screenMode)
|
public void orientationUpdate(int screenMode)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
public void titleSet(String value)
|
||||||
|
{
|
||||||
|
// no title in the wallpaper ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -1,189 +0,0 @@
|
|||||||
/**
|
|
||||||
* @author Edouard DUPIN
|
|
||||||
*
|
|
||||||
* @copyright 2011, Edouard DUPIN, all right reserved
|
|
||||||
*
|
|
||||||
* @license BSD v3 (see license file)
|
|
||||||
*/
|
|
||||||
package org.ewol;
|
|
||||||
|
|
||||||
import android.app.ActivityManager;
|
|
||||||
import android.content.pm.ApplicationInfo;
|
|
||||||
import android.content.pm.ConfigurationInfo;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.opengl.GLSurfaceView;
|
|
||||||
import android.opengl.GLSurfaceView.Renderer;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.service.wallpaper.WallpaperService;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.SurfaceHolder;
|
|
||||||
import org.ewol.EwolSurfaceViewGL;
|
|
||||||
|
|
||||||
import static org.ewol.Ewol.EWOL;
|
|
||||||
|
|
||||||
public abstract class EwolWallpaperService extends WallpaperService implements EwolCallback, EwolConstants
|
|
||||||
{
|
|
||||||
private GLEngine mGLView;
|
|
||||||
static {
|
|
||||||
System.loadLibrary("ewol");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void initApkPath(String org, String vendor, String project) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
sb.append(org).append(".");
|
|
||||||
sb.append(vendor).append(".");
|
|
||||||
sb.append(project);
|
|
||||||
String apkFilePath = null;
|
|
||||||
ApplicationInfo appInfo = null;
|
|
||||||
PackageManager packMgmr = getPackageManager();
|
|
||||||
try {
|
|
||||||
appInfo = packMgmr.getApplicationInfo(sb.toString(), 0);
|
|
||||||
} catch (NameNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
throw new RuntimeException("Unable to locate assets, aborting...");
|
|
||||||
}
|
|
||||||
apkFilePath = appInfo.sourceDir;
|
|
||||||
Ewol.paramSetArchiveDir(0, apkFilePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public Engine onCreateEngine() {
|
|
||||||
|
|
||||||
// set the java evironement in the C sources :
|
|
||||||
Ewol.setJavaVirtualMachineStartWallpaperEngine(this);
|
|
||||||
|
|
||||||
// Load the application directory
|
|
||||||
Ewol.paramSetArchiveDir(1, getFilesDir().toString());
|
|
||||||
Ewol.paramSetArchiveDir(2, getCacheDir().toString());
|
|
||||||
// to enable extarnal storage: add in the manifest the restriction needed ...
|
|
||||||
//packageManager.checkPermission("android.permission.READ_SMS", myPackage) == PERMISSION_GRANTED;
|
|
||||||
//Ewol.paramSetArchiveDir(3, getExternalCacheDir().toString());
|
|
||||||
|
|
||||||
|
|
||||||
//! DisplayMetrics metrics = new DisplayMetrics();
|
|
||||||
//! getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
|
||||||
//! EWOL.displayPropertyMetrics(metrics.xdpi, metrics.ydpi);
|
|
||||||
|
|
||||||
// call C init ...
|
|
||||||
EWOL.onCreate();
|
|
||||||
|
|
||||||
// create bsurface system
|
|
||||||
mGLView = new GLEngine();
|
|
||||||
|
|
||||||
return mGLView;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class GLEngine extends Engine
|
|
||||||
{
|
|
||||||
class WallpaperGLSurfaceView extends EwolSurfaceViewGL
|
|
||||||
{
|
|
||||||
private static final String TAG = "WallpaperGLSurfaceView";
|
|
||||||
WallpaperGLSurfaceView(Context context)
|
|
||||||
{
|
|
||||||
super(context);
|
|
||||||
Log.d(TAG, "WallpaperGLSurfaceView(" + context + ")");
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public SurfaceHolder getHolder()
|
|
||||||
{
|
|
||||||
Log.d(TAG, "getHolder(): returning " + getSurfaceHolder());
|
|
||||||
return getSurfaceHolder();
|
|
||||||
}
|
|
||||||
public void onDestroy()
|
|
||||||
{
|
|
||||||
Log.d(TAG, "onDestroy()");
|
|
||||||
super.onDetachedFromWindow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String TAG = "GLEngine";
|
|
||||||
private WallpaperGLSurfaceView glSurfaceView;
|
|
||||||
private boolean rendererHasBeenSet;
|
|
||||||
|
|
||||||
@Override public void onCreate(SurfaceHolder surfaceHolder)
|
|
||||||
{
|
|
||||||
Log.d(TAG, "onCreate(" + surfaceHolder + ")");
|
|
||||||
super.onCreate(surfaceHolder);
|
|
||||||
|
|
||||||
glSurfaceView = new WallpaperGLSurfaceView(EwolWallpaperService.this);
|
|
||||||
|
|
||||||
// Check if the system supports OpenGL ES 2.0.
|
|
||||||
final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
|
|
||||||
final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
|
|
||||||
final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;
|
|
||||||
|
|
||||||
if (false==supportsEs2) {
|
|
||||||
Log.d("LiveWallpaper", "does not support board with only open GL ES 1");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Request an OpenGL ES 2.0 compatible context.
|
|
||||||
//setEGLContextClientVersion(2);
|
|
||||||
|
|
||||||
// On Honeycomb+ devices, this improves the performance when
|
|
||||||
// leaving and resuming the live wallpaper.
|
|
||||||
setPreserveEGLContextOnPause(true);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public void onVisibilityChanged(boolean visible)
|
|
||||||
{
|
|
||||||
Log.d(TAG, "onVisibilityChanged(" + visible + ")");
|
|
||||||
super.onVisibilityChanged(visible);
|
|
||||||
if (rendererHasBeenSet) {
|
|
||||||
if (visible) {
|
|
||||||
glSurfaceView.onResume();
|
|
||||||
} else {
|
|
||||||
glSurfaceView.onPause();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public void onDestroy()
|
|
||||||
{
|
|
||||||
Log.d(TAG, "onDestroy()");
|
|
||||||
super.onDestroy();
|
|
||||||
glSurfaceView.onDestroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setRenderer(Renderer renderer)
|
|
||||||
{
|
|
||||||
Log.d(TAG, "setRenderer(" + renderer + ")");
|
|
||||||
glSurfaceView.setRenderer(renderer);
|
|
||||||
rendererHasBeenSet = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setPreserveEGLContextOnPause(boolean preserve)
|
|
||||||
{
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
|
||||||
Log.d(TAG, "setPreserveEGLContextOnPause(" + preserve + ")");
|
|
||||||
glSurfaceView.setPreserveEGLContextOnPause(preserve);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setEGLContextClientVersion(int version)
|
|
||||||
{
|
|
||||||
Log.d(TAG, "setEGLContextClientVersion(" + version + ")");
|
|
||||||
glSurfaceView.setEGLContextClientVersion(version);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void keyboardUpdate(boolean show)
|
|
||||||
{
|
|
||||||
// never display keyboard on wallpaer...
|
|
||||||
}
|
|
||||||
|
|
||||||
public void eventNotifier(String[] args)
|
|
||||||
{
|
|
||||||
// just for the test ...
|
|
||||||
EWOL.touchEvent();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void orientationUpdate(int screenMode)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,73 +0,0 @@
|
|||||||
package org.ewol;
|
|
||||||
|
|
||||||
import org.ewol.LessonTwoRenderer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class implements our custom renderer. Note that the GL10 parameter passed in is unused for OpenGL ES 2.0
|
|
||||||
* renderers -- the static class GLES20 is used instead.
|
|
||||||
*/
|
|
||||||
public class LessonThreeRenderer extends LessonTwoRenderer
|
|
||||||
{
|
|
||||||
protected String getVertexShader()
|
|
||||||
{
|
|
||||||
// Define our per-pixel lighting shader.
|
|
||||||
final String perPixelVertexShader =
|
|
||||||
"uniform mat4 u_MVPMatrix; \n" // A constant representing the combined model/view/projection matrix.
|
|
||||||
+ "uniform mat4 u_MVMatrix; \n" // A constant representing the combined model/view matrix.
|
|
||||||
|
|
||||||
+ "attribute vec4 a_Position; \n" // Per-vertex position information we will pass in.
|
|
||||||
+ "attribute vec4 a_Color; \n" // Per-vertex color information we will pass in.
|
|
||||||
+ "attribute vec3 a_Normal; \n" // Per-vertex normal information we will pass in.
|
|
||||||
|
|
||||||
+ "varying vec3 v_Position; \n" // This will be passed into the fragment shader.
|
|
||||||
+ "varying vec4 v_Color; \n" // This will be passed into the fragment shader.
|
|
||||||
+ "varying vec3 v_Normal; \n" // This will be passed into the fragment shader.
|
|
||||||
|
|
||||||
// The entry point for our vertex shader.
|
|
||||||
+ "void main() \n"
|
|
||||||
+ "{ \n"
|
|
||||||
// Transform the vertex into eye space.
|
|
||||||
+ " v_Position = vec3(u_MVMatrix * a_Position); \n"
|
|
||||||
// Pass through the color.
|
|
||||||
+ " v_Color = a_Color; \n"
|
|
||||||
// Transform the normal's orientation into eye space.
|
|
||||||
+ " v_Normal = vec3(u_MVMatrix * vec4(a_Normal, 0.0)); \n"
|
|
||||||
// gl_Position is a special variable used to store the final position.
|
|
||||||
// Multiply the vertex by the matrix to get the final point in normalized screen coordinates.
|
|
||||||
+ " gl_Position = u_MVPMatrix * a_Position; \n"
|
|
||||||
+ "} \n";
|
|
||||||
|
|
||||||
return perPixelVertexShader;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getFragmentShader()
|
|
||||||
{
|
|
||||||
final String perPixelFragmentShader =
|
|
||||||
"precision mediump float; \n" // Set the default precision to medium. We don't need as high of a
|
|
||||||
// precision in the fragment shader.
|
|
||||||
+ "uniform vec3 u_LightPos; \n" // The position of the light in eye space.
|
|
||||||
|
|
||||||
+ "varying vec3 v_Position; \n" // Interpolated position for this fragment.
|
|
||||||
+ "varying vec4 v_Color; \n" // This is the color from the vertex shader interpolated across the
|
|
||||||
// triangle per fragment.
|
|
||||||
+ "varying vec3 v_Normal; \n" // Interpolated normal for this fragment.
|
|
||||||
|
|
||||||
// The entry point for our fragment shader.
|
|
||||||
+ "void main() \n"
|
|
||||||
+ "{ \n"
|
|
||||||
// Will be used for attenuation.
|
|
||||||
+ " float distance = length(u_LightPos - v_Position); \n"
|
|
||||||
// Get a lighting direction vector from the light to the vertex.
|
|
||||||
+ " vec3 lightVector = normalize(u_LightPos - v_Position); \n"
|
|
||||||
// Calculate the dot product of the light vector and vertex normal. If the normal and light vector are
|
|
||||||
// pointing in the same direction then it will get max illumination.
|
|
||||||
+ " float diffuse = max(dot(v_Normal, lightVector), 0.1); \n"
|
|
||||||
// Add attenuation.
|
|
||||||
+ " diffuse = diffuse * (1.0 / (1.0 + (0.25 * distance * distance))); \n"
|
|
||||||
// Multiply the color by the diffuse illumination level to get final output color.
|
|
||||||
+ " gl_FragColor = v_Color * diffuse; \n"
|
|
||||||
+ "} \n";
|
|
||||||
|
|
||||||
return perPixelFragmentShader;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
package com.learnopengles.android.livewallpaper;
|
|
||||||
|
|
||||||
import android.opengl.GLSurfaceView.Renderer;
|
|
||||||
|
|
||||||
import com.learnopengles.android.lesson3.LessonThreeRenderer;
|
|
||||||
|
|
||||||
public class LessonThreeWallpaperService extends OpenGLES2WallpaperService {
|
|
||||||
@Override
|
|
||||||
Renderer getNewRenderer() {
|
|
||||||
return new LessonThreeRenderer();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,642 +0,0 @@
|
|||||||
package org.ewol;
|
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.nio.ByteOrder;
|
|
||||||
import java.nio.FloatBuffer;
|
|
||||||
|
|
||||||
import javax.microedition.khronos.egl.EGLConfig;
|
|
||||||
import javax.microedition.khronos.opengles.GL10;
|
|
||||||
|
|
||||||
import android.opengl.GLES20;
|
|
||||||
import android.opengl.GLSurfaceView;
|
|
||||||
import android.opengl.Matrix;
|
|
||||||
import android.os.SystemClock;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class implements our custom renderer. Note that the GL10 parameter passed in is unused for OpenGL ES 2.0
|
|
||||||
* renderers -- the static class GLES20 is used instead.
|
|
||||||
*/
|
|
||||||
public class LessonTwoRenderer implements GLSurfaceView.Renderer
|
|
||||||
{
|
|
||||||
/** Used for debug logs. */
|
|
||||||
private static final String TAG = "LessonTwoRenderer";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store the model matrix. This matrix is used to move models from object space (where each model can be thought
|
|
||||||
* of being located at the center of the universe) to world space.
|
|
||||||
*/
|
|
||||||
private float[] mModelMatrix = new float[16];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Store the view matrix. This can be thought of as our camera. This matrix transforms world space to eye space;
|
|
||||||
* it positions things relative to our eye.
|
|
||||||
*/
|
|
||||||
private float[] mViewMatrix = new float[16];
|
|
||||||
|
|
||||||
/** Store the projection matrix. This is used to project the scene onto a 2D viewport. */
|
|
||||||
private float[] mProjectionMatrix = new float[16];
|
|
||||||
|
|
||||||
/** Allocate storage for the final combined matrix. This will be passed into the shader program. */
|
|
||||||
private float[] mMVPMatrix = new float[16];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Stores a copy of the model matrix specifically for the light position.
|
|
||||||
*/
|
|
||||||
private float[] mLightModelMatrix = new float[16];
|
|
||||||
|
|
||||||
/** Store our model data in a float buffer. */
|
|
||||||
private final FloatBuffer mCubePositions;
|
|
||||||
private final FloatBuffer mCubeColors;
|
|
||||||
private final FloatBuffer mCubeNormals;
|
|
||||||
|
|
||||||
/** This will be used to pass in the transformation matrix. */
|
|
||||||
private int mMVPMatrixHandle;
|
|
||||||
|
|
||||||
/** This will be used to pass in the modelview matrix. */
|
|
||||||
private int mMVMatrixHandle;
|
|
||||||
|
|
||||||
/** This will be used to pass in the light position. */
|
|
||||||
private int mLightPosHandle;
|
|
||||||
|
|
||||||
/** This will be used to pass in model position information. */
|
|
||||||
private int mPositionHandle;
|
|
||||||
|
|
||||||
/** This will be used to pass in model color information. */
|
|
||||||
private int mColorHandle;
|
|
||||||
|
|
||||||
/** This will be used to pass in model normal information. */
|
|
||||||
private int mNormalHandle;
|
|
||||||
|
|
||||||
/** How many bytes per float. */
|
|
||||||
private final int mBytesPerFloat = 4;
|
|
||||||
|
|
||||||
/** Size of the position data in elements. */
|
|
||||||
private final int mPositionDataSize = 3;
|
|
||||||
|
|
||||||
/** Size of the color data in elements. */
|
|
||||||
private final int mColorDataSize = 4;
|
|
||||||
|
|
||||||
/** Size of the normal data in elements. */
|
|
||||||
private final int mNormalDataSize = 3;
|
|
||||||
|
|
||||||
/** Used to hold a light centered on the origin in model space. We need a 4th coordinate so we can get translations to work when
|
|
||||||
* we multiply this by our transformation matrices. */
|
|
||||||
private final float[] mLightPosInModelSpace = new float[] {0.0f, 0.0f, 0.0f, 1.0f};
|
|
||||||
|
|
||||||
/** Used to hold the current position of the light in world space (after transformation via model matrix). */
|
|
||||||
private final float[] mLightPosInWorldSpace = new float[4];
|
|
||||||
|
|
||||||
/** Used to hold the transformed position of the light in eye space (after transformation via modelview matrix) */
|
|
||||||
private final float[] mLightPosInEyeSpace = new float[4];
|
|
||||||
|
|
||||||
/** This is a handle to our per-vertex cube shading program. */
|
|
||||||
private int mPerVertexProgramHandle;
|
|
||||||
|
|
||||||
/** This is a handle to our light point program. */
|
|
||||||
private int mPointProgramHandle;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize the model data.
|
|
||||||
*/
|
|
||||||
public LessonTwoRenderer()
|
|
||||||
{
|
|
||||||
// Define points for a cube.
|
|
||||||
|
|
||||||
// X, Y, Z
|
|
||||||
final float[] cubePositionData =
|
|
||||||
{
|
|
||||||
// In OpenGL counter-clockwise winding is default. This means that when we look at a triangle,
|
|
||||||
// if the points are counter-clockwise we are looking at the "front". If not we are looking at
|
|
||||||
// the back. OpenGL has an optimization where all back-facing triangles are culled, since they
|
|
||||||
// usually represent the backside of an object and aren't visible anyways.
|
|
||||||
|
|
||||||
// Front face
|
|
||||||
-1.0f, 1.0f, 1.0f,
|
|
||||||
-1.0f, -1.0f, 1.0f,
|
|
||||||
1.0f, 1.0f, 1.0f,
|
|
||||||
-1.0f, -1.0f, 1.0f,
|
|
||||||
1.0f, -1.0f, 1.0f,
|
|
||||||
1.0f, 1.0f, 1.0f,
|
|
||||||
|
|
||||||
// Right face
|
|
||||||
1.0f, 1.0f, 1.0f,
|
|
||||||
1.0f, -1.0f, 1.0f,
|
|
||||||
1.0f, 1.0f, -1.0f,
|
|
||||||
1.0f, -1.0f, 1.0f,
|
|
||||||
1.0f, -1.0f, -1.0f,
|
|
||||||
1.0f, 1.0f, -1.0f,
|
|
||||||
|
|
||||||
// Back face
|
|
||||||
1.0f, 1.0f, -1.0f,
|
|
||||||
1.0f, -1.0f, -1.0f,
|
|
||||||
-1.0f, 1.0f, -1.0f,
|
|
||||||
1.0f, -1.0f, -1.0f,
|
|
||||||
-1.0f, -1.0f, -1.0f,
|
|
||||||
-1.0f, 1.0f, -1.0f,
|
|
||||||
|
|
||||||
// Left face
|
|
||||||
-1.0f, 1.0f, -1.0f,
|
|
||||||
-1.0f, -1.0f, -1.0f,
|
|
||||||
-1.0f, 1.0f, 1.0f,
|
|
||||||
-1.0f, -1.0f, -1.0f,
|
|
||||||
-1.0f, -1.0f, 1.0f,
|
|
||||||
-1.0f, 1.0f, 1.0f,
|
|
||||||
|
|
||||||
// Top face
|
|
||||||
-1.0f, 1.0f, -1.0f,
|
|
||||||
-1.0f, 1.0f, 1.0f,
|
|
||||||
1.0f, 1.0f, -1.0f,
|
|
||||||
-1.0f, 1.0f, 1.0f,
|
|
||||||
1.0f, 1.0f, 1.0f,
|
|
||||||
1.0f, 1.0f, -1.0f,
|
|
||||||
|
|
||||||
// Bottom face
|
|
||||||
1.0f, -1.0f, -1.0f,
|
|
||||||
1.0f, -1.0f, 1.0f,
|
|
||||||
-1.0f, -1.0f, -1.0f,
|
|
||||||
1.0f, -1.0f, 1.0f,
|
|
||||||
-1.0f, -1.0f, 1.0f,
|
|
||||||
-1.0f, -1.0f, -1.0f,
|
|
||||||
};
|
|
||||||
|
|
||||||
// R, G, B, A
|
|
||||||
final float[] cubeColorData =
|
|
||||||
{
|
|
||||||
// Front face (red)
|
|
||||||
1.0f, 0.0f, 0.0f, 1.0f,
|
|
||||||
1.0f, 0.0f, 0.0f, 1.0f,
|
|
||||||
1.0f, 0.0f, 0.0f, 1.0f,
|
|
||||||
1.0f, 0.0f, 0.0f, 1.0f,
|
|
||||||
1.0f, 0.0f, 0.0f, 1.0f,
|
|
||||||
1.0f, 0.0f, 0.0f, 1.0f,
|
|
||||||
|
|
||||||
// Right face (green)
|
|
||||||
0.0f, 1.0f, 0.0f, 1.0f,
|
|
||||||
0.0f, 1.0f, 0.0f, 1.0f,
|
|
||||||
0.0f, 1.0f, 0.0f, 1.0f,
|
|
||||||
0.0f, 1.0f, 0.0f, 1.0f,
|
|
||||||
0.0f, 1.0f, 0.0f, 1.0f,
|
|
||||||
0.0f, 1.0f, 0.0f, 1.0f,
|
|
||||||
|
|
||||||
// Back face (blue)
|
|
||||||
0.0f, 0.0f, 1.0f, 1.0f,
|
|
||||||
0.0f, 0.0f, 1.0f, 1.0f,
|
|
||||||
0.0f, 0.0f, 1.0f, 1.0f,
|
|
||||||
0.0f, 0.0f, 1.0f, 1.0f,
|
|
||||||
0.0f, 0.0f, 1.0f, 1.0f,
|
|
||||||
0.0f, 0.0f, 1.0f, 1.0f,
|
|
||||||
|
|
||||||
// Left face (yellow)
|
|
||||||
1.0f, 1.0f, 0.0f, 1.0f,
|
|
||||||
1.0f, 1.0f, 0.0f, 1.0f,
|
|
||||||
1.0f, 1.0f, 0.0f, 1.0f,
|
|
||||||
1.0f, 1.0f, 0.0f, 1.0f,
|
|
||||||
1.0f, 1.0f, 0.0f, 1.0f,
|
|
||||||
1.0f, 1.0f, 0.0f, 1.0f,
|
|
||||||
|
|
||||||
// Top face (cyan)
|
|
||||||
0.0f, 1.0f, 1.0f, 1.0f,
|
|
||||||
0.0f, 1.0f, 1.0f, 1.0f,
|
|
||||||
0.0f, 1.0f, 1.0f, 1.0f,
|
|
||||||
0.0f, 1.0f, 1.0f, 1.0f,
|
|
||||||
0.0f, 1.0f, 1.0f, 1.0f,
|
|
||||||
0.0f, 1.0f, 1.0f, 1.0f,
|
|
||||||
|
|
||||||
// Bottom face (magenta)
|
|
||||||
1.0f, 0.0f, 1.0f, 1.0f,
|
|
||||||
1.0f, 0.0f, 1.0f, 1.0f,
|
|
||||||
1.0f, 0.0f, 1.0f, 1.0f,
|
|
||||||
1.0f, 0.0f, 1.0f, 1.0f,
|
|
||||||
1.0f, 0.0f, 1.0f, 1.0f,
|
|
||||||
1.0f, 0.0f, 1.0f, 1.0f
|
|
||||||
};
|
|
||||||
|
|
||||||
// X, Y, Z
|
|
||||||
// The normal is used in light calculations and is a vector which points
|
|
||||||
// orthogonal to the plane of the surface. For a cube model, the normals
|
|
||||||
// should be orthogonal to the points of each face.
|
|
||||||
final float[] cubeNormalData =
|
|
||||||
{
|
|
||||||
// Front face
|
|
||||||
0.0f, 0.0f, 1.0f,
|
|
||||||
0.0f, 0.0f, 1.0f,
|
|
||||||
0.0f, 0.0f, 1.0f,
|
|
||||||
0.0f, 0.0f, 1.0f,
|
|
||||||
0.0f, 0.0f, 1.0f,
|
|
||||||
0.0f, 0.0f, 1.0f,
|
|
||||||
|
|
||||||
// Right face
|
|
||||||
1.0f, 0.0f, 0.0f,
|
|
||||||
1.0f, 0.0f, 0.0f,
|
|
||||||
1.0f, 0.0f, 0.0f,
|
|
||||||
1.0f, 0.0f, 0.0f,
|
|
||||||
1.0f, 0.0f, 0.0f,
|
|
||||||
1.0f, 0.0f, 0.0f,
|
|
||||||
|
|
||||||
// Back face
|
|
||||||
0.0f, 0.0f, -1.0f,
|
|
||||||
0.0f, 0.0f, -1.0f,
|
|
||||||
0.0f, 0.0f, -1.0f,
|
|
||||||
0.0f, 0.0f, -1.0f,
|
|
||||||
0.0f, 0.0f, -1.0f,
|
|
||||||
0.0f, 0.0f, -1.0f,
|
|
||||||
|
|
||||||
// Left face
|
|
||||||
-1.0f, 0.0f, 0.0f,
|
|
||||||
-1.0f, 0.0f, 0.0f,
|
|
||||||
-1.0f, 0.0f, 0.0f,
|
|
||||||
-1.0f, 0.0f, 0.0f,
|
|
||||||
-1.0f, 0.0f, 0.0f,
|
|
||||||
-1.0f, 0.0f, 0.0f,
|
|
||||||
|
|
||||||
// Top face
|
|
||||||
0.0f, 1.0f, 0.0f,
|
|
||||||
0.0f, 1.0f, 0.0f,
|
|
||||||
0.0f, 1.0f, 0.0f,
|
|
||||||
0.0f, 1.0f, 0.0f,
|
|
||||||
0.0f, 1.0f, 0.0f,
|
|
||||||
0.0f, 1.0f, 0.0f,
|
|
||||||
|
|
||||||
// Bottom face
|
|
||||||
0.0f, -1.0f, 0.0f,
|
|
||||||
0.0f, -1.0f, 0.0f,
|
|
||||||
0.0f, -1.0f, 0.0f,
|
|
||||||
0.0f, -1.0f, 0.0f,
|
|
||||||
0.0f, -1.0f, 0.0f,
|
|
||||||
0.0f, -1.0f, 0.0f
|
|
||||||
};
|
|
||||||
|
|
||||||
// Initialize the buffers.
|
|
||||||
mCubePositions = ByteBuffer.allocateDirect(cubePositionData.length * mBytesPerFloat)
|
|
||||||
.order(ByteOrder.nativeOrder()).asFloatBuffer();
|
|
||||||
mCubePositions.put(cubePositionData).position(0);
|
|
||||||
|
|
||||||
mCubeColors = ByteBuffer.allocateDirect(cubeColorData.length * mBytesPerFloat)
|
|
||||||
.order(ByteOrder.nativeOrder()).asFloatBuffer();
|
|
||||||
mCubeColors.put(cubeColorData).position(0);
|
|
||||||
|
|
||||||
mCubeNormals = ByteBuffer.allocateDirect(cubeNormalData.length * mBytesPerFloat)
|
|
||||||
.order(ByteOrder.nativeOrder()).asFloatBuffer();
|
|
||||||
mCubeNormals.put(cubeNormalData).position(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getVertexShader()
|
|
||||||
{
|
|
||||||
// TODO: Explain why we normalize the vectors, explain some of the vector math behind it all. Explain what is eye space.
|
|
||||||
final String vertexShader =
|
|
||||||
"uniform mat4 u_MVPMatrix; \n" // A constant representing the combined model/view/projection matrix.
|
|
||||||
+ "uniform mat4 u_MVMatrix; \n" // A constant representing the combined model/view matrix.
|
|
||||||
+ "uniform vec3 u_LightPos; \n" // The position of the light in eye space.
|
|
||||||
|
|
||||||
+ "attribute vec4 a_Position; \n" // Per-vertex position information we will pass in.
|
|
||||||
+ "attribute vec4 a_Color; \n" // Per-vertex color information we will pass in.
|
|
||||||
+ "attribute vec3 a_Normal; \n" // Per-vertex normal information we will pass in.
|
|
||||||
|
|
||||||
+ "varying vec4 v_Color; \n" // This will be passed into the fragment shader.
|
|
||||||
|
|
||||||
+ "void main() \n" // The entry point for our vertex shader.
|
|
||||||
+ "{ \n"
|
|
||||||
// Transform the vertex into eye space.
|
|
||||||
+ " vec3 modelViewVertex = vec3(u_MVMatrix * a_Position); \n"
|
|
||||||
// Transform the normal's orientation into eye space.
|
|
||||||
+ " vec3 modelViewNormal = vec3(u_MVMatrix * vec4(a_Normal, 0.0)); \n"
|
|
||||||
// Will be used for attenuation.
|
|
||||||
+ " float distance = length(u_LightPos - modelViewVertex); \n"
|
|
||||||
// Get a lighting direction vector from the light to the vertex.
|
|
||||||
+ " vec3 lightVector = normalize(u_LightPos - modelViewVertex); \n"
|
|
||||||
// Calculate the dot product of the light vector and vertex normal. If the normal and light vector are
|
|
||||||
// pointing in the same direction then it will get max illumination.
|
|
||||||
+ " float diffuse = max(dot(modelViewNormal, lightVector), 0.1); \n"
|
|
||||||
// Attenuate the light based on distance.
|
|
||||||
+ " diffuse = diffuse * (1.0 / (1.0 + (0.25 * distance * distance))); \n"
|
|
||||||
// Multiply the color by the illumination level. It will be interpolated across the triangle.
|
|
||||||
+ " v_Color = a_Color * diffuse; \n"
|
|
||||||
// gl_Position is a special variable used to store the final position.
|
|
||||||
// Multiply the vertex by the matrix to get the final point in normalized screen coordinates.
|
|
||||||
+ " gl_Position = u_MVPMatrix * a_Position; \n"
|
|
||||||
+ "} \n";
|
|
||||||
|
|
||||||
return vertexShader;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getFragmentShader()
|
|
||||||
{
|
|
||||||
final String fragmentShader =
|
|
||||||
"precision mediump float; \n" // Set the default precision to medium. We don't need as high of a
|
|
||||||
// precision in the fragment shader.
|
|
||||||
+ "varying vec4 v_Color; \n" // This is the color from the vertex shader interpolated across the
|
|
||||||
// triangle per fragment.
|
|
||||||
+ "void main() \n" // The entry point for our fragment shader.
|
|
||||||
+ "{ \n"
|
|
||||||
+ " gl_FragColor = v_Color; \n" // Pass the color directly through the pipeline.
|
|
||||||
+ "} \n";
|
|
||||||
|
|
||||||
return fragmentShader;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onSurfaceCreated(GL10 glUnused, EGLConfig config)
|
|
||||||
{
|
|
||||||
// Set the background clear color to black.
|
|
||||||
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
|
||||||
|
|
||||||
// Use culling to remove back faces.
|
|
||||||
GLES20.glEnable(GLES20.GL_CULL_FACE);
|
|
||||||
|
|
||||||
// Enable depth testing
|
|
||||||
GLES20.glEnable(GLES20.GL_DEPTH_TEST);
|
|
||||||
|
|
||||||
// Position the eye in front of the origin.
|
|
||||||
final float eyeX = 0.0f;
|
|
||||||
final float eyeY = 0.0f;
|
|
||||||
final float eyeZ = -0.5f;
|
|
||||||
|
|
||||||
// We are looking toward the distance
|
|
||||||
final float lookX = 0.0f;
|
|
||||||
final float lookY = 0.0f;
|
|
||||||
final float lookZ = -5.0f;
|
|
||||||
|
|
||||||
// Set our up vector. This is where our head would be pointing were we holding the camera.
|
|
||||||
final float upX = 0.0f;
|
|
||||||
final float upY = 1.0f;
|
|
||||||
final float upZ = 0.0f;
|
|
||||||
|
|
||||||
// Set the view matrix. This matrix can be said to represent the camera position.
|
|
||||||
// NOTE: In OpenGL 1, a ModelView matrix is used, which is a combination of a model and
|
|
||||||
// view matrix. In OpenGL 2, we can keep track of these matrices separately if we choose.
|
|
||||||
Matrix.setLookAtM(mViewMatrix, 0, eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ);
|
|
||||||
|
|
||||||
final String vertexShader = getVertexShader();
|
|
||||||
final String fragmentShader = getFragmentShader();
|
|
||||||
|
|
||||||
final int vertexShaderHandle = compileShader(GLES20.GL_VERTEX_SHADER, vertexShader);
|
|
||||||
final int fragmentShaderHandle = compileShader(GLES20.GL_FRAGMENT_SHADER, fragmentShader);
|
|
||||||
|
|
||||||
mPerVertexProgramHandle = createAndLinkProgram(vertexShaderHandle, fragmentShaderHandle,
|
|
||||||
new String[] {"a_Position", "a_Color", "a_Normal"});
|
|
||||||
|
|
||||||
// Define a simple shader program for our point.
|
|
||||||
final String pointVertexShader =
|
|
||||||
"uniform mat4 u_MVPMatrix; \n"
|
|
||||||
+ "attribute vec4 a_Position; \n"
|
|
||||||
+ "void main() \n"
|
|
||||||
+ "{ \n"
|
|
||||||
+ " gl_Position = u_MVPMatrix \n"
|
|
||||||
+ " * a_Position; \n"
|
|
||||||
+ " gl_PointSize = 5.0; \n"
|
|
||||||
+ "} \n";
|
|
||||||
|
|
||||||
final String pointFragmentShader =
|
|
||||||
"precision mediump float; \n"
|
|
||||||
+ "void main() \n"
|
|
||||||
+ "{ \n"
|
|
||||||
+ " gl_FragColor = vec4(1.0, \n"
|
|
||||||
+ " 1.0, 1.0, 1.0); \n"
|
|
||||||
+ "} \n";
|
|
||||||
|
|
||||||
final int pointVertexShaderHandle = compileShader(GLES20.GL_VERTEX_SHADER, pointVertexShader);
|
|
||||||
final int pointFragmentShaderHandle = compileShader(GLES20.GL_FRAGMENT_SHADER, pointFragmentShader);
|
|
||||||
mPointProgramHandle = createAndLinkProgram(pointVertexShaderHandle, pointFragmentShaderHandle,
|
|
||||||
new String[] {"a_Position"});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onSurfaceChanged(GL10 glUnused, int width, int height)
|
|
||||||
{
|
|
||||||
// Set the OpenGL viewport to the same size as the surface.
|
|
||||||
GLES20.glViewport(0, 0, width, height);
|
|
||||||
|
|
||||||
// Create a new perspective projection matrix. The height will stay the same
|
|
||||||
// while the width will vary as per aspect ratio.
|
|
||||||
final float ratio = (float) width / height;
|
|
||||||
final float left = -ratio;
|
|
||||||
final float right = ratio;
|
|
||||||
final float bottom = -1.0f;
|
|
||||||
final float top = 1.0f;
|
|
||||||
final float near = 1.0f;
|
|
||||||
final float far = 10.0f;
|
|
||||||
|
|
||||||
Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onDrawFrame(GL10 glUnused)
|
|
||||||
{
|
|
||||||
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
|
|
||||||
|
|
||||||
// Do a complete rotation every 10 seconds.
|
|
||||||
long time = SystemClock.uptimeMillis() % 10000L;
|
|
||||||
float angleInDegrees = (360.0f / 10000.0f) * ((int) time);
|
|
||||||
|
|
||||||
// Set our per-vertex lighting program.
|
|
||||||
GLES20.glUseProgram(mPerVertexProgramHandle);
|
|
||||||
|
|
||||||
// Set program handles for cube drawing.
|
|
||||||
mMVPMatrixHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_MVPMatrix");
|
|
||||||
mMVMatrixHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_MVMatrix");
|
|
||||||
mLightPosHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_LightPos");
|
|
||||||
mPositionHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Position");
|
|
||||||
mColorHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Color");
|
|
||||||
mNormalHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Normal");
|
|
||||||
|
|
||||||
// Calculate position of the light. Rotate and then push into the distance.
|
|
||||||
Matrix.setIdentityM(mLightModelMatrix, 0);
|
|
||||||
Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, -5.0f);
|
|
||||||
Matrix.rotateM(mLightModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
|
|
||||||
Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, 2.0f);
|
|
||||||
|
|
||||||
Matrix.multiplyMV(mLightPosInWorldSpace, 0, mLightModelMatrix, 0, mLightPosInModelSpace, 0);
|
|
||||||
Matrix.multiplyMV(mLightPosInEyeSpace, 0, mViewMatrix, 0, mLightPosInWorldSpace, 0);
|
|
||||||
|
|
||||||
// Draw some cubes.
|
|
||||||
Matrix.setIdentityM(mModelMatrix, 0);
|
|
||||||
Matrix.translateM(mModelMatrix, 0, 4.0f, 0.0f, -7.0f);
|
|
||||||
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 0.0f, 0.0f);
|
|
||||||
drawCube();
|
|
||||||
|
|
||||||
Matrix.setIdentityM(mModelMatrix, 0);
|
|
||||||
Matrix.translateM(mModelMatrix, 0, -4.0f, 0.0f, -7.0f);
|
|
||||||
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
|
|
||||||
drawCube();
|
|
||||||
|
|
||||||
Matrix.setIdentityM(mModelMatrix, 0);
|
|
||||||
Matrix.translateM(mModelMatrix, 0, 0.0f, 4.0f, -7.0f);
|
|
||||||
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
|
|
||||||
drawCube();
|
|
||||||
|
|
||||||
Matrix.setIdentityM(mModelMatrix, 0);
|
|
||||||
Matrix.translateM(mModelMatrix, 0, 0.0f, -4.0f, -7.0f);
|
|
||||||
drawCube();
|
|
||||||
|
|
||||||
Matrix.setIdentityM(mModelMatrix, 0);
|
|
||||||
Matrix.translateM(mModelMatrix, 0, 0.0f, 0.0f, -5.0f);
|
|
||||||
Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 1.0f, 0.0f);
|
|
||||||
drawCube();
|
|
||||||
|
|
||||||
// Draw a point to indicate the light.
|
|
||||||
GLES20.glUseProgram(mPointProgramHandle);
|
|
||||||
drawLight();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Draws a cube.
|
|
||||||
*/
|
|
||||||
private void drawCube()
|
|
||||||
{
|
|
||||||
// Pass in the position information
|
|
||||||
mCubePositions.position(0);
|
|
||||||
GLES20.glVertexAttribPointer(mPositionHandle, mPositionDataSize, GLES20.GL_FLOAT, false,
|
|
||||||
0, mCubePositions);
|
|
||||||
|
|
||||||
GLES20.glEnableVertexAttribArray(mPositionHandle);
|
|
||||||
|
|
||||||
// Pass in the color information
|
|
||||||
mCubeColors.position(0);
|
|
||||||
GLES20.glVertexAttribPointer(mColorHandle, mColorDataSize, GLES20.GL_FLOAT, false,
|
|
||||||
0, mCubeColors);
|
|
||||||
|
|
||||||
GLES20.glEnableVertexAttribArray(mColorHandle);
|
|
||||||
|
|
||||||
// Pass in the normal information
|
|
||||||
mCubeNormals.position(0);
|
|
||||||
GLES20.glVertexAttribPointer(mNormalHandle, mNormalDataSize, GLES20.GL_FLOAT, false,
|
|
||||||
0, mCubeNormals);
|
|
||||||
|
|
||||||
GLES20.glEnableVertexAttribArray(mNormalHandle);
|
|
||||||
|
|
||||||
// This multiplies the view matrix by the model matrix, and stores the result in the MVP matrix
|
|
||||||
// (which currently contains model * view).
|
|
||||||
Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
|
|
||||||
|
|
||||||
// Pass in the modelview matrix.
|
|
||||||
GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 0);
|
|
||||||
|
|
||||||
// This multiplies the modelview matrix by the projection matrix, and stores the result in the MVP matrix
|
|
||||||
// (which now contains model * view * projection).
|
|
||||||
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
|
|
||||||
|
|
||||||
// Pass in the combined matrix.
|
|
||||||
GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);
|
|
||||||
|
|
||||||
// Pass in the light position in eye space.
|
|
||||||
GLES20.glUniform3f(mLightPosHandle, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]);
|
|
||||||
|
|
||||||
// Draw the cube.
|
|
||||||
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 36);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Draws a point representing the position of the light.
|
|
||||||
*/
|
|
||||||
private void drawLight()
|
|
||||||
{
|
|
||||||
final int pointMVPMatrixHandle = GLES20.glGetUniformLocation(mPointProgramHandle, "u_MVPMatrix");
|
|
||||||
final int pointPositionHandle = GLES20.glGetAttribLocation(mPointProgramHandle, "a_Position");
|
|
||||||
|
|
||||||
// Pass in the position.
|
|
||||||
GLES20.glVertexAttrib3f(pointPositionHandle, mLightPosInModelSpace[0], mLightPosInModelSpace[1], mLightPosInModelSpace[2]);
|
|
||||||
|
|
||||||
// Since we are not using a buffer object, disable vertex arrays for this attribute.
|
|
||||||
GLES20.glDisableVertexAttribArray(pointPositionHandle);
|
|
||||||
|
|
||||||
// Pass in the transformation matrix.
|
|
||||||
Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mLightModelMatrix, 0);
|
|
||||||
Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
|
|
||||||
GLES20.glUniformMatrix4fv(pointMVPMatrixHandle, 1, false, mMVPMatrix, 0);
|
|
||||||
|
|
||||||
// Draw the point.
|
|
||||||
GLES20.glDrawArrays(GLES20.GL_POINTS, 0, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function to compile a shader.
|
|
||||||
*
|
|
||||||
* @param shaderType The shader type.
|
|
||||||
* @param shaderSource The shader source code.
|
|
||||||
* @return An OpenGL handle to the shader.
|
|
||||||
*/
|
|
||||||
private int compileShader(final int shaderType, final String shaderSource)
|
|
||||||
{
|
|
||||||
int shaderHandle = GLES20.glCreateShader(shaderType);
|
|
||||||
|
|
||||||
if (shaderHandle != 0)
|
|
||||||
{
|
|
||||||
// Pass in the shader source.
|
|
||||||
GLES20.glShaderSource(shaderHandle, shaderSource);
|
|
||||||
|
|
||||||
// Compile the shader.
|
|
||||||
GLES20.glCompileShader(shaderHandle);
|
|
||||||
|
|
||||||
// Get the compilation status.
|
|
||||||
final int[] compileStatus = new int[1];
|
|
||||||
GLES20.glGetShaderiv(shaderHandle, GLES20.GL_COMPILE_STATUS, compileStatus, 0);
|
|
||||||
|
|
||||||
// If the compilation failed, delete the shader.
|
|
||||||
if (compileStatus[0] == 0)
|
|
||||||
{
|
|
||||||
Log.e(TAG, "Error compiling shader: " + GLES20.glGetShaderInfoLog(shaderHandle));
|
|
||||||
GLES20.glDeleteShader(shaderHandle);
|
|
||||||
shaderHandle = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shaderHandle == 0)
|
|
||||||
{
|
|
||||||
throw new RuntimeException("Error creating shader.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return shaderHandle;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper function to compile and link a program.
|
|
||||||
*
|
|
||||||
* @param vertexShaderHandle An OpenGL handle to an already-compiled vertex shader.
|
|
||||||
* @param fragmentShaderHandle An OpenGL handle to an already-compiled fragment shader.
|
|
||||||
* @param attributes Attributes that need to be bound to the program.
|
|
||||||
* @return An OpenGL handle to the program.
|
|
||||||
*/
|
|
||||||
private int createAndLinkProgram(final int vertexShaderHandle, final int fragmentShaderHandle, final String[] attributes)
|
|
||||||
{
|
|
||||||
int programHandle = GLES20.glCreateProgram();
|
|
||||||
|
|
||||||
if (programHandle != 0)
|
|
||||||
{
|
|
||||||
// Bind the vertex shader to the program.
|
|
||||||
GLES20.glAttachShader(programHandle, vertexShaderHandle);
|
|
||||||
|
|
||||||
// Bind the fragment shader to the program.
|
|
||||||
GLES20.glAttachShader(programHandle, fragmentShaderHandle);
|
|
||||||
|
|
||||||
// Bind attributes
|
|
||||||
if (attributes != null)
|
|
||||||
{
|
|
||||||
final int size = attributes.length;
|
|
||||||
for (int i = 0; i < size; i++)
|
|
||||||
{
|
|
||||||
GLES20.glBindAttribLocation(programHandle, i, attributes[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Link the two shaders together into a program.
|
|
||||||
GLES20.glLinkProgram(programHandle);
|
|
||||||
|
|
||||||
// Get the link status.
|
|
||||||
final int[] linkStatus = new int[1];
|
|
||||||
GLES20.glGetProgramiv(programHandle, GLES20.GL_LINK_STATUS, linkStatus, 0);
|
|
||||||
|
|
||||||
// If the link failed, delete the program.
|
|
||||||
if (linkStatus[0] == 0)
|
|
||||||
{
|
|
||||||
Log.e(TAG, "Error compiling program: " + GLES20.glGetProgramInfoLog(programHandle));
|
|
||||||
GLES20.glDeleteProgram(programHandle);
|
|
||||||
programHandle = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (programHandle == 0)
|
|
||||||
{
|
|
||||||
throw new RuntimeException("Error creating program.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return programHandle;
|
|
||||||
}
|
|
||||||
}
|
|
@ -54,7 +54,7 @@ class AndroidContext : public ewol::eContext
|
|||||||
// get a resources from the java environement :
|
// get a resources from the java environement :
|
||||||
JNIEnv* m_JavaVirtualMachinePointer; //!< the JVM
|
JNIEnv* m_JavaVirtualMachinePointer; //!< the JVM
|
||||||
jclass m_javaClassEwol; //!< main activity class (android ...)
|
jclass m_javaClassEwol; //!< main activity class (android ...)
|
||||||
jclass m_javaClassEwolCallbackAndActivity;
|
jclass m_javaClassEwolCallback;
|
||||||
jobject m_javaObjectEwolCallbackAndActivity;
|
jobject m_javaObjectEwolCallbackAndActivity;
|
||||||
jmethodID m_javaMethodEwolCallbackEventNotifier; //!< basic methode to call ...
|
jmethodID m_javaMethodEwolCallbackEventNotifier; //!< basic methode to call ...
|
||||||
jmethodID m_javaMethodEwolCallbackKeyboardUpdate; //!< basic methode to call ...
|
jmethodID m_javaMethodEwolCallbackKeyboardUpdate; //!< basic methode to call ...
|
||||||
@ -81,7 +81,7 @@ class AndroidContext : public ewol::eContext
|
|||||||
m_javaApplicationType(_typeAPPL),
|
m_javaApplicationType(_typeAPPL),
|
||||||
m_JavaVirtualMachinePointer(NULL),
|
m_JavaVirtualMachinePointer(NULL),
|
||||||
m_javaClassEwol(0),
|
m_javaClassEwol(0),
|
||||||
m_javaClassEwolCallbackAndActivity(0),
|
m_javaClassEwolCallback(0),
|
||||||
m_javaObjectEwolCallbackAndActivity(0),
|
m_javaObjectEwolCallbackAndActivity(0),
|
||||||
m_javaMethodEwolCallbackEventNotifier(0),
|
m_javaMethodEwolCallbackEventNotifier(0),
|
||||||
m_javaMethodEwolCallbackKeyboardUpdate(0),
|
m_javaMethodEwolCallbackKeyboardUpdate(0),
|
||||||
@ -110,45 +110,47 @@ class AndroidContext : public ewol::eContext
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* The object field extends Activity and implement EwolCallback */
|
/* The object field extends Activity and implement EwolCallback */
|
||||||
m_javaClassEwolCallbackAndActivity = m_JavaVirtualMachinePointer->GetObjectClass(_objCallback);
|
m_javaClassEwolCallback = m_JavaVirtualMachinePointer->GetObjectClass(_objCallback);
|
||||||
if(m_javaClassEwolCallbackAndActivity == NULL) {
|
if(m_javaClassEwolCallback == NULL) {
|
||||||
EWOL_ERROR("C->java : Can't find org/ewol/EwolCallback class");
|
EWOL_ERROR("C->java : Can't find org/ewol/EwolCallback class");
|
||||||
// remove access on the virtual machine :
|
// remove access on the virtual machine :
|
||||||
m_JavaVirtualMachinePointer = NULL;
|
m_JavaVirtualMachinePointer = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bool ret= false;
|
bool ret= false;
|
||||||
if (m_javaApplicationType == appl_application) {
|
ret=SafeInitMethodID(m_javaMethodEwolActivitySetTitle,
|
||||||
ret=SafeInitMethodID(m_javaMethodEwolActivitySetTitle,
|
m_javaClassEwolCallback,
|
||||||
m_javaClassEwolCallbackAndActivity,
|
"titleSet",
|
||||||
"setTitle",
|
"(Ljava/lang/String;)V");
|
||||||
"(Ljava/lang/CharSequence;)V");
|
if (ret==false) {
|
||||||
if (ret==false) {
|
java_check_exception(_env);
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret=SafeInitMethodID(m_javaMethodEwolCallbackEventNotifier,
|
ret=SafeInitMethodID(m_javaMethodEwolCallbackEventNotifier,
|
||||||
m_javaClassEwolCallbackAndActivity,
|
m_javaClassEwolCallback,
|
||||||
"eventNotifier",
|
"eventNotifier",
|
||||||
"([Ljava/lang/String;)V");
|
"([Ljava/lang/String;)V");
|
||||||
if (ret==false) {
|
if (ret==false) {
|
||||||
|
java_check_exception(_env);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret=SafeInitMethodID(m_javaMethodEwolCallbackKeyboardUpdate,
|
ret=SafeInitMethodID(m_javaMethodEwolCallbackKeyboardUpdate,
|
||||||
m_javaClassEwolCallbackAndActivity,
|
m_javaClassEwolCallback,
|
||||||
"keyboardUpdate",
|
"keyboardUpdate",
|
||||||
"(Z)V");
|
"(Z)V");
|
||||||
if (ret==false) {
|
if (ret==false) {
|
||||||
|
java_check_exception(_env);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret=SafeInitMethodID(m_javaMethodEwolCallbackOrientationUpdate,
|
ret=SafeInitMethodID(m_javaMethodEwolCallbackOrientationUpdate,
|
||||||
m_javaClassEwolCallbackAndActivity,
|
m_javaClassEwolCallback,
|
||||||
"orientationUpdate",
|
"orientationUpdate",
|
||||||
"(I)V");
|
"(I)V");
|
||||||
if (ret==false) {
|
if (ret==false) {
|
||||||
|
java_check_exception(_env);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,7 +169,7 @@ class AndroidContext : public ewol::eContext
|
|||||||
|
|
||||||
~AndroidContext(void)
|
~AndroidContext(void)
|
||||||
{
|
{
|
||||||
|
// TODO ...
|
||||||
}
|
}
|
||||||
|
|
||||||
void UnInit(JNIEnv* _env)
|
void UnInit(JNIEnv* _env)
|
||||||
@ -414,12 +416,12 @@ extern "C"
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Call to initialize the graphics state */
|
/* Call to initialize the graphics state */
|
||||||
void Java_org_ewol_Ewol_paramSetArchiveDir(JNIEnv* _env, jclass _cls, jint _mode, jstring _myString)
|
void Java_org_ewol_Ewol_EWparamSetArchiveDir(JNIEnv* _env, jclass _cls, jint _mode, jstring _myString, jint _id)
|
||||||
{
|
{
|
||||||
esize_t _id=0;
|
|
||||||
if( _id>=s_listInstance.Size()
|
if( _id>=s_listInstance.Size()
|
||||||
|
|| _id<0
|
||||||
|| NULL==s_listInstance[_id] ) {
|
|| NULL==s_listInstance[_id] ) {
|
||||||
EWOL_ERROR("Call C With an incorrect instance");
|
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||||
// TODO : Generate error in java to stop the current instance
|
// TODO : Generate error in java to stop the current instance
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -435,11 +437,14 @@ extern "C"
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO : Return the local ID ...
|
// TODO : Return the local ID ...
|
||||||
void Java_org_ewol_Ewol_setJavaVirtualMachineStart(JNIEnv* _env, jclass _classBase, jobject _objCallback)
|
void Java_org_ewol_Ewol_EWsetJavaVirtualMachineStart(JNIEnv* _env, jclass _classBase, jobject _objCallback)
|
||||||
{
|
{
|
||||||
|
EWOL_DEBUG("*******************************************");
|
||||||
|
EWOL_DEBUG("** Creating EWOL context **");
|
||||||
|
EWOL_DEBUG("*******************************************");
|
||||||
AndroidContext* tmpContext = new AndroidContext(_env, _classBase, _objCallback, AndroidContext::appl_application);
|
AndroidContext* tmpContext = new AndroidContext(_env, _classBase, _objCallback, AndroidContext::appl_application);
|
||||||
if (NULL == tmpContext) {
|
if (NULL == tmpContext) {
|
||||||
EWOL_ERROR("Can not allocate the main context instance");
|
EWOL_ERROR("Can not allocate the main context instance _id=" << (s_listInstance.Size()-1));
|
||||||
// TODO : return -1;
|
// TODO : return -1;
|
||||||
}
|
}
|
||||||
// TODO : Change this ==> this generate the new ID ...
|
// TODO : Change this ==> this generate the new ID ...
|
||||||
@ -449,17 +454,20 @@ extern "C"
|
|||||||
} else {
|
} else {
|
||||||
// for future case : all time this ...
|
// for future case : all time this ...
|
||||||
s_listInstance.PushBack(tmpContext);
|
s_listInstance.PushBack(tmpContext);
|
||||||
// esize_t newID = s_listInstance.Size();
|
// esize_t newID = s_listInstance.Size()-1;
|
||||||
// return newID;
|
// return newID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO : Return the local ID ...
|
// TODO : Return the local ID ...
|
||||||
void Java_org_ewol_Ewol_setJavaVirtualMachineStartWallpaperEngine(JNIEnv* _env, jclass _classBase, jobject _objCallback)
|
void Java_org_ewol_Ewol_EWsetJavaVirtualMachineStartWallpaperEngine(JNIEnv* _env, jclass _classBase, jobject _objCallback)
|
||||||
{
|
{
|
||||||
|
EWOL_DEBUG("*******************************************");
|
||||||
|
EWOL_DEBUG("** Creating EWOL context **");
|
||||||
|
EWOL_DEBUG("*******************************************");
|
||||||
AndroidContext* tmpContext = new AndroidContext(_env, _classBase, _objCallback, AndroidContext::appl_wallpaper);
|
AndroidContext* tmpContext = new AndroidContext(_env, _classBase, _objCallback, AndroidContext::appl_wallpaper);
|
||||||
if (NULL == tmpContext) {
|
if (NULL == tmpContext) {
|
||||||
EWOL_ERROR("Can not allocate the main context instance");
|
EWOL_ERROR("Can not allocate the main context instance _id=" << (s_listInstance.Size()-1));
|
||||||
// TODO : return -1;
|
// TODO : return -1;
|
||||||
}
|
}
|
||||||
// TODO : Change this ==> this generate the new ID ...
|
// TODO : Change this ==> this generate the new ID ...
|
||||||
@ -469,21 +477,21 @@ extern "C"
|
|||||||
} else {
|
} else {
|
||||||
// for future case : all time this ...
|
// for future case : all time this ...
|
||||||
s_listInstance.PushBack(tmpContext);
|
s_listInstance.PushBack(tmpContext);
|
||||||
// esize_t newID = s_listInstance.Size();
|
// esize_t newID = s_listInstance.Size()-1;
|
||||||
// return newID;
|
// return newID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Java_org_ewol_Ewol_setJavaVirtualMachineStop(JNIEnv* _env, jclass _cls)
|
void Java_org_ewol_Ewol_EWsetJavaVirtualMachineStop(JNIEnv* _env, jclass _cls, jint _id)
|
||||||
{
|
{
|
||||||
EWOL_DEBUG("*******************************************");
|
EWOL_DEBUG("*******************************************");
|
||||||
EWOL_DEBUG("** Remove JVM Pointer **");
|
EWOL_DEBUG("** Remove JVM Pointer **");
|
||||||
EWOL_DEBUG("*******************************************");
|
EWOL_DEBUG("*******************************************");
|
||||||
esize_t _id = 0; // uint
|
|
||||||
if( _id>=s_listInstance.Size()
|
if( _id>=s_listInstance.Size()
|
||||||
|
|| _id<0
|
||||||
|| NULL==s_listInstance[_id] ) {
|
|| NULL==s_listInstance[_id] ) {
|
||||||
EWOL_ERROR("Call C With an incorrect instance");
|
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||||
// TODO : Generate error in java to stop the current instance
|
// TODO : Generate error in java to stop the current instance
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -491,111 +499,111 @@ extern "C"
|
|||||||
delete(s_listInstance[_id]);
|
delete(s_listInstance[_id]);
|
||||||
s_listInstance[_id]=NULL;
|
s_listInstance[_id]=NULL;
|
||||||
}
|
}
|
||||||
void Java_org_ewol_Ewol_touchEvent(JNIEnv* _env, jobject _thiz )
|
void Java_org_ewol_Ewol_EWtouchEvent(JNIEnv* _env, jobject _thiz, jint _id)
|
||||||
{
|
{
|
||||||
EWOL_DEBUG(" ==> Touch Event");
|
EWOL_DEBUG(" ==> Touch Event");
|
||||||
esize_t _id = 0; // uint
|
|
||||||
if( _id>=s_listInstance.Size()
|
if( _id>=s_listInstance.Size()
|
||||||
|
|| _id<0
|
||||||
|| NULL==s_listInstance[_id] ) {
|
|| NULL==s_listInstance[_id] ) {
|
||||||
EWOL_ERROR("Call C With an incorrect instance");
|
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||||
// TODO : Generate error in java to stop the current instance
|
// TODO : Generate error in java to stop the current instance
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
java_check_exception(_env);
|
java_check_exception(_env);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Java_org_ewol_Ewol_onCreate(JNIEnv* _env, jobject _thiz )
|
void Java_org_ewol_Ewol_EWonCreate(JNIEnv* _env, jobject _thiz, jint _id)
|
||||||
{
|
{
|
||||||
EWOL_DEBUG("*******************************************");
|
EWOL_DEBUG("*******************************************");
|
||||||
EWOL_DEBUG("** Activity On Create **");
|
EWOL_DEBUG("** Activity On Create **");
|
||||||
EWOL_DEBUG("*******************************************");
|
EWOL_DEBUG("*******************************************");
|
||||||
esize_t _id = 0; // uint
|
|
||||||
if( _id>=s_listInstance.Size()
|
if( _id>=s_listInstance.Size()
|
||||||
|
|| _id<0
|
||||||
|| NULL==s_listInstance[_id] ) {
|
|| NULL==s_listInstance[_id] ) {
|
||||||
EWOL_ERROR("Call C With an incorrect instance");
|
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||||
// TODO : Generate error in java to stop the current instance
|
// TODO : Generate error in java to stop the current instance
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//s_listInstance[_id]->Init();
|
//s_listInstance[_id]->Init();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Java_org_ewol_Ewol_onStart(JNIEnv* _env, jobject _thiz)
|
void Java_org_ewol_Ewol_EWonStart(JNIEnv* _env, jobject _thiz, jint _id)
|
||||||
{
|
{
|
||||||
EWOL_DEBUG("*******************************************");
|
EWOL_DEBUG("*******************************************");
|
||||||
EWOL_DEBUG("** Activity On Start **");
|
EWOL_DEBUG("** Activity On Start **");
|
||||||
EWOL_DEBUG("*******************************************");
|
EWOL_DEBUG("*******************************************");
|
||||||
esize_t _id = 0; // uint
|
|
||||||
if( _id>=s_listInstance.Size()
|
if( _id>=s_listInstance.Size()
|
||||||
|
|| _id<0
|
||||||
|| NULL==s_listInstance[_id] ) {
|
|| NULL==s_listInstance[_id] ) {
|
||||||
EWOL_ERROR("Call C With an incorrect instance");
|
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||||
// TODO : Generate error in java to stop the current instance
|
// TODO : Generate error in java to stop the current instance
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//SendSystemMessage(" testmessages ... ");
|
//SendSystemMessage(" testmessages ... ");
|
||||||
}
|
}
|
||||||
void Java_org_ewol_Ewol_onReStart(JNIEnv* _env, jobject _thiz)
|
void Java_org_ewol_Ewol_EWonReStart(JNIEnv* _env, jobject _thiz, jint _id)
|
||||||
{
|
{
|
||||||
EWOL_DEBUG("*******************************************");
|
EWOL_DEBUG("*******************************************");
|
||||||
EWOL_DEBUG("** Activity On Re-Start **");
|
EWOL_DEBUG("** Activity On Re-Start **");
|
||||||
EWOL_DEBUG("*******************************************");
|
EWOL_DEBUG("*******************************************");
|
||||||
esize_t _id = 0; // uint
|
|
||||||
if( _id>=s_listInstance.Size()
|
if( _id>=s_listInstance.Size()
|
||||||
|
|| _id<0
|
||||||
|| NULL==s_listInstance[_id] ) {
|
|| NULL==s_listInstance[_id] ) {
|
||||||
EWOL_ERROR("Call C With an incorrect instance");
|
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||||
// TODO : Generate error in java to stop the current instance
|
// TODO : Generate error in java to stop the current instance
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Java_org_ewol_Ewol_onResume(JNIEnv* _env, jobject _thiz)
|
void Java_org_ewol_Ewol_EWonResume(JNIEnv* _env, jobject _thiz, jint _id)
|
||||||
{
|
{
|
||||||
EWOL_DEBUG("*******************************************");
|
EWOL_DEBUG("*******************************************");
|
||||||
EWOL_DEBUG("** Activity On Resume **");
|
EWOL_DEBUG("** Activity On Resume **");
|
||||||
EWOL_DEBUG("*******************************************");
|
EWOL_DEBUG("*******************************************");
|
||||||
esize_t _id = 0; // uint
|
|
||||||
if( _id>=s_listInstance.Size()
|
if( _id>=s_listInstance.Size()
|
||||||
|
|| _id<0
|
||||||
|| NULL==s_listInstance[_id] ) {
|
|| NULL==s_listInstance[_id] ) {
|
||||||
EWOL_ERROR("Call C With an incorrect instance");
|
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||||
// TODO : Generate error in java to stop the current instance
|
// TODO : Generate error in java to stop the current instance
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Java_org_ewol_Ewol_onPause(JNIEnv* _env, jobject _thiz)
|
void Java_org_ewol_Ewol_EWonPause(JNIEnv* _env, jobject _thiz, jint _id)
|
||||||
{
|
{
|
||||||
EWOL_DEBUG("*******************************************");
|
EWOL_DEBUG("*******************************************");
|
||||||
EWOL_DEBUG("** Activity On Pause **");
|
EWOL_DEBUG("** Activity On Pause **");
|
||||||
EWOL_DEBUG("*******************************************");
|
EWOL_DEBUG("*******************************************");
|
||||||
esize_t _id = 0; // uint
|
|
||||||
if( _id>=s_listInstance.Size()
|
if( _id>=s_listInstance.Size()
|
||||||
|
|| _id<0
|
||||||
|| NULL==s_listInstance[_id] ) {
|
|| NULL==s_listInstance[_id] ) {
|
||||||
EWOL_ERROR("Call C With an incorrect instance");
|
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||||
// TODO : Generate error in java to stop the current instance
|
// TODO : Generate error in java to stop the current instance
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// All the openGl has been destroyed ...
|
// All the openGl has been destroyed ...
|
||||||
s_listInstance[_id]->GetResourcesManager().ContextHasBeenDestroyed();
|
s_listInstance[_id]->GetResourcesManager().ContextHasBeenDestroyed();
|
||||||
}
|
}
|
||||||
void Java_org_ewol_Ewol_onStop(JNIEnv* _env, jobject _thiz)
|
void Java_org_ewol_Ewol_EWonStop(JNIEnv* _env, jobject _thiz, jint _id)
|
||||||
{
|
{
|
||||||
EWOL_DEBUG("*******************************************");
|
EWOL_DEBUG("*******************************************");
|
||||||
EWOL_DEBUG("** Activity On Stop **");
|
EWOL_DEBUG("** Activity On Stop **");
|
||||||
EWOL_DEBUG("*******************************************");
|
EWOL_DEBUG("*******************************************");
|
||||||
esize_t _id = 0; // uint
|
|
||||||
if( _id>=s_listInstance.Size()
|
if( _id>=s_listInstance.Size()
|
||||||
|
|| _id<0
|
||||||
|| NULL==s_listInstance[_id] ) {
|
|| NULL==s_listInstance[_id] ) {
|
||||||
EWOL_ERROR("Call C With an incorrect instance");
|
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||||
// TODO : Generate error in java to stop the current instance
|
// TODO : Generate error in java to stop the current instance
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Java_org_ewol_Ewol_onDestroy(JNIEnv* _env, jobject _thiz)
|
void Java_org_ewol_Ewol_EWonDestroy(JNIEnv* _env, jobject _thiz, jint _id)
|
||||||
{
|
{
|
||||||
EWOL_DEBUG("*******************************************");
|
EWOL_DEBUG("*******************************************");
|
||||||
EWOL_DEBUG("** Activity On Destroy **");
|
EWOL_DEBUG("** Activity On Destroy **");
|
||||||
EWOL_DEBUG("*******************************************");
|
EWOL_DEBUG("*******************************************");
|
||||||
esize_t _id = 0; // uint
|
|
||||||
if( _id>=s_listInstance.Size()
|
if( _id>=s_listInstance.Size()
|
||||||
|
|| _id<0
|
||||||
|| NULL==s_listInstance[_id] ) {
|
|| NULL==s_listInstance[_id] ) {
|
||||||
EWOL_ERROR("Call C With an incorrect instance");
|
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||||
// TODO : Generate error in java to stop the current instance
|
// TODO : Generate error in java to stop the current instance
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -607,84 +615,84 @@ extern "C"
|
|||||||
/* **********************************************************************************************
|
/* **********************************************************************************************
|
||||||
* ** IO section :
|
* ** IO section :
|
||||||
* ********************************************************************************************** */
|
* ********************************************************************************************** */
|
||||||
void Java_org_ewol_Ewol_inputEventMotion(JNIEnv* _env, jobject _thiz, jint _pointerID, jfloat _x, jfloat _y )
|
void Java_org_ewol_Ewol_EWinputEventMotion(JNIEnv* _env, jobject _thiz, jint _id, jint _pointerID, jfloat _x, jfloat _y )
|
||||||
{
|
{
|
||||||
esize_t _id = 0; // uint
|
|
||||||
if( _id>=s_listInstance.Size()
|
if( _id>=s_listInstance.Size()
|
||||||
|
|| _id<0
|
||||||
|| NULL==s_listInstance[_id] ) {
|
|| NULL==s_listInstance[_id] ) {
|
||||||
EWOL_ERROR("Call C With an incorrect instance");
|
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||||
// TODO : Generate error in java to stop the current instance
|
// TODO : Generate error in java to stop the current instance
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
s_listInstance[_id]->OS_SetInputMotion(_pointerID+1, vec2(_x,_y));
|
s_listInstance[_id]->OS_SetInputMotion(_pointerID+1, vec2(_x,_y));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Java_org_ewol_Ewol_inputEventState(JNIEnv* _env, jobject _thiz, jint _pointerID, jboolean _isUp, jfloat _x, jfloat _y)
|
void Java_org_ewol_Ewol_EWinputEventState(JNIEnv* _env, jobject _thiz, jint _id, jint _pointerID, jboolean _isUp, jfloat _x, jfloat _y)
|
||||||
{
|
{
|
||||||
esize_t _id = 0; // uint
|
|
||||||
if( _id>=s_listInstance.Size()
|
if( _id>=s_listInstance.Size()
|
||||||
|
|| _id<0
|
||||||
|| NULL==s_listInstance[_id] ) {
|
|| NULL==s_listInstance[_id] ) {
|
||||||
EWOL_ERROR("Call C With an incorrect instance");
|
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||||
// TODO : Generate error in java to stop the current instance
|
// TODO : Generate error in java to stop the current instance
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
s_listInstance[_id]->OS_SetInputState(_pointerID+1, _isUp, vec2(_x,_y));
|
s_listInstance[_id]->OS_SetInputState(_pointerID+1, _isUp, vec2(_x,_y));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Java_org_ewol_Ewol_mouseEventMotion(JNIEnv* _env, jobject _thiz, jint _pointerID, jfloat _x, jfloat _y)
|
void Java_org_ewol_Ewol_EWmouseEventMotion(JNIEnv* _env, jobject _thiz, jint _id, jint _pointerID, jfloat _x, jfloat _y)
|
||||||
{
|
{
|
||||||
esize_t _id = 0; // uint
|
|
||||||
if( _id>=s_listInstance.Size()
|
if( _id>=s_listInstance.Size()
|
||||||
|
|| _id<0
|
||||||
|| NULL==s_listInstance[_id] ) {
|
|| NULL==s_listInstance[_id] ) {
|
||||||
EWOL_ERROR("Call C With an incorrect instance");
|
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||||
// TODO : Generate error in java to stop the current instance
|
// TODO : Generate error in java to stop the current instance
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
s_listInstance[_id]->OS_SetMouseMotion(_pointerID+1, vec2(_x,_y));
|
s_listInstance[_id]->OS_SetMouseMotion(_pointerID+1, vec2(_x,_y));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Java_org_ewol_Ewol_mouseEventState(JNIEnv* _env, jobject _thiz, jint _pointerID, jboolean _isUp, jfloat _x, jfloat _y)
|
void Java_org_ewol_Ewol_EWmouseEventState(JNIEnv* _env, jobject _thiz, jint _id, jint _pointerID, jboolean _isUp, jfloat _x, jfloat _y)
|
||||||
{
|
{
|
||||||
esize_t _id = 0; // uint
|
|
||||||
if( _id>=s_listInstance.Size()
|
if( _id>=s_listInstance.Size()
|
||||||
|
|| _id<0
|
||||||
|| NULL==s_listInstance[_id] ) {
|
|| NULL==s_listInstance[_id] ) {
|
||||||
EWOL_ERROR("Call C With an incorrect instance");
|
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||||
// TODO : Generate error in java to stop the current instance
|
// TODO : Generate error in java to stop the current instance
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
s_listInstance[_id]->OS_SetMouseState(_pointerID+1, _isUp, vec2(_x,_y));
|
s_listInstance[_id]->OS_SetMouseState(_pointerID+1, _isUp, vec2(_x,_y));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Java_org_ewol_Ewol_unknowEvent(JNIEnv* _env, jobject _thiz, jint _pointerID)
|
void Java_org_ewol_Ewol_EWunknowEvent(JNIEnv* _env, jobject _thiz, jint _id, jint _pointerID)
|
||||||
{
|
{
|
||||||
esize_t _id = 0; // uint
|
|
||||||
if( _id>=s_listInstance.Size()
|
if( _id>=s_listInstance.Size()
|
||||||
|
|| _id<0
|
||||||
|| NULL==s_listInstance[_id] ) {
|
|| NULL==s_listInstance[_id] ) {
|
||||||
EWOL_ERROR("Call C With an incorrect instance");
|
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||||
// TODO : Generate error in java to stop the current instance
|
// TODO : Generate error in java to stop the current instance
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EWOL_DEBUG("Unknown IO event : " << _pointerID << " ???");
|
EWOL_DEBUG("Unknown IO event : " << _pointerID << " ???");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Java_org_ewol_Ewol_keyboardEventMove(JNIEnv* _env, jobject _thiz, jint _type, jboolean _isdown)
|
void Java_org_ewol_Ewol_EWkeyboardEventMove(JNIEnv* _env, jobject _thiz, jint _id, jint _type, jboolean _isdown)
|
||||||
{
|
{
|
||||||
esize_t _id = 0; // uint
|
|
||||||
if( _id>=s_listInstance.Size()
|
if( _id>=s_listInstance.Size()
|
||||||
|
|| _id<0
|
||||||
|| NULL==s_listInstance[_id] ) {
|
|| NULL==s_listInstance[_id] ) {
|
||||||
EWOL_ERROR("Call C With an incorrect instance");
|
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||||
// TODO : Generate error in java to stop the current instance
|
// TODO : Generate error in java to stop the current instance
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
EWOL_DEBUG("IO keyboard Move event : \"" << _type << "\" is down=" << _isdown);
|
EWOL_DEBUG("IO keyboard Move event : \"" << _type << "\" is down=" << _isdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Java_org_ewol_Ewol_keyboardEventKey(JNIEnv* _env, jobject _thiz, jint _uniChar, jboolean _isdown)
|
void Java_org_ewol_Ewol_EWkeyboardEventKey(JNIEnv* _env, jobject _thiz, jint _id, jint _uniChar, jboolean _isdown)
|
||||||
{
|
{
|
||||||
esize_t _id = 0; // uint
|
|
||||||
if( _id>=s_listInstance.Size()
|
if( _id>=s_listInstance.Size()
|
||||||
|
|| _id<0
|
||||||
|| NULL==s_listInstance[_id] ) {
|
|| NULL==s_listInstance[_id] ) {
|
||||||
EWOL_ERROR("Call C With an incorrect instance");
|
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||||
// TODO : Generate error in java to stop the current instance
|
// TODO : Generate error in java to stop the current instance
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -692,12 +700,12 @@ extern "C"
|
|||||||
s_listInstance[_id]->ANDROID_SetKeyboard(_uniChar, _isdown);
|
s_listInstance[_id]->ANDROID_SetKeyboard(_uniChar, _isdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Java_org_ewol_Ewol_displayPropertyMetrics(JNIEnv* _env, jobject _thiz, jfloat _ratioX, jfloat _ratioY)
|
void Java_org_ewol_Ewol_EWdisplayPropertyMetrics(JNIEnv* _env, jobject _thiz, jint _id, jfloat _ratioX, jfloat _ratioY)
|
||||||
{
|
{
|
||||||
esize_t _id = 0; // uint
|
|
||||||
if( _id>=s_listInstance.Size()
|
if( _id>=s_listInstance.Size()
|
||||||
|
|| _id<0
|
||||||
|| NULL==s_listInstance[_id] ) {
|
|| NULL==s_listInstance[_id] ) {
|
||||||
EWOL_ERROR("Call C With an incorrect instance");
|
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||||
// TODO : Generate error in java to stop the current instance
|
// TODO : Generate error in java to stop the current instance
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -706,12 +714,12 @@ extern "C"
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO : Set a return true or false if we want to grep this event ...
|
// TODO : Set a return true or false if we want to grep this event ...
|
||||||
void Java_org_ewol_Ewol_keyboardEventKeySystem(JNIEnv* _env, jobject _thiz, jint _keyVal, jboolean _isdown)
|
void Java_org_ewol_Ewol_EWkeyboardEventKeySystem(JNIEnv* _env, jobject _thiz, jint _id, jint _keyVal, jboolean _isdown)
|
||||||
{
|
{
|
||||||
esize_t _id = 0; // uint
|
|
||||||
if( _id>=s_listInstance.Size()
|
if( _id>=s_listInstance.Size()
|
||||||
|
|| _id<0
|
||||||
|| NULL==s_listInstance[_id] ) {
|
|| NULL==s_listInstance[_id] ) {
|
||||||
EWOL_ERROR("Call C With an incorrect instance");
|
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||||
// TODO : Generate error in java to stop the current instance
|
// TODO : Generate error in java to stop the current instance
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -744,24 +752,24 @@ extern "C"
|
|||||||
/* **********************************************************************************************
|
/* **********************************************************************************************
|
||||||
* ** Renderer section :
|
* ** Renderer section :
|
||||||
* ********************************************************************************************** */
|
* ********************************************************************************************** */
|
||||||
void Java_org_ewol_Ewol_renderInit(JNIEnv* _env, jobject _thiz)
|
void Java_org_ewol_Ewol_EWrenderInit(JNIEnv* _env, jobject _thiz, jint _id)
|
||||||
{
|
{
|
||||||
esize_t _id = 0; // uint
|
|
||||||
if( _id>=s_listInstance.Size()
|
if( _id>=s_listInstance.Size()
|
||||||
|
|| _id<0
|
||||||
|| NULL==s_listInstance[_id] ) {
|
|| NULL==s_listInstance[_id] ) {
|
||||||
EWOL_ERROR("Call C With an incorrect instance");
|
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||||
// TODO : Generate error in java to stop the current instance
|
// TODO : Generate error in java to stop the current instance
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Java_org_ewol_Ewol_renderResize( JNIEnv* _env, jobject _thiz, jint _w, jint _h )
|
void Java_org_ewol_Ewol_EWrenderResize( JNIEnv* _env, jobject _thiz, jint _id, jint _w, jint _h )
|
||||||
{
|
{
|
||||||
esize_t _id = 0; // uint
|
|
||||||
if( _id>=s_listInstance.Size()
|
if( _id>=s_listInstance.Size()
|
||||||
|
|| _id<0
|
||||||
|| NULL==s_listInstance[_id] ) {
|
|| NULL==s_listInstance[_id] ) {
|
||||||
EWOL_ERROR("Call C With an incorrect instance");
|
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||||
// TODO : Generate error in java to stop the current instance
|
// TODO : Generate error in java to stop the current instance
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -769,24 +777,24 @@ extern "C"
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO : Return tur or foalse to not redraw when the under draw has not be done (processing gain of time)
|
// TODO : Return tur or foalse to not redraw when the under draw has not be done (processing gain of time)
|
||||||
void Java_org_ewol_Ewol_renderDraw(JNIEnv* _env, jobject _thiz)
|
void Java_org_ewol_Ewol_EWrenderDraw(JNIEnv* _env, jobject _thiz, jint _id)
|
||||||
{
|
{
|
||||||
esize_t _id = 0; // uint
|
|
||||||
if( _id>=s_listInstance.Size()
|
if( _id>=s_listInstance.Size()
|
||||||
|
|| _id<0
|
||||||
|| NULL==s_listInstance[_id] ) {
|
|| NULL==s_listInstance[_id] ) {
|
||||||
EWOL_ERROR("Call C With an incorrect instance");
|
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||||
// TODO : Generate error in java to stop the current instance
|
// TODO : Generate error in java to stop the current instance
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
s_listInstance[_id]->OS_Draw(true);
|
s_listInstance[_id]->OS_Draw(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Java_org_ewol_Ewol_audioPlayback(JNIEnv* _env, void* _reserved, jshortArray _location, jint _frameRate, jint _nbChannels)
|
void Java_org_ewol_Ewol_EWaudioPlayback(JNIEnv* _env, void* _reserved, jint _id, jshortArray _location, jint _frameRate, jint _nbChannels)
|
||||||
{
|
{
|
||||||
esize_t _id = 0; // uint
|
|
||||||
if( _id>=s_listInstance.Size()
|
if( _id>=s_listInstance.Size()
|
||||||
|
|| _id<0
|
||||||
|| NULL==s_listInstance[_id] ) {
|
|| NULL==s_listInstance[_id] ) {
|
||||||
EWOL_ERROR("Call C With an incorrect instance");
|
EWOL_ERROR("Call C With an incorrect instance _id=" << (int32_t)_id);
|
||||||
// TODO : Generate error in java to stop the current instance
|
// TODO : Generate error in java to stop the current instance
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ namespace ewol
|
|||||||
bool _isDown,
|
bool _isDown,
|
||||||
bool _isARepeateKey=false);
|
bool _isARepeateKey=false);
|
||||||
|
|
||||||
virtual void OS_SetClipBoard(ewol::clipBoard::clipboardListe_te _clipboardID);
|
//virtual void OS_SetClipBoard(ewol::clipBoard::clipboardListe_te _clipboardID);
|
||||||
|
|
||||||
void RequestUpdateSize(void);
|
void RequestUpdateSize(void);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user