浏览代码

Merge branch 'master' into PBRisComing

Nehon 10 年之前
父节点
当前提交
0594e5dc7e
共有 100 个文件被更改,包括 3119 次插入6523 次删除
  1. 14 2
      .travis.yml
  2. 3 1
      README.md
  3. 38 13
      common.gradle
  4. 11 0
      gradle.properties
  5. 5 0
      jme3-android/src/main/java/com/jme3/audio/android/AndroidMediaPlayerAudioRenderer.java
  6. 100 174
      jme3-android/src/main/java/com/jme3/input/android/AndroidGestureProcessor.java
  7. 0 686
      jme3-android/src/main/java/com/jme3/input/android/AndroidInput.java
  8. 147 172
      jme3-android/src/main/java/com/jme3/input/android/AndroidInputHandler.java
  9. 159 0
      jme3-android/src/main/java/com/jme3/input/android/AndroidInputHandler14.java
  10. 24 43
      jme3-android/src/main/java/com/jme3/input/android/AndroidJoyInput.java
  11. 108 0
      jme3-android/src/main/java/com/jme3/input/android/AndroidJoyInput14.java
  12. 416 0
      jme3-android/src/main/java/com/jme3/input/android/AndroidJoystickJoyInput14.java
  13. 0 140
      jme3-android/src/main/java/com/jme3/input/android/AndroidKeyHandler.java
  14. 11 6
      jme3-android/src/main/java/com/jme3/input/android/AndroidKeyMapping.java
  15. 24 24
      jme3-android/src/main/java/com/jme3/input/android/AndroidSensorJoyInput.java
  16. 0 257
      jme3-android/src/main/java/com/jme3/input/android/AndroidTouchHandler.java
  17. 475 0
      jme3-android/src/main/java/com/jme3/input/android/AndroidTouchInput.java
  18. 30 46
      jme3-android/src/main/java/com/jme3/input/android/AndroidTouchInput14.java
  19. 12 8
      jme3-android/src/main/java/com/jme3/renderer/android/AndroidGL.java
  20. 11 15
      jme3-android/src/main/java/com/jme3/system/android/OGLESContext.java
  21. 12 0
      jme3-bullet-native/src/native/cpp/com_jme3_bullet_PhysicsSpace.cpp
  22. 8 0
      jme3-bullet-native/src/native/cpp/com_jme3_bullet_PhysicsSpace.h
  23. 1 11
      jme3-bullet/src/common/java/com/jme3/bullet/BulletAppState.java
  24. 1 1
      jme3-bullet/src/common/java/com/jme3/bullet/control/RigidBodyControl.java
  25. 23 23
      jme3-bullet/src/main/java/com/jme3/bullet/PhysicsSpace.java
  26. 20 0
      jme3-core/src/main/java/com/jme3/animation/Bone.java
  27. 15 4
      jme3-core/src/main/java/com/jme3/animation/SkeletonControl.java
  28. 12 12
      jme3-core/src/main/java/com/jme3/app/StatsView.java
  29. 9 1
      jme3-core/src/main/java/com/jme3/audio/AudioNode.java
  30. 1 0
      jme3-core/src/main/java/com/jme3/audio/AudioRenderer.java
  31. 5 0
      jme3-core/src/main/java/com/jme3/audio/AudioSource.java
  32. 13 0
      jme3-core/src/main/java/com/jme3/audio/AudioStream.java
  33. 60 0
      jme3-core/src/main/java/com/jme3/audio/openal/ALAudioRenderer.java
  34. 2 6
      jme3-core/src/main/java/com/jme3/export/JmeExporter.java
  35. 18 18
      jme3-core/src/main/java/com/jme3/math/ColorRGBA.java
  36. 19 0
      jme3-core/src/main/java/com/jme3/math/FastMath.java
  37. 20 0
      jme3-core/src/main/java/com/jme3/math/Transform.java
  38. 13 1
      jme3-core/src/main/java/com/jme3/renderer/Caps.java
  39. 2 1
      jme3-core/src/main/java/com/jme3/renderer/opengl/GL.java
  40. 7 3
      jme3-core/src/main/java/com/jme3/renderer/opengl/GL3.java
  41. 23 3
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLDebugDesktop.java
  42. 8 6
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLDebugES.java
  43. 1 3
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLExt.java
  44. 2 1
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLFbo.java
  45. 24 14
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLImageFormats.java
  46. 111 98
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java
  47. 122 0
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLTiming.java
  48. 41 0
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLTimingState.java
  49. 3 4
      jme3-core/src/main/java/com/jme3/renderer/opengl/GLTracer.java
  50. 7 5
      jme3-core/src/main/java/com/jme3/scene/BatchNode.java
  51. 1 0
      jme3-core/src/main/java/com/jme3/scene/shape/AbstractBox.java
  52. 1 0
      jme3-core/src/main/java/com/jme3/shader/Glsl100ShaderGenerator.java
  53. 0 9
      jme3-core/src/main/java/com/jme3/system/JmeSystem.java
  54. 0 5
      jme3-core/src/main/java/com/jme3/system/JmeSystemDelegate.java
  55. 17 15
      jme3-core/src/main/java/com/jme3/texture/Image.java
  56. 46 5
      jme3-core/src/main/java/com/jme3/texture/image/DefaultImageRaster.java
  57. 23 2
      jme3-core/src/main/java/com/jme3/texture/image/ImageRaster.java
  58. 140 0
      jme3-core/src/main/java/com/jme3/util/MipMapGenerator.java
  59. 15 17
      jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.frag
  60. 12 9
      jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.vert
  61. 0 22
      jme3-core/src/main/resources/com/jme3/asset/Desktop.cfg
  62. 1 1
      jme3-core/src/main/resources/com/jme3/asset/General.cfg
  63. 13 6
      jme3-core/src/main/resources/joystick-mapping.properties
  64. 31 9
      jme3-core/src/plugins/java/com/jme3/export/binary/BinaryExporter.java
  65. 7 5
      jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java
  66. 12 11
      jme3-core/src/plugins/java/com/jme3/texture/plugins/DXTFlipper.java
  67. 90 0
      jme3-core/src/tools/java/jme3tools/optimize/GeometryBatchFactory.java
  68. 2 2
      jme3-effects/src/main/java/com/jme3/post/ssao/SSAOFilter.java
  69. 2 2
      jme3-examples/src/main/java/jme3test/bullet/TestAttachDriver.java
  70. 1 1
      jme3-examples/src/main/java/jme3test/bullet/TestAttachGhostObject.java
  71. 152 152
      jme3-examples/src/main/java/jme3test/bullet/TestCcd.java
  72. 2 2
      jme3-examples/src/main/java/jme3test/bullet/TestCollisionGroups.java
  73. 98 98
      jme3-examples/src/main/java/jme3test/bullet/TestCollisionListener.java
  74. 1 1
      jme3-examples/src/main/java/jme3test/bullet/TestCollisionShapeFactory.java
  75. 1 1
      jme3-examples/src/main/java/jme3test/bullet/TestGhostObject.java
  76. 4 4
      jme3-examples/src/main/java/jme3test/bullet/TestKinematicAddToPhysicsSpaceIssue.java
  77. 1 1
      jme3-examples/src/main/java/jme3test/bullet/TestLocalPhysics.java
  78. 1 1
      jme3-examples/src/main/java/jme3test/bullet/TestPhysicsCar.java
  79. 2 2
      jme3-examples/src/main/java/jme3test/bullet/TestPhysicsHingeJoint.java
  80. 9 9
      jme3-examples/src/main/java/jme3test/bullet/TestPhysicsRayCast.java
  81. 1 1
      jme3-examples/src/main/java/jme3test/bullet/TestPhysicsReadWrite.java
  82. 1 1
      jme3-examples/src/main/java/jme3test/bullet/TestRagDoll.java
  83. 1 1
      jme3-examples/src/main/java/jme3test/bullet/TestSimplePhysics.java
  84. 3 3
      jme3-examples/src/main/java/jme3test/bullet/TestSweepTest.java
  85. 3 20
      jme3-examples/src/main/java/jme3test/effect/TestParticleExportingCloning.java
  86. 83 0
      jme3-examples/src/main/java/jme3test/model/anim/TestModelExportingCloning.java
  87. 2 2
      jme3-examples/src/main/resources/jme3test/texture/UnshadedArray.frag
  88. 6 0
      jme3-ios/src/main/java/com/jme3/asset/IOS.cfg
  89. 0 1054
      jme3-ios/src/main/java/com/jme3/audio/android/AL.java
  90. 0 67
      jme3-ios/src/main/java/com/jme3/audio/android/AndroidAudioData.java
  91. 53 0
      jme3-ios/src/main/java/com/jme3/audio/ios/IosAL.java
  92. 26 0
      jme3-ios/src/main/java/com/jme3/audio/ios/IosALC.java
  93. 32 0
      jme3-ios/src/main/java/com/jme3/audio/ios/IosEFX.java
  94. 0 20
      jme3-ios/src/main/java/com/jme3/audio/plugins/AndroidAudioLoader.java
  95. 0 2573
      jme3-ios/src/main/java/com/jme3/renderer/ios/IGLESShaderRenderer.java
  96. 7 1
      jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java
  97. 0 576
      jme3-ios/src/main/java/com/jme3/renderer/ios/TextureUtil.java
  98. 3 2
      jme3-ios/src/main/java/com/jme3/system/ios/IGLESContext.java
  99. 9 6
      jme3-ios/src/main/java/com/jme3/system/ios/IosImageLoader.java
  100. 13 2
      jme3-ios/src/main/java/com/jme3/system/ios/JmeIosSystem.java

+ 14 - 2
.travis.yml

@@ -1,11 +1,23 @@
 language: java
-# jdk:
-#   - oraclejdk8
+sudo: false
+env:
+ - GRADLE_USER_HOME=gradle-cache
+ 
+cache:
+  directories:
+   - gradle-cache
+   - netbeans
 
 branches:
   only:
   - master
 
+notifications:
+  slack:
+    secure: "PWEk4+VL986c3gAjWp12nqyifvxCjBqKoESG9d7zWh1uiTLadTHhZJRMdsye36FCpz/c/Jt7zCRO/5y7FaubQptnRrkrRfjp5f99MJRzQVXnUAM+y385qVkXKRKd/PLpM7XPm4AvjvxHCyvzX2wamRvul/TekaXKB9Ti5FCN87s="
+    on_success: change
+    on_failure: always
+
 before_install:
   # required libs for android build tools
   # sudo apt-get update

+ 3 - 1
README.md

@@ -1,6 +1,8 @@
-jMonkeyEngine
+jMonkeyEngine 
 =============
 
+[![Build Status](https://travis-ci.org/jMonkeyEngine/jmonkeyengine.svg?branch=master)](https://travis-ci.org/jMonkeyEngine/jmonkeyengine)
+
 jMonkeyEngine is a 3D game engine for adventurous Java developers. It’s open source, cross platform and cutting edge. And it is all beautifully documented. The 3.0 branch is the latest stable version of the jMonkeyEngine 3 SDK, a complete game development suite. We'll be frequently submitting stable 3.0.x updates until the major 3.1 version arrives.
 
 The engine is used by several commercial game studios and computer-science courses. Here's a taste:

+ 38 - 13
common.gradle

@@ -4,16 +4,17 @@
 
 apply plugin: 'java'
 apply plugin: 'maven'
+apply plugin: 'maven-publish'
 
-String mavenGroupId = 'com.jme3'
-String mavenVersion = jmeVersion + '-' + jmeVersionTag //'-SNAPSHOT'
+group   = 'com.jme3'
+version = jmeVersion + '-' + jmeVersionTag
 
 sourceCompatibility = '1.6'
 [compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
 
 repositories {
     mavenCentral()
-    maven{
+    maven {
         url "http://nifty-gui.sourceforge.net/nifty-maven-repo"
     }
 }
@@ -23,11 +24,6 @@ dependencies {
     testCompile group: 'junit', name: 'junit', version: '4.10'
 }
 
-String mavenArtifactId = name
-
-group = mavenGroupId
-version = mavenVersion
-
 javadoc {
     failOnError = false
     options.memberLevel = org.gradle.external.javadoc.JavadocMemberLevel.PROTECTED
@@ -60,11 +56,40 @@ artifacts {
     }
 }
 
-configure(install.repositories.mavenInstaller) {
-    pom.project {
-        groupId = mavenGroupId
-        artifactId = mavenArtifactId
-        version = mavenVersion
+publishing {
+    publications {
+        maven(MavenPublication) {
+            from components.java
+            artifact sourcesJar
+            artifact javadocJar
+
+            pom.withXml {
+                asNode().children().last() + {
+                        resolveStrategy = Closure.DELEGATE_FIRST
+                        name POM_NAME
+                        description POM_DESCRIPTION
+                        url POM_URL
+                        scm {
+                            url POM_SCM_URL
+                            connection POM_SCM_CONNECTION
+                            developerConnection POM_SCM_DEVELOPER_CONNECTION
+                        }
+                        licenses {
+                            license {
+                                name POM_LICENSE_NAME
+                                url POM_LICENSE_URL
+                                distribution POM_LICENSE_DISTRIBUTION
+                            }
+                        }
+                }
+            }
+        }
+    }
+
+    repositories {
+        maven {
+            url "${rootProject.buildDir}/repo" // change to point to your repo, e.g. http://my.org/repo
+        }
     }
 }
 

+ 11 - 0
gradle.properties

@@ -23,3 +23,14 @@ bulletZipFile = bullet.zip
 
 # Path for downloading NetBeans Base
 netbeansUrl = http://download.netbeans.org/netbeans/8.0.2/final/zip/netbeans-8.0.2-201411181905-javase.zip
+
+# POM settings
+POM_NAME=jMonkeyEngine
+POM_DESCRIPTION=jMonkeyEngine is a 3D game engine for adventurous Java developers
+POM_URL=http://jmonkeyengine.org
+POM_SCM_URL=https://github.com/jMonkeyEngine/jmonkeyengine
+POM_SCM_CONNECTION=scm:git:git://github.com/jMonkeyEngine/jmonkeyengine.git
+POM_SCM_DEVELOPER_CONNECTION=scm:git:[email protected]:jMonkeyEngine/jmonkeyengine.git
+POM_LICENSE_NAME=New BSD (3-clause) License
+POM_LICENSE_URL=http://opensource.org/licenses/BSD-3-Clause
+POM_LICENSE_DISTRIBUTION=repo

+ 5 - 0
jme3-android/src/main/java/com/jme3/audio/android/AndroidMediaPlayerAudioRenderer.java

@@ -525,4 +525,9 @@ public class AndroidMediaPlayerAudioRenderer implements AudioRenderer,
     @Override
     public void deleteFilter(Filter filter) {
     }
+
+    @Override
+    public float getSourcePlaybackTime(AudioSource src) {
+        throw new UnsupportedOperationException("Not supported yet.");
+    }
 }

+ 100 - 174
jme3-android/src/main/java/com/jme3/input/android/AndroidGestureHandler.java → jme3-android/src/main/java/com/jme3/input/android/AndroidGestureProcessor.java

@@ -35,314 +35,240 @@ package com.jme3.input.android;
 import android.view.GestureDetector;
 import android.view.MotionEvent;
 import android.view.ScaleGestureDetector;
-import android.view.View;
-import com.jme3.input.event.InputEvent;
-import com.jme3.input.event.MouseMotionEvent;
 import com.jme3.input.event.TouchEvent;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
 /**
  * AndroidGestureHandler uses Gesture type listeners to create jME TouchEvents
- * for gestures.  This class is designed to handle the gestures supported 
+ * for gestures.  This class is designed to handle the gestures supported
  * on Android rev 9 (Android 2.3).  Extend this class to add functionality
  * added by Android after rev 9.
- * 
+ *
  * @author iwgeric
  */
-public class AndroidGestureHandler implements 
-        GestureDetector.OnGestureListener, 
+public class AndroidGestureProcessor implements
+        GestureDetector.OnGestureListener,
         GestureDetector.OnDoubleTapListener,
         ScaleGestureDetector.OnScaleGestureListener {
-    private static final Logger logger = Logger.getLogger(AndroidGestureHandler.class.getName());
-    private AndroidInputHandler androidInput;
-    private GestureDetector gestureDetector;
-    private ScaleGestureDetector scaleDetector;
+    private static final Logger logger = Logger.getLogger(AndroidGestureProcessor.class.getName());
+
+    private AndroidTouchInput touchInput;
     float gestureDownX = -1f;
     float gestureDownY = -1f;
     float scaleStartX = -1f;
     float scaleStartY = -1f;
 
-    public AndroidGestureHandler(AndroidInputHandler androidInput) {
-        this.androidInput = androidInput;
-    }
-    
-    public void initialize() {
-    }
-    
-    public void destroy() {
-        setView(null);
-    }
-    
-    public void setView(View view) {
-        if (view != null) {
-            gestureDetector = new GestureDetector(view.getContext(), this);
-            scaleDetector = new ScaleGestureDetector(view.getContext(), this);
-        } else {
-            gestureDetector = null;
-            scaleDetector = null;
-        }
-    }
-    
-    public void detectGesture(MotionEvent event) {
-        if (gestureDetector != null && scaleDetector != null) {
-            gestureDetector.onTouchEvent(event);
-            scaleDetector.onTouchEvent(event);
-        }
-    }
-
-    private int getPointerIndex(MotionEvent event) {
-        return (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK)
-                >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
-    }
-    
-    private int getPointerId(MotionEvent event) {
-        return event.getPointerId(getPointerIndex(event));
+    public AndroidGestureProcessor(AndroidTouchInput touchInput) {
+        this.touchInput = touchInput;
     }
-    
-    private void processEvent(TouchEvent event) {
-        // Add the touch event
-        androidInput.addEvent(event);
-        if (androidInput.isSimulateMouse()) {
-            InputEvent mouseEvent = generateMouseEvent(event);
-            if (mouseEvent != null) {
-                // Add the mouse event
-                androidInput.addEvent(mouseEvent);
-            }
-        }
-    }
-
-    // TODO: Ring Buffer for mouse events?
-    private InputEvent generateMouseEvent(TouchEvent event) {
-        InputEvent inputEvent = null;
-        int newX;
-        int newY;
-        int newDX;
-        int newDY;
 
-        if (androidInput.isMouseEventsInvertX()) {
-            newX = (int) (androidInput.invertX(event.getX()));
-            newDX = (int)event.getDeltaX() * -1;
-        } else {
-            newX = (int) event.getX();
-            newDX = (int)event.getDeltaX();
-        }
-        int wheel = (int) (event.getScaleSpan()); // might need to scale to match mouse wheel
-        int dWheel = (int) (event.getDeltaScaleSpan()); // might need to scale to match mouse wheel
-
-        if (androidInput.isMouseEventsInvertY()) {
-            newY = (int) (androidInput.invertY(event.getY()));
-            newDY = (int)event.getDeltaY() * -1;
-        } else {
-            newY = (int) event.getY();
-            newDY = (int)event.getDeltaY();
-        }
-
-        switch (event.getType()) {
-            case SCALE_MOVE:
-                inputEvent = new MouseMotionEvent(newX, newY, newDX, newDY, wheel, dWheel);
-                inputEvent.setTime(event.getTime());
-                break;
-        }
-
-        return inputEvent;
-    }
-    
     /* Events from onGestureListener */
-    
+
+    @Override
     public boolean onDown(MotionEvent event) {
         // start of all GestureListeners.  Not really a gesture by itself
         // so we don't create an event.
         // However, reset the scaleInProgress here since this is the beginning
         // of a series of gesture events.
-//        logger.log(Level.INFO, "onDown pointerId: {0}, action: {1}, x: {2}, y: {3}", 
-//                new Object[]{getPointerId(event), getAction(event), event.getX(), event.getY()});
-        gestureDownX = androidInput.getJmeX(event.getX());
-        gestureDownY = androidInput.invertY(androidInput.getJmeY(event.getY()));
+//        logger.log(Level.INFO, "onDown pointerId: {0}, action: {1}, x: {2}, y: {3}",
+//                new Object[]{touchInput.getPointerId(event), touchInput.getAction(event), event.getX(), event.getY()});
+        gestureDownX = touchInput.getJmeX(event.getX());
+        gestureDownY = touchInput.invertY(touchInput.getJmeY(event.getY()));
         return true;
     }
 
+    @Override
     public boolean onSingleTapUp(MotionEvent event) {
         // Up of single tap.  May be followed by a double tap later.
         // use onSingleTapConfirmed instead.
-//        logger.log(Level.INFO, "onSingleTapUp pointerId: {0}, action: {1}, x: {2}, y: {3}", 
-//                new Object[]{getPointerId(event), getAction(event), event.getX(), event.getY()});
+//        logger.log(Level.INFO, "onSingleTapUp pointerId: {0}, action: {1}, x: {2}, y: {3}",
+//                new Object[]{touchInput.getPointerId(event), touchInput.getAction(event), event.getX(), event.getY()});
         return true;
     }
 
+    @Override
     public void onShowPress(MotionEvent event) {
-//        logger.log(Level.INFO, "onShowPress pointerId: {0}, action: {1}, x: {2}, y: {3}", 
-//                new Object[]{getPointerId(event), getAction(event), event.getX(), event.getY()});
-        float jmeX = androidInput.getJmeX(event.getX());
-        float jmeY = androidInput.invertY(androidInput.getJmeY(event.getY()));
-        TouchEvent touchEvent = androidInput.getFreeTouchEvent();
+//        logger.log(Level.INFO, "onShowPress pointerId: {0}, action: {1}, x: {2}, y: {3}",
+//                new Object[]{touchInput.getPointerId(event), touchInput.getAction(event), event.getX(), event.getY()});
+        float jmeX = touchInput.getJmeX(event.getX());
+        float jmeY = touchInput.invertY(touchInput.getJmeY(event.getY()));
+        TouchEvent touchEvent = touchInput.getFreeTouchEvent();
         touchEvent.set(TouchEvent.Type.SHOWPRESS, jmeX, jmeY, 0, 0);
-        touchEvent.setPointerId(getPointerId(event));
+        touchEvent.setPointerId(touchInput.getPointerId(event));
         touchEvent.setTime(event.getEventTime());
         touchEvent.setPressure(event.getPressure());
-        processEvent(touchEvent);
+        touchInput.addEvent(touchEvent);
     }
 
+    @Override
     public void onLongPress(MotionEvent event) {
-//        logger.log(Level.INFO, "onLongPress pointerId: {0}, action: {1}, x: {2}, y: {3}", 
-//                new Object[]{getPointerId(event), getAction(event), event.getX(), event.getY()});
-        float jmeX = androidInput.getJmeX(event.getX());
-        float jmeY = androidInput.invertY(androidInput.getJmeY(event.getY()));
-        TouchEvent touchEvent = androidInput.getFreeTouchEvent();
+//        logger.log(Level.INFO, "onLongPress pointerId: {0}, action: {1}, x: {2}, y: {3}",
+//                new Object[]{touchInput.getPointerId(event), touchInput.getAction(event), event.getX(), event.getY()});
+        float jmeX = touchInput.getJmeX(event.getX());
+        float jmeY = touchInput.invertY(touchInput.getJmeY(event.getY()));
+        TouchEvent touchEvent = touchInput.getFreeTouchEvent();
         touchEvent.set(TouchEvent.Type.LONGPRESSED, jmeX, jmeY, 0, 0);
-        touchEvent.setPointerId(getPointerId(event));
+        touchEvent.setPointerId(touchInput.getPointerId(event));
         touchEvent.setTime(event.getEventTime());
         touchEvent.setPressure(event.getPressure());
-        processEvent(touchEvent);
+        touchInput.addEvent(touchEvent);
     }
 
+    @Override
     public boolean onScroll(MotionEvent startEvent, MotionEvent endEvent, float distX, float distY) {
         // if not scaleInProgess, send scroll events.  This is to avoid sending
         // scroll events when one of the fingers is lifted just before the other one.
         // Avoids sending the scroll for that brief period of time.
         // Return true so that the next event doesn't accumulate the distX and distY values.
-        // Apparantly, both distX and distY are negative.  
+        // Apparantly, both distX and distY are negative.
         // Negate distX to get the real value, but leave distY negative to compensate
         // for the fact that jME has y=0 at bottom where Android has y=0 at top.
-//        if (!scaleInProgress) {
-        if (!scaleDetector.isInProgress()) {
-//            logger.log(Level.INFO, "onScroll pointerId: {0}, startAction: {1}, startX: {2}, startY: {3}, endAction: {4}, endX: {5}, endY: {6}, dx: {7}, dy: {8}", 
-//                    new Object[]{getPointerId(startEvent), getAction(startEvent), startEvent.getX(), startEvent.getY(), getAction(endEvent), endEvent.getX(), endEvent.getY(), distX, distY});
+        if (!touchInput.getScaleDetector().isInProgress()) {
+//            logger.log(Level.INFO, "onScroll pointerId: {0}, startAction: {1}, startX: {2}, startY: {3}, endAction: {4}, endX: {5}, endY: {6}, dx: {7}, dy: {8}",
+//                    new Object[]{touchInput.getPointerId(startEvent), touchInput.getAction(startEvent), startEvent.getX(), startEvent.getY(), touchInput.getAction(endEvent), endEvent.getX(), endEvent.getY(), distX, distY});
 
-            float jmeX = androidInput.getJmeX(endEvent.getX());
-            float jmeY = androidInput.invertY(androidInput.getJmeY(endEvent.getY()));
-            TouchEvent touchEvent = androidInput.getFreeTouchEvent();
-            touchEvent.set(TouchEvent.Type.SCROLL, jmeX, jmeY, androidInput.getJmeX(-distX), androidInput.getJmeY(distY));
-            touchEvent.setPointerId(getPointerId(endEvent));
+            float jmeX = touchInput.getJmeX(endEvent.getX());
+            float jmeY = touchInput.invertY(touchInput.getJmeY(endEvent.getY()));
+            TouchEvent touchEvent = touchInput.getFreeTouchEvent();
+            touchEvent.set(TouchEvent.Type.SCROLL, jmeX, jmeY, touchInput.getJmeX(-distX), touchInput.getJmeY(distY));
+            touchEvent.setPointerId(touchInput.getPointerId(endEvent));
             touchEvent.setTime(endEvent.getEventTime());
             touchEvent.setPressure(endEvent.getPressure());
-            processEvent(touchEvent);
+            touchInput.addEvent(touchEvent);
         }
         return true;
     }
 
+    @Override
     public boolean onFling(MotionEvent startEvent, MotionEvent endEvent, float velocityX, float velocityY) {
         // Fling happens only once at the end of the gesture (all fingers up).
         // Fling returns the velocity of the finger movement in pixels/sec.
         // Therefore, the dX and dY values are actually velocity instead of distance values
         // Since this does not track the movement, use the start position and velocity values.
-        
-//        logger.log(Level.INFO, "onFling pointerId: {0}, startAction: {1}, startX: {2}, startY: {3}, endAction: {4}, endX: {5}, endY: {6}, velocityX: {7}, velocityY: {8}", 
-//                new Object[]{getPointerId(startEvent), getAction(startEvent), startEvent.getX(), startEvent.getY(), getAction(endEvent), endEvent.getX(), endEvent.getY(), velocityX, velocityY});
 
-        float jmeX = androidInput.getJmeX(startEvent.getX());
-        float jmeY = androidInput.invertY(androidInput.getJmeY(startEvent.getY()));
-        TouchEvent touchEvent = androidInput.getFreeTouchEvent();
+//        logger.log(Level.INFO, "onFling pointerId: {0}, startAction: {1}, startX: {2}, startY: {3}, endAction: {4}, endX: {5}, endY: {6}, velocityX: {7}, velocityY: {8}",
+//                new Object[]{touchInput.getPointerId(startEvent), touchInput.getAction(startEvent), startEvent.getX(), startEvent.getY(), touchInput.getAction(endEvent), endEvent.getX(), endEvent.getY(), velocityX, velocityY});
+
+        float jmeX = touchInput.getJmeX(startEvent.getX());
+        float jmeY = touchInput.invertY(touchInput.getJmeY(startEvent.getY()));
+        TouchEvent touchEvent = touchInput.getFreeTouchEvent();
         touchEvent.set(TouchEvent.Type.FLING, jmeX, jmeY, velocityX, velocityY);
-        touchEvent.setPointerId(getPointerId(endEvent));
+        touchEvent.setPointerId(touchInput.getPointerId(endEvent));
         touchEvent.setTime(endEvent.getEventTime());
         touchEvent.setPressure(endEvent.getPressure());
-        processEvent(touchEvent);
+        touchInput.addEvent(touchEvent);
         return true;
     }
 
     /* Events from onDoubleTapListener */
-    
+
+    @Override
     public boolean onSingleTapConfirmed(MotionEvent event) {
         // Up of single tap when no double tap followed.
-//        logger.log(Level.INFO, "onSingleTapConfirmed pointerId: {0}, action: {1}, x: {2}, y: {3}", 
-//                new Object[]{getPointerId(event), getAction(event), event.getX(), event.getY()});
-        float jmeX = androidInput.getJmeX(event.getX());
-        float jmeY = androidInput.invertY(androidInput.getJmeY(event.getY()));
-        TouchEvent touchEvent = androidInput.getFreeTouchEvent();
+//        logger.log(Level.INFO, "onSingleTapConfirmed pointerId: {0}, action: {1}, x: {2}, y: {3}",
+//                new Object[]{touchInput.getPointerId(event), touchInput.getAction(event), event.getX(), event.getY()});
+        float jmeX = touchInput.getJmeX(event.getX());
+        float jmeY = touchInput.invertY(touchInput.getJmeY(event.getY()));
+        TouchEvent touchEvent = touchInput.getFreeTouchEvent();
         touchEvent.set(TouchEvent.Type.TAP, jmeX, jmeY, 0, 0);
-        touchEvent.setPointerId(getPointerId(event));
+        touchEvent.setPointerId(touchInput.getPointerId(event));
         touchEvent.setTime(event.getEventTime());
         touchEvent.setPressure(event.getPressure());
-        processEvent(touchEvent);
+        touchInput.addEvent(touchEvent);
         return true;
     }
 
+    @Override
     public boolean onDoubleTap(MotionEvent event) {
         //The down motion event of the first tap of the double-tap
-        // We could use this event to fire off a double tap event, or use 
+        // We could use this event to fire off a double tap event, or use
         // DoubleTapEvent with a check for the UP action
-//        logger.log(Level.INFO, "onDoubleTap pointerId: {0}, action: {1}, x: {2}, y: {3}", 
-//                new Object[]{getPointerId(event), getAction(event), event.getX(), event.getY()});
-        float jmeX = androidInput.getJmeX(event.getX());
-        float jmeY = androidInput.invertY(androidInput.getJmeY(event.getY()));
-        TouchEvent touchEvent = androidInput.getFreeTouchEvent();
+//        logger.log(Level.INFO, "onDoubleTap pointerId: {0}, action: {1}, x: {2}, y: {3}",
+//                new Object[]{touchInput.getPointerId(event), touchInput.getAction(event), event.getX(), event.getY()});
+        float jmeX = touchInput.getJmeX(event.getX());
+        float jmeY = touchInput.invertY(touchInput.getJmeY(event.getY()));
+        TouchEvent touchEvent = touchInput.getFreeTouchEvent();
         touchEvent.set(TouchEvent.Type.DOUBLETAP, jmeX, jmeY, 0, 0);
-        touchEvent.setPointerId(getPointerId(event));
+        touchEvent.setPointerId(touchInput.getPointerId(event));
         touchEvent.setTime(event.getEventTime());
         touchEvent.setPressure(event.getPressure());
-        processEvent(touchEvent);
+        touchInput.addEvent(touchEvent);
         return true;
     }
 
+    @Override
     public boolean onDoubleTapEvent(MotionEvent event) {
         //Notified when an event within a double-tap gesture occurs, including the down, move(s), and up events.
         // this means it will get called multiple times for a single double tap
-//        logger.log(Level.INFO, "onDoubleTapEvent pointerId: {0}, action: {1}, x: {2}, y: {3}", 
-//                new Object[]{getPointerId(event), getAction(event), event.getX(), event.getY()});
-//        if (getAction(event) == MotionEvent.ACTION_UP) {
-//            TouchEvent touchEvent = touchEventPool.getNextFreeEvent();
-//            touchEvent.set(TouchEvent.Type.DOUBLETAP, event.getX(), androidInput.invertY(event.getY()), 0, 0);
-//            touchEvent.setPointerId(getPointerId(event));
-//            touchEvent.setTime(event.getEventTime());
-//            touchEvent.setPressure(event.getPressure());
-//            processEvent(touchEvent);
-//        }
+//        logger.log(Level.INFO, "onDoubleTapEvent pointerId: {0}, action: {1}, x: {2}, y: {3}",
+//                new Object[]{touchInput.getPointerId(event), touchInput.getAction(event), event.getX(), event.getY()});
+        if (touchInput.getAction(event) == MotionEvent.ACTION_UP) {
+            TouchEvent touchEvent = touchInput.getFreeTouchEvent();
+            touchEvent.set(TouchEvent.Type.DOUBLETAP, event.getX(), touchInput.invertY(event.getY()), 0, 0);
+            touchEvent.setPointerId(touchInput.getPointerId(event));
+            touchEvent.setTime(event.getEventTime());
+            touchEvent.setPressure(event.getPressure());
+            touchInput.addEvent(touchEvent);
+        }
         return true;
     }
 
     /* Events from ScaleGestureDetector */
-    
+
+    @Override
     public boolean onScaleBegin(ScaleGestureDetector scaleGestureDetector) {
         // Scale uses a focusX and focusY instead of x and y.  Focus is the middle
         // of the fingers.  Therefore, use the x and y values from the Down event
         // so that the x and y values don't jump to the middle position.
         // return true or all gestures for this beginning event will be discarded
-        logger.log(Level.INFO, "onScaleBegin");
+//        logger.log(Level.INFO, "onScaleBegin");
         scaleStartX = gestureDownX;
         scaleStartY = gestureDownY;
-        TouchEvent touchEvent = androidInput.getFreeTouchEvent();
+        TouchEvent touchEvent = touchInput.getFreeTouchEvent();
         touchEvent.set(TouchEvent.Type.SCALE_START, scaleStartX, scaleStartY, 0f, 0f);
         touchEvent.setPointerId(0);
         touchEvent.setTime(scaleGestureDetector.getEventTime());
         touchEvent.setScaleSpan(scaleGestureDetector.getCurrentSpan());
         touchEvent.setDeltaScaleSpan(0f);
         touchEvent.setScaleFactor(scaleGestureDetector.getScaleFactor());
-        touchEvent.setScaleSpanInProgress(scaleDetector.isInProgress());
-        processEvent(touchEvent);
-        
+        touchEvent.setScaleSpanInProgress(touchInput.getScaleDetector().isInProgress());
+        touchInput.addEvent(touchEvent);
+
         return true;
     }
 
+    @Override
     public boolean onScale(ScaleGestureDetector scaleGestureDetector) {
         // return true or all gestures for this event will be accumulated
-        logger.log(Level.INFO, "onScale");
+//        logger.log(Level.INFO, "onScale");
         scaleStartX = gestureDownX;
         scaleStartY = gestureDownY;
-        TouchEvent touchEvent = androidInput.getFreeTouchEvent();
+        TouchEvent touchEvent = touchInput.getFreeTouchEvent();
         touchEvent.set(TouchEvent.Type.SCALE_MOVE, scaleStartX, scaleStartY, 0f, 0f);
         touchEvent.setPointerId(0);
         touchEvent.setTime(scaleGestureDetector.getEventTime());
         touchEvent.setScaleSpan(scaleGestureDetector.getCurrentSpan());
         touchEvent.setDeltaScaleSpan(scaleGestureDetector.getCurrentSpan() - scaleGestureDetector.getPreviousSpan());
         touchEvent.setScaleFactor(scaleGestureDetector.getScaleFactor());
-        touchEvent.setScaleSpanInProgress(scaleDetector.isInProgress());
-        processEvent(touchEvent);
+        touchEvent.setScaleSpanInProgress(touchInput.getScaleDetector().isInProgress());
+        touchInput.addEvent(touchEvent);
         return true;
     }
 
+    @Override
     public void onScaleEnd(ScaleGestureDetector scaleGestureDetector) {
-        logger.log(Level.INFO, "onScaleEnd");
+//        logger.log(Level.INFO, "onScaleEnd");
         scaleStartX = gestureDownX;
         scaleStartY = gestureDownY;
-        TouchEvent touchEvent = androidInput.getFreeTouchEvent();
+        TouchEvent touchEvent = touchInput.getFreeTouchEvent();
         touchEvent.set(TouchEvent.Type.SCALE_END, scaleStartX, scaleStartY, 0f, 0f);
         touchEvent.setPointerId(0);
         touchEvent.setTime(scaleGestureDetector.getEventTime());
         touchEvent.setScaleSpan(scaleGestureDetector.getCurrentSpan());
         touchEvent.setDeltaScaleSpan(scaleGestureDetector.getCurrentSpan() - scaleGestureDetector.getPreviousSpan());
         touchEvent.setScaleFactor(scaleGestureDetector.getScaleFactor());
-        touchEvent.setScaleSpanInProgress(scaleDetector.isInProgress());
-        processEvent(touchEvent);
+        touchEvent.setScaleSpanInProgress(touchInput.getScaleDetector().isInProgress());
+        touchInput.addEvent(touchEvent);
     }
 }

+ 0 - 686
jme3-android/src/main/java/com/jme3/input/android/AndroidInput.java

@@ -1,686 +0,0 @@
-package com.jme3.input.android;
-
-import android.view.*;
-import com.jme3.input.KeyInput;
-import com.jme3.input.RawInputListener;
-import com.jme3.input.TouchInput;
-import com.jme3.input.event.MouseButtonEvent;
-import com.jme3.input.event.MouseMotionEvent;
-import com.jme3.input.event.TouchEvent;
-import com.jme3.input.event.TouchEvent.Type;
-import com.jme3.math.Vector2f;
-import com.jme3.system.AppSettings;
-import com.jme3.util.RingBuffer;
-import java.util.HashMap;
-import java.util.logging.Logger;
-
-/**
- * <code>AndroidInput</code> is one of the main components that connect jme with android. Is derived from GLSurfaceView and handles all Inputs
- * @author larynx
- *
- */
-public class AndroidInput implements
-        TouchInput,
-        View.OnTouchListener,
-        View.OnKeyListener,
-        GestureDetector.OnGestureListener,
-        GestureDetector.OnDoubleTapListener,
-        ScaleGestureDetector.OnScaleGestureListener {
-
-    final private static int MAX_EVENTS = 1024;
-    // Custom settings
-    public boolean mouseEventsEnabled = true;
-    public boolean mouseEventsInvertX = false;
-    public boolean mouseEventsInvertY = false;
-    public boolean keyboardEventsEnabled = false;
-    public boolean dontSendHistory = false;
-    // Used to transfer events from android thread to GLThread
-    final private RingBuffer<TouchEvent> eventQueue = new RingBuffer<TouchEvent>(MAX_EVENTS);
-    final private RingBuffer<TouchEvent> eventPoolUnConsumed = new RingBuffer<TouchEvent>(MAX_EVENTS);
-    final private RingBuffer<TouchEvent> eventPool = new RingBuffer<TouchEvent>(MAX_EVENTS);
-    final private HashMap<Integer, Vector2f> lastPositions = new HashMap<Integer, Vector2f>();
-    // Internal
-    private View view;
-    private ScaleGestureDetector scaledetector;
-    private boolean scaleInProgress = false;
-    private GestureDetector detector;
-    private int lastX;
-    private int lastY;
-    private final static Logger logger = Logger.getLogger(AndroidInput.class.getName());
-    private boolean isInitialized = false;
-    private RawInputListener listener = null;
-    private static final int[] ANDROID_TO_JME = {
-        0x0, // unknown
-        0x0, // key code soft left
-        0x0, // key code soft right
-        KeyInput.KEY_HOME,
-        KeyInput.KEY_ESCAPE, // key back
-        0x0, // key call
-        0x0, // key endcall
-        KeyInput.KEY_0,
-        KeyInput.KEY_1,
-        KeyInput.KEY_2,
-        KeyInput.KEY_3,
-        KeyInput.KEY_4,
-        KeyInput.KEY_5,
-        KeyInput.KEY_6,
-        KeyInput.KEY_7,
-        KeyInput.KEY_8,
-        KeyInput.KEY_9,
-        KeyInput.KEY_MULTIPLY,
-        0x0, // key pound
-        KeyInput.KEY_UP,
-        KeyInput.KEY_DOWN,
-        KeyInput.KEY_LEFT,
-        KeyInput.KEY_RIGHT,
-        KeyInput.KEY_RETURN, // dpad center
-        0x0, // volume up
-        0x0, // volume down
-        KeyInput.KEY_POWER, // power (?)
-        0x0, // camera
-        0x0, // clear
-        KeyInput.KEY_A,
-        KeyInput.KEY_B,
-        KeyInput.KEY_C,
-        KeyInput.KEY_D,
-        KeyInput.KEY_E,
-        KeyInput.KEY_F,
-        KeyInput.KEY_G,
-        KeyInput.KEY_H,
-        KeyInput.KEY_I,
-        KeyInput.KEY_J,
-        KeyInput.KEY_K,
-        KeyInput.KEY_L,
-        KeyInput.KEY_M,
-        KeyInput.KEY_N,
-        KeyInput.KEY_O,
-        KeyInput.KEY_P,
-        KeyInput.KEY_Q,
-        KeyInput.KEY_R,
-        KeyInput.KEY_S,
-        KeyInput.KEY_T,
-        KeyInput.KEY_U,
-        KeyInput.KEY_V,
-        KeyInput.KEY_W,
-        KeyInput.KEY_X,
-        KeyInput.KEY_Y,
-        KeyInput.KEY_Z,
-        KeyInput.KEY_COMMA,
-        KeyInput.KEY_PERIOD,
-        KeyInput.KEY_LMENU,
-        KeyInput.KEY_RMENU,
-        KeyInput.KEY_LSHIFT,
-        KeyInput.KEY_RSHIFT,
-        //        0x0, // fn
-        //        0x0, // cap (?)
-
-        KeyInput.KEY_TAB,
-        KeyInput.KEY_SPACE,
-        0x0, // sym (?) symbol
-        0x0, // explorer
-        0x0, // envelope
-        KeyInput.KEY_RETURN, // newline/enter
-        KeyInput.KEY_DELETE,
-        KeyInput.KEY_GRAVE,
-        KeyInput.KEY_MINUS,
-        KeyInput.KEY_EQUALS,
-        KeyInput.KEY_LBRACKET,
-        KeyInput.KEY_RBRACKET,
-        KeyInput.KEY_BACKSLASH,
-        KeyInput.KEY_SEMICOLON,
-        KeyInput.KEY_APOSTROPHE,
-        KeyInput.KEY_SLASH,
-        KeyInput.KEY_AT, // at (@)
-        KeyInput.KEY_NUMLOCK, //0x0, // num
-        0x0, //headset hook
-        0x0, //focus
-        KeyInput.KEY_ADD,
-        KeyInput.KEY_LMETA, //menu
-        0x0,//notification
-        0x0,//search
-        0x0,//media play/pause
-        0x0,//media stop
-        0x0,//media next
-        0x0,//media previous
-        0x0,//media rewind
-        0x0,//media fastforward
-        0x0,//mute
-    };
-
-    public AndroidInput() {
-    }
-
-    public void setView(View view) {
-        this.view = view;
-        if (view != null) {
-            detector = new GestureDetector(null, this, null, false);
-            scaledetector = new ScaleGestureDetector(view.getContext(), this);
-            view.setOnTouchListener(this);
-            view.setOnKeyListener(this);
-        }
-    }
-
-    private TouchEvent getNextFreeTouchEvent() {
-        return getNextFreeTouchEvent(false);
-    }
-
-    /**
-     * Fetches a touch event from the reuse pool
-     * @param wait if true waits for a reusable event to get available/released
-     * by an other thread, if false returns a new one if needed.
-     *
-     * @return a usable TouchEvent
-     */
-    private TouchEvent getNextFreeTouchEvent(boolean wait) {
-        TouchEvent evt = null;
-        synchronized (eventPoolUnConsumed) {
-            int size = eventPoolUnConsumed.size();
-            while (size > 0) {
-                evt = eventPoolUnConsumed.pop();
-                if (!evt.isConsumed()) {
-                    eventPoolUnConsumed.push(evt);
-                    evt = null;
-                } else {
-                    break;
-                }
-                size--;
-            }
-        }
-
-        if (evt == null) {
-            if (eventPool.isEmpty() && wait) {
-                logger.warning("eventPool buffer underrun");
-                boolean isEmpty;
-                do {
-                    synchronized (eventPool) {
-                        isEmpty = eventPool.isEmpty();
-                    }
-                    try {
-                        Thread.sleep(50);
-                    } catch (InterruptedException e) {
-                    }
-                } while (isEmpty);
-                synchronized (eventPool) {
-                    evt = eventPool.pop();
-                }
-            } else if (eventPool.isEmpty()) {
-                evt = new TouchEvent();
-                logger.warning("eventPool buffer underrun");
-            } else {
-                synchronized (eventPool) {
-                    evt = eventPool.pop();
-                }
-            }
-        }
-        return evt;
-    }
-
-    /**
-     * onTouch gets called from android thread on touchpad events
-     */
-    public boolean onTouch(View view, MotionEvent event) {
-        if (view != this.view) {
-            return false;
-        }
-        boolean bWasHandled = false;
-        TouchEvent touch;
-        //    System.out.println("native : " + event.getAction());
-        int action = event.getAction() & MotionEvent.ACTION_MASK;
-        int pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK)
-                >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
-        int pointerId = event.getPointerId(pointerIndex);
-        Vector2f lastPos = lastPositions.get(pointerId);
-
-        // final int historySize = event.getHistorySize();
-        //final int pointerCount = event.getPointerCount();
-        switch (action) {
-            case MotionEvent.ACTION_POINTER_DOWN:
-            case MotionEvent.ACTION_DOWN:
-                touch = getNextFreeTouchEvent();
-                touch.set(Type.DOWN, event.getX(pointerIndex), view.getHeight() - event.getY(pointerIndex), 0, 0);
-                touch.setPointerId(pointerId);
-                touch.setTime(event.getEventTime());
-                touch.setPressure(event.getPressure(pointerIndex));
-                processEvent(touch);
-
-                lastPos = new Vector2f(event.getX(pointerIndex), view.getHeight() - event.getY(pointerIndex));
-                lastPositions.put(pointerId, lastPos);
-
-                bWasHandled = true;
-                break;
-            case MotionEvent.ACTION_POINTER_UP:
-            case MotionEvent.ACTION_CANCEL:
-            case MotionEvent.ACTION_UP:
-                touch = getNextFreeTouchEvent();
-                touch.set(Type.UP, event.getX(pointerIndex), view.getHeight() - event.getY(pointerIndex), 0, 0);
-                touch.setPointerId(pointerId);
-                touch.setTime(event.getEventTime());
-                touch.setPressure(event.getPressure(pointerIndex));
-                processEvent(touch);
-                lastPositions.remove(pointerId);
-
-                bWasHandled = true;
-                break;
-            case MotionEvent.ACTION_MOVE:
-                // Convert all pointers into events
-                for (int p = 0; p < event.getPointerCount(); p++) {
-                    lastPos = lastPositions.get(event.getPointerId(p));
-                    if (lastPos == null) {
-                        lastPos = new Vector2f(event.getX(p), view.getHeight() - event.getY(p));
-                        lastPositions.put(event.getPointerId(p), lastPos);
-                    }
-
-                    float dX = event.getX(p) - lastPos.x;
-                    float dY = view.getHeight() - event.getY(p) - lastPos.y;
-                    if (dX != 0 || dY != 0) {
-                        touch = getNextFreeTouchEvent();
-                        touch.set(Type.MOVE, event.getX(p), view.getHeight() - event.getY(p), dX, dY);
-                        touch.setPointerId(event.getPointerId(p));
-                        touch.setTime(event.getEventTime());
-                        touch.setPressure(event.getPressure(p));
-                        touch.setScaleSpanInProgress(scaleInProgress);
-                        processEvent(touch);
-                        lastPos.set(event.getX(p), view.getHeight() - event.getY(p));
-                    }
-                }
-                bWasHandled = true;
-                break;
-            case MotionEvent.ACTION_OUTSIDE:
-                break;
-
-        }
-
-        // Try to detect gestures
-        this.detector.onTouchEvent(event);
-        this.scaledetector.onTouchEvent(event);
-
-        return bWasHandled;
-    }
-
-    /**
-     * onKey gets called from android thread on key events
-     */
-    public boolean onKey(View view, int keyCode, KeyEvent event) {
-        if (view != this.view) {
-            return false;
-        }
-
-        if (event.getAction() == KeyEvent.ACTION_DOWN) {
-        TouchEvent evt;
-        evt = getNextFreeTouchEvent();
-        evt.set(TouchEvent.Type.KEY_DOWN);
-        evt.setKeyCode(keyCode);
-        evt.setCharacters(event.getCharacters());
-        evt.setTime(event.getEventTime());
-
-        // Send the event
-        processEvent(evt);
-
-        // Handle all keys ourself except Volume Up/Down
-        if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP) || (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
-            return false;
-        } else {
-            return true;
-        }
-        } else if (event.getAction() == KeyEvent.ACTION_UP) {
-        TouchEvent evt;
-        evt = getNextFreeTouchEvent();
-        evt.set(TouchEvent.Type.KEY_UP);
-        evt.setKeyCode(keyCode);
-        evt.setCharacters(event.getCharacters());
-        evt.setTime(event.getEventTime());
-
-        // Send the event
-        processEvent(evt);
-
-        // Handle all keys ourself except Volume Up/Down
-        if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP) || (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
-            return false;
-        } else {
-            return true;
-        }
-        } else {
-            return false;
-        }
-    }
-
-    public void loadSettings(AppSettings settings) {
-        mouseEventsEnabled = settings.isEmulateMouse();
-        mouseEventsInvertX = settings.isEmulateMouseFlipX();
-        mouseEventsInvertY = settings.isEmulateMouseFlipY();
-    }
-
-    // -----------------------------------------
-    // JME3 Input interface
-    @Override
-    public void initialize() {
-        TouchEvent item;
-        for (int i = 0; i < MAX_EVENTS; i++) {
-            item = new TouchEvent();
-            eventPool.push(item);
-        }
-        isInitialized = true;
-    }
-
-    @Override
-    public void destroy() {
-        isInitialized = false;
-
-        // Clean up queues
-        while (!eventPool.isEmpty()) {
-            eventPool.pop();
-        }
-        while (!eventQueue.isEmpty()) {
-            eventQueue.pop();
-        }
-
-
-        this.view = null;
-    }
-
-    @Override
-    public boolean isInitialized() {
-        return isInitialized;
-    }
-
-    @Override
-    public void setInputListener(RawInputListener listener) {
-        this.listener = listener;
-    }
-
-    @Override
-    public long getInputTimeNanos() {
-        return System.nanoTime();
-    }
-    // -----------------------------------------
-
-    private void processEvent(TouchEvent event) {
-        synchronized (eventQueue) {
-            //Discarding events when the ring buffer is full to avoid buffer overflow.
-            if(eventQueue.size()< MAX_EVENTS){
-                eventQueue.push(event);
-            }
-
-        }
-    }
-
-    //  ---------------  INSIDE GLThread  ---------------
-    @Override
-    public void update() {
-        generateEvents();
-    }
-
-    private void generateEvents() {
-        if (listener != null) {
-            TouchEvent event;
-            MouseButtonEvent btn;
-            MouseMotionEvent mot;
-            int newX;
-            int newY;
-
-            while (!eventQueue.isEmpty()) {
-                synchronized (eventQueue) {
-                    event = eventQueue.pop();
-                }
-                if (event != null) {
-                    listener.onTouchEvent(event);
-
-                    if (mouseEventsEnabled) {
-                        if (mouseEventsInvertX) {
-                            newX = view.getWidth() - (int) event.getX();
-                        } else {
-                            newX = (int) event.getX();
-                        }
-
-                        if (mouseEventsInvertY) {
-                            newY = view.getHeight() - (int) event.getY();
-                        } else {
-                            newY = (int) event.getY();
-                        }
-
-                        switch (event.getType()) {
-                            case DOWN:
-                                // Handle mouse down event
-                                btn = new MouseButtonEvent(0, true, newX, newY);
-                                btn.setTime(event.getTime());
-                                listener.onMouseButtonEvent(btn);
-                                // Store current pos
-                                lastX = -1;
-                                lastY = -1;
-                                break;
-
-                            case UP:
-                                // Handle mouse up event
-                                btn = new MouseButtonEvent(0, false, newX, newY);
-                                btn.setTime(event.getTime());
-                                listener.onMouseButtonEvent(btn);
-                                // Store current pos
-                                lastX = -1;
-                                lastY = -1;
-                                break;
-
-                            case SCALE_MOVE:
-                                if (lastX != -1 && lastY != -1) {
-                                    newX = lastX;
-                                    newY = lastY;
-                                }
-                                int wheel = (int) (event.getScaleSpan() / 4f); // scale to match mouse wheel
-                                int dwheel = (int) (event.getDeltaScaleSpan() / 4f); // scale to match mouse wheel
-                                mot = new MouseMotionEvent(newX, newX, 0, 0, wheel, dwheel);
-                                mot.setTime(event.getTime());
-                                listener.onMouseMotionEvent(mot);
-                                lastX = newX;
-                                lastY = newY;
-
-                                break;
-
-                            case MOVE:
-                                if (event.isScaleSpanInProgress()) {
-                                    break;
-                                }
-
-                                int dx;
-                                int dy;
-                                if (lastX != -1) {
-                                    dx = newX - lastX;
-                                    dy = newY - lastY;
-                                } else {
-                                    dx = 0;
-                                    dy = 0;
-                                }
-
-                                mot = new MouseMotionEvent(newX, newY, dx, dy, (int)event.getScaleSpan(), (int)event.getDeltaScaleSpan());
-                                mot.setTime(event.getTime());
-                                listener.onMouseMotionEvent(mot);
-                                lastX = newX;
-                                lastY = newY;
-
-                                break;
-                        }
-                    }
-                }
-
-                if (event.isConsumed() == false) {
-                    synchronized (eventPoolUnConsumed) {
-                        eventPoolUnConsumed.push(event);
-                    }
-
-                } else {
-                    synchronized (eventPool) {
-                        eventPool.push(event);
-                    }
-                }
-            }
-
-        }
-    }
-    //  --------------- ENDOF INSIDE GLThread  ---------------
-
-    // --------------- Gesture detected callback events  ---------------
-    public boolean onDown(MotionEvent event) {
-        return false;
-    }
-
-    public void onLongPress(MotionEvent event) {
-        TouchEvent touch = getNextFreeTouchEvent();
-        touch.set(Type.LONGPRESSED, event.getX(), view.getHeight() - event.getY(), 0f, 0f);
-        touch.setPointerId(0);
-        touch.setTime(event.getEventTime());
-        processEvent(touch);
-    }
-
-    public boolean onFling(MotionEvent event, MotionEvent event2, float vx, float vy) {
-        TouchEvent touch = getNextFreeTouchEvent();
-        touch.set(Type.FLING, event.getX(), view.getHeight() - event.getY(), vx, vy);
-        touch.setPointerId(0);
-        touch.setTime(event.getEventTime());
-        processEvent(touch);
-
-        return true;
-    }
-
-    public boolean onSingleTapConfirmed(MotionEvent event) {
-        //Nothing to do here the tap has already been detected.
-        return false;
-    }
-
-    public boolean onDoubleTap(MotionEvent event) {
-        TouchEvent touch = getNextFreeTouchEvent();
-        touch.set(Type.DOUBLETAP, event.getX(), view.getHeight() - event.getY(), 0f, 0f);
-        touch.setPointerId(0);
-        touch.setTime(event.getEventTime());
-        processEvent(touch);
-        return true;
-    }
-
-    public boolean onDoubleTapEvent(MotionEvent event) {
-        return false;
-    }
-
-    public boolean onScaleBegin(ScaleGestureDetector scaleGestureDetector) {
-        scaleInProgress = true;
-        TouchEvent touch = getNextFreeTouchEvent();
-        touch.set(Type.SCALE_START, scaleGestureDetector.getFocusX(), scaleGestureDetector.getFocusY(), 0f, 0f);
-        touch.setPointerId(0);
-        touch.setTime(scaleGestureDetector.getEventTime());
-        touch.setScaleSpan(scaleGestureDetector.getCurrentSpan());
-        touch.setDeltaScaleSpan(scaleGestureDetector.getCurrentSpan() - scaleGestureDetector.getPreviousSpan());
-        touch.setScaleFactor(scaleGestureDetector.getScaleFactor());
-        touch.setScaleSpanInProgress(scaleInProgress);
-        processEvent(touch);
-        //    System.out.println("scaleBegin");
-
-        return true;
-    }
-
-    public boolean onScale(ScaleGestureDetector scaleGestureDetector) {
-        TouchEvent touch = getNextFreeTouchEvent();
-        touch.set(Type.SCALE_MOVE, scaleGestureDetector.getFocusX(), view.getHeight() - scaleGestureDetector.getFocusY(), 0f, 0f);
-        touch.setPointerId(0);
-        touch.setTime(scaleGestureDetector.getEventTime());
-        touch.setScaleSpan(scaleGestureDetector.getCurrentSpan());
-        touch.setDeltaScaleSpan(scaleGestureDetector.getCurrentSpan() - scaleGestureDetector.getPreviousSpan());
-        touch.setScaleFactor(scaleGestureDetector.getScaleFactor());
-        touch.setScaleSpanInProgress(scaleInProgress);
-        processEvent(touch);
-        //   System.out.println("scale");
-
-        return false;
-    }
-
-    public void onScaleEnd(ScaleGestureDetector scaleGestureDetector) {
-        scaleInProgress = false;
-        TouchEvent touch = getNextFreeTouchEvent();
-        touch.set(Type.SCALE_END, scaleGestureDetector.getFocusX(), view.getHeight() - scaleGestureDetector.getFocusY(), 0f, 0f);
-        touch.setPointerId(0);
-        touch.setTime(scaleGestureDetector.getEventTime());
-        touch.setScaleSpan(scaleGestureDetector.getCurrentSpan());
-        touch.setDeltaScaleSpan(scaleGestureDetector.getCurrentSpan() - scaleGestureDetector.getPreviousSpan());
-        touch.setScaleFactor(scaleGestureDetector.getScaleFactor());
-        touch.setScaleSpanInProgress(scaleInProgress);
-        processEvent(touch);
-    }
-
-    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
-        TouchEvent touch = getNextFreeTouchEvent();
-        touch.set(Type.SCROLL, e1.getX(), view.getHeight() - e1.getY(), distanceX, distanceY * (-1));
-        touch.setPointerId(0);
-        touch.setTime(e1.getEventTime());
-        processEvent(touch);
-        //System.out.println("scroll " + e1.getPointerCount());
-        return false;
-    }
-
-    public void onShowPress(MotionEvent event) {
-        TouchEvent touch = getNextFreeTouchEvent();
-        touch.set(Type.SHOWPRESS, event.getX(), view.getHeight() - event.getY(), 0f, 0f);
-        touch.setPointerId(0);
-        touch.setTime(event.getEventTime());
-        processEvent(touch);
-    }
-
-    public boolean onSingleTapUp(MotionEvent event) {
-        TouchEvent touch = getNextFreeTouchEvent();
-        touch.set(Type.TAP, event.getX(), view.getHeight() - event.getY(), 0f, 0f);
-        touch.setPointerId(0);
-        touch.setTime(event.getEventTime());
-        processEvent(touch);
-        return true;
-    }
-
-    @Override
-    public void setSimulateKeyboard(boolean simulate) {
-        keyboardEventsEnabled = simulate;
-    }
-
-    @Override
-    public void setOmitHistoricEvents(boolean dontSendHistory) {
-        this.dontSendHistory = dontSendHistory;
-    }
-
-    /**
-     * @deprecated Use {@link #getSimulateMouse()};
-     */
-    @Deprecated
-    public boolean isMouseEventsEnabled() {
-        return mouseEventsEnabled;
-    }
-
-    @Deprecated
-    public void setMouseEventsEnabled(boolean mouseEventsEnabled) {
-        this.mouseEventsEnabled = mouseEventsEnabled;
-    }
-
-    public boolean isMouseEventsInvertY() {
-        return mouseEventsInvertY;
-    }
-
-    public void setMouseEventsInvertY(boolean mouseEventsInvertY) {
-        this.mouseEventsInvertY = mouseEventsInvertY;
-    }
-
-    public boolean isMouseEventsInvertX() {
-        return mouseEventsInvertX;
-    }
-
-    public void setMouseEventsInvertX(boolean mouseEventsInvertX) {
-        this.mouseEventsInvertX = mouseEventsInvertX;
-    }
-
-    public void setSimulateMouse(boolean simulate) {
-        mouseEventsEnabled = simulate;
-    }
-
-    public boolean getSimulateMouse() {
-        return isSimulateMouse();
-    }
-
-    public boolean isSimulateMouse() {
-        return mouseEventsEnabled;
-    }
-
-    public boolean isSimulateKeyboard() {
-        return keyboardEventsEnabled;
-    }
-
-}

+ 147 - 172
jme3-android/src/main/java/com/jme3/input/android/AndroidInputHandler.java

@@ -33,231 +33,206 @@
 package com.jme3.input.android;
 
 import android.opengl.GLSurfaceView;
-import android.os.Build;
+import android.view.GestureDetector;
+import android.view.InputDevice;
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+import android.view.ScaleGestureDetector;
 import android.view.View;
-import com.jme3.input.RawInputListener;
+import com.jme3.input.JoyInput;
 import com.jme3.input.TouchInput;
-import com.jme3.input.event.InputEvent;
-import com.jme3.input.event.KeyInputEvent;
-import com.jme3.input.event.MouseButtonEvent;
-import com.jme3.input.event.MouseMotionEvent;
-import com.jme3.input.event.TouchEvent;
 import com.jme3.system.AppSettings;
-import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
 /**
  * <code>AndroidInput</code> is the main class that connects the Android system
- * inputs to jME. It serves as the manager that gathers inputs from the various
- * Android input methods and provides them to jME's <code>InputManager</code>.
+ * inputs to jME. It receives the inputs from the Android View and passes them
+ * to the appropriate classes based on the source of the input.</br>
+ * This class is to be extended when new functionality is released in Android.
  *
  * @author iwgeric
  */
-public class AndroidInputHandler implements TouchInput {
-    private static final Logger logger = Logger.getLogger(AndroidInputHandler.class.getName());
-
-    // Custom settings
-    private boolean mouseEventsEnabled = true;
-    private boolean mouseEventsInvertX = false;
-    private boolean mouseEventsInvertY = false;
-    private boolean keyboardEventsEnabled = false;
-    private boolean dontSendHistory = false;
+public class AndroidInputHandler implements View.OnTouchListener,
+                                            View.OnKeyListener {
 
+    private static final Logger logger = Logger.getLogger(AndroidInputHandler.class.getName());
 
-    // Internal
-    private GLSurfaceView view;
-    private AndroidTouchHandler touchHandler;
-    private AndroidKeyHandler keyHandler;
-    private AndroidGestureHandler gestureHandler;
-    private boolean initialized = false;
-    private RawInputListener listener = null;
-    private ConcurrentLinkedQueue<InputEvent> inputEventQueue = new ConcurrentLinkedQueue<InputEvent>();
-    private final static int MAX_TOUCH_EVENTS = 1024;
-    private final TouchEventPool touchEventPool = new TouchEventPool(MAX_TOUCH_EVENTS);
-    private float scaleX = 1f;
-    private float scaleY = 1f;
+    protected GLSurfaceView view;
+    protected AndroidTouchInput touchInput;
+    protected AndroidJoyInput joyInput;
 
 
     public AndroidInputHandler() {
-        int buildVersion = Build.VERSION.SDK_INT;
-        logger.log(Level.INFO, "Android Build Version: {0}", buildVersion);
-        if (buildVersion >= 14) {
-            // add support for onHover and GenericMotionEvent (ie. gamepads)
-            gestureHandler = new AndroidGestureHandler(this);
-            touchHandler = new AndroidTouchHandler14(this, gestureHandler);
-            keyHandler = new AndroidKeyHandler(this);
-        } else if (buildVersion >= 8){
-            gestureHandler = new AndroidGestureHandler(this);
-            touchHandler = new AndroidTouchHandler(this, gestureHandler);
-            keyHandler = new AndroidKeyHandler(this);
-        }
-    }
-
-    public AndroidInputHandler(AndroidTouchHandler touchInput,
-            AndroidKeyHandler keyInput, AndroidGestureHandler gestureHandler) {
-        this.touchHandler = touchInput;
-        this.keyHandler = keyInput;
-        this.gestureHandler = gestureHandler;
+        touchInput = new AndroidTouchInput(this);
+        joyInput = new AndroidJoyInput(this);
     }
 
     public void setView(View view) {
-        if (touchHandler != null) {
-            touchHandler.setView(view);
+        if (this.view != null && view != null && this.view.equals(view)) {
+            return;
         }
-        if (keyHandler != null) {
-            keyHandler.setView(view);
-        }
-        if (gestureHandler != null) {
-            gestureHandler.setView(view);
+
+        if (this.view != null) {
+            removeListeners(this.view);
         }
+
         this.view = (GLSurfaceView)view;
-    }
 
-    public View getView() {
-        return view;
-    }
+        if (this.view != null) {
+            addListeners(this.view);
+        }
 
-    public float invertX(float origX) {
-        return getJmeX(view.getWidth()) - origX;
+        joyInput.setView((GLSurfaceView)view);
     }
 
-    public float invertY(float origY) {
-        return getJmeY(view.getHeight()) - origY;
+    public View getView() {
+        return view;
     }
 
-    public float getJmeX(float origX) {
-        return origX * scaleX;
+    protected void removeListeners(GLSurfaceView view) {
+        view.setOnTouchListener(null);
+        view.setOnKeyListener(null);
+        touchInput.setGestureDetector(null);
+        touchInput.setScaleDetector(null);
     }
 
-    public float getJmeY(float origY) {
-        return origY * scaleY;
+    protected void addListeners(GLSurfaceView view) {
+        view.setOnTouchListener(this);
+        view.setOnKeyListener(this);
+        AndroidGestureProcessor gestureHandler = new AndroidGestureProcessor(touchInput);
+        touchInput.setGestureDetector(new GestureDetector(
+                view.getContext(), gestureHandler));
+        touchInput.setScaleDetector(new ScaleGestureDetector(
+                view.getContext(), gestureHandler));
     }
 
     public void loadSettings(AppSettings settings) {
-        keyboardEventsEnabled = settings.isEmulateKeyboard();
-        mouseEventsEnabled = settings.isEmulateMouse();
-        mouseEventsInvertX = settings.isEmulateMouseFlipX();
-        mouseEventsInvertY = settings.isEmulateMouseFlipY();
-
-        // view width and height are 0 until the view is displayed on the screen
-        if (view.getWidth() != 0 && view.getHeight() != 0) {
-            scaleX = (float)settings.getWidth() / (float)view.getWidth();
-            scaleY = (float)settings.getHeight() / (float)view.getHeight();
-        }
-        logger.log(Level.FINE, "Setting input scaling, scaleX: {0}, scaleY: {1}",
-                new Object[]{scaleX, scaleY});
+        touchInput.loadSettings(settings);
+    }
+
+    public TouchInput getTouchInput() {
+        return touchInput;
+    }
+
+    public JoyInput getJoyInput() {
+        return joyInput;
+    }
+
+    /*
+     *  Android input events include the source from which the input came from.
+     *  We must look at the source of the input event to determine which type
+     *  of jME input it belongs to.
+     *  If the input is from a gamepad or joystick source, the event is sent
+     *  to the JoyInput class to convert the event into jME joystick events.
+     *  </br>
+     *  If the input is from a touchscreen source, the event is sent to the
+     *  TouchProcessor to convert the event into touch events.
+     *  The TouchProcessor also converts the events into Mouse and Key events
+     *  if AppSettings is set to simulate Mouse or Keyboard events.
+     *
+     *  Android reports the source as a bitmask as shown below.</br>
+     *
+     *  InputDevice Sources
+     *     0000 0000 0000 0000 0000 0000 0000 0000 - 32 bit bitmask
+     *
+     *     0000 0000 0000 0000 0000 0000 1111 1111 - SOURCE_CLASS_MASK       (0x000000ff)
+     *     0000 0000 0000 0000 0000 0000 0000 0000 - SOURCE_CLASS_NONE       (0x00000000)
+     *     0000 0000 0000 0000 0000 0000 0000 0001 - SOURCE_CLASS_BUTTON     (0x00000001)
+     *     0000 0000 0000 0000 0000 0000 0000 0010 - SOURCE_CLASS_POINTER    (0x00000002)
+     *     0000 0000 0000 0000 0000 0000 0000 0100 - SOURCE_CLASS_TRACKBALL  (0x00000004)
+     *     0000 0000 0000 0000 0000 0000 0000 1000 - SOURCE_CLASS_POSITION   (0x00000008)
+     *     0000 0000 0000 0000 0000 0000 0001 0000 - SOURCE_CLASS_JOYSTICK   (0x00000010)
+     *
+     *     1111 1111 1111 1111 1111 1111 0000 0000 - Source_Any              (0xffffff00)
+     *     0000 0000 0000 0000 0000 0000 0000 0000 - SOURCE_UNKNOWN          (0x00000000)
+     *     0000 0000 0000 0000 0000 0001 0000 0001 - SOURCE_KEYBOARD         (0x00000101)
+     *     0000 0000 0000 0000 0000 0010 0000 0001 - SOURCE_DPAD             (0x00000201)
+     *     0000 0000 0000 0000 0000 0100 0000 0001 - SOURCE_GAMEPAD          (0x00000401)
+     *     0000 0000 0000 0000 0001 0000 0000 0010 - SOURCE_TOUCHSCREEN      (0x00001002)
+     *     0000 0000 0000 0000 0010 0000 0000 0010 - SOURCE_MOUSE            (0x00002002)
+     *     0000 0000 0000 0000 0100 0000 0000 0010 - SOURCE_STYLUS           (0x00004002)
+     *     0000 0000 0000 0001 0000 0000 0000 0100 - SOURCE_TRACKBALL        (0x00010004)
+     *     0000 0000 0001 0000 0000 0000 0000 1000 - SOURCE_TOUCHPAD         (0x00100008)
+     *     0000 0000 0010 0000 0000 0000 0000 0000 - SOURCE_TOUCH_NAVIGATION (0x00200000)
+     *     0000 0001 0000 0000 0000 0000 0001 0000 - SOURCE_JOYSTICK         (0x01000010)
+     *     0000 0010 0000 0000 0000 0000 0000 0001 - SOURCE_HDMI             (0x02000001)
+     *
+     * Example values reported by Android for Source
+     * 4,098 = 0x00001002 =
+     *     0000 0000 0000 0000 0001 0000 0000 0010 - SOURCE_CLASS_POINTER
+     *                                               SOURCE_TOUCHSCREEN
+     * 1,281 = 0x00000501 =
+     *     0000 0000 0000 0000 0000 0101 0000 0001 - SOURCE_CLASS_BUTTON
+     *                                               SOURCE_KEYBOARD
+     *                                               SOURCE_GAMEPAD
+     * 16,777,232 = 0x01000010 =
+     *     0000 0001 0000 0000 0000 0000 0001 0000 - SOURCE_CLASS_JOYSTICK
+     *                                               SOURCE_JOYSTICK
+     *
+     * 16,778,513 = 0x01000511 =
+     *     0000 0001 0000 0000 0000 0101 0001 0001 - SOURCE_CLASS_BUTTON
+     *                                               SOURCE_CLASS_JOYSTICK
+     *                                               SOURCE_GAMEPAD
+     *                                               SOURCE_KEYBOARD
+     *                                               SOURCE_JOYSTICK
+     *
+     * 257 = 0x00000101 =
+     *     0000 0000 0000 0000 0000 0001 0000 0001 - SOURCE_CLASS_BUTTON
+     *                                               SOURCE_KEYBOARD
+     *
+     *
+     *
+     */
 
-    }
 
-        // -----------------------------------------
-    // JME3 Input interface
     @Override
-    public void initialize() {
-        touchEventPool.initialize();
-        if (touchHandler != null) {
-            touchHandler.initialize();
-        }
-        if (keyHandler != null) {
-            keyHandler.initialize();
-        }
-        if (gestureHandler != null) {
-            gestureHandler.initialize();
+    public boolean onTouch(View view, MotionEvent event) {
+        if (view != getView()) {
+            return false;
         }
 
-        initialized = true;
-    }
+        boolean consumed = false;
 
-    @Override
-    public void destroy() {
-        initialized = false;
+        int source = event.getSource();
+//        logger.log(Level.INFO, "onTouch source: {0}", source);
 
-        touchEventPool.destroy();
-        if (touchHandler != null) {
-            touchHandler.destroy();
-        }
-        if (keyHandler != null) {
-            keyHandler.destroy();
-        }
-        if (gestureHandler != null) {
-            gestureHandler.destroy();
-        }
-
-        setView(null);
-    }
-
-    @Override
-    public boolean isInitialized() {
-        return initialized;
-    }
-
-    @Override
-    public void setInputListener(RawInputListener listener) {
-        this.listener = listener;
-    }
-
-    @Override
-    public long getInputTimeNanos() {
-        return System.nanoTime();
-    }
+        boolean isTouch = ((source & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN);
+//        logger.log(Level.INFO, "onTouch source: {0}, isTouch: {1}",
+//                new Object[]{source, isTouch});
 
-    public void update() {
-        if (listener != null) {
-            InputEvent inputEvent;
-
-            while ((inputEvent = inputEventQueue.poll()) != null) {
-                if (inputEvent instanceof TouchEvent) {
-                    listener.onTouchEvent((TouchEvent)inputEvent);
-                } else if (inputEvent instanceof MouseButtonEvent) {
-                    listener.onMouseButtonEvent((MouseButtonEvent)inputEvent);
-                } else if (inputEvent instanceof MouseMotionEvent) {
-                    listener.onMouseMotionEvent((MouseMotionEvent)inputEvent);
-                } else if (inputEvent instanceof KeyInputEvent) {
-                    listener.onKeyEvent((KeyInputEvent)inputEvent);
-                }
-            }
+        if (isTouch && touchInput != null) {
+            // send the event to the touch processor
+            consumed = touchInput.onTouch(event);
         }
-    }
 
-    // -----------------------------------------
+        return consumed;
 
-    public TouchEvent getFreeTouchEvent() {
-            return touchEventPool.getNextFreeEvent();
     }
 
-    public void addEvent(InputEvent event) {
-        inputEventQueue.add(event);
-        if (event instanceof TouchEvent) {
-            touchEventPool.storeEvent((TouchEvent)event);
+    @Override
+    public boolean onKey(View view, int keyCode, KeyEvent event) {
+        if (view != getView()) {
+            return false;
         }
-    }
 
-    public void setSimulateMouse(boolean simulate) {
-        this.mouseEventsEnabled = simulate;
-    }
+        boolean consumed = false;
 
-    public boolean isSimulateMouse() {
-        return mouseEventsEnabled;
-    }
+        int source = event.getSource();
+//        logger.log(Level.INFO, "onKey source: {0}", source);
 
-    public boolean isMouseEventsInvertX() {
-        return mouseEventsInvertX;
-    }
+        boolean isTouch =
+                ((source & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN) ||
+                ((source & InputDevice.SOURCE_KEYBOARD) == InputDevice.SOURCE_KEYBOARD);
+//        logger.log(Level.INFO, "onKey source: {0}, isTouch: {1}",
+//                new Object[]{source, isTouch});
 
-    public boolean isMouseEventsInvertY() {
-        return mouseEventsInvertY;
-    }
-
-    public void setSimulateKeyboard(boolean simulate) {
-        this.keyboardEventsEnabled = simulate;
-    }
+        if (touchInput != null) {
+            consumed = touchInput.onKey(event);
+        }
 
-    public boolean isSimulateKeyboard() {
-        return keyboardEventsEnabled;
-    }
+        return consumed;
 
-    public void setOmitHistoricEvents(boolean dontSendHistory) {
-        this.dontSendHistory = dontSendHistory;
     }
 
 }

+ 159 - 0
jme3-android/src/main/java/com/jme3/input/android/AndroidInputHandler14.java

@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 2009-2012 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *   may be used to endorse or promote products derived from this software
+ *   without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package com.jme3.input.android;
+
+import android.opengl.GLSurfaceView;
+import android.view.InputDevice;
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+import android.view.View;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * <code>AndroidInputHandler14</code> extends <code>AndroidInputHandler</code> to
+ * add the onHover and onGenericMotion events that where added in Android rev 14 (Android 4.0).</br>
+ * The onGenericMotion events are the main interface to Joystick axes.  They
+ * were actually released in Android rev 12.
+ *
+ * @author iwgeric
+ */
+public class AndroidInputHandler14 extends AndroidInputHandler implements View.OnHoverListener,
+                                                                            View.OnGenericMotionListener {
+
+    private static final Logger logger = Logger.getLogger(AndroidInputHandler14.class.getName());
+
+    public AndroidInputHandler14() {
+        touchInput = new AndroidTouchInput14(this);
+        joyInput = new AndroidJoyInput14(this);
+    }
+
+    @Override
+    protected void removeListeners(GLSurfaceView view) {
+        super.removeListeners(view);
+        view.setOnHoverListener(null);
+        view.setOnGenericMotionListener(null);
+    }
+
+    @Override
+    protected void addListeners(GLSurfaceView view) {
+        super.addListeners(view);
+        view.setOnHoverListener(this);
+        view.setOnGenericMotionListener(this);
+    }
+
+    @Override
+    public boolean onHover(View view, MotionEvent event) {
+        if (view != getView()) {
+            return false;
+        }
+
+        boolean consumed = false;
+
+        int source = event.getSource();
+//        logger.log(Level.INFO, "onTouch source: {0}", source);
+
+        boolean isTouch = ((source & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN);
+//        logger.log(Level.INFO, "onTouch source: {0}, isTouch: {1}",
+//                new Object[]{source, isTouch});
+
+        if (isTouch && touchInput != null) {
+            // send the event to the touch processor
+            consumed = ((AndroidTouchInput14)touchInput).onHover(event);
+        }
+
+        return consumed;
+    }
+
+    @Override
+    public boolean onGenericMotion(View view, MotionEvent event) {
+        if (view != getView()) {
+            return false;
+        }
+
+        boolean consumed = false;
+
+        int source = event.getSource();
+//        logger.log(Level.INFO, "onGenericMotion source: {0}", source);
+
+        boolean isJoystick =
+                ((source & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) ||
+                ((source & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK);
+
+        if (isJoystick && joyInput != null) {
+//            logger.log(Level.INFO, "onGenericMotion source: {0}, isJoystick: {1}",
+//                    new Object[]{source, isJoystick});
+            // send the event to the touch processor
+            consumed = consumed || ((AndroidJoyInput14)joyInput).onGenericMotion(event);
+        }
+
+        return consumed;
+    }
+
+    @Override
+    public boolean onKey(View view, int keyCode, KeyEvent event) {
+        if (view != getView()) {
+            return false;
+        }
+
+        boolean consumed = false;
+
+//        logger.log(Level.INFO, "onKey keyCode: {0}, action: {1}, event: {2}",
+//                new Object[]{KeyEvent.keyCodeToString(keyCode), event.getAction(), event});
+        int source = event.getSource();
+//        logger.log(Level.INFO, "onKey source: {0}", source);
+
+        boolean isTouch =
+                ((source & InputDevice.SOURCE_TOUCHSCREEN) == InputDevice.SOURCE_TOUCHSCREEN) ||
+                ((source & InputDevice.SOURCE_KEYBOARD) == InputDevice.SOURCE_KEYBOARD);
+        boolean isJoystick =
+                ((source & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) ||
+                ((source & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK);
+
+        if (isTouch && touchInput != null) {
+//            logger.log(Level.INFO, "onKey source: {0}, isTouch: {1}",
+//                    new Object[]{source, isTouch});
+            consumed = touchInput.onKey(event);
+        }
+        if (isJoystick && joyInput != null) {
+//            logger.log(Level.INFO, "onKey source: {0}, isJoystick: {1}",
+//                    new Object[]{source, isJoystick});
+            // use inclusive OR to make sure the onKey method is called.
+            consumed = consumed | ((AndroidJoyInput14)joyInput).onKey(event);
+        }
+
+        return consumed;
+
+    }
+
+}

+ 24 - 43
jme3-android/src/main/java/com/jme3/input/android/AndroidJoyInputHandler.java → jme3-android/src/main/java/com/jme3/input/android/AndroidJoyInput.java

@@ -33,9 +33,7 @@ package com.jme3.input.android;
 
 import android.content.Context;
 import android.opengl.GLSurfaceView;
-import android.os.Build;
 import android.os.Vibrator;
-import android.view.View;
 import com.jme3.input.InputManager;
 import com.jme3.input.JoyInput;
 import com.jme3.input.Joystick;
@@ -79,15 +77,16 @@ import java.util.logging.Logger;
  *
  * @author iwgeric
  */
-public class AndroidJoyInputHandler implements JoyInput {
-    private static final Logger logger = Logger.getLogger(AndroidJoyInputHandler.class.getName());
+public class AndroidJoyInput implements JoyInput {
+    private static final Logger logger = Logger.getLogger(AndroidJoyInput.class.getName());
+    public static boolean disableSensors = false;
 
-    private List<Joystick> joystickList = new ArrayList<Joystick>();
+    protected AndroidInputHandler inputHandler;
+    protected List<Joystick> joystickList = new ArrayList<Joystick>();
 //    private boolean dontSendHistory = false;
 
 
     // Internal
-    private GLSurfaceView view;
     private boolean initialized = false;
     private RawInputListener listener = null;
     private ConcurrentLinkedQueue<InputEvent> eventQueue = new ConcurrentLinkedQueue<InputEvent>();
@@ -96,34 +95,29 @@ public class AndroidJoyInputHandler implements JoyInput {
     private boolean vibratorActive = false;
     private long maxRumbleTime = 250;  // 250ms
 
-    public AndroidJoyInputHandler() {
-        int buildVersion = Build.VERSION.SDK_INT;
-        logger.log(Level.INFO, "Android Build Version: {0}", buildVersion);
-//        if (buildVersion >= 14) {
-//            touchHandler = new AndroidTouchHandler14(this);
-//        } else if (buildVersion >= 8){
-//            touchHandler = new AndroidTouchHandler(this);
-//        }
+    public AndroidJoyInput(AndroidInputHandler inputHandler) {
+        this.inputHandler = inputHandler;
         sensorJoyInput = new AndroidSensorJoyInput(this);
     }
 
     public void setView(GLSurfaceView view) {
-//        if (touchHandler != null) {
-//            touchHandler.setView(view);
-//        }
+        if (view == null) {
+            vibrator = null;
+        } else {
+            // Get instance of Vibrator from current Context
+            vibrator = (Vibrator) view.getContext().getSystemService(Context.VIBRATOR_SERVICE);
+            if (vibrator == null) {
+                logger.log(Level.FINE, "Vibrator Service not found.");
+            }
+        }
+
         if (sensorJoyInput != null) {
             sensorJoyInput.setView(view);
         }
-        this.view = (GLSurfaceView)view;
-
-    }
-
-    public View getView() {
-        return view;
     }
 
     public void loadSettings(AppSettings settings) {
-//        sensorEventsEnabled = settings.useSensors();
+
     }
 
     public void addEvent(InputEvent event) {
@@ -155,20 +149,8 @@ public class AndroidJoyInputHandler implements JoyInput {
 
     }
 
-
-
-
-
     @Override
     public void initialize() {
-//        if (sensorJoyInput != null) {
-//            sensorJoyInput.initialize();
-//        }
-        // Get instance of Vibrator from current Context
-        vibrator = (Vibrator) view.getContext().getSystemService(Context.VIBRATOR_SERVICE);
-        if (vibrator == null) {
-            logger.log(Level.FINE, "Vibrator Service not found.");
-        }
         initialized = true;
     }
 
@@ -211,8 +193,8 @@ public class AndroidJoyInputHandler implements JoyInput {
             };
             final int rumbleRepeatFrom = 0; // index into rumble pattern to repeat from
 
-            logger.log(Level.FINE, "Rumble amount: {0}, rumbleOnDur: {1}, rumbleOffDur: {2}",
-                    new Object[]{amount, rumbleOnDur, rumbleOffDur});
+//            logger.log(Level.FINE, "Rumble amount: {0}, rumbleOnDur: {1}, rumbleOffDur: {2}",
+//                    new Object[]{amount, rumbleOnDur, rumbleOffDur});
 
             if (rumbleOnDur > 0) {
                 vibrator.vibrate(rumblePattern, rumbleRepeatFrom);
@@ -226,9 +208,10 @@ public class AndroidJoyInputHandler implements JoyInput {
 
     @Override
     public Joystick[] loadJoysticks(InputManager inputManager) {
-        joystickList.add(sensorJoyInput.loadJoystick(joystickList.size(), inputManager));
-
-
+        logger.log(Level.INFO, "loading joysticks for {0}", this.getClass().getName());
+        if (!disableSensors) {
+            joystickList.add(sensorJoyInput.loadJoystick(joystickList.size(), inputManager));
+        }
         return joystickList.toArray( new Joystick[joystickList.size()] );
     }
 
@@ -252,6 +235,4 @@ public class AndroidJoyInputHandler implements JoyInput {
 
     }
 
-
-
 }

+ 108 - 0
jme3-android/src/main/java/com/jme3/input/android/AndroidJoyInput14.java

@@ -0,0 +1,108 @@
+/*
+ * Copyright (c) 2009-2015 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *   may be used to endorse or promote products derived from this software
+ *   without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.jme3.input.android;
+
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+import com.jme3.input.InputManager;
+import com.jme3.input.Joystick;
+import java.util.logging.Logger;
+
+/**
+ * <code>AndroidJoyInput14</code> extends <code>AndroidJoyInput</code>
+ * to include support for physical joysticks/gamepads.</br>
+ *
+ * @author iwgeric
+ */
+public class AndroidJoyInput14 extends AndroidJoyInput {
+    private static final Logger logger = Logger.getLogger(AndroidJoyInput14.class.getName());
+
+    private AndroidJoystickJoyInput14 joystickJoyInput;
+
+    public AndroidJoyInput14(AndroidInputHandler inputHandler) {
+        super(inputHandler);
+        joystickJoyInput = new AndroidJoystickJoyInput14(this);
+    }
+
+    /**
+     * Pauses the joystick device listeners to save battery life if they are not needed.
+     * Used to pause when the activity pauses
+     */
+    @Override
+    public void pauseJoysticks() {
+        super.pauseJoysticks();
+
+        if (joystickJoyInput != null) {
+            joystickJoyInput.pauseJoysticks();
+        }
+    }
+
+    /**
+     * Resumes the joystick device listeners.
+     * Used to resume when the activity comes to the top of the stack
+     */
+    @Override
+    public void resumeJoysticks() {
+        super.resumeJoysticks();
+        if (joystickJoyInput != null) {
+            joystickJoyInput.resumeJoysticks();
+        }
+
+    }
+
+    @Override
+    public void destroy() {
+        super.destroy();
+        if (joystickJoyInput != null) {
+            joystickJoyInput.destroy();
+        }
+    }
+
+    @Override
+    public Joystick[] loadJoysticks(InputManager inputManager) {
+        // load the simulated joystick for device orientation
+        super.loadJoysticks(inputManager);
+        // load physical gamepads/joysticks
+        joystickList.addAll(joystickJoyInput.loadJoysticks(joystickList.size(), inputManager));
+        // return the list of joysticks back to InputManager
+        return joystickList.toArray( new Joystick[joystickList.size()] );
+    }
+
+    public boolean onGenericMotion(MotionEvent event) {
+        return joystickJoyInput.onGenericMotion(event);
+    }
+
+    public boolean onKey(KeyEvent event) {
+        return joystickJoyInput.onKey(event);
+    }
+
+}

+ 416 - 0
jme3-android/src/main/java/com/jme3/input/android/AndroidJoystickJoyInput14.java

@@ -0,0 +1,416 @@
+/*
+ * Copyright (c) 2009-2015 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *   may be used to endorse or promote products derived from this software
+ *   without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.jme3.input.android;
+
+import android.view.InputDevice;
+import android.view.InputDevice.MotionRange;
+import android.view.KeyCharacterMap;
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+import com.jme3.input.AbstractJoystick;
+import com.jme3.input.DefaultJoystickAxis;
+import com.jme3.input.DefaultJoystickButton;
+import com.jme3.input.InputManager;
+import com.jme3.input.JoyInput;
+import com.jme3.input.Joystick;
+import com.jme3.input.JoystickAxis;
+import com.jme3.input.JoystickButton;
+import com.jme3.input.JoystickCompatibilityMappings;
+import com.jme3.input.event.JoyAxisEvent;
+import com.jme3.input.event.JoyButtonEvent;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Main class that creates and manages Android inputs for physical gamepads/joysticks.
+ *
+ * @author iwgeric
+ */
+public class AndroidJoystickJoyInput14 {
+    private static final Logger logger = Logger.getLogger(AndroidJoystickJoyInput14.class.getName());
+
+    private boolean loaded = false;
+    private AndroidJoyInput joyInput;
+    private Map<Integer, AndroidJoystick> joystickIndex = new HashMap<Integer, AndroidJoystick>();
+
+    private static int[] AndroidGamepadButtons = {
+            // Dpad buttons
+            KeyEvent.KEYCODE_DPAD_UP,        KeyEvent.KEYCODE_DPAD_DOWN,
+            KeyEvent.KEYCODE_DPAD_LEFT,      KeyEvent.KEYCODE_DPAD_RIGHT,
+            KeyEvent.KEYCODE_DPAD_CENTER,
+
+            // pressing joystick down
+            KeyEvent.KEYCODE_BUTTON_THUMBL,  KeyEvent.KEYCODE_BUTTON_THUMBR,
+
+            // buttons
+            KeyEvent.KEYCODE_BUTTON_A,       KeyEvent.KEYCODE_BUTTON_B,
+            KeyEvent.KEYCODE_BUTTON_X,       KeyEvent.KEYCODE_BUTTON_Y,
+
+            // buttons on back of device
+            KeyEvent.KEYCODE_BUTTON_L1,      KeyEvent.KEYCODE_BUTTON_R1,
+            KeyEvent.KEYCODE_BUTTON_L2,      KeyEvent.KEYCODE_BUTTON_R2,
+
+            // start / select buttons
+            KeyEvent.KEYCODE_BUTTON_START,   KeyEvent.KEYCODE_BUTTON_SELECT,
+            KeyEvent.KEYCODE_BUTTON_MODE,
+
+    };
+
+    public AndroidJoystickJoyInput14(AndroidJoyInput joyInput) {
+        this.joyInput = joyInput;
+    }
+
+
+    public void pauseJoysticks() {
+
+    }
+
+    public void resumeJoysticks() {
+
+    }
+
+    public void destroy() {
+
+    }
+
+    public List<Joystick> loadJoysticks(int joyId, InputManager inputManager) {
+        logger.log(Level.INFO, "loading Joystick devices");
+        ArrayList<Joystick> joysticks = new ArrayList<Joystick>();
+        joysticks.clear();
+        joystickIndex.clear();
+
+        ArrayList gameControllerDeviceIds = new ArrayList();
+        int[] deviceIds = InputDevice.getDeviceIds();
+        for (int deviceId : deviceIds) {
+            InputDevice dev = InputDevice.getDevice(deviceId);
+            int sources = dev.getSources();
+            logger.log(Level.FINE, "deviceId[{0}] sources: {1}", new Object[]{deviceId, sources});
+
+            // Verify that the device has gamepad buttons, control sticks, or both.
+            if (((sources & InputDevice.SOURCE_GAMEPAD) == InputDevice.SOURCE_GAMEPAD) ||
+                    ((sources & InputDevice.SOURCE_JOYSTICK) == InputDevice.SOURCE_JOYSTICK)) {
+                // This device is a game controller. Store its device ID.
+                if (!gameControllerDeviceIds.contains(deviceId)) {
+                    gameControllerDeviceIds.add(deviceId);
+                    logger.log(Level.FINE, "Attempting to create joystick for device: {0}", dev);
+                    // Create an AndroidJoystick and store the InputDevice so we
+                    // can later correspond the input from the InputDevice to the
+                    // appropriate jME Joystick event
+                    AndroidJoystick joystick = new AndroidJoystick(inputManager,
+                                                                joyInput,
+                                                                dev,
+                                                                joyId+joysticks.size(),
+                                                                dev.getName());
+                    joystickIndex.put(deviceId, joystick);
+                    joysticks.add(joystick);
+
+                    // Each analog input is reported as a MotionRange
+                    // The axis number corresponds to the type of axis
+                    // The AndroidJoystick.addAxis(MotionRange) converts the axis
+                    // type reported by Android into the jME Joystick axis
+                    List<MotionRange> motionRanges = dev.getMotionRanges();
+                    for (MotionRange motionRange: motionRanges) {
+                        logger.log(Level.INFO, "motion range: {0}", motionRange.toString());
+                        logger.log(Level.INFO, "axis: {0}", motionRange.getAxis());
+                        JoystickAxis axis = joystick.addAxis(motionRange);
+                        logger.log(Level.INFO, "added axis: {0}", axis);
+                    }
+
+                    // InputDevice has a method for determining if a keyCode is
+                    // supported (InputDevice  public boolean[] hasKeys (int... keys)).
+                    // But this method wasn't added until rev 19 (Android 4.4)
+                    // Therefore, we only can query the entire device and see if
+                    // any InputDevice supports the keyCode.  This may result in
+                    // buttons being configured that don't exist on the specific
+                    // device, but I haven't found a better way yet.
+                    for (int keyCode: AndroidGamepadButtons) {
+                        logger.log(Level.INFO, "button[{0}]: {1}",
+                                new Object[]{keyCode, KeyCharacterMap.deviceHasKey(keyCode)});
+                        if (KeyCharacterMap.deviceHasKey(keyCode)) {
+                            // add button even though we aren't sure if the button
+                            // actually exists on this InputDevice
+                            logger.log(Level.INFO, "button[{0}] exists somewhere", keyCode);
+                            JoystickButton button = joystick.addButton(keyCode);
+                            logger.log(Level.INFO, "added button: {0}", button);
+                        }
+                    }
+
+                }
+            }
+        }
+
+
+        loaded = true;
+        return joysticks;
+    }
+
+    public boolean onGenericMotion(MotionEvent event) {
+        boolean consumed = false;
+//        logger.log(Level.INFO, "onGenericMotion event: {0}", event);
+        event.getDeviceId();
+        event.getSource();
+//        logger.log(Level.INFO, "deviceId: {0}, source: {1}", new Object[]{event.getDeviceId(), event.getSource()});
+        AndroidJoystick joystick = joystickIndex.get(event.getDeviceId());
+        if (joystick != null) {
+            for (int androidAxis: joystick.getAndroidAxes()) {
+                String axisName = MotionEvent.axisToString(androidAxis);
+                float value = event.getAxisValue(androidAxis);
+                int action = event.getAction();
+                if (action == MotionEvent.ACTION_MOVE) {
+//                    logger.log(Level.INFO, "MOVE axis num: {0}, axisName: {1}, value: {2}",
+//                            new Object[]{androidAxis, axisName, value});
+                    JoystickAxis axis = joystick.getAxis(androidAxis);
+                    if (axis != null) {
+//                        logger.log(Level.INFO, "MOVE axis num: {0}, axisName: {1}, value: {2}, deadzone: {3}",
+//                                new Object[]{androidAxis, axisName, value, axis.getDeadZone()});
+                        JoyAxisEvent axisEvent = new JoyAxisEvent(axis, value);
+                        joyInput.addEvent(axisEvent);
+                        consumed = true;
+                    } else {
+//                        logger.log(Level.INFO, "axis was null for axisName: {0}", axisName);
+                    }
+                } else {
+//                    logger.log(Level.INFO, "action: {0}", action);
+                }
+            }
+        }
+
+        return consumed;
+    }
+
+    public boolean onKey(KeyEvent event) {
+        boolean consumed = false;
+//        logger.log(Level.INFO, "onKey event: {0}", event);
+
+        event.getDeviceId();
+        event.getSource();
+        AndroidJoystick joystick = joystickIndex.get(event.getDeviceId());
+        if (joystick != null) {
+            JoystickButton button = joystick.getButton(event.getKeyCode());
+            boolean pressed = event.getAction() == KeyEvent.ACTION_DOWN;
+            if (button != null) {
+                JoyButtonEvent buttonEvent = new JoyButtonEvent(button, pressed);
+                joyInput.addEvent(buttonEvent);
+                consumed = true;
+            } else {
+                JoystickButton newButton = joystick.addButton(event.getKeyCode());
+                JoyButtonEvent buttonEvent = new JoyButtonEvent(newButton, pressed);
+                joyInput.addEvent(buttonEvent);
+                consumed = true;
+            }
+        }
+
+        return consumed;
+    }
+
+    protected class AndroidJoystick extends AbstractJoystick {
+
+        private JoystickAxis nullAxis;
+        private InputDevice device;
+        private JoystickAxis xAxis;
+        private JoystickAxis yAxis;
+        private JoystickAxis povX;
+        private JoystickAxis povY;
+        private Map<Integer, JoystickAxis> axisIndex = new HashMap<Integer, JoystickAxis>();
+        private Map<Integer, JoystickButton> buttonIndex = new HashMap<Integer, JoystickButton>();
+
+        public AndroidJoystick( InputManager inputManager, JoyInput joyInput, InputDevice device,
+                               int joyId, String name ) {
+            super( inputManager, joyInput, joyId, name );
+
+            this.device = device;
+
+            this.nullAxis = new DefaultJoystickAxis( getInputManager(), this, -1,
+                                                     "Null", "null", false, false, 0 );
+            this.xAxis = nullAxis;
+            this.yAxis = nullAxis;
+            this.povX = nullAxis;
+            this.povY = nullAxis;
+        }
+
+        protected JoystickAxis getAxis(int androidAxis) {
+            return axisIndex.get(androidAxis);
+        }
+
+        protected Set<Integer> getAndroidAxes() {
+            return axisIndex.keySet();
+        }
+
+        protected JoystickButton getButton(int keyCode) {
+            return buttonIndex.get(keyCode);
+        }
+
+        protected JoystickButton addButton( int keyCode ) {
+
+//            logger.log(Level.FINE, "Adding button: {0}", keyCode);
+
+            String name = KeyEvent.keyCodeToString(keyCode);
+            String original = KeyEvent.keyCodeToString(keyCode);
+            // A/B/X/Y buttons
+            if (keyCode == KeyEvent.KEYCODE_BUTTON_Y) {
+                original = JoystickButton.BUTTON_0;
+            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_B) {
+                original = JoystickButton.BUTTON_1;
+            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_A) {
+                original = JoystickButton.BUTTON_2;
+            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_X) {
+                original = JoystickButton.BUTTON_3;
+            // Front buttons  Some of these have the top ones and the bottoms ones flipped.
+            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_L1) {
+                original = JoystickButton.BUTTON_4;
+            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_R1) {
+                original = JoystickButton.BUTTON_5;
+            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_L2) {
+                original = JoystickButton.BUTTON_6;
+            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_R2) {
+                original = JoystickButton.BUTTON_7;
+//            // Dpad buttons
+//            } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
+//                original = JoystickButton.BUTTON_8;
+//            } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
+//                original = JoystickButton.BUTTON_9;
+//            } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
+//                original = JoystickButton.BUTTON_8;
+//            } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
+//                original = JoystickButton.BUTTON_9;
+            // Select and start buttons
+            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_SELECT) {
+                original = JoystickButton.BUTTON_8;
+            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_START) {
+                original = JoystickButton.BUTTON_9;
+            // Joystick push buttons
+            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_THUMBL) {
+                original = JoystickButton.BUTTON_10;
+            } else if (keyCode == KeyEvent.KEYCODE_BUTTON_THUMBR) {
+                original = JoystickButton.BUTTON_11;
+            }
+
+            String logicalId = JoystickCompatibilityMappings.remapComponent( getName(), original );
+            if( logicalId == null ? original != null : !logicalId.equals(original) ) {
+                logger.log(Level.FINE, "Remapped: {0} to: {1}",
+                        new Object[]{original, logicalId});
+            }
+
+            JoystickButton button = new DefaultJoystickButton( getInputManager(), this, getButtonCount(),
+                                                               name, logicalId );
+            addButton(button);
+            buttonIndex.put( keyCode, button );
+            return button;
+        }
+
+        protected JoystickAxis addAxis(MotionRange motionRange) {
+
+            String name = MotionEvent.axisToString(motionRange.getAxis());
+
+            String original = MotionEvent.axisToString(motionRange.getAxis());
+            if (motionRange.getAxis() == MotionEvent.AXIS_X) {
+                original = JoystickAxis.X_AXIS;
+            } else if (motionRange.getAxis() == MotionEvent.AXIS_Y) {
+                original = JoystickAxis.Y_AXIS;
+            } else if (motionRange.getAxis() == MotionEvent.AXIS_Z) {
+                original = JoystickAxis.Z_AXIS;
+            } else if (motionRange.getAxis() == MotionEvent.AXIS_RZ) {
+                original = JoystickAxis.Z_ROTATION;
+            } else if (motionRange.getAxis() == MotionEvent.AXIS_HAT_X) {
+                original = JoystickAxis.POV_X;
+            } else if (motionRange.getAxis() == MotionEvent.AXIS_HAT_Y) {
+                original = JoystickAxis.POV_Y;
+            }
+            String logicalId = JoystickCompatibilityMappings.remapComponent( getName(), original );
+            if( logicalId == null ? original != null : !logicalId.equals(original) ) {
+                logger.log(Level.FINE, "Remapped: {0} to: {1}",
+                        new Object[]{original, logicalId});
+            }
+
+            JoystickAxis axis = new DefaultJoystickAxis(getInputManager(),
+                                                this,
+                                                getAxisCount(),
+                                                name,
+                                                logicalId,
+                                                true,
+                                                true,
+                                                motionRange.getFlat());
+
+            if (motionRange.getAxis() == MotionEvent.AXIS_X) {
+                xAxis = axis;
+            }
+            if (motionRange.getAxis() == MotionEvent.AXIS_Y) {
+                yAxis = axis;
+            }
+            if (motionRange.getAxis() == MotionEvent.AXIS_HAT_X) {
+                povX = axis;
+            }
+            if (motionRange.getAxis() == MotionEvent.AXIS_HAT_Y) {
+                povY = axis;
+            }
+
+            addAxis(axis);
+            axisIndex.put(motionRange.getAxis(), axis);
+            return axis;
+        }
+
+        @Override
+        public JoystickAxis getXAxis() {
+            return xAxis;
+        }
+
+        @Override
+        public JoystickAxis getYAxis() {
+            return yAxis;
+        }
+
+        @Override
+        public JoystickAxis getPovXAxis() {
+            return povX;
+        }
+
+        @Override
+        public JoystickAxis getPovYAxis() {
+            return povY;
+        }
+
+        @Override
+        public int getXAxisIndex(){
+            return xAxis.getAxisId();
+        }
+
+        @Override
+        public int getYAxisIndex(){
+            return yAxis.getAxisId();
+        }
+    }
+}

+ 0 - 140
jme3-android/src/main/java/com/jme3/input/android/AndroidKeyHandler.java

@@ -1,140 +0,0 @@
-/*
- * Copyright (c) 2009-2012 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- *   may be used to endorse or promote products derived from this software
- *   without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-package com.jme3.input.android;
-
-import android.content.Context;
-import android.view.KeyEvent;
-import android.view.View;
-import android.view.inputmethod.InputMethodManager;
-import com.jme3.input.event.KeyInputEvent;
-import com.jme3.input.event.TouchEvent;
-import java.util.logging.Logger;
-
-/**
- * AndroidKeyHandler recieves onKey events from the Android system and creates
- * the jME KeyEvents.  onKey is used by Android to receive keys from the keyboard
- * or device buttons.  All key events are consumed by jME except for the Volume
- * buttons and menu button.
- *
- * This class also provides the functionality to display or hide the soft keyboard
- * for inputing single key events.  Use OGLESContext to display an dialog to type
- * in complete strings.
- *
- * @author iwgeric
- */
-public class AndroidKeyHandler implements View.OnKeyListener {
-    private static final Logger logger = Logger.getLogger(AndroidKeyHandler.class.getName());
-
-    private AndroidInputHandler androidInput;
-    private boolean sendKeyEvents = true;
-
-    public AndroidKeyHandler(AndroidInputHandler androidInput) {
-        this.androidInput = androidInput;
-    }
-
-    public void initialize() {
-    }
-
-    public void destroy() {
-    }
-
-    public void setView(View view) {
-        if (view != null) {
-            view.setOnKeyListener(this);
-        } else {
-            androidInput.getView().setOnKeyListener(null);
-        }
-    }
-
-    /**
-     * onKey gets called from android thread on key events
-     */
-    public boolean onKey(View view, int keyCode, KeyEvent event) {
-        if (androidInput.isInitialized() && view != androidInput.getView()) {
-            return false;
-        }
-
-        TouchEvent evt;
-        // TODO: get touch event from pool
-        if (event.getAction() == KeyEvent.ACTION_DOWN) {
-            evt = new TouchEvent();
-            evt.set(TouchEvent.Type.KEY_DOWN);
-            evt.setKeyCode(keyCode);
-            evt.setCharacters(event.getCharacters());
-            evt.setTime(event.getEventTime());
-
-            // Send the event
-            androidInput.addEvent(evt);
-
-        } else if (event.getAction() == KeyEvent.ACTION_UP) {
-            evt = new TouchEvent();
-            evt.set(TouchEvent.Type.KEY_UP);
-            evt.setKeyCode(keyCode);
-            evt.setCharacters(event.getCharacters());
-            evt.setTime(event.getEventTime());
-
-            // Send the event
-            androidInput.addEvent(evt);
-
-        }
-
-        if (androidInput.isSimulateKeyboard()) {
-            KeyInputEvent kie;
-            char unicodeChar = (char)event.getUnicodeChar();
-            int jmeKeyCode = AndroidKeyMapping.getJmeKey(keyCode);
-
-            boolean pressed = event.getAction() == KeyEvent.ACTION_DOWN;
-            boolean repeating = pressed && event.getRepeatCount() > 0;
-
-            kie = new KeyInputEvent(jmeKeyCode, unicodeChar, pressed, repeating);
-            kie.setTime(event.getEventTime());
-            androidInput.addEvent(kie);
-//            logger.log(Level.FINE, "onKey keyCode: {0}, jmeKeyCode: {1}, pressed: {2}, repeating: {3}",
-//                    new Object[]{keyCode, jmeKeyCode, pressed, repeating});
-//            logger.log(Level.FINE, "creating KeyInputEvent: {0}", kie);
-        }
-
-        // consume all keys ourself except Volume Up/Down and Menu
-        //   Don't do Menu so that typical Android Menus can be created and used
-        //   by the user in MainActivity
-        if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP) ||
-                (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) ||
-                (keyCode == KeyEvent.KEYCODE_MENU)) {
-            return false;
-        } else {
-            return true;
-        }
-
-   }
-
-}

+ 11 - 6
jme3-android/src/main/java/com/jme3/input/android/AndroidKeyMapping.java

@@ -37,13 +37,14 @@ import java.util.logging.Logger;
 
 /**
  * AndroidKeyMapping is just a utility to convert the Android keyCodes into
- * jME KeyCodes received in jME's KeyEvent will match between Desktop and Android.
- * 
+ * jME KeyCodes so that events received in jME's KeyEvent will match between
+ * Desktop and Android.
+ *
  * @author iwgeric
  */
 public class AndroidKeyMapping {
     private static final Logger logger = Logger.getLogger(AndroidKeyMapping.class.getName());
-    
+
     private static final int[] ANDROID_TO_JME = {
         0x0, // unknown
         0x0, // key code soft left
@@ -141,9 +142,13 @@ public class AndroidKeyMapping {
         0x0,//media fastforward
         0x0,//mute
     };
-    
+
     public static int getJmeKey(int androidKey) {
-        return ANDROID_TO_JME[androidKey];
+        if (androidKey > ANDROID_TO_JME.length) {
+            return androidKey;
+        } else {
+            return ANDROID_TO_JME[androidKey];
+        }
     }
-    
+
 }

+ 24 - 24
jme3-android/src/main/java/com/jme3/input/android/AndroidSensorJoyInput.java

@@ -75,15 +75,15 @@ import java.util.logging.Logger;
 public class AndroidSensorJoyInput implements SensorEventListener {
     private final static Logger logger = Logger.getLogger(AndroidSensorJoyInput.class.getName());
 
-    private AndroidJoyInputHandler joyHandler;
+    private AndroidJoyInput joyInput;
     private SensorManager sensorManager = null;
     private WindowManager windowManager = null;
     private IntMap<SensorData> sensors = new IntMap<SensorData>();
     private int lastRotation = 0;
     private boolean loaded = false;
 
-    public AndroidSensorJoyInput(AndroidJoyInputHandler joyHandler) {
-        this.joyHandler = joyHandler;
+    public AndroidSensorJoyInput(AndroidJoyInput joyInput) {
+        this.joyInput = joyInput;
     }
 
     /**
@@ -96,7 +96,7 @@ public class AndroidSensorJoyInput implements SensorEventListener {
         int sensorAccuracy = -1;
         float[] lastValues;
         final Object valuesLock = new Object();
-        ArrayList<AndroidJoystickAxis> axes = new ArrayList<AndroidJoystickAxis>();
+        ArrayList<AndroidSensorJoystickAxis> axes = new ArrayList<AndroidSensorJoystickAxis>();
         boolean enabled = false;
         boolean haveData = false;
 
@@ -306,7 +306,7 @@ public class AndroidSensorJoyInput implements SensorEventListener {
      */
     private boolean updateOrientation() {
         SensorData sensorData;
-        AndroidJoystickAxis axis;
+        AndroidSensorJoystickAxis axis;
         final float[] curInclinationMat = new float[16];
         final float[] curRotationMat = new float[16];
         final float[] rotatedRotationMat = new float[16];
@@ -374,7 +374,7 @@ public class AndroidSensorJoyInput implements SensorEventListener {
                                 sensorData.haveData = true;
                             } else {
                                 if (axis.isChanged()) {
-                                    joyHandler.addEvent(new JoyAxisEvent(axis, axis.getJoystickAxisValue()));
+                                    joyInput.addEvent(new JoyAxisEvent(axis, axis.getJoystickAxisValue()));
                                 }
                             }
                         }
@@ -401,10 +401,10 @@ public class AndroidSensorJoyInput implements SensorEventListener {
 
     public Joystick loadJoystick(int joyId, InputManager inputManager) {
         SensorData sensorData;
-        AndroidJoystickAxis axis;
+        AndroidSensorJoystickAxis axis;
 
-        AndroidJoystick joystick = new AndroidJoystick(inputManager,
-                                    joyHandler,
+        AndroidSensorJoystick joystick = new AndroidSensorJoystick(inputManager,
+                                    joyInput,
                                     joyId,
                                     "AndroidSensorsJoystick");
 
@@ -522,15 +522,15 @@ public class AndroidSensorJoyInput implements SensorEventListener {
         if (!loaded) {
             return;
         }
-        logger.log(Level.FINE, "onSensorChanged for {0}: accuracy: {1}, values: {2}",
-                new Object[]{se.sensor.getName(), se.accuracy, se.values});
+//        logger.log(Level.FINE, "onSensorChanged for {0}: accuracy: {1}, values: {2}",
+//                new Object[]{se.sensor.getName(), se.accuracy, se.values});
 
         int sensorType = se.sensor.getType();
 
         SensorData sensorData = sensors.get(sensorType);
         if (sensorData != null) {
-            logger.log(Level.FINE, "sensorData name: {0}, enabled: {1}, unreliable: {2}",
-                    new Object[]{sensorData.sensor.getName(), sensorData.enabled, sensorData.sensorAccuracy == SensorManager.SENSOR_STATUS_UNRELIABLE});
+//            logger.log(Level.FINE, "sensorData name: {0}, enabled: {1}, unreliable: {2}",
+//                    new Object[]{sensorData.sensor.getName(), sensorData.enabled, sensorData.sensorAccuracy == SensorManager.SENSOR_STATUS_UNRELIABLE});
         }
         if (sensorData != null && sensorData.sensor.equals(se.sensor) && sensorData.enabled) {
 
@@ -543,8 +543,8 @@ public class AndroidSensorJoyInput implements SensorEventListener {
                 }
             }
 
-            if (sensorData != null && sensorData.axes.size() > 0) {
-                AndroidJoystickAxis axis;
+            if (sensorData.axes.size() > 0) {
+                AndroidSensorJoystickAxis axis;
                 for (int i=0; i<se.values.length; i++) {
                     axis = sensorData.axes.get(i);
                     if (axis != null) {
@@ -554,8 +554,8 @@ public class AndroidSensorJoyInput implements SensorEventListener {
                         } else {
                             if (axis.isChanged()) {
                                 JoyAxisEvent event = new JoyAxisEvent(axis, axis.getJoystickAxisValue());
-                                logger.log(Level.INFO, "adding JoyAxisEvent: {0}", event);
-                                joyHandler.addEvent(event);
+//                                logger.log(Level.INFO, "adding JoyAxisEvent: {0}", event);
+                                joyInput.addEvent(event);
 //                                joyHandler.addEvent(new JoyAxisEvent(axis, axis.getJoystickAxisValue()));
                             }
                         }
@@ -585,14 +585,14 @@ public class AndroidSensorJoyInput implements SensorEventListener {
 
     // End of SensorEventListener methods
 
-    protected class AndroidJoystick extends AbstractJoystick {
+    protected class AndroidSensorJoystick extends AbstractJoystick {
         private JoystickAxis nullAxis;
         private JoystickAxis xAxis;
         private JoystickAxis yAxis;
         private JoystickAxis povX;
         private JoystickAxis povY;
 
-        public AndroidJoystick( InputManager inputManager, JoyInput joyInput,
+        public AndroidSensorJoystick( InputManager inputManager, JoyInput joyInput,
                                 int joyId, String name){
 
             super( inputManager, joyInput, joyId, name );
@@ -606,10 +606,10 @@ public class AndroidSensorJoyInput implements SensorEventListener {
 
         }
 
-        protected AndroidJoystickAxis addAxis(String axisName, String logicalName, int axisNum, float maxRawValue) {
-            AndroidJoystickAxis axis;
+        protected AndroidSensorJoystickAxis addAxis(String axisName, String logicalName, int axisNum, float maxRawValue) {
+            AndroidSensorJoystickAxis axis;
 
-            axis = new AndroidJoystickAxis(
+            axis = new AndroidSensorJoystickAxis(
                     getInputManager(),          // InputManager (InputManager)
                     this,                       // parent Joystick (Joystick)
                     axisNum,                    // Axis Index (int)
@@ -654,7 +654,7 @@ public class AndroidSensorJoyInput implements SensorEventListener {
 
     }
 
-    public class AndroidJoystickAxis extends DefaultJoystickAxis implements SensorJoystickAxis {
+    public class AndroidSensorJoystickAxis extends DefaultJoystickAxis implements SensorJoystickAxis {
         float zeroRawValue = 0f;
         float curRawValue = 0f;
         float lastRawValue = 0f;
@@ -662,7 +662,7 @@ public class AndroidSensorJoyInput implements SensorEventListener {
         float maxRawValue = FastMath.HALF_PI;
         boolean enabled = true;
 
-        public AndroidJoystickAxis(InputManager inputManager, Joystick parent,
+        public AndroidSensorJoystickAxis(InputManager inputManager, Joystick parent,
                            int axisIndex, String name, String logicalId,
                            boolean isAnalog, boolean isRelative, float deadZone,
                            float maxRawValue) {

+ 0 - 257
jme3-android/src/main/java/com/jme3/input/android/AndroidTouchHandler.java

@@ -1,257 +0,0 @@
-/*
- * Copyright (c) 2009-2012 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- *   may be used to endorse or promote products derived from this software
- *   without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-package com.jme3.input.android;
-
-import android.view.MotionEvent;
-import android.view.View;
-import com.jme3.input.event.InputEvent;
-import com.jme3.input.event.MouseButtonEvent;
-import com.jme3.input.event.MouseMotionEvent;
-import com.jme3.input.event.TouchEvent;
-import static com.jme3.input.event.TouchEvent.Type.DOWN;
-import static com.jme3.input.event.TouchEvent.Type.MOVE;
-import static com.jme3.input.event.TouchEvent.Type.UP;
-import com.jme3.math.Vector2f;
-import java.util.HashMap;
-import java.util.logging.Logger;
-
-/**
- * AndroidTouchHandler is the base class that receives touch inputs from the 
- * Android system and creates the TouchEvents for jME.  This class is designed
- * to handle the base touch events for Android rev 9 (Android 2.3).  This is
- * extended by other classes to add features that were introducted after
- * Android rev 9.
- * 
- * @author iwgeric
- */
-public class AndroidTouchHandler implements View.OnTouchListener {
-    private static final Logger logger = Logger.getLogger(AndroidTouchHandler.class.getName());
-    
-    final private HashMap<Integer, Vector2f> lastPositions = new HashMap<Integer, Vector2f>();
-
-    protected int numPointers = 0;
-    
-    protected AndroidInputHandler androidInput;
-    protected AndroidGestureHandler gestureHandler;
-
-    public AndroidTouchHandler(AndroidInputHandler androidInput, AndroidGestureHandler gestureHandler) {
-        this.androidInput = androidInput;
-        this.gestureHandler = gestureHandler;
-    }
-
-    public void initialize() {
-    }
-    
-    public void destroy() {
-        setView(null);
-    }
-    
-    public void setView(View view) {
-        if (view != null) {
-            view.setOnTouchListener(this);
-        } else {
-            androidInput.getView().setOnTouchListener(null);
-        }
-    }
-    
-    protected int getPointerIndex(MotionEvent event) {
-        return (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK)
-                >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
-    }
-    
-    protected int getPointerId(MotionEvent event) {
-        return event.getPointerId(getPointerIndex(event));
-    }
-    
-    protected int getAction(MotionEvent event) {
-        return event.getAction() & MotionEvent.ACTION_MASK;
-    }
-    
-    /**
-     * onTouch gets called from android thread on touch events
-     */
-    public boolean onTouch(View view, MotionEvent event) {
-        if (!androidInput.isInitialized() || view != androidInput.getView()) {
-            return false;
-        }
-        
-        boolean bWasHandled = false;
-        TouchEvent touch = null;
-        //    System.out.println("native : " + event.getAction());
-        int action = getAction(event);
-        int pointerIndex = getPointerIndex(event);
-        int pointerId = getPointerId(event);
-        Vector2f lastPos = lastPositions.get(pointerId);
-        float jmeX;
-        float jmeY;
-        
-        numPointers = event.getPointerCount();
-
-        // final int historySize = event.getHistorySize();
-        //final int pointerCount = event.getPointerCount();
-        switch (getAction(event)) {
-            case MotionEvent.ACTION_POINTER_DOWN:
-            case MotionEvent.ACTION_DOWN:
-                jmeX = androidInput.getJmeX(event.getX(pointerIndex));
-                jmeY = androidInput.invertY(androidInput.getJmeY(event.getY(pointerIndex)));
-                touch = androidInput.getFreeTouchEvent();
-                touch.set(TouchEvent.Type.DOWN, jmeX, jmeY, 0, 0);
-                touch.setPointerId(pointerId);
-                touch.setTime(event.getEventTime());
-                touch.setPressure(event.getPressure(pointerIndex));
-
-                lastPos = new Vector2f(jmeX, jmeY);
-                lastPositions.put(pointerId, lastPos);
-
-                processEvent(touch);
-
-                bWasHandled = true;
-                break;
-            case MotionEvent.ACTION_POINTER_UP:
-            case MotionEvent.ACTION_CANCEL:
-            case MotionEvent.ACTION_UP:
-                jmeX = androidInput.getJmeX(event.getX(pointerIndex));
-                jmeY = androidInput.invertY(androidInput.getJmeY(event.getY(pointerIndex)));
-                touch = androidInput.getFreeTouchEvent();
-                touch.set(TouchEvent.Type.UP, jmeX, jmeY, 0, 0);
-                touch.setPointerId(pointerId);
-                touch.setTime(event.getEventTime());
-                touch.setPressure(event.getPressure(pointerIndex));
-                lastPositions.remove(pointerId);
-
-                processEvent(touch);
-
-                bWasHandled = true;
-                break;
-            case MotionEvent.ACTION_MOVE:
-                // Convert all pointers into events
-                for (int p = 0; p < event.getPointerCount(); p++) {
-                    jmeX = androidInput.getJmeX(event.getX(p));
-                    jmeY = androidInput.invertY(androidInput.getJmeY(event.getY(p)));
-                    lastPos = lastPositions.get(event.getPointerId(p));
-                    if (lastPos == null) {
-                        lastPos = new Vector2f(jmeX, jmeY);
-                        lastPositions.put(event.getPointerId(p), lastPos);
-                    }
-
-                    float dX = jmeX - lastPos.x;
-                    float dY = jmeY - lastPos.y;
-                    if (dX != 0 || dY != 0) {
-                        touch = androidInput.getFreeTouchEvent();
-                        touch.set(TouchEvent.Type.MOVE, jmeX, jmeY, dX, dY);
-                        touch.setPointerId(event.getPointerId(p));
-                        touch.setTime(event.getEventTime());
-                        touch.setPressure(event.getPressure(p));
-                        lastPos.set(jmeX, jmeY);
-
-                        processEvent(touch);
-
-                        bWasHandled = true;
-                    }
-                }
-                break;
-            case MotionEvent.ACTION_OUTSIDE:
-                break;
-
-        }
-
-        // Try to detect gestures
-        if (gestureHandler != null) {
-            gestureHandler.detectGesture(event);
-        }
-
-        return bWasHandled;
-    }
-
-    protected void processEvent(TouchEvent event) {
-        // Add the touch event
-        androidInput.addEvent(event);
-        // MouseEvents do not support multi-touch, so only evaluate 1 finger pointer events
-        if (androidInput.isSimulateMouse() && numPointers == 1) {
-            InputEvent mouseEvent = generateMouseEvent(event);
-            if (mouseEvent != null) {
-                // Add the mouse event
-                androidInput.addEvent(mouseEvent);
-            }
-        }
-        
-    }
-
-    // TODO: Ring Buffer for mouse events?
-    protected InputEvent generateMouseEvent(TouchEvent event) {
-        InputEvent inputEvent = null;
-        int newX;
-        int newY;
-        int newDX;
-        int newDY;
-
-        if (androidInput.isMouseEventsInvertX()) {
-            newX = (int) (androidInput.invertX(event.getX()));
-            newDX = (int)event.getDeltaX() * -1;
-        } else {
-            newX = (int) event.getX();
-            newDX = (int)event.getDeltaX();
-        }
-
-        if (androidInput.isMouseEventsInvertY()) {
-            newY = (int) (androidInput.invertY(event.getY()));
-            newDY = (int)event.getDeltaY() * -1;
-        } else {
-            newY = (int) event.getY();
-            newDY = (int)event.getDeltaY();
-        }
-
-        switch (event.getType()) {
-            case DOWN:
-                // Handle mouse down event
-                inputEvent = new MouseButtonEvent(0, true, newX, newY);
-                inputEvent.setTime(event.getTime());
-                break;
-
-            case UP:
-                // Handle mouse up event
-                inputEvent = new MouseButtonEvent(0, false, newX, newY);
-                inputEvent.setTime(event.getTime());
-                break;
-
-            case HOVER_MOVE:
-            case MOVE:
-                inputEvent = new MouseMotionEvent(newX, newY, newDX, newDY, (int)event.getScaleSpan(), (int)event.getDeltaScaleSpan());
-                inputEvent.setTime(event.getTime());
-                break;
-        }
-
-        return inputEvent;
-    }
-    
-}

+ 475 - 0
jme3-android/src/main/java/com/jme3/input/android/AndroidTouchInput.java

@@ -0,0 +1,475 @@
+/*
+ * Copyright (c) 2009-2012 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *   may be used to endorse or promote products derived from this software
+ *   without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package com.jme3.input.android;
+
+import android.view.GestureDetector;
+import android.view.KeyEvent;
+import android.view.MotionEvent;
+import android.view.ScaleGestureDetector;
+import com.jme3.input.RawInputListener;
+import com.jme3.input.TouchInput;
+import com.jme3.input.event.InputEvent;
+import com.jme3.input.event.KeyInputEvent;
+import com.jme3.input.event.MouseButtonEvent;
+import com.jme3.input.event.MouseMotionEvent;
+import com.jme3.input.event.TouchEvent;
+import static com.jme3.input.event.TouchEvent.Type.DOWN;
+import static com.jme3.input.event.TouchEvent.Type.MOVE;
+import static com.jme3.input.event.TouchEvent.Type.UP;
+import com.jme3.math.Vector2f;
+import com.jme3.system.AppSettings;
+import java.util.HashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * AndroidTouchInput is the base class that receives touch inputs from the
+ * Android system and creates the TouchEvents for jME.  This class is designed
+ * to handle the base touch events for Android rev 9 (Android 2.3).  This is
+ * extended by other classes to add features that were introducted after
+ * Android rev 9.
+ *
+ * @author iwgeric
+ */
+public class AndroidTouchInput implements TouchInput {
+    private static final Logger logger = Logger.getLogger(AndroidTouchInput.class.getName());
+
+    private boolean mouseEventsEnabled = true;
+    private boolean mouseEventsInvertX = false;
+    private boolean mouseEventsInvertY = false;
+    private boolean keyboardEventsEnabled = false;
+    private boolean dontSendHistory = false;
+
+    protected int numPointers = 0;
+    final private HashMap<Integer, Vector2f> lastPositions = new HashMap<Integer, Vector2f>();
+    final private ConcurrentLinkedQueue<InputEvent> inputEventQueue = new ConcurrentLinkedQueue<InputEvent>();
+    private final static int MAX_TOUCH_EVENTS = 1024;
+    private final TouchEventPool touchEventPool = new TouchEventPool(MAX_TOUCH_EVENTS);
+    private float scaleX = 1f;
+    private float scaleY = 1f;
+
+    private boolean initialized = false;
+    private RawInputListener listener = null;
+
+    private GestureDetector gestureDetector;
+    private ScaleGestureDetector scaleDetector;
+
+    protected AndroidInputHandler androidInput;
+
+    public AndroidTouchInput(AndroidInputHandler androidInput) {
+        this.androidInput = androidInput;
+    }
+
+    public GestureDetector getGestureDetector() {
+        return gestureDetector;
+    }
+
+    public void setGestureDetector(GestureDetector gestureDetector) {
+        this.gestureDetector = gestureDetector;
+    }
+
+    public ScaleGestureDetector getScaleDetector() {
+        return scaleDetector;
+    }
+
+    public void setScaleDetector(ScaleGestureDetector scaleDetector) {
+        this.scaleDetector = scaleDetector;
+    }
+
+    public float invertX(float origX) {
+        return getJmeX(androidInput.getView().getWidth()) - origX;
+    }
+
+    public float invertY(float origY) {
+        return getJmeY(androidInput.getView().getHeight()) - origY;
+    }
+
+    public float getJmeX(float origX) {
+        return origX * scaleX;
+    }
+
+    public float getJmeY(float origY) {
+        return origY * scaleY;
+    }
+
+    public void loadSettings(AppSettings settings) {
+        keyboardEventsEnabled = settings.isEmulateKeyboard();
+        mouseEventsEnabled = settings.isEmulateMouse();
+        mouseEventsInvertX = settings.isEmulateMouseFlipX();
+        mouseEventsInvertY = settings.isEmulateMouseFlipY();
+
+        // view width and height are 0 until the view is displayed on the screen
+        if (androidInput.getView().getWidth() != 0 && androidInput.getView().getHeight() != 0) {
+            scaleX = (float)settings.getWidth() / (float)androidInput.getView().getWidth();
+            scaleY = (float)settings.getHeight() / (float)androidInput.getView().getHeight();
+        }
+        logger.log(Level.FINE, "Setting input scaling, scaleX: {0}, scaleY: {1}",
+                new Object[]{scaleX, scaleY});
+
+
+    }
+
+
+    protected int getPointerIndex(MotionEvent event) {
+        return (event.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK)
+                >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
+    }
+
+    protected int getPointerId(MotionEvent event) {
+        return event.getPointerId(getPointerIndex(event));
+    }
+
+    protected int getAction(MotionEvent event) {
+        return event.getAction() & MotionEvent.ACTION_MASK;
+    }
+
+    public boolean onTouch(MotionEvent event) {
+        if (!isInitialized()) {
+            return false;
+        }
+
+        boolean bWasHandled = false;
+        TouchEvent touch = null;
+        //    System.out.println("native : " + event.getAction());
+        int action = getAction(event);
+        int pointerIndex = getPointerIndex(event);
+        int pointerId = getPointerId(event);
+        Vector2f lastPos = lastPositions.get(pointerId);
+        float jmeX;
+        float jmeY;
+
+        numPointers = event.getPointerCount();
+
+        // final int historySize = event.getHistorySize();
+        //final int pointerCount = event.getPointerCount();
+        switch (getAction(event)) {
+            case MotionEvent.ACTION_POINTER_DOWN:
+            case MotionEvent.ACTION_DOWN:
+                jmeX = getJmeX(event.getX(pointerIndex));
+                jmeY = invertY(getJmeY(event.getY(pointerIndex)));
+                touch = getFreeTouchEvent();
+                touch.set(TouchEvent.Type.DOWN, jmeX, jmeY, 0, 0);
+                touch.setPointerId(pointerId);
+                touch.setTime(event.getEventTime());
+                touch.setPressure(event.getPressure(pointerIndex));
+
+                lastPos = new Vector2f(jmeX, jmeY);
+                lastPositions.put(pointerId, lastPos);
+
+                addEvent(touch);
+                addEvent(generateMouseEvent(touch));
+
+                bWasHandled = true;
+                break;
+            case MotionEvent.ACTION_POINTER_UP:
+            case MotionEvent.ACTION_CANCEL:
+            case MotionEvent.ACTION_UP:
+                jmeX = getJmeX(event.getX(pointerIndex));
+                jmeY = invertY(getJmeY(event.getY(pointerIndex)));
+                touch = getFreeTouchEvent();
+                touch.set(TouchEvent.Type.UP, jmeX, jmeY, 0, 0);
+                touch.setPointerId(pointerId);
+                touch.setTime(event.getEventTime());
+                touch.setPressure(event.getPressure(pointerIndex));
+                lastPositions.remove(pointerId);
+
+                addEvent(touch);
+                addEvent(generateMouseEvent(touch));
+
+                bWasHandled = true;
+                break;
+            case MotionEvent.ACTION_MOVE:
+                // Convert all pointers into events
+                for (int p = 0; p < event.getPointerCount(); p++) {
+                    jmeX = getJmeX(event.getX(p));
+                    jmeY = invertY(getJmeY(event.getY(p)));
+                    lastPos = lastPositions.get(event.getPointerId(p));
+                    if (lastPos == null) {
+                        lastPos = new Vector2f(jmeX, jmeY);
+                        lastPositions.put(event.getPointerId(p), lastPos);
+                    }
+
+                    float dX = jmeX - lastPos.x;
+                    float dY = jmeY - lastPos.y;
+                    if (dX != 0 || dY != 0) {
+                        touch = getFreeTouchEvent();
+                        touch.set(TouchEvent.Type.MOVE, jmeX, jmeY, dX, dY);
+                        touch.setPointerId(event.getPointerId(p));
+                        touch.setTime(event.getEventTime());
+                        touch.setPressure(event.getPressure(p));
+                        lastPos.set(jmeX, jmeY);
+
+                        addEvent(touch);
+                        addEvent(generateMouseEvent(touch));
+
+                        bWasHandled = true;
+                    }
+                }
+                break;
+            case MotionEvent.ACTION_OUTSIDE:
+                break;
+
+        }
+
+        // Try to detect gestures
+        if (gestureDetector != null) {
+            gestureDetector.onTouchEvent(event);
+        }
+        if (scaleDetector != null) {
+            scaleDetector.onTouchEvent(event);
+        }
+
+        return bWasHandled;
+    }
+
+    // TODO: Ring Buffer for mouse events?
+    public InputEvent generateMouseEvent(TouchEvent event) {
+        InputEvent inputEvent = null;
+        int newX;
+        int newY;
+        int newDX;
+        int newDY;
+
+        // MouseEvents do not support multi-touch, so only evaluate 1 finger pointer events
+        if (!isSimulateMouse() || numPointers > 1) {
+            return null;
+        }
+
+
+        if (isMouseEventsInvertX()) {
+            newX = (int) (invertX(event.getX()));
+            newDX = (int)event.getDeltaX() * -1;
+        } else {
+            newX = (int) event.getX();
+            newDX = (int)event.getDeltaX();
+        }
+
+        if (isMouseEventsInvertY()) {
+            newY = (int) (invertY(event.getY()));
+            newDY = (int)event.getDeltaY() * -1;
+        } else {
+            newY = (int) event.getY();
+            newDY = (int)event.getDeltaY();
+        }
+
+        switch (event.getType()) {
+            case DOWN:
+                // Handle mouse down event
+                inputEvent = new MouseButtonEvent(0, true, newX, newY);
+                inputEvent.setTime(event.getTime());
+                break;
+
+            case UP:
+                // Handle mouse up event
+                inputEvent = new MouseButtonEvent(0, false, newX, newY);
+                inputEvent.setTime(event.getTime());
+                break;
+
+            case HOVER_MOVE:
+            case MOVE:
+                inputEvent = new MouseMotionEvent(newX, newY, newDX, newDY, (int)event.getScaleSpan(), (int)event.getDeltaScaleSpan());
+                inputEvent.setTime(event.getTime());
+                break;
+        }
+
+        return inputEvent;
+    }
+
+
+    public boolean onKey(KeyEvent event) {
+        if (!isInitialized()) {
+            return false;
+        }
+
+        TouchEvent evt;
+        // TODO: get touch event from pool
+        if (event.getAction() == KeyEvent.ACTION_DOWN) {
+            evt = new TouchEvent();
+            evt.set(TouchEvent.Type.KEY_DOWN);
+            evt.setKeyCode(event.getKeyCode());
+            evt.setCharacters(event.getCharacters());
+            evt.setTime(event.getEventTime());
+
+            // Send the event
+            addEvent(evt);
+
+        } else if (event.getAction() == KeyEvent.ACTION_UP) {
+            evt = new TouchEvent();
+            evt.set(TouchEvent.Type.KEY_UP);
+            evt.setKeyCode(event.getKeyCode());
+            evt.setCharacters(event.getCharacters());
+            evt.setTime(event.getEventTime());
+
+            // Send the event
+            addEvent(evt);
+
+        }
+
+        if (isSimulateKeyboard()) {
+            KeyInputEvent kie;
+            char unicodeChar = (char)event.getUnicodeChar();
+            int jmeKeyCode = AndroidKeyMapping.getJmeKey(event.getKeyCode());
+
+            boolean pressed = event.getAction() == KeyEvent.ACTION_DOWN;
+            boolean repeating = pressed && event.getRepeatCount() > 0;
+
+            kie = new KeyInputEvent(jmeKeyCode, unicodeChar, pressed, repeating);
+            kie.setTime(event.getEventTime());
+            addEvent(kie);
+//            logger.log(Level.FINE, "onKey keyCode: {0}, jmeKeyCode: {1}, pressed: {2}, repeating: {3}",
+//                    new Object[]{event.getKeyCode(), jmeKeyCode, pressed, repeating});
+//            logger.log(Level.FINE, "creating KeyInputEvent: {0}", kie);
+        }
+
+        // consume all keys ourself except Volume Up/Down and Menu
+        //   Don't do Menu so that typical Android Menus can be created and used
+        //   by the user in MainActivity
+        if ((event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_UP) ||
+                (event.getKeyCode() == KeyEvent.KEYCODE_VOLUME_DOWN) ||
+                (event.getKeyCode() == KeyEvent.KEYCODE_MENU)) {
+            return false;
+        } else {
+            return true;
+        }
+
+   }
+
+
+
+
+        // -----------------------------------------
+    // JME3 Input interface
+    @Override
+    public void initialize() {
+        touchEventPool.initialize();
+
+        initialized = true;
+    }
+
+    @Override
+    public void destroy() {
+        initialized = false;
+
+        touchEventPool.destroy();
+
+    }
+
+    @Override
+    public boolean isInitialized() {
+        return initialized;
+    }
+
+    @Override
+    public void setInputListener(RawInputListener listener) {
+        this.listener = listener;
+    }
+
+    @Override
+    public long getInputTimeNanos() {
+        return System.nanoTime();
+    }
+
+    @Override
+    public void update() {
+        if (listener != null) {
+            InputEvent inputEvent;
+
+            while ((inputEvent = inputEventQueue.poll()) != null) {
+                if (inputEvent instanceof TouchEvent) {
+                    listener.onTouchEvent((TouchEvent)inputEvent);
+                } else if (inputEvent instanceof MouseButtonEvent) {
+                    listener.onMouseButtonEvent((MouseButtonEvent)inputEvent);
+                } else if (inputEvent instanceof MouseMotionEvent) {
+                    listener.onMouseMotionEvent((MouseMotionEvent)inputEvent);
+                } else if (inputEvent instanceof KeyInputEvent) {
+                    listener.onKeyEvent((KeyInputEvent)inputEvent);
+                }
+            }
+        }
+    }
+
+    // -----------------------------------------
+
+    public TouchEvent getFreeTouchEvent() {
+            return touchEventPool.getNextFreeEvent();
+    }
+
+    public void addEvent(InputEvent event) {
+        if (event == null) {
+            return;
+        }
+
+        logger.log(Level.INFO, "event: {0}", event);
+
+        inputEventQueue.add(event);
+        if (event instanceof TouchEvent) {
+            touchEventPool.storeEvent((TouchEvent)event);
+        }
+
+    }
+
+    @Override
+    public void setSimulateMouse(boolean simulate) {
+        this.mouseEventsEnabled = simulate;
+    }
+
+    @Override
+    public boolean isSimulateMouse() {
+        return mouseEventsEnabled;
+    }
+
+    public boolean isMouseEventsInvertX() {
+        return mouseEventsInvertX;
+    }
+
+    public boolean isMouseEventsInvertY() {
+        return mouseEventsInvertY;
+    }
+
+    @Override
+    public void setSimulateKeyboard(boolean simulate) {
+        this.keyboardEventsEnabled = simulate;
+    }
+
+    @Override
+    public boolean isSimulateKeyboard() {
+        return keyboardEventsEnabled;
+    }
+
+    @Override
+    public void setOmitHistoricEvents(boolean dontSendHistory) {
+        this.dontSendHistory = dontSendHistory;
+    }
+
+}

+ 30 - 46
jme3-android/src/main/java/com/jme3/input/android/AndroidTouchHandler14.java → jme3-android/src/main/java/com/jme3/input/android/AndroidTouchInput14.java

@@ -33,7 +33,6 @@
 package com.jme3.input.android;
 
 import android.view.MotionEvent;
-import android.view.View;
 import com.jme3.input.event.TouchEvent;
 import com.jme3.math.Vector2f;
 import java.util.HashMap;
@@ -41,36 +40,20 @@ import java.util.logging.Level;
 import java.util.logging.Logger;
 
 /**
- * AndroidTouchHandler14 is an extension of AndroidTouchHander that adds the
- * Android touch event functionality between Android rev 9 (Android 2.3) and 
- * Android rev 14 (Android 4.0).
- * 
+ * AndroidTouchHandler14 extends AndroidTouchHandler to process the onHover
+ * events added in Android rev 14 (Android 4.0).
+ *
  * @author iwgeric
  */
-public class AndroidTouchHandler14 extends AndroidTouchHandler implements 
-        View.OnHoverListener {
-    private static final Logger logger = Logger.getLogger(AndroidTouchHandler14.class.getName());
+public class AndroidTouchInput14 extends AndroidTouchInput {
+    private static final Logger logger = Logger.getLogger(AndroidTouchInput14.class.getName());
     final private HashMap<Integer, Vector2f> lastHoverPositions = new HashMap<Integer, Vector2f>();
-    
-    public AndroidTouchHandler14(AndroidInputHandler androidInput, AndroidGestureHandler gestureHandler) {
-        super(androidInput, gestureHandler);
-    }
 
-    @Override
-    public void setView(View view) {
-        if (view != null) {
-            view.setOnHoverListener(this);
-        } else {
-            androidInput.getView().setOnHoverListener(null);
-        }
-        super.setView(view);
+    public AndroidTouchInput14(AndroidInputHandler androidInput) {
+        super(androidInput);
     }
-    
-    public boolean onHover(View view, MotionEvent event) {
-        if (view == null || view != androidInput.getView()) {
-            return false;
-        }
-        
+
+    public boolean onHover(MotionEvent event) {
         boolean consumed = false;
         int action = getAction(event);
         int pointerId = getPointerId(event);
@@ -78,34 +61,34 @@ public class AndroidTouchHandler14 extends AndroidTouchHandler implements
         Vector2f lastPos = lastHoverPositions.get(pointerId);
         float jmeX;
         float jmeY;
-        
+
         numPointers = event.getPointerCount();
-        
-        logger.log(Level.INFO, "onHover pointerId: {0}, action: {1}, x: {2}, y: {3}, numPointers: {4}", 
-                new Object[]{pointerId, action, event.getX(), event.getY(), event.getPointerCount()});
+
+//        logger.log(Level.INFO, "onHover pointerId: {0}, action: {1}, x: {2}, y: {3}, numPointers: {4}",
+//                new Object[]{pointerId, action, event.getX(), event.getY(), event.getPointerCount()});
 
         TouchEvent touchEvent;
         switch (action) {
             case MotionEvent.ACTION_HOVER_ENTER:
-                jmeX = androidInput.getJmeX(event.getX(pointerIndex));
-                jmeY = androidInput.invertY(androidInput.getJmeY(event.getY(pointerIndex)));
-                touchEvent = androidInput.getFreeTouchEvent();
+                jmeX = getJmeX(event.getX(pointerIndex));
+                jmeY = invertY(getJmeY(event.getY(pointerIndex)));
+                touchEvent = getFreeTouchEvent();
                 touchEvent.set(TouchEvent.Type.HOVER_START, jmeX, jmeY, 0, 0);
                 touchEvent.setPointerId(pointerId);
                 touchEvent.setTime(event.getEventTime());
                 touchEvent.setPressure(event.getPressure(pointerIndex));
-                
+
                 lastPos = new Vector2f(jmeX, jmeY);
                 lastHoverPositions.put(pointerId, lastPos);
-                
-                processEvent(touchEvent);
+
+                addEvent(touchEvent);
                 consumed = true;
                 break;
             case MotionEvent.ACTION_HOVER_MOVE:
                 // Convert all pointers into events
                 for (int p = 0; p < event.getPointerCount(); p++) {
-                    jmeX = androidInput.getJmeX(event.getX(p));
-                    jmeY = androidInput.invertY(androidInput.getJmeY(event.getY(p)));
+                    jmeX = getJmeX(event.getX(p));
+                    jmeY = invertY(getJmeY(event.getY(p)));
                     lastPos = lastHoverPositions.get(event.getPointerId(p));
                     if (lastPos == null) {
                         lastPos = new Vector2f(jmeX, jmeY);
@@ -115,38 +98,39 @@ public class AndroidTouchHandler14 extends AndroidTouchHandler implements
                     float dX = jmeX - lastPos.x;
                     float dY = jmeY - lastPos.y;
                     if (dX != 0 || dY != 0) {
-                        touchEvent = androidInput.getFreeTouchEvent();
+                        touchEvent = getFreeTouchEvent();
                         touchEvent.set(TouchEvent.Type.HOVER_MOVE, jmeX, jmeY, dX, dY);
                         touchEvent.setPointerId(event.getPointerId(p));
                         touchEvent.setTime(event.getEventTime());
                         touchEvent.setPressure(event.getPressure(p));
                         lastPos.set(jmeX, jmeY);
 
-                        processEvent(touchEvent);
+                        addEvent(touchEvent);
 
                     }
                 }
                 consumed = true;
                 break;
             case MotionEvent.ACTION_HOVER_EXIT:
-                jmeX = androidInput.getJmeX(event.getX(pointerIndex));
-                jmeY = androidInput.invertY(androidInput.getJmeY(event.getY(pointerIndex)));
-                touchEvent = androidInput.getFreeTouchEvent();
+                jmeX = getJmeX(event.getX(pointerIndex));
+                jmeY = invertY(getJmeY(event.getY(pointerIndex)));
+                touchEvent = getFreeTouchEvent();
                 touchEvent.set(TouchEvent.Type.HOVER_END, jmeX, jmeY, 0, 0);
                 touchEvent.setPointerId(pointerId);
                 touchEvent.setTime(event.getEventTime());
                 touchEvent.setPressure(event.getPressure(pointerIndex));
                 lastHoverPositions.remove(pointerId);
 
-                processEvent(touchEvent);
+                addEvent(touchEvent);
                 consumed = true;
                 break;
             default:
                 consumed = false;
                 break;
         }
-        
+
         return consumed;
+
     }
-    
+
 }

+ 12 - 8
jme3-android/src/main/java/com/jme3/renderer/android/AndroidGL.java

@@ -35,39 +35,43 @@ import android.opengl.GLES20;
 import com.jme3.renderer.RendererException;
 import com.jme3.renderer.opengl.GL;
 import com.jme3.renderer.opengl.GLExt;
+import com.jme3.renderer.opengl.GLFbo;
 import java.nio.Buffer;
 import java.nio.ByteBuffer;
 import java.nio.FloatBuffer;
 import java.nio.IntBuffer;
 import java.nio.ShortBuffer;
 
-public class AndroidGL implements GL, GLExt {
+public class AndroidGL implements GL, GLExt, GLFbo {
+
+    public void resetStats() {
+    }
 
     private static int getLimitBytes(ByteBuffer buffer) {
         checkLimit(buffer);
         return buffer.limit();
     }
-    
+
     private static int getLimitBytes(ShortBuffer buffer) {
         checkLimit(buffer);
         return buffer.limit() * 2;
     }
-    
+
     private static int getLimitBytes(IntBuffer buffer) {
         checkLimit(buffer);
         return buffer.limit() * 4;
     }
-    
+
     private static int getLimitBytes(FloatBuffer buffer) {
         checkLimit(buffer);
         return buffer.limit() * 4;
     }
-    
+
     private static int getLimitCount(Buffer buffer, int elementSize) {
         checkLimit(buffer);
         return buffer.limit() / elementSize;
     }
-    
+
     private static void checkLimit(Buffer buffer) {
         if (buffer == null) {
             return;
@@ -79,7 +83,7 @@ public class AndroidGL implements GL, GLExt {
             throw new RendererException("Attempting to upload empty buffer (remaining = 0), that's an error");
         }
     }
-    
+
     public void glActiveTexture(int texture) {
         GLES20.glActiveTexture(texture);
     }
@@ -127,7 +131,7 @@ public class AndroidGL implements GL, GLExt {
     public void glBufferSubData(int target, long offset, ByteBuffer data) {
         GLES20.glBufferSubData(target, (int) offset, getLimitBytes(data), data);
     }
-    
+
     public void glGetBufferSubData(int target, long offset, ByteBuffer data) {
         throw new UnsupportedOperationException("OpenGL ES 2 does not support glGetBufferSubData");
     }

+ 11 - 15
jme3-android/src/main/java/com/jme3/system/android/OGLESContext.java

@@ -47,13 +47,14 @@ import android.widget.EditText;
 import android.widget.FrameLayout;
 import com.jme3.input.*;
 import com.jme3.input.android.AndroidInputHandler;
-import com.jme3.input.android.AndroidJoyInputHandler;
+import com.jme3.input.android.AndroidInputHandler14;
 import com.jme3.input.controls.SoftTextDialogInputListener;
 import com.jme3.input.dummy.DummyKeyInput;
 import com.jme3.input.dummy.DummyMouseInput;
 import com.jme3.renderer.android.AndroidGL;
 import com.jme3.renderer.opengl.GL;
 import com.jme3.renderer.opengl.GLExt;
+import com.jme3.renderer.opengl.GLFbo;
 import com.jme3.renderer.opengl.GLRenderer;
 import com.jme3.system.*;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -75,7 +76,6 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
     protected SystemListener listener;
     protected boolean autoFlush = true;
     protected AndroidInputHandler androidInput;
-    protected AndroidJoyInputHandler androidJoyInput = null;
     protected long minFrameDuration = 0;                   // No FPS cap
     protected long lastUpdateTime = 0;
 
@@ -111,18 +111,17 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
 
         // Start to set up the view
         GLSurfaceView view = new GLSurfaceView(context);
+        logger.log(Level.INFO, "Android Build Version: {0}", Build.VERSION.SDK_INT);
         if (androidInput == null) {
-            androidInput = new AndroidInputHandler();
+            if (Build.VERSION.SDK_INT >= 14) {
+                androidInput = new AndroidInputHandler14();
+            } else if (Build.VERSION.SDK_INT >= 9){
+                androidInput = new AndroidInputHandler();
+            }
         }
         androidInput.setView(view);
         androidInput.loadSettings(settings);
 
-        if (androidJoyInput == null) {
-            androidJoyInput = new AndroidJoyInputHandler();
-        }
-        androidJoyInput.setView(view);
-        androidJoyInput.loadSettings(settings);
-
         // setEGLContextClientVersion must be set before calling setRenderer
         // this means it cannot be set in AndroidConfigChooser (too late)
         view.setEGLContextClientVersion(2);
@@ -198,7 +197,7 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
         Object gl = new AndroidGL();
         // gl = GLTracer.createGlesTracer((GL)gl, (GLExt)gl);
         // gl = new GLDebugES((GL)gl, (GLExt)gl);
-        renderer = new GLRenderer((GL)gl, (GLExt)gl);
+        renderer = new GLRenderer((GL)gl, (GLExt)gl, (GLFbo)gl);
         renderer.initialize();
 
         JmeSystem.setSoftTextDialogInput(this);
@@ -235,9 +234,6 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
         if (androidInput != null) {
             androidInput.loadSettings(settings);
         }
-        if (androidJoyInput != null) {
-            androidJoyInput.loadSettings(settings);
-        }
 
         if (settings.getFrameRate() > 0) {
             minFrameDuration = (long)(1000d / (double)settings.getFrameRate()); // ms
@@ -274,12 +270,12 @@ public class OGLESContext implements JmeContext, GLSurfaceView.Renderer, SoftTex
 
     @Override
     public JoyInput getJoyInput() {
-        return androidJoyInput;
+        return androidInput.getJoyInput();
     }
 
     @Override
     public TouchInput getTouchInput() {
-        return androidInput;
+        return androidInput.getTouchInput();
     }
 
     @Override

+ 12 - 0
jme3-bullet-native/src/native/cpp/com_jme3_bullet_PhysicsSpace.cpp

@@ -528,6 +528,18 @@ extern "C" {
         space->getDynamicsWorld()->convexSweepTest((btConvexShape *) shape, native_from, native_to, resultCallback, native_allowed_ccd_penetration);
         return;
     }
+    
+    JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_setSolverNumIterations
+    (JNIEnv *env, jobject object, jlong spaceId, jint value) {
+        jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*>(spaceId);
+        if (space == NULL) {
+            jclass newExc = env->FindClass("java/lang/NullPointerException");
+            env->ThrowNew(newExc, "The physics space does not exist.");
+            return;
+        }
+        
+        space->getDynamicsWorld()->getSolverInfo().m_numIterations = value;
+    }
 
 #ifdef __cplusplus
 }

+ 8 - 0
jme3-bullet-native/src/native/cpp/com_jme3_bullet_PhysicsSpace.h

@@ -174,6 +174,14 @@ JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_finalizeNative
 JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_sweepTest_1native
 (JNIEnv *, jobject, jlong, jobject, jobject, jlong, jobject, jfloat);
 
+/*
+ * Class:     com_jme3_bullet_PhysicsSpace
+ * Method:    setSolverNumIterations
+ * Signature: (JI)V
+ */
+JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_setSolverNumIterations
+(JNIEnv *, jobject, jlong, jint);
+
 #ifdef __cplusplus
 }
 #endif

+ 1 - 11
jme3-bullet/src/common/java/com/jme3/bullet/BulletAppState.java

@@ -166,7 +166,7 @@ public class BulletAppState implements AppState, PhysicsTickListener {
         pSpace.addTickListener(this);
         initialized = true;
     }
-    
+
     public void stopPhysics() {
         if(!initialized){
             return;
@@ -226,19 +226,9 @@ public class BulletAppState implements AppState, PhysicsTickListener {
         if (debugEnabled && debugAppState == null && pSpace != null) {
             debugAppState = new BulletDebugAppState(pSpace);
             stateManager.attach(debugAppState);
-            pSpace.enableDebug(app.getAssetManager());
         } else if (!debugEnabled && debugAppState != null) {
             stateManager.detach(debugAppState);
             debugAppState = null;
-            if (pSpace != null) {
-                pSpace.enableDebug(null);
-            }
-        }
-        //TODO: remove when deprecation of PhysicsSpace.enableDebug is through
-        if (pSpace.getDebugManager() != null && !debugEnabled) {
-            debugEnabled = true;
-        } else if (pSpace.getDebugManager() == null && debugEnabled) {
-            debugEnabled = false;
         }
         if (!active) {
             return;

+ 1 - 1
jme3-bullet/src/common/java/com/jme3/bullet/control/RigidBodyControl.java

@@ -195,7 +195,7 @@ public class RigidBodyControl extends PhysicsRigidBody implements PhysicsControl
 
     /**
      * When set to true, the physics coordinates will be applied to the local
-     * translation of the Spatial instead of the world traslation.
+     * translation of the Spatial instead of the world translation.
      * @param applyPhysicsLocal
      */
     public void setApplyPhysicsLocal(boolean applyPhysicsLocal) {

+ 23 - 23
jme3-bullet/src/main/java/com/jme3/bullet/PhysicsSpace.java

@@ -102,7 +102,7 @@ public class PhysicsSpace {
     private Vector3f worldMax = new Vector3f(10000f, 10000f, 10000f);
     private float accuracy = 1f / 60f;
     private int maxSubSteps = 4, rayTestFlags = 1 << 2;
-    private AssetManager debugManager;
+    private int solverNumIterations = 10;
 
     static {
 //        System.loadLibrary("bulletjme");
@@ -702,7 +702,7 @@ public class PhysicsSpace {
     public Vector3f getGravity(Vector3f gravity) {
         return gravity.set(this.gravity);
     }
-    
+
 //    /**
 //     * applies gravity value to all objects
 //     */
@@ -783,7 +783,7 @@ public class PhysicsSpace {
     public void SetRayTestFlags(int flags) {
         rayTestFlags = flags;
     }
-    
+
     /**
      * Gets m_flags for raytest, see https://code.google.com/p/bullet/source/browse/trunk/src/BulletCollision/NarrowPhaseCollision/btRaycastCallback.h
      * for possible options.
@@ -792,7 +792,7 @@ public class PhysicsSpace {
     public int GetRayTestFlags() {
         return rayTestFlags;
     }
-    
+
     /**
      * Performs a ray collision test and returns the results as a list of
      * PhysicsRayTestResults
@@ -837,7 +837,7 @@ public class PhysicsSpace {
         return (List<PhysicsSweepTestResult>) results;
     }
 
-    public List<PhysicsSweepTestResult> sweepTest(CollisionShape shape, Transform start, Transform end, List<PhysicsSweepTestResult> results) {        
+    public List<PhysicsSweepTestResult> sweepTest(CollisionShape shape, Transform start, Transform end, List<PhysicsSweepTestResult> results) {
         return sweepTest(shape, start, end, results, 0.0f);
     }
 
@@ -849,7 +849,7 @@ public class PhysicsSpace {
      * collision if it starts INSIDE an object and is moving AWAY from its
      * center.
      */
-    public List<PhysicsSweepTestResult> sweepTest(CollisionShape shape, Transform start, Transform end, List<PhysicsSweepTestResult> results, float allowedCcdPenetration ) {        
+    public List<PhysicsSweepTestResult> sweepTest(CollisionShape shape, Transform start, Transform end, List<PhysicsSweepTestResult> results, float allowedCcdPenetration ) {
         results.clear();
         sweepTest_native(shape.getObjectId(), start, end, physicsSpaceId, results, allowedCcdPenetration);
         return results;
@@ -960,28 +960,28 @@ public class PhysicsSpace {
     }
 
     /**
-     * Enable debug display for physics.
-     *
-     * @deprecated in favor of BulletDebugAppState, use
-     * <code>BulletAppState.setDebugEnabled(boolean)</code> to add automatically
-     * @param manager AssetManager to use to create debug materials
+     * Set the number of iterations used by the contact solver.
+     * 
+     * The default is 10. Use 4 for low quality, 20 for high quality.
+     * 
+     * @param numIterations The number of iterations used by the contact & constraint solver.
      */
-    @Deprecated
-    public void enableDebug(AssetManager manager) {
-        debugManager = manager;
+    public void setSolverNumIterations(int numIterations) {
+        this.solverNumIterations = numIterations;
+        setSolverNumIterations(physicsSpaceId, numIterations);
     }
-
+    
     /**
-     * Disable debug display
+     * Get the number of iterations used by the contact solver.
+     * 
+     * @return The number of iterations used by the contact & constraint solver.
      */
-    public void disableDebug() {
-        debugManager = null;
-    }
-
-    public AssetManager getDebugManager() {
-        return debugManager;
+    public int getSolverNumIterations() {
+        return solverNumIterations;
     }
-
+    
+    private static native void setSolverNumIterations(long physicsSpaceId, int numIterations);
+    
     public static native void initNativePhysics();
 
     /**

+ 20 - 0
jme3-core/src/main/java/com/jme3/animation/Bone.java

@@ -313,6 +313,26 @@ public final class Bone implements Savable {
         return modelBindInverseScale;
     }
 
+    public Transform getModelBindInverseTransform() {
+        Transform t = new Transform();
+        t.setTranslation(modelBindInversePos);
+        t.setRotation(modelBindInverseRot);
+        if (modelBindInverseScale != null) {
+            t.setScale(modelBindInverseScale);
+        }
+        return t;
+    }
+    
+    public Transform getBindInverseTransform() {
+        Transform t = new Transform();
+        t.setTranslation(bindPos);
+        t.setRotation(bindRot);
+        if (bindScale != null) {
+            t.setScale(bindScale);
+        }
+        return t.invert();
+    }
+    
     /**    
      * @deprecated use {@link #getBindPosition()}
      */

+ 15 - 4
jme3-core/src/main/java/com/jme3/animation/SkeletonControl.java

@@ -82,7 +82,7 @@ public class SkeletonControl extends AbstractControl implements Cloneable {
     /**
      * User wishes to use hardware skinning if available.
      */
-    private transient boolean hwSkinningDesired = false;
+    private transient boolean hwSkinningDesired = true;
     
     /**
      * Hardware skinning is currently being used.
@@ -347,11 +347,22 @@ public class SkeletonControl extends AbstractControl implements Cloneable {
 
     public Control cloneForSpatial(Spatial spatial) {
         Node clonedNode = (Node) spatial;
-        AnimControl ctrl = spatial.getControl(AnimControl.class);
         SkeletonControl clone = new SkeletonControl();
 
-        clone.skeleton = ctrl.getSkeleton();
-
+        AnimControl ctrl = spatial.getControl(AnimControl.class);
+        if (ctrl != null) {
+            // AnimControl is responsible for cloning the skeleton, not
+            // SkeletonControl.
+            clone.skeleton = ctrl.getSkeleton();
+        } else {
+            // If there's no AnimControl, create the clone ourselves.
+            clone.skeleton = new Skeleton(skeleton);
+        }
+        clone.hwSkinningDesired = this.hwSkinningDesired;
+        clone.hwSkinningEnabled = this.hwSkinningEnabled;
+        clone.hwSkinningSupported = this.hwSkinningSupported;
+        clone.hwSkinningTested = this.hwSkinningTested;
+        
         clone.setSpatial(clonedNode);
 
         // Fix attachments for the cloned node

+ 12 - 12
jme3-core/src/main/java/com/jme3/app/StatsView.java

@@ -60,7 +60,7 @@ import com.jme3.scene.control.Control;
  */
 public class StatsView extends Node implements Control {
 
-    private BitmapText[] labels;
+    private BitmapText statText;
     private Statistics statistics;
 
     private String[] statLabels;
@@ -81,20 +81,17 @@ public class StatsView extends Node implements Control {
 
         statLabels = statistics.getLabels();
         statData = new int[statLabels.length];
-        labels = new BitmapText[statLabels.length];
 
         BitmapFont font = manager.loadFont("Interface/Fonts/Console.fnt");
-        for (int i = 0; i < labels.length; i++){
-            labels[i] = new BitmapText(font);
-            labels[i].setLocalTranslation(0, labels[i].getLineHeight() * (i+1), 0);
-            attachChild(labels[i]);
-        }
+        statText = new BitmapText(font);
+        statText.setLocalTranslation(0, statText.getLineHeight() * statLabels.length, 0);
+        attachChild(statText);
 
         addControl(this);
     }
 
     public float getHeight() {
-        return labels[0].getLineHeight() * statLabels.length;
+        return statText.getLineHeight() * statLabels.length;
     }
     
     public void update(float tpf) {
@@ -103,11 +100,14 @@ public class StatsView extends Node implements Control {
             return;
             
         statistics.getData(statData);
-        for (int i = 0; i < labels.length; i++) {
-            stringBuilder.setLength(0);
-            stringBuilder.append(statLabels[i]).append(" = ").append(statData[i]);
-            labels[i].setText(stringBuilder);
+        stringBuilder.setLength(0);
+        
+        // Need to walk through it backwards, as the first label 
+        // should appear at the bottom, not the top.
+        for (int i = statLabels.length - 1; i >= 0; i--) {
+            stringBuilder.append(statLabels[i]).append(" = ").append(statData[i]).append('\n');
         }
+        statText.setText(stringBuilder);
         
         // Moved to ResetStatsState to make sure it is
         // done even if there is no StatsView or the StatsView

+ 9 - 1
jme3-core/src/main/java/com/jme3/audio/AudioNode.java

@@ -77,7 +77,7 @@ public class AudioNode extends Node implements AudioSource {
     protected transient volatile AudioSource.Status status = AudioSource.Status.Stopped;
     protected transient volatile int channel = -1;
     protected Vector3f velocity = new Vector3f();
-    protected boolean reverbEnabled = true;
+    protected boolean reverbEnabled = false;
     protected float maxDistance = 200; // 200 meters
     protected float refDistance = 10; // 10 meters
     protected Filter reverbFilter;
@@ -409,6 +409,14 @@ public class AudioNode extends Node implements AudioSource {
             play();
         }
     }
+    
+    @Override
+    public float getPlaybackTime() {
+        if (channel >= 0)
+            return getRenderer().getSourcePlaybackTime(this);
+        else
+            return 0;
+    }
 
     public Vector3f getPosition() {
         return getWorldTranslation();

+ 1 - 0
jme3-core/src/main/java/com/jme3/audio/AudioRenderer.java

@@ -59,6 +59,7 @@ public interface AudioRenderer {
 
     public void updateSourceParam(AudioSource src, AudioParam param);
     public void updateListenerParam(Listener listener, ListenerParam param);
+    public float getSourcePlaybackTime(AudioSource src);
 
     public void deleteFilter(Filter filter);
     public void deleteAudioData(AudioData ad);

+ 5 - 0
jme3-core/src/main/java/com/jme3/audio/AudioSource.java

@@ -95,6 +95,11 @@ public interface AudioSource {
      * @return the time offset in the sound sample when to start playing.
      */
     public float getTimeOffset();
+    
+    /**
+     * @return the current playback position of the source in seconds.
+     */
+    public float getPlaybackTime();
 
     /**
      * @return The velocity of the audio source.

+ 13 - 0
jme3-core/src/main/java/com/jme3/audio/AudioStream.java

@@ -54,6 +54,8 @@ public class AudioStream extends AudioData implements Closeable {
     protected boolean eof = false;
     protected int[] ids;
 
+    protected int unqueuedBuffersBytes = 0;
+    
     public AudioStream() {
         super();
     }
@@ -196,10 +198,21 @@ public class AudioStream extends AudioData implements Closeable {
         return in instanceof SeekableStream;
     }
 
+    public int getUnqueuedBufferBytes() {
+        return unqueuedBuffersBytes;
+    }
+
+    public void setUnqueuedBufferBytes(int unqueuedBuffers) {
+        this.unqueuedBuffersBytes = unqueuedBuffers;
+    }
+    
     public void setTime(float time) {
         if (in instanceof SeekableStream) {
             ((SeekableStream) in).setTime(time);
             eof = false;
+            
+            // TODO: when we actually support seeking, this will need to be properly set.
+            unqueuedBuffersBytes = 0; 
         } else {
             throw new IllegalStateException(
                     "Cannot use setTime on a stream that "

+ 60 - 0
jme3-core/src/main/java/com/jme3/audio/openal/ALAudioRenderer.java

@@ -301,6 +301,58 @@ public class ALAudioRenderer implements AudioRenderer, Runnable {
         f.clearUpdateNeeded();
     }
 
+    @Override
+    public float getSourcePlaybackTime(AudioSource src) {
+        checkDead();
+        synchronized (threadLock) {
+            if (audioDisabled) {
+                return 0;
+            }
+            
+            // See comment in updateSourceParam().
+            if (src.getChannel() < 0) {
+                return 0;
+            }
+            
+            int id = channels[src.getChannel()];
+            AudioData data = src.getAudioData();
+            int playbackOffsetBytes = 0;
+            
+            if (data instanceof AudioStream) {
+                // Because audio streams are processed in buffer chunks, 
+                // we have to compute the amount of time the stream was already
+                // been playing based on the number of buffers that were processed.
+                AudioStream stream = (AudioStream) data;
+                
+                // NOTE: the assumption is that all enqueued buffers are the same size.
+                //       this is currently enforced by fillBuffer().
+                
+                // The number of unenqueued bytes that the decoder thread
+                // keeps track of.
+                int unqueuedBytes = stream.getUnqueuedBufferBytes();
+                
+                // Additional processed buffers that the decoder thread
+                // did not unenqueue yet (it only updates 20 times per second).
+                int unqueuedBytesExtra = al.alGetSourcei(id, AL_BUFFERS_PROCESSED) * BUFFER_SIZE;
+                
+                // Total additional bytes that need to be considered.
+                playbackOffsetBytes = unqueuedBytes; // + unqueuedBytesExtra;
+            }
+            
+            // Add byte offset from source (for both streams and buffers)
+            playbackOffsetBytes += al.alGetSourcei(id, AL_BYTE_OFFSET);
+            
+            // Compute time value from bytes
+            // E.g. for 44100 source with 2 channels and 16 bits per sample:
+            //    (44100 * 2 * 16 / 8) = 176400
+            int bytesPerSecond = (data.getSampleRate() * 
+                                  data.getChannels() * 
+                                  data.getBitsPerSample() / 8);
+            
+            return (float)playbackOffsetBytes / bytesPerSecond;
+        }
+    }
+    
     public void updateSourceParam(AudioSource src, AudioParam param) {
         checkDead();
         synchronized (threadLock) {
@@ -648,6 +700,7 @@ public class ALAudioRenderer implements AudioRenderer, Runnable {
     private boolean fillStreamingSource(int sourceId, AudioStream stream, boolean looping) {
         boolean success = false;
         int processed = al.alGetSourcei(sourceId, AL_BUFFERS_PROCESSED);
+        int unqueuedBufferBytes = 0;
         
         for (int i = 0; i < processed; i++) {
             int buffer;
@@ -656,6 +709,11 @@ public class ALAudioRenderer implements AudioRenderer, Runnable {
             al.alSourceUnqueueBuffers(sourceId, 1, ib);
             buffer = ib.get(0);
             
+            // XXX: assume that reading from AudioStream always 
+            // gives BUFFER_SIZE amount of bytes! This might not always
+            // be the case...
+            unqueuedBufferBytes += BUFFER_SIZE;
+            
             boolean active = fillBuffer(stream, buffer);
             
             if (!active && !stream.isEOF()) {
@@ -682,6 +740,8 @@ public class ALAudioRenderer implements AudioRenderer, Runnable {
                 break;
             }
         }
+        
+        stream.setUnqueuedBufferBytes(stream.getUnqueuedBufferBytes() + unqueuedBufferBytes);
 
         return success;
     }

+ 2 - 6
jme3-core/src/main/java/com/jme3/export/JmeExporter.java

@@ -46,22 +46,18 @@ public interface JmeExporter {
      * 
      * @param object The savable to export
      * @param f The output stream
-     * @return Always returns true. If an error occurs during export, 
-     * an exception is thrown
      * @throws IOException If an io exception occurs during export
      */
-    public boolean save(Savable object, OutputStream f) throws IOException;
+    public void save(Savable object, OutputStream f) throws IOException;
     
     /**
      * Export the {@link Savable} to a file.
      * 
      * @param object The savable to export
      * @param f The file to export to
-     * @return Always returns true. If an error occurs during export, 
-     * an exception is thrown
      * @throws IOException If an io exception occurs during export
      */
-    public boolean save(Savable object, File f) throws IOException;
+    public void save(Savable object, File f) throws IOException;
     
     /**
      * Returns the {@link OutputCapsule} for the given savable object.

+ 18 - 18
jme3-core/src/main/java/com/jme3/math/ColorRGBA.java

@@ -607,28 +607,28 @@ public final class ColorRGBA implements Savable, Cloneable, java.io.Serializable
     }
     
     /**
-     * Get the color in sRGB color space as a Vector4f
+     * Get the color in sRGB color space as a <code>ColorRGBA</code>.
      * 
      * Note that linear values stored in the ColorRGBA will be gamma corrected 
-     * and returned as a Vector4f
-     * the x atribute will be fed with the r channel in sRGB space
-     * the y atribute will be fed with the g channel in sRGB space
-     * the z atribute will be fed with the b channel in sRGB space
-     * the w atribute will be fed with the a channel
+     * and returned as a ColorRGBA.
      * 
-     * Note that no correction will be performed on the alpha channel as it's 
-     * conventionnally doesn't represent a color itself
+     * The x attribute will be fed with the r channel in sRGB space.
+     * The y attribute will be fed with the g channel in sRGB space.
+     * The z attribute will be fed with the b channel in sRGB space.
+     * The w attribute will be fed with the a channel.
      * 
-     * @return the color in sRGB color space as a Vector4f
-     */
-    public Vector4f getAsSrgb(){
-        Vector4f srgb = new Vector4f();
-        float invGama = 1f/GAMMA;
-        srgb.x = (float)Math.pow(r, invGama);
-        srgb.y = (float)Math.pow(g, invGama);
-        srgb.z = (float)Math.pow(b, invGama);
-        srgb.w = a;
-        
+     * Note that no correction will be performed on the alpha channel as it 
+     * conventionally doesn't represent a color itself.
+     * 
+     * @return the color in sRGB color space as a ColorRGBA.
+     */
+    public ColorRGBA getAsSrgb() {
+        ColorRGBA srgb = new ColorRGBA();
+        float invGama = 1f / GAMMA;
+        srgb.r = (float) Math.pow(r, invGama);
+        srgb.g = (float) Math.pow(g, invGama);
+        srgb.b = (float) Math.pow(b, invGama);
+        srgb.a = a;
         return srgb;
     }
     

+ 19 - 0
jme3-core/src/main/java/com/jme3/math/FastMath.java

@@ -902,6 +902,25 @@ final public class FastMath {
         return clamp(input, 0f, 1f);
     }
 
+    /**
+     * Determine if two floats are approximately equal.
+     * This takes into account the magnitude of the floats, since
+     * large numbers will have larger differences be close to each other.
+     * 
+     * Should return true for a=100000, b=100001, but false for a=10000, b=10001.
+     * 
+     * @param a The first float to compare
+     * @param b The second float to compare
+     * @return True if a and b are approximately equal, false otherwise.
+     */
+    public static boolean approximateEquals(float a, float b) {
+        if (a == b) {
+            return true;
+        } else {
+            return (abs(a - b) / Math.max(abs(a), abs(b))) <= 0.00001f;
+        }
+    }
+    
     /**
      * Converts a single precision (32 bit) floating point value
      * into half precision (16 bit).

+ 20 - 0
jme3-core/src/main/java/com/jme3/math/Transform.java

@@ -259,6 +259,26 @@ public final class Transform implements Savable, Cloneable, java.io.Serializable
         return store;
     }
 
+    public Matrix4f toTransformMatrix() {
+        Matrix4f trans = new Matrix4f();
+        trans.setTranslation(translation);
+        trans.setRotationQuaternion(rot);
+        trans.setScale(scale);
+        return trans;
+    }
+    
+    public void fromTransformMatrix(Matrix4f mat) {
+        translation.set(mat.toTranslationVector());
+        rot.set(mat.toRotationQuat());
+        scale.set(mat.toScaleVector());
+    }
+    
+    public Transform invert() {
+        Transform t = new Transform();
+        t.fromTransformMatrix(toTransformMatrix().invertLocal());
+        return t;
+    }
+    
     /**
      * Loads the identity.  Equal to translation=0,0,0 scale=1,1,1 rot=0,0,0,1.
      */

+ 13 - 1
jme3-core/src/main/java/com/jme3/renderer/Caps.java

@@ -337,7 +337,19 @@ public enum Caps {
      * <p>
      * Improves the quality of environment mapping.
      */
-    SeamlessCubemap;
+    SeamlessCubemap,
+    
+    /**
+     * Running with OpenGL 3.2+ core profile.
+     * 
+     * Compatibility features will not be available.
+     */
+    CoreProfile,
+    
+    /**
+     * GPU can provide and accept binary shaders.
+     */
+    BinaryShader;
 
     /**
      * Returns true if given the renderer capabilities, the texture

+ 2 - 1
jme3-core/src/main/java/com/jme3/renderer/opengl/GL.java

@@ -32,7 +32,6 @@
 package com.jme3.renderer.opengl;
 
 import java.nio.ByteBuffer;
-import java.nio.DoubleBuffer;
 import java.nio.FloatBuffer;
 import java.nio.IntBuffer;
 import java.nio.ShortBuffer;
@@ -178,6 +177,8 @@ public interface GL {
 	public static final int GL_VERTEX_SHADER = 0x8B31;
 	public static final int GL_ZERO = 0x0;
 
+        public void resetStats();
+        
 	public void glActiveTexture(int texture);
 	public void glAttachShader(int program, int shader);
 	public void glBindBuffer(int target, int buffer);

+ 7 - 3
jme3-core/src/main/java/com/jme3/renderer/opengl/GL3.java

@@ -35,14 +35,18 @@ import java.nio.IntBuffer;
 
 /**
  * GL functions only available on vanilla desktop OpenGL 3.0.
- * 
+ *
  * @author Kirill Vainer
  */
 public interface GL3 extends GL2 {
-    
+
     public static final int GL_DEPTH_STENCIL_ATTACHMENT = 0x821A;
-    public static final int GL_GEOMETRY_SHADER=0x8DD9;
+    public static final int GL_GEOMETRY_SHADER = 0x8DD9;
+    public static final int GL_NUM_EXTENSIONS = 0x821D;
+    
     public void glBindFragDataLocation(int param1, int param2, String param3); /// GL3+
     public void glBindVertexArray(int param1); /// GL3+
+    public void glDeleteVertexArrays(IntBuffer arrays); /// GL3+
     public void glGenVertexArrays(IntBuffer param1); /// GL3+
+    public String glGetString(int param1, int param2); /// GL3+
 }

+ 23 - 3
jme3-core/src/main/java/com/jme3/renderer/opengl/GLDebugDesktop.java

@@ -3,15 +3,17 @@ package com.jme3.renderer.opengl;
 import java.nio.ByteBuffer;
 import java.nio.IntBuffer;
 
-public class GLDebugDesktop extends GLDebugES implements GL2, GL3 {
+public class GLDebugDesktop extends GLDebugES implements GL2, GL3, GL4 {
 
     private final GL2 gl2;
     private final GL3 gl3;
+    private final GL4 gl4;
     
-    public GLDebugDesktop(GL gl, GLFbo glfbo) {
-        super(gl, glfbo);
+    public GLDebugDesktop(GL gl, GLExt glext, GLFbo glfbo) {
+        super(gl, glext, glfbo);
         this.gl2 = gl instanceof GL2 ? (GL2) gl : null;
         this.gl3 = gl instanceof GL3 ? (GL3) gl : null;
+        this.gl4 = gl instanceof GL4 ? (GL4) gl : null;
     }
     
     public void glAlphaFunc(int func, float ref) {
@@ -73,5 +75,23 @@ public class GLDebugDesktop extends GLDebugES implements GL2, GL3 {
         gl3.glGenVertexArrays(param1);
         checkError();
     }
+    
+    @Override
+    public String glGetString(int param1, int param2) {
+        String result = gl3.glGetString(param1, param2);
+        checkError();
+        return result;
+    }
+
+    @Override
+    public void glDeleteVertexArrays(IntBuffer arrays) {
+        gl3.glDeleteVertexArrays(arrays);
+        checkError();
+    }
 
+    @Override
+    public void glPatchParameter(int count) {
+        gl4.glPatchParameter(count);
+        checkError();
+    }
 }

+ 8 - 6
jme3-core/src/main/java/com/jme3/renderer/opengl/GLDebugES.java

@@ -10,14 +10,16 @@ public class GLDebugES extends GLDebug implements GL, GLFbo, GLExt {
     private final GLFbo glfbo;
     private final GLExt glext;
 
-    public GLDebugES(GL gl, GLFbo glfbo) {
+    public GLDebugES(GL gl, GLExt glext, GLFbo glfbo) {
         this.gl = gl;
-//        this.gl2 = gl instanceof GL2 ? (GL2) gl : null;
-//        this.gl3 = gl instanceof GL3 ? (GL3) gl : null;
+        this.glext = glext;
         this.glfbo = glfbo;
-        this.glext = glfbo instanceof GLExt ? (GLExt) glfbo : null;
     }
 
+    public void resetStats() {
+        gl.resetStats();
+    }
+    
     public void glActiveTexture(int texture) {
         gl.glActiveTexture(texture);
         checkError();
@@ -478,7 +480,7 @@ public class GLDebugES extends GLDebug implements GL, GLFbo, GLExt {
     }
 
     public void glBlitFramebufferEXT(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, int mask, int filter) {
-        glext.glBlitFramebufferEXT(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
+        glfbo.glBlitFramebufferEXT(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
         checkError();
     }
 
@@ -525,7 +527,7 @@ public class GLDebugES extends GLDebug implements GL, GLFbo, GLExt {
     }
 
     public void glRenderbufferStorageMultisampleEXT(int target, int samples, int internalformat, int width, int height) {
-        glext.glRenderbufferStorageMultisampleEXT(target, samples, internalformat, width, height);
+        glfbo.glRenderbufferStorageMultisampleEXT(target, samples, internalformat, width, height);
         checkError();
     }
 

+ 1 - 3
jme3-core/src/main/java/com/jme3/renderer/opengl/GLExt.java

@@ -41,7 +41,7 @@ import java.nio.IntBuffer;
  * 
  * @author Kirill Vainer
  */
-public interface GLExt extends GLFbo {
+public interface GLExt {
 
         public static final int GL_ALREADY_SIGNALED = 0x911A;
 	public static final int GL_COMPRESSED_RGB8_ETC2 = 0x9274;
@@ -100,7 +100,6 @@ public interface GLExt extends GLFbo {
 	public static final int GL_UNSIGNED_INT_5_9_9_9_REV_EXT = 0x8C3E;
         public static final int GL_WAIT_FAILED = 0x911D;
 
-	public void glBlitFramebufferEXT(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, int mask, int filter);
         public void glBufferData(int target, IntBuffer data, int usage);
         public void glBufferSubData(int target, long offset, IntBuffer data);
         public int glClientWaitSync(Object sync, int flags, long timeout);
@@ -110,7 +109,6 @@ public interface GLExt extends GLFbo {
 	public void glDrawElementsInstancedARB(int mode, int indices_count, int type, long indices_buffer_offset, int primcount);
         public Object glFenceSync(int condition, int flags);
 	public void glGetMultisample(int pname, int index, FloatBuffer val);
-        public void glRenderbufferStorageMultisampleEXT(int target, int samples, int internalformat, int width, int height);
 	public void glTexImage2DMultisample(int target, int samples, int internalformat, int width, int height, boolean fixedsamplelocations);
 	public void glVertexAttribDivisorARB(int index, int divisor);
 }

+ 2 - 1
jme3-core/src/main/java/com/jme3/renderer/opengl/GLFbo.java

@@ -83,6 +83,7 @@ public interface GLFbo {
     
     public void glBindFramebufferEXT(int param1, int param2);
     public void glBindRenderbufferEXT(int param1, int param2);
+    public void glBlitFramebufferEXT(int srcX0, int srcY0, int srcX1, int srcY1, int dstX0, int dstY0, int dstX1, int dstY1, int mask, int filter);
     public int glCheckFramebufferStatusEXT(int param1);
     public void glDeleteFramebuffersEXT(IntBuffer param1);
     public void glDeleteRenderbuffersEXT(IntBuffer param1);
@@ -92,5 +93,5 @@ public interface GLFbo {
     public void glGenRenderbuffersEXT(IntBuffer param1);
     public void glGenerateMipmapEXT(int param1);
     public void glRenderbufferStorageEXT(int param1, int param2, int param3, int param4);
-    
+    public void glRenderbufferStorageMultisampleEXT(int target, int samples, int internalformat, int width, int height);
 }

+ 24 - 14
jme3-core/src/main/java/com/jme3/renderer/opengl/GLImageFormats.java

@@ -89,9 +89,11 @@ public final class GLImageFormats {
         GLImageFormat[][] formatToGL = new GLImageFormat[2][Image.Format.values().length];
         
         if (caps.contains(Caps.OpenGL20)) {
-            format(formatToGL, Format.Alpha8,           GL2.GL_ALPHA8,            GL.GL_ALPHA,           GL.GL_UNSIGNED_BYTE);
-            format(formatToGL, Format.Luminance8,       GL2.GL_LUMINANCE8,        GL.GL_LUMINANCE,       GL.GL_UNSIGNED_BYTE);
-            format(formatToGL, Format.Luminance8Alpha8, GL2.GL_LUMINANCE8_ALPHA8, GL.GL_LUMINANCE_ALPHA, GL.GL_UNSIGNED_BYTE);
+            if (!caps.contains(Caps.CoreProfile)) {
+                format(formatToGL, Format.Alpha8,           GL2.GL_ALPHA8,            GL.GL_ALPHA,           GL.GL_UNSIGNED_BYTE);
+                format(formatToGL, Format.Luminance8,       GL2.GL_LUMINANCE8,        GL.GL_LUMINANCE,       GL.GL_UNSIGNED_BYTE);
+                format(formatToGL, Format.Luminance8Alpha8, GL2.GL_LUMINANCE8_ALPHA8, GL.GL_LUMINANCE_ALPHA, GL.GL_UNSIGNED_BYTE);
+            }
             format(formatToGL, Format.RGB8,             GL2.GL_RGB8,              GL.GL_RGB,             GL.GL_UNSIGNED_BYTE);
             format(formatToGL, Format.RGBA8,            GLExt.GL_RGBA8,           GL.GL_RGBA,            GL.GL_UNSIGNED_BYTE);
             format(formatToGL, Format.RGB565,           GL2.GL_RGB8,              GL.GL_RGB,             GL.GL_UNSIGNED_SHORT_5_6_5);
@@ -108,8 +110,10 @@ public final class GLImageFormats {
                 formatSrgb(formatToGL, Format.RGB565,           GLExt.GL_SRGB8_EXT,              GL.GL_RGB,             GL.GL_UNSIGNED_SHORT_5_6_5);
                 formatSrgb(formatToGL, Format.RGB5A1,           GLExt.GL_SRGB8_ALPHA8_EXT,       GL.GL_RGBA,            GL.GL_UNSIGNED_SHORT_5_5_5_1);
                 formatSrgb(formatToGL, Format.RGBA8,            GLExt.GL_SRGB8_ALPHA8_EXT,       GL.GL_RGBA,            GL.GL_UNSIGNED_BYTE);
-                formatSrgb(formatToGL, Format.Luminance8,       GLExt.GL_SLUMINANCE8_EXT,        GL.GL_LUMINANCE,       GL.GL_UNSIGNED_BYTE);
-                formatSrgb(formatToGL, Format.Luminance8Alpha8, GLExt.GL_SLUMINANCE8_ALPHA8_EXT, GL.GL_LUMINANCE_ALPHA, GL.GL_UNSIGNED_BYTE);
+                if (!caps.contains(Caps.CoreProfile)) {
+                    formatSrgb(formatToGL, Format.Luminance8,       GLExt.GL_SLUMINANCE8_EXT,        GL.GL_LUMINANCE,       GL.GL_UNSIGNED_BYTE);
+                    formatSrgb(formatToGL, Format.Luminance8Alpha8, GLExt.GL_SLUMINANCE8_ALPHA8_EXT, GL.GL_LUMINANCE_ALPHA, GL.GL_UNSIGNED_BYTE);
+                }
                 formatSrgb(formatToGL, Format.BGR8,             GLExt.GL_SRGB8_EXT,              GL2.GL_BGR,            GL.GL_UNSIGNED_BYTE);
                 formatSrgb(formatToGL, Format.ABGR8,            GLExt.GL_SRGB8_ALPHA8_EXT,       GL.GL_RGBA,            GL2.GL_UNSIGNED_INT_8_8_8_8);
                 formatSrgb(formatToGL, Format.ARGB8,            GLExt.GL_SRGB8_ALPHA8_EXT,       GL2.GL_BGRA,           GL2.GL_UNSIGNED_INT_8_8_8_8);
@@ -124,16 +128,20 @@ public final class GLImageFormats {
             }
         } else if (caps.contains(Caps.Rgba8)) {
             // A more limited form of 32-bit RGBA. Only GL_RGBA8 is available.
-            format(formatToGL, Format.Alpha8,           GLExt.GL_RGBA8, GL.GL_ALPHA,           GL.GL_UNSIGNED_BYTE);
-            format(formatToGL, Format.Luminance8,       GLExt.GL_RGBA8, GL.GL_LUMINANCE,       GL.GL_UNSIGNED_BYTE);
-            format(formatToGL, Format.Luminance8Alpha8, GLExt.GL_RGBA8, GL.GL_LUMINANCE_ALPHA, GL.GL_UNSIGNED_BYTE);
+            if (!caps.contains(Caps.CoreProfile)) {
+                format(formatToGL, Format.Alpha8,           GLExt.GL_RGBA8, GL.GL_ALPHA,           GL.GL_UNSIGNED_BYTE);
+                format(formatToGL, Format.Luminance8,       GLExt.GL_RGBA8, GL.GL_LUMINANCE,       GL.GL_UNSIGNED_BYTE);
+                format(formatToGL, Format.Luminance8Alpha8, GLExt.GL_RGBA8, GL.GL_LUMINANCE_ALPHA, GL.GL_UNSIGNED_BYTE);
+            }
             format(formatToGL, Format.RGB8,             GLExt.GL_RGBA8, GL.GL_RGB,             GL.GL_UNSIGNED_BYTE);
             format(formatToGL, Format.RGBA8,            GLExt.GL_RGBA8, GL.GL_RGBA,            GL.GL_UNSIGNED_BYTE);
         } else {
             // Actually, the internal format isn't used for OpenGL ES 2! This is the same as the above..
-            format(formatToGL, Format.Alpha8,           GL.GL_RGBA4,   GL.GL_ALPHA,           GL.GL_UNSIGNED_BYTE);
-            format(formatToGL, Format.Luminance8,       GL.GL_RGB565,  GL.GL_LUMINANCE,       GL.GL_UNSIGNED_BYTE);
-            format(formatToGL, Format.Luminance8Alpha8, GL.GL_RGBA4,   GL.GL_LUMINANCE_ALPHA, GL.GL_UNSIGNED_BYTE);
+            if (!caps.contains(Caps.CoreProfile)) {
+                format(formatToGL, Format.Alpha8,           GL.GL_RGBA4,   GL.GL_ALPHA,           GL.GL_UNSIGNED_BYTE);
+                format(formatToGL, Format.Luminance8,       GL.GL_RGB565,  GL.GL_LUMINANCE,       GL.GL_UNSIGNED_BYTE);
+                format(formatToGL, Format.Luminance8Alpha8, GL.GL_RGBA4,   GL.GL_LUMINANCE_ALPHA, GL.GL_UNSIGNED_BYTE);
+            }
             format(formatToGL, Format.RGB8,             GL.GL_RGB565,  GL.GL_RGB,             GL.GL_UNSIGNED_BYTE);
             format(formatToGL, Format.RGBA8,            GL.GL_RGBA4,   GL.GL_RGBA,            GL.GL_UNSIGNED_BYTE);
         }
@@ -145,9 +153,11 @@ public final class GLImageFormats {
         format(formatToGL, Format.RGB5A1, GL.GL_RGB5_A1, GL.GL_RGBA, GL.GL_UNSIGNED_SHORT_5_5_5_1);
         
         if (caps.contains(Caps.FloatTexture)) {
-            format(formatToGL, Format.Luminance16F,         GLExt.GL_LUMINANCE16F_ARB,       GL.GL_LUMINANCE,       GLExt.GL_HALF_FLOAT_ARB);
-            format(formatToGL, Format.Luminance32F,         GLExt.GL_LUMINANCE32F_ARB,       GL.GL_LUMINANCE,       GL.GL_FLOAT);
-            format(formatToGL, Format.Luminance16FAlpha16F, GLExt.GL_LUMINANCE_ALPHA16F_ARB, GL.GL_LUMINANCE_ALPHA, GLExt.GL_HALF_FLOAT_ARB);
+            if (!caps.contains(Caps.CoreProfile)) {
+                format(formatToGL, Format.Luminance16F,         GLExt.GL_LUMINANCE16F_ARB,       GL.GL_LUMINANCE,       GLExt.GL_HALF_FLOAT_ARB);
+                format(formatToGL, Format.Luminance32F,         GLExt.GL_LUMINANCE32F_ARB,       GL.GL_LUMINANCE,       GL.GL_FLOAT);
+                format(formatToGL, Format.Luminance16FAlpha16F, GLExt.GL_LUMINANCE_ALPHA16F_ARB, GL.GL_LUMINANCE_ALPHA, GLExt.GL_HALF_FLOAT_ARB);
+            }
             format(formatToGL, Format.RGB16F,               GLExt.GL_RGB16F_ARB,             GL.GL_RGB,             GLExt.GL_HALF_FLOAT_ARB);
             format(formatToGL, Format.RGB32F,               GLExt.GL_RGB32F_ARB,             GL.GL_RGB,             GL.GL_FLOAT);
             format(formatToGL, Format.RGBA16F,              GLExt.GL_RGBA16F_ARB,            GL.GL_RGBA,            GLExt.GL_HALF_FLOAT_ARB);

+ 111 - 98
jme3-core/src/main/java/com/jme3/renderer/opengl/GLRenderer.java

@@ -54,8 +54,10 @@ import com.jme3.texture.Texture;
 import com.jme3.texture.Texture.WrapAxis;
 import com.jme3.util.BufferUtils;
 import com.jme3.util.ListMap;
+import com.jme3.util.MipMapGenerator;
 import com.jme3.util.NativeObjectManager;
 import java.nio.*;
+import java.util.Arrays;
 import java.util.EnumMap;
 import java.util.EnumSet;
 import java.util.HashSet;
@@ -112,13 +114,13 @@ public class GLRenderer implements Renderer {
     private final GLFbo glfbo;
     private final TextureUtil texUtil;
     
-    public GLRenderer(GL gl, GLFbo glfbo) {
+    public GLRenderer(GL gl, GLExt glext, GLFbo glfbo) {
         this.gl = gl;
         this.gl2 = gl instanceof GL2 ? (GL2)gl : null;
         this.gl3 = gl instanceof GL3 ? (GL3)gl : null;
         this.gl4 = gl instanceof GL4 ? (GL4)gl : null;
         this.glfbo = glfbo;
-        this.glext = glfbo instanceof GLExt ? (GLExt)glfbo : null;
+        this.glext = glext;
         this.texUtil = new TextureUtil(gl, gl2, glext, context);
     }
 
@@ -137,10 +139,19 @@ public class GLRenderer implements Renderer {
         return limits;
     }
 
-    private static HashSet<String> loadExtensions(String extensions) {
+    private HashSet<String> loadExtensions() {
         HashSet<String> extensionSet = new HashSet<String>(64);
-        for (String extension : extensions.split(" ")) {
-            extensionSet.add(extension);
+        if (caps.contains(Caps.OpenGL30)) {
+            // If OpenGL3+ is available, use the non-deprecated way
+            // of getting supported extensions.
+            gl3.glGetInteger(GL3.GL_NUM_EXTENSIONS, intBuf16);
+            int extensionCount = intBuf16.get(0);
+            for (int i = 0; i < extensionCount; i++) {
+                String extension = gl3.glGetString(GL.GL_EXTENSIONS, i);
+                extensionSet.add(extension);
+            }
+        } else {
+            extensionSet.addAll(Arrays.asList(gl.glGetString(GL.GL_EXTENSIONS).split(" ")));
         }
         return extensionSet;
     }
@@ -185,10 +196,12 @@ public class GLRenderer implements Renderer {
                         caps.add(Caps.OpenGL31);
                         if (oglVer >= 320) {
                             caps.add(Caps.OpenGL32);
-                        }if(oglVer>=330){
+                        }
+                        if (oglVer >= 330) {
                             caps.add(Caps.OpenGL33);
                             caps.add(Caps.GeometryShader);
-                        }if(oglVer>=400){
+                        }
+                        if (oglVer >= 400) {
                             caps.add(Caps.OpenGL40);
                             caps.add(Caps.TesselationShader);
                         }
@@ -243,7 +256,7 @@ public class GLRenderer implements Renderer {
     }
     
     private void loadCapabilitiesCommon() {
-        extensions = loadExtensions(gl.glGetString(GL.GL_EXTENSIONS));
+        extensions = loadExtensions();
         
         limits.put(Limits.VertexTextureUnits, getInteger(GL.GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS));
         if (limits.get(Limits.VertexTextureUnits) > 0) {
@@ -251,7 +264,7 @@ public class GLRenderer implements Renderer {
         }
 
         limits.put(Limits.FragmentTextureUnits, getInteger(GL.GL_MAX_TEXTURE_IMAGE_UNITS));
-
+        
 //        gl.glGetInteger(GL.GL_MAX_VERTEX_UNIFORM_COMPONENTS, intBuf16);
 //        vertexUniforms = intBuf16.get(0);
 //        logger.log(Level.FINER, "Vertex Uniforms: {0}", vertexUniforms);
@@ -279,7 +292,7 @@ public class GLRenderer implements Renderer {
         
         // == texture format extensions ==
         
-        boolean hasFloatTexture = false;
+        boolean hasFloatTexture;
 
         hasFloatTexture = hasExtension("GL_OES_texture_half_float") &&
                           hasExtension("GL_OES_texture_float");
@@ -375,11 +388,11 @@ public class GLRenderer implements Renderer {
             caps.add(Caps.TextureFilterAnisotropic);
         }
 
-        if (hasExtension("GL_EXT_framebuffer_object")) {
+        if (hasExtension("GL_EXT_framebuffer_object") || gl3 != null) {
             caps.add(Caps.FrameBuffer);
             
-            limits.put(Limits.RenderBufferSize, getInteger(GLExt.GL_MAX_RENDERBUFFER_SIZE_EXT));
-            limits.put(Limits.FrameBufferAttachments, getInteger(GLExt.GL_MAX_COLOR_ATTACHMENTS_EXT));
+            limits.put(Limits.RenderBufferSize, getInteger(GLFbo.GL_MAX_RENDERBUFFER_SIZE_EXT));
+            limits.put(Limits.FrameBufferAttachments, getInteger(GLFbo.GL_MAX_COLOR_ATTACHMENTS_EXT));
             
             if (hasExtension("GL_EXT_framebuffer_blit")) {
                 caps.add(Caps.FrameBufferBlit);
@@ -434,21 +447,30 @@ public class GLRenderer implements Renderer {
             caps.add(Caps.SeamlessCubemap);
         }
         
-//        if (hasExtension("GL_ARB_get_program_binary")) {
-//            int binaryFormats = getInteger(GLExt.GL_NUM_PROGRAM_BINARY_FORMATS);
-//        }
+        if (caps.contains(Caps.OpenGL32) && !hasExtension("GL_ARB_compatibility")) {
+            caps.add(Caps.CoreProfile);
+        }
+        
+        if (hasExtension("GL_ARB_get_program_binary")) {
+            int binaryFormats = getInteger(GLExt.GL_NUM_PROGRAM_BINARY_FORMATS);
+            if (binaryFormats > 0) {
+                caps.add(Caps.BinaryShader);
+            }
+        }
         
         // Print context information
         logger.log(Level.INFO, "OpenGL Renderer Information\n" +
                                " * Vendor: {0}\n" +
                                " * Renderer: {1}\n" +
                                " * OpenGL Version: {2}\n" +
-                               " * GLSL Version: {3}",
+                               " * GLSL Version: {3}\n" +
+                               " * Profile: {4}",
                                new Object[]{ 
                                    gl.glGetString(GL.GL_VENDOR), 
                                    gl.glGetString(GL.GL_RENDERER),
                                    gl.glGetString(GL.GL_VERSION),
-                                   gl.glGetString(GL.GL_SHADING_LANGUAGE_VERSION)
+                                   gl.glGetString(GL.GL_SHADING_LANGUAGE_VERSION),
+                                   caps.contains(Caps.CoreProfile) ? "Core" : "Compatibility"
                                });
         
         // Print capabilities (if fine logging is enabled)
@@ -491,6 +513,20 @@ public class GLRenderer implements Renderer {
         
         // Initialize default state..
         gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
+        
+        if (caps.contains(Caps.CoreProfile)) {
+            // Core Profile requires VAO to be bound.
+            gl3.glGenVertexArrays(intBuf16);
+            int vaoId = intBuf16.get(0);
+            gl3.glBindVertexArray(vaoId);
+        } 
+        if (gl2 != null) {
+            gl2.glEnable(GL2.GL_VERTEX_PROGRAM_POINT_SIZE);
+            if (!caps.contains(Caps.CoreProfile)) {
+                gl2.glEnable(GL2.GL_POINT_SPRITE);
+                context.pointSprite = true;
+            }
+        }
     }
 
     public void invalidateState() {
@@ -610,31 +646,6 @@ public class GLRenderer implements Renderer {
             context.colorWriteEnabled = false;
         }
 
-        if (gl2 != null) {
-            if (state.isPointSprite() && !context.pointSprite) {
-                // Only enable/disable sprite
-                if (context.boundTextures[0] != null) {
-                    if (context.boundTextureUnit != 0) {
-                        gl.glActiveTexture(GL.GL_TEXTURE0);
-                        context.boundTextureUnit = 0;
-                    }
-                    gl2.glEnable(GL2.GL_POINT_SPRITE);
-                    gl2.glEnable(GL2.GL_VERTEX_PROGRAM_POINT_SIZE);
-                }
-                context.pointSprite = true;
-            } else if (!state.isPointSprite() && context.pointSprite) {
-                if (context.boundTextures[0] != null) {
-                    if (context.boundTextureUnit != 0) {
-                        gl.glActiveTexture(GL.GL_TEXTURE0);
-                        context.boundTextureUnit = 0;
-                    }
-                    gl2.glDisable(GL2.GL_POINT_SPRITE);
-                    gl2.glDisable(GL2.GL_VERTEX_PROGRAM_POINT_SIZE);
-                    context.pointSprite = false;
-                }
-            }
-        }
-
         if (state.isPolyOffset()) {
             if (!context.polyOffsetEnabled) {
                 gl.glEnable(GL.GL_POLYGON_OFFSET_FILL);
@@ -704,9 +715,6 @@ public class GLRenderer implements Renderer {
                     case AlphaAdditive:
                         gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
                         break;
-                    case Color:
-                        gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_COLOR);
-                        break;
                     case Alpha:
                         gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
                         break;
@@ -719,6 +727,7 @@ public class GLRenderer implements Renderer {
                     case ModulateX2:
                         gl.glBlendFunc(GL.GL_DST_COLOR, GL.GL_SRC_COLOR);
                         break;
+                    case Color:
                     case Screen:
                         gl.glBlendFunc(GL.GL_ONE, GL.GL_ONE_MINUS_SRC_COLOR);
                         break;       
@@ -862,6 +871,7 @@ public class GLRenderer implements Renderer {
 
     public void postFrame() {
         objManager.deleteUnused(this);
+        gl.resetStats();
     }
 
     /*********************************************************************\
@@ -1290,24 +1300,24 @@ public class GLRenderer implements Renderer {
             }
 
             if (src == null) {
-                glfbo.glBindFramebufferEXT(GLExt.GL_READ_FRAMEBUFFER_EXT, 0);
+                glfbo.glBindFramebufferEXT(GLFbo.GL_READ_FRAMEBUFFER_EXT, 0);
                 srcX0 = vpX;
                 srcY0 = vpY;
                 srcX1 = vpX + vpW;
                 srcY1 = vpY + vpH;
             } else {
-                glfbo.glBindFramebufferEXT(GLExt.GL_READ_FRAMEBUFFER_EXT, src.getId());
+                glfbo.glBindFramebufferEXT(GLFbo.GL_READ_FRAMEBUFFER_EXT, src.getId());
                 srcX1 = src.getWidth();
                 srcY1 = src.getHeight();
             }
             if (dst == null) {
-                glfbo.glBindFramebufferEXT(GLExt.GL_DRAW_FRAMEBUFFER_EXT, 0);
+                glfbo.glBindFramebufferEXT(GLFbo.GL_DRAW_FRAMEBUFFER_EXT, 0);
                 dstX0 = vpX;
                 dstY0 = vpY;
                 dstX1 = vpX + vpW;
                 dstY1 = vpY + vpH;
             } else {
-                glfbo.glBindFramebufferEXT(GLExt.GL_DRAW_FRAMEBUFFER_EXT, dst.getId());
+                glfbo.glBindFramebufferEXT(GLFbo.GL_DRAW_FRAMEBUFFER_EXT, dst.getId());
                 dstX1 = dst.getWidth();
                 dstY1 = dst.getHeight();
             }
@@ -1315,12 +1325,12 @@ public class GLRenderer implements Renderer {
             if (copyDepth) {
                 mask |= GL.GL_DEPTH_BUFFER_BIT;
             }
-            glext.glBlitFramebufferEXT(srcX0, srcY0, srcX1, srcY1,
+            glfbo.glBlitFramebufferEXT(srcX0, srcY0, srcX1, srcY1,
                     dstX0, dstY0, dstX1, dstY1, mask,
                     GL.GL_NEAREST);
 
 
-            glfbo.glBindFramebufferEXT(GLExt.GL_FRAMEBUFFER_EXT, prevFBO);
+            glfbo.glBindFramebufferEXT(GLFbo.GL_FRAMEBUFFER_EXT, prevFBO);
         } else {
             throw new RendererException("Framebuffer blitting not supported by the video hardware");
         }
@@ -1366,7 +1376,7 @@ public class GLRenderer implements Renderer {
         }
 
         if (context.boundRB != id) {
-            glfbo.glBindRenderbufferEXT(GLExt.GL_RENDERBUFFER_EXT, id);
+            glfbo.glBindRenderbufferEXT(GLFbo.GL_RENDERBUFFER_EXT, id);
             context.boundRB = id;
         }
 
@@ -1384,13 +1394,13 @@ public class GLRenderer implements Renderer {
             if (maxSamples < samples) {
                 samples = maxSamples;
             }
-            glext.glRenderbufferStorageMultisampleEXT(GLExt.GL_RENDERBUFFER_EXT,
+            glfbo.glRenderbufferStorageMultisampleEXT(GLFbo.GL_RENDERBUFFER_EXT,
                     samples,
                     glFmt.internalFormat,
                     fb.getWidth(),
                     fb.getHeight());
         } else {
-            glfbo.glRenderbufferStorageEXT(GLExt.GL_RENDERBUFFER_EXT,
+            glfbo.glRenderbufferStorageEXT(GLFbo.GL_RENDERBUFFER_EXT,
                     glFmt.internalFormat,
                     fb.getWidth(),
                     fb.getHeight());
@@ -1400,7 +1410,7 @@ public class GLRenderer implements Renderer {
     private int convertAttachmentSlot(int attachmentSlot) {
         // can also add support for stencil here
         if (attachmentSlot == FrameBuffer.SLOT_DEPTH) {
-            return GLExt.GL_DEPTH_ATTACHMENT_EXT;
+            return GLFbo.GL_DEPTH_ATTACHMENT_EXT;
         } else if (attachmentSlot == FrameBuffer.SLOT_DEPTH_STENCIL) {
             // NOTE: Using depth stencil format requires GL3, this is already
             // checked via render caps.
@@ -1409,7 +1419,7 @@ public class GLRenderer implements Renderer {
             throw new UnsupportedOperationException("Invalid FBO attachment slot: " + attachmentSlot);
         }
         
-        return GLExt.GL_COLOR_ATTACHMENT0_EXT + attachmentSlot;
+        return GLFbo.GL_COLOR_ATTACHMENT0_EXT + attachmentSlot;
     }
 
     public void updateRenderTexture(FrameBuffer fb, RenderBuffer rb) {
@@ -1419,7 +1429,7 @@ public class GLRenderer implements Renderer {
             // Check NPOT requirements
             checkNonPowerOfTwo(tex);
             
-            updateTexImageData(image, tex.getType(), 0);
+            updateTexImageData(image, tex.getType(), 0, false);
 
             // NOTE: For depth textures, sets nearest/no-mips mode
             // Required to fix "framebuffer unsupported"
@@ -1427,7 +1437,7 @@ public class GLRenderer implements Renderer {
             setupTextureParams(tex);
         }
 
-        glfbo.glFramebufferTexture2DEXT(GLExt.GL_FRAMEBUFFER_EXT,
+        glfbo.glFramebufferTexture2DEXT(GLFbo.GL_FRAMEBUFFER_EXT,
                 convertAttachmentSlot(rb.getSlot()),
                 convertTextureType(tex.getType(), image.getMultiSamples(), rb.getFace()),
                 image.getId(),
@@ -1445,9 +1455,9 @@ public class GLRenderer implements Renderer {
             updateRenderTexture(fb, rb);
         }
         if (needAttach) {
-            glfbo.glFramebufferRenderbufferEXT(GLExt.GL_FRAMEBUFFER_EXT,
+            glfbo.glFramebufferRenderbufferEXT(GLFbo.GL_FRAMEBUFFER_EXT,
                     convertAttachmentSlot(rb.getSlot()),
-                    GLExt.GL_RENDERBUFFER_EXT,
+                    GLFbo.GL_RENDERBUFFER_EXT,
                     rb.getId());
         }
     }
@@ -1465,7 +1475,7 @@ public class GLRenderer implements Renderer {
         }
 
         if (context.boundFBO != id) {
-            glfbo.glBindFramebufferEXT(GLExt.GL_FRAMEBUFFER_EXT, id);
+            glfbo.glBindFramebufferEXT(GLFbo.GL_FRAMEBUFFER_EXT, id);
             // binding an FBO automatically sets draw buf to GL_COLOR_ATTACHMENT0
             context.boundDrawBuf = 0;
             context.boundFBO = id;
@@ -1545,7 +1555,7 @@ public class GLRenderer implements Renderer {
         if (fb == null) {
             // unbind any fbos
             if (context.boundFBO != 0) {
-                glfbo.glBindFramebufferEXT(GLExt.GL_FRAMEBUFFER_EXT, 0);
+                glfbo.glBindFramebufferEXT(GLFbo.GL_FRAMEBUFFER_EXT, 0);
                 statistics.onFrameBufferUse(null, true);
 
                 context.boundFBO = 0;
@@ -1577,7 +1587,7 @@ public class GLRenderer implements Renderer {
             setViewPort(0, 0, fb.getWidth(), fb.getHeight());
             
             if (context.boundFBO != fb.getId()) {
-                glfbo.glBindFramebufferEXT(GLExt.GL_FRAMEBUFFER_EXT, fb.getId());
+                glfbo.glBindFramebufferEXT(GLFbo.GL_FRAMEBUFFER_EXT, fb.getId());
                 statistics.onFrameBufferUse(fb, true);
 
                 context.boundFBO = fb.getId();
@@ -1617,7 +1627,7 @@ public class GLRenderer implements Renderer {
                     if (context.boundDrawBuf != 100 + fb.getNumColorBuffers()) {
                         intBuf16.clear();
                         for (int i = 0; i < fb.getNumColorBuffers(); i++) {
-                            intBuf16.put(GLExt.GL_COLOR_ATTACHMENT0_EXT + i);
+                            intBuf16.put(GLFbo.GL_COLOR_ATTACHMENT0_EXT + i);
                         }
 
                         intBuf16.flip();
@@ -1629,7 +1639,7 @@ public class GLRenderer implements Renderer {
                     // select this draw buffer
                     if (gl2 != null) {
                         if (context.boundDrawBuf != rb.getSlot()) {
-                            gl2.glDrawBuffer(GLExt.GL_COLOR_ATTACHMENT0_EXT + rb.getSlot());
+                            gl2.glDrawBuffer(GLFbo.GL_COLOR_ATTACHMENT0_EXT + rb.getSlot());
                             context.boundDrawBuf = rb.getSlot();
                         }
                     }
@@ -1658,7 +1668,7 @@ public class GLRenderer implements Renderer {
             setFrameBuffer(fb);
             if (gl2 != null) {
                 if (context.boundReadBuf != rb.getSlot()) {
-                    gl2.glReadBuffer(GLExt.GL_COLOR_ATTACHMENT0_EXT + rb.getSlot());
+                    gl2.glReadBuffer(GLFbo.GL_COLOR_ATTACHMENT0_EXT + rb.getSlot());
                     context.boundReadBuf = rb.getSlot();
                 }
             }
@@ -1682,7 +1692,7 @@ public class GLRenderer implements Renderer {
     public void deleteFrameBuffer(FrameBuffer fb) {
         if (fb.getId() != -1) {
             if (context.boundFBO == fb.getId()) {
-                glfbo.glBindFramebufferEXT(GLExt.GL_FRAMEBUFFER_EXT, 0);
+                glfbo.glBindFramebufferEXT(GLFbo.GL_FRAMEBUFFER_EXT, 0);
                 context.boundFBO = 0;
             }
 
@@ -1956,8 +1966,10 @@ public class GLRenderer implements Renderer {
      * @param img The image to upload
      * @param type How the data in the image argument should be interpreted.
      * @param unit The texture slot to be used to upload the image, not important
+     * @param scaleToPot If true, the image will be scaled to power-of-2 dimensions
+     * before being uploaded.
      */
-    public void updateTexImageData(Image img, Texture.Type type, int unit) {
+    public void updateTexImageData(Image img, Texture.Type type, int unit, boolean scaleToPot) {
         int texId = img.getId();
         if (texId == -1) {
             // create texture
@@ -2041,33 +2053,39 @@ public class GLRenderer implements Renderer {
             }
         }
 
+        Image imageForUpload;
+        if (scaleToPot) {
+            imageForUpload = MipMapGenerator.resizeToPowerOf2(img);
+        } else {
+            imageForUpload = img;
+        }
         if (target == GL.GL_TEXTURE_CUBE_MAP) {
-            List<ByteBuffer> data = img.getData();
+            List<ByteBuffer> data = imageForUpload.getData();
             if (data.size() != 6) {
                 logger.log(Level.WARNING, "Invalid texture: {0}\n"
                         + "Cubemap textures must contain 6 data units.", img);
                 return;
             }
             for (int i = 0; i < 6; i++) {
-                texUtil.uploadTexture(img, GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, i, linearizeSrgbImages);
+                texUtil.uploadTexture(imageForUpload, GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, i, linearizeSrgbImages);
             }
         } else if (target == GLExt.GL_TEXTURE_2D_ARRAY_EXT) {
             if (!caps.contains(Caps.TextureArray)) {
                 throw new RendererException("Texture arrays not supported by graphics hardware");
             }
             
-            List<ByteBuffer> data = img.getData();
+            List<ByteBuffer> data = imageForUpload.getData();
             
             // -1 index specifies prepare data for 2D Array
-            texUtil.uploadTexture(img, target, -1, linearizeSrgbImages);
+            texUtil.uploadTexture(imageForUpload, target, -1, linearizeSrgbImages);
             
             for (int i = 0; i < data.size(); i++) {
                 // upload each slice of 2D array in turn
                 // this time with the appropriate index
-                texUtil.uploadTexture(img, target, i, linearizeSrgbImages);
+                texUtil.uploadTexture(imageForUpload, target, i, linearizeSrgbImages);
             }
         } else {
-            texUtil.uploadTexture(img, target, 0, linearizeSrgbImages);
+            texUtil.uploadTexture(imageForUpload, target, 0, linearizeSrgbImages);
         }
 
         if (img.getMultiSamples() != imageSamples) {
@@ -2088,9 +2106,23 @@ public class GLRenderer implements Renderer {
         Image image = tex.getImage();
         if (image.isUpdateNeeded() || (image.isGeneratedMipmapsRequired() && !image.isMipmapsGenerated())) {
             // Check NPOT requirements
-            checkNonPowerOfTwo(tex);
+            boolean scaleToPot = false;
+            
+            try {
+                checkNonPowerOfTwo(tex);
+            } catch (RendererException ex) {
+                if (logger.isLoggable(Level.WARNING)) {
+                    int nextWidth = FastMath.nearestPowerOfTwo(tex.getImage().getWidth());
+                    int nextHeight = FastMath.nearestPowerOfTwo(tex.getImage().getHeight());
+                    logger.log(Level.WARNING, 
+                               "Non-power-of-2 textures are not supported! Scaling texture '" + tex.getName() + 
+                               "' of size " + tex.getImage().getWidth() + "x" + tex.getImage().getHeight() + 
+                               " to " + nextWidth + "x" + nextHeight);
+                }
+                scaleToPot = true;
+            }
             
-            updateTexImageData(image, tex.getType(), unit);
+            updateTexImageData(image, tex.getType(), unit, scaleToPot);
         }
 
         int texId = image.getId();
@@ -2620,32 +2652,13 @@ public class GLRenderer implements Renderer {
             return;
         }
 
-        if (context.pointSprite && mesh.getMode() != Mode.Points) {
-            // XXX: Hack, disable point sprite mode if mesh not in point mode
-            if (context.boundTextures[0] != null) {
-                if (context.boundTextureUnit != 0) {
-                    gl.glActiveTexture(GL.GL_TEXTURE0);
-                    context.boundTextureUnit = 0;
-                }
-                if (gl2 != null) {
-                    gl2.glDisable(GL2.GL_POINT_SPRITE);
-                    gl2.glDisable(GL2.GL_VERTEX_PROGRAM_POINT_SIZE);
-                }
-                context.pointSprite = false;
-            }
-        }
 
-        if (gl2 != null) {
-            if (context.pointSize != mesh.getPointSize()) {
-                gl2.glPointSize(mesh.getPointSize());
-                context.pointSize = mesh.getPointSize();
-            }
-        }
         if (context.lineWidth != mesh.getLineWidth()) {
             gl.glLineWidth(mesh.getLineWidth());
             context.lineWidth = mesh.getLineWidth();
         }
-        if(gl4!=null && mesh.getMode().equals(Mode.Patch)){
+        
+        if (gl4 != null && mesh.getMode().equals(Mode.Patch)) {
             gl4.glPatchParameter(mesh.getPatchVertexCount());
         }
         statistics.onMeshDrawn(mesh, lod, count);

+ 122 - 0
jme3-core/src/main/java/com/jme3/renderer/opengl/GLTiming.java

@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2009-2015 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *   may be used to endorse or promote products derived from this software
+ *   without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.jme3.renderer.opengl;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Arrays;
+import java.util.Comparator;
+import java.util.Map;
+
+public class GLTiming implements InvocationHandler {
+    
+    private final Object obj;
+    private final GLTimingState state;
+    
+    public GLTiming(Object obj, GLTimingState state) {
+        this.obj = obj;
+        this.state = state;
+    }
+    
+    public static Object createGLTiming(Object glInterface, GLTimingState state, Class<?> ... glInterfaceClasses) {
+        return Proxy.newProxyInstance(glInterface.getClass().getClassLoader(),
+                                      glInterfaceClasses, 
+                                      new GLTiming(glInterface, state));
+    }
+    
+    private static class CallTimingComparator implements Comparator<Map.Entry<String, Long>> {
+        @Override
+        public int compare(Map.Entry<String, Long> o1, Map.Entry<String, Long> o2) {
+            return (int) (o2.getValue() - o1.getValue());
+        }
+    }
+    
+    @Override
+    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+        String methodName = method.getName();
+        if (methodName.equals("resetStats")) {
+            if (state.lastPrintOutTime + 1000000000 <= System.nanoTime() && state.sampleCount > 0) {
+                state.timeSpentInGL /= state.sampleCount;
+                System.out.println("--- TOTAL TIME SPENT IN GL CALLS: " + (state.timeSpentInGL/1000) + "us");
+                
+                Map.Entry<String, Long>[] callTimes = new Map.Entry[state.callTiming.size()];
+                int i = 0;
+                for (Map.Entry<String, Long> callTime : state.callTiming.entrySet()) {
+                    callTimes[i++] = callTime;
+                }
+                Arrays.sort(callTimes, new CallTimingComparator());
+                int limit = 10;
+                for (Map.Entry<String, Long> callTime : callTimes) {
+                    long val = callTime.getValue() / state.sampleCount;
+                    String name = callTime.getKey();
+                    String pad = "                                     ".substring(0, 30 - name.length());
+                    System.out.println("\t" + callTime.getKey() + pad + (val/1000) + "us");
+                    if (limit-- == 0) break;
+                }
+                for (Map.Entry<String, Long> callTime : callTimes) {
+                    state.callTiming.put(callTime.getKey(), Long.valueOf(0));
+                }
+                
+                state.sampleCount = 0;
+                state.timeSpentInGL = 0;
+                state.lastPrintOutTime = System.nanoTime();
+            } else {
+                state.sampleCount++;
+            }
+            return null;
+        } else {
+            Long currentTimeObj = state.callTiming.get(methodName);
+            long currentTime = 0;
+            if (currentTimeObj != null) currentTime = currentTimeObj;
+            
+            
+            long startTime = System.nanoTime();
+            Object result = method.invoke(obj, args);
+            long delta = System.nanoTime() - startTime;
+            
+            currentTime += delta;
+            state.timeSpentInGL += delta;
+            
+            state.callTiming.put(methodName, currentTime);
+            
+            if (delta > 1000000 && !methodName.equals("glClear")) {
+                // More than 1ms
+                // Ignore glClear as it cannot be avoided.
+                System.out.println("GL call " + methodName + " took " + (delta/1000) + "us to execute!");
+            }
+            
+            return result;
+        }
+    }
+    
+}

+ 41 - 0
jme3-core/src/main/java/com/jme3/renderer/opengl/GLTimingState.java

@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2009-2015 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *   may be used to endorse or promote products derived from this software
+ *   without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.jme3.renderer.opengl;
+
+import java.util.HashMap;
+
+public class GLTimingState {
+    long timeSpentInGL = 0;
+    int sampleCount = 0;
+    long lastPrintOutTime = 0;
+    final HashMap<String, Long> callTiming = new HashMap<String, Long>();
+}

+ 3 - 4
jme3-core/src/main/java/com/jme3/renderer/opengl/GLTracer.java

@@ -64,6 +64,7 @@ public final class GLTracer implements InvocationHandler {
         noEnumArgs("glScissor", 0, 1, 2, 3);
         noEnumArgs("glClear", 0);
         noEnumArgs("glGetInteger", 1);
+        noEnumArgs("glGetString", 1);
         
         noEnumArgs("glBindTexture", 1);
         noEnumArgs("glPixelStorei", 1);
@@ -95,8 +96,6 @@ public final class GLTracer implements InvocationHandler {
         noEnumArgs("glFramebufferTexture2DEXT", 3, 4);
         noEnumArgs("glBlitFramebufferEXT", 0, 1, 2, 3, 4, 5, 6, 7, 8);
         
-        
-        
         noEnumArgs("glCreateProgram", -1);
         noEnumArgs("glCreateShader", -1);
         noEnumArgs("glShaderSource", 0);
@@ -155,7 +154,7 @@ public final class GLTracer implements InvocationHandler {
      * @return A tracer that implements the given interface
      */
     public static Object createGlesTracer(Object glInterface, Class<?> glInterfaceClass) {
-        IntMap<String> constMap = generateConstantMap(GL.class, GLExt.class);
+        IntMap<String> constMap = generateConstantMap(GL.class, GLFbo.class, GLExt.class);
         return Proxy.newProxyInstance(glInterface.getClass().getClassLoader(),
                                       new Class<?>[] { glInterfaceClass }, 
                                       new GLTracer(glInterface, constMap));
@@ -169,7 +168,7 @@ public final class GLTracer implements InvocationHandler {
      * @return A tracer that implements the given interface
      */
     public static Object createDesktopGlTracer(Object glInterface, Class<?> ... glInterfaceClasses) {
-        IntMap<String> constMap = generateConstantMap(GL2.class, GLExt.class);
+        IntMap<String> constMap = generateConstantMap(GL2.class, GL3.class, GL4.class, GLFbo.class, GLExt.class);
         return Proxy.newProxyInstance(glInterface.getClass().getClassLoader(),
                                       glInterfaceClasses, 
                                       new GLTracer(glInterface, constMap));

+ 7 - 5
jme3-core/src/main/java/com/jme3/scene/BatchNode.java

@@ -583,11 +583,13 @@ public class BatchNode extends GeometryGroupNode {
                         useTangents = true;
                     }
                 } else {
-                    inBuf.copyElements(0, outBuf, globalVertIndex, geomVertCount);
-//                    for (int vert = 0; vert < geomVertCount; vert++) {
-//                        int curGlobalVertIndex = globalVertIndex + vert;
-//                        inBuf.copyElement(vert, outBuf, curGlobalVertIndex);
-//                    }
+                    if (inBuf == null) {
+                        throw new IllegalArgumentException("Geometry " + geom.getName() + " has no " + outBuf.getBufferType() + " buffer whereas other geoms have. all geometries should have the same types of buffers.\n Try to use GeometryBatchFactory.alignBuffer() on the BatchNode before batching");
+                    } else if (outBuf == null) {
+                        throw new IllegalArgumentException("Geometry " + geom.getName() + " has a " + outBuf.getBufferType() + " buffer whereas other geoms don't. all geometries should have the same types of buffers.\n Try to use GeometryBatchFactory.alignBuffer() on the BatchNode before batching");
+                    } else {
+                        inBuf.copyElements(0, outBuf, globalVertIndex, geomVertCount);
+                    }
                 }
             }
 

+ 1 - 0
jme3-core/src/main/java/com/jme3/scene/shape/AbstractBox.java

@@ -149,6 +149,7 @@ public abstract class AbstractBox extends Mesh {
         duUpdateGeometryNormals();
         duUpdateGeometryTextures();
         duUpdateGeometryIndices();
+        setStatic();
     }
 
     /**

+ 1 - 0
jme3-core/src/main/java/com/jme3/shader/Glsl100ShaderGenerator.java

@@ -127,6 +127,7 @@ public class Glsl100ShaderGenerator extends ShaderGenerator {
             unIndent();
             startCondition(shaderNode.getCondition(), source);
             source.append(nodeSource);
+            source.append("\n");
             endCondition(shaderNode.getCondition(), source);
             indent();
         }

+ 0 - 9
jme3-core/src/main/java/com/jme3/system/JmeSystem.java

@@ -172,15 +172,6 @@ public class JmeSystem {
         return systemDelegate.getPlatformAssetConfigURL();
     }
     
-    /**
-     * @deprecated Directly create an image raster via {@link DefaultImageRaster}.
-     */
-    @Deprecated
-    public static ImageRaster createImageRaster(Image image, int slice) {
-        checkDelegate();
-        return systemDelegate.createImageRaster(image, slice);
-    }
-
     /**
      * Displays an error message to the user in whichever way the context
      * feels is appropriate. If this is a headless or an offscreen surface

+ 0 - 5
jme3-core/src/main/java/com/jme3/system/JmeSystemDelegate.java

@@ -132,11 +132,6 @@ public abstract class JmeSystemDelegate {
         return new DesktopAssetManager(null);
     }
     
-    @Deprecated
-    public final ImageRaster createImageRaster(Image image, int slice) {
-        return new DefaultImageRaster(image, slice);
-    }
-    
     public abstract void writeImageFile(OutputStream outStream, String format, ByteBuffer imageData, int width, int height) throws IOException;
 
     public abstract void showErrorDialog(String message);

+ 17 - 15
jme3-core/src/main/java/com/jme3/texture/Image.java

@@ -367,7 +367,6 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
     protected int width, height, depth;
     protected int[] mipMapSizes;
     protected ArrayList<ByteBuffer> data;
-    protected transient Object efficientData;
     protected int multiSamples = 1;
     protected ColorSpace colorSpace = null;
 //    protected int mipOffset = 0;
@@ -375,7 +374,7 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
     // attributes relating to GL object
     protected boolean mipsWereGenerated = false;
     protected boolean needGeneratedMips = false;
-    protected final LastTextureState lastTextureState = new LastTextureState();
+    protected LastTextureState lastTextureState = new LastTextureState();
 
     /**
      * Internal use only.
@@ -421,7 +420,8 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
     
     /**
      * @return True if the image needs to have mipmaps generated
-     * for it (as requested by the texture).
+     * for it (as requested by the texture). This stays true even
+     * after mipmaps have been generated.
      */
     public boolean isGeneratedMipmapsRequired() {
         return needGeneratedMips;
@@ -434,8 +434,9 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
     @Override
     public void setUpdateNeeded() {
         super.setUpdateNeeded();
-        if (!isGeneratedMipmapsRequired() && !hasMipmaps()) {
-            setNeedGeneratedMipmaps();
+        if (isGeneratedMipmapsRequired() && !hasMipmaps()) {
+            // Mipmaps are no longer valid, since the image was changed.
+            setMipmapsGenerated(false);
         }
     }
     
@@ -488,6 +489,7 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
         Image clone = (Image) super.clone();
         clone.mipMapSizes = mipMapSizes != null ? mipMapSizes.clone() : null;
         clone.data = data != null ? new ArrayList<ByteBuffer>(data) : null;
+        clone.lastTextureState = new LastTextureState();
         clone.setUpdateNeeded();
         return clone;
     }
@@ -527,11 +529,13 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
         
         this();
 
-        if (mipMapSizes != null && mipMapSizes.length <= 1) {
-            mipMapSizes = null;
-        } else {
-            needGeneratedMips = false;
-            mipsWereGenerated = true;
+        if (mipMapSizes != null) {
+            if (mipMapSizes.length <= 1) {
+                mipMapSizes = null;
+            } else {
+                needGeneratedMips = false;
+                mipsWereGenerated = true;
+            }
         }
 
         setFormat(format);
@@ -756,8 +760,6 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
      */
     @Deprecated
     public void setEfficentData(Object efficientData){
-        this.efficientData = efficientData;
-        setUpdateNeeded();
     }
 
     /**
@@ -765,7 +767,7 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
      */
     @Deprecated
     public Object getEfficentData(){
-        return efficientData;
+        return null;
     }
 
     /**
@@ -787,8 +789,8 @@ public class Image extends NativeObject implements Savable /*, Cloneable*/ {
              needGeneratedMips = false;
              mipsWereGenerated = false;
         } else {
-             needGeneratedMips = false;
-             mipsWereGenerated = true;
+             needGeneratedMips = true;
+             mipsWereGenerated = false;
         }
 
         setUpdateNeeded();

+ 46 - 5
jme3-core/src/main/java/com/jme3/texture/image/DefaultImageRaster.java

@@ -44,7 +44,9 @@ public class DefaultImageRaster extends ImageRaster {
     private final ImageCodec codec;
     private final int width;
     private final int height;
+    private final int offset;
     private final byte[] temp;
+    private final boolean convertToLinear;
     private int slice;
     
     private void rangeCheck(int x, int y) {
@@ -53,13 +55,40 @@ public class DefaultImageRaster extends ImageRaster {
         }
     }
     
-    public DefaultImageRaster(Image image, int slice) {
+    public DefaultImageRaster(Image image, int slice, int mipMapLevel, boolean convertToLinear) {
+        int[] mipMapSizes = image.getMipMapSizes();
+        int availableMips = mipMapSizes != null ? mipMapSizes.length : 1;
+        
+        if (mipMapLevel >= availableMips) {
+            throw new IllegalStateException("Cannot create image raster for mipmap level #" + mipMapLevel + ". "
+                                          + "Image only has " + availableMips + " mipmap levels.");
+        }
+        
+        if (image.hasMipmaps()) {
+            this.width  = Math.max(1, image.getWidth()  >> mipMapLevel);
+            this.height = Math.max(1, image.getHeight() >> mipMapLevel);
+            
+            int mipOffset = 0;
+            for (int i = 0; i < mipMapLevel; i++) {
+                mipOffset += mipMapSizes[i];
+            }
+            
+            this.offset = mipOffset;
+        } else {
+            this.width = image.getWidth();
+            this.height = image.getHeight();
+            this.offset = 0;
+        }
+        
         this.image = image;
         this.slice = slice;
+        
+        // Conversion to linear only needed if image's color space is sRGB.
+        this.convertToLinear = convertToLinear && image.getColorSpace() == ColorSpace.sRGB;
+        
         this.buffer = image.getData(slice);
         this.codec = ImageCodec.lookup(image.getFormat());
-        this.width = image.getWidth();
-        this.height = image.getHeight();
+        
         if (codec instanceof ByteAlignedImageCodec || codec instanceof ByteOffsetImageCodec) {
             this.temp = new byte[codec.bpp];
         } else {
@@ -86,6 +115,12 @@ public class DefaultImageRaster extends ImageRaster {
     public void setPixel(int x, int y, ColorRGBA color) {
         rangeCheck(x, y);
         
+        if (convertToLinear) {
+            // Input is linear, needs to be converted to sRGB before writing
+            // into image.
+            color = color.getAsSrgb();
+        }
+        
         // Check flags for grayscale
         if (codec.isGray) {
             float gray = color.r * 0.27f + color.g * 0.67f + color.b * 0.06f;
@@ -113,7 +148,7 @@ public class DefaultImageRaster extends ImageRaster {
                 components[3] = Math.min( (int) (color.b * codec.maxBlue + 0.5f), codec.maxBlue);
                 break;
         }     
-        codec.writeComponents(getBuffer(), x, y, width, 0, components, temp);
+        codec.writeComponents(getBuffer(), x, y, width, offset, components, temp);
         image.setUpdateNeeded();
     }
     
@@ -128,7 +163,7 @@ public class DefaultImageRaster extends ImageRaster {
     public ColorRGBA getPixel(int x, int y, ColorRGBA store) {
         rangeCheck(x, y);
         
-        codec.readComponents(getBuffer(), x, y, width, 0, components, temp);
+        codec.readComponents(getBuffer(), x, y, width, offset, components, temp);
         if (store == null) {
             store = new ColorRGBA();
         }
@@ -169,6 +204,12 @@ public class DefaultImageRaster extends ImageRaster {
                 store.a = 1;
             }
         }
+        
+        if (convertToLinear) {
+            // Input image is sRGB, need to convert to linear.
+            store.setAsSrgb(store.r, store.g, store.b, store.a);
+        }
+        
         return store;
     }
 }

+ 23 - 2
jme3-core/src/main/java/com/jme3/texture/image/ImageRaster.java

@@ -71,21 +71,42 @@ public abstract class ImageRaster {
      * @param image The image to read / write to.
      * @param slice Which slice to use. Only applies to 3D images, 2D image
      * arrays or cubemaps.
+     * @param mipMapLevel The mipmap level to read / write to. To access levels 
+     * other than 0, the image must have 
+     * {@link Image#setMipMapSizes(int[]) mipmap sizes} set.
+     * @param convertToLinear If true, the application expects read or written
+     * colors to be in linear color space (<code>ImageRaster</code> will
+     * automatically perform a conversion as needed). If false, the application expects
+     * colors to be in the image's native {@link Image#getColorSpace() color space}.
+     * @return An ImageRaster to read / write to the image.
+     */
+    public static ImageRaster create(Image image, int slice, int mipMapLevel, boolean convertToLinear) {
+        return new DefaultImageRaster(image, slice, mipMapLevel, convertToLinear);
+    }
+    
+    /**
+     * Create new image reader / writer.
+     *
+     * @param image The image to read / write to.
+     * @param slice Which slice to use. Only applies to 3D images, 2D image
+     * arrays or cubemaps.
+     * @return An ImageRaster to read / write to the image.
      */
     public static ImageRaster create(Image image, int slice) {
-        return JmeSystem.createImageRaster(image, slice);
+        return create(image, slice, 0, false);
     }
     
     /**
      * Create new image reader / writer for 2D images.
      * 
      * @param image The image to read / write to.
+     * @return An ImageRaster to read / write to the image.
      */
     public static ImageRaster create(Image image) {
         if (image.getData().size() > 1) {
             throw new IllegalStateException("Use constructor that takes slices argument to read from multislice image");
         }
-        return JmeSystem.createImageRaster(image, 0);
+        return create(image, 0, 0, false);
     }
     
     public ImageRaster() {

+ 140 - 0
jme3-core/src/main/java/com/jme3/util/MipMapGenerator.java

@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2009-2012 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *   may be used to endorse or promote products derived from this software
+ *   without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package com.jme3.util;
+
+import com.jme3.math.ColorRGBA;
+import com.jme3.math.FastMath;
+import com.jme3.texture.Image;
+import com.jme3.texture.Image.Format;
+import com.jme3.texture.image.ImageRaster;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+
+public class MipMapGenerator {
+
+    private MipMapGenerator() {
+    }
+    
+    public static Image scaleImage(Image inputImage, int outputWidth, int outputHeight) {
+        int size = outputWidth * outputHeight * inputImage.getFormat().getBitsPerPixel() / 8;
+        ByteBuffer buffer = BufferUtils.createByteBuffer(size);
+        Image outputImage = new Image(inputImage.getFormat(), 
+                                      outputWidth, 
+                                      outputHeight, 
+                                      buffer, 
+                                      inputImage.getColorSpace());
+        
+        ImageRaster input = ImageRaster.create(inputImage, 0, 0, false);
+        ImageRaster output = ImageRaster.create(outputImage, 0, 0, false);
+        
+        float xRatio = ((float)(input.getWidth()  - 1)) / output.getWidth();
+        float yRatio = ((float)(input.getHeight() - 1)) / output.getHeight();
+        
+        ColorRGBA outputColor = new ColorRGBA();
+        ColorRGBA bottomLeft = new ColorRGBA();
+        ColorRGBA bottomRight = new ColorRGBA();
+        ColorRGBA topLeft = new ColorRGBA();
+        ColorRGBA topRight = new ColorRGBA();
+        
+        for (int y = 0; y < outputHeight; y++) {
+            for (int x = 0; x < outputWidth; x++) {
+                float x2f = x * xRatio;
+                float y2f = y * yRatio;
+                
+                int x2 = (int)x2f;
+                int y2 = (int)y2f;
+                
+                float xDiff = x2f - x2;
+                float yDiff = y2f - y2;
+                
+                input.getPixel(x2,     y2,     bottomLeft);
+                input.getPixel(x2 + 1, y2,     bottomRight);
+                input.getPixel(x2,     y2 + 1, topLeft);
+                input.getPixel(x2 + 1, y2 + 1, topRight);
+                
+                bottomLeft.multLocal(  (1f - xDiff) * (1f - yDiff) );
+                bottomRight.multLocal( (xDiff)      * (1f - yDiff) );
+                topLeft.multLocal(     (1f - xDiff) * (yDiff) );
+                topRight.multLocal(    (xDiff)      * (yDiff) );
+                
+                outputColor.set(bottomLeft).addLocal(bottomRight)
+                           .addLocal(topLeft).addLocal(topRight);
+                
+                output.setPixel(x, y, outputColor);
+            }
+        }
+        return outputImage;
+    }
+    
+    public static Image resizeToPowerOf2(Image original){
+        int potWidth = FastMath.nearestPowerOfTwo(original.getWidth());
+        int potHeight = FastMath.nearestPowerOfTwo(original.getHeight());
+        return scaleImage(original, potWidth, potHeight);
+    }
+    
+    public static void generateMipMaps(Image image){
+        int width = image.getWidth();
+        int height = image.getHeight();
+
+        Image current = image;
+        ArrayList<ByteBuffer> output = new ArrayList<ByteBuffer>();
+        int totalSize = 0;
+        
+        while (height >= 1 || width >= 1){
+            output.add(current.getData(0));
+            totalSize += current.getData(0).capacity();
+
+            if (height == 1 || width == 1) {
+                break;
+            }
+
+            height /= 2;
+            width  /= 2;
+
+            current = scaleImage(current, width, height);
+        }
+
+        ByteBuffer combinedData = BufferUtils.createByteBuffer(totalSize);
+        int[] mipSizes = new int[output.size()];
+        for (int i = 0; i < output.size(); i++){
+            ByteBuffer data = output.get(i);
+            data.clear();
+            combinedData.put(data);
+            mipSizes[i] = data.capacity();
+        }
+        combinedData.flip();
+
+        // insert mip data into image
+        image.setData(0, combinedData);
+        image.setMipMapSizes(mipSizes);
+    }
+}

+ 15 - 17
jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.frag

@@ -17,10 +17,7 @@ varying vec3 SpecularSum;
 #ifndef VERTEX_LIGHTING
     uniform mat4 g_ViewMatrix;
     uniform vec4 g_LightData[NB_LIGHTS];
-    varying vec3 vPos;    
-#else
-    varying vec3 specularAccum;
-    varying vec4 diffuseAccum;
+    varying vec3 vPos; 
 #endif
 
 #ifdef DIFFUSEMAP
@@ -72,17 +69,19 @@ uniform float m_Shininess;
 #endif
 
 void main(){
-    #ifdef NORMALMAP   
-        mat3 tbnMat = mat3(normalize(vTangent.xyz) , normalize(vBinormal.xyz) , normalize(vNormal.xyz));
+    #if !defined(VERTEX_LIGHTING)
+        #if defined(NORMALMAP)
+            mat3 tbnMat = mat3(normalize(vTangent.xyz) , normalize(vBinormal.xyz) , normalize(vNormal.xyz));
 
-        if (!gl_FrontFacing)
-        {
-            tbnMat[2] = -tbnMat[2];
-        }
+            if (!gl_FrontFacing)
+            {
+                tbnMat[2] = -tbnMat[2];
+            }
 
-        vec3 viewDir = normalize(-vPos.xyz * tbnMat);
-    #else
-        vec3 viewDir = normalize(-vPos.xyz);
+            vec3 viewDir = normalize(-vPos.xyz * tbnMat);
+        #else
+            vec3 viewDir = normalize(-vPos.xyz);
+        #endif
     #endif
 
     vec2 newTexCoord;
@@ -165,10 +164,9 @@ void main(){
     #endif
 
     #ifdef VERTEX_LIGHTING
-        gl_FragColor.rgb = AmbientSum  * diffuseColor.rgb 
-                            +diffuseAccum.rgb *diffuseColor.rgb
-                            +specularAccum.rgb * specularColor.rgb;
-        gl_FragColor.a=1.0;                           
+        gl_FragColor.rgb = AmbientSum.rgb  * diffuseColor.rgb 
+                         + DiffuseSum.rgb  * diffuseColor.rgb
+                         + SpecularSum.rgb * specularColor.rgb;                         
     #else       
         
         int i = 0;

+ 12 - 9
jme3-core/src/main/resources/Common/MatDefs/Light/SPLighting.vert

@@ -43,8 +43,9 @@ attribute vec3 inNormal;
         varying vec3 vBinormal;
     #endif
 #else
-    varying vec3 specularAccum;
-    varying vec4 diffuseAccum;
+    #ifdef COLORRAMP
+      uniform sampler2D m_ColorRamp;
+    #endif
 #endif
 
 #ifdef USE_REFLECTION
@@ -128,14 +129,13 @@ void main(){
     #endif
     #ifdef VERTEX_LIGHTING
         int i = 0;
-        diffuseAccum = vec4(0.0);
-        specularAccum = vec3(0.0);
+        vec3 diffuseAccum  = vec3(0.0);
+        vec3 specularAccum = vec3(0.0);
         vec4 diffuseColor;
         vec3 specularColor;
         for (int i =0;i < NB_LIGHTS; i+=3){
             vec4 lightColor = g_LightData[i];            
             vec4 lightData1 = g_LightData[i+1];            
-            DiffuseSum = vec4(1.0);
             #ifdef MATERIAL_COLORS
               diffuseColor  = m_Diffuse * vec4(lightColor.rgb, 1.0);                
               specularColor = m_Specular.rgb * lightColor.rgb;
@@ -160,16 +160,19 @@ void main(){
             #if __VERSION__ >= 110
             }
             #endif
-            vec2 v = computeLighting(wvNormal, viewDir, lightDir.xyz, lightDir.w  * spotFallOff, m_Shininess);
+            vec2 light = computeLighting(wvNormal, viewDir, lightDir.xyz, lightDir.w  * spotFallOff, m_Shininess);
 
             #ifdef COLORRAMP
-                diffuseAccum  += texture2D(m_ColorRamp, vec2(light.x, 0.0)).rgb * diffuseColor;
+                diffuseAccum  += texture2D(m_ColorRamp, vec2(light.x, 0.0)).rgb * diffuseColor.rgb;
                 specularAccum += texture2D(m_ColorRamp, vec2(light.y, 0.0)).rgb * specularColor;
             #else
-                diffuseAccum  += v.x * diffuseColor;
-                specularAccum += v.y * specularColor;
+                diffuseAccum  += light.x * diffuseColor.rgb;
+                specularAccum += light.y * specularColor;
             #endif
         }
+
+        DiffuseSum.rgb  *= diffuseAccum.rgb;
+        SpecularSum.rgb *= specularAccum.rgb;
     #endif
     
 

+ 0 - 22
jme3-core/src/main/resources/com/jme3/asset/Desktop.cfg

@@ -2,26 +2,4 @@ INCLUDE com/jme3/asset/General.cfg
 
 # Desktop-specific loaders
 LOADER com.jme3.texture.plugins.AWTLoader : jpg, bmp, gif, png, jpeg
-LOADER com.jme3.audio.plugins.OGGLoader : oggLOADER com.jme3.audio.plugins.WAVLoader : wav
 LOADER com.jme3.audio.plugins.OGGLoader : ogg
-LOADER com.jme3.cursors.plugins.CursorLoader : ani, cur, ico
-LOADER com.jme3.material.plugins.J3MLoader : j3m
-LOADER com.jme3.material.plugins.J3MLoader : j3md
-LOADER com.jme3.material.plugins.ShaderNodeDefinitionLoader : j3sn
-LOADER com.jme3.font.plugins.BitmapFontLoader : fnt
-LOADER com.jme3.texture.plugins.DDSLoader : dds
-LOADER com.jme3.texture.plugins.PFMLoader : pfm
-LOADER com.jme3.texture.plugins.HDRLoader : hdr
-LOADER com.jme3.texture.plugins.TGALoader : tga
-LOADER com.jme3.export.binary.BinaryImporter : j3o
-LOADER com.jme3.export.binary.BinaryImporter : j3f
-LOADER com.jme3.scene.plugins.OBJLoader : obj
-LOADER com.jme3.scene.plugins.MTLLoader : mtl
-LOADER com.jme3.scene.plugins.ogre.MeshLoader : meshxml, mesh.xml
-LOADER com.jme3.scene.plugins.ogre.SkeletonLoader : skeletonxml, skeleton.xml
-LOADER com.jme3.scene.plugins.ogre.MaterialLoader : material
-LOADER com.jme3.scene.plugins.ogre.SceneLoader : scene
-LOADER com.jme3.scene.plugins.blender.BlenderModelLoader : blend
-LOADER com.jme3.shader.plugins.GLSLLoader : vert, frag,geom,tsctrl,tseval, glsl, glsllib
-LOADER com.jme3.scene.plugins.fbx.SceneLoader : fbx
-LOADER com.jme3.scene.plugins.fbx.SceneWithAnimationLoader : fba

+ 1 - 1
jme3-core/src/main/resources/com/jme3/asset/General.cfg

@@ -21,6 +21,6 @@ LOADER com.jme3.scene.plugins.ogre.SkeletonLoader : skeletonxml, skeleton.xml
 LOADER com.jme3.scene.plugins.ogre.MaterialLoader : material
 LOADER com.jme3.scene.plugins.ogre.SceneLoader : scene
 LOADER com.jme3.scene.plugins.blender.BlenderModelLoader : blend
-LOADER com.jme3.shader.plugins.GLSLLoader : vert, frag, glsl, glsllib
+LOADER com.jme3.shader.plugins.GLSLLoader : vert, frag, geom, tsctrl, tseval, glsl, glsllib
 LOADER com.jme3.scene.plugins.fbx.SceneLoader : fbx
 LOADER com.jme3.scene.plugins.fbx.SceneWithAnimationLoader : fba

+ 13 - 6
jme3-core/src/main/resources/joystick-mapping.properties

@@ -6,7 +6,7 @@
 #   the new name as it will be reported through the Joystick
 #   interface.
 #
-#   Keys with spaces in them should have those spaces escaped. 
+#   Keys with spaces in them should have those spaces escaped.
 #   Values do not need their spaces escaped.  For example:
 #
 #   Some\ Joystick.0=3
@@ -37,22 +37,29 @@ Controller\ (Xbox\ 360\ Wireless\ Receiver\ for\ Windows).ry=rz
 # requires custom code to support trigger buttons but this
 # keeps it from confusing the .rx mapping.
 Controller\ (Xbox\ 360\ Wireless\ Receiver\ for\ Windows).z=trigger
- 
+
 # Xbox 360 Controller (copied from wireless version)
 Controller\ (XBOX\ 360\ For\ Windows).0=2
 Controller\ (XBOX\ 360\ For\ Windows).1=1
 Controller\ (XBOX\ 360\ For\ Windows).2=3
 Controller\ (XBOX\ 360\ For\ Windows).3=0
- 
+
 Controller\ (XBOX\ 360\ For\ Windows).6=8
 Controller\ (XBOX\ 360\ For\ Windows).7=9
- 
+
 Controller\ (XBOX\ 360\ For\ Windows).8=10
 Controller\ (XBOX\ 360\ For\ Windows).9=11
- 
+
 Controller\ (XBOX\ 360\ For\ Windows).rx=z
 Controller\ (XBOX\ 360\ For\ Windows).ry=rz
- 
+
 # requires custom code to support trigger buttons but this
 # keeps it from confusing the .rx mapping.
 Controller\ (XBOX\ 360\ For\ Windows).z=trigger
+
+# XBOX 360 Controller connected to Android using
+# the USB dongle
+Xbox\ 360\ Wireless\ Receiver.AXIS_RX=z
+Xbox\ 360\ Wireless\ Receiver.AXIS_RY=rz
+Xbox\ 360\ Wireless\ Receiver.z=AXIS_RX
+Xbox\ 360\ Wireless\ Receiver.rz=AXIS_RY

+ 31 - 9
jme3-core/src/plugins/java/com/jme3/export/binary/BinaryExporter.java

@@ -31,6 +31,7 @@
  */
 package com.jme3.export.binary;
 
+import com.jme3.asset.AssetManager;
 import com.jme3.export.FormatVersion;
 import com.jme3.export.JmeExporter;
 import com.jme3.export.Savable;
@@ -167,8 +168,33 @@ public class BinaryExporter implements JmeExporter {
     public static BinaryExporter getInstance() {
         return new BinaryExporter();
     }
+    
+    /**
+     * Saves the object into memory then loads it from memory.
+     * 
+     * Used by tests to check if the persistence system is working.
+     * 
+     * @param <T> The type of savable.
+     * @param assetManager AssetManager to load assets from.
+     * @param object The object to save and then load.
+     * @return A new instance that has been saved and loaded from the 
+     * original object.
+     */
+    public static <T extends Savable> T saveAndLoad(AssetManager assetManager, T object) {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        try {
+            BinaryExporter exporter = new BinaryExporter();
+            exporter.save(object, baos);
+            BinaryImporter importer = new BinaryImporter();
+            importer.setAssetManager(assetManager);
+            return (T) importer.load(baos.toByteArray());
+        } catch (IOException ex) {
+            // Should never happen.
+            throw new AssertionError(ex);
+        }
+    }
 
-    public boolean save(Savable object, OutputStream os) throws IOException {
+    public void save(Savable object, OutputStream os) throws IOException {
         // reset some vars
         aliasCount = 1;
         idCount = 1;
@@ -286,7 +312,7 @@ public class BinaryExporter implements JmeExporter {
         out = null;
         os = null;
 
-        if (debug ) {
+        if (debug) {
             logger.fine("Stats:");
             logger.log(Level.FINE, "classes: {0}", classNum);
             logger.log(Level.FINE, "class table: {0} bytes", classTableSize);
@@ -294,8 +320,6 @@ public class BinaryExporter implements JmeExporter {
             logger.log(Level.FINE, "location table: {0} bytes", locationTableSize);
             logger.log(Level.FINE, "data: {0} bytes", location);
         }
-
-        return true;
     }
 
     protected String getChunk(BinaryIdContentPair pair) {
@@ -325,7 +349,7 @@ public class BinaryExporter implements JmeExporter {
         return bytes;
     }
 
-    public boolean save(Savable object, File f) throws IOException {
+    public void save(Savable object, File f) throws IOException {
         File parentDirectory = f.getParentFile();
         if (parentDirectory != null && !parentDirectory.exists()) {
             parentDirectory.mkdirs();
@@ -333,11 +357,9 @@ public class BinaryExporter implements JmeExporter {
 
         FileOutputStream fos = new FileOutputStream(f);
         try {
-            return save(object, fos);
+            save(object, fos);
         } finally {
-            if (fos != null) {
-                fos.close();
-            }
+            fos.close();
         }
     }
 

+ 7 - 5
jme3-core/src/plugins/java/com/jme3/material/plugins/J3MLoader.java

@@ -582,10 +582,15 @@ public class J3MLoader implements AssetLoader {
 
     public Object load(AssetInfo info) throws IOException {       
         this.assetManager = info.getManager();
-
+        
         InputStream in = info.openStream();        
         try {
-            key = info.getKey();            
+            key = info.getKey();
+            if (key.getExtension().equals("j3m") && !(key instanceof MaterialKey)) {
+                throw new IOException("Material instances must be loaded via MaterialKey");
+            } else if (key.getExtension().equals("j3md") && key instanceof MaterialKey) {
+                throw new IOException("Material definitions must be loaded via AssetKey");
+            }
             loadFromRoot(BlockLanguageParser.parse(in));
         } finally {
             if (in != null){
@@ -594,9 +599,6 @@ public class J3MLoader implements AssetLoader {
         }
         
         if (material != null){
-            if (!(info.getKey() instanceof MaterialKey)){
-                throw new IOException("Material instances must be loaded via MaterialKey");
-            }
             // material implementation
             return material;
         }else{

+ 12 - 11
jme3-core/src/plugins/java/com/jme3/texture/plugins/DXTFlipper.java

@@ -242,21 +242,12 @@ public class DXTFlipper {
                 img.position(blockByteOffset);
                 img.limit(blockByteOffset + bpb);
 
-                img.get(colorBlock);
-                if (type == 4 || type == 5)
-                    flipDXT5Block(colorBlock, h);
-                else
-                    flipDXT1orDXTA3Block(colorBlock, h);
-
-                // write block (no need to flip block indexes, only pixels
-                // inside block
-                retImg.put(colorBlock);
-
                 if (alphaBlock != null){
                     img.get(alphaBlock);
                     switch (type){
                         case 2:
-                            flipDXT3Block(alphaBlock, h); break;
+                            flipDXT3Block(alphaBlock, h); 
+                            break;
                         case 3:
                         case 4: 
                             flipDXT5Block(alphaBlock, h);
@@ -264,6 +255,16 @@ public class DXTFlipper {
                     }
                     retImg.put(alphaBlock);
                 }
+                
+                img.get(colorBlock);
+                if (type == 4 || type == 5)
+                    flipDXT5Block(colorBlock, h);
+                else
+                    flipDXT1orDXTA3Block(colorBlock, h);
+
+                // write block (no need to flip block indexes, only pixels
+                // inside block
+                retImg.put(colorBlock);
             }
             retImg.rewind();
         }else if (h >= 4){

+ 90 - 0
jme3-core/src/tools/java/jme3tools/optimize/GeometryBatchFactory.java

@@ -16,6 +16,7 @@ import java.nio.FloatBuffer;
 import java.nio.IntBuffer;
 import java.nio.ShortBuffer;
 import java.util.*;
+import java.util.logging.Level;
 import java.util.logging.Logger;
 
 public class GeometryBatchFactory {
@@ -453,4 +454,93 @@ public class GeometryBatchFactory {
         mergeGeometries(geoms, outMesh);
         printMesh(outMesh);
     }
+    
+    /**
+     * Options to align the buffers of geometries' meshes of a sub graph
+     * 
+     */
+    public static enum AlignOption {
+        
+        /**
+         * Will remove the buffers of a type that is not on all the geometries
+         */
+        RemoveUnalignedBuffers,
+        /**
+         * Will create missing buffers and pad with dummy data
+         */
+        CreateMissingBuffers
+    }
+
+    /**
+     * Will ensure that all the geometries' meshes of the n sub graph have the 
+     * same types of buffers
+     * @param n the node to gather geometries from
+     * @param option the align options 
+     * @see AlignOption
+     * 
+     * Very experimental for now.
+     */
+    public static void alignBuffers(Node n, AlignOption option) {
+        List<Geometry> geoms = new ArrayList<Geometry>();
+        gatherGeoms(n, geoms);
+
+        //gather buffer types
+        Map<VertexBuffer.Type, VertexBuffer> types = new EnumMap<VertexBuffer.Type, VertexBuffer>(VertexBuffer.Type.class);
+        Map<VertexBuffer.Type, Integer> typesCount = new EnumMap<VertexBuffer.Type, Integer>(VertexBuffer.Type.class);
+        for (Geometry geom : geoms) {
+            for (VertexBuffer buffer : geom.getMesh().getBufferList()) {
+                if (types.get(buffer.getBufferType()) == null) {
+                    types.put(buffer.getBufferType(), buffer);
+                    logger.log(Level.FINE, buffer.getBufferType().toString());
+                }
+                Integer count = typesCount.get(buffer.getBufferType());
+                if (count == null) {
+                    count = 0;
+                }
+                count++;
+                typesCount.put(buffer.getBufferType(), count);
+            }
+        }
+
+        switch (option) {
+            case RemoveUnalignedBuffers:
+                for (Geometry geom : geoms) {
+
+                    for (VertexBuffer buffer : geom.getMesh().getBufferList()) {
+                        Integer count = typesCount.get(buffer.getBufferType());
+                        if (count != null && count < geoms.size()) {
+                            geom.getMesh().clearBuffer(buffer.getBufferType());
+                            logger.log(Level.FINE, "removing {0} from {1}", new Object[]{buffer.getBufferType(), geom.getName()});
+
+                        }
+                    }
+                }
+                break;
+            case CreateMissingBuffers:
+                for (Geometry geom : geoms) {
+                    for (VertexBuffer.Type type : types.keySet()) {
+                        if (geom.getMesh().getBuffer(type) == null) {
+                            VertexBuffer vb = new VertexBuffer(type);
+                            Buffer b;
+                            switch (type) {
+                                case Index:
+                                case BoneIndex:
+                                case HWBoneIndex:
+                                    b = BufferUtils.createIntBuffer(geom.getMesh().getVertexCount() * types.get(type).getNumComponents());
+                                    break;
+                                case InterleavedData:
+                                    b = BufferUtils.createByteBuffer(geom.getMesh().getVertexCount() * types.get(type).getNumComponents());
+                                    break;
+                                default:
+                                    b = BufferUtils.createFloatBuffer(geom.getMesh().getVertexCount() * types.get(type).getNumComponents());
+                            }
+                            vb.setupData(types.get(type).getUsage(), types.get(type).getNumComponents(), types.get(type).getFormat(), b);
+                            geom.getMesh().setBuffer(vb);
+                            logger.log(Level.FINE, "geom {0} misses buffer {1}. Creating", new Object[]{geom.getName(), type});
+                        }
+                    }
+                }
+                break;
+        }
+    }
 }

+ 2 - 2
jme3-effects/src/main/java/com/jme3/post/ssao/SSAOFilter.java

@@ -162,8 +162,8 @@ public class SSAOFilter extends Filter {
         };
 
         ssaoPass.init(renderManager.getRenderer(), (int) (screenWidth / downSampleFactor), (int) (screenHeight / downSampleFactor), Format.RGBA8, Format.Depth, 1, ssaoMat);
-        ssaoPass.getRenderedTexture().setMinFilter(Texture.MinFilter.Trilinear);
-        ssaoPass.getRenderedTexture().setMagFilter(Texture.MagFilter.Bilinear);
+//        ssaoPass.getRenderedTexture().setMinFilter(Texture.MinFilter.Trilinear);
+//        ssaoPass.getRenderedTexture().setMagFilter(Texture.MagFilter.Bilinear);
         postRenderPasses.add(ssaoPass);
         material = new Material(manager, "Common/MatDefs/SSAO/ssaoBlur.j3md");
         material.setTexture("SSAOMap", ssaoPass.getRenderedTexture());

+ 2 - 2
jme3-examples/src/main/java/jme3test/bullet/TestAttachDriver.java

@@ -69,7 +69,7 @@ public class TestAttachDriver extends SimpleApplication implements ActionListene
     private float accelerationValue = 0;
     private Vector3f jumpForce = new Vector3f(0, 3000, 0);
     private BulletAppState bulletAppState;
-    
+
     public static void main(String[] args) {
         TestAttachDriver app = new TestAttachDriver();
         app.start();
@@ -79,7 +79,7 @@ public class TestAttachDriver extends SimpleApplication implements ActionListene
     public void simpleInitApp() {
         bulletAppState = new BulletAppState();
         stateManager.attach(bulletAppState);
-        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
+        bulletAppState.setDebugEnabled(true);
         setupKeys();
         setupFloor();
         buildPlayer();

+ 1 - 1
jme3-examples/src/main/java/jme3test/bullet/TestAttachGhostObject.java

@@ -85,7 +85,7 @@ public class TestAttachGhostObject extends SimpleApplication implements AnalogLi
     public void simpleInitApp() {
         bulletAppState = new BulletAppState();
         stateManager.attach(bulletAppState);
-        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
+        bulletAppState.setDebugEnabled(true);
         setupKeys();
         setupJoint();
     }

+ 152 - 152
jme3-examples/src/main/java/jme3test/bullet/TestCcd.java

@@ -1,152 +1,152 @@
-/*
- * Copyright (c) 2009-2012 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- *   may be used to endorse or promote products derived from this software
- *   without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-package jme3test.bullet;
-
-import com.jme3.app.SimpleApplication;
-import com.jme3.bullet.BulletAppState;
-import com.jme3.bullet.PhysicsSpace;
-import com.jme3.bullet.collision.shapes.BoxCollisionShape;
-import com.jme3.bullet.collision.shapes.MeshCollisionShape;
-import com.jme3.bullet.collision.shapes.SphereCollisionShape;
-import com.jme3.bullet.control.RigidBodyControl;
-import com.jme3.input.MouseInput;
-import com.jme3.input.controls.ActionListener;
-import com.jme3.input.controls.MouseButtonTrigger;
-import com.jme3.material.Material;
-import com.jme3.math.ColorRGBA;
-import com.jme3.math.Vector3f;
-import com.jme3.renderer.RenderManager;
-import com.jme3.renderer.queue.RenderQueue.ShadowMode;
-import com.jme3.scene.Geometry;
-import com.jme3.scene.Node;
-import com.jme3.scene.shape.Box;
-import com.jme3.scene.shape.Sphere;
-import com.jme3.scene.shape.Sphere.TextureMode;
-
-/**
- *
- * @author normenhansen
- */
-public class TestCcd extends SimpleApplication implements ActionListener {
-
-    private Material mat;
-    private Material mat2;
-    private Sphere bullet;
-    private SphereCollisionShape bulletCollisionShape;
-    private BulletAppState bulletAppState;
-
-    public static void main(String[] args) {
-        TestCcd app = new TestCcd();
-        app.start();
-    }
-
-    private void setupKeys() {
-        inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
-        inputManager.addMapping("shoot2", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
-        inputManager.addListener(this, "shoot");
-        inputManager.addListener(this, "shoot2");
-    }
-
-    @Override
-    public void simpleInitApp() {
-        bulletAppState = new BulletAppState();
-        stateManager.attach(bulletAppState);
-        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
-        bullet = new Sphere(32, 32, 0.4f, true, false);
-        bullet.setTextureMode(TextureMode.Projected);
-        bulletCollisionShape = new SphereCollisionShape(0.1f);
-        setupKeys();
-
-        mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
-        mat.getAdditionalRenderState().setWireframe(true);
-        mat.setColor("Color", ColorRGBA.Green);
-
-        mat2 = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
-        mat2.getAdditionalRenderState().setWireframe(true);
-        mat2.setColor("Color", ColorRGBA.Red);
-
-        // An obstacle mesh, does not move (mass=0)
-        Node node2 = new Node();
-        node2.setName("mesh");
-        node2.setLocalTranslation(new Vector3f(2.5f, 0, 0f));
-        node2.addControl(new RigidBodyControl(new MeshCollisionShape(new Box(Vector3f.ZERO, 4, 4, 0.1f)), 0));
-        rootNode.attachChild(node2);
-        getPhysicsSpace().add(node2);
-
-        // The floor, does not move (mass=0)
-        Node node3 = new Node();
-        node3.setLocalTranslation(new Vector3f(0f, -6, 0f));
-        node3.addControl(new RigidBodyControl(new BoxCollisionShape(new Vector3f(100, 1, 100)), 0));
-        rootNode.attachChild(node3);
-        getPhysicsSpace().add(node3);
-
-    }
-
-    private PhysicsSpace getPhysicsSpace() {
-        return bulletAppState.getPhysicsSpace();
-    }
-
-    @Override
-    public void simpleUpdate(float tpf) {
-        //TODO: add update code
-    }
-
-    @Override
-    public void simpleRender(RenderManager rm) {
-        //TODO: add render code
-    }
-
-    public void onAction(String binding, boolean value, float tpf) {
-        if (binding.equals("shoot") && !value) {
-            Geometry bulletg = new Geometry("bullet", bullet);
-            bulletg.setMaterial(mat);
-            bulletg.setName("bullet");
-            bulletg.setLocalTranslation(cam.getLocation());
-            bulletg.setShadowMode(ShadowMode.CastAndReceive);
-            bulletg.addControl(new RigidBodyControl(bulletCollisionShape, 1));
-            bulletg.getControl(RigidBodyControl.class).setCcdMotionThreshold(0.1f);
-            bulletg.getControl(RigidBodyControl.class).setLinearVelocity(cam.getDirection().mult(40));
-            rootNode.attachChild(bulletg);
-            getPhysicsSpace().add(bulletg);
-        } else if (binding.equals("shoot2") && !value) {
-            Geometry bulletg = new Geometry("bullet", bullet);
-            bulletg.setMaterial(mat2);
-            bulletg.setName("bullet");
-            bulletg.setLocalTranslation(cam.getLocation());
-            bulletg.setShadowMode(ShadowMode.CastAndReceive);
-            bulletg.addControl(new RigidBodyControl(bulletCollisionShape, 1));
-            bulletg.getControl(RigidBodyControl.class).setLinearVelocity(cam.getDirection().mult(40));
-            rootNode.attachChild(bulletg);
-            getPhysicsSpace().add(bulletg);
-        }
-    }
-}
+/*
+ * Copyright (c) 2009-2012 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *   may be used to endorse or promote products derived from this software
+ *   without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package jme3test.bullet;
+
+import com.jme3.app.SimpleApplication;
+import com.jme3.bullet.BulletAppState;
+import com.jme3.bullet.PhysicsSpace;
+import com.jme3.bullet.collision.shapes.BoxCollisionShape;
+import com.jme3.bullet.collision.shapes.MeshCollisionShape;
+import com.jme3.bullet.collision.shapes.SphereCollisionShape;
+import com.jme3.bullet.control.RigidBodyControl;
+import com.jme3.input.MouseInput;
+import com.jme3.input.controls.ActionListener;
+import com.jme3.input.controls.MouseButtonTrigger;
+import com.jme3.material.Material;
+import com.jme3.math.ColorRGBA;
+import com.jme3.math.Vector3f;
+import com.jme3.renderer.RenderManager;
+import com.jme3.renderer.queue.RenderQueue.ShadowMode;
+import com.jme3.scene.Geometry;
+import com.jme3.scene.Node;
+import com.jme3.scene.shape.Box;
+import com.jme3.scene.shape.Sphere;
+import com.jme3.scene.shape.Sphere.TextureMode;
+
+/**
+ *
+ * @author normenhansen
+ */
+public class TestCcd extends SimpleApplication implements ActionListener {
+
+    private Material mat;
+    private Material mat2;
+    private Sphere bullet;
+    private SphereCollisionShape bulletCollisionShape;
+    private BulletAppState bulletAppState;
+
+    public static void main(String[] args) {
+        TestCcd app = new TestCcd();
+        app.start();
+    }
+
+    private void setupKeys() {
+        inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
+        inputManager.addMapping("shoot2", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
+        inputManager.addListener(this, "shoot");
+        inputManager.addListener(this, "shoot2");
+    }
+
+    @Override
+    public void simpleInitApp() {
+        bulletAppState = new BulletAppState();
+        stateManager.attach(bulletAppState);
+        bulletAppState.setDebugEnabled(true);
+        bullet = new Sphere(32, 32, 0.4f, true, false);
+        bullet.setTextureMode(TextureMode.Projected);
+        bulletCollisionShape = new SphereCollisionShape(0.1f);
+        setupKeys();
+
+        mat = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
+        mat.getAdditionalRenderState().setWireframe(true);
+        mat.setColor("Color", ColorRGBA.Green);
+
+        mat2 = new Material(getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
+        mat2.getAdditionalRenderState().setWireframe(true);
+        mat2.setColor("Color", ColorRGBA.Red);
+
+        // An obstacle mesh, does not move (mass=0)
+        Node node2 = new Node();
+        node2.setName("mesh");
+        node2.setLocalTranslation(new Vector3f(2.5f, 0, 0f));
+        node2.addControl(new RigidBodyControl(new MeshCollisionShape(new Box(Vector3f.ZERO, 4, 4, 0.1f)), 0));
+        rootNode.attachChild(node2);
+        getPhysicsSpace().add(node2);
+
+        // The floor, does not move (mass=0)
+        Node node3 = new Node();
+        node3.setLocalTranslation(new Vector3f(0f, -6, 0f));
+        node3.addControl(new RigidBodyControl(new BoxCollisionShape(new Vector3f(100, 1, 100)), 0));
+        rootNode.attachChild(node3);
+        getPhysicsSpace().add(node3);
+
+    }
+
+    private PhysicsSpace getPhysicsSpace() {
+        return bulletAppState.getPhysicsSpace();
+    }
+
+    @Override
+    public void simpleUpdate(float tpf) {
+        //TODO: add update code
+    }
+
+    @Override
+    public void simpleRender(RenderManager rm) {
+        //TODO: add render code
+    }
+
+    public void onAction(String binding, boolean value, float tpf) {
+        if (binding.equals("shoot") && !value) {
+            Geometry bulletg = new Geometry("bullet", bullet);
+            bulletg.setMaterial(mat);
+            bulletg.setName("bullet");
+            bulletg.setLocalTranslation(cam.getLocation());
+            bulletg.setShadowMode(ShadowMode.CastAndReceive);
+            bulletg.addControl(new RigidBodyControl(bulletCollisionShape, 1));
+            bulletg.getControl(RigidBodyControl.class).setCcdMotionThreshold(0.1f);
+            bulletg.getControl(RigidBodyControl.class).setLinearVelocity(cam.getDirection().mult(40));
+            rootNode.attachChild(bulletg);
+            getPhysicsSpace().add(bulletg);
+        } else if (binding.equals("shoot2") && !value) {
+            Geometry bulletg = new Geometry("bullet", bullet);
+            bulletg.setMaterial(mat2);
+            bulletg.setName("bullet");
+            bulletg.setLocalTranslation(cam.getLocation());
+            bulletg.setShadowMode(ShadowMode.CastAndReceive);
+            bulletg.addControl(new RigidBodyControl(bulletCollisionShape, 1));
+            bulletg.getControl(RigidBodyControl.class).setLinearVelocity(cam.getDirection().mult(40));
+            rootNode.attachChild(bulletg);
+            getPhysicsSpace().add(bulletg);
+        }
+    }
+}

+ 2 - 2
jme3-examples/src/main/java/jme3test/bullet/TestCollisionGroups.java

@@ -61,8 +61,8 @@ public class TestCollisionGroups extends SimpleApplication {
     public void simpleInitApp() {
         bulletAppState = new BulletAppState();
         stateManager.attach(bulletAppState);
-        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
-        
+        bulletAppState.setDebugEnabled(true);
+
         // Add a physics sphere to the world
         Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
         physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0));

+ 98 - 98
jme3-examples/src/main/java/jme3test/bullet/TestCollisionListener.java

@@ -1,98 +1,98 @@
-/*
- * Copyright (c) 2009-2012 jMonkeyEngine
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
- * met:
- *
- * * Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- *
- * * Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- *
- * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
- *   may be used to endorse or promote products derived from this software
- *   without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
- * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
- * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-package jme3test.bullet;
-
-import com.jme3.app.SimpleApplication;
-import com.jme3.bullet.BulletAppState;
-import com.jme3.bullet.PhysicsSpace;
-import com.jme3.bullet.collision.PhysicsCollisionEvent;
-import com.jme3.bullet.collision.PhysicsCollisionListener;
-import com.jme3.bullet.collision.shapes.SphereCollisionShape;
-import com.jme3.renderer.RenderManager;
-import com.jme3.scene.shape.Sphere;
-import com.jme3.scene.shape.Sphere.TextureMode;
-
-/**
- *
- * @author normenhansen
- */
-public class TestCollisionListener extends SimpleApplication implements PhysicsCollisionListener {
-
-    private BulletAppState bulletAppState;
-    private Sphere bullet;
-    private SphereCollisionShape bulletCollisionShape;
-
-    public static void main(String[] args) {
-        TestCollisionListener app = new TestCollisionListener();
-        app.start();
-    }
-
-    @Override
-    public void simpleInitApp() {
-        bulletAppState = new BulletAppState();
-        stateManager.attach(bulletAppState);
-        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
-        bullet = new Sphere(32, 32, 0.4f, true, false);
-        bullet.setTextureMode(TextureMode.Projected);
-        bulletCollisionShape = new SphereCollisionShape(0.4f);
-
-        PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
-        PhysicsTestHelper.createBallShooter(this, rootNode, bulletAppState.getPhysicsSpace());
-
-        // add ourselves as collision listener
-        getPhysicsSpace().addCollisionListener(this);
-    }
-
-    private PhysicsSpace getPhysicsSpace(){
-        return bulletAppState.getPhysicsSpace();
-    }
-
-    @Override
-    public void simpleUpdate(float tpf) {
-        //TODO: add update code
-    }
-
-    @Override
-    public void simpleRender(RenderManager rm) {
-        //TODO: add render code
-    }
-
-    public void collision(PhysicsCollisionEvent event) {
-        if ("Box".equals(event.getNodeA().getName()) || "Box".equals(event.getNodeB().getName())) {
-            if ("bullet".equals(event.getNodeA().getName()) || "bullet".equals(event.getNodeB().getName())) {
-                fpsText.setText("You hit the box!");
-            }
-        }
-    }
-
-}
+/*
+ * Copyright (c) 2009-2012 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *   may be used to endorse or promote products derived from this software
+ *   without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package jme3test.bullet;
+
+import com.jme3.app.SimpleApplication;
+import com.jme3.bullet.BulletAppState;
+import com.jme3.bullet.PhysicsSpace;
+import com.jme3.bullet.collision.PhysicsCollisionEvent;
+import com.jme3.bullet.collision.PhysicsCollisionListener;
+import com.jme3.bullet.collision.shapes.SphereCollisionShape;
+import com.jme3.renderer.RenderManager;
+import com.jme3.scene.shape.Sphere;
+import com.jme3.scene.shape.Sphere.TextureMode;
+
+/**
+ *
+ * @author normenhansen
+ */
+public class TestCollisionListener extends SimpleApplication implements PhysicsCollisionListener {
+
+    private BulletAppState bulletAppState;
+    private Sphere bullet;
+    private SphereCollisionShape bulletCollisionShape;
+
+    public static void main(String[] args) {
+        TestCollisionListener app = new TestCollisionListener();
+        app.start();
+    }
+
+    @Override
+    public void simpleInitApp() {
+        bulletAppState = new BulletAppState();
+        stateManager.attach(bulletAppState);
+        bulletAppState.setDebugEnabled(true);
+        bullet = new Sphere(32, 32, 0.4f, true, false);
+        bullet.setTextureMode(TextureMode.Projected);
+        bulletCollisionShape = new SphereCollisionShape(0.4f);
+
+        PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
+        PhysicsTestHelper.createBallShooter(this, rootNode, bulletAppState.getPhysicsSpace());
+
+        // add ourselves as collision listener
+        getPhysicsSpace().addCollisionListener(this);
+    }
+
+    private PhysicsSpace getPhysicsSpace(){
+        return bulletAppState.getPhysicsSpace();
+    }
+
+    @Override
+    public void simpleUpdate(float tpf) {
+        //TODO: add update code
+    }
+
+    @Override
+    public void simpleRender(RenderManager rm) {
+        //TODO: add render code
+    }
+
+    public void collision(PhysicsCollisionEvent event) {
+        if ("Box".equals(event.getNodeA().getName()) || "Box".equals(event.getNodeB().getName())) {
+            if ("bullet".equals(event.getNodeA().getName()) || "bullet".equals(event.getNodeB().getName())) {
+                fpsText.setText("You hit the box!");
+            }
+        }
+    }
+
+}

+ 1 - 1
jme3-examples/src/main/java/jme3test/bullet/TestCollisionShapeFactory.java

@@ -67,7 +67,7 @@ public class TestCollisionShapeFactory extends SimpleApplication {
     public void simpleInitApp() {
         bulletAppState = new BulletAppState();
         stateManager.attach(bulletAppState);
-        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
+        bulletAppState.setDebugEnabled(true);
         createMaterial();
 
         Node node = new Node("node1");

+ 1 - 1
jme3-examples/src/main/java/jme3test/bullet/TestGhostObject.java

@@ -62,7 +62,7 @@ public class TestGhostObject extends SimpleApplication {
     public void simpleInitApp() {
         bulletAppState = new BulletAppState();
         stateManager.attach(bulletAppState);
-        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
+        bulletAppState.setDebugEnabled(true);
 
         // Mesh to be shared across several boxes.
         Box boxGeom = new Box(Vector3f.ZERO, 1f, 1f, 1f);

+ 4 - 4
jme3-examples/src/main/java/jme3test/bullet/TestKinematicAddToPhysicsSpaceIssue.java

@@ -60,7 +60,7 @@ public class TestKinematicAddToPhysicsSpaceIssue extends SimpleApplication {
 
         bulletAppState = new BulletAppState();
         stateManager.attach(bulletAppState);
-        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
+        bulletAppState.setDebugEnabled(true);
         // Add a physics sphere to the world
         Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
         physicsSphere.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(3, 6, 0));
@@ -69,7 +69,7 @@ public class TestKinematicAddToPhysicsSpaceIssue extends SimpleApplication {
         //Setting the rigidBody to kinematic before adding it to the physic space
         physicsSphere.getControl(RigidBodyControl.class).setKinematic(true);
         //adding it to the physic space
-        getPhysicsSpace().add(physicsSphere);         
+        getPhysicsSpace().add(physicsSphere);
         //Making it not kinematic again, it should fall under gravity, it doesn't
         physicsSphere.getControl(RigidBodyControl.class).setKinematic(false);
 
@@ -77,7 +77,7 @@ public class TestKinematicAddToPhysicsSpaceIssue extends SimpleApplication {
         Node physicsSphere2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);
         physicsSphere2.getControl(RigidBodyControl.class).setPhysicsLocation(new Vector3f(5, 6, 0));
         rootNode.attachChild(physicsSphere2);
-        
+
         //Adding the rigid body to physic space
         getPhysicsSpace().add(physicsSphere2);
         //making it kinematic
@@ -85,7 +85,7 @@ public class TestKinematicAddToPhysicsSpaceIssue extends SimpleApplication {
         //Making it not kinematic again, it works properly, the rigidbody is affected by grvity.
         physicsSphere2.getControl(RigidBodyControl.class).setKinematic(false);
 
-      
+
 
         // an obstacle mesh, does not move (mass=0)
         Node node2 = PhysicsTestHelper.createPhysicsTestNode(assetManager, new MeshCollisionShape(new Sphere(16, 16, 1.2f)), 0);

+ 1 - 1
jme3-examples/src/main/java/jme3test/bullet/TestLocalPhysics.java

@@ -59,7 +59,7 @@ public class TestLocalPhysics extends SimpleApplication {
     public void simpleInitApp() {
         bulletAppState = new BulletAppState();
         stateManager.attach(bulletAppState);
-        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
+        bulletAppState.setDebugEnabled(true);
 
         // Add a physics sphere to the world
         Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);

+ 1 - 1
jme3-examples/src/main/java/jme3test/bullet/TestPhysicsCar.java

@@ -69,7 +69,7 @@ public class TestPhysicsCar extends SimpleApplication implements ActionListener
     public void simpleInitApp() {
         bulletAppState = new BulletAppState();
         stateManager.attach(bulletAppState);
-        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
+        bulletAppState.setDebugEnabled(true);
         PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
         setupKeys();
         buildPlayer();

+ 2 - 2
jme3-examples/src/main/java/jme3test/bullet/TestPhysicsHingeJoint.java

@@ -76,7 +76,7 @@ public class TestPhysicsHingeJoint extends SimpleApplication implements AnalogLi
     public void simpleInitApp() {
         bulletAppState = new BulletAppState();
         stateManager.attach(bulletAppState);
-        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
+        bulletAppState.setDebugEnabled(true);
         setupKeys();
         setupJoint();
     }
@@ -102,7 +102,7 @@ public class TestPhysicsHingeJoint extends SimpleApplication implements AnalogLi
 
     @Override
     public void simpleUpdate(float tpf) {
-        
+
     }
 
 

+ 9 - 9
jme3-examples/src/main/java/jme3test/bullet/TestPhysicsRayCast.java

@@ -1,5 +1,5 @@
 package jme3test.bullet;
- 
+
 import com.jme3.app.SimpleApplication;
 import com.jme3.bullet.BulletAppState;
 import com.jme3.bullet.collision.PhysicsCollisionObject;
@@ -16,30 +16,30 @@ import java.util.List;
  * @author @wezrule
  */
 public class TestPhysicsRayCast extends SimpleApplication {
- 
+
     private BulletAppState bulletAppState = new BulletAppState();
- 
+
     public static void main(String[] args) {
         new TestPhysicsRayCast().start();
     }
- 
+
     @Override
     public void simpleInitApp() {
         stateManager.attach(bulletAppState);
         initCrossHair();
- 
+
         Spatial s = assetManager.loadModel("Models/Elephant/Elephant.mesh.xml");
         s.setLocalScale(0.1f);
- 
+
         CollisionShape collisionShape = CollisionShapeFactory.createMeshShape(s);
         Node n = new Node("elephant");
         n.addControl(new RigidBodyControl(collisionShape, 1));
         n.getControl(RigidBodyControl.class).setKinematic(true);
         bulletAppState.getPhysicsSpace().add(n);
         rootNode.attachChild(n);
-        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
+        bulletAppState.setDebugEnabled(true);
     }
- 
+
     @Override
     public void simpleUpdate(float tpf) {
         List<PhysicsRayTestResult> rayTest = bulletAppState.getPhysicsSpace().rayTest(cam.getLocation(), cam.getLocation().add(cam.getDirection()));
@@ -50,7 +50,7 @@ public class TestPhysicsRayCast extends SimpleApplication {
             fpsText.setText(collisionObject.getUserObject().toString());
         }
     }
- 
+
     private void initCrossHair() {
         BitmapText bitmapText = new BitmapText(guiFont);
         bitmapText.setText("+");

+ 1 - 1
jme3-examples/src/main/java/jme3test/bullet/TestPhysicsReadWrite.java

@@ -69,7 +69,7 @@ public class TestPhysicsReadWrite extends SimpleApplication{
     public void simpleInitApp() {
         bulletAppState = new BulletAppState();
         stateManager.attach(bulletAppState);
-        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
+        bulletAppState.setDebugEnabled(true);
         physicsRootNode=new Node("PhysicsRootNode");
         rootNode.attachChild(physicsRootNode);
 

+ 1 - 1
jme3-examples/src/main/java/jme3test/bullet/TestRagDoll.java

@@ -64,7 +64,7 @@ public class TestRagDoll extends SimpleApplication implements ActionListener {
     public void simpleInitApp() {
         bulletAppState = new BulletAppState();
         stateManager.attach(bulletAppState);
-        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
+        bulletAppState.setDebugEnabled(true);
         inputManager.addMapping("Pull ragdoll up", new MouseButtonTrigger(0));
         inputManager.addListener(this, "Pull ragdoll up");
         PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());

+ 1 - 1
jme3-examples/src/main/java/jme3test/bullet/TestSimplePhysics.java

@@ -59,7 +59,7 @@ public class TestSimplePhysics extends SimpleApplication {
     public void simpleInitApp() {
         bulletAppState = new BulletAppState();
         stateManager.attach(bulletAppState);
-        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
+        bulletAppState.setDebugEnabled(true);
 
         // Add a physics sphere to the world
         Node physicsSphere = PhysicsTestHelper.createPhysicsTestNode(assetManager, new SphereCollisionShape(1), 1);

+ 3 - 3
jme3-examples/src/main/java/jme3test/bullet/TestSweepTest.java

@@ -35,7 +35,7 @@ public class TestSweepTest extends SimpleApplication {
     public void simpleInitApp() {
         obstacleCollisionShape = new CapsuleCollisionShape(0.3f, 0.5f);
         capsuleCollisionShape = new CapsuleCollisionShape(1f, 1f);
-        
+
         stateManager.attach(bulletAppState);
 
         capsule = new Node("capsule");
@@ -52,7 +52,7 @@ public class TestSweepTest extends SimpleApplication {
         bulletAppState.getPhysicsSpace().add(obstacle);
         rootNode.attachChild(obstacle);
 
-        bulletAppState.getPhysicsSpace().enableDebug(assetManager);
+        bulletAppState.setDebugEnabled(true);
     }
 
     @Override
@@ -70,7 +70,7 @@ public class TestSweepTest extends SimpleApplication {
                 colliding = true;
             }
         }
-        
+
         if (!colliding) {
             // if the sweep is clear then move the spatial
             capsule.move(move, 0, 0);

+ 3 - 20
jme3-examples/src/main/java/jme3test/effect/TestParticleExportingCloning.java

@@ -69,26 +69,9 @@ public class TestParticleExportingCloning extends SimpleApplication {
         rootNode.attachChild(emit);
         rootNode.attachChild(emit2);
         
-        ByteArrayOutputStream out = new ByteArrayOutputStream();
-        try {
-            BinaryExporter.getInstance().save(emit, out);
-            
-            BinaryImporter imp = new BinaryImporter();
-            imp.setAssetManager(assetManager);
-            ParticleEmitter emit3 = (ParticleEmitter) imp.load(out.toByteArray());
-            
-            emit3.move(-3, 0, 0);
-            rootNode.attachChild(emit3);
-        } catch (IOException ex) {
-            ex.printStackTrace();
-        }
-
-            //        Camera cam2 = cam.clone();
-    //        cam.setViewPortTop(0.5f);
-    //        cam2.setViewPortBottom(0.5f);
-    //        ViewPort vp = renderManager.createMainView("SecondView", cam2);
-    //        viewPort.setClearEnabled(false);
-    //        vp.attachScene(rootNode);
+        ParticleEmitter emit3 = BinaryExporter.saveAndLoad(assetManager, emit);
+        emit3.move(-3, 0, 0);
+        rootNode.attachChild(emit3);
     }
 
 }

+ 83 - 0
jme3-examples/src/main/java/jme3test/model/anim/TestModelExportingCloning.java

@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2009-2015 jMonkeyEngine
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ *
+ * * Neither the name of 'jMonkeyEngine' nor the names of its contributors
+ *   may be used to endorse or promote products derived from this software
+ *   without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package jme3test.model.anim;
+
+import com.jme3.animation.AnimChannel;
+import com.jme3.animation.AnimControl;
+import com.jme3.app.SimpleApplication;
+import com.jme3.export.binary.BinaryExporter;
+import com.jme3.light.DirectionalLight;
+import com.jme3.math.ColorRGBA;
+import com.jme3.math.Vector3f;
+import com.jme3.scene.Spatial;
+
+public class TestModelExportingCloning extends SimpleApplication {
+    
+    public static void main(String[] args) {
+        TestModelExportingCloning app = new TestModelExportingCloning();
+        app.start();
+    }
+
+    @Override
+    public void simpleInitApp() {
+        cam.setLocation(new Vector3f(10f, 3f, 40f));
+        cam.lookAtDirection(Vector3f.UNIT_Z.negate(), Vector3f.UNIT_Y);
+
+        DirectionalLight dl = new DirectionalLight();
+        dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
+        dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
+        rootNode.addLight(dl);
+
+        AnimControl control;
+        AnimChannel channel;
+        
+        Spatial originalModel = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
+        control = originalModel.getControl(AnimControl.class);
+        channel = control.createChannel();
+        channel.setAnim("Walk");
+        rootNode.attachChild(originalModel);
+        
+        Spatial clonedModel = originalModel.clone();
+        clonedModel.move(10, 0, 0);
+        control = clonedModel.getControl(AnimControl.class);
+        channel = control.createChannel();
+        channel.setAnim("push");
+        rootNode.attachChild(clonedModel);
+        
+        Spatial exportedModel = BinaryExporter.saveAndLoad(assetManager, originalModel);
+        exportedModel.move(20, 0, 0);
+        control = exportedModel.getControl(AnimControl.class);
+        channel = control.createChannel();
+        channel.setAnim("pull");
+        rootNode.attachChild(exportedModel);
+    }
+}

+ 2 - 2
jme3-examples/src/main/resources/jme3test/texture/UnshadedArray.frag

@@ -1,5 +1,5 @@
 #extension GL_EXT_texture_array : enable
-#extension GL_EXT_gpu_shader4 : enable
+// #extension GL_EXT_gpu_shader4 : enable
 
 uniform vec4 m_Color;
 
@@ -8,7 +8,7 @@ uniform vec4 m_Color;
 #endif
 
 #ifdef HAS_COLORMAP
-    #if !defined(GL_EXT_texture_array) && !defined(GL_EXT_gpu_shader4)
+    #if !defined(GL_EXT_texture_array)
         #error Texture arrays are not supported, but required for this shader.
     #endif
 

+ 6 - 0
jme3-ios/src/main/java/com/jme3/asset/IOS.cfg

@@ -2,3 +2,9 @@ INCLUDE com/jme3/asset/General.cfg
 
 # IOS specific loaders
 LOADER com.jme3.system.ios.IosImageLoader : jpg, bmp, gif, png, jpeg
+LOADER com.jme3.audio.plugins.OGGLoader : ogg
+LOADER com.jme3.material.plugins.J3MLoader : j3m
+LOADER com.jme3.material.plugins.J3MLoader : j3md
+LOADER com.jme3.shader.plugins.GLSLLoader : vert, frag, glsl, glsllib
+LOADER com.jme3.export.binary.BinaryImporter : j3o
+LOADER com.jme3.font.plugins.BitmapFontLoader : fnt

+ 0 - 1054
jme3-ios/src/main/java/com/jme3/audio/android/AL.java

@@ -1,1054 +0,0 @@
-package com.jme3.audio.android;
-
-/**
- *
- * @author iwgeric
- */
-public class AL {
-
-
-
-    /* ********** */
-    /* FROM ALC.h */
-    /* ********** */
-
-//    typedef struct ALCdevice_struct ALCdevice;
-//    typedef struct ALCcontext_struct ALCcontext;
-
-
-    /**
-     * No error
-     */
-    static final int ALC_NO_ERROR = 0;
-
-    /**
-     * No device
-     */
-    static final int ALC_INVALID_DEVICE = 0xA001;
-
-    /**
-     * invalid context ID
-     */
-    static final int ALC_INVALID_CONTEXT = 0xA002;
-
-    /**
-     * bad enum
-     */
-    static final int ALC_INVALID_ENUM = 0xA003;
-
-    /**
-     * bad value
-     */
-    static final int ALC_INVALID_VALUE = 0xA004;
-
-    /**
-     * Out of memory.
-     */
-    static final int ALC_OUT_OF_MEMORY = 0xA005;
-
-
-    /**
-     * The Specifier string for default device
-     */
-    static final int ALC_DEFAULT_DEVICE_SPECIFIER = 0x1004;
-    static final int ALC_DEVICE_SPECIFIER = 0x1005;
-    static final int ALC_EXTENSIONS = 0x1006;
-
-    static final int ALC_MAJOR_VERSION = 0x1000;
-    static final int ALC_MINOR_VERSION = 0x1001;
-
-    static final int ALC_ATTRIBUTES_SIZE = 0x1002;
-    static final int ALC_ALL_ATTRIBUTES = 0x1003;
-
-
-    /**
-     * Capture extension
-     */
-    static final int ALC_EXT_CAPTURE = 1;
-    static final int ALC_CAPTURE_DEVICE_SPECIFIER = 0x310;
-    static final int ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER = 0x311;
-    static final int ALC_CAPTURE_SAMPLES = 0x312;
-
-
-    /**
-     * ALC_ENUMERATE_ALL_EXT enums
-     */
-    static final int ALC_ENUMERATE_ALL_EXT = 1;
-    static final int ALC_DEFAULT_ALL_DEVICES_SPECIFIER = 0x1012;
-    static final int ALC_ALL_DEVICES_SPECIFIER = 0x1013;
-
-
-    /* ********** */
-    /* FROM AL.h */
-    /* ********** */
-
-/** Boolean False. */
-    static final int AL_FALSE = 0;
-
-/** Boolean True. */
-    static final int AL_TRUE = 1;
-
-/* "no distance model" or "no buffer" */
-    static final int AL_NONE = 0;
-
-/** Indicate Source has relative coordinates. */
-    static final int AL_SOURCE_RELATIVE = 0x202;
-
-
-
-/**
- * Directional source, inner cone angle, in degrees.
- * Range:    [0-360]
- * Default:  360
- */
-    static final int AL_CONE_INNER_ANGLE = 0x1001;
-
-/**
- * Directional source, outer cone angle, in degrees.
- * Range:    [0-360]
- * Default:  360
- */
-    static final int AL_CONE_OUTER_ANGLE = 0x1002;
-
-/**
- * Specify the pitch to be applied at source.
- * Range:   [0.5-2.0]
- * Default: 1.0
- */
-    static final int AL_PITCH = 0x1003;
-
-/**
- * Specify the current location in three dimensional space.
- * OpenAL, like OpenGL, uses a right handed coordinate system,
- *  where in a frontal default view X (thumb) points right,
- *  Y points up (index finger), and Z points towards the
- *  viewer/camera (middle finger).
- * To switch from a left handed coordinate system, flip the
- *  sign on the Z coordinate.
- * Listener position is always in the world coordinate system.
- */
-    static final int AL_POSITION = 0x1004;
-
-/** Specify the current direction. */
-    static final int AL_DIRECTION = 0x1005;
-
-/** Specify the current velocity in three dimensional space. */
-    static final int AL_VELOCITY = 0x1006;
-
-/**
- * Indicate whether source is looping.
- * Type: ALboolean?
- * Range:   [AL_TRUE, AL_FALSE]
- * Default: FALSE.
- */
-    static final int AL_LOOPING = 0x1007;
-
-/**
- * Indicate the buffer to provide sound samples.
- * Type: ALuint.
- * Range: any valid Buffer id.
- */
-    static final int AL_BUFFER = 0x1009;
-
-/**
- * Indicate the gain (volume amplification) applied.
- * Type:   ALfloat.
- * Range:  ]0.0-  ]
- * A value of 1.0 means un-attenuated/unchanged.
- * Each division by 2 equals an attenuation of -6dB.
- * Each multiplicaton with 2 equals an amplification of +6dB.
- * A value of 0.0 is meaningless with respect to a logarithmic
- *  scale; it is interpreted as zero volume - the channel
- *  is effectively disabled.
- */
-    static final int AL_GAIN = 0x100A;
-
-/*
- * Indicate minimum source attenuation
- * Type: ALfloat
- * Range:  [0.0 - 1.0]
- *
- * Logarthmic
- */
-    static final int AL_MIN_GAIN = 0x100D;
-
-/**
- * Indicate maximum source attenuation
- * Type: ALfloat
- * Range:  [0.0 - 1.0]
- *
- * Logarthmic
- */
-    static final int AL_MAX_GAIN = 0x100E;
-
-/**
- * Indicate listener orientation.
- *
- * at/up
- */
-    static final int AL_ORIENTATION = 0x100F;
-
-/**
- * Source state information.
- */
-    static final int AL_SOURCE_STATE = 0x1010;
-    static final int AL_INITIAL = 0x1011;
-    static final int AL_PLAYING = 0x1012;
-    static final int AL_PAUSED = 0x1013;
-    static final int AL_STOPPED = 0x1014;
-
-/**
- * Buffer Queue params
- */
-    static final int AL_BUFFERS_QUEUED = 0x1015;
-    static final int AL_BUFFERS_PROCESSED = 0x1016;
-
-/**
- * Source buffer position information
- */
-    static final int AL_SEC_OFFSET = 0x1024;
-    static final int AL_SAMPLE_OFFSET = 0x1025;
-    static final int AL_BYTE_OFFSET = 0x1026;
-
-/*
- * Source type (Static, Streaming or undetermined)
- * Source is Static if a Buffer has been attached using AL_BUFFER
- * Source is Streaming if one or more Buffers have been attached using alSourceQueueBuffers
- * Source is undetermined when it has the NULL buffer attached
- */
-    static final int AL_SOURCE_TYPE = 0x1027;
-    static final int AL_STATIC = 0x1028;
-    static final int AL_STREAMING = 0x1029;
-    static final int AL_UNDETERMINED = 0x1030;
-
-/** Sound samples: format specifier. */
-    static final int AL_FORMAT_MONO8 = 0x1100;
-    static final int AL_FORMAT_MONO16 = 0x1101;
-    static final int AL_FORMAT_STEREO8 = 0x1102;
-    static final int AL_FORMAT_STEREO16 = 0x1103;
-
-/**
- * source specific reference distance
- * Type: ALfloat
- * Range:  0.0 - +inf
- *
- * At 0.0, no distance attenuation occurs.  Default is
- * 1.0.
- */
-    static final int AL_REFERENCE_DISTANCE = 0x1020;
-
-/**
- * source specific rolloff factor
- * Type: ALfloat
- * Range:  0.0 - +inf
- *
- */
-    static final int AL_ROLLOFF_FACTOR = 0x1021;
-
-/**
- * Directional source, outer cone gain.
- *
- * Default:  0.0
- * Range:    [0.0 - 1.0]
- * Logarithmic
- */
-    static final int AL_CONE_OUTER_GAIN = 0x1022;
-
-/**
- * Indicate distance above which sources are not
- * attenuated using the inverse clamped distance model.
- *
- * Default: +inf
- * Type: ALfloat
- * Range:  0.0 - +inf
- */
-    static final int AL_MAX_DISTANCE = 0x1023;
-
-/**
- * Sound samples: frequency, in units of Hertz [Hz].
- * This is the number of samples per second. Half of the
- *  sample frequency marks the maximum significant
- *  frequency component.
- */
-    static final int AL_FREQUENCY = 0x2001;
-    static final int AL_BITS = 0x2002;
-    static final int AL_CHANNELS = 0x2003;
-    static final int AL_SIZE = 0x2004;
-
-/**
- * Buffer state.
- *
- * Not supported for public use (yet).
- */
-    static final int AL_UNUSED = 0x2010;
-    static final int AL_PENDING = 0x2011;
-    static final int AL_PROCESSED = 0x2012;
-
-
-/** Errors: No Error. */
-    static final int AL_NO_ERROR = 0;
-
-/**
- * Invalid Name paramater passed to AL call.
- */
-    static final int AL_INVALID_NAME = 0xA001;
-
-/**
- * Invalid parameter passed to AL call.
- */
-    static final int AL_INVALID_ENUM = 0xA002;
-
-/**
- * Invalid enum parameter value.
- */
-    static final int AL_INVALID_VALUE = 0xA003;
-
-/**
- * Illegal call.
- */
-    static final int AL_INVALID_OPERATION = 0xA004;
-
-
-/**
- * No mojo.
- */
-    static final int AL_OUT_OF_MEMORY = 0xA005;
-
-
-/** Context strings: Vendor Name. */
-    static final int AL_VENDOR = 0xB001;
-    static final int AL_VERSION = 0xB002;
-    static final int AL_RENDERER = 0xB003;
-    static final int AL_EXTENSIONS = 0xB004;
-
-/** Global tweakage. */
-
-/**
- * Doppler scale.  Default 1.0
- */
-    static final int AL_DOPPLER_FACTOR = 0xC000;
-
-/**
- * Tweaks speed of propagation.
- */
-    static final int AL_DOPPLER_VELOCITY = 0xC001;
-
-/**
- * Speed of Sound in units per second
- */
-    static final int AL_SPEED_OF_SOUND = 0xC003;
-
-/**
- * Distance models
- *
- * used in conjunction with DistanceModel
- *
- * implicit: NONE, which disances distance attenuation.
- */
-    static final int AL_DISTANCE_MODEL = 0xD000;
-    static final int AL_INVERSE_DISTANCE = 0xD001;
-    static final int AL_INVERSE_DISTANCE_CLAMPED = 0xD002;
-    static final int AL_LINEAR_DISTANCE = 0xD003;
-    static final int AL_LINEAR_DISTANCE_CLAMPED = 0xD004;
-    static final int AL_EXPONENT_DISTANCE = 0xD005;
-    static final int AL_EXPONENT_DISTANCE_CLAMPED = 0xD006;
-
-    /* ********** */
-    /* FROM efx.h */
-    /* ********** */
-
-    static final String ALC_EXT_EFX_NAME = "ALC_EXT_EFX";
-
-    static final int ALC_EFX_MAJOR_VERSION = 0x20001;
-    static final int ALC_EFX_MINOR_VERSION = 0x20002;
-    static final int ALC_MAX_AUXILIARY_SENDS  = 0x20003;
-
-
-///* Listener properties. */
-//#define AL_METERS_PER_UNIT                       0x20004
-//
-///* Source properties. */
-    static final int AL_DIRECT_FILTER = 0x20005;
-    static final int AL_AUXILIARY_SEND_FILTER = 0x20006;
-//#define AL_AIR_ABSORPTION_FACTOR                 0x20007
-//#define AL_ROOM_ROLLOFF_FACTOR                   0x20008
-//#define AL_CONE_OUTER_GAINHF                     0x20009
-    static final int AL_DIRECT_FILTER_GAINHF_AUTO = 0x2000A;
-//#define AL_AUXILIARY_SEND_FILTER_GAIN_AUTO       0x2000B
-//#define AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO     0x2000C
-//
-//
-///* Effect properties. */
-//
-///* Reverb effect parameters */
-    static final int AL_REVERB_DENSITY = 0x0001;
-    static final int AL_REVERB_DIFFUSION = 0x0002;
-    static final int AL_REVERB_GAIN = 0x0003;
-    static final int AL_REVERB_GAINHF = 0x0004;
-    static final int AL_REVERB_DECAY_TIME = 0x0005;
-    static final int AL_REVERB_DECAY_HFRATIO = 0x0006;
-    static final int AL_REVERB_REFLECTIONS_GAIN = 0x0007;
-    static final int AL_REVERB_REFLECTIONS_DELAY = 0x0008;
-    static final int AL_REVERB_LATE_REVERB_GAIN = 0x0009;
-    static final int AL_REVERB_LATE_REVERB_DELAY = 0x000A;
-    static final int AL_REVERB_AIR_ABSORPTION_GAINHF = 0x000B;
-    static final int AL_REVERB_ROOM_ROLLOFF_FACTOR = 0x000C;
-    static final int AL_REVERB_DECAY_HFLIMIT = 0x000D;
-
-///* EAX Reverb effect parameters */
-//#define AL_EAXREVERB_DENSITY                     0x0001
-//#define AL_EAXREVERB_DIFFUSION                   0x0002
-//#define AL_EAXREVERB_GAIN                        0x0003
-//#define AL_EAXREVERB_GAINHF                      0x0004
-//#define AL_EAXREVERB_GAINLF                      0x0005
-//#define AL_EAXREVERB_DECAY_TIME                  0x0006
-//#define AL_EAXREVERB_DECAY_HFRATIO               0x0007
-//#define AL_EAXREVERB_DECAY_LFRATIO               0x0008
-//#define AL_EAXREVERB_REFLECTIONS_GAIN            0x0009
-//#define AL_EAXREVERB_REFLECTIONS_DELAY           0x000A
-//#define AL_EAXREVERB_REFLECTIONS_PAN             0x000B
-//#define AL_EAXREVERB_LATE_REVERB_GAIN            0x000C
-//#define AL_EAXREVERB_LATE_REVERB_DELAY           0x000D
-//#define AL_EAXREVERB_LATE_REVERB_PAN             0x000E
-//#define AL_EAXREVERB_ECHO_TIME                   0x000F
-//#define AL_EAXREVERB_ECHO_DEPTH                  0x0010
-//#define AL_EAXREVERB_MODULATION_TIME             0x0011
-//#define AL_EAXREVERB_MODULATION_DEPTH            0x0012
-//#define AL_EAXREVERB_AIR_ABSORPTION_GAINHF       0x0013
-//#define AL_EAXREVERB_HFREFERENCE                 0x0014
-//#define AL_EAXREVERB_LFREFERENCE                 0x0015
-//#define AL_EAXREVERB_ROOM_ROLLOFF_FACTOR         0x0016
-//#define AL_EAXREVERB_DECAY_HFLIMIT               0x0017
-//
-///* Chorus effect parameters */
-//#define AL_CHORUS_WAVEFORM                       0x0001
-//#define AL_CHORUS_PHASE                          0x0002
-//#define AL_CHORUS_RATE                           0x0003
-//#define AL_CHORUS_DEPTH                          0x0004
-//#define AL_CHORUS_FEEDBACK                       0x0005
-//#define AL_CHORUS_DELAY                          0x0006
-//
-///* Distortion effect parameters */
-//#define AL_DISTORTION_EDGE                       0x0001
-//#define AL_DISTORTION_GAIN                       0x0002
-//#define AL_DISTORTION_LOWPASS_CUTOFF             0x0003
-//#define AL_DISTORTION_EQCENTER                   0x0004
-//#define AL_DISTORTION_EQBANDWIDTH                0x0005
-//
-///* Echo effect parameters */
-//#define AL_ECHO_DELAY                            0x0001
-//#define AL_ECHO_LRDELAY                          0x0002
-//#define AL_ECHO_DAMPING                          0x0003
-//#define AL_ECHO_FEEDBACK                         0x0004
-//#define AL_ECHO_SPREAD                           0x0005
-//
-///* Flanger effect parameters */
-//#define AL_FLANGER_WAVEFORM                      0x0001
-//#define AL_FLANGER_PHASE                         0x0002
-//#define AL_FLANGER_RATE                          0x0003
-//#define AL_FLANGER_DEPTH                         0x0004
-//#define AL_FLANGER_FEEDBACK                      0x0005
-//#define AL_FLANGER_DELAY                         0x0006
-//
-///* Frequency shifter effect parameters */
-//#define AL_FREQUENCY_SHIFTER_FREQUENCY           0x0001
-//#define AL_FREQUENCY_SHIFTER_LEFT_DIRECTION      0x0002
-//#define AL_FREQUENCY_SHIFTER_RIGHT_DIRECTION     0x0003
-//
-///* Vocal morpher effect parameters */
-//#define AL_VOCAL_MORPHER_PHONEMEA                0x0001
-//#define AL_VOCAL_MORPHER_PHONEMEA_COARSE_TUNING  0x0002
-//#define AL_VOCAL_MORPHER_PHONEMEB                0x0003
-//#define AL_VOCAL_MORPHER_PHONEMEB_COARSE_TUNING  0x0004
-//#define AL_VOCAL_MORPHER_WAVEFORM                0x0005
-//#define AL_VOCAL_MORPHER_RATE                    0x0006
-//
-///* Pitchshifter effect parameters */
-//#define AL_PITCH_SHIFTER_COARSE_TUNE             0x0001
-//#define AL_PITCH_SHIFTER_FINE_TUNE               0x0002
-//
-///* Ringmodulator effect parameters */
-//#define AL_RING_MODULATOR_FREQUENCY              0x0001
-//#define AL_RING_MODULATOR_HIGHPASS_CUTOFF        0x0002
-//#define AL_RING_MODULATOR_WAVEFORM               0x0003
-//
-///* Autowah effect parameters */
-//#define AL_AUTOWAH_ATTACK_TIME                   0x0001
-//#define AL_AUTOWAH_RELEASE_TIME                  0x0002
-//#define AL_AUTOWAH_RESONANCE                     0x0003
-//#define AL_AUTOWAH_PEAK_GAIN                     0x0004
-//
-///* Compressor effect parameters */
-//#define AL_COMPRESSOR_ONOFF                      0x0001
-//
-///* Equalizer effect parameters */
-//#define AL_EQUALIZER_LOW_GAIN                    0x0001
-//#define AL_EQUALIZER_LOW_CUTOFF                  0x0002
-//#define AL_EQUALIZER_MID1_GAIN                   0x0003
-//#define AL_EQUALIZER_MID1_CENTER                 0x0004
-//#define AL_EQUALIZER_MID1_WIDTH                  0x0005
-//#define AL_EQUALIZER_MID2_GAIN                   0x0006
-//#define AL_EQUALIZER_MID2_CENTER                 0x0007
-//#define AL_EQUALIZER_MID2_WIDTH                  0x0008
-//#define AL_EQUALIZER_HIGH_GAIN                   0x0009
-//#define AL_EQUALIZER_HIGH_CUTOFF                 0x000A
-//
-///* Effect type */
-//#define AL_EFFECT_FIRST_PARAMETER                0x0000
-//#define AL_EFFECT_LAST_PARAMETER                 0x8000
-    static final int AL_EFFECT_TYPE = 0x8001;
-//
-///* Effect types, used with the AL_EFFECT_TYPE property */
-//#define AL_EFFECT_NULL                           0x0000
-    static final int AL_EFFECT_REVERB = 0x0001;
-//#define AL_EFFECT_CHORUS                         0x0002
-//#define AL_EFFECT_DISTORTION                     0x0003
-//#define AL_EFFECT_ECHO                           0x0004
-//#define AL_EFFECT_FLANGER                        0x0005
-//#define AL_EFFECT_FREQUENCY_SHIFTER              0x0006
-//#define AL_EFFECT_VOCAL_MORPHER                  0x0007
-//#define AL_EFFECT_PITCH_SHIFTER                  0x0008
-//#define AL_EFFECT_RING_MODULATOR                 0x0009
-//#define AL_EFFECT_AUTOWAH                        0x000A
-//#define AL_EFFECT_COMPRESSOR                     0x000B
-//#define AL_EFFECT_EQUALIZER                      0x000C
-//#define AL_EFFECT_EAXREVERB                      0x8000
-//
-///* Auxiliary Effect Slot properties. */
-    static final int AL_EFFECTSLOT_EFFECT = 0x0001;
-//#define AL_EFFECTSLOT_GAIN                       0x0002
-//#define AL_EFFECTSLOT_AUXILIARY_SEND_AUTO        0x0003
-//
-///* NULL Auxiliary Slot ID to disable a source send. */
-//#define AL_EFFECTSLOT_NULL                       0x0000
-//
-//
-///* Filter properties. */
-//
-///* Lowpass filter parameters */
-    static final int AL_LOWPASS_GAIN = 0x0001;
-    static final int AL_LOWPASS_GAINHF = 0x0002;
-//
-///* Highpass filter parameters */
-//#define AL_HIGHPASS_GAIN                         0x0001
-//#define AL_HIGHPASS_GAINLF                       0x0002
-//
-///* Bandpass filter parameters */
-//#define AL_BANDPASS_GAIN                         0x0001
-//#define AL_BANDPASS_GAINLF                       0x0002
-//#define AL_BANDPASS_GAINHF                       0x0003
-//
-///* Filter type */
-//#define AL_FILTER_FIRST_PARAMETER                0x0000
-//#define AL_FILTER_LAST_PARAMETER                 0x8000
-    static final int AL_FILTER_TYPE = 0x8001;
-//
-///* Filter types, used with the AL_FILTER_TYPE property */
-    static final int AL_FILTER_NULL = 0x0000;
-    static final int AL_FILTER_LOWPASS = 0x0001;
-    static final int AL_FILTER_HIGHPASS = 0x0002;
-//#define AL_FILTER_BANDPASS                       0x0003
-//
-///* Filter ranges and defaults. */
-//
-///* Lowpass filter */
-//#define AL_LOWPASS_MIN_GAIN                      (0.0f)
-//#define AL_LOWPASS_MAX_GAIN                      (1.0f)
-//#define AL_LOWPASS_DEFAULT_GAIN                  (1.0f)
-//
-//#define AL_LOWPASS_MIN_GAINHF                    (0.0f)
-//#define AL_LOWPASS_MAX_GAINHF                    (1.0f)
-//#define AL_LOWPASS_DEFAULT_GAINHF                (1.0f)
-//
-///* Highpass filter */
-//#define AL_HIGHPASS_MIN_GAIN                     (0.0f)
-//#define AL_HIGHPASS_MAX_GAIN                     (1.0f)
-//#define AL_HIGHPASS_DEFAULT_GAIN                 (1.0f)
-//
-//#define AL_HIGHPASS_MIN_GAINLF                   (0.0f)
-//#define AL_HIGHPASS_MAX_GAINLF                   (1.0f)
-//#define AL_HIGHPASS_DEFAULT_GAINLF               (1.0f)
-//
-///* Bandpass filter */
-//#define AL_BANDPASS_MIN_GAIN                     (0.0f)
-//#define AL_BANDPASS_MAX_GAIN                     (1.0f)
-//#define AL_BANDPASS_DEFAULT_GAIN                 (1.0f)
-//
-//#define AL_BANDPASS_MIN_GAINHF                   (0.0f)
-//#define AL_BANDPASS_MAX_GAINHF                   (1.0f)
-//#define AL_BANDPASS_DEFAULT_GAINHF               (1.0f)
-//
-//#define AL_BANDPASS_MIN_GAINLF                   (0.0f)
-//#define AL_BANDPASS_MAX_GAINLF                   (1.0f)
-//#define AL_BANDPASS_DEFAULT_GAINLF               (1.0f)
-//
-//
-///* Effect parameter ranges and defaults. */
-//
-///* Standard reverb effect */
-//#define AL_REVERB_MIN_DENSITY                    (0.0f)
-//#define AL_REVERB_MAX_DENSITY                    (1.0f)
-//#define AL_REVERB_DEFAULT_DENSITY                (1.0f)
-//
-//#define AL_REVERB_MIN_DIFFUSION                  (0.0f)
-//#define AL_REVERB_MAX_DIFFUSION                  (1.0f)
-//#define AL_REVERB_DEFAULT_DIFFUSION              (1.0f)
-//
-//#define AL_REVERB_MIN_GAIN                       (0.0f)
-//#define AL_REVERB_MAX_GAIN                       (1.0f)
-//#define AL_REVERB_DEFAULT_GAIN                   (0.32f)
-//
-//#define AL_REVERB_MIN_GAINHF                     (0.0f)
-//#define AL_REVERB_MAX_GAINHF                     (1.0f)
-//#define AL_REVERB_DEFAULT_GAINHF                 (0.89f)
-//
-//#define AL_REVERB_MIN_DECAY_TIME                 (0.1f)
-//#define AL_REVERB_MAX_DECAY_TIME                 (20.0f)
-//#define AL_REVERB_DEFAULT_DECAY_TIME             (1.49f)
-//
-//#define AL_REVERB_MIN_DECAY_HFRATIO              (0.1f)
-//#define AL_REVERB_MAX_DECAY_HFRATIO              (2.0f)
-//#define AL_REVERB_DEFAULT_DECAY_HFRATIO          (0.83f)
-//
-//#define AL_REVERB_MIN_REFLECTIONS_GAIN           (0.0f)
-//#define AL_REVERB_MAX_REFLECTIONS_GAIN           (3.16f)
-//#define AL_REVERB_DEFAULT_REFLECTIONS_GAIN       (0.05f)
-//
-//#define AL_REVERB_MIN_REFLECTIONS_DELAY          (0.0f)
-//#define AL_REVERB_MAX_REFLECTIONS_DELAY          (0.3f)
-//#define AL_REVERB_DEFAULT_REFLECTIONS_DELAY      (0.007f)
-//
-//#define AL_REVERB_MIN_LATE_REVERB_GAIN           (0.0f)
-//#define AL_REVERB_MAX_LATE_REVERB_GAIN           (10.0f)
-//#define AL_REVERB_DEFAULT_LATE_REVERB_GAIN       (1.26f)
-//
-//#define AL_REVERB_MIN_LATE_REVERB_DELAY          (0.0f)
-//#define AL_REVERB_MAX_LATE_REVERB_DELAY          (0.1f)
-//#define AL_REVERB_DEFAULT_LATE_REVERB_DELAY      (0.011f)
-//
-//#define AL_REVERB_MIN_AIR_ABSORPTION_GAINHF      (0.892f)
-//#define AL_REVERB_MAX_AIR_ABSORPTION_GAINHF      (1.0f)
-//#define AL_REVERB_DEFAULT_AIR_ABSORPTION_GAINHF  (0.994f)
-//
-//#define AL_REVERB_MIN_ROOM_ROLLOFF_FACTOR        (0.0f)
-//#define AL_REVERB_MAX_ROOM_ROLLOFF_FACTOR        (10.0f)
-//#define AL_REVERB_DEFAULT_ROOM_ROLLOFF_FACTOR    (0.0f)
-//
-//#define AL_REVERB_MIN_DECAY_HFLIMIT              AL_FALSE
-//#define AL_REVERB_MAX_DECAY_HFLIMIT              AL_TRUE
-//#define AL_REVERB_DEFAULT_DECAY_HFLIMIT          AL_TRUE
-//
-///* EAX reverb effect */
-//#define AL_EAXREVERB_MIN_DENSITY                 (0.0f)
-//#define AL_EAXREVERB_MAX_DENSITY                 (1.0f)
-//#define AL_EAXREVERB_DEFAULT_DENSITY             (1.0f)
-//
-//#define AL_EAXREVERB_MIN_DIFFUSION               (0.0f)
-//#define AL_EAXREVERB_MAX_DIFFUSION               (1.0f)
-//#define AL_EAXREVERB_DEFAULT_DIFFUSION           (1.0f)
-//
-//#define AL_EAXREVERB_MIN_GAIN                    (0.0f)
-//#define AL_EAXREVERB_MAX_GAIN                    (1.0f)
-//#define AL_EAXREVERB_DEFAULT_GAIN                (0.32f)
-//
-//#define AL_EAXREVERB_MIN_GAINHF                  (0.0f)
-//#define AL_EAXREVERB_MAX_GAINHF                  (1.0f)
-//#define AL_EAXREVERB_DEFAULT_GAINHF              (0.89f)
-//
-//#define AL_EAXREVERB_MIN_GAINLF                  (0.0f)
-//#define AL_EAXREVERB_MAX_GAINLF                  (1.0f)
-//#define AL_EAXREVERB_DEFAULT_GAINLF              (1.0f)
-//
-//#define AL_EAXREVERB_MIN_DECAY_TIME              (0.1f)
-//#define AL_EAXREVERB_MAX_DECAY_TIME              (20.0f)
-//#define AL_EAXREVERB_DEFAULT_DECAY_TIME          (1.49f)
-//
-//#define AL_EAXREVERB_MIN_DECAY_HFRATIO           (0.1f)
-//#define AL_EAXREVERB_MAX_DECAY_HFRATIO           (2.0f)
-//#define AL_EAXREVERB_DEFAULT_DECAY_HFRATIO       (0.83f)
-//
-//#define AL_EAXREVERB_MIN_DECAY_LFRATIO           (0.1f)
-//#define AL_EAXREVERB_MAX_DECAY_LFRATIO           (2.0f)
-//#define AL_EAXREVERB_DEFAULT_DECAY_LFRATIO       (1.0f)
-//
-//#define AL_EAXREVERB_MIN_REFLECTIONS_GAIN        (0.0f)
-//#define AL_EAXREVERB_MAX_REFLECTIONS_GAIN        (3.16f)
-//#define AL_EAXREVERB_DEFAULT_REFLECTIONS_GAIN    (0.05f)
-//
-//#define AL_EAXREVERB_MIN_REFLECTIONS_DELAY       (0.0f)
-//#define AL_EAXREVERB_MAX_REFLECTIONS_DELAY       (0.3f)
-//#define AL_EAXREVERB_DEFAULT_REFLECTIONS_DELAY   (0.007f)
-//
-//#define AL_EAXREVERB_DEFAULT_REFLECTIONS_PAN_XYZ (0.0f)
-//
-//#define AL_EAXREVERB_MIN_LATE_REVERB_GAIN        (0.0f)
-//#define AL_EAXREVERB_MAX_LATE_REVERB_GAIN        (10.0f)
-//#define AL_EAXREVERB_DEFAULT_LATE_REVERB_GAIN    (1.26f)
-//
-//#define AL_EAXREVERB_MIN_LATE_REVERB_DELAY       (0.0f)
-//#define AL_EAXREVERB_MAX_LATE_REVERB_DELAY       (0.1f)
-//#define AL_EAXREVERB_DEFAULT_LATE_REVERB_DELAY   (0.011f)
-//
-//#define AL_EAXREVERB_DEFAULT_LATE_REVERB_PAN_XYZ (0.0f)
-//
-//#define AL_EAXREVERB_MIN_ECHO_TIME               (0.075f)
-//#define AL_EAXREVERB_MAX_ECHO_TIME               (0.25f)
-//#define AL_EAXREVERB_DEFAULT_ECHO_TIME           (0.25f)
-//
-//#define AL_EAXREVERB_MIN_ECHO_DEPTH              (0.0f)
-//#define AL_EAXREVERB_MAX_ECHO_DEPTH              (1.0f)
-//#define AL_EAXREVERB_DEFAULT_ECHO_DEPTH          (0.0f)
-//
-//#define AL_EAXREVERB_MIN_MODULATION_TIME         (0.04f)
-//#define AL_EAXREVERB_MAX_MODULATION_TIME         (4.0f)
-//#define AL_EAXREVERB_DEFAULT_MODULATION_TIME     (0.25f)
-//
-//#define AL_EAXREVERB_MIN_MODULATION_DEPTH        (0.0f)
-//#define AL_EAXREVERB_MAX_MODULATION_DEPTH        (1.0f)
-//#define AL_EAXREVERB_DEFAULT_MODULATION_DEPTH    (0.0f)
-//
-//#define AL_EAXREVERB_MIN_AIR_ABSORPTION_GAINHF   (0.892f)
-//#define AL_EAXREVERB_MAX_AIR_ABSORPTION_GAINHF   (1.0f)
-//#define AL_EAXREVERB_DEFAULT_AIR_ABSORPTION_GAINHF (0.994f)
-//
-//#define AL_EAXREVERB_MIN_HFREFERENCE             (1000.0f)
-//#define AL_EAXREVERB_MAX_HFREFERENCE             (20000.0f)
-//#define AL_EAXREVERB_DEFAULT_HFREFERENCE         (5000.0f)
-//
-//#define AL_EAXREVERB_MIN_LFREFERENCE             (20.0f)
-//#define AL_EAXREVERB_MAX_LFREFERENCE             (1000.0f)
-//#define AL_EAXREVERB_DEFAULT_LFREFERENCE         (250.0f)
-//
-//#define AL_EAXREVERB_MIN_ROOM_ROLLOFF_FACTOR     (0.0f)
-//#define AL_EAXREVERB_MAX_ROOM_ROLLOFF_FACTOR     (10.0f)
-//#define AL_EAXREVERB_DEFAULT_ROOM_ROLLOFF_FACTOR (0.0f)
-//
-//#define AL_EAXREVERB_MIN_DECAY_HFLIMIT           AL_FALSE
-//#define AL_EAXREVERB_MAX_DECAY_HFLIMIT           AL_TRUE
-//#define AL_EAXREVERB_DEFAULT_DECAY_HFLIMIT       AL_TRUE
-//
-///* Chorus effect */
-//#define AL_CHORUS_WAVEFORM_SINUSOID              (0)
-//#define AL_CHORUS_WAVEFORM_TRIANGLE              (1)
-//
-//#define AL_CHORUS_MIN_WAVEFORM                   (0)
-//#define AL_CHORUS_MAX_WAVEFORM                   (1)
-//#define AL_CHORUS_DEFAULT_WAVEFORM               (1)
-//
-//#define AL_CHORUS_MIN_PHASE                      (-180)
-//#define AL_CHORUS_MAX_PHASE                      (180)
-//#define AL_CHORUS_DEFAULT_PHASE                  (90)
-//
-//#define AL_CHORUS_MIN_RATE                       (0.0f)
-//#define AL_CHORUS_MAX_RATE                       (10.0f)
-//#define AL_CHORUS_DEFAULT_RATE                   (1.1f)
-//
-//#define AL_CHORUS_MIN_DEPTH                      (0.0f)
-//#define AL_CHORUS_MAX_DEPTH                      (1.0f)
-//#define AL_CHORUS_DEFAULT_DEPTH                  (0.1f)
-//
-//#define AL_CHORUS_MIN_FEEDBACK                   (-1.0f)
-//#define AL_CHORUS_MAX_FEEDBACK                   (1.0f)
-//#define AL_CHORUS_DEFAULT_FEEDBACK               (0.25f)
-//
-//#define AL_CHORUS_MIN_DELAY                      (0.0f)
-//#define AL_CHORUS_MAX_DELAY                      (0.016f)
-//#define AL_CHORUS_DEFAULT_DELAY                  (0.016f)
-//
-///* Distortion effect */
-//#define AL_DISTORTION_MIN_EDGE                   (0.0f)
-//#define AL_DISTORTION_MAX_EDGE                   (1.0f)
-//#define AL_DISTORTION_DEFAULT_EDGE               (0.2f)
-//
-//#define AL_DISTORTION_MIN_GAIN                   (0.01f)
-//#define AL_DISTORTION_MAX_GAIN                   (1.0f)
-//#define AL_DISTORTION_DEFAULT_GAIN               (0.05f)
-//
-//#define AL_DISTORTION_MIN_LOWPASS_CUTOFF         (80.0f)
-//#define AL_DISTORTION_MAX_LOWPASS_CUTOFF         (24000.0f)
-//#define AL_DISTORTION_DEFAULT_LOWPASS_CUTOFF     (8000.0f)
-//
-//#define AL_DISTORTION_MIN_EQCENTER               (80.0f)
-//#define AL_DISTORTION_MAX_EQCENTER               (24000.0f)
-//#define AL_DISTORTION_DEFAULT_EQCENTER           (3600.0f)
-//
-//#define AL_DISTORTION_MIN_EQBANDWIDTH            (80.0f)
-//#define AL_DISTORTION_MAX_EQBANDWIDTH            (24000.0f)
-//#define AL_DISTORTION_DEFAULT_EQBANDWIDTH        (3600.0f)
-//
-///* Echo effect */
-//#define AL_ECHO_MIN_DELAY                        (0.0f)
-//#define AL_ECHO_MAX_DELAY                        (0.207f)
-//#define AL_ECHO_DEFAULT_DELAY                    (0.1f)
-//
-//#define AL_ECHO_MIN_LRDELAY                      (0.0f)
-//#define AL_ECHO_MAX_LRDELAY                      (0.404f)
-//#define AL_ECHO_DEFAULT_LRDELAY                  (0.1f)
-//
-//#define AL_ECHO_MIN_DAMPING                      (0.0f)
-//#define AL_ECHO_MAX_DAMPING                      (0.99f)
-//#define AL_ECHO_DEFAULT_DAMPING                  (0.5f)
-//
-//#define AL_ECHO_MIN_FEEDBACK                     (0.0f)
-//#define AL_ECHO_MAX_FEEDBACK                     (1.0f)
-//#define AL_ECHO_DEFAULT_FEEDBACK                 (0.5f)
-//
-//#define AL_ECHO_MIN_SPREAD                       (-1.0f)
-//#define AL_ECHO_MAX_SPREAD                       (1.0f)
-//#define AL_ECHO_DEFAULT_SPREAD                   (-1.0f)
-//
-///* Flanger effect */
-//#define AL_FLANGER_WAVEFORM_SINUSOID             (0)
-//#define AL_FLANGER_WAVEFORM_TRIANGLE             (1)
-//
-//#define AL_FLANGER_MIN_WAVEFORM                  (0)
-//#define AL_FLANGER_MAX_WAVEFORM                  (1)
-//#define AL_FLANGER_DEFAULT_WAVEFORM              (1)
-//
-//#define AL_FLANGER_MIN_PHASE                     (-180)
-//#define AL_FLANGER_MAX_PHASE                     (180)
-//#define AL_FLANGER_DEFAULT_PHASE                 (0)
-//
-//#define AL_FLANGER_MIN_RATE                      (0.0f)
-//#define AL_FLANGER_MAX_RATE                      (10.0f)
-//#define AL_FLANGER_DEFAULT_RATE                  (0.27f)
-//
-//#define AL_FLANGER_MIN_DEPTH                     (0.0f)
-//#define AL_FLANGER_MAX_DEPTH                     (1.0f)
-//#define AL_FLANGER_DEFAULT_DEPTH                 (1.0f)
-//
-//#define AL_FLANGER_MIN_FEEDBACK                  (-1.0f)
-//#define AL_FLANGER_MAX_FEEDBACK                  (1.0f)
-//#define AL_FLANGER_DEFAULT_FEEDBACK              (-0.5f)
-//
-//#define AL_FLANGER_MIN_DELAY                     (0.0f)
-//#define AL_FLANGER_MAX_DELAY                     (0.004f)
-//#define AL_FLANGER_DEFAULT_DELAY                 (0.002f)
-//
-///* Frequency shifter effect */
-//#define AL_FREQUENCY_SHIFTER_MIN_FREQUENCY       (0.0f)
-//#define AL_FREQUENCY_SHIFTER_MAX_FREQUENCY       (24000.0f)
-//#define AL_FREQUENCY_SHIFTER_DEFAULT_FREQUENCY   (0.0f)
-//
-//#define AL_FREQUENCY_SHIFTER_MIN_LEFT_DIRECTION  (0)
-//#define AL_FREQUENCY_SHIFTER_MAX_LEFT_DIRECTION  (2)
-//#define AL_FREQUENCY_SHIFTER_DEFAULT_LEFT_DIRECTION (0)
-//
-//#define AL_FREQUENCY_SHIFTER_DIRECTION_DOWN      (0)
-//#define AL_FREQUENCY_SHIFTER_DIRECTION_UP        (1)
-//#define AL_FREQUENCY_SHIFTER_DIRECTION_OFF       (2)
-//
-//#define AL_FREQUENCY_SHIFTER_MIN_RIGHT_DIRECTION (0)
-//#define AL_FREQUENCY_SHIFTER_MAX_RIGHT_DIRECTION (2)
-//#define AL_FREQUENCY_SHIFTER_DEFAULT_RIGHT_DIRECTION (0)
-//
-///* Vocal morpher effect */
-//#define AL_VOCAL_MORPHER_MIN_PHONEMEA            (0)
-//#define AL_VOCAL_MORPHER_MAX_PHONEMEA            (29)
-//#define AL_VOCAL_MORPHER_DEFAULT_PHONEMEA        (0)
-//
-//#define AL_VOCAL_MORPHER_MIN_PHONEMEA_COARSE_TUNING (-24)
-//#define AL_VOCAL_MORPHER_MAX_PHONEMEA_COARSE_TUNING (24)
-//#define AL_VOCAL_MORPHER_DEFAULT_PHONEMEA_COARSE_TUNING (0)
-//
-//#define AL_VOCAL_MORPHER_MIN_PHONEMEB            (0)
-//#define AL_VOCAL_MORPHER_MAX_PHONEMEB            (29)
-//#define AL_VOCAL_MORPHER_DEFAULT_PHONEMEB        (10)
-//
-//#define AL_VOCAL_MORPHER_MIN_PHONEMEB_COARSE_TUNING (-24)
-//#define AL_VOCAL_MORPHER_MAX_PHONEMEB_COARSE_TUNING (24)
-//#define AL_VOCAL_MORPHER_DEFAULT_PHONEMEB_COARSE_TUNING (0)
-//
-//#define AL_VOCAL_MORPHER_PHONEME_A               (0)
-//#define AL_VOCAL_MORPHER_PHONEME_E               (1)
-//#define AL_VOCAL_MORPHER_PHONEME_I               (2)
-//#define AL_VOCAL_MORPHER_PHONEME_O               (3)
-//#define AL_VOCAL_MORPHER_PHONEME_U               (4)
-//#define AL_VOCAL_MORPHER_PHONEME_AA              (5)
-//#define AL_VOCAL_MORPHER_PHONEME_AE              (6)
-//#define AL_VOCAL_MORPHER_PHONEME_AH              (7)
-//#define AL_VOCAL_MORPHER_PHONEME_AO              (8)
-//#define AL_VOCAL_MORPHER_PHONEME_EH              (9)
-//#define AL_VOCAL_MORPHER_PHONEME_ER              (10)
-//#define AL_VOCAL_MORPHER_PHONEME_IH              (11)
-//#define AL_VOCAL_MORPHER_PHONEME_IY              (12)
-//#define AL_VOCAL_MORPHER_PHONEME_UH              (13)
-//#define AL_VOCAL_MORPHER_PHONEME_UW              (14)
-//#define AL_VOCAL_MORPHER_PHONEME_B               (15)
-//#define AL_VOCAL_MORPHER_PHONEME_D               (16)
-//#define AL_VOCAL_MORPHER_PHONEME_F               (17)
-//#define AL_VOCAL_MORPHER_PHONEME_G               (18)
-//#define AL_VOCAL_MORPHER_PHONEME_J               (19)
-//#define AL_VOCAL_MORPHER_PHONEME_K               (20)
-//#define AL_VOCAL_MORPHER_PHONEME_L               (21)
-//#define AL_VOCAL_MORPHER_PHONEME_M               (22)
-//#define AL_VOCAL_MORPHER_PHONEME_N               (23)
-//#define AL_VOCAL_MORPHER_PHONEME_P               (24)
-//#define AL_VOCAL_MORPHER_PHONEME_R               (25)
-//#define AL_VOCAL_MORPHER_PHONEME_S               (26)
-//#define AL_VOCAL_MORPHER_PHONEME_T               (27)
-//#define AL_VOCAL_MORPHER_PHONEME_V               (28)
-//#define AL_VOCAL_MORPHER_PHONEME_Z               (29)
-//
-//#define AL_VOCAL_MORPHER_WAVEFORM_SINUSOID       (0)
-//#define AL_VOCAL_MORPHER_WAVEFORM_TRIANGLE       (1)
-//#define AL_VOCAL_MORPHER_WAVEFORM_SAWTOOTH       (2)
-//
-//#define AL_VOCAL_MORPHER_MIN_WAVEFORM            (0)
-//#define AL_VOCAL_MORPHER_MAX_WAVEFORM            (2)
-//#define AL_VOCAL_MORPHER_DEFAULT_WAVEFORM        (0)
-//
-//#define AL_VOCAL_MORPHER_MIN_RATE                (0.0f)
-//#define AL_VOCAL_MORPHER_MAX_RATE                (10.0f)
-//#define AL_VOCAL_MORPHER_DEFAULT_RATE            (1.41f)
-//
-///* Pitch shifter effect */
-//#define AL_PITCH_SHIFTER_MIN_COARSE_TUNE         (-12)
-//#define AL_PITCH_SHIFTER_MAX_COARSE_TUNE         (12)
-//#define AL_PITCH_SHIFTER_DEFAULT_COARSE_TUNE     (12)
-//
-//#define AL_PITCH_SHIFTER_MIN_FINE_TUNE           (-50)
-//#define AL_PITCH_SHIFTER_MAX_FINE_TUNE           (50)
-//#define AL_PITCH_SHIFTER_DEFAULT_FINE_TUNE       (0)
-//
-///* Ring modulator effect */
-//#define AL_RING_MODULATOR_MIN_FREQUENCY          (0.0f)
-//#define AL_RING_MODULATOR_MAX_FREQUENCY          (8000.0f)
-//#define AL_RING_MODULATOR_DEFAULT_FREQUENCY      (440.0f)
-//
-//#define AL_RING_MODULATOR_MIN_HIGHPASS_CUTOFF    (0.0f)
-//#define AL_RING_MODULATOR_MAX_HIGHPASS_CUTOFF    (24000.0f)
-//#define AL_RING_MODULATOR_DEFAULT_HIGHPASS_CUTOFF (800.0f)
-//
-//#define AL_RING_MODULATOR_SINUSOID               (0)
-//#define AL_RING_MODULATOR_SAWTOOTH               (1)
-//#define AL_RING_MODULATOR_SQUARE                 (2)
-//
-//#define AL_RING_MODULATOR_MIN_WAVEFORM           (0)
-//#define AL_RING_MODULATOR_MAX_WAVEFORM           (2)
-//#define AL_RING_MODULATOR_DEFAULT_WAVEFORM       (0)
-//
-///* Autowah effect */
-//#define AL_AUTOWAH_MIN_ATTACK_TIME               (0.0001f)
-//#define AL_AUTOWAH_MAX_ATTACK_TIME               (1.0f)
-//#define AL_AUTOWAH_DEFAULT_ATTACK_TIME           (0.06f)
-//
-//#define AL_AUTOWAH_MIN_RELEASE_TIME              (0.0001f)
-//#define AL_AUTOWAH_MAX_RELEASE_TIME              (1.0f)
-//#define AL_AUTOWAH_DEFAULT_RELEASE_TIME          (0.06f)
-//
-//#define AL_AUTOWAH_MIN_RESONANCE                 (2.0f)
-//#define AL_AUTOWAH_MAX_RESONANCE                 (1000.0f)
-//#define AL_AUTOWAH_DEFAULT_RESONANCE             (1000.0f)
-//
-//#define AL_AUTOWAH_MIN_PEAK_GAIN                 (0.00003f)
-//#define AL_AUTOWAH_MAX_PEAK_GAIN                 (31621.0f)
-//#define AL_AUTOWAH_DEFAULT_PEAK_GAIN             (11.22f)
-//
-///* Compressor effect */
-//#define AL_COMPRESSOR_MIN_ONOFF                  (0)
-//#define AL_COMPRESSOR_MAX_ONOFF                  (1)
-//#define AL_COMPRESSOR_DEFAULT_ONOFF              (1)
-//
-///* Equalizer effect */
-//#define AL_EQUALIZER_MIN_LOW_GAIN                (0.126f)
-//#define AL_EQUALIZER_MAX_LOW_GAIN                (7.943f)
-//#define AL_EQUALIZER_DEFAULT_LOW_GAIN            (1.0f)
-//
-//#define AL_EQUALIZER_MIN_LOW_CUTOFF              (50.0f)
-//#define AL_EQUALIZER_MAX_LOW_CUTOFF              (800.0f)
-//#define AL_EQUALIZER_DEFAULT_LOW_CUTOFF          (200.0f)
-//
-//#define AL_EQUALIZER_MIN_MID1_GAIN               (0.126f)
-//#define AL_EQUALIZER_MAX_MID1_GAIN               (7.943f)
-//#define AL_EQUALIZER_DEFAULT_MID1_GAIN           (1.0f)
-//
-//#define AL_EQUALIZER_MIN_MID1_CENTER             (200.0f)
-//#define AL_EQUALIZER_MAX_MID1_CENTER             (3000.0f)
-//#define AL_EQUALIZER_DEFAULT_MID1_CENTER         (500.0f)
-//
-//#define AL_EQUALIZER_MIN_MID1_WIDTH              (0.01f)
-//#define AL_EQUALIZER_MAX_MID1_WIDTH              (1.0f)
-//#define AL_EQUALIZER_DEFAULT_MID1_WIDTH          (1.0f)
-//
-//#define AL_EQUALIZER_MIN_MID2_GAIN               (0.126f)
-//#define AL_EQUALIZER_MAX_MID2_GAIN               (7.943f)
-//#define AL_EQUALIZER_DEFAULT_MID2_GAIN           (1.0f)
-//
-//#define AL_EQUALIZER_MIN_MID2_CENTER             (1000.0f)
-//#define AL_EQUALIZER_MAX_MID2_CENTER             (8000.0f)
-//#define AL_EQUALIZER_DEFAULT_MID2_CENTER         (3000.0f)
-//
-//#define AL_EQUALIZER_MIN_MID2_WIDTH              (0.01f)
-//#define AL_EQUALIZER_MAX_MID2_WIDTH              (1.0f)
-//#define AL_EQUALIZER_DEFAULT_MID2_WIDTH          (1.0f)
-//
-//#define AL_EQUALIZER_MIN_HIGH_GAIN               (0.126f)
-//#define AL_EQUALIZER_MAX_HIGH_GAIN               (7.943f)
-//#define AL_EQUALIZER_DEFAULT_HIGH_GAIN           (1.0f)
-//
-//#define AL_EQUALIZER_MIN_HIGH_CUTOFF             (4000.0f)
-//#define AL_EQUALIZER_MAX_HIGH_CUTOFF             (16000.0f)
-//#define AL_EQUALIZER_DEFAULT_HIGH_CUTOFF         (6000.0f)
-//
-//
-///* Source parameter value ranges and defaults. */
-//#define AL_MIN_AIR_ABSORPTION_FACTOR             (0.0f)
-//#define AL_MAX_AIR_ABSORPTION_FACTOR             (10.0f)
-//#define AL_DEFAULT_AIR_ABSORPTION_FACTOR         (0.0f)
-//
-//#define AL_MIN_ROOM_ROLLOFF_FACTOR               (0.0f)
-//#define AL_MAX_ROOM_ROLLOFF_FACTOR               (10.0f)
-//#define AL_DEFAULT_ROOM_ROLLOFF_FACTOR           (0.0f)
-//
-//#define AL_MIN_CONE_OUTER_GAINHF                 (0.0f)
-//#define AL_MAX_CONE_OUTER_GAINHF                 (1.0f)
-//#define AL_DEFAULT_CONE_OUTER_GAINHF             (1.0f)
-//
-//#define AL_MIN_DIRECT_FILTER_GAINHF_AUTO         AL_FALSE
-//#define AL_MAX_DIRECT_FILTER_GAINHF_AUTO         AL_TRUE
-//#define AL_DEFAULT_DIRECT_FILTER_GAINHF_AUTO     AL_TRUE
-//
-//#define AL_MIN_AUXILIARY_SEND_FILTER_GAIN_AUTO   AL_FALSE
-//#define AL_MAX_AUXILIARY_SEND_FILTER_GAIN_AUTO   AL_TRUE
-//#define AL_DEFAULT_AUXILIARY_SEND_FILTER_GAIN_AUTO AL_TRUE
-//
-//#define AL_MIN_AUXILIARY_SEND_FILTER_GAINHF_AUTO AL_FALSE
-//#define AL_MAX_AUXILIARY_SEND_FILTER_GAINHF_AUTO AL_TRUE
-//#define AL_DEFAULT_AUXILIARY_SEND_FILTER_GAINHF_AUTO AL_TRUE
-//
-//
-///* Listener parameter value ranges and defaults. */
-//#define AL_MIN_METERS_PER_UNIT                   FLT_MIN
-//#define AL_MAX_METERS_PER_UNIT                   FLT_MAX
-//#define AL_DEFAULT_METERS_PER_UNIT               (1.0f)
-
-
-    public static String GetALErrorMsg(int errorCode) {
-        String errorText;
-        switch (errorCode) {
-            case AL_NO_ERROR:
-                errorText = "No Error";
-                break;
-            case AL_INVALID_NAME:
-                errorText = "Invalid Name";
-                break;
-            case AL_INVALID_ENUM:
-                errorText = "Invalid Enum";
-                break;
-            case AL_INVALID_VALUE:
-                errorText = "Invalid Value";
-                break;
-            case AL_INVALID_OPERATION:
-                errorText = "Invalid Operation";
-                break;
-            case AL_OUT_OF_MEMORY:
-                errorText = "Out of Memory";
-                break;
-            default:
-                errorText = "Unknown Error Code: " + String.valueOf(errorCode);
-        }
-        return errorText;
-    }
-}
-

+ 0 - 67
jme3-ios/src/main/java/com/jme3/audio/android/AndroidAudioData.java

@@ -1,67 +0,0 @@
-package com.jme3.audio.android;
-
-import com.jme3.asset.AssetKey;
-import com.jme3.audio.AudioData;
-import com.jme3.audio.AudioRenderer;
-import com.jme3.util.NativeObject;
-
-public class AndroidAudioData extends AudioData {
-
-    protected AssetKey<?> assetKey;
-    protected float currentVolume = 0f;
-
-    public AndroidAudioData(){
-        super();
-    }
-    
-    protected AndroidAudioData(int id){
-        super(id);
-    }
-    
-    public AssetKey<?> getAssetKey() {
-        return assetKey;
-    }
-
-    public void setAssetKey(AssetKey<?> assetKey) {
-        this.assetKey = assetKey;
-    }
-
-    @Override
-    public DataType getDataType() {
-        return DataType.Buffer;
-    }
-
-    @Override
-    public float getDuration() {
-        return 0; // TODO: ???
-    }
-
-    @Override
-    public void resetObject() {
-        this.id = -1;
-        setUpdateNeeded();  
-    }
-
-    @Override
-    public void deleteObject(Object rendererObject) {
-        ((AudioRenderer)rendererObject).deleteAudioData(this);
-    }
-
-    public float getCurrentVolume() {
-        return currentVolume;
-    }
-
-    public void setCurrentVolume(float currentVolume) {
-        this.currentVolume = currentVolume;
-    }
-
-    @Override
-    public NativeObject createDestructableClone() {
-        return new AndroidAudioData(id);
-    }
-
-    @Override
-    public long getUniqueId() {
-        return ((long)OBJTYPE_AUDIOBUFFER << 32) | ((long)id);
-    }
-}

+ 53 - 0
jme3-ios/src/main/java/com/jme3/audio/ios/IosAL.java

@@ -0,0 +1,53 @@
+package com.jme3.audio.ios;
+
+import com.jme3.audio.openal.AL;
+import java.nio.ByteBuffer;
+import java.nio.FloatBuffer;
+import java.nio.IntBuffer;
+
+public final class IosAL implements AL {
+
+    public IosAL() {
+    }
+
+    public native String alGetString(int parameter);
+
+    public native int alGenSources();
+
+    public native int alGetError();
+
+    public native void alDeleteSources(int numSources, IntBuffer sources);
+
+    public native void alGenBuffers(int numBuffers, IntBuffer buffers);
+
+    public native void alDeleteBuffers(int numBuffers, IntBuffer buffers);
+
+    public native void alSourceStop(int source);
+
+    public native void alSourcei(int source, int param, int value);
+
+    public native void alBufferData(int buffer, int format, ByteBuffer data, int size, int frequency);
+
+    public native void alSourcePlay(int source);
+
+    public native void alSourcePause(int source);
+
+    public native void alSourcef(int source, int param, float value);
+
+    public native void alSource3f(int source, int param, float value1, float value2, float value3);
+
+    public native int alGetSourcei(int source, int param);
+
+    public native void alSourceUnqueueBuffers(int source, int numBuffers, IntBuffer buffers);
+
+    public native void alSourceQueueBuffers(int source, int numBuffers, IntBuffer buffers);
+
+    public native void alListener(int param, FloatBuffer data);
+
+    public native void alListenerf(int param, float value);
+
+    public native void alListener3f(int param, float value1, float value2, float value3);
+
+    public native void alSource3i(int source, int param, int value1, int value2, int value3);
+
+}

+ 26 - 0
jme3-ios/src/main/java/com/jme3/audio/ios/IosALC.java

@@ -0,0 +1,26 @@
+package com.jme3.audio.ios;
+
+import com.jme3.audio.openal.ALC;
+import java.nio.IntBuffer;
+
+public final class IosALC implements ALC {
+    
+    public IosALC() {
+    }
+
+    public native void createALC();
+
+    public native void destroyALC();
+
+    public native boolean isCreated();
+
+    public native String alcGetString(int parameter);
+    
+    public native boolean alcIsExtensionPresent(String extension);
+    
+    public native void alcGetInteger(int param, IntBuffer buffer, int size);
+    
+    public native void alcDevicePauseSOFT();
+    
+    public native void alcDeviceResumeSOFT();
+}

+ 32 - 0
jme3-ios/src/main/java/com/jme3/audio/ios/IosEFX.java

@@ -0,0 +1,32 @@
+package com.jme3.audio.ios;
+
+import com.jme3.audio.openal.EFX;
+import java.nio.IntBuffer;
+
+public class IosEFX implements EFX {
+
+    public IosEFX() {
+    }
+
+    public native void alGenAuxiliaryEffectSlots(int numSlots, IntBuffer buffers);
+
+    public native void alGenEffects(int numEffects, IntBuffer buffers);
+
+    public native void alEffecti(int effect, int param, int value);
+
+    public native void alAuxiliaryEffectSloti(int effectSlot, int param, int value);
+
+    public native void alDeleteEffects(int numEffects, IntBuffer buffers);
+
+    public native void alDeleteAuxiliaryEffectSlots(int numEffectSlots, IntBuffer buffers);
+
+    public native void alGenFilters(int numFilters, IntBuffer buffers);
+
+    public native void alFilteri(int filter, int param, int value);
+
+    public native void alFilterf(int filter, int param, float value);
+
+    public native void alDeleteFilters(int numFilters, IntBuffer buffers);
+
+    public native void alEffectf(int effect, int param, float value);
+}

+ 0 - 20
jme3-ios/src/main/java/com/jme3/audio/plugins/AndroidAudioLoader.java

@@ -1,20 +0,0 @@
-package com.jme3.audio.plugins;
-
-import com.jme3.asset.AssetInfo;
-import com.jme3.asset.AssetLoader;
-import com.jme3.audio.android.AndroidAudioData;
-import java.io.IOException;
-
-/**
- * <code>AndroidAudioLoader</code> will create an 
- * {@link AndroidAudioData} object with the specified asset key.
- */
-public class AndroidAudioLoader implements AssetLoader {
-
-    @Override
-    public Object load(AssetInfo assetInfo) throws IOException {
-        AndroidAudioData result = new AndroidAudioData();
-        result.setAssetKey(assetInfo.getKey());
-        return result;
-    }
-}

+ 0 - 2573
jme3-ios/src/main/java/com/jme3/renderer/ios/IGLESShaderRenderer.java

@@ -1,2573 +0,0 @@
-package com.jme3.renderer.ios;
-
-import com.jme3.light.LightList;
-import com.jme3.material.RenderState;
-import com.jme3.math.*;
-import com.jme3.renderer.*;
-import com.jme3.scene.Mesh;
-import com.jme3.scene.Mesh.Mode;
-import com.jme3.scene.VertexBuffer;
-import com.jme3.scene.VertexBuffer.Format;
-import com.jme3.scene.VertexBuffer.Type;
-import com.jme3.scene.VertexBuffer.Usage;
-import com.jme3.shader.Attribute;
-import com.jme3.shader.Shader;
-import com.jme3.shader.Shader.ShaderSource;
-import com.jme3.shader.Shader.ShaderType;
-import com.jme3.shader.Uniform;
-import com.jme3.texture.FrameBuffer;
-import com.jme3.texture.FrameBuffer.RenderBuffer;
-import com.jme3.texture.Image;
-import com.jme3.texture.Texture;
-import com.jme3.texture.Texture.WrapAxis;
-import com.jme3.util.BufferUtils;
-import com.jme3.util.ListMap;
-import com.jme3.util.NativeObjectManager;
-
-import java.nio.*;
-import java.util.EnumSet;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import jme3tools.shader.ShaderDebug;
-
-/**
- * The <code>Renderer</code> is responsible for taking rendering commands and
- * executing them on the underlying video hardware.
- *
- * @author Kirill Vainer
- */
-public class IGLESShaderRenderer implements Renderer {
-
-    private static final Logger logger = Logger.getLogger(IGLESShaderRenderer.class.getName());
-    private static final boolean VALIDATE_SHADER = false;
-
-    private final NativeObjectManager objManager = new NativeObjectManager();
-    private final EnumSet<Caps> caps = EnumSet.noneOf(Caps.class);
-    private final Statistics statistics = new Statistics();
-    private final StringBuilder stringBuf = new StringBuilder(250);
-    private final RenderContext context = new RenderContext();
-    private final ByteBuffer nameBuf = BufferUtils.createByteBuffer(250);
-
-    private final int maxFBOAttachs = 1; // Only 1 color attachment on ES
-    private final int maxMRTFBOAttachs = 1; // FIXME for now, not sure if > 1 is needed for ES
-
-    private final int[] intBuf1 = new int[1];
-    private final int[] intBuf16 = new int[16];
-
-    private int glslVer;
-    private int vertexTextureUnits;
-    private int fragTextureUnits;
-    private int vertexUniforms;
-    private int fragUniforms;
-    private int vertexAttribs;
-    private int maxRBSize;
-    private int maxTexSize;
-    private int maxCubeTexSize;
-
-    private FrameBuffer lastFb = null;
-    private FrameBuffer mainFbOverride = null;
-    private boolean useVBO = true;
-    private boolean powerVr = false;
-    private boolean uintIndexSupport = false;
-
-    private Shader boundShader;
-
-    private int vpX, vpY, vpW, vpH;
-    private int clipX, clipY, clipW, clipH;
-
-    public IGLESShaderRenderer() {
-        logger.log(Level.FINE, "IGLESShaderRenderer Constructor");
-    }
-
-    /**
-     * Get the capabilities of the renderer.
-     * @return The capabilities of the renderer.
-     */
-    public EnumSet<Caps> getCaps() {
-        logger.log(Level.FINE, "IGLESShaderRenderer getCaps");
-        return caps;
-    }
-
-    /**
-     * The statistics allow tracking of how data
-     * per frame, such as number of objects rendered, number of triangles, etc.
-     * These are updated when the Renderer's methods are used, make sure
-     * to call {@link Statistics#clearFrame() } at the appropriate time
-     * to get accurate info per frame.
-     */
-    public Statistics getStatistics() {
-        logger.log(Level.FINE, "IGLESShaderRenderer getStatistics");
-        return statistics;
-    }
-
-    /**
-     * Invalidates the current rendering state. Should be called after
-     * the GL state was changed manually or through an external library.
-     */
-    public void invalidateState() {
-        logger.log(Level.FINE, "IGLESShaderRenderer invalidateState");
-    }
-
-    /**
-     * Clears certain channels of the currently bound framebuffer.
-     *
-     * @param color True if to clear colors (RGBA)
-     * @param depth True if to clear depth/z
-     * @param stencil True if to clear stencil buffer (if available, otherwise
-     * ignored)
-     */
-    public void clearBuffers(boolean color, boolean depth, boolean stencil) {
-        logger.log(Level.FINE, "IGLESShaderRenderer clearBuffers");
-        int bits = 0;
-        if (color) {
-            //See explanations of the depth below, we must enable color write to be able to clear the color buffer
-            if (context.colorWriteEnabled == false) {
-                JmeIosGLES.glColorMask(true, true, true, true);
-                context.colorWriteEnabled = true;
-            }
-            bits = JmeIosGLES.GL_COLOR_BUFFER_BIT;
-        }
-        if (depth) {
-            //glClear(GL_DEPTH_BUFFER_BIT) seems to not work when glDepthMask is false
-            //here s some link on openl board
-            //http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=257223
-            //if depth clear is requested, we enable the depthMask
-            if (context.depthWriteEnabled == false) {
-                JmeIosGLES.glDepthMask(true);
-                context.depthWriteEnabled = true;
-            }
-            bits |= JmeIosGLES.GL_DEPTH_BUFFER_BIT;
-        }
-        if (stencil) {
-            bits |= JmeIosGLES.GL_STENCIL_BUFFER_BIT;
-        }
-        if (bits != 0) {
-            JmeIosGLES.glClear(bits);
-            JmeIosGLES.checkGLError();
-        }
-    }
-
-    /**
-     * Sets the background (aka clear) color.
-     *
-     * @param color The background color to set
-     */
-    public void setBackgroundColor(ColorRGBA color) {
-        logger.log(Level.FINE, "IGLESShaderRenderer setBackgroundColor");
-        JmeIosGLES.glClearColor(color.r, color.g, color.b, color.a);
-        JmeIosGLES.checkGLError();
-    }
-
-    /**
-     * Applies the given {@link RenderState}, making the necessary
-     * GL calls so that the state is applied.
-     */
-    public void applyRenderState(RenderState state) {
-        logger.log(Level.FINE, "IGLESShaderRenderer applyRenderState");
-        /*
-        if (state.isWireframe() && !context.wireframe){
-        GLES20.glPolygonMode(GLES20.GL_FRONT_AND_BACK, GLES20.GL_LINE);
-        context.wireframe = true;
-        }else if (!state.isWireframe() && context.wireframe){
-        GLES20.glPolygonMode(GLES20.GL_FRONT_AND_BACK, GLES20.GL_FILL);
-        context.wireframe = false;
-        }
-         */
-        if (state.isDepthTest() && !context.depthTestEnabled) {
-            JmeIosGLES.glEnable(JmeIosGLES.GL_DEPTH_TEST);
-            JmeIosGLES.glDepthFunc(convertTestFunction(context.depthFunc));
-            JmeIosGLES.checkGLError();
-            context.depthTestEnabled = true;
-        } else if (!state.isDepthTest() && context.depthTestEnabled) {
-            JmeIosGLES.glDisable(JmeIosGLES.GL_DEPTH_TEST);
-            JmeIosGLES.checkGLError();
-            context.depthTestEnabled = false;
-        }
-		if (state.getDepthFunc() != context.depthFunc) {
-			JmeIosGLES.glDepthFunc(convertTestFunction(state.getDepthFunc()));
-			context.depthFunc = state.getDepthFunc();
-		}
-
-        if (state.isDepthWrite() && !context.depthWriteEnabled) {
-            JmeIosGLES.glDepthMask(true);
-            JmeIosGLES.checkGLError();
-            context.depthWriteEnabled = true;
-        } else if (!state.isDepthWrite() && context.depthWriteEnabled) {
-            JmeIosGLES.glDepthMask(false);
-            JmeIosGLES.checkGLError();
-            context.depthWriteEnabled = false;
-        }
-        if (state.isColorWrite() && !context.colorWriteEnabled) {
-            JmeIosGLES.glColorMask(true, true, true, true);
-            JmeIosGLES.checkGLError();
-            context.colorWriteEnabled = true;
-        } else if (!state.isColorWrite() && context.colorWriteEnabled) {
-            JmeIosGLES.glColorMask(false, false, false, false);
-            JmeIosGLES.checkGLError();
-            context.colorWriteEnabled = false;
-        }
-//        if (state.isPointSprite() && !context.pointSprite) {
-////            GLES20.glEnable(GLES20.GL_POINT_SPRITE);
-////            GLES20.glTexEnvi(GLES20.GL_POINT_SPRITE, GLES20.GL_COORD_REPLACE, GLES20.GL_TRUE);
-////            GLES20.glEnable(GLES20.GL_VERTEX_PROGRAM_POINT_SIZE);
-////            GLES20.glPointParameterf(GLES20.GL_POINT_SIZE_MIN, 1.0f);
-//        } else if (!state.isPointSprite() && context.pointSprite) {
-////            GLES20.glDisable(GLES20.GL_POINT_SPRITE);
-//        }
-
-        if (state.isPolyOffset()) {
-            if (!context.polyOffsetEnabled) {
-                JmeIosGLES.glEnable(JmeIosGLES.GL_POLYGON_OFFSET_FILL);
-                JmeIosGLES.glPolygonOffset(state.getPolyOffsetFactor(),
-                        state.getPolyOffsetUnits());
-                JmeIosGLES.checkGLError();
-
-                context.polyOffsetEnabled = true;
-                context.polyOffsetFactor = state.getPolyOffsetFactor();
-                context.polyOffsetUnits = state.getPolyOffsetUnits();
-            } else {
-                if (state.getPolyOffsetFactor() != context.polyOffsetFactor
-                        || state.getPolyOffsetUnits() != context.polyOffsetUnits) {
-                    JmeIosGLES.glPolygonOffset(state.getPolyOffsetFactor(),
-                            state.getPolyOffsetUnits());
-                    JmeIosGLES.checkGLError();
-
-                    context.polyOffsetFactor = state.getPolyOffsetFactor();
-                    context.polyOffsetUnits = state.getPolyOffsetUnits();
-                }
-            }
-        } else {
-            if (context.polyOffsetEnabled) {
-                JmeIosGLES.glDisable(JmeIosGLES.GL_POLYGON_OFFSET_FILL);
-                JmeIosGLES.checkGLError();
-
-                context.polyOffsetEnabled = false;
-                context.polyOffsetFactor = 0;
-                context.polyOffsetUnits = 0;
-            }
-        }
-        if (state.getFaceCullMode() != context.cullMode) {
-            if (state.getFaceCullMode() == RenderState.FaceCullMode.Off) {
-                JmeIosGLES.glDisable(JmeIosGLES.GL_CULL_FACE);
-                JmeIosGLES.checkGLError();
-            } else {
-                JmeIosGLES.glEnable(JmeIosGLES.GL_CULL_FACE);
-                JmeIosGLES.checkGLError();
-            }
-
-            switch (state.getFaceCullMode()) {
-                case Off:
-                    break;
-                case Back:
-                    JmeIosGLES.glCullFace(JmeIosGLES.GL_BACK);
-                    JmeIosGLES.checkGLError();
-                    break;
-                case Front:
-                    JmeIosGLES.glCullFace(JmeIosGLES.GL_FRONT);
-                    JmeIosGLES.checkGLError();
-                    break;
-                case FrontAndBack:
-                    JmeIosGLES.glCullFace(JmeIosGLES.GL_FRONT_AND_BACK);
-                    JmeIosGLES.checkGLError();
-                    break;
-                default:
-                    throw new UnsupportedOperationException("Unrecognized face cull mode: "
-                            + state.getFaceCullMode());
-            }
-
-            context.cullMode = state.getFaceCullMode();
-        }
-
-        if (state.getBlendMode() != context.blendMode) {
-            if (state.getBlendMode() == RenderState.BlendMode.Off) {
-                JmeIosGLES.glDisable(JmeIosGLES.GL_BLEND);
-                JmeIosGLES.checkGLError();
-            } else {
-                JmeIosGLES.glEnable(JmeIosGLES.GL_BLEND);
-                switch (state.getBlendMode()) {
-                    case Off:
-                        break;
-                    case Additive:
-                        JmeIosGLES.glBlendFunc(JmeIosGLES.GL_ONE, JmeIosGLES.GL_ONE);
-                        break;
-                    case AlphaAdditive:
-                        JmeIosGLES.glBlendFunc(JmeIosGLES.GL_SRC_ALPHA, JmeIosGLES.GL_ONE);
-                        break;
-                    case Color:
-                        JmeIosGLES.glBlendFunc(JmeIosGLES.GL_ONE, JmeIosGLES.GL_ONE_MINUS_SRC_COLOR);
-                        break;
-                    case Alpha:
-                        JmeIosGLES.glBlendFunc(JmeIosGLES.GL_SRC_ALPHA, JmeIosGLES.GL_ONE_MINUS_SRC_ALPHA);
-                        break;
-                    case PremultAlpha:
-                        JmeIosGLES.glBlendFunc(JmeIosGLES.GL_ONE, JmeIosGLES.GL_ONE_MINUS_SRC_ALPHA);
-                        break;
-                    case Modulate:
-                        JmeIosGLES.glBlendFunc(JmeIosGLES.GL_DST_COLOR, JmeIosGLES.GL_ZERO);
-                        break;
-                    case ModulateX2:
-                        JmeIosGLES.glBlendFunc(JmeIosGLES.GL_DST_COLOR, JmeIosGLES.GL_SRC_COLOR);
-                        break;
-                    default:
-                        throw new UnsupportedOperationException("Unrecognized blend mode: "
-                                + state.getBlendMode());
-                }
-                JmeIosGLES.checkGLError();
-            }
-            context.blendMode = state.getBlendMode();
-        }
-    }
-
-    /**
-     * Set the range of the depth values for objects. All rendered
-     * objects will have their depth clamped to this range.
-     *
-     * @param start The range start
-     * @param end The range end
-     */
-    public void setDepthRange(float start, float end) {
-        logger.log(Level.FINE, "IGLESShaderRenderer setDepthRange");
-        JmeIosGLES.glDepthRangef(start, end);
-        JmeIosGLES.checkGLError();
-    }
-
-    /**
-     * Called when a new frame has been rendered.
-     */
-    public void postFrame() {
-        logger.log(Level.FINE, "IGLESShaderRenderer onFrame");
-        //JmeIosGLES.checkGLErrorForced();
-        JmeIosGLES.checkGLError();
-
-        objManager.deleteUnused(this);
-    }
-
-    /**
-     * Set the world matrix to use. Does nothing if the Renderer is
-     * shader based.
-     *
-     * @param worldMatrix World matrix to use.
-     */
-    public void setWorldMatrix(Matrix4f worldMatrix) {
-        logger.log(Level.FINE, "IGLESShaderRenderer setWorldMatrix");
-    }
-
-    /**
-     * Sets the view and projection matrices to use. Does nothing if the Renderer
-     * is shader based.
-     *
-     * @param viewMatrix The view matrix to use.
-     * @param projMatrix The projection matrix to use.
-     */
-    public void setViewProjectionMatrices(Matrix4f viewMatrix, Matrix4f projMatrix) {
-        logger.log(Level.FINE, "IGLESShaderRenderer setViewProjectionMatrices");
-    }
-
-    /**
-     * Set the viewport location and resolution on the screen.
-     *
-     * @param x The x coordinate of the viewport
-     * @param y The y coordinate of the viewport
-     * @param width Width of the viewport
-     * @param height Height of the viewport
-     */
-    public void setViewPort(int x, int y, int width, int height) {
-        logger.log(Level.FINE, "IGLESShaderRenderer setViewPort");
-        if (x != vpX || vpY != y || vpW != width || vpH != height) {
-            JmeIosGLES.glViewport(x, y, width, height);
-            JmeIosGLES.checkGLError();
-
-            vpX = x;
-            vpY = y;
-            vpW = width;
-            vpH = height;
-        }
-    }
-
-    /**
-     * Specifies a clipping rectangle.
-     * For all future rendering commands, no pixels will be allowed
-     * to be rendered outside of the clip rectangle.
-     *
-     * @param x The x coordinate of the clip rect
-     * @param y The y coordinate of the clip rect
-     * @param width Width of the clip rect
-     * @param height Height of the clip rect
-     */
-    public void setClipRect(int x, int y, int width, int height) {
-        logger.log(Level.FINE, "IGLESShaderRenderer setClipRect");
-        if (!context.clipRectEnabled) {
-            JmeIosGLES.glEnable(JmeIosGLES.GL_SCISSOR_TEST);
-            JmeIosGLES.checkGLError();
-            context.clipRectEnabled = true;
-        }
-        if (clipX != x || clipY != y || clipW != width || clipH != height) {
-            JmeIosGLES.glScissor(x, y, width, height);
-            JmeIosGLES.checkGLError();
-            clipX = x;
-            clipY = y;
-            clipW = width;
-            clipH = height;
-        }
-    }
-
-    /**
-     * Clears the clipping rectangle set with
-     * {@link #setClipRect(int, int, int, int) }.
-     */
-    public void clearClipRect() {
-        logger.log(Level.FINE, "IGLESShaderRenderer clearClipRect");
-        if (context.clipRectEnabled) {
-            JmeIosGLES.glDisable(JmeIosGLES.GL_SCISSOR_TEST);
-            JmeIosGLES.checkGLError();
-            context.clipRectEnabled = false;
-
-            clipX = 0;
-            clipY = 0;
-            clipW = 0;
-            clipH = 0;
-        }
-    }
-
-    /**
-     * Set lighting state.
-     * Does nothing if the renderer is shader based.
-     * The lights should be provided in world space.
-     * Specify <code>null</code> to disable lighting.
-     *
-     * @param lights The light list to set.
-     */
-    public void setLighting(LightList lights) {
-        logger.log(Level.FINE, "IGLESShaderRenderer setLighting");
-    }
-
-    /**
-     * Sets the shader to use for rendering.
-     * If the shader has not been uploaded yet, it is compiled
-     * and linked. If it has been uploaded, then the
-     * uniform data is updated and the shader is set.
-     *
-     * @param shader The shader to use for rendering.
-     */
-    public void setShader(Shader shader) {
-        logger.log(Level.FINE, "IGLESShaderRenderer setShader");
-        if (shader == null) {
-            throw new IllegalArgumentException("Shader cannot be null");
-        } else {
-            if (shader.isUpdateNeeded()) {
-                updateShaderData(shader);
-            }
-
-            // NOTE: might want to check if any of the
-            // sources need an update?
-
-            assert shader.getId() > 0;
-
-            updateShaderUniforms(shader);
-            bindProgram(shader);
-        }
-    }
-
-    /**
-     * Deletes a shader. This method also deletes
-     * the attached shader sources.
-     *
-     * @param shader Shader to delete.
-     */
-    public void deleteShader(Shader shader) {
-        logger.log(Level.FINE, "IGLESShaderRenderer deleteShader");
-        if (shader.getId() == -1) {
-            logger.warning("Shader is not uploaded to GPU, cannot delete.");
-            return;
-        }
-
-        for (ShaderSource source : shader.getSources()) {
-            if (source.getId() != -1) {
-                JmeIosGLES.glDetachShader(shader.getId(), source.getId());
-                JmeIosGLES.checkGLError();
-
-                deleteShaderSource(source);
-            }
-        }
-
-        JmeIosGLES.glDeleteProgram(shader.getId());
-        JmeIosGLES.checkGLError();
-
-        statistics.onDeleteShader();
-        shader.resetObject();
-    }
-
-    /**
-     * Deletes the provided shader source.
-     *
-     * @param source The ShaderSource to delete.
-     */
-    public void deleteShaderSource(ShaderSource source) {
-        logger.log(Level.FINE, "IGLESShaderRenderer deleteShaderSource");
-        if (source.getId() < 0) {
-            logger.warning("Shader source is not uploaded to GPU, cannot delete.");
-            return;
-        }
-
-        source.clearUpdateNeeded();
-
-        JmeIosGLES.glDeleteShader(source.getId());
-        JmeIosGLES.checkGLError();
-
-        source.resetObject();
-    }
-
-    /**
-     * Copies contents from src to dst, scaling if necessary.
-     */
-    public void copyFrameBuffer(FrameBuffer src, FrameBuffer dst) {
-        logger.log(Level.FINE, "IGLESShaderRenderer copyFrameBuffer");
-        copyFrameBuffer(src, dst, true);
-    }
-
-    /**
-     * Copies contents from src to dst, scaling if necessary.
-     * set copyDepth to false to only copy the color buffers.
-     */
-    public void copyFrameBuffer(FrameBuffer src, FrameBuffer dst, boolean copyDepth) {
-        logger.warning("IGLESShaderRenderer copyFrameBuffer with depth TODO");
-        throw new RendererException("Copy framebuffer not implemented yet.");
-    }
-
-    /**
-     * Sets the framebuffer that will be drawn to.
-     */
-    public void setFrameBuffer(FrameBuffer fb) {
-        logger.log(Level.FINE, "IGLESShaderRenderer setFrameBuffer");
-        if (fb == null && mainFbOverride != null) {
-            fb = mainFbOverride;
-        }
-
-        if (lastFb == fb) {
-            if (fb == null || !fb.isUpdateNeeded()) {
-                return;
-            }
-        }
-
-        // generate mipmaps for last FB if needed
-        if (lastFb != null) {
-            for (int i = 0; i < lastFb.getNumColorBuffers(); i++) {
-                RenderBuffer rb = lastFb.getColorBuffer(i);
-                Texture tex = rb.getTexture();
-                if (tex != null
-                        && tex.getMinFilter().usesMipMapLevels()) {
-                    setTexture(0, rb.getTexture());
-
-//                    int textureType = convertTextureType(tex.getType(), tex.getImage().getMultiSamples(), rb.getFace());
-                    int textureType = convertTextureType(tex.getType());
-                    JmeIosGLES.glGenerateMipmap(textureType);
-                    JmeIosGLES.checkGLError();
-                }
-            }
-        }
-
-        if (fb == null) {
-            // unbind any fbos
-            if (context.boundFBO != 0) {
-                JmeIosGLES.glBindFramebuffer(JmeIosGLES.GL_FRAMEBUFFER, 0);
-                JmeIosGLES.checkGLError();
-
-                statistics.onFrameBufferUse(null, true);
-
-                context.boundFBO = 0;
-            }
-
-            /*
-            // select back buffer
-            if (context.boundDrawBuf != -1) {
-                glDrawBuffer(initialDrawBuf);
-                context.boundDrawBuf = -1;
-            }
-            if (context.boundReadBuf != -1) {
-                glReadBuffer(initialReadBuf);
-                context.boundReadBuf = -1;
-            }
-             */
-
-            lastFb = null;
-        } else {
-            if (fb.getNumColorBuffers() == 0 && fb.getDepthBuffer() == null) {
-                throw new IllegalArgumentException("The framebuffer: " + fb
-                        + "\nDoesn't have any color/depth buffers");
-            }
-
-            if (fb.isUpdateNeeded()) {
-                updateFrameBuffer(fb);
-            }
-
-            if (context.boundFBO != fb.getId()) {
-                JmeIosGLES.glBindFramebuffer(JmeIosGLES.GL_FRAMEBUFFER, fb.getId());
-                JmeIosGLES.checkGLError();
-
-                statistics.onFrameBufferUse(fb, true);
-
-                // update viewport to reflect framebuffer's resolution
-                setViewPort(0, 0, fb.getWidth(), fb.getHeight());
-
-                context.boundFBO = fb.getId();
-            } else {
-                statistics.onFrameBufferUse(fb, false);
-            }
-            if (fb.getNumColorBuffers() == 0) {
-//                // make sure to select NONE as draw buf
-//                // no color buffer attached. select NONE
-                if (context.boundDrawBuf != -2) {
-//                    glDrawBuffer(GL_NONE);
-                    context.boundDrawBuf = -2;
-                }
-                if (context.boundReadBuf != -2) {
-//                    glReadBuffer(GL_NONE);
-                    context.boundReadBuf = -2;
-                }
-            } else {
-                if (fb.getNumColorBuffers() > maxFBOAttachs) {
-                    throw new RendererException("Framebuffer has more color "
-                            + "attachments than are supported"
-                            + " by the video hardware!");
-                }
-                if (fb.isMultiTarget()) {
-                    if (fb.getNumColorBuffers() > maxMRTFBOAttachs) {
-                        throw new RendererException("Framebuffer has more"
-                                + " multi targets than are supported"
-                                + " by the video hardware!");
-                    }
-
-                    if (context.boundDrawBuf != 100 + fb.getNumColorBuffers()) {
-                        //intBuf16.clear();
-                        for (int i = 0; i < 16; i++) {
-                            intBuf16[i] = i < fb.getNumColorBuffers() ? JmeIosGLES.GL_COLOR_ATTACHMENT0 + i : 0;
-                        }
-
-                        //intBuf16.flip();// TODO: flip
-//                        glDrawBuffers(intBuf16);
-                        context.boundDrawBuf = 100 + fb.getNumColorBuffers();
-                    }
-                } else {
-                    RenderBuffer rb = fb.getColorBuffer(fb.getTargetIndex());
-                    // select this draw buffer
-                    if (context.boundDrawBuf != rb.getSlot()) {
-                        JmeIosGLES.glActiveTexture(convertAttachmentSlot(rb.getSlot()));
-                        JmeIosGLES.checkGLError();
-
-                        context.boundDrawBuf = rb.getSlot();
-                    }
-                }
-            }
-
-            assert fb.getId() >= 0;
-            assert context.boundFBO == fb.getId();
-
-            lastFb = fb;
-
-            checkFrameBufferStatus(fb);
-        }
-    }
-
-    /**
-     * Set the framebuffer that will be set instead of the main framebuffer
-     * when a call to setFrameBuffer(null) is made.
-     *
-     * @param fb
-     */
-    public void setMainFrameBufferOverride(FrameBuffer fb) {
-        logger.log(Level.FINE, "IGLESShaderRenderer setMainFrameBufferOverride");
-        mainFbOverride = fb;
-    }
-
-    /**
-     * Reads the pixels currently stored in the specified framebuffer
-     * into the given ByteBuffer object.
-     * Only color pixels are transferred, the format is BGRA with 8 bits
-     * per component. The given byte buffer should have at least
-     * fb.getWidth() * fb.getHeight() * 4 bytes remaining.
-     *
-     * @param fb The framebuffer to read from
-     * @param byteBuf The bytebuffer to transfer color data to
-     */
-    public void readFrameBuffer(FrameBuffer fb, ByteBuffer byteBuf) {
-        logger.log(Level.FINE, "IGLESShaderRenderer readFrameBuffer");
-        if (fb != null) {
-            RenderBuffer rb = fb.getColorBuffer();
-            if (rb == null) {
-                throw new IllegalArgumentException("Specified framebuffer"
-                        + " does not have a colorbuffer");
-            }
-
-            setFrameBuffer(fb);
-        } else {
-            setFrameBuffer(null);
-        }
-
-        //JmeIosGLES.glReadPixels2(vpX, vpY, vpW, vpH, JmeIosGLES.GL_RGBA, JmeIosGLES.GL_UNSIGNED_BYTE, byteBuf.array(), 0, vpW * vpH * 4);
-        JmeIosGLES.glReadPixels(vpX, vpY, vpW, vpH, JmeIosGLES.GL_RGBA, JmeIosGLES.GL_UNSIGNED_BYTE, byteBuf);
-        JmeIosGLES.checkGLError();
-    }
-
-    /**
-     * Deletes a framebuffer and all attached renderbuffers
-     */
-    public void deleteFrameBuffer(FrameBuffer fb) {
-        logger.log(Level.FINE, "IGLESShaderRenderer deleteFrameBuffer");
-        if (fb.getId() != -1) {
-            if (context.boundFBO == fb.getId()) {
-                JmeIosGLES.glBindFramebuffer(JmeIosGLES.GL_FRAMEBUFFER, 0);
-                JmeIosGLES.checkGLError();
-
-                context.boundFBO = 0;
-            }
-
-            if (fb.getDepthBuffer() != null) {
-                deleteRenderBuffer(fb, fb.getDepthBuffer());
-            }
-            if (fb.getColorBuffer() != null) {
-                deleteRenderBuffer(fb, fb.getColorBuffer());
-            }
-
-            intBuf1[0] = fb.getId();
-            JmeIosGLES.glDeleteFramebuffers(1, intBuf1, 0);
-            JmeIosGLES.checkGLError();
-
-            fb.resetObject();
-
-            statistics.onDeleteFrameBuffer();
-        }
-    }
-
-    /**
-     * Sets the texture to use for the given texture unit.
-     */
-    public void setTexture(int unit, Texture tex) {
-        logger.log(Level.FINE, "IGLESShaderRenderer setTexture");
-        Image image = tex.getImage();
-        if (image.isUpdateNeeded() || (image.isGeneratedMipmapsRequired() && !image.isMipmapsGenerated()) ) {
-            updateTexImageData(image, tex.getType());
-        }
-
-        int texId = image.getId();
-        assert texId != -1;
-
-        if (texId == -1) {
-            logger.warning("error: texture image has -1 id");
-        }
-
-        Image[] textures = context.boundTextures;
-
-        int type = convertTextureType(tex.getType());
-        if (textures[unit] != image) {
-            if (context.boundTextureUnit != unit) {
-                JmeIosGLES.glActiveTexture(JmeIosGLES.GL_TEXTURE0 + unit);
-                context.boundTextureUnit = unit;
-            }
-
-            JmeIosGLES.glBindTexture(type, texId);
-            JmeIosGLES.checkGLError();
-
-            textures[unit] = image;
-
-            statistics.onTextureUse(tex.getImage(), true);
-        } else {
-            statistics.onTextureUse(tex.getImage(), false);
-        }
-
-        setupTextureParams(tex);
-    }
-
-    /**
-     * Modify the given Texture tex with the given Image. The image will be put at x and y into the texture.
-     *
-     * @param tex the Texture that will be modified
-     * @param pixels the source Image data to copy data from
-     * @param x the x position to put the image into the texture
-     * @param y the y position to put the image into the texture
-     */
-    public void modifyTexture(Texture tex, Image pixels, int x, int y) {
-		logger.log(Level.FINE, "IGLESShaderRenderer modifyTexture");
-		setTexture(0, tex);
-		TextureUtil.uploadSubTexture(pixels, convertTextureType(tex.getType()), 0, x, y);
-    }
-
-    /**
-     * Deletes a texture from the GPU.
-     */
-    public void deleteImage(Image image) {
-        logger.log(Level.FINE, "IGLESShaderRenderer deleteImage");
-        int texId = image.getId();
-        if (texId != -1) {
-            intBuf1[0] = texId;
-
-            JmeIosGLES.glDeleteTextures(1, intBuf1, 0);
-            JmeIosGLES.checkGLError();
-
-            image.resetObject();
-
-            statistics.onDeleteTexture();
-        }
-    }
-
-    /**
-     * Uploads a vertex buffer to the GPU.
-     *
-     * @param vb The vertex buffer to upload
-     */
-    public void updateBufferData(VertexBuffer vb) {
-        logger.log(Level.FINE, "IGLESShaderRenderer updateBufferData");
-        int bufId = vb.getId();
-        boolean created = false;
-        if (bufId == -1) {
-            // create buffer
-            JmeIosGLES.glGenBuffers(1, intBuf1, 0);
-            JmeIosGLES.checkGLError();
-
-            bufId = intBuf1[0];
-            vb.setId(bufId);
-            objManager.registerObject(vb);
-
-            created = true;
-        }
-
-        // bind buffer
-        int target;
-        if (vb.getBufferType() == VertexBuffer.Type.Index) {
-            target = JmeIosGLES.GL_ELEMENT_ARRAY_BUFFER;
-            if (context.boundElementArrayVBO != bufId) {
-                JmeIosGLES.glBindBuffer(target, bufId);
-                JmeIosGLES.checkGLError();
-
-                context.boundElementArrayVBO = bufId;
-            }
-        } else {
-            target = JmeIosGLES.GL_ARRAY_BUFFER;
-            if (context.boundArrayVBO != bufId) {
-                JmeIosGLES.glBindBuffer(target, bufId);
-                JmeIosGLES.checkGLError();
-
-                context.boundArrayVBO = bufId;
-            }
-        }
-
-        int usage = convertUsage(vb.getUsage());
-        vb.getData().rewind();
-
-        if (created || vb.hasDataSizeChanged()) {
-            // upload data based on format
-            int size = vb.getData().limit() * vb.getFormat().getComponentSize();
-
-            switch (vb.getFormat()) {
-                case Byte:
-                case UnsignedByte:
-					JmeIosGLES.glBufferData(target, size, (ByteBuffer) vb.getData(), usage);
-                    JmeIosGLES.checkGLError();
-                    break;
-                case Short:
-                case UnsignedShort:
-                    JmeIosGLES.glBufferData(target, size, (ShortBuffer) vb.getData(), usage);
-                    JmeIosGLES.checkGLError();
-                    break;
-                case Int:
-                case UnsignedInt:
-                    JmeIosGLES.glBufferData(target, size, (IntBuffer) vb.getData(), usage);
-                    JmeIosGLES.checkGLError();
-                    break;
-                case Float:
-                    JmeIosGLES.glBufferData(target, size, (FloatBuffer) vb.getData(), usage);
-                    JmeIosGLES.checkGLError();
-                    break;
-                default:
-                    throw new RuntimeException("Unknown buffer format.");
-            }
-        } else {
-            int size = vb.getData().limit() * vb.getFormat().getComponentSize();
-
-            switch (vb.getFormat()) {
-                case Byte:
-                case UnsignedByte:
-                    JmeIosGLES.glBufferSubData(target, 0, size, (ByteBuffer) vb.getData());
-                    JmeIosGLES.checkGLError();
-                    break;
-                case Short:
-                case UnsignedShort:
-                    JmeIosGLES.glBufferSubData(target, 0, size, (ShortBuffer) vb.getData());
-                    JmeIosGLES.checkGLError();
-                    break;
-                case Int:
-                case UnsignedInt:
-                    JmeIosGLES.glBufferSubData(target, 0, size, (IntBuffer) vb.getData());
-                    JmeIosGLES.checkGLError();
-                    break;
-                case Float:
-                    JmeIosGLES.glBufferSubData(target, 0, size, (FloatBuffer) vb.getData());
-                    JmeIosGLES.checkGLError();
-                    break;
-                default:
-                    throw new RuntimeException("Unknown buffer format.");
-            }
-        }
-        vb.clearUpdateNeeded();
-    }
-
-    /**
-     * Deletes a vertex buffer from the GPU.
-     * @param vb The vertex buffer to delete
-     */
-    public void deleteBuffer(VertexBuffer vb) {
-        logger.log(Level.FINE, "IGLESShaderRenderer deleteBuffer");
-        int bufId = vb.getId();
-        if (bufId != -1) {
-            // delete buffer
-            intBuf1[0] = bufId;
-
-            JmeIosGLES.glDeleteBuffers(1, intBuf1, 0);
-            JmeIosGLES.checkGLError();
-
-            vb.resetObject();
-        }
-    }
-
-    /**
-     * Renders <code>count</code> meshes, with the geometry data supplied.
-     * The shader which is currently set with <code>setShader</code> is
-     * responsible for transforming the input verticies into clip space
-     * and shading it based on the given vertex attributes.
-     * The int variable gl_InstanceID can be used to access the current
-     * instance of the mesh being rendered inside the vertex shader.
-     *
-     * @param mesh The mesh to render
-     * @param lod The LOD level to use, see {@link Mesh#setLodLevels(com.jme3.scene.VertexBuffer[]) }.
-     * @param count Number of mesh instances to render
-     */
-    public void renderMesh(Mesh mesh, int lod, int count, VertexBuffer[] instanceData) {
-        logger.log(Level.FINE, "IGLESShaderRenderer renderMesh");
-        if (mesh.getVertexCount() == 0) {
-        	return;
-        }
-        /*
-         * NOTE: not supported in OpenGL ES 2.0.
-        if (context.pointSize != mesh.getPointSize()) {
-            GLES10.glPointSize(mesh.getPointSize());
-            context.pointSize = mesh.getPointSize();
-        }
-        */
-        if (context.lineWidth != mesh.getLineWidth()) {
-            JmeIosGLES.glLineWidth(mesh.getLineWidth());
-            JmeIosGLES.checkGLError();
-            context.lineWidth = mesh.getLineWidth();
-        }
-
-        statistics.onMeshDrawn(mesh, lod);
-//        if (GLContext.getCapabilities().GL_ARB_vertex_array_object){
-//            renderMeshVertexArray(mesh, lod, count);
-//        }else{
-
-        if (useVBO) {
-            renderMeshDefault(mesh, lod, count);
-        } else {
-            renderMeshVertexArray(mesh, lod, count);
-        }
-    }
-
-    /**
-     * Resets all previously used {@link NativeObject Native Objects} on this Renderer.
-     * The state of the native objects is reset in such way, that using
-     * them again will cause the renderer to reupload them.
-     * Call this method when you know the GL context is going to shutdown.
-     *
-     * @see NativeObject#resetObject()
-     */
-    public void resetGLObjects() {
-        logger.log(Level.FINE, "IGLESShaderRenderer resetGLObjects");
-        objManager.resetObjects();
-        statistics.clearMemory();
-        boundShader = null;
-        lastFb = null;
-        context.reset();
-    }
-
-    /**
-     * Deletes all previously used {@link NativeObject Native Objects} on this Renderer, and
-     * then resets the native objects.
-     *
-     * @see #resetGLObjects()
-     * @see NativeObject#deleteObject(java.lang.Object)
-     */
-    public void cleanup() {
-        logger.log(Level.FINE, "IGLESShaderRenderer cleanup");
-        objManager.deleteAllObjects(this);
-        statistics.clearMemory();
-    }
-
-    /**
-     * Sets the alpha to coverage state.
-     * <p>
-     * When alpha coverage and multi-sampling is enabled,
-     * each pixel will contain alpha coverage in all
-     * of its subsamples, which is then combined when
-     * other future alpha-blended objects are rendered.
-     * </p>
-     * <p>
-     * Alpha-to-coverage is useful for rendering transparent objects
-     * without having to worry about sorting them.
-     * </p>
-     */
-    public void setAlphaToCoverage(boolean value) {
-        logger.log(Level.FINE, "IGLESShaderRenderer setAlphaToCoverage");
-        if (value) {
-            JmeIosGLES.glEnable(JmeIosGLES.GL_SAMPLE_ALPHA_TO_COVERAGE);
-            JmeIosGLES.checkGLError();
-        } else {
-            JmeIosGLES.glDisable(JmeIosGLES.GL_SAMPLE_ALPHA_TO_COVERAGE);
-            JmeIosGLES.checkGLError();
-        }
-    }
-
-
-    /* ------------------------------------------------------------------------------ */
-
-
-    public void initialize() {
-        Level store = logger.getLevel();
-        logger.setLevel(Level.FINE);
-
-        logger.log(Level.FINE, "Vendor: {0}", JmeIosGLES.glGetString(JmeIosGLES.GL_VENDOR));
-        logger.log(Level.FINE, "Renderer: {0}", JmeIosGLES.glGetString(JmeIosGLES.GL_RENDERER));
-        logger.log(Level.FINE, "Version: {0}", JmeIosGLES.glGetString(JmeIosGLES.GL_VERSION));
-        logger.log(Level.FINE, "Shading Language Version: {0}", JmeIosGLES.glGetString(JmeIosGLES.GL_SHADING_LANGUAGE_VERSION));
-
-        /*
-        // Fix issue in TestRenderToMemory when GL_FRONT is the main
-        // buffer being used.
-        initialDrawBuf = glGetInteger(GL_DRAW_BUFFER);
-        initialReadBuf = glGetInteger(GL_READ_BUFFER);
-
-        // XXX: This has to be GL_BACK for canvas on Mac
-        // Since initialDrawBuf is GL_FRONT for pbuffer, gotta
-        // change this value later on ...
-//        initialDrawBuf = GL_BACK;
-//        initialReadBuf = GL_BACK;
-         */
-
-        // Check OpenGL version
-        int openGlVer = extractVersion("OpenGL ES ", JmeIosGLES.glGetString(JmeIosGLES.GL_VERSION));
-        if (openGlVer == -1) {
-            glslVer = -1;
-            throw new UnsupportedOperationException("OpenGL ES 2.0+ is required for IGLESShaderRenderer!");
-        }
-
-        // Check shader language version
-        glslVer = extractVersion("OpenGL ES GLSL ES ", JmeIosGLES.glGetString(JmeIosGLES.GL_SHADING_LANGUAGE_VERSION));
-        switch (glslVer) {
-            // TODO: When new versions of OpenGL ES shader language come out,
-            // update this.
-            default:
-                caps.add(Caps.GLSL100);
-                break;
-        }
-
-        JmeIosGLES.glGetIntegerv(JmeIosGLES.GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, intBuf16, 0);
-        vertexTextureUnits = intBuf16[0];
-        logger.log(Level.FINE, "VTF Units: {0}", vertexTextureUnits);
-        if (vertexTextureUnits > 0) {
-            caps.add(Caps.VertexTextureFetch);
-        }
-
-        JmeIosGLES.glGetIntegerv(JmeIosGLES.GL_MAX_TEXTURE_IMAGE_UNITS, intBuf16, 0);
-        fragTextureUnits = intBuf16[0];
-        logger.log(Level.FINE, "Texture Units: {0}", fragTextureUnits);
-
-        // Multiply vector count by 4 to get float count.
-        JmeIosGLES.glGetIntegerv(JmeIosGLES.GL_MAX_VERTEX_UNIFORM_VECTORS, intBuf16, 0);
-        vertexUniforms = intBuf16[0] * 4;
-        logger.log(Level.FINER, "Vertex Uniforms: {0}", vertexUniforms);
-
-        JmeIosGLES.glGetIntegerv(JmeIosGLES.GL_MAX_FRAGMENT_UNIFORM_VECTORS, intBuf16, 0);
-        fragUniforms = intBuf16[0] * 4;
-        logger.log(Level.FINER, "Fragment Uniforms: {0}", fragUniforms);
-
-        JmeIosGLES.glGetIntegerv(JmeIosGLES.GL_MAX_VARYING_VECTORS, intBuf16, 0);
-        int varyingFloats = intBuf16[0] * 4;
-        logger.log(Level.FINER, "Varying Floats: {0}", varyingFloats);
-
-        JmeIosGLES.glGetIntegerv(JmeIosGLES.GL_MAX_VERTEX_ATTRIBS, intBuf16, 0);
-        vertexAttribs = intBuf16[0];
-        logger.log(Level.FINE, "Vertex Attributes: {0}", vertexAttribs);
-
-        JmeIosGLES.glGetIntegerv(JmeIosGLES.GL_SUBPIXEL_BITS, intBuf16, 0);
-        int subpixelBits = intBuf16[0];
-        logger.log(Level.FINE, "Subpixel Bits: {0}", subpixelBits);
-
-//        GLES10.glGetIntegerv(GLES10.GL_MAX_ELEMENTS_VERTICES, intBuf16);
-//        maxVertCount = intBuf16.get(0);
-//        logger.log(Level.FINER, "Preferred Batch Vertex Count: {0}", maxVertCount);
-//
-//        GLES10.glGetIntegerv(GLES10.GL_MAX_ELEMENTS_INDICES, intBuf16);
-//        maxTriCount = intBuf16.get(0);
-//        logger.log(Level.FINER, "Preferred Batch Index Count: {0}", maxTriCount);
-
-        JmeIosGLES.glGetIntegerv(JmeIosGLES.GL_MAX_TEXTURE_SIZE, intBuf16, 0);
-        maxTexSize = intBuf16[0];
-        logger.log(Level.FINE, "Maximum Texture Resolution: {0}", maxTexSize);
-
-        JmeIosGLES.glGetIntegerv(JmeIosGLES.GL_MAX_CUBE_MAP_TEXTURE_SIZE, intBuf16, 0);
-        maxCubeTexSize = intBuf16[0];
-        logger.log(Level.FINE, "Maximum CubeMap Resolution: {0}", maxCubeTexSize);
-
-        JmeIosGLES.glGetIntegerv(JmeIosGLES.GL_MAX_RENDERBUFFER_SIZE, intBuf16, 0);
-        maxRBSize = intBuf16[0];
-        logger.log(Level.FINER, "FBO RB Max Size: {0}", maxRBSize);
-
-        /*
-        if (ctxCaps.GL_ARB_color_buffer_float){
-        // XXX: Require both 16 and 32 bit float support for FloatColorBuffer.
-        if (ctxCaps.GL_ARB_half_float_pixel){
-        caps.add(Caps.FloatColorBuffer);
-        }
-        }
-
-        if (ctxCaps.GL_ARB_depth_buffer_float){
-        caps.add(Caps.FloatDepthBuffer);
-        }
-
-        if (ctxCaps.GL_ARB_draw_instanced)
-        caps.add(Caps.MeshInstancing);
-
-        if (ctxCaps.GL_ARB_texture_buffer_object)
-        caps.add(Caps.TextureBuffer);
-
-        if (ctxCaps.GL_ARB_texture_float){
-        if (ctxCaps.GL_ARB_half_float_pixel){
-        caps.add(Caps.FloatTexture);
-        }
-        }
-
-        if (ctxCaps.GL_EXT_packed_float){
-        caps.add(Caps.PackedFloatColorBuffer);
-        if (ctxCaps.GL_ARB_half_float_pixel){
-        // because textures are usually uploaded as RGB16F
-        // need half-float pixel
-        caps.add(Caps.PackedFloatTexture);
-        }
-        }
-
-        if (ctxCaps.GL_EXT_texture_array)
-        caps.add(Caps.TextureArray);
-
-        if (ctxCaps.GL_EXT_texture_shared_exponent)
-        caps.add(Caps.SharedExponentTexture);
-
-        if (ctxCaps.GL_EXT_framebuffer_object){
-        caps.add(Caps.FrameBuffer);
-
-        glGetInteger(GL_MAX_RENDERBUFFER_SIZE_EXT, intBuf16);
-        maxRBSize = intBuf16.get(0);
-        logger.log(Level.FINER, "FBO RB Max Size: {0}", maxRBSize);
-
-        glGetInteger(GL_MAX_COLOR_ATTACHMENTS_EXT, intBuf16);
-        maxFBOAttachs = intBuf16.get(0);
-        logger.log(Level.FINER, "FBO Max renderbuffers: {0}", maxFBOAttachs);
-
-        if (ctxCaps.GL_EXT_framebuffer_multisample){
-        caps.add(Caps.FrameBufferMultisample);
-
-        glGetInteger(GL_MAX_SAMPLES_EXT, intBuf16);
-        maxFBOSamples = intBuf16.get(0);
-        logger.log(Level.FINER, "FBO Max Samples: {0}", maxFBOSamples);
-        }
-
-        if (ctxCaps.GL_ARB_draw_buffers){
-        caps.add(Caps.FrameBufferMRT);
-        glGetInteger(ARBDrawBuffers.GL_MAX_DRAW_BUFFERS_ARB, intBuf16);
-        maxMRTFBOAttachs = intBuf16.get(0);
-        logger.log(Level.FINER, "FBO Max MRT renderbuffers: {0}", maxMRTFBOAttachs);
-        }
-        }
-
-        if (ctxCaps.GL_ARB_multisample){
-        glGetInteger(ARBMultisample.GL_SAMPLE_BUFFERS_ARB, intBuf16);
-        boolean available = intBuf16.get(0) != 0;
-        glGetInteger(ARBMultisample.GL_SAMPLES_ARB, intBuf16);
-        int samples = intBuf16.get(0);
-        logger.log(Level.FINER, "Samples: {0}", samples);
-        boolean enabled = glIsEnabled(ARBMultisample.GL_MULTISAMPLE_ARB);
-        if (samples > 0 && available && !enabled){
-        glEnable(ARBMultisample.GL_MULTISAMPLE_ARB);
-        }
-        }
-         */
-
-        String extensions = JmeIosGLES.glGetString(JmeIosGLES.GL_EXTENSIONS);
-        logger.log(Level.FINE, "GL_EXTENSIONS: {0}", extensions);
-
-        // Get number of compressed formats available.
-        JmeIosGLES.glGetIntegerv(JmeIosGLES.GL_NUM_COMPRESSED_TEXTURE_FORMATS, intBuf16, 0);
-        int numCompressedFormats = intBuf16[0];
-
-        // Allocate buffer for compressed formats.
-        int[] compressedFormats = new int[numCompressedFormats];
-        JmeIosGLES.glGetIntegerv(JmeIosGLES.GL_COMPRESSED_TEXTURE_FORMATS, compressedFormats, 0);
-
-        // Check for errors after all glGet calls.
-        JmeIosGLES.checkGLError();
-
-        // Print compressed formats.
-        for (int i = 0; i < numCompressedFormats; i++) {
-            logger.log(Level.FINE, "Compressed Texture Formats: {0}", compressedFormats[i]);
-        }
-
-        TextureUtil.loadTextureFeatures(extensions);
-
-        applyRenderState(RenderState.DEFAULT);
-        JmeIosGLES.glDisable(JmeIosGLES.GL_DITHER);
-        JmeIosGLES.checkGLError();
-
-        logger.log(Level.FINE, "Caps: {0}", caps);
-        logger.setLevel(store);
-
-        uintIndexSupport = extensions.contains("GL_OES_element_index_uint");
-        logger.log(Level.FINE, "Support for UInt index: {0}", uintIndexSupport);
-    }
-
-
-    /* ------------------------------------------------------------------------------ */
-
-
-    private int extractVersion(String prefixStr, String versionStr) {
-        if (versionStr != null) {
-            int spaceIdx = versionStr.indexOf(" ", prefixStr.length());
-            if (spaceIdx >= 1) {
-                versionStr = versionStr.substring(prefixStr.length(), spaceIdx).trim();
-            } else {
-                versionStr = versionStr.substring(prefixStr.length()).trim();
-            }
-            float version = Float.parseFloat(versionStr);
-            return (int) (version * 100);
-        } else {
-            return -1;
-        }
-    }
-
-    private void deleteRenderBuffer(FrameBuffer fb, RenderBuffer rb) {
-        intBuf1[0] = rb.getId();
-        JmeIosGLES.glDeleteRenderbuffers(1, intBuf1, 0);
-        JmeIosGLES.checkGLError();
-    }
-
-	private int convertUsage(Usage usage) {
-        switch (usage) {
-            case Static:
-                return JmeIosGLES.GL_STATIC_DRAW;
-            case Dynamic:
-                return JmeIosGLES.GL_DYNAMIC_DRAW;
-            case Stream:
-                return JmeIosGLES.GL_STREAM_DRAW;
-            default:
-                throw new RuntimeException("Unknown usage type.");
-        }
-    }
-
-
-    protected void bindProgram(Shader shader) {
-        int shaderId = shader.getId();
-        if (context.boundShaderProgram != shaderId) {
-            JmeIosGLES.glUseProgram(shaderId);
-            JmeIosGLES.checkGLError();
-
-            statistics.onShaderUse(shader, true);
-            boundShader = shader;
-            context.boundShaderProgram = shaderId;
-        } else {
-            statistics.onShaderUse(shader, false);
-        }
-    }
-
-    protected void updateShaderUniforms(Shader shader) {
-        ListMap<String, Uniform> uniforms = shader.getUniformMap();
-        for (int i = 0; i < uniforms.size(); i++) {
-            Uniform uniform = uniforms.getValue(i);
-            if (uniform.isUpdateNeeded()) {
-                updateUniform(shader, uniform);
-            }
-        }
-    }
-
-
-    protected void updateUniform(Shader shader, Uniform uniform) {
-        logger.log(Level.FINE, "IGLESShaderRenderer private updateUniform: " + uniform.getVarType());
-        int shaderId = shader.getId();
-
-        assert uniform.getName() != null;
-        assert shader.getId() > 0;
-
-        if (context.boundShaderProgram != shaderId) {
-            JmeIosGLES.glUseProgram(shaderId);
-            JmeIosGLES.checkGLError();
-
-            statistics.onShaderUse(shader, true);
-            boundShader = shader;
-            context.boundShaderProgram = shaderId;
-        } else {
-            statistics.onShaderUse(shader, false);
-        }
-
-        int loc = uniform.getLocation();
-        if (loc == -1) {
-            return;
-        }
-
-        if (loc == -2) {
-            // get uniform location
-            updateUniformLocation(shader, uniform);
-            if (uniform.getLocation() == -1) {
-                // not declared, ignore
-                uniform.clearUpdateNeeded();
-                return;
-            }
-            loc = uniform.getLocation();
-        }
-
-        if (uniform.getVarType() == null) {
-            // removed logging the warning to avoid flooding the log
-            // (LWJGL also doesn't post a warning)
-            //logger.log(Level.FINEST, "Uniform value is not set yet. Shader: {0}, Uniform: {1}",
-            //        new Object[]{shader.toString(), uniform.toString()});
-            return; // value not set yet..
-        }
-
-        statistics.onUniformSet();
-
-        uniform.clearUpdateNeeded();
-        ByteBuffer bb;//GetPrimitiveArrayCritical
-        FloatBuffer fb;
-        IntBuffer ib;
-        switch (uniform.getVarType()) {
-            case Float:
-                Float f = (Float) uniform.getValue();
-                JmeIosGLES.glUniform1f(loc, f.floatValue());
-                break;
-            case Vector2:
-                Vector2f v2 = (Vector2f) uniform.getValue();
-                JmeIosGLES.glUniform2f(loc, v2.getX(), v2.getY());
-                break;
-            case Vector3:
-                Vector3f v3 = (Vector3f) uniform.getValue();
-                JmeIosGLES.glUniform3f(loc, v3.getX(), v3.getY(), v3.getZ());
-                break;
-            case Vector4:
-                Object val = uniform.getValue();
-                if (val instanceof ColorRGBA) {
-                    ColorRGBA c = (ColorRGBA) val;
-                    JmeIosGLES.glUniform4f(loc, c.r, c.g, c.b, c.a);
-                } else if (val instanceof Vector4f) {
-                    Vector4f c = (Vector4f) val;
-                    JmeIosGLES.glUniform4f(loc, c.x, c.y, c.z, c.w);
-                } else {
-                    Quaternion c = (Quaternion) uniform.getValue();
-                    JmeIosGLES.glUniform4f(loc, c.getX(), c.getY(), c.getZ(), c.getW());
-                }
-                break;
-            case Boolean:
-                Boolean b = (Boolean) uniform.getValue();
-                JmeIosGLES.glUniform1i(loc, b.booleanValue() ? JmeIosGLES.GL_TRUE : JmeIosGLES.GL_FALSE);
-                break;
-            case Matrix3:
-                fb = (FloatBuffer) uniform.getValue();
-                assert fb.remaining() == 9;
-                JmeIosGLES.glUniformMatrix3fv(loc, 1, false, fb);
-                break;
-            case Matrix4:
-                fb = (FloatBuffer) uniform.getValue();
-                assert fb.remaining() == 16;
-                JmeIosGLES.glUniformMatrix4fv(loc, 1, false, fb);
-                break;
-            case IntArray:
-                ib = (IntBuffer) uniform.getValue();
-                JmeIosGLES.glUniform1iv(loc, ib.limit(), ib);
-                break;
-            case FloatArray:
-                fb = (FloatBuffer) uniform.getValue();
-                JmeIosGLES.glUniform1fv(loc, fb.limit(), fb);
-                break;
-            case Vector2Array:
-                fb = (FloatBuffer) uniform.getValue();
-                JmeIosGLES.glUniform2fv(loc, fb.limit() / 2, fb);
-                break;
-            case Vector3Array:
-                fb = (FloatBuffer) uniform.getValue();
-                JmeIosGLES.glUniform3fv(loc, fb.limit() / 3, fb);
-                break;
-            case Vector4Array:
-                fb = (FloatBuffer) uniform.getValue();
-                JmeIosGLES.glUniform4fv(loc, fb.limit() / 4, fb);
-                break;
-            case Matrix4Array:
-                fb = (FloatBuffer) uniform.getValue();
-                JmeIosGLES.glUniformMatrix4fv(loc, fb.limit() / 16, false, fb);
-                break;
-            case Int:
-                Integer i = (Integer) uniform.getValue();
-                JmeIosGLES.glUniform1i(loc, i.intValue());
-                break;
-            default:
-                throw new UnsupportedOperationException("Unsupported uniform type: " + uniform.getVarType());
-        }
-        JmeIosGLES.checkGLError();
-    }
-
-    protected void updateUniformLocation(Shader shader, Uniform uniform) {
-        stringBuf.setLength(0);
-        stringBuf.append(uniform.getName()).append('\0');
-        updateNameBuffer();
-        int loc = JmeIosGLES.glGetUniformLocation(shader.getId(), uniform.getName());
-        JmeIosGLES.checkGLError();
-
-        if (loc < 0) {
-            uniform.setLocation(-1);
-            // uniform is not declared in shader
-        } else {
-            uniform.setLocation(loc);
-        }
-    }
-
-    protected void updateNameBuffer() {
-        int len = stringBuf.length();
-
-        nameBuf.position(0);
-        nameBuf.limit(len);
-        for (int i = 0; i < len; i++) {
-            nameBuf.put((byte) stringBuf.charAt(i));
-        }
-
-        nameBuf.rewind();
-    }
-
-
-    public void updateShaderData(Shader shader) {
-        int id = shader.getId();
-        boolean needRegister = false;
-        if (id == -1) {
-            // create program
-            id = JmeIosGLES.glCreateProgram();
-            JmeIosGLES.checkGLError();
-
-            if (id <= 0) {
-                throw new RendererException("Invalid ID received when trying to create shader program.");
-            }
-
-            shader.setId(id);
-            needRegister = true;
-        }
-
-        for (ShaderSource source : shader.getSources()) {
-            if (source.isUpdateNeeded()) {
-                updateShaderSourceData(source);
-            }
-
-            JmeIosGLES.glAttachShader(id, source.getId());
-            JmeIosGLES.checkGLError();
-        }
-
-        // link shaders to program
-        JmeIosGLES.glLinkProgram(id);
-        JmeIosGLES.checkGLError();
-
-        JmeIosGLES.glGetProgramiv(id, JmeIosGLES.GL_LINK_STATUS, intBuf1, 0);
-        JmeIosGLES.checkGLError();
-
-        boolean linkOK = intBuf1[0] == JmeIosGLES.GL_TRUE;
-        String infoLog = null;
-
-        if (VALIDATE_SHADER || !linkOK) {
-            JmeIosGLES.glGetProgramiv(id, JmeIosGLES.GL_INFO_LOG_LENGTH, intBuf1, 0);
-            JmeIosGLES.checkGLError();
-
-            int length = intBuf1[0];
-            if (length > 3) {
-                // get infos
-                infoLog = JmeIosGLES.glGetProgramInfoLog(id);
-                JmeIosGLES.checkGLError();
-            }
-        }
-
-        if (linkOK) {
-            if (infoLog != null) {
-                logger.log(Level.FINE, "shader link success. \n{0}", infoLog);
-            } else {
-                logger.fine("shader link success");
-            }
-            shader.clearUpdateNeeded();
-            if (needRegister) {
-                // Register shader for clean up if it was created in this method.
-                objManager.registerObject(shader);
-                statistics.onNewShader();
-            } else {
-                // OpenGL spec: uniform locations may change after re-link
-                resetUniformLocations(shader);
-            }
-        } else {
-            if (infoLog != null) {
-                throw new RendererException("Shader link failure, shader:" + shader + "\n" + infoLog);
-            } else {
-                throw new RendererException("Shader link failure, shader:" + shader + "\ninfo: <not provided>");
-            }
-        }
-    }
-
-    protected void resetUniformLocations(Shader shader) {
-        ListMap<String, Uniform> uniforms = shader.getUniformMap();
-        for (int i = 0; i < uniforms.size(); i++) {
-            Uniform uniform = uniforms.getValue(i);
-            uniform.reset(); // e.g check location again
-        }
-    }
-
-    public void updateTexImageData(Image img, Texture.Type type) {
-        int texId = img.getId();
-        if (texId == -1) {
-            // create texture
-            JmeIosGLES.glGenTextures(1, intBuf1, 0);
-            JmeIosGLES.checkGLError();
-
-            texId = intBuf1[0];
-            img.setId(texId);
-            objManager.registerObject(img);
-
-            statistics.onNewTexture();
-        }
-
-        // bind texture
-        int target = convertTextureType(type);
-        if (context.boundTextures[0] != img) {
-            if (context.boundTextureUnit != 0) {
-                JmeIosGLES.glActiveTexture(JmeIosGLES.GL_TEXTURE0);
-                JmeIosGLES.checkGLError();
-
-                context.boundTextureUnit = 0;
-            }
-
-            JmeIosGLES.glBindTexture(target, texId);
-            JmeIosGLES.checkGLError();
-
-            context.boundTextures[0] = img;
-        }
-
-        boolean needMips = false;
-        if (img.isGeneratedMipmapsRequired()) {
-            needMips = true;
-            img.setMipmapsGenerated(true);
-        }
-
-        if (target == JmeIosGLES.GL_TEXTURE_CUBE_MAP) {
-            // Check max texture size before upload
-            if (img.getWidth() > maxCubeTexSize || img.getHeight() > maxCubeTexSize) {
-                throw new RendererException("Cannot upload cubemap " + img + ". The maximum supported cubemap resolution is " + maxCubeTexSize);
-            }
-        } else {
-            if (img.getWidth() > maxTexSize || img.getHeight() > maxTexSize) {
-                throw new RendererException("Cannot upload texture " + img + ". The maximum supported texture resolution is " + maxTexSize);
-            }
-        }
-
-        if (target == JmeIosGLES.GL_TEXTURE_CUBE_MAP) {
-            // Upload a cube map / sky box
-            /*
-            @SuppressWarnings("unchecked")
-            List<AndroidImageInfo> bmps = (List<AndroidImageInfo>) img.getEfficentData();
-            if (bmps != null) {
-                // Native android bitmap
-                if (bmps.size() != 6) {
-                    throw new UnsupportedOperationException("Invalid texture: " + img
-                            + "Cubemap textures must contain 6 data units.");
-                }
-                for (int i = 0; i < 6; i++) {
-                    TextureUtil.uploadTextureBitmap(JmeIosGLES.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, bmps.get(i).getBitmap(), needMips);
-                    bmps.get(i).notifyBitmapUploaded();
-                }
-            } else {
-        	*/
-                // Standard jme3 image data
-                List<ByteBuffer> data = img.getData();
-                if (data.size() != 6) {
-                    throw new UnsupportedOperationException("Invalid texture: " + img
-                            + "Cubemap textures must contain 6 data units.");
-                }
-                for (int i = 0; i < 6; i++) {
-                    TextureUtil.uploadTextureAny(img, JmeIosGLES.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, i, needMips);
-                }
-            //}
-        } else {
-            TextureUtil.uploadTextureAny(img, target, 0, needMips);
-            /*
-            if (img.getEfficentData() instanceof AndroidImageInfo) {
-                AndroidImageInfo info = (AndroidImageInfo) img.getEfficentData();
-                info.notifyBitmapUploaded();
-            }
-            */
-        }
-
-        img.clearUpdateNeeded();
-    }
-
-    private void setupTextureParams(Texture tex) {
-        int target = convertTextureType(tex.getType());
-
-        // filter things
-        int minFilter = convertMinFilter(tex.getMinFilter());
-        int magFilter = convertMagFilter(tex.getMagFilter());
-
-        JmeIosGLES.glTexParameteri(target, JmeIosGLES.GL_TEXTURE_MIN_FILTER, minFilter);
-        JmeIosGLES.checkGLError();
-        JmeIosGLES.glTexParameteri(target, JmeIosGLES.GL_TEXTURE_MAG_FILTER, magFilter);
-        JmeIosGLES.checkGLError();
-
-        /*
-        if (tex.getAnisotropicFilter() > 1){
-
-        if (GLContext.getCapabilities().GL_EXT_texture_filter_anisotropic){
-        glTexParameterf(target,
-        EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT,
-        tex.getAnisotropicFilter());
-        }
-
-        }
-         */
-        // repeat modes
-
-        switch (tex.getType()) {
-            case ThreeDimensional:
-            case CubeMap: // cubemaps use 3D coords
-            // GL_TEXTURE_WRAP_R is not available in api 8
-            //GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_WRAP_R, convertWrapMode(tex.getWrap(WrapAxis.R)));
-            case TwoDimensional:
-            case TwoDimensionalArray:
-                JmeIosGLES.glTexParameteri(target, JmeIosGLES.GL_TEXTURE_WRAP_T, convertWrapMode(tex.getWrap(WrapAxis.T)));
-
-                // fall down here is intentional..
-//          case OneDimensional:
-                JmeIosGLES.glTexParameteri(target, JmeIosGLES.GL_TEXTURE_WRAP_S, convertWrapMode(tex.getWrap(WrapAxis.S)));
-
-                JmeIosGLES.checkGLError();
-                break;
-            default:
-                throw new UnsupportedOperationException("Unknown texture type: " + tex.getType());
-        }
-
-        // R to Texture compare mode
-/*
-        if (tex.getShadowCompareMode() != Texture.ShadowCompareMode.Off){
-        GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_COMPARE_MODE, GLES20.GL_COMPARE_R_TO_TEXTURE);
-        GLES20.glTexParameteri(target, GLES20.GL_DEPTH_TEXTURE_MODE, GLES20.GL_INTENSITY);
-        if (tex.getShadowCompareMode() == Texture.ShadowCompareMode.GreaterOrEqual){
-        GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_COMPARE_FUNC, GLES20.GL_GEQUAL);
-        }else{
-        GLES20.glTexParameteri(target, GLES20.GL_TEXTURE_COMPARE_FUNC, GLES20.GL_LEQUAL);
-        }
-        }
-         */
-    }
-
-    private int convertTextureType(Texture.Type type) {
-        switch (type) {
-            case TwoDimensional:
-                return JmeIosGLES.GL_TEXTURE_2D;
-            //        case TwoDimensionalArray:
-            //            return EXTTextureArray.GL_TEXTURE_2D_ARRAY_EXT;
-//            case ThreeDimensional:
-            //               return GLES20.GL_TEXTURE_3D;
-            case CubeMap:
-                return JmeIosGLES.GL_TEXTURE_CUBE_MAP;
-            default:
-                throw new UnsupportedOperationException("Unknown texture type: " + type);
-        }
-    }
-
-    private int convertMagFilter(Texture.MagFilter filter) {
-        switch (filter) {
-            case Bilinear:
-                return JmeIosGLES.GL_LINEAR;
-            case Nearest:
-                return JmeIosGLES.GL_NEAREST;
-            default:
-                throw new UnsupportedOperationException("Unknown mag filter: " + filter);
-        }
-    }
-
-    private int convertMinFilter(Texture.MinFilter filter) {
-        switch (filter) {
-            case Trilinear:
-                return JmeIosGLES.GL_LINEAR_MIPMAP_LINEAR;
-            case BilinearNearestMipMap:
-                return JmeIosGLES.GL_LINEAR_MIPMAP_NEAREST;
-            case NearestLinearMipMap:
-                return JmeIosGLES.GL_NEAREST_MIPMAP_LINEAR;
-            case NearestNearestMipMap:
-                return JmeIosGLES.GL_NEAREST_MIPMAP_NEAREST;
-            case BilinearNoMipMaps:
-                return JmeIosGLES.GL_LINEAR;
-            case NearestNoMipMaps:
-                return JmeIosGLES.GL_NEAREST;
-            default:
-                throw new UnsupportedOperationException("Unknown min filter: " + filter);
-        }
-    }
-
-    private int convertWrapMode(Texture.WrapMode mode) {
-        switch (mode) {
-            case BorderClamp:
-            case Clamp:
-            case EdgeClamp:
-                return JmeIosGLES.GL_CLAMP_TO_EDGE;
-            case Repeat:
-                return JmeIosGLES.GL_REPEAT;
-            case MirroredRepeat:
-                return JmeIosGLES.GL_MIRRORED_REPEAT;
-            default:
-                throw new UnsupportedOperationException("Unknown wrap mode: " + mode);
-        }
-    }
-
-    private void renderMeshVertexArray(Mesh mesh, int lod, int count) {
-         for (VertexBuffer vb : mesh.getBufferList().getArray()) {
-            if (vb.getBufferType() == Type.InterleavedData
-                    || vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers
-                    || vb.getBufferType() == Type.Index) {
-                continue;
-            }
-
-            if (vb.getStride() == 0) {
-                // not interleaved
-                setVertexAttrib_Array(vb);
-            } else {
-                // interleaved
-                VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
-                setVertexAttrib_Array(vb, interleavedData);
-            }
-        }
-
-        VertexBuffer indices = null;
-        if (mesh.getNumLodLevels() > 0) {
-            indices = mesh.getLodLevel(lod);
-        } else {
-            indices = mesh.getBuffer(Type.Index);//buffers.get(Type.Index.ordinal());
-        }
-        if (indices != null) {
-            drawTriangleList_Array(indices, mesh, count);
-        } else {
-            JmeIosGLES.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount());
-            JmeIosGLES.checkGLError();
-        }
-        clearVertexAttribs();
-    }
-
-    private void renderMeshDefault(Mesh mesh, int lod, int count) {
-        VertexBuffer indices = null;
-        VertexBuffer interleavedData = mesh.getBuffer(Type.InterleavedData);
-        if (interleavedData != null && interleavedData.isUpdateNeeded()) {
-            updateBufferData(interleavedData);
-        }
-
-        //IntMap<VertexBuffer> buffers = mesh.getBuffers();     ;
-        if (mesh.getNumLodLevels() > 0) {
-            indices = mesh.getLodLevel(lod);
-        } else {
-            indices = mesh.getBuffer(Type.Index);// buffers.get(Type.Index.ordinal());
-        }
-        for (VertexBuffer vb : mesh.getBufferList().getArray()){
-            if (vb.getBufferType() == Type.InterleavedData
-                    || vb.getUsage() == Usage.CpuOnly // ignore cpu-only buffers
-                    || vb.getBufferType() == Type.Index) {
-                continue;
-            }
-
-            if (vb.getStride() == 0) {
-                // not interleaved
-                setVertexAttrib(vb);
-            } else {
-                // interleaved
-                setVertexAttrib(vb, interleavedData);
-            }
-        }
-        if (indices != null) {
-            drawTriangleList(indices, mesh, count);
-        } else {
-//            throw new UnsupportedOperationException("Cannot render without index buffer");
-            JmeIosGLES.glDrawArrays(convertElementMode(mesh.getMode()), 0, mesh.getVertexCount());
-            JmeIosGLES.checkGLError();
-        }
-        clearVertexAttribs();
-    }
-
-
-    public void setVertexAttrib(VertexBuffer vb, VertexBuffer idb) {
-        if (vb.getBufferType() == VertexBuffer.Type.Index) {
-            throw new IllegalArgumentException("Index buffers not allowed to be set to vertex attrib");
-        }
-
-        if (vb.isUpdateNeeded() && idb == null) {
-            updateBufferData(vb);
-        }
-
-        int programId = context.boundShaderProgram;
-        if (programId > 0) {
-            Attribute attrib = boundShader.getAttribute(vb.getBufferType());
-            int loc = attrib.getLocation();
-            if (loc == -1) {
-                return; // not defined
-            }
-
-            if (loc == -2) {
-//                stringBuf.setLength(0);
-//                stringBuf.append("in").append(vb.getBufferType().name()).append('\0');
-//                updateNameBuffer();
-
-                String attributeName = "in" + vb.getBufferType().name();
-                loc = JmeIosGLES.glGetAttribLocation(programId, attributeName);
-                JmeIosGLES.checkGLError();
-
-                // not really the name of it in the shader (inPosition\0) but
-                // the internal name of the enum (Position).
-                if (loc < 0) {
-                    attrib.setLocation(-1);
-                    return; // not available in shader.
-                } else {
-                    attrib.setLocation(loc);
-                }
-            }
-
-            VertexBuffer[] attribs = context.boundAttribs;
-            if (!context.attribIndexList.moveToNew(loc)) {
-                JmeIosGLES.glEnableVertexAttribArray(loc);
-                JmeIosGLES.checkGLError();
-                //System.out.println("Enabled ATTRIB IDX: "+loc);
-            }
-            if (attribs[loc] != vb) {
-                // NOTE: Use id from interleaved buffer if specified
-                int bufId = idb != null ? idb.getId() : vb.getId();
-                assert bufId != -1;
-
-                if (bufId == -1) {
-                    logger.warning("invalid buffer id");
-                }
-
-                if (context.boundArrayVBO != bufId) {
-                    JmeIosGLES.glBindBuffer(JmeIosGLES.GL_ARRAY_BUFFER, bufId);
-                    JmeIosGLES.checkGLError();
-
-                    context.boundArrayVBO = bufId;
-                }
-
-                vb.getData().rewind();
-				/*
-                Android22Workaround.glVertexAttribPointer(loc,
-                                    vb.getNumComponents(),
-                                    convertVertexBufferFormat(vb.getFormat()),
-                                    vb.isNormalized(),
-                                    vb.getStride(),
-                                    0);
-				*/
-                logger.warning("iTODO Android22Workaround");
-
-                JmeIosGLES.glVertexAttribPointer(loc,
-                                    vb.getNumComponents(),
-                                    convertVertexBufferFormat(vb.getFormat()),
-                                    vb.isNormalized(),
-                                    vb.getStride(),
-                                    null);
-
-                JmeIosGLES.checkGLError();
-
-                attribs[loc] = vb;
-            }
-        } else {
-            throw new IllegalStateException("Cannot render mesh without shader bound");
-        }
-    }
-
-    public void setVertexAttrib(VertexBuffer vb) {
-        setVertexAttrib(vb, null);
-    }
-
-    public void drawTriangleArray(Mesh.Mode mode, int count, int vertCount) {
-        /*        if (count > 1){
-        ARBDrawInstanced.glDrawArraysInstancedARB(convertElementMode(mode), 0,
-        vertCount, count);
-        }else{*/
-        JmeIosGLES.glDrawArrays(convertElementMode(mode), 0, vertCount);
-        JmeIosGLES.checkGLError();
-        /*
-        }*/
-    }
-
-    public void drawTriangleList(VertexBuffer indexBuf, Mesh mesh, int count) {
-        if (indexBuf.getBufferType() != VertexBuffer.Type.Index) {
-            throw new IllegalArgumentException("Only index buffers are allowed as triangle lists.");
-        }
-
-        if (indexBuf.isUpdateNeeded()) {
-            updateBufferData(indexBuf);
-        }
-
-        int bufId = indexBuf.getId();
-        assert bufId != -1;
-
-        if (bufId == -1) {
-            throw new RendererException("Invalid buffer ID");
-        }
-
-        if (context.boundElementArrayVBO != bufId) {
-            JmeIosGLES.glBindBuffer(JmeIosGLES.GL_ELEMENT_ARRAY_BUFFER, bufId);
-            JmeIosGLES.checkGLError();
-
-            context.boundElementArrayVBO = bufId;
-        }
-
-        int vertCount = mesh.getVertexCount();
-        boolean useInstancing = count > 1 && caps.contains(Caps.MeshInstancing);
-
-        Buffer indexData = indexBuf.getData();
-
-        if (!uintIndexSupport && (indexBuf.getFormat() == Format.UnsignedInt)) {
-            throw new RendererException("OpenGL ES does not support 32-bit index buffers." +
-                                        "Split your models to avoid going over 65536 vertices.");
-        }
-
-        if (mesh.getMode() == Mode.Hybrid) {
-            int[] modeStart = mesh.getModeStart();
-            int[] elementLengths = mesh.getElementLengths();
-
-            int elMode = convertElementMode(Mode.Triangles);
-            int fmt = convertVertexBufferFormat(indexBuf.getFormat());
-            int elSize = indexBuf.getFormat().getComponentSize();
-            int listStart = modeStart[0];
-            int stripStart = modeStart[1];
-            int fanStart = modeStart[2];
-            int curOffset = 0;
-            for (int i = 0; i < elementLengths.length; i++) {
-                if (i == stripStart) {
-                    elMode = convertElementMode(Mode.TriangleStrip);
-                } else if (i == fanStart) {
-                    elMode = convertElementMode(Mode.TriangleStrip);
-                }
-                int elementLength = elementLengths[i];
-
-                if (useInstancing) {
-                    //ARBDrawInstanced.
-                    throw new IllegalArgumentException("instancing is not supported.");
-                    /*
-                    GLES20.glDrawElementsInstancedARB(elMode,
-                    elementLength,
-                    fmt,
-                    curOffset,
-                    count);
-                     */
-                } else {
-                    indexBuf.getData().position(curOffset);
-                    JmeIosGLES.glDrawElements(elMode, elementLength, fmt, indexBuf.getData());
-                    JmeIosGLES.checkGLError();
-                    /*
-                    glDrawRangeElements(elMode,
-                    0,
-                    vertCount,
-                    elementLength,
-                    fmt,
-                    curOffset);
-                     */
-                }
-
-                curOffset += elementLength * elSize;
-            }
-        } else {
-            if (useInstancing) {
-                throw new IllegalArgumentException("instancing is not supported.");
-                //ARBDrawInstanced.
-/*
-                GLES20.glDrawElementsInstancedARB(convertElementMode(mesh.getMode()),
-                indexBuf.getData().limit(),
-                convertVertexBufferFormat(indexBuf.getFormat()),
-                0,
-                count);
-                 */
-            } else {
-				logger.log(Level.FINE, "IGLESShaderRenderer drawTriangleList TODO check");
-                indexData.rewind();
-                JmeIosGLES.glDrawElementsIndex(
-                        convertElementMode(mesh.getMode()),
-                        indexBuf.getData().limit(),
-                        convertVertexBufferFormat(indexBuf.getFormat()),
-                        0);
-				/*TODO:
-                indexData.rewind();
-                JmeIosGLES.glDrawElements(
-                        convertElementMode(mesh.getMode()),
-                        indexBuf.getData().limit(),
-                        convertVertexBufferFormat(indexBuf.getFormat()),
-                        0);
-                */
-                JmeIosGLES.checkGLError();
-            }
-        }
-    }
-
-    public int convertElementMode(Mesh.Mode mode) {
-        switch (mode) {
-            case Points:
-                return JmeIosGLES.GL_POINTS;
-            case Lines:
-                return JmeIosGLES.GL_LINES;
-            case LineLoop:
-                return JmeIosGLES.GL_LINE_LOOP;
-            case LineStrip:
-                return JmeIosGLES.GL_LINE_STRIP;
-            case Triangles:
-                return JmeIosGLES.GL_TRIANGLES;
-            case TriangleFan:
-                return JmeIosGLES.GL_TRIANGLE_FAN;
-            case TriangleStrip:
-                return JmeIosGLES.GL_TRIANGLE_STRIP;
-            default:
-                throw new UnsupportedOperationException("Unrecognized mesh mode: " + mode);
-        }
-    }
-
-
-    private int convertVertexBufferFormat(Format format) {
-        switch (format) {
-            case Byte:
-                return JmeIosGLES.GL_BYTE;
-            case UnsignedByte:
-                return JmeIosGLES.GL_UNSIGNED_BYTE;
-            case Short:
-                return JmeIosGLES.GL_SHORT;
-            case UnsignedShort:
-                return JmeIosGLES.GL_UNSIGNED_SHORT;
-            case Int:
-                return JmeIosGLES.GL_INT;
-            case UnsignedInt:
-                return JmeIosGLES.GL_UNSIGNED_INT;
-            /*
-            case Half:
-            return NVHalfFloat.GL_HALF_FLOAT_NV;
-            //                return ARBHalfFloatVertex.GL_HALF_FLOAT;
-             */
-            case Float:
-                return JmeIosGLES.GL_FLOAT;
-//            case Double:
-//                return JmeIosGLES.GL_DOUBLE;
-            default:
-                throw new RuntimeException("Unknown buffer format.");
-
-        }
-    }
-
-    public void clearVertexAttribs() {
-        IDList attribList = context.attribIndexList;
-        for (int i = 0; i < attribList.oldLen; i++) {
-            int idx = attribList.oldList[i];
-
-            JmeIosGLES.glDisableVertexAttribArray(idx);
-            JmeIosGLES.checkGLError();
-
-            context.boundAttribs[idx] = null;
-        }
-        context.attribIndexList.copyNewToOld();
-    }
-
-    public void updateFrameBuffer(FrameBuffer fb) {
-        int id = fb.getId();
-        if (id == -1) {
-            // create FBO
-            JmeIosGLES.glGenFramebuffers(1, intBuf1, 0);
-            JmeIosGLES.checkGLError();
-
-            id = intBuf1[0];
-            fb.setId(id);
-            objManager.registerObject(fb);
-
-            statistics.onNewFrameBuffer();
-        }
-
-        if (context.boundFBO != id) {
-            JmeIosGLES.glBindFramebuffer(JmeIosGLES.GL_FRAMEBUFFER, id);
-            JmeIosGLES.checkGLError();
-
-            // binding an FBO automatically sets draw buf to GL_COLOR_ATTACHMENT0
-            context.boundDrawBuf = 0;
-            context.boundFBO = id;
-        }
-
-        FrameBuffer.RenderBuffer depthBuf = fb.getDepthBuffer();
-        if (depthBuf != null) {
-            updateFrameBufferAttachment(fb, depthBuf);
-        }
-
-        for (int i = 0; i < fb.getNumColorBuffers(); i++) {
-            FrameBuffer.RenderBuffer colorBuf = fb.getColorBuffer(i);
-            updateFrameBufferAttachment(fb, colorBuf);
-        }
-
-        fb.clearUpdateNeeded();
-    }
-
-
-    public void updateFrameBufferAttachment(FrameBuffer fb, RenderBuffer rb) {
-        boolean needAttach;
-        if (rb.getTexture() == null) {
-            // if it hasn't been created yet, then attach is required.
-            needAttach = rb.getId() == -1;
-            updateRenderBuffer(fb, rb);
-        } else {
-            needAttach = false;
-            updateRenderTexture(fb, rb);
-        }
-        if (needAttach) {
-            JmeIosGLES.glFramebufferRenderbuffer(JmeIosGLES.GL_FRAMEBUFFER,
-                    convertAttachmentSlot(rb.getSlot()),
-                    JmeIosGLES.GL_RENDERBUFFER,
-                    rb.getId());
-
-            JmeIosGLES.checkGLError();
-        }
-    }
-
-
-    public void updateRenderTexture(FrameBuffer fb, RenderBuffer rb) {
-        Texture tex = rb.getTexture();
-        Image image = tex.getImage();
-        if (image.isUpdateNeeded()) {
-            updateTexImageData(image, tex.getType());
-
-            // NOTE: For depth textures, sets nearest/no-mips mode
-            // Required to fix "framebuffer unsupported"
-            // for old NVIDIA drivers!
-            setupTextureParams(tex);
-        }
-
-        JmeIosGLES.glFramebufferTexture2D(JmeIosGLES.GL_FRAMEBUFFER,
-                convertAttachmentSlot(rb.getSlot()),
-                convertTextureType(tex.getType()),
-                image.getId(),
-                0);
-
-        JmeIosGLES.checkGLError();
-    }
-
-
-    private void updateRenderBuffer(FrameBuffer fb, RenderBuffer rb) {
-        int id = rb.getId();
-        if (id == -1) {
-            JmeIosGLES.glGenRenderbuffers(1, intBuf1, 0);
-            JmeIosGLES.checkGLError();
-
-            id = intBuf1[0];
-            rb.setId(id);
-        }
-
-        if (context.boundRB != id) {
-            JmeIosGLES.glBindRenderbuffer(JmeIosGLES.GL_RENDERBUFFER, id);
-            JmeIosGLES.checkGLError();
-
-            context.boundRB = id;
-        }
-
-        if (fb.getWidth() > maxRBSize || fb.getHeight() > maxRBSize) {
-            throw new RendererException("Resolution " + fb.getWidth()
-                    + ":" + fb.getHeight() + " is not supported.");
-        }
-
-        TextureUtil.IosGLImageFormat imageFormat = TextureUtil.getImageFormat(rb.getFormat());
-        if (imageFormat.renderBufferStorageFormat == 0) {
-            throw new RendererException("The format '" + rb.getFormat() + "' cannot be used for renderbuffers.");
-        }
-
-//        if (fb.getSamples() > 1 && GLContext.getCapabilities().GL_EXT_framebuffer_multisample) {
-        if (fb.getSamples() > 1) {
-//            // FIXME
-            throw new RendererException("Multisample FrameBuffer is not supported yet.");
-//            int samples = fb.getSamples();
-//            if (maxFBOSamples < samples) {
-//                samples = maxFBOSamples;
-//            }
-//            glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT,
-//                    samples,
-//                    glFmt.internalFormat,
-//                    fb.getWidth(),
-//                    fb.getHeight());
-        } else {
-            JmeIosGLES.glRenderbufferStorage(JmeIosGLES.GL_RENDERBUFFER,
-                    imageFormat.renderBufferStorageFormat,
-                    fb.getWidth(),
-                    fb.getHeight());
-
-            JmeIosGLES.checkGLError();
-        }
-    }
-
-
-    private int convertAttachmentSlot(int attachmentSlot) {
-        // can also add support for stencil here
-        if (attachmentSlot == FrameBuffer.SLOT_DEPTH) {
-            return JmeIosGLES.GL_DEPTH_ATTACHMENT;
-        } else if (attachmentSlot == 0) {
-            return JmeIosGLES.GL_COLOR_ATTACHMENT0;
-        } else {
-            throw new UnsupportedOperationException("Android does not support multiple color attachments to an FBO");
-        }
-    }
-
-
-    private void checkFrameBufferStatus(FrameBuffer fb) {
-        try {
-            checkFrameBufferError();
-        } catch (IllegalStateException ex) {
-            logger.log(Level.SEVERE, "=== jMonkeyEngine FBO State ===\n{0}", fb);
-            printRealFrameBufferInfo(fb);
-            throw ex;
-        }
-    }
-
-    private void checkFrameBufferError() {
-        int status = JmeIosGLES.glCheckFramebufferStatus(JmeIosGLES.GL_FRAMEBUFFER);
-        switch (status) {
-            case JmeIosGLES.GL_FRAMEBUFFER_COMPLETE:
-                break;
-            case JmeIosGLES.GL_FRAMEBUFFER_UNSUPPORTED:
-                //Choose different formats
-                throw new IllegalStateException("Framebuffer object format is "
-                        + "unsupported by the video hardware.");
-            case JmeIosGLES.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
-                throw new IllegalStateException("Framebuffer has erronous attachment.");
-            case JmeIosGLES.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
-                throw new IllegalStateException("Framebuffer doesn't have any renderbuffers attached.");
-            case JmeIosGLES.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
-                throw new IllegalStateException("Framebuffer attachments must have same dimensions.");
-//            case GLES20.GL_FRAMEBUFFER_INCOMPLETE_FORMATS:
-//                throw new IllegalStateException("Framebuffer attachments must have same formats.");
-//            case GLES20.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER:
-//                throw new IllegalStateException("Incomplete draw buffer.");
-//            case GLES20.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
-//                throw new IllegalStateException("Incomplete read buffer.");
-//            case GLES20.GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE_EXT:
-//                throw new IllegalStateException("Incomplete multisample buffer.");
-            default:
-                //Programming error; will fail on all hardware
-                throw new IllegalStateException("Some video driver error "
-                        + "or programming error occured. "
-                        + "Framebuffer object status is invalid: " + status);
-        }
-    }
-
-    private void printRealRenderBufferInfo(FrameBuffer fb, RenderBuffer rb, String name) {
-        System.out.println("== Renderbuffer " + name + " ==");
-        System.out.println("RB ID: " + rb.getId());
-        System.out.println("Is proper? " + JmeIosGLES.glIsRenderbuffer(rb.getId()));
-
-        int attachment = convertAttachmentSlot(rb.getSlot());
-
-        //intBuf16.clear();
-        JmeIosGLES.glGetFramebufferAttachmentParameteriv(JmeIosGLES.GL_FRAMEBUFFER,
-                attachment, JmeIosGLES.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, intBuf16, 0);
-        int type = intBuf16[0];
-
-        //intBuf16.clear();
-        JmeIosGLES.glGetFramebufferAttachmentParameteriv(JmeIosGLES.GL_FRAMEBUFFER,
-                attachment, JmeIosGLES.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, intBuf16, 0);
-        int rbName = intBuf16[0];
-
-        switch (type) {
-            case JmeIosGLES.GL_NONE:
-                System.out.println("Type: None");
-                break;
-            case JmeIosGLES.GL_TEXTURE:
-                System.out.println("Type: Texture");
-                break;
-            case JmeIosGLES.GL_RENDERBUFFER:
-                System.out.println("Type: Buffer");
-                System.out.println("RB ID: " + rbName);
-                break;
-        }
-	}
-
-    private void printRealFrameBufferInfo(FrameBuffer fb) {
-//        boolean doubleBuffer = GLES20.glGetBooleanv(GLES20.GL_DOUBLEBUFFER);
-        boolean doubleBuffer = false; // FIXME
-//        String drawBuf = getTargetBufferName(glGetInteger(GL_DRAW_BUFFER));
-//        String readBuf = getTargetBufferName(glGetInteger(GL_READ_BUFFER));
-
-        int fbId = fb.getId();
-        //intBuf16.clear();
-//        int curDrawBinding = GLES20.glGetIntegerv(GLES20.GL_DRAW_FRAMEBUFFER_BINDING);
-//        int curReadBinding = glGetInteger(ARBFramebufferObject.GL_READ_FRAMEBUFFER_BINDING);
-
-        System.out.println("=== OpenGL FBO State ===");
-        System.out.println("Context doublebuffered? " + doubleBuffer);
-        System.out.println("FBO ID: " + fbId);
-        System.out.println("Is proper? " + JmeIosGLES.glIsFramebuffer(fbId));
-//        System.out.println("Is bound to draw? " + (fbId == curDrawBinding));
-//        System.out.println("Is bound to read? " + (fbId == curReadBinding));
-//        System.out.println("Draw buffer: " + drawBuf);
-//        System.out.println("Read buffer: " + readBuf);
-
-        if (context.boundFBO != fbId) {
-            JmeIosGLES.glBindFramebuffer(JmeIosGLES.GL_FRAMEBUFFER, fbId);
-            context.boundFBO = fbId;
-        }
-
-        if (fb.getDepthBuffer() != null) {
-            printRealRenderBufferInfo(fb, fb.getDepthBuffer(), "Depth");
-        }
-        for (int i = 0; i < fb.getNumColorBuffers(); i++) {
-            printRealRenderBufferInfo(fb, fb.getColorBuffer(i), "Color" + i);
-        }
-
-
-    }
-
-    public void drawTriangleList_Array(VertexBuffer indexBuf, Mesh mesh, int count) {
-        if (indexBuf.getBufferType() != VertexBuffer.Type.Index) {
-            throw new IllegalArgumentException("Only index buffers are allowed as triangle lists.");
-        }
-
-        boolean useInstancing = count > 1 && caps.contains(Caps.MeshInstancing);
-        if (useInstancing) {
-            throw new IllegalArgumentException("Caps.MeshInstancing is not supported.");
-        }
-
-        int vertCount = mesh.getVertexCount();
-        Buffer indexData = indexBuf.getData();
-        indexData.rewind();
-
-        if (mesh.getMode() == Mode.Hybrid) {
-            int[] modeStart = mesh.getModeStart();
-            int[] elementLengths = mesh.getElementLengths();
-
-            int elMode = convertElementMode(Mode.Triangles);
-            int fmt = convertVertexBufferFormat(indexBuf.getFormat());
-            int elSize = indexBuf.getFormat().getComponentSize();
-            int listStart = modeStart[0];
-            int stripStart = modeStart[1];
-            int fanStart = modeStart[2];
-            int curOffset = 0;
-            for (int i = 0; i < elementLengths.length; i++) {
-                if (i == stripStart) {
-                    elMode = convertElementMode(Mode.TriangleStrip);
-                } else if (i == fanStart) {
-                    elMode = convertElementMode(Mode.TriangleFan);
-                }
-                int elementLength = elementLengths[i];
-
-                indexBuf.getData().position(curOffset);
-                JmeIosGLES.glDrawElements(elMode, elementLength, fmt, indexBuf.getData());
-                JmeIosGLES.checkGLError();
-
-                curOffset += elementLength * elSize;
-            }
-        } else {
-           JmeIosGLES.glDrawElements(
-                    convertElementMode(mesh.getMode()),
-                    indexBuf.getData().limit(),
-                    convertVertexBufferFormat(indexBuf.getFormat()),
-                    indexBuf.getData());
-            JmeIosGLES.checkGLError();
-        }
-    }
-
-    public void setVertexAttrib_Array(VertexBuffer vb, VertexBuffer idb) {
-        if (vb.getBufferType() == VertexBuffer.Type.Index) {
-            throw new IllegalArgumentException("Index buffers not allowed to be set to vertex attrib");
-        }
-
-        // Get shader
-        int programId = context.boundShaderProgram;
-        if (programId > 0) {
-            VertexBuffer[] attribs = context.boundAttribs;
-
-            Attribute attrib = boundShader.getAttribute(vb.getBufferType());
-            int loc = attrib.getLocation();
-            if (loc == -1) {
-                //throw new IllegalArgumentException("Location is invalid for attrib: [" + vb.getBufferType().name() + "]");
-                return;
-            } else if (loc == -2) {
-                String attributeName = "in" + vb.getBufferType().name();
-
-                loc = JmeIosGLES.glGetAttribLocation(programId, attributeName);
-                JmeIosGLES.checkGLError();
-
-                if (loc < 0) {
-                    attrib.setLocation(-1);
-                    return; // not available in shader.
-                } else {
-                    attrib.setLocation(loc);
-                }
-
-            }  // if (loc == -2)
-
-            if ((attribs[loc] != vb) || vb.isUpdateNeeded()) {
-                // NOTE: Use data from interleaved buffer if specified
-                VertexBuffer avb = idb != null ? idb : vb;
-                avb.getData().rewind();
-                avb.getData().position(vb.getOffset());
-
-                // Upload attribute data
-                JmeIosGLES.glVertexAttribPointer(loc,
-                        vb.getNumComponents(),
-                        convertVertexBufferFormat(vb.getFormat()),
-                        vb.isNormalized(),
-                        vb.getStride(),
-                        avb.getData());
-
-                JmeIosGLES.checkGLError();
-
-                JmeIosGLES.glEnableVertexAttribArray(loc);
-                JmeIosGLES.checkGLError();
-
-                attribs[loc] = vb;
-            } // if (attribs[loc] != vb)
-        } else {
-            throw new IllegalStateException("Cannot render mesh without shader bound");
-        }
-    }
-
-    public void setVertexAttrib_Array(VertexBuffer vb) {
-        setVertexAttrib_Array(vb, null);
-    }
-
-
-    public void updateShaderSourceData(ShaderSource source) {
-        int id = source.getId();
-        if (id == -1) {
-            // Create id
-            id = JmeIosGLES.glCreateShader(convertShaderType(source.getType()));
-            JmeIosGLES.checkGLError();
-
-            if (id <= 0) {
-                throw new RendererException("Invalid ID received when trying to create shader.");
-            }
-            source.setId(id);
-        }
-
-        if (!source.getLanguage().equals("GLSL100")) {
-            throw new RendererException("This shader cannot run in OpenGL ES. "
-                                      + "Only GLSL 1.0 shaders are supported.");
-        }
-
-        // upload shader source
-        // merge the defines and source code
-        byte[] definesCodeData = source.getDefines().getBytes();
-        byte[] sourceCodeData = source.getSource().getBytes();
-        ByteBuffer codeBuf = BufferUtils.createByteBuffer(definesCodeData.length
-                                                        + sourceCodeData.length);
-        codeBuf.put(definesCodeData);
-        codeBuf.put(sourceCodeData);
-        codeBuf.flip();
-
-        if (powerVr && source.getType() == ShaderType.Vertex) {
-            // XXX: This is to fix a bug in old PowerVR, remove
-            // when no longer applicable.
-            JmeIosGLES.glShaderSource(
-                    id, source.getDefines()
-                    + source.getSource());
-        } else {
-            String precision ="";
-            if (source.getType() == ShaderType.Fragment) {
-                precision =  "precision mediump float;\n";
-            }
-            JmeIosGLES.glShaderSource(
-                    id,
-                    precision
-                    +source.getDefines()
-                    + source.getSource());
-        }
-//        int range[] = new int[2];
-//        int precision[] =  new int[1];
-//        GLES20.glGetShaderPrecisionFormat(GLES20.GL_VERTEX_SHADER, GLES20.GL_HIGH_FLOAT, range, 0, precision, 0);
-//        System.out.println("PRECISION HIGH FLOAT VERTEX");
-//        System.out.println("range "+range[0]+"," +range[1]);
-//        System.out.println("precision "+precision[0]);
-
-        JmeIosGLES.glCompileShader(id);
-        JmeIosGLES.checkGLError();
-
-        JmeIosGLES.glGetShaderiv(id, JmeIosGLES.GL_COMPILE_STATUS, intBuf1, 0);
-        JmeIosGLES.checkGLError();
-
-        boolean compiledOK = intBuf1[0] == JmeIosGLES.GL_TRUE;
-        String infoLog = null;
-
-        if (VALIDATE_SHADER || !compiledOK) {
-            // even if compile succeeded, check
-            // log for warnings
-            JmeIosGLES.glGetShaderiv(id, JmeIosGLES.GL_INFO_LOG_LENGTH, intBuf1, 0);
-            JmeIosGLES.checkGLError();
-            infoLog = JmeIosGLES.glGetShaderInfoLog(id);
-        }
-
-        if (compiledOK) {
-            if (infoLog != null) {
-                logger.log(Level.FINE, "compile success: {0}, {1}", new Object[]{source.getName(), infoLog});
-            } else {
-                logger.log(Level.FINE, "compile success: {0}", source.getName());
-            }
-            source.clearUpdateNeeded();
-        } else {
-           logger.log(Level.WARNING, "Bad compile of:\n{0}",
-                    new Object[]{ShaderDebug.formatShaderSource(stringBuf.toString() + source.getDefines() + source.getSource())});
-            if (infoLog != null) {
-                throw new RendererException("compile error in: " + source + "\n" + infoLog);
-            } else {
-                throw new RendererException("compile error in: " + source + "\nerror: <not provided>");
-            }
-        }
-    }
-
-
-    public int convertShaderType(ShaderType type) {
-        switch (type) {
-            case Fragment:
-                return JmeIosGLES.GL_FRAGMENT_SHADER;
-            case Vertex:
-                return JmeIosGLES.GL_VERTEX_SHADER;
-//            case Geometry:
-//                return ARBGeometryShader4.GL_GEOMETRY_SHADER_ARB;
-            default:
-                throw new RuntimeException("Unrecognized shader type.");
-        }
-    }
-
-	private int convertTestFunction(RenderState.TestFunction testFunc) {
-		switch (testFunc) {
-			case Never:
-				return JmeIosGLES.GL_NEVER;
-			case Less:
-				return JmeIosGLES.GL_LESS;
-			case LessOrEqual:
-				return JmeIosGLES.GL_LEQUAL;
-			case Greater:
-				return JmeIosGLES.GL_GREATER;
-			case GreaterOrEqual:
-				return JmeIosGLES.GL_GEQUAL;
-			case Equal:
-				return JmeIosGLES.GL_EQUAL;
-			case NotEqual:
-				return JmeIosGLES.GL_NOTEQUAL;
-			case Always:
-				return JmeIosGLES.GL_ALWAYS;
-			default:
-				throw new UnsupportedOperationException("Unrecognized test function: " + testFunc);
-		}
-	}
-
-    public void setMainFrameBufferSrgb(boolean srgb) {
-
-    }
-
-    public void setLinearizeSrgbImages(boolean linearize) {
-
-    }
-
-    public void readFrameBufferWithFormat(FrameBuffer fb, ByteBuffer byteBuf, Image.Format format) {
-        throw new UnsupportedOperationException("Not supported yet. URA will make that work seamlessly");
-    }
-}

+ 7 - 1
jme3-ios/src/main/java/com/jme3/renderer/ios/IosGL.java

@@ -34,6 +34,7 @@ package com.jme3.renderer.ios;
 import com.jme3.renderer.RendererException;
 import com.jme3.renderer.opengl.GL;
 import com.jme3.renderer.opengl.GLExt;
+import com.jme3.renderer.opengl.GLFbo;
 import java.nio.Buffer;
 import java.nio.BufferOverflowException;
 import java.nio.ByteBuffer;
@@ -46,10 +47,13 @@ import java.nio.ShortBuffer;
  * 
  * @author Kirill Vainer
  */
-public class IosGL implements GL, GLExt {
+public class IosGL implements GL, GLExt, GLFbo {
     
     private final int[] temp_array = new int[16];
     
+    public void resetStats() {
+    }
+    
     private static int getLimitBytes(ByteBuffer buffer) {
         checkLimit(buffer);
         return buffer.limit();
@@ -90,7 +94,9 @@ public class IosGL implements GL, GLExt {
         if (buffer.remaining() < n) { 
             throw new BufferOverflowException();
         }
+        int pos = buffer.position();
         buffer.put(array, 0, n);
+        buffer.position(pos);
     }
     
     private static void checkLimit(Buffer buffer) {

+ 0 - 576
jme3-ios/src/main/java/com/jme3/renderer/ios/TextureUtil.java

@@ -1,576 +0,0 @@
-package com.jme3.renderer.ios;
-
-//import android.graphics.Bitmap;
-//import android.opengl.ETC1;
-//import android.opengl.ETC1Util.ETC1Texture;
-//import android.opengl.JmeIosGLES;
-//import android.opengl.GLUtils;
-//import com.jme3.asset.AndroidImageInfo;
-import com.jme3.renderer.ios.JmeIosGLES;
-import com.jme3.math.FastMath;
-import com.jme3.renderer.RendererException;
-import com.jme3.texture.Image;
-import com.jme3.texture.Image.Format;
-import com.jme3.util.BufferUtils;
-import java.nio.ByteBuffer;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-
-public class TextureUtil {
-
-    private static final Logger logger = Logger.getLogger(TextureUtil.class.getName());
-    //TODO Make this configurable through appSettings
-    public static boolean ENABLE_COMPRESSION = true;
-    private static boolean NPOT = false;
-    private static boolean ETC1support = false;
-    private static boolean DXT1 = false;
-    private static boolean PVRTC = false;
-    private static boolean DEPTH24_STENCIL8 = false;
-    private static boolean DEPTH_TEXTURE = false;
-    private static boolean RGBA8 = false;
-    
-    // Same constant used by both GL_ARM_rgba8 and GL_OES_rgb8_rgba8.
-    private static final int GL_RGBA8 = 0x8058;
-    
-    private static final int GL_DXT1 = 0x83F0;
-    private static final int GL_DXT1A = 0x83F1;
-    
-    private static final int GL_DEPTH_STENCIL_OES = 0x84F9;
-    private static final int GL_UNSIGNED_INT_24_8_OES = 0x84FA;
-    private static final int GL_DEPTH24_STENCIL8_OES = 0x88F0;
-
-    public static void loadTextureFeatures(String extensionString) {
-        ETC1support = extensionString.contains("GL_OES_compressed_ETC1_RGB8_texture");
-        DEPTH24_STENCIL8 = extensionString.contains("GL_OES_packed_depth_stencil");
-        NPOT = extensionString.contains("GL_IMG_texture_npot") 
-                || extensionString.contains("GL_OES_texture_npot") 
-                || extensionString.contains("GL_NV_texture_npot_2D_mipmap");
-        
-        PVRTC = extensionString.contains("GL_IMG_texture_compression_pvrtc");
-        
-        DXT1 = extensionString.contains("GL_EXT_texture_compression_dxt1");
-        DEPTH_TEXTURE = extensionString.contains("GL_OES_depth_texture");
-        
-        RGBA8 = extensionString.contains("GL_ARM_rgba8") ||
-                extensionString.contains("GL_OES_rgb8_rgba8");
-        
-        logger.log(Level.FINE, "Supports ETC1? {0}", ETC1support);
-        logger.log(Level.FINE, "Supports DEPTH24_STENCIL8? {0}", DEPTH24_STENCIL8);
-        logger.log(Level.FINE, "Supports NPOT? {0}", NPOT);
-        logger.log(Level.FINE, "Supports PVRTC? {0}", PVRTC);
-        logger.log(Level.FINE, "Supports DXT1? {0}", DXT1);
-        logger.log(Level.FINE, "Supports DEPTH_TEXTURE? {0}", DEPTH_TEXTURE);
-        logger.log(Level.FINE, "Supports RGBA8? {0}", RGBA8);
-    }
-
-	/*
-    private static void buildMipmap(Bitmap bitmap, boolean compress) {
-        int level = 0;
-        int height = bitmap.getHeight();
-        int width = bitmap.getWidth();
-
-        logger.log(Level.FINEST, " - Generating mipmaps for bitmap using SOFTWARE");
-
-        JmeIosGLES.glPixelStorei(JmeIosGLES.GL_UNPACK_ALIGNMENT, 1);
-
-        while (height >= 1 || width >= 1) {
-            //First of all, generate the texture from our bitmap and set it to the according level
-            if (compress) {
-                logger.log(Level.FINEST, " - Uploading LOD level {0} ({1}x{2}) with compression.", new Object[]{level, width, height});
-                uploadBitmapAsCompressed(JmeIosGLES.GL_TEXTURE_2D, level, bitmap, false, 0, 0);
-            } else {
-                logger.log(Level.FINEST, " - Uploading LOD level {0} ({1}x{2}) directly.", new Object[]{level, width, height});
-                GLUtils.texImage2D(JmeIosGLES.GL_TEXTURE_2D, level, bitmap, 0);
-            }
-
-            if (height == 1 || width == 1) {
-                break;
-            }
-
-            //Increase the mipmap level
-            height /= 2;
-            width /= 2;
-            Bitmap bitmap2 = Bitmap.createScaledBitmap(bitmap, width, height, true);
-
-            // Recycle any bitmaps created as a result of scaling the bitmap.
-            // Do not recycle the original image (mipmap level 0)
-            if (level != 0) {
-                bitmap.recycle();
-            }
-
-            bitmap = bitmap2;
-
-            level++;
-        }
-    }
-
-    private static void uploadBitmapAsCompressed(int target, int level, Bitmap bitmap, boolean subTexture, int x, int y) {
-        if (bitmap.hasAlpha()) {
-            logger.log(Level.FINEST, " - Uploading bitmap directly. Cannot compress as alpha present.");
-            if (subTexture) {
-                GLUtils.texSubImage2D(target, level, x, y, bitmap);
-                JmeIosGLES.checkGLError();
-            } else {
-                GLUtils.texImage2D(target, level, bitmap, 0);
-                JmeIosGLES.checkGLError();
-            }
-        } else {
-            // Convert to RGB565
-            int bytesPerPixel = 2;
-            Bitmap rgb565 = bitmap.copy(Bitmap.Config.RGB_565, true);
-
-            // Put texture data into ByteBuffer
-            ByteBuffer inputImage = BufferUtils.createByteBuffer(bitmap.getRowBytes() * bitmap.getHeight());
-            rgb565.copyPixelsToBuffer(inputImage);
-            inputImage.position(0);
-
-            // Delete the copied RGB565 image
-            rgb565.recycle();
-
-            // Encode the image into the output bytebuffer
-            int encodedImageSize = ETC1.getEncodedDataSize(bitmap.getWidth(), bitmap.getHeight());
-            ByteBuffer compressedImage = BufferUtils.createByteBuffer(encodedImageSize);
-            ETC1.encodeImage(inputImage, bitmap.getWidth(),
-                    bitmap.getHeight(),
-                    bytesPerPixel,
-                    bytesPerPixel * bitmap.getWidth(),
-                    compressedImage);
-
-            // Delete the input image buffer
-            BufferUtils.destroyDirectBuffer(inputImage);
-
-            // Create an ETC1Texture from the compressed image data
-            ETC1Texture etc1tex = new ETC1Texture(bitmap.getWidth(), bitmap.getHeight(), compressedImage);
-
-            // Upload the ETC1Texture
-            if (bytesPerPixel == 2) {
-                int oldSize = (bitmap.getRowBytes() * bitmap.getHeight());
-                int newSize = compressedImage.capacity();
-                logger.log(Level.FINEST, " - Uploading compressed image to GL, oldSize = {0}, newSize = {1}, ratio = {2}", new Object[]{oldSize, newSize, (float) oldSize / newSize});
-                if (subTexture) {
-                    JmeIosGLES.glCompressedTexSubImage2D(target,
-                            level,
-                            x, y,
-                            bitmap.getWidth(),
-                            bitmap.getHeight(),
-                            ETC1.ETC1_RGB8_OES,
-                            etc1tex.getData().capacity(),
-                            etc1tex.getData());
-                    
-                    JmeIosGLES.checkGLError();
-                } else {
-                    JmeIosGLES.glCompressedTexImage2D(target,
-                            level,
-                            ETC1.ETC1_RGB8_OES,
-                            bitmap.getWidth(),
-                            bitmap.getHeight(),
-                            0,
-                            etc1tex.getData().capacity(),
-                            etc1tex.getData());
-                    
-                    JmeIosGLES.checkGLError();
-                }
-
-//                ETC1Util.loadTexture(target, level, 0, JmeIosGLES.GL_RGB,
-//                        JmeIosGLES.GL_UNSIGNED_SHORT_5_6_5, etc1Texture);
-//            } else if (bytesPerPixel == 3) {
-//                ETC1Util.loadTexture(target, level, 0, JmeIosGLES.GL_RGB,
-//                        JmeIosGLES.GL_UNSIGNED_BYTE, etc1Texture);
-            }
-
-            BufferUtils.destroyDirectBuffer(compressedImage);
-        }
-    }
-
-    /**
-     * <code>uploadTextureBitmap</code> uploads a native android bitmap
-     */
-    /*
-    public static void uploadTextureBitmap(final int target, Bitmap bitmap, boolean needMips) {
-        uploadTextureBitmap(target, bitmap, needMips, false, 0, 0);
-    }
-
-    /**
-     * <code>uploadTextureBitmap</code> uploads a native android bitmap
-     */
-    /*
-    public static void uploadTextureBitmap(final int target, Bitmap bitmap, boolean needMips, boolean subTexture, int x, int y) {
-        boolean recycleBitmap = false;
-        //TODO, maybe this should raise an exception when NPOT is not supported
-
-        boolean willCompress = ENABLE_COMPRESSION && ETC1support && !bitmap.hasAlpha();
-        if (needMips && willCompress) {
-            // Image is compressed and mipmaps are desired, generate them
-            // using software.
-            buildMipmap(bitmap, willCompress);
-        } else {
-            if (willCompress) {
-                // Image is compressed but mipmaps are not desired, upload directly.
-                logger.log(Level.FINEST, " - Uploading compressed bitmap. Mipmaps are not generated.");
-                uploadBitmapAsCompressed(target, 0, bitmap, subTexture, x, y);
-
-            } else {
-                // Image is not compressed, mipmaps may or may not be desired.
-                logger.log(Level.FINEST, " - Uploading bitmap directly.{0}",
-                        (needMips
-                        ? " Mipmaps will be generated in HARDWARE"
-                        : " Mipmaps are not generated."));
-                if (subTexture) {
-                    System.err.println("x : " + x + " y :" + y + " , " + bitmap.getWidth() + "/" + bitmap.getHeight());
-                    GLUtils.texSubImage2D(target, 0, x, y, bitmap);
-                    JmeIosGLES.checkGLError();
-                } else {
-                    GLUtils.texImage2D(target, 0, bitmap, 0);
-                    JmeIosGLES.checkGLError();
-                }
-
-                if (needMips) {
-                    // No pregenerated mips available,
-                    // generate from base level if required
-                    JmeIosGLES.glGenerateMipmap(target);
-                    JmeIosGLES.checkGLError();
-                }
-            }
-        }
-
-        if (recycleBitmap) {
-            bitmap.recycle();
-        }
-    }
-    */
-
-    public static void uploadTextureAny(Image img, int target, int index, boolean needMips) {
-    	/*
-        if (img.getEfficentData() instanceof AndroidImageInfo) {
-            logger.log(Level.FINEST, " === Uploading image {0}. Using BITMAP PATH === ", img);
-            // If image was loaded from asset manager, use fast path
-            AndroidImageInfo imageInfo = (AndroidImageInfo) img.getEfficentData();
-            uploadTextureBitmap(target, imageInfo.getBitmap(), needMips);
-        } else {
-        */
-            logger.log(Level.FINEST, " === Uploading image {0}. Using BUFFER PATH === ", img);
-            boolean wantGeneratedMips = needMips && !img.hasMipmaps();
-            if (wantGeneratedMips && img.getFormat().isCompressed()) {
-                logger.log(Level.WARNING, "Generating mipmaps is only"
-                        + " supported for Bitmap based or non-compressed images!");
-            }
-
-            // Upload using slower path
-            logger.log(Level.FINEST, " - Uploading bitmap directly.{0}",
-                    (wantGeneratedMips
-                    ? " Mipmaps will be generated in HARDWARE"
-                    : " Mipmaps are not generated."));
-            
-            uploadTexture(img, target, index);
-
-            // Image was uploaded using slower path, since it is not compressed,
-            // then compress it
-            if (wantGeneratedMips) {
-                // No pregenerated mips available,
-                // generate from base level if required
-                JmeIosGLES.glGenerateMipmap(target);
-                JmeIosGLES.checkGLError();
-            }
-        //}
-    }
-
-    private static void unsupportedFormat(Format fmt) {
-        throw new UnsupportedOperationException("The image format '" + fmt + "' is unsupported by the video hardware.");
-    }
-
-    public static IosGLImageFormat getImageFormat(Format fmt) throws UnsupportedOperationException {
-        IosGLImageFormat imageFormat = new IosGLImageFormat();
-        switch (fmt) {
-            case Depth32:
-            case Depth32F:
-                throw new UnsupportedOperationException("The image format '"
-                        + fmt + "' is not supported by OpenGL ES 2.0 specification.");
-            case Alpha8:
-                imageFormat.format = JmeIosGLES.GL_ALPHA;
-                imageFormat.dataType = JmeIosGLES.GL_UNSIGNED_BYTE;
-                if (RGBA8) {
-                    imageFormat.renderBufferStorageFormat = GL_RGBA8;
-                } else {
-                    // Highest precision alpha supported by vanilla OGLES2
-                    imageFormat.renderBufferStorageFormat = JmeIosGLES.GL_RGBA4;
-                }
-                break;
-            case Luminance8:
-                imageFormat.format = JmeIosGLES.GL_LUMINANCE;
-                imageFormat.dataType = JmeIosGLES.GL_UNSIGNED_BYTE;
-                if (RGBA8) {
-                    imageFormat.renderBufferStorageFormat = GL_RGBA8;
-                } else {
-                    // Highest precision luminance supported by vanilla OGLES2
-                    imageFormat.renderBufferStorageFormat = JmeIosGLES.GL_RGB565;
-                }
-                break;
-            case Luminance8Alpha8:
-                imageFormat.format = JmeIosGLES.GL_LUMINANCE_ALPHA;
-                imageFormat.dataType = JmeIosGLES.GL_UNSIGNED_BYTE;
-                if (RGBA8) {
-                    imageFormat.renderBufferStorageFormat = GL_RGBA8;
-                } else {
-                    imageFormat.renderBufferStorageFormat = JmeIosGLES.GL_RGBA4;
-                }
-                break;
-            case RGB565:
-                imageFormat.format = JmeIosGLES.GL_RGB;
-                imageFormat.dataType = JmeIosGLES.GL_UNSIGNED_SHORT_5_6_5;
-                imageFormat.renderBufferStorageFormat = JmeIosGLES.GL_RGB565;
-                break;
-            case RGB5A1:
-                imageFormat.format = JmeIosGLES.GL_RGBA;
-                imageFormat.dataType = JmeIosGLES.GL_UNSIGNED_SHORT_5_5_5_1;
-                imageFormat.renderBufferStorageFormat = JmeIosGLES.GL_RGB5_A1;
-                break;
-            case RGB8:
-                imageFormat.format = JmeIosGLES.GL_RGB;
-                imageFormat.dataType = JmeIosGLES.GL_UNSIGNED_BYTE;
-                if (RGBA8) {
-                    imageFormat.renderBufferStorageFormat = GL_RGBA8;
-                } else {
-                    // Fallback: Use RGB565 if RGBA8 is not available.
-                    imageFormat.renderBufferStorageFormat = JmeIosGLES.GL_RGB565;
-                }
-                break;
-            case BGR8:
-                imageFormat.format = JmeIosGLES.GL_RGB;
-                imageFormat.dataType = JmeIosGLES.GL_UNSIGNED_BYTE;
-                if (RGBA8) {
-                    imageFormat.renderBufferStorageFormat = GL_RGBA8;
-                } else {
-                    imageFormat.renderBufferStorageFormat = JmeIosGLES.GL_RGB565;
-                }
-                break;
-            case RGBA8:
-                imageFormat.format = JmeIosGLES.GL_RGBA;
-                imageFormat.dataType = JmeIosGLES.GL_UNSIGNED_BYTE;
-                if (RGBA8) {
-                    imageFormat.renderBufferStorageFormat = GL_RGBA8;
-                } else {
-                    imageFormat.renderBufferStorageFormat = JmeIosGLES.GL_RGBA4;
-                }
-                break;
-            case Depth:
-            case Depth16:
-                if (!DEPTH_TEXTURE) {
-                    unsupportedFormat(fmt);
-                }
-                imageFormat.format = JmeIosGLES.GL_DEPTH_COMPONENT;
-                imageFormat.dataType = JmeIosGLES.GL_UNSIGNED_SHORT;
-                imageFormat.renderBufferStorageFormat = JmeIosGLES.GL_DEPTH_COMPONENT16;
-                break;
-            case Depth24:
-            case Depth24Stencil8:
-                if (!DEPTH_TEXTURE) {
-                    unsupportedFormat(fmt);
-                }
-                if (DEPTH24_STENCIL8) {
-                    // NEW: True Depth24 + Stencil8 format.
-                    imageFormat.format = GL_DEPTH_STENCIL_OES;
-                    imageFormat.dataType = GL_UNSIGNED_INT_24_8_OES;
-                    imageFormat.renderBufferStorageFormat = GL_DEPTH24_STENCIL8_OES;
-                } else {
-                    // Vanilla OGLES2, only Depth16 available.
-                    imageFormat.format = JmeIosGLES.GL_DEPTH_COMPONENT;
-                    imageFormat.dataType = JmeIosGLES.GL_UNSIGNED_SHORT;
-                    imageFormat.renderBufferStorageFormat = JmeIosGLES.GL_DEPTH_COMPONENT16;
-                }
-                break;
-            case DXT1:
-                if (!DXT1) {
-                    unsupportedFormat(fmt);
-                }
-                imageFormat.format = GL_DXT1;
-                imageFormat.dataType = JmeIosGLES.GL_UNSIGNED_BYTE;
-                imageFormat.compress = true;
-                break;
-            case DXT1A:
-                if (!DXT1) {
-                    unsupportedFormat(fmt);
-                }
-                imageFormat.format = GL_DXT1A;
-                imageFormat.dataType = JmeIosGLES.GL_UNSIGNED_BYTE;
-                imageFormat.compress = true;
-                break;
-            default:
-                throw new UnsupportedOperationException("Unrecognized format: " + fmt);
-        }
-        return imageFormat;
-    }
-
-    public static class IosGLImageFormat {
-
-        boolean compress = false;
-        int format = -1;
-        int renderBufferStorageFormat = -1;
-        int dataType = -1;
-    }
-
-    private static void uploadTexture(Image img,
-            int target,
-            int index) {
-
-		/*
-        if (img.getEfficentData() instanceof AndroidImageInfo) {
-            throw new RendererException("This image uses efficient data. "
-                    + "Use uploadTextureBitmap instead.");
-        }
-        */
-
-        // Otherwise upload image directly.
-        // Prefer to only use power of 2 textures here to avoid errors.
-        Image.Format fmt = img.getFormat();
-        ByteBuffer data;
-        if (index >= 0 || img.getData() != null && img.getData().size() > 0) {
-            data = img.getData(index);
-        } else {
-            data = null;
-        }
-
-        int width = img.getWidth();
-        int height = img.getHeight();
-
-        if (!NPOT && img.isNPOT()) {
-            // Check if texture is POT
-            throw new RendererException("Non-power-of-2 textures "
-                    + "are not supported by the video hardware "
-                    + "and no scaling path available for image: " + img);
-        }
-        IosGLImageFormat imageFormat = getImageFormat(fmt);
-
-        if (data != null) {
-            JmeIosGLES.glPixelStorei(JmeIosGLES.GL_UNPACK_ALIGNMENT, 1);
-            JmeIosGLES.checkGLError();
-        }
-
-        int[] mipSizes = img.getMipMapSizes();
-        int pos = 0;
-        if (mipSizes == null) {
-            if (data != null) {
-                mipSizes = new int[]{data.capacity()};
-            } else {
-                mipSizes = new int[]{width * height * fmt.getBitsPerPixel() / 8};
-            }
-        }
-
-        for (int i = 0; i < mipSizes.length; i++) {
-            int mipWidth = Math.max(1, width >> i);
-            int mipHeight = Math.max(1, height >> i);
-
-            if (data != null) {
-                data.position(pos);
-                data.limit(pos + mipSizes[i]);
-            }
-
-            if (imageFormat.compress && data != null) {
-                JmeIosGLES.glCompressedTexImage2D(target,
-                        i,
-                        imageFormat.format,
-                        mipWidth,
-                        mipHeight,
-                        0,
-                        data.remaining(),
-                        data);
-            } else {
-                JmeIosGLES.glTexImage2D(target,
-                        i,
-                        imageFormat.format,
-                        mipWidth,
-                        mipHeight,
-                        0,
-                        imageFormat.format,
-                        imageFormat.dataType,
-                        data);
-            }
-            JmeIosGLES.checkGLError();
-
-            pos += mipSizes[i];
-        }
-    }
-
-    /**
-     * Update the texture currently bound to target at with data from the given
-     * Image at position x and y. The parameter index is used as the zoffset in
-     * case a 3d texture or texture 2d array is being updated.
-     *
-     * @param image Image with the source data (this data will be put into the
-     * texture)
-     * @param target the target texture
-     * @param index the mipmap level to update
-     * @param x the x position where to put the image in the texture
-     * @param y the y position where to put the image in the texture
-     */
-    public static void uploadSubTexture(
-            Image img,
-            int target,
-            int index,
-            int x,
-            int y) {
-        //TODO: 
-        /*
-        if (img.getEfficentData() instanceof AndroidImageInfo) {
-            AndroidImageInfo imageInfo = (AndroidImageInfo) img.getEfficentData();
-            uploadTextureBitmap(target, imageInfo.getBitmap(), true, true, x, y);
-            return;
-        }
-        */
-
-        // Otherwise upload image directly.
-        // Prefer to only use power of 2 textures here to avoid errors.
-        Image.Format fmt = img.getFormat();
-        ByteBuffer data;
-        if (index >= 0 || img.getData() != null && img.getData().size() > 0) {
-            data = img.getData(index);
-        } else {
-            data = null;
-        }
-
-        int width = img.getWidth();
-        int height = img.getHeight();
-
-        if (!NPOT && img.isNPOT()) {
-            // Check if texture is POT
-            throw new RendererException("Non-power-of-2 textures "
-                    + "are not supported by the video hardware "
-                    + "and no scaling path available for image: " + img);
-        }
-        IosGLImageFormat imageFormat = getImageFormat(fmt);
-
-        if (data != null) {
-            JmeIosGLES.glPixelStorei(JmeIosGLES.GL_UNPACK_ALIGNMENT, 1);
-            JmeIosGLES.checkGLError();
-        }
-
-        int[] mipSizes = img.getMipMapSizes();
-        int pos = 0;
-        if (mipSizes == null) {
-            if (data != null) {
-                mipSizes = new int[]{data.capacity()};
-            } else {
-                mipSizes = new int[]{width * height * fmt.getBitsPerPixel() / 8};
-            }
-        }
-
-        for (int i = 0; i < mipSizes.length; i++) {
-            int mipWidth = Math.max(1, width >> i);
-            int mipHeight = Math.max(1, height >> i);
-
-            if (data != null) {
-                data.position(pos);
-                data.limit(pos + mipSizes[i]);
-            }
-
-            if (imageFormat.compress && data != null) {
-                JmeIosGLES.glCompressedTexSubImage2D(target, i, x, y, mipWidth, mipHeight, imageFormat.format, data.remaining(), data);
-                JmeIosGLES.checkGLError();
-            } else {
-                JmeIosGLES.glTexSubImage2D(target, i, x, y, mipWidth, mipHeight, imageFormat.format, imageFormat.dataType, data);
-                JmeIosGLES.checkGLError();
-            }
-
-            pos += mipSizes[i];
-        }
-    }
-}

+ 3 - 2
jme3-ios/src/main/java/com/jme3/system/ios/IGLESContext.java

@@ -40,6 +40,7 @@ import com.jme3.renderer.ios.IosGL;
 import com.jme3.renderer.opengl.GL;
 import com.jme3.renderer.opengl.GLDebugES;
 import com.jme3.renderer.opengl.GLExt;
+import com.jme3.renderer.opengl.GLFbo;
 import com.jme3.renderer.opengl.GLRenderer;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.logging.Level;
@@ -158,11 +159,11 @@ public class IGLESContext implements JmeContext {
         GLExt glext = (GLExt) gl;
 
 //        if (settings.getBoolean("GraphicsDebug")) {
-            gl = new GLDebugES(gl, glext);
+            gl = new GLDebugES(gl, glext, (GLFbo) glext);
             glext = (GLExt) gl;
 //        }
 
-        renderer = new GLRenderer(gl, glext);
+        renderer = new GLRenderer(gl, glext, (GLFbo) glext);
         renderer.initialize();
         
         input = new IosInputHandler();

+ 9 - 6
jme3-ios/src/main/java/com/jme3/system/ios/IosImageLoader.java

@@ -33,6 +33,7 @@ package com.jme3.system.ios;
 
 import com.jme3.asset.AssetInfo;
 import com.jme3.asset.AssetLoader;
+import com.jme3.asset.TextureKey;
 import com.jme3.texture.Image;
 import com.jme3.texture.Image.Format;
 import java.io.IOException;
@@ -45,14 +46,16 @@ import java.io.InputStream;
 public class IosImageLoader implements AssetLoader {
 
     public Object load(AssetInfo info) throws IOException {
-        InputStream in = info.openStream();
+        boolean flip = ((TextureKey) info.getKey()).isFlipY();
         Image img = null;
+        InputStream in = null;
         try {
-            img = loadImageData(Image.Format.RGBA8, in);
-        } catch (Exception e) {
-            e.printStackTrace();
+        	in = info.openStream();
+            img = loadImageData(Format.RGBA8, flip, in);
         } finally {
-            in.close();
+        	if (in != null) {
+            	in.close();
+            }
         }
         return img;
     }
@@ -64,5 +67,5 @@ public class IosImageLoader implements AssetLoader {
      * @param inputStream the InputStream to load the image data from
      * @return the loaded Image
      */
-    private static native Image loadImageData(Format format, InputStream inputStream);
+    private static native Image loadImageData(Format format, boolean flipY, InputStream inputStream);
 }

+ 13 - 2
jme3-ios/src/main/java/com/jme3/system/ios/JmeIosSystem.java

@@ -36,6 +36,14 @@ import com.jme3.system.AppSettings;
 import com.jme3.system.JmeContext;
 import com.jme3.system.JmeSystemDelegate;
 import com.jme3.system.NullContext;
+import com.jme3.audio.AudioRenderer;
+import com.jme3.audio.ios.IosAL;
+import com.jme3.audio.ios.IosALC;
+//import com.jme3.audio.ios.IosEFX;
+import com.jme3.audio.openal.AL;
+import com.jme3.audio.openal.ALAudioRenderer;
+import com.jme3.audio.openal.ALC;
+import com.jme3.audio.openal.EFX;
 import java.io.IOException;
 import java.io.OutputStream;
 import java.net.URL;
@@ -89,8 +97,11 @@ public class JmeIosSystem extends JmeSystemDelegate {
 
     @Override
     public AudioRenderer newAudioRenderer(AppSettings settings) {
-        return null;
-    }
+        ALC alc = new IosALC();
+        AL al = new IosAL();
+        //EFX efx = new IosEFX();
+        return new ALAudioRenderer(al, alc, null);
+     }
 
     @Override
     public void initialize(AppSettings settings) {

部分文件因为文件数量过多而无法显示