OSDN Git Service

change material code
authorKazuhiko Kobayashi <chototsu_moushinp@yahoo.co.jp>
Tue, 29 May 2012 03:14:33 +0000 (12:14 +0900)
committerkobayasi <kobayasi@pscnet.co.jp>
Sat, 6 Jul 2013 01:36:59 +0000 (10:36 +0900)
engine/lib/bullet/jME3-bullet-natives.jar
engine/lib/bullet/jarcontent/native/macosx/libbulletjme.jnilib
engine/src/android/com/jme3/app/AndroidHarness.java
engine/src/core/com/jme3/material/MatParam.java
engine/src/core/com/jme3/material/Material.java
engine/src/core/com/jme3/renderer/RenderManager.java
engine/src/core/com/jme3/shader/Shader.java

index aa9434f..8aaa963 100644 (file)
Binary files a/engine/lib/bullet/jME3-bullet-natives.jar and b/engine/lib/bullet/jME3-bullet-natives.jar differ
index a3185f1..aa549ca 100755 (executable)
Binary files a/engine/lib/bullet/jarcontent/native/macosx/libbulletjme.jnilib and b/engine/lib/bullet/jarcontent/native/macosx/libbulletjme.jnilib differ
index 0e1db3e..acb4ac3 100644 (file)
@@ -108,6 +108,7 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
     protected OGLESContext ctx;\r
     protected GLSurfaceView view = null;\r
     protected boolean isGLThreadPaused = true;\r
+    protected AppSettings settings = null;\r
     final private String ESCAPE_EVENT = "TouchEscape";\r
 \r
     @Override\r
@@ -145,8 +146,9 @@ public class AndroidHarness extends Activity implements TouchListener, DialogInt
         setRequestedOrientation(screenOrientation);\r
 \r
         // Create Settings\r
-        AppSettings settings = new AppSettings(true);\r
-\r
+        if (settings == null) {\r
+            settings = new AppSettings(true);\r
+        }\r
         // Create the input class\r
         AndroidInput input = new AndroidInput(this);\r
         input.setMouseEventsInvertX(mouseEventsInvertX);\r
index 714ced7..4e33985 100644 (file)
@@ -151,6 +151,10 @@ public class MatParam implements Savable, Cloneable {
      */
     public void setValue(Object value) {
         this.value = value;
+        if (value instanceof FloatBuffer) {
+            multiData = (FloatBuffer)value;
+            return;
+        }
             switch (type){
                 case Matrix3:
                     Matrix3f m3 = (Matrix3f) value;
index 3275394..f70613d 100644 (file)
@@ -702,14 +702,14 @@ public class Material implements Asset, Cloneable, Savable, Comparable<Material>
         }
 
         LightList lightList = g.getWorldLightList();
-        Uniform lightColor = shader.getUniform("g_LightColor");
-        Uniform lightPos = shader.getUniform("g_LightPosition");
-        Uniform lightDir = shader.getUniform("g_LightDirection");
+        Uniform lightColor = shader.getLightColorUniform();
+        Uniform lightPos = shader.getLightPositionUniform();
+        Uniform lightDir = shader.getLightDirectionUniform();
         lightColor.setVector4Length(numLights);
         lightPos.setVector4Length(numLights);
         lightDir.setVector4Length(numLights);
 
-        Uniform ambientColor = shader.getUniform("g_AmbientLightColor");
+        Uniform ambientColor = shader.getAmbientColorUniform();
         ambientColor.setValue(VarType.Vector4, getAmbientColor(lightList));
 
         int lightIndex = 0;
@@ -772,10 +772,10 @@ public class Material implements Asset, Cloneable, Savable, Comparable<Material>
 
         Renderer r = rm.getRenderer();
         LightList lightList = g.getWorldLightList();
-        Uniform lightDir = shader.getUniform("g_LightDirection");
-        Uniform lightColor = shader.getUniform("g_LightColor");
-        Uniform lightPos = shader.getUniform("g_LightPosition");
-        Uniform ambientColor = shader.getUniform("g_AmbientLightColor");
+        Uniform lightDir = shader.getLightDirectionUniform();
+        Uniform lightColor = shader.getLightColorUniform();
+        Uniform lightPos = shader.getLightPositionUniform();
+        Uniform ambientColor = shader.getAmbientColorUniform();
         boolean isFirstLight = true;
         boolean isSecondLight = false;
 
index 7e2dc96..760c140 100644 (file)
@@ -55,8 +55,10 @@ import com.jme3.shader.UniformBinding;
 import com.jme3.shader.VarType;
 import com.jme3.system.NullRenderer;
 import com.jme3.system.Timer;
+import com.jme3.util.BufferUtils;
 import com.jme3.util.IntMap.Entry;
 import com.jme3.util.TempVars;
+import java.nio.FloatBuffer;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -88,10 +90,21 @@ public class RenderManager {
     private int viewX, viewY, viewWidth, viewHeight;
     private float near, far;
     private Matrix4f orthoMatrix = new Matrix4f();
+//    private FloatBuffer orthoMatrixBuf = BufferUtils.createFloatBuffer(16);
     private Matrix4f viewMatrix = new Matrix4f();
+    private FloatBuffer viewMatrixBuf = BufferUtils.createFloatBuffer(16);
     private Matrix4f projMatrix = new Matrix4f();
+    private FloatBuffer projMatrixBuf = BufferUtils.createFloatBuffer(16);
     private Matrix4f viewProjMatrix = new Matrix4f();
+    private FloatBuffer viewProjMatrixBuf = BufferUtils.createFloatBuffer(16);
     private Matrix4f worldMatrix = new Matrix4f();
+    private FloatBuffer worldMatrixBuf = BufferUtils.createFloatBuffer(16);
+    private FloatBuffer worldViewMatrixBuf = BufferUtils.createFloatBuffer(16);
+    private boolean worldViewMatrixBufDirty = true;
+    private FloatBuffer worldViewProjectionMatrixBuf = BufferUtils.createFloatBuffer(16);
+    private boolean worldViewProjectionMatrixBufDirty = true;
+    private FloatBuffer normalMatrixBuf = BufferUtils.createFloatBuffer(9);
+    private boolean normalMatrixBufDirty = true;
     private Vector3f camUp = new Vector3f(),
             camLeft = new Vector3f(),
             camDir = new Vector3f(),
@@ -353,21 +366,22 @@ public class RenderManager {
             Uniform u = params.get(i);
             switch (u.getBinding()) {
                 case WorldMatrix:
-                    u.setValue(VarType.Matrix4, worldMatrix);
+                    u.setValue(VarType.Matrix4, worldMatrixBuf);
                     break;
                 case ViewMatrix:
                     u.setValue(VarType.Matrix4, viewMatrix);
                     break;
                 case ProjectionMatrix:
-                    u.setValue(VarType.Matrix4, projMatrix);
+                    u.setValue(VarType.Matrix4, projMatrixBuf);
                     break;
                 case ViewProjectionMatrix:
-                    u.setValue(VarType.Matrix4, viewProjMatrix);
+                    u.setValue(VarType.Matrix4, viewProjMatrixBuf);
                     break;
                 case WorldViewMatrix:
-                    tempMat4.set(viewMatrix);
-                    tempMat4.multLocal(worldMatrix);
-                    u.setValue(VarType.Matrix4, tempMat4);
+//                    tempMat4.set(viewMatrix);
+//                    tempMat4.multLocal(worldMatrix);
+//                    u.setValue(VarType.Matrix4, tempMat4);
+                    u.setValue(VarType.Matrix4, getWorldViewMatrixBuf());
                     break;
                 case NormalMatrix:
                     tempMat4.set(viewMatrix);
@@ -378,9 +392,10 @@ public class RenderManager {
                     u.setValue(VarType.Matrix3, tempMat3);
                     break;
                 case WorldViewProjectionMatrix:
-                    tempMat4.set(viewProjMatrix);
-                    tempMat4.multLocal(worldMatrix);
-                    u.setValue(VarType.Matrix4, tempMat4);
+//                    tempMat4.set(viewProjMatrix);
+//                    tempMat4.multLocal(worldMatrix);
+//                    u.setValue(VarType.Matrix4, tempMat4);
+                    u.setValue(VarType.Matrix4, getWorldViewProjectionMatrixBuf());
                     break;
                 case WorldMatrixInverse:
                     tempMat4.multLocal(worldMatrix);
@@ -590,6 +605,10 @@ public class RenderManager {
     public void setWorldMatrix(Matrix4f mat) {
         if (shader) {
             worldMatrix.set(mat);
+            worldMatrix.fillFloatBuffer(worldMatrixBuf, true);
+            worldMatrixBuf.position(0);
+            worldViewProjectionMatrixBufDirty = true;
+            normalMatrixBufDirty = true;
         } else {
             renderer.setWorldMatrix(mat);
         }
@@ -969,6 +988,7 @@ public class RenderManager {
             orthoMatrix.loadIdentity();
             orthoMatrix.setTranslation(-1f, -1f, 0f);
             orthoMatrix.setScale(2f / cam.getWidth(), 2f / cam.getHeight(), 0f);
+//            orthoMatrix.fillFloatBuffer(orthoMatrixBuf, true);
         }
     }
 
@@ -983,7 +1003,15 @@ public class RenderManager {
                 projMatrix.set(cam.getProjectionMatrix());
                 viewProjMatrix.set(cam.getViewProjectionMatrix());
             }
-
+//            viewMatrix.fillFloatBuffer(viewMatrixBuf, true);
+//            viewMatrixBuf.position(0);
+            projMatrix.fillFloatBuffer(projMatrixBuf, true);
+            projMatrixBuf.position(0);
+            viewProjMatrix.fillFloatBuffer(viewProjMatrixBuf, true);
+            viewProjMatrixBuf.position(0);
+            worldViewMatrixBufDirty = true;
+            worldViewProjectionMatrixBufDirty = true;
+            normalMatrixBufDirty = true;
             camLoc.set(cam.getLocation());
             cam.getLeft(camLeft);
             cam.getUp(camUp);
@@ -1001,7 +1029,45 @@ public class RenderManager {
 
         }
     }
-
+    private FloatBuffer getWorldViewMatrixBuf() {
+        if (worldViewMatrixBufDirty) {
+            TempVars tmp = TempVars.get();
+            tmp.tempMat4.set(viewMatrix);
+            tmp.tempMat4.multLocal(worldMatrix);
+            tmp.tempMat4.fillFloatBuffer(worldViewMatrixBuf, true);
+            worldViewMatrixBuf.position(0);
+            tmp.release();
+            worldViewMatrixBufDirty = false;
+        }
+        return worldViewMatrixBuf;
+    }
+    private FloatBuffer getWorldViewProjectionMatrixBuf() {
+        if (worldViewProjectionMatrixBufDirty) {
+            TempVars tmp = TempVars.get();
+            tmp.tempMat4.set(viewProjMatrix);
+            tmp.tempMat4.multLocal(worldMatrix);
+            tmp.tempMat4.fillFloatBuffer(worldViewProjectionMatrixBuf, true);
+            worldViewProjectionMatrixBuf.position(0);
+            tmp.release();
+            worldViewProjectionMatrixBufDirty = false;
+        }
+        return worldViewProjectionMatrixBuf;
+    }
+    private FloatBuffer getNormalMatrixBuf() {
+        if (normalMatrixBufDirty) {
+            TempVars tmp = TempVars.get();
+            tmp.tempMat4.set(viewMatrix);
+            tmp.tempMat4.multLocal(worldMatrix);
+            tmp.tempMat4.toRotationMatrix(tmp.tempMat3);
+            tmp.tempMat3.invertLocal();
+            tmp.tempMat3.transposeLocal();
+            tmp.tempMat3.fillFloatBuffer(normalMatrixBuf, true);
+            normalMatrixBuf.position(0);
+            tmp.release();
+            normalMatrixBufDirty = false;
+        }
+        return worldViewProjectionMatrixBuf;
+    }
     /**
      * Set the camera to use for rendering.
      * <p>
index 65a07d7..2ae8fe5 100644 (file)
@@ -49,7 +49,10 @@ import java.util.Collection;
 import java.util.HashMap;\r
 \r
 public final class Shader extends NativeObject implements Savable {\r
-\r
+    private Uniform lightColorUniform;\r
+    private Uniform lightPositionUniform;\r
+    private Uniform lightDirectionUniform;\r
+    private Uniform ambientLightColorUniform;\r
     private String language;\r
 \r
     /**\r
@@ -332,6 +335,33 @@ public final class Shader extends NativeObject implements Savable {
         return uniform;\r
     }\r
 \r
+    public Uniform getLightColorUniform() {\r
+        if (lightColorUniform == null) {\r
+            lightColorUniform = getUniform("g_LightColor");\r
+        }\r
+        return lightColorUniform;\r
+    }\r
+\r
+    public Uniform getLightDirectionUniform() {\r
+        if (lightDirectionUniform == null) {\r
+            lightDirectionUniform = getUniform("g_LightDirection");\r
+        }\r
+        return lightDirectionUniform;\r
+    }\r
+\r
+    public Uniform getLightPositionUniform() {\r
+        if (lightPositionUniform == null) {\r
+            lightPositionUniform = getUniform("g_LightPosition");\r
+        }\r
+        return lightPositionUniform;\r
+    }\r
+    public Uniform getAmbientColorUniform() {\r
+        if (ambientLightColorUniform == null) {\r
+            ambientLightColorUniform = getUniform("g_AmbientLightColor");\r
+        }\r
+        return ambientLightColorUniform;\r
+    }\r
+\r
     public void removeUniform(String name){\r
         uniforms.remove(name);\r
     }\r