Android OGLESShaderRenderer bug patch

1.fix Matrix4Array, Vector4Array, Vector3Array, Vector2Array bug.

2.add VBO support.(Android 2.2: default VBA, Android 2.3.1 or above: default VBO)



compile

1.copy {ANROID_SDK_HOME}platformsandroid-9android.jar to enginelibandroid

2.build engine



[patch]

diff -r 15a24e3ca250 engine/src/android/com/jme3/renderer/android/OGLESShaderRenderer.java

— a/engine/src/android/com/jme3/renderer/android/OGLESShaderRenderer.java Sun Sep 04 21:44:42 2011 +0900

+++ b/engine/src/android/com/jme3/renderer/android/OGLESShaderRenderer.java Thu Sep 15 04:32:04 2011 +0900

@@ -81,6 +81,7 @@

import android.opengl.GLES10;

import android.opengl.GLES11;

import android.opengl.GLES20;

+import android.os.Build;



public class OGLESShaderRenderer implements Renderer {



@@ -405,6 +406,11 @@



// checkGLError();


  •    if (&quot;2.2&quot;.equals(Build.VERSION.RELEASE)) {<br />
    
  •        useVBO = false;<br />
    
  •    } else {<br />
    
  •        useVBO = true;<br />
    
  •    }<br />
    

logger.log(Level.INFO, "Caps: {0}", caps);

}



@@ -843,6 +849,7 @@



uniform.clearUpdateNeeded();

FloatBuffer fb;

  •    int size;<br />
    

switch (uniform.getVarType()) {

case Float:

if (verboseLogging) {

@@ -906,35 +913,40 @@

logger.info("GLES20.glUniform1fv set FloatArray." + uniform.getName());

}

fb = (FloatBuffer) uniform.getValue();

  •            GLES20.glUniform1fv(loc, 1, fb);<br />
    
  •            size = fb.capacity();<br />
    
  •            GLES20.glUniform1fv(loc, size, fb);<br />
    

break;

case Vector2Array:

if (verboseLogging) {

logger.info("GLES20.glUniform2fv set Vector2Array." + uniform.getName());

}

fb = (FloatBuffer) uniform.getValue();

  •            GLES20.glUniform2fv(loc, 1, fb);<br />
    
  •            size = fb.capacity() / 2;<br />
    
  •            GLES20.glUniform2fv(loc, size, fb);<br />
    

break;

case Vector3Array:

if (verboseLogging) {

logger.info("GLES20.glUniform3fv set Vector3Array." + uniform.getName());

}

fb = (FloatBuffer) uniform.getValue();

  •            GLES20.glUniform3fv(loc, 1, fb);<br />
    
  •            size = fb.capacity() / 3;<br />
    
  •            GLES20.glUniform3fv(loc, size, fb);<br />
    

break;

case Vector4Array:

if (verboseLogging) {

logger.info("GLES20.glUniform4fv set Vector4Array." + uniform.getName());

}

fb = (FloatBuffer) uniform.getValue();

  •            GLES20.glUniform4fv(loc, 1, fb);<br />
    
  •            size = fb.capacity() / 4;<br />
    
  •            GLES20.glUniform4fv(loc, size, fb);<br />
    

break;

case Matrix4Array:

if (verboseLogging) {

logger.info("GLES20.glUniform4fv set Matrix4Array." + uniform.getName());

}

fb = (FloatBuffer) uniform.getValue();

  •            GLES20.glUniformMatrix4fv(loc, 1, false, fb);<br />
    
  •            size = fb.capacity() / 16;<br />
    
  •            GLES20.glUniformMatrix4fv(loc, size, false, fb);<br />
    

break;

case Int:

if (verboseLogging) {

@@ -2429,8 +2441,7 @@

convertFormat(vb.getFormat()),

vb.isNormalized(),

vb.getStride(),

  •                    vb.getData());<br />
    

-

  •                    0/*vb.getData()*/);<br />
    

attribs[loc] = vb;

}

} else {

[/patch]

1 Like