adding support for zeroing buffers - patch'ish by MatthiasM

This commit is contained in:
Brian Matzon 2010-11-24 21:48:23 +00:00
parent 63e79ab5b3
commit ebb196936e
3 changed files with 43 additions and 0 deletions

View File

@ -266,6 +266,7 @@
<class name="org.lwjgl.opengl.CallbackUtil" />
<class name="org.lwjgl.opencl.CL" />
<class name="org.lwjgl.opencl.CallbackUtil" />
<class name="org.lwjgl.BufferUtils" />
</javah>
</target>

View File

@ -155,4 +155,41 @@ public final class BufferUtils {
return buffer.position() << getElementSizeExponent(buffer);
}
/** Fill buffer with zeros from position to remaining */
public static void zeroBuffer(ByteBuffer b) {
zeroBuffer0(b, b.position(), b.remaining());
}
/** Fill buffer with zeros from position to remaining */
public static void zeroBuffer(ShortBuffer b) {
zeroBuffer0(b, b.position()*2L, b.remaining()*2L);
}
/** Fill buffer with zeros from position to remaining */
public static void zeroBuffer(CharBuffer b) {
zeroBuffer0(b, b.position()*2L, b.remaining()*2L);
}
/** Fill buffer with zeros from position to remaining */
public static void zeroBuffer(IntBuffer b) {
zeroBuffer0(b, b.position()*4L, b.remaining()*4L);
}
/** Fill buffer with zeros from position to remaining */
public static void zeroBuffer(FloatBuffer b) {
zeroBuffer0(b, b.position()*4L, b.remaining()*4L);
}
/** Fill buffer with zeros from position to remaining */
public static void zeroBuffer(LongBuffer b) {
zeroBuffer0(b, b.position()*8L, b.remaining()*8L);
}
/** Fill buffer with zeros from position to remaining */
public static void zeroBuffer(DoubleBuffer b) {
zeroBuffer0(b, b.position()*8L, b.remaining()*8L);
}
/** Fill buffer with zeros from position to remaining */
private static native void zeroBuffer0(Buffer b, long off, long size);
}

View File

@ -0,0 +1,5 @@
#include "org_lwjgl_BufferUtils.h"
JNIEXPORT void JNICALL Java_org_lwjgl_BufferUtils_zeroBuffer0(JNIEnv *env, jclass clazz, jobject buffer, jlong offset, jlong size) {
memset((char*)(*env)->GetDirectBufferAddress(env, buffer) + (size_t)offset, 0, (size_t)size);
}