Explorar o código

Added a version of createFloatBuffer that takes
a ColoRGBA array.

pspeed42 %!s(int64=11) %!d(string=hai) anos
pai
achega
1ad6a57b32
Modificáronse 1 ficheiros con 22 adicións e 0 borrados
  1. 22 0
      jme3-core/src/main/java/com/jme3/util/BufferUtils.java

+ 22 - 0
jme3-core/src/main/java/com/jme3/util/BufferUtils.java

@@ -224,6 +224,28 @@ public final class BufferUtils {
         return buff;
     }
 
+    /**
+     * Generate a new FloatBuffer using the given array of ColorRGBA objects.
+     * The FloatBuffer will be 4 * data.length long and contain the color data.
+     *
+     * @param data array of ColorRGBA objects to place into a new FloatBuffer
+     */
+    public static FloatBuffer createFloatBuffer(ColorRGBA... data) {
+        if (data == null) {
+            return null;
+        }
+        FloatBuffer buff = createFloatBuffer(4 * data.length);
+        for (int x = 0; x < data.length; x++) {
+            if (data[x] != null) {
+                buff.put(data[x].getRed()).put(data[x].getGreen()).put(data[x].getBlue()).put(data[x].getAlpha());
+            } else {
+                buff.put(0).put(0).put(0).put(0);
+            }
+        }
+        buff.flip();
+        return buff;
+    }
+
     /**
      * Generate a new FloatBuffer using the given array of float primitives.
      * @param data array of float primitives to place into a new FloatBuffer