You can subscribe to this list here.
| 2002 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
(134) |
Sep
(52) |
Oct
(13) |
Nov
(342) |
Dec
(163) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2003 |
Jan
(44) |
Feb
(62) |
Mar
(158) |
Apr
(38) |
May
(70) |
Jun
(58) |
Jul
(104) |
Aug
(207) |
Sep
(83) |
Oct
(122) |
Nov
(23) |
Dec
(49) |
| 2004 |
Jan
(119) |
Feb
(132) |
Mar
(192) |
Apr
(140) |
May
(77) |
Jun
(74) |
Jul
(201) |
Aug
(63) |
Sep
(102) |
Oct
(70) |
Nov
(173) |
Dec
(78) |
| 2005 |
Jan
(174) |
Feb
(197) |
Mar
(105) |
Apr
(59) |
May
(77) |
Jun
(43) |
Jul
(21) |
Aug
(18) |
Sep
(47) |
Oct
(37) |
Nov
(74) |
Dec
(50) |
| 2006 |
Jan
(44) |
Feb
(19) |
Mar
(32) |
Apr
(24) |
May
(31) |
Jun
(55) |
Jul
(138) |
Aug
(28) |
Sep
(12) |
Oct
(41) |
Nov
(58) |
Dec
(24) |
| 2007 |
Jan
(28) |
Feb
(14) |
Mar
(10) |
Apr
(68) |
May
(30) |
Jun
(26) |
Jul
(18) |
Aug
(63) |
Sep
(19) |
Oct
(29) |
Nov
(20) |
Dec
(10) |
| 2008 |
Jan
(38) |
Feb
(7) |
Mar
(37) |
Apr
(120) |
May
(41) |
Jun
(36) |
Jul
(39) |
Aug
(24) |
Sep
(28) |
Oct
(30) |
Nov
(36) |
Dec
(75) |
| 2009 |
Jan
(46) |
Feb
(22) |
Mar
(50) |
Apr
(70) |
May
(134) |
Jun
(105) |
Jul
(75) |
Aug
(34) |
Sep
(38) |
Oct
(34) |
Nov
(19) |
Dec
(20) |
| 2010 |
Jan
(11) |
Feb
(20) |
Mar
(65) |
Apr
(83) |
May
(104) |
Jun
(73) |
Jul
(78) |
Aug
(57) |
Sep
(43) |
Oct
(35) |
Nov
(9) |
Dec
(4) |
| 2011 |
Jan
(21) |
Feb
(11) |
Mar
(18) |
Apr
(10) |
May
(18) |
Jun
(15) |
Jul
(48) |
Aug
(25) |
Sep
(17) |
Oct
(45) |
Nov
(15) |
Dec
(12) |
| 2012 |
Jan
(21) |
Feb
(9) |
Mar
(12) |
Apr
(9) |
May
(9) |
Jun
(5) |
Jul
(1) |
Aug
(10) |
Sep
(12) |
Oct
(1) |
Nov
(28) |
Dec
(5) |
| 2013 |
Jan
(4) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
| 2014 |
Jan
|
Feb
(1) |
Mar
(1) |
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
|
Dec
|
| 2015 |
Jan
(1) |
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
|
| 2016 |
Jan
(2) |
Feb
(1) |
Mar
(1) |
Apr
(1) |
May
(2) |
Jun
|
Jul
(1) |
Aug
(2) |
Sep
|
Oct
|
Nov
(1) |
Dec
|
| 2017 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|
From: <sp...@us...> - 2011-07-16 16:59:53
|
Revision: 3591
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3591&view=rev
Author: spasi
Date: 2011-07-16 16:59:46 +0000 (Sat, 16 Jul 2011)
Log Message:
-----------
Pointer cast warning fix.
Modified Paths:
--------------
trunk/LWJGL/src/native/common/opengl/org_lwjgl_opengl_CallbackUtil.c
Modified: trunk/LWJGL/src/native/common/opengl/org_lwjgl_opengl_CallbackUtil.c
===================================================================
--- trunk/LWJGL/src/native/common/opengl/org_lwjgl_opengl_CallbackUtil.c 2011-07-16 16:42:51 UTC (rev 3590)
+++ trunk/LWJGL/src/native/common/opengl/org_lwjgl_opengl_CallbackUtil.c 2011-07-16 16:59:46 UTC (rev 3591)
@@ -45,11 +45,11 @@
static jmethodID debugOutputCallbackAMDJ;
JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_CallbackUtil_ncreateGlobalRef(JNIEnv *env, jclass clazz, jobject obj) {
- return (jlong)(*env)->NewGlobalRef(env, obj);
+ return (jlong)(intptr_t)(*env)->NewGlobalRef(env, obj);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_CallbackUtil_deleteGlobalRef(JNIEnv *env, jclass clazz, jlong globalRef) {
- (*env)->DeleteGlobalRef(env, (jobject)globalRef);
+ (*env)->DeleteGlobalRef(env, (jobject)(intptr_t)globalRef);
}
// ----------------- [ ARB_debug_output ] -----------------
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sp...@us...> - 2011-07-16 16:42:59
|
Revision: 3590
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3590&view=rev
Author: spasi
Date: 2011-07-16 16:42:51 +0000 (Sat, 16 Jul 2011)
Log Message:
-----------
More java-side pointer arithmetic.
Fixed pointer cast warning.
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/openal/ALC10.java
trunk/LWJGL/src/java/org/lwjgl/openal/ALC11.java
trunk/LWJGL/src/java/org/lwjgl/opengles/EGL.java
trunk/LWJGL/src/java/org/lwjgl/opengles/EGLKHRFenceSync.java
trunk/LWJGL/src/java/org/lwjgl/opengles/EGLNVSync.java
trunk/LWJGL/src/java/org/lwjgl/util/generator/NativeMethodStubsGenerator.java
trunk/LWJGL/src/native/common/opengles/org_lwjgl_opengles_EGL.c
trunk/LWJGL/src/native/common/opengles/org_lwjgl_opengles_EGLKHRFenceSync.c
trunk/LWJGL/src/native/common/opengles/org_lwjgl_opengles_EGLNVSync.c
trunk/LWJGL/src/native/common/org_lwjgl_openal_ALC10.c
trunk/LWJGL/src/native/common/org_lwjgl_openal_ALC11.c
Modified: trunk/LWJGL/src/java/org/lwjgl/openal/ALC10.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/openal/ALC10.java 2011-07-16 16:05:37 UTC (rev 3589)
+++ trunk/LWJGL/src/java/org/lwjgl/openal/ALC10.java 2011-07-16 16:42:51 UTC (rev 3590)
@@ -37,6 +37,7 @@
import org.lwjgl.BufferChecks;
import org.lwjgl.LWJGLException;
+import org.lwjgl.MemoryUtil;
/**
*
@@ -180,10 +181,10 @@
*/
public static void alcGetInteger(ALCdevice device, int pname, IntBuffer integerdata) {
BufferChecks.checkDirect(integerdata);
- nalcGetIntegerv(getDevice(device), pname, integerdata.remaining(), integerdata, integerdata.position());
+ nalcGetIntegerv(getDevice(device), pname, integerdata.remaining(), MemoryUtil.getAddress(integerdata));
Util.checkALCError(device);
}
- static native void nalcGetIntegerv(long device, int pname, int size, Buffer integerdata, int offset);
+ static native void nalcGetIntegerv(long device, int pname, int size, long integerdata);
/**
* The <code>alcOpenDevice</code> function allows the application (i.e. the client program) to
@@ -246,7 +247,7 @@
* @return New context, or null if creation failed
*/
public static ALCcontext alcCreateContext(ALCdevice device, IntBuffer attrList) {
- long context_address = nalcCreateContext(getDevice(device), attrList);
+ long context_address = nalcCreateContext(getDevice(device), MemoryUtil.getAddressSafe(attrList));
Util.checkALCError(device);
if(context_address != 0) {
@@ -259,7 +260,7 @@
}
return null;
}
- static native long nalcCreateContext(long device, IntBuffer attrList);
+ static native long nalcCreateContext(long device, long attrList);
/**
* To make a Context current with respect to AL Operation (state changes by issueing
Modified: trunk/LWJGL/src/java/org/lwjgl/openal/ALC11.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/openal/ALC11.java 2011-07-16 16:05:37 UTC (rev 3589)
+++ trunk/LWJGL/src/java/org/lwjgl/openal/ALC11.java 2011-07-16 16:42:51 UTC (rev 3590)
@@ -37,8 +37,8 @@
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
import org.lwjgl.LWJGLUtil;
+import org.lwjgl.MemoryUtil;
-
/**
* <p>
* The ALC11 class implements features in OpenAL 1.1, specifically
@@ -162,9 +162,9 @@
* @param samples Number of samples to request
*/
public static void alcCaptureSamples(ALCdevice device, ByteBuffer buffer, int samples ) {
- nalcCaptureSamples(ALC10.getDevice(device), buffer, buffer.position(), samples);
+ nalcCaptureSamples(ALC10.getDevice(device), MemoryUtil.getAddress(buffer), samples);
}
- static native void nalcCaptureSamples(long device, ByteBuffer buffer, int position, int samples );
+ static native void nalcCaptureSamples(long device, long buffer, int samples );
static native void initNativeStubs() throws LWJGLException;
Modified: trunk/LWJGL/src/java/org/lwjgl/opengles/EGL.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengles/EGL.java 2011-07-16 16:05:37 UTC (rev 3589)
+++ trunk/LWJGL/src/java/org/lwjgl/opengles/EGL.java 2011-07-16 16:42:51 UTC (rev 3590)
@@ -33,9 +33,9 @@
import org.lwjgl.BufferChecks;
import org.lwjgl.LWJGLException;
+import org.lwjgl.MemoryUtil;
import org.lwjgl.PointerBuffer;
-import java.nio.ByteBuffer;
import java.nio.IntBuffer;
/** EGL wrapper class. */
@@ -266,11 +266,11 @@
static void eglInitialize(EGLDisplay dpy, IntBuffer version) throws LWJGLException {
//LWJGLUtil.log("eglInitialize");
BufferChecks.checkBuffer(version, 2);
- if ( !neglInitialize(dpy.getPointer(), version, version.position()) )
+ if ( !neglInitialize(dpy.getPointer(), MemoryUtil.getAddress(version)) )
throwEGLError("Failed to initialize EGL display.");
}
- private static native boolean neglInitialize(long dpy_ptr, IntBuffer version, int version_position);
+ private static native boolean neglInitialize(long dpy_ptr, long version);
/**
* Release the resources associated with the specified EGL display.
@@ -314,7 +314,7 @@
//LWJGLUtil.log("eglGetConfigsNum");
IntBuffer num_config = APIUtil.getBufferInt();
- if ( !neglGetConfigs(dpy.getPointer(), null, 0, 0, num_config, num_config.position()) )
+ if ( !neglGetConfigs(dpy.getPointer(), 0L, 0, MemoryUtil.getAddress0(num_config)) )
throwEGLError("Failed to get EGL configs.");
return num_config.get(0);
@@ -340,14 +340,14 @@
BufferChecks.checkBuffer(num_config, 1);
if ( configs == null ) {
- if ( !neglGetConfigs(dpy.getPointer(), null, 0, 0, num_config, num_config.position()) )
+ if ( !neglGetConfigs(dpy.getPointer(), 0L, 0, MemoryUtil.getAddress(num_config)) )
throwEGLError("Failed to get number of available EGL configs.");
configs = new EGLConfig[num_config.get(num_config.position())];
}
final PointerBuffer configs_buffer = APIUtil.getBufferPointer(configs.length);
- if ( !neglGetConfigs(dpy.getPointer(), configs_buffer.getBuffer(), 0, configs.length, num_config, num_config.position()) )
+ if ( !neglGetConfigs(dpy.getPointer(), MemoryUtil.getAddress0(configs_buffer), configs.length, MemoryUtil.getAddress(num_config)) )
throwEGLError("Failed to get EGL configs.");
final int config_size = num_config.get(num_config.position());
@@ -357,7 +357,7 @@
return configs;
}
- private static native boolean neglGetConfigs(long dpy_ptr, ByteBuffer configs, int configs_position, int config_size, IntBuffer num_config, int num_config_position);
+ private static native boolean neglGetConfigs(long dpy_ptr, long configs, int config_size, long num_config);
/**
* Returns the number of EGLConfigs that are available on the specified display and
@@ -376,7 +376,7 @@
checkAttribList(attrib_list);
IntBuffer num_config = APIUtil.getBufferInt();
- if ( !neglChooseConfig(dpy.getPointer(), attrib_list, attrib_list == null ? 0 : attrib_list.position(), null, 0, 0, num_config, num_config.position()) )
+ if ( !neglChooseConfig(dpy.getPointer(), MemoryUtil.getAddressSafe(attrib_list), 0L, 0, MemoryUtil.getAddress0(num_config)) )
throwEGLError("Failed to get EGL configs.");
return num_config.get(0);
@@ -405,7 +405,7 @@
int config_size;
if ( configs == null ) {
- if ( !neglChooseConfig(dpy.getPointer(), attrib_list, attrib_list == null ? 0 : attrib_list.position(), null, 0, 0, num_config, num_config.position()) )
+ if ( !neglChooseConfig(dpy.getPointer(), MemoryUtil.getAddressSafe(attrib_list), 0L, 0, MemoryUtil.getAddress(num_config)) )
throwEGLError("Failed to get number of available EGL configs.");
config_size = num_config.get(num_config.position());
@@ -414,7 +414,7 @@
//LWJGLUtil.log("config_size = " + config_size);
PointerBuffer configs_buffer = APIUtil.getBufferPointer(config_size);
- if ( !neglChooseConfig(dpy.getPointer(), attrib_list, attrib_list == null ? 0 : attrib_list.position(), configs_buffer.getBuffer(), 0, config_size, num_config, num_config.position()) )
+ if ( !neglChooseConfig(dpy.getPointer(), MemoryUtil.getAddressSafe(attrib_list), MemoryUtil.getAddress0(configs_buffer), config_size, MemoryUtil.getAddress(num_config)) )
throwEGLError("Failed to choose EGL config.");
// Get the true number of configurations (the first neglChooseConfig call may return more than the second)
@@ -427,7 +427,7 @@
return configs;
}
- private static native boolean neglChooseConfig(long dpy_ptr, IntBuffer attrib_list, int attrib_list_position, ByteBuffer configs, int configs_position, int config_size, IntBuffer num_config, int num_config_position);
+ private static native boolean neglChooseConfig(long dpy_ptr, long attrib_list, long configs, int config_size, long num_config);
/**
* Returns the value of an EGL config attribute.
@@ -442,13 +442,13 @@
//LWJGLUtil.log("eglGetConfigAttrib");
final IntBuffer value = APIUtil.getBufferInt();
- if ( !neglGetConfigAttrib(dpy.getPointer(), config.getPointer(), attribute, value, value.position()) )
+ if ( !neglGetConfigAttrib(dpy.getPointer(), config.getPointer(), attribute, MemoryUtil.getAddress(value)) )
throwEGLError("Failed to get EGL config attribute.");
return value.get(0);
}
- private static native boolean neglGetConfigAttrib(long dpy_ptr, long config_ptr, int attribute, IntBuffer value, int value_position);
+ private static native boolean neglGetConfigAttrib(long dpy_ptr, long config_ptr, int attribute, long value);
/**
* Creates an on-screen rendering surface on the specified EGL display.
@@ -465,7 +465,7 @@
static EGLSurface eglCreateWindowSurface(EGLDisplay dpy, EGLConfig config, long win, IntBuffer attrib_list) throws LWJGLException {
//LWJGLUtil.log("eglCreateWindowSurface");
checkAttribList(attrib_list);
- final long pointer = neglCreateWindowSurface(dpy.getPointer(), config.getPointer(), win, attrib_list, attrib_list == null ? 0 : attrib_list.position());
+ final long pointer = neglCreateWindowSurface(dpy.getPointer(), config.getPointer(), win, MemoryUtil.getAddressSafe(attrib_list));
if ( pointer == EGL_NO_SURFACE )
throwEGLError("Failed to create EGL window surface.");
@@ -473,7 +473,7 @@
return new EGLSurface(dpy, config, pointer);
}
- private static native long neglCreateWindowSurface(long dpy_ptr, long config_ptr, long win, IntBuffer attrib_list, int attrib_list_position);
+ private static native long neglCreateWindowSurface(long dpy_ptr, long config_ptr, long win, long attrib_list);
/**
* Creates an off-screen rendering surface on the specified EGL display.
@@ -489,7 +489,7 @@
static EGLSurface eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config, IntBuffer attrib_list) throws LWJGLException {
//LWJGLUtil.log("eglCreatePbufferSurface");
checkAttribList(attrib_list);
- final long pointer = neglCreatePbufferSurface(dpy.getPointer(), config.getPointer(), attrib_list, attrib_list == null ? 0 : attrib_list.position());
+ final long pointer = neglCreatePbufferSurface(dpy.getPointer(), config.getPointer(), MemoryUtil.getAddressSafe(attrib_list));
if ( pointer == EGL_NO_SURFACE )
throwEGLError("Failed to create EGL pbuffer surface.");
@@ -497,7 +497,7 @@
return new EGLSurface(dpy, config, pointer);
}
- private static native long neglCreatePbufferSurface(long dpy_ptr, long config_ptr, IntBuffer attrib_list, int attrib_list_position);
+ private static native long neglCreatePbufferSurface(long dpy_ptr, long config_ptr, long attrib_list);
/*
EGLAPI EGLSurface EGLAPIENTRY eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list);
@@ -550,11 +550,11 @@
public static void eglQuerySurface(EGLDisplay dpy, EGLSurface surface, int attribute, IntBuffer value) throws LWJGLException {
//LWJGLUtil.log("eglQuerySurface");
BufferChecks.checkBuffer(value, 1);
- if ( !neglQuerySurface(dpy.getPointer(), surface.getPointer(), attribute, value, value.position()) )
+ if ( !neglQuerySurface(dpy.getPointer(), surface.getPointer(), attribute, MemoryUtil.getAddress(value)) )
throwEGLError("Failed to query surface attribute.");
}
- private static native boolean neglQuerySurface(long dpy_ptr, long surface_ptr, int attribute, IntBuffer value, int value_position);
+ private static native boolean neglQuerySurface(long dpy_ptr, long surface_ptr, int attribute, long value);
/**
* Binds the specified rendering API to the current thread.
@@ -627,7 +627,7 @@
checkAttribList(attrib_list);
final long pointer = neglCreateContext(dpy.getPointer(), config.getPointer(),
share_context == null ? EGL_NO_CONTEXT : share_context.getPointer(),
- attrib_list, attrib_list == null ? 0 : attrib_list.position());
+ MemoryUtil.getAddressSafe(attrib_list));
if ( pointer == EGL_NO_CONTEXT )
throwEGLError("Failed to create EGL context.");
@@ -635,7 +635,7 @@
return new EGLContext(dpy, config, pointer);
}
- private static native long neglCreateContext(long dpy_ptr, long config_ptr, long share_context_ptr, IntBuffer attrib_list, int attrib_list_position);
+ private static native long neglCreateContext(long dpy_ptr, long config_ptr, long share_context_ptr, long attrib_list);
/**
* Destroys a rendering context.
@@ -714,7 +714,7 @@
// Query context's CONFIG_ID
final IntBuffer attrib_list = APIUtil.getBufferInt();
- neglQueryContext(display.getPointer(), ctx, EGL_CONFIG_ID, attrib_list, 0);
+ neglQueryContext(display.getPointer(), ctx, EGL_CONFIG_ID, MemoryUtil.getAddress0(attrib_list));
final EGLConfig config = getEGLConfig(display, attrib_list);
@@ -761,7 +761,7 @@
// Query context's CONFIG_ID
final IntBuffer attrib_list = APIUtil.getBufferInt();
- if ( !neglQuerySurface(display.getPointer(), surface, EGL_CONFIG_ID, attrib_list, 0) )
+ if ( !neglQuerySurface(display.getPointer(), surface, EGL_CONFIG_ID, MemoryUtil.getAddress0(attrib_list)) )
throwEGLError("Failed to query surface EGL config ID.");
final EGLConfig config = getEGLConfig(display, attrib_list);
@@ -799,11 +799,11 @@
public static void eglQueryContext(EGLDisplay dpy, EGLContext ctx, int attribute, IntBuffer value) throws LWJGLException {
//LWJGLUtil.log("eglQueryContext");
BufferChecks.checkBuffer(value, 1);
- if ( !neglQueryContext(dpy.getPointer(), ctx.getPointer(), attribute, value, value.position()) )
+ if ( !neglQueryContext(dpy.getPointer(), ctx.getPointer(), attribute, MemoryUtil.getAddress(value)) )
throwEGLError("Failed to query context attribute.");
}
- private static native boolean neglQueryContext(long dpy_ptr, long ctx_ptr, int attribute, IntBuffer value, int value_position);
+ private static native boolean neglQueryContext(long dpy_ptr, long ctx_ptr, int attribute, long value);
/**
* Prevents native rendering API functions from executing until any
@@ -883,7 +883,7 @@
attrib_list.put(0, EGL_CONFIG_ID).put(1, configID).put(2, EGL_NONE);
final PointerBuffer configs_buffer = APIUtil.getBufferPointer(1);
- if ( !neglChooseConfig(dpy.getPointer(), attrib_list, attrib_list.position(), configs_buffer.getBuffer(), 0, 1, attrib_list, attrib_list.position() + 3) )
+ if ( !neglChooseConfig(dpy.getPointer(), MemoryUtil.getAddress(attrib_list), MemoryUtil.getAddress0(configs_buffer), 1, MemoryUtil.getAddress(attrib_list, 3)) )
throwEGLError("Failed to choose EGL config.");
return new EGLConfig(dpy, configs_buffer.get(0));
Modified: trunk/LWJGL/src/java/org/lwjgl/opengles/EGLKHRFenceSync.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengles/EGLKHRFenceSync.java 2011-07-16 16:05:37 UTC (rev 3589)
+++ trunk/LWJGL/src/java/org/lwjgl/opengles/EGLKHRFenceSync.java 2011-07-16 16:42:51 UTC (rev 3590)
@@ -32,6 +32,7 @@
package org.lwjgl.opengles;
import org.lwjgl.LWJGLException;
+import org.lwjgl.MemoryUtil;
import java.nio.IntBuffer;
@@ -102,7 +103,7 @@
public static EGLSyncKHR eglCreateSyncKHR(EGLDisplay dpy, int type, IntBuffer attrib_list) throws LWJGLException {
checkAttribList(attrib_list);
- final long pointer = neglCreateSyncKHR(dpy.getPointer(), type, attrib_list, attrib_list == null ? 0 : attrib_list.position());
+ final long pointer = neglCreateSyncKHR(dpy.getPointer(), type, MemoryUtil.getAddressSafe(attrib_list));
if ( pointer == EGL_NO_SYNC_KHR )
throwEGLError("Failed to create KHR fence sync object.");
@@ -110,7 +111,7 @@
return new EGLSyncKHR(pointer);
}
- private static native long neglCreateSyncKHR(long dpy_ptr, int type, IntBuffer attrib_list, int attrib_list_position);
+ private static native long neglCreateSyncKHR(long dpy_ptr, int type, long attrib_list);
/**
* Destroys an existing sync object.
@@ -162,12 +163,12 @@
public static int eglGetSyncAttribKHR(EGLDisplay dpy, EGLSyncKHR sync, int attribute) throws LWJGLException {
final IntBuffer value = APIUtil.getBufferInt();
- if ( !neglGetSyncAttribKHR(dpy.getPointer(), sync.getPointer(), attribute, value, value.position()) )
+ if ( !neglGetSyncAttribKHR(dpy.getPointer(), sync.getPointer(), attribute, MemoryUtil.getAddress(value)) )
throwEGLError("Failed to get KHR fence sync object attribute.");
return value.get(0);
}
- private static native boolean neglGetSyncAttribKHR(long dpy_ptr, long sync_ptr, int attribute, IntBuffer value, int value_position);
+ private static native boolean neglGetSyncAttribKHR(long dpy_ptr, long sync_ptr, int attribute, long value);
}
\ No newline at end of file
Modified: trunk/LWJGL/src/java/org/lwjgl/opengles/EGLNVSync.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengles/EGLNVSync.java 2011-07-16 16:05:37 UTC (rev 3589)
+++ trunk/LWJGL/src/java/org/lwjgl/opengles/EGLNVSync.java 2011-07-16 16:42:51 UTC (rev 3590)
@@ -32,6 +32,7 @@
package org.lwjgl.opengles;
import org.lwjgl.LWJGLException;
+import org.lwjgl.MemoryUtil;
import java.nio.IntBuffer;
@@ -112,7 +113,7 @@
public static EGLSyncNV eglCreateFenceSyncNV(EGLDisplay dpy, int condition, IntBuffer attrib_list) throws LWJGLException {
checkAttribList(attrib_list);
- final long pointer = neglCreateFenceSyncNV(dpy.getPointer(), condition, attrib_list, attrib_list == null ? 0 : attrib_list.position());
+ final long pointer = neglCreateFenceSyncNV(dpy.getPointer(), condition, MemoryUtil.getAddressSafe(attrib_list));
if ( pointer == EGL_NO_SYNC_NV )
throwEGLError("Failed to create NV fence sync object.");
@@ -120,7 +121,7 @@
return new EGLSyncNV(pointer);
}
- private static native long neglCreateFenceSyncNV(long dpy_ptr, int condition, IntBuffer attrib_list, int attrib_list_position);
+ private static native long neglCreateFenceSyncNV(long dpy_ptr, int condition, long attrib_list);
/**
* Destroys an existing sync object.
@@ -203,12 +204,12 @@
public static int eglGetSyncAttribNV(EGLSyncNV sync, int attribute) throws LWJGLException {
final IntBuffer value = APIUtil.getBufferInt();
- if ( !neglGetSyncAttribNV(sync.getPointer(), attribute, value, 0) )
+ if ( !neglGetSyncAttribNV(sync.getPointer(), attribute, MemoryUtil.getAddress0(value)) )
throwEGLError("Failed to get NV fence sync object attribute.");
return value.get(0);
}
- private static native boolean neglGetSyncAttribNV(long sync_ptr, int attribute, IntBuffer value, int value_position);
+ private static native boolean neglGetSyncAttribNV(long sync_ptr, int attribute, long value);
}
\ No newline at end of file
Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/NativeMethodStubsGenerator.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/generator/NativeMethodStubsGenerator.java 2011-07-16 16:05:37 UTC (rev 3589)
+++ trunk/LWJGL/src/java/org/lwjgl/util/generator/NativeMethodStubsGenerator.java 2011-07-16 16:42:51 UTC (rev 3590)
@@ -298,7 +298,7 @@
writer.print("\t" + native_type + param.getSimpleName());
writer.print(BUFFER_ADDRESS_POSTFIX + " = (");
writer.print(native_type);
- writer.print(")");
+ writer.print(")(intptr_t)");
if (mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null) {
writer.print("offsetToPointer(" + param.getSimpleName() + Utils.BUFFER_OBJECT_PARAMETER_POSTFIX + ")");
Modified: trunk/LWJGL/src/native/common/opengles/org_lwjgl_opengles_EGL.c
===================================================================
--- trunk/LWJGL/src/native/common/opengles/org_lwjgl_opengles_EGL.c 2011-07-16 16:05:37 UTC (rev 3589)
+++ trunk/LWJGL/src/native/common/opengles/org_lwjgl_opengles_EGL.c 2011-07-16 16:42:51 UTC (rev 3590)
@@ -43,9 +43,9 @@
return (intptr_t)eglGetDisplay((EGLNativeDisplayType)(intptr_t)display_id);
}
-JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengles_EGL_neglInitialize(JNIEnv *env, jclass clazz, jlong dpy_ptr, jobject version, jint version_position) {
+JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengles_EGL_neglInitialize(JNIEnv *env, jclass clazz, jlong dpy_ptr, jlong version) {
EGLDisplay dpy = (EGLDisplay)(intptr_t)dpy_ptr;
- EGLint *version_address = ((EGLint *)(*env)->GetDirectBufferAddress(env, version)) + version_position;
+ EGLint *version_address = (EGLint *)(intptr_t)version;
return eglInitialize(dpy, version_address, version_address + 1);
}
@@ -65,43 +65,43 @@
return NewStringNativeWithLength(env, __result, strlen(__result));
}
-JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengles_EGL_neglGetConfigs(JNIEnv *env, jclass clazz, jlong dpy_ptr, jobject configs, jint configs_position, jint config_size, jobject num_config, jint num_config_position) {
+JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengles_EGL_neglGetConfigs(JNIEnv *env, jclass clazz, jlong dpy_ptr, jlong configs, jint config_size, jlong num_config) {
EGLDisplay dpy = (EGLDisplay)(intptr_t)dpy_ptr;
- EGLConfig *configs_address = ((EGLConfig *)safeGetBufferAddress(env, configs)) + configs_position;
- EGLint *num_config_address = ((EGLint *)(*env)->GetDirectBufferAddress(env, num_config)) + num_config_position;
+ EGLConfig *configs_address = (EGLConfig *)(intptr_t)configs;
+ EGLint *num_config_address = (EGLint *)(intptr_t)num_config;
return eglGetConfigs(dpy, configs_address, config_size, num_config_address);
}
-JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengles_EGL_neglChooseConfig(JNIEnv *env, jclass clazz, jlong dpy_ptr, jobject attrib_list, jint attrib_list_position, jobject configs, jint configs_position, jint config_size, jobject num_config, jint num_config_position) {
+JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengles_EGL_neglChooseConfig(JNIEnv *env, jclass clazz, jlong dpy_ptr, jlong attrib_list, jlong configs, jint config_size, jlong num_config) {
EGLDisplay dpy = (EGLDisplay)(intptr_t)dpy_ptr;
- const EGLint *attrib_list_address = ((EGLint *)safeGetBufferAddress(env, attrib_list)) + attrib_list_position;
- EGLConfig *configs_address = ((EGLConfig *)safeGetBufferAddress(env, configs)) + configs_position;
- EGLint *num_config_address = ((EGLint *)(*env)->GetDirectBufferAddress(env, num_config)) + num_config_position;
+ const EGLint *attrib_list_address = (EGLint *)(intptr_t)attrib_list;
+ EGLConfig *configs_address = (EGLConfig *)(intptr_t)configs;
+ EGLint *num_config_address = (EGLint *)(intptr_t)num_config;
return eglChooseConfig(dpy, attrib_list_address, configs_address, config_size, num_config_address);
}
-JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengles_EGL_neglGetConfigAttrib(JNIEnv *env, jclass clazz, jlong dpy_ptr, jlong config_ptr, jint attribute, jobject value, jint value_position) {
+JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengles_EGL_neglGetConfigAttrib(JNIEnv *env, jclass clazz, jlong dpy_ptr, jlong config_ptr, jint attribute, jlong value) {
EGLDisplay dpy = (EGLDisplay)(intptr_t)dpy_ptr;
EGLConfig config = (EGLConfig)(intptr_t)config_ptr;
- EGLint *value_address = ((EGLint *)(*env)->GetDirectBufferAddress(env, value)) + value_position;
+ EGLint *value_address = (EGLint *)(intptr_t)value;
return eglGetConfigAttrib(dpy, config, attribute, value_address);
}
-JNIEXPORT jlong JNICALL Java_org_lwjgl_opengles_EGL_neglCreateWindowSurface(JNIEnv *env, jclass clazz, jlong dpy_ptr, jlong config_ptr, jlong win, jobject attrib_list, jint attrib_list_position) {
+JNIEXPORT jlong JNICALL Java_org_lwjgl_opengles_EGL_neglCreateWindowSurface(JNIEnv *env, jclass clazz, jlong dpy_ptr, jlong config_ptr, jlong win, jlong attrib_list) {
EGLDisplay dpy = (EGLDisplay)(intptr_t)dpy_ptr;
EGLConfig config = (EGLConfig)(intptr_t)config_ptr;
- const EGLint *attrib_list_address = ((EGLint *)safeGetBufferAddress(env, attrib_list)) + attrib_list_position;
+ const EGLint *attrib_list_address = (EGLint *)(intptr_t)attrib_list;
return (intptr_t)eglCreateWindowSurface(dpy, config, (EGLNativeWindowType)(intptr_t)win, attrib_list_address);
}
-JNIEXPORT jlong JNICALL Java_org_lwjgl_opengles_EGL_neglCreatePbufferSurface(JNIEnv *env, jclass clazz, jlong dpy_ptr, jlong config_ptr, jobject attrib_list, jint attrib_list_position) {
+JNIEXPORT jlong JNICALL Java_org_lwjgl_opengles_EGL_neglCreatePbufferSurface(JNIEnv *env, jclass clazz, jlong dpy_ptr, jlong config_ptr, jlong attrib_list) {
EGLDisplay dpy = (EGLDisplay)(intptr_t)dpy_ptr;
EGLConfig config = (EGLConfig)(intptr_t)config_ptr;
- const EGLint *attrib_list_address = ((EGLint *)safeGetBufferAddress(env, attrib_list)) + attrib_list_position;
+ const EGLint *attrib_list_address = (EGLint *)(intptr_t)attrib_list;
return (intptr_t)eglCreatePbufferSurface(dpy, config, attrib_list_address);
}
@@ -120,10 +120,10 @@
return eglSurfaceAttrib(dpy, surface, attribute, value);
}
-JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengles_EGL_neglQuerySurface(JNIEnv *env, jclass clazz, jlong dpy_ptr, jlong surface_ptr, jint attribute, jobject value, jint value_position) {
+JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengles_EGL_neglQuerySurface(JNIEnv *env, jclass clazz, jlong dpy_ptr, jlong surface_ptr, jint attribute, jlong value) {
EGLDisplay dpy = (EGLDisplay)(intptr_t)dpy_ptr;
EGLSurface surface = (EGLSurface)(intptr_t)surface_ptr;
- EGLint *value_address = ((EGLint *)(*env)->GetDirectBufferAddress(env, value)) + value_position;
+ EGLint *value_address = (EGLint *)(intptr_t)value;
return eglQuerySurface(dpy, surface, attribute, value_address);
}
@@ -145,11 +145,11 @@
return eglSwapInterval(dpy, interval);
}
-JNIEXPORT jlong JNICALL Java_org_lwjgl_opengles_EGL_neglCreateContext(JNIEnv *env, jclass clazz, jlong dpy_ptr, jlong config_ptr, jlong share_context_ptr, jobject attrib_list, jint attrib_list_position) {
+JNIEXPORT jlong JNICALL Java_org_lwjgl_opengles_EGL_neglCreateContext(JNIEnv *env, jclass clazz, jlong dpy_ptr, jlong config_ptr, jlong share_context_ptr, jlong attrib_list) {
EGLDisplay dpy = (EGLDisplay)(intptr_t)dpy_ptr;
EGLConfig config = (EGLConfig)(intptr_t)config_ptr;
EGLContext share_context = (EGLContext)(intptr_t)share_context_ptr;
- const EGLint *attrib_list_address = ((EGLint *)safeGetBufferAddress(env, attrib_list)) + attrib_list_position;
+ const EGLint *attrib_list_address = (EGLint *)(intptr_t)attrib_list;
return (intptr_t)eglCreateContext(dpy, config, share_context, attrib_list_address);
}
@@ -182,10 +182,10 @@
return (intptr_t)eglGetCurrentDisplay();
}
-JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengles_EGL_neglQueryContext(JNIEnv *env, jclass clazz, jlong dpy_ptr, jlong ctx_ptr, jint attribute, jobject value, jint value_position) {
+JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengles_EGL_neglQueryContext(JNIEnv *env, jclass clazz, jlong dpy_ptr, jlong ctx_ptr, jint attribute, jlong value) {
EGLDisplay dpy = (EGLDisplay)(intptr_t)dpy_ptr;
EGLContext ctx = (EGLContext)(intptr_t)ctx_ptr;
- EGLint *value_address = ((EGLint *)(*env)->GetDirectBufferAddress(env, value)) + value_position;
+ EGLint *value_address = (EGLint *)(intptr_t)value;
return eglQueryContext(dpy, ctx, attribute, value_address);
Modified: trunk/LWJGL/src/native/common/opengles/org_lwjgl_opengles_EGLKHRFenceSync.c
===================================================================
--- trunk/LWJGL/src/native/common/opengles/org_lwjgl_opengles_EGLKHRFenceSync.c 2011-07-16 16:05:37 UTC (rev 3589)
+++ trunk/LWJGL/src/native/common/opengles/org_lwjgl_opengles_EGLKHRFenceSync.c 2011-07-16 16:42:51 UTC (rev 3590)
@@ -40,9 +40,9 @@
static PFNEGLCLIENTWAITSYNCKHRPROC eglClientWaitSyncKHR;
static PFNEGLGETSYNCATTRIBKHRPROC eglGetSyncAttribKHR;
-JNIEXPORT jlong JNICALL Java_org_lwjgl_opengles_EGLKHRFenceSync_neglCreateSyncKHR(JNIEnv *env, jclass clazz, jlong dpy_ptr, jint type, jobject attrib_list, jint attrib_list_position) {
+JNIEXPORT jlong JNICALL Java_org_lwjgl_opengles_EGLKHRFenceSync_neglCreateSyncKHR(JNIEnv *env, jclass clazz, jlong dpy_ptr, jint type, jlong attrib_list) {
EGLDisplay dpy = (EGLDisplay)(intptr_t)dpy_ptr;
- const EGLint *attrib_list_address = ((EGLint *)safeGetBufferAddress(env, attrib_list)) + attrib_list_position;
+ const EGLint *attrib_list_address = (EGLint *)(intptr_t)attrib_list;
return (intptr_t)eglCreateSyncKHR(dpy, type, attrib_list_address);
}
@@ -61,20 +61,20 @@
return eglClientWaitSyncKHR(dpy, sync, flags, timeout);
}
-JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengles_EGLKHRFenceSync_neglGetSyncAttribKHR(JNIEnv *env, jclass clazz, jlong dpy_ptr, jlong sync_ptr, jint attribute, jobject value, jint value_position) {
+JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengles_EGLKHRFenceSync_neglGetSyncAttribKHR(JNIEnv *env, jclass clazz, jlong dpy_ptr, jlong sync_ptr, jint attribute, jlong value) {
EGLDisplay dpy = (EGLDisplay)(intptr_t)dpy_ptr;
EGLSyncKHR sync = (EGLSyncKHR)(intptr_t)sync_ptr;
- EGLint *value_address = ((EGLint *)(*env)->GetDirectBufferAddress(env, value)) + value_position;
+ EGLint *value_address = (EGLint *)(intptr_t)value;
return eglGetSyncAttribKHR(dpy, sync, attribute, value_address);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengles_EGLKHRFenceSync_initNativeStubs(JNIEnv *env, jclass clazz) {
JavaMethodAndExtFunction functions[] = {
- {"neglCreateSyncKHR", "(JILjava/nio/IntBuffer;I)J", (void *)&Java_org_lwjgl_opengles_EGLKHRFenceSync_neglCreateSyncKHR, "eglCreateSyncKHR", (void *)&eglCreateSyncKHR},
+ {"neglCreateSyncKHR", "(JIJ)J", (void *)&Java_org_lwjgl_opengles_EGLKHRFenceSync_neglCreateSyncKHR, "eglCreateSyncKHR", (void *)&eglCreateSyncKHR},
{"neglDestroySyncKHR", "(JJ)Z", (void *)&Java_org_lwjgl_opengles_EGLKHRFenceSync_neglDestroySyncKHR, "eglDestroySyncKHR", (void *)&eglDestroySyncKHR},
{"neglClientWaitSyncKHR", "(JJIJ)I", (void *)&Java_org_lwjgl_opengles_EGLKHRFenceSync_neglClientWaitSyncKHR, "eglClientWaitSyncKHR", (void *)&eglClientWaitSyncKHR},
- {"neglGetSyncAttribKHR", "(JJILjava/nio/IntBuffer;I)Z", (void *)&Java_org_lwjgl_opengles_EGLKHRFenceSync_neglGetSyncAttribKHR, "eglGetSyncAttribKHR", (void *)&eglGetSyncAttribKHR}
+ {"neglGetSyncAttribKHR", "(JJIJ)Z", (void *)&Java_org_lwjgl_opengles_EGLKHRFenceSync_neglGetSyncAttribKHR, "eglGetSyncAttribKHR", (void *)&eglGetSyncAttribKHR}
};
int num_functions = NUMFUNCTIONS(functions);
extgl_InitializeClass(env, clazz, num_functions, functions);
Modified: trunk/LWJGL/src/native/common/opengles/org_lwjgl_opengles_EGLNVSync.c
===================================================================
--- trunk/LWJGL/src/native/common/opengles/org_lwjgl_opengles_EGLNVSync.c 2011-07-16 16:05:37 UTC (rev 3589)
+++ trunk/LWJGL/src/native/common/opengles/org_lwjgl_opengles_EGLNVSync.c 2011-07-16 16:42:51 UTC (rev 3590)
@@ -42,9 +42,9 @@
static PFNEGLSIGNALSYNCNVPROC eglSignalSyncNV;
static PFNEGLGETSYNCATTRIBNVPROC eglGetSyncAttribNV;
-JNIEXPORT jlong JNICALL Java_org_lwjgl_opengles_EGLNVSync_neglCreateFenceSyncNV(JNIEnv *env, jclass clazz, jlong dpy_ptr, jint condition, jobject attrib_list, jint attrib_list_position) {
+JNIEXPORT jlong JNICALL Java_org_lwjgl_opengles_EGLNVSync_neglCreateFenceSyncNV(JNIEnv *env, jclass clazz, jlong dpy_ptr, jint condition, jlong attrib_list) {
EGLDisplay dpy = (EGLDisplay)(intptr_t)dpy_ptr;
- const EGLint *attrib_list_address = ((EGLint *)safeGetBufferAddress(env, attrib_list)) + attrib_list_position;
+ const EGLint *attrib_list_address = (EGLint *)(intptr_t)attrib_list;
return (intptr_t)eglCreateFenceSyncNV(dpy, condition, attrib_list_address);
}
@@ -73,21 +73,21 @@
return eglSignalSyncNV(sync, mode);
}
-JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengles_EGLNVSync_neglGetSyncAttribNV(JNIEnv *env, jclass clazz, jlong sync_ptr, jint attribute, jobject value, jint value_position) {
+JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengles_EGLNVSync_neglGetSyncAttribNV(JNIEnv *env, jclass clazz, jlong sync_ptr, jint attribute, jlong value) {
EGLSyncNV sync = (EGLSyncNV)(intptr_t)sync_ptr;
- EGLint *value_address = ((EGLint *)(*env)->GetDirectBufferAddress(env, value)) + value_position;
+ EGLint *value_address = (EGLint *)(intptr_t)value;
return eglGetSyncAttribNV(sync, attribute, value_address);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengles_EGLNVSync_initNativeStubs(JNIEnv *env, jclass clazz) {
JavaMethodAndExtFunction functions[] = {
- {"neglCreateFenceSyncNV", "(JILjava/nio/IntBuffer;I)J", (void *)&Java_org_lwjgl_opengles_EGLNVSync_neglCreateFenceSyncNV, "eglCreateFenceSyncNV", (void *)&eglCreateFenceSyncNV},
+ {"neglCreateFenceSyncNV", "(JIJ)J", (void *)&Java_org_lwjgl_opengles_EGLNVSync_neglCreateFenceSyncNV, "eglCreateFenceSyncNV", (void *)&eglCreateFenceSyncNV},
{"neglDestroySyncNV", "(J)Z", (void *)&Java_org_lwjgl_opengles_EGLNVSync_neglDestroySyncNV, "eglDestroySyncNV", (void *)&eglDestroySyncNV},
{"neglFenceNV", "(J)Z", (void *)&Java_org_lwjgl_opengles_EGLNVSync_neglFenceNV, "eglFenceNV", (void *)&eglFenceNV},
{"neglClientWaitSyncNV", "(JIJ)I", (void *)&Java_org_lwjgl_opengles_EGLNVSync_neglClientWaitSyncNV, "eglClientWaitSyncNV", (void *)&eglClientWaitSyncNV},
{"neglSignalSyncNV", "(JI)Z", (void *)&Java_org_lwjgl_opengles_EGLNVSync_neglSignalSyncNV, "eglSignalSyncNV", (void *)&eglSignalSyncNV},
- {"neglGetSyncAttribNV", "(JILjava/nio/IntBuffer;I)Z", (void *)&Java_org_lwjgl_opengles_EGLNVSync_neglGetSyncAttribNV, "eglGetSyncAttribNV", (void *)&eglGetSyncAttribNV}
+ {"neglGetSyncAttribNV", "(JIJ)Z", (void *)&Java_org_lwjgl_opengles_EGLNVSync_neglGetSyncAttribNV, "eglGetSyncAttribNV", (void *)&eglGetSyncAttribNV}
};
int num_functions = NUMFUNCTIONS(functions);
extgl_InitializeClass(env, clazz, num_functions, functions);
Modified: trunk/LWJGL/src/native/common/org_lwjgl_openal_ALC10.c
===================================================================
--- trunk/LWJGL/src/native/common/org_lwjgl_openal_ALC10.c 2011-07-16 16:05:37 UTC (rev 3589)
+++ trunk/LWJGL/src/native/common/org_lwjgl_openal_ALC10.c 2011-07-16 16:42:51 UTC (rev 3590)
@@ -1,40 +1,40 @@
-/*
+/*
* Copyright (c) 2002-2008 LWJGL Project
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
+ * modification, are permitted provided that the following conditions are
* met:
- *
- * * Redistributions of source code must retain the above copyright
+ *
+ * * 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 'LWJGL' nor the names of
- * its contributors may be used to endorse or promote products derived
+ * * Neither the name of 'LWJGL' 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
+ * 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
+ * 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.
*/
-
+
/**
* $Id: org_lwjgl_openal_ALC.c 2279 2006-02-23 19:22:00Z elias_naur $
*
- * This is the actual JNI implementation of the OpenAL context/device library.
- *
+ * This is the actual JNI implementation of the OpenAL context/device library.
+ *
* @author Brian Matzon <br...@ma...>
* @version $Revision: 2279 $
*/
@@ -103,8 +103,8 @@
break;
}
case 0x1013: // ALC_ALL_DEVICES_SPECIFIER
- while (alcString[i - 1] != '\0' || alcString[i] != '\0') {
- i++;
+ while (alcString[i - 1] != '\0' || alcString[i] != '\0') {
+ i++;
}
length = i + 1;
break;
@@ -116,21 +116,18 @@
/**
* This function returns integers related to the context.
- *
+ *
* C Specification:
* ALvoid alcGetIntegerv(ALCdevice *device, ALenum token, ALsizei size, ALint *dest);
*/
-static void JNICALL Java_org_lwjgl_openal_ALC10_nalcGetIntegerv (JNIEnv *env, jclass clazz, jlong deviceaddress, jint token, jint size, jobject dest, jint offset) {
- ALint* address = NULL;
- if (dest != NULL) {
- address = offset + (ALint*) (*env)->GetDirectBufferAddress(env, dest);
- }
- alcGetIntegerv((ALCdevice*)((intptr_t)deviceaddress), (ALenum) token, (ALsizei) size, address);
+static void JNICALL Java_org_lwjgl_openal_ALC10_nalcGetIntegerv (JNIEnv *env, jclass clazz, jlong deviceaddress, jint token, jint size, jlong dest) {
+ ALint* dest_address = (ALint*)(intptr_t)dest;
+ alcGetIntegerv((ALCdevice*)((intptr_t)deviceaddress), (ALenum) token, (ALsizei) size, dest_address);
}
/**
* This function opens a device by name.
- *
+ *
* C Specification:
* ALCdevice *alcOpenDevice( const ALubyte *tokstr );
*/
@@ -156,7 +153,7 @@
/**
* This function closes a device by name.
- *
+ *
* C Specification:
* bool alcCloseDevice( ALCdevice *dev );
*/
@@ -166,19 +163,16 @@
/**
* This function creates a context using a specified device.
- *
+ *
* C Specification:
* ALCcontext* alcCreateContext( ALCdevice *dev, ALint* attrlist );
*/
-static jlong JNICALL Java_org_lwjgl_openal_ALC10_nalcCreateContext (JNIEnv *env, jclass clazz, jlong deviceaddress, jobject attrlist) {
- ALint* address = NULL;
+static jlong JNICALL Java_org_lwjgl_openal_ALC10_nalcCreateContext (JNIEnv *env, jclass clazz, jlong deviceaddress, jlong attrlist) {
+ ALint* attrlist_address = (ALint*)(intptr_t)attrlist;
ALCcontext* context;
- if (attrlist != NULL) {
- address = (ALint*) safeGetBufferAddress(env, attrlist);
- }
- context = alcCreateContext((ALCdevice*)((intptr_t)deviceaddress), address);
-
+ context = alcCreateContext((ALCdevice*)((intptr_t)deviceaddress), attrlist_address);
+
return (jlong)((intptr_t)context);
}
@@ -195,7 +189,7 @@
/**
* This function tells a context to begin processing.
- *
+ *
* C Specification:
* void alcProcessContext(ALCcontext *context);
*/
@@ -205,7 +199,7 @@
/**
* This function retrieves the current context.
- *
+ *
* C Specification:
* ALCcontext* alcGetCurrentContext( ALvoid );
*/
@@ -216,7 +210,7 @@
/**
* This function retrieves the specified contexts device
- *
+ *
* C Specification:
* ALCdevice* alcGetContextsDevice(ALCcontext *context);
*/
@@ -237,7 +231,7 @@
/**
* This function destroys a context.
- *
+ *
* C Specification:
* void alcDestroyContext(ALCcontext *context);
*/
@@ -247,7 +241,7 @@
/**
* This function retrieves the specified devices context error state.
- *
+ *
* C Specification:
* ALCenum alcGetError(ALCdevice *device);
*/
@@ -257,18 +251,18 @@
/**
* This function queries if a specified context extension is available.
- *
+ *
* C Specification:
* ALboolean alcIsExtensionPresent(ALCdevice *device, ALubyte *extName);
*/
static jboolean JNICALL Java_org_lwjgl_openal_ALC10_nalcIsExtensionPresent (JNIEnv *env, jclass clazz, jlong deviceaddress, jstring extName) {
/* get extension */
ALubyte* functionname = (ALubyte*) GetStringNativeChars(env, extName);
-
+
jboolean result = (jboolean) alcIsExtensionPresent((ALCdevice*)((intptr_t)deviceaddress), functionname);
-
+
free(functionname);
-
+
return result;
}
@@ -278,14 +272,14 @@
* C Specification:
* ALenum alcGetEnumValue(ALCdevice *device, ALubyte *enumName);
*/
-static jint JNICALL Java_org_lwjgl_openal_ALC10_nalcGetEnumValue (JNIEnv *env, jclass clazz, jlong deviceaddress, jstring enumName) {
+static jint JNICALL Java_org_lwjgl_openal_ALC10_nalcGetEnumValue (JNIEnv *env, jclass clazz, jlong deviceaddress, jstring enumName) {
/* get extension */
ALubyte* enumerationname = (ALubyte*) GetStringNativeChars(env, enumName);
-
+
jint result = (jint) alcGetEnumValue((ALCdevice*)((intptr_t)deviceaddress), enumerationname);
-
+
free(enumerationname);
-
+
return result;
}
Modified: trunk/LWJGL/src/native/common/org_lwjgl_openal_ALC11.c
===================================================================
--- trunk/LWJGL/src/native/common/org_lwjgl_openal_ALC11.c 2011-07-16 16:05:37 UTC (rev 3589)
+++ trunk/LWJGL/src/native/common/org_lwjgl_openal_ALC11.c 2011-07-16 16:42:51 UTC (rev 3590)
@@ -1,40 +1,40 @@
-/*
+/*
* Copyright (c) 2002-2008 LWJGL Project
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are
+ * modification, are permitted provided that the following conditions are
* met:
- *
- * * Redistributions of source code must retain the above copyright
+ *
+ * * 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 'LWJGL' nor the names of
- * its contributors may be used to endorse or promote products derived
+ * * Neither the name of 'LWJGL' 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
+ * 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
+ * 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.
*/
-
+
/**
* $Id: org_lwjgl_openal_ALC.c 2279 2006-02-23 19:22:00Z elias_naur $
*
- * This is the actual JNI implementation of the OpenAL context/device library.
- *
+ * This is the actual JNI implementation of the OpenAL context/device library.
+ *
* @author Brian Matzon <br...@ma...>
* @version $Revision: 2279 $
*/
@@ -106,8 +106,8 @@
* Method: nalcCaptureSamples
* Signature: (JLjava/nio/ByteBuffer;I)V
*/
-static void JNICALL Java_org_lwjgl_openal_ALC11_nalcCaptureSamples(JNIEnv *env, jclass clazz, jlong device, jobject buffer, jint position, jint samples) {
- ALvoid *buffer_address = ((ALbyte *)(((char*)(*env)->GetDirectBufferAddress(env, buffer)) + position));
+static void JNICALL Java_org_lwjgl_openal_ALC11_nalcCaptureSamples(JNIEnv *env, jclass clazz, jlong device, jlong buffer, jint samples) {
+ ALvoid *buffer_address = (ALbyte *)(intptr_t)buffer;
alcCaptureSamples((ALCdevice*) ((intptr_t)device), buffer_address, samples);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sp...@us...> - 2011-07-16 16:05:47
|
Revision: 3589
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3589&view=rev
Author: spasi
Date: 2011-07-16 16:05:37 +0000 (Sat, 16 Jul 2011)
Log Message:
-----------
Moved all pointer arithmetic to Java code.
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/PointerBuffer.java
trunk/LWJGL/src/java/org/lwjgl/opencl/APIUtil.java
trunk/LWJGL/src/java/org/lwjgl/opencl/InfoUtilFactory.java
trunk/LWJGL/src/java/org/lwjgl/opengl/APIUtil.java
trunk/LWJGL/src/java/org/lwjgl/opengles/APIUtil.java
trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests3.java
trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/SpriteShootout.java
trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/SpriteShootout2P.java
trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/SpriteShootoutCL.java
trunk/LWJGL/src/java/org/lwjgl/util/generator/JNITypeTranslator.java
trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java
trunk/LWJGL/src/java/org/lwjgl/util/generator/NativeMethodStubsGenerator.java
trunk/LWJGL/src/templates/org/lwjgl/opencl/CL10.java
trunk/LWJGL/src/templates/org/lwjgl/opencl/CL10GL.java
trunk/LWJGL/src/templates/org/lwjgl/opencl/EXT_migrate_memobject.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/AMD_name_gen_delete.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/AMD_performance_monitor.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/APPLE_fence.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/APPLE_vertex_array_object.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_buffer_object.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_draw_buffers.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_framebuffer_object.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_occlusion_query.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_program.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_sampler_objects.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_separate_shader_objects.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_shader_objects.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_shading_language_include.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_transform_feedback2.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_array_object.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_shader.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/ATI_draw_buffers.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_direct_state_access.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_framebuffer_object.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_texture_integer.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_transform_feedback.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/GL11.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/GL15.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/GL20.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/GL30.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/GL31.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/GL32.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/GL33.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/GL40.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/GL41.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_fence.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_occlusion_query.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_program.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_transform_feedback.java
trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_transform_feedback2.java
trunk/LWJGL/src/templates/org/lwjgl/opengles/AMD_performance_monitor.java
trunk/LWJGL/src/templates/org/lwjgl/opengles/ARB_draw_buffers.java
trunk/LWJGL/src/templates/org/lwjgl/opengles/GLES20.java
trunk/LWJGL/src/templates/org/lwjgl/opengles/NV_draw_buffers.java
trunk/LWJGL/src/templates/org/lwjgl/opengles/NV_fence.java
trunk/LWJGL/src/templates/org/lwjgl/opengles/OES_framebuffer_object.java
trunk/LWJGL/src/templates/org/lwjgl/opengles/OES_vertex_array_object.java
trunk/LWJGL/src/templates/org/lwjgl/opengles/QCOM_driver_control.java
Added Paths:
-----------
trunk/LWJGL/src/java/org/lwjgl/MemoryUtil.java
trunk/LWJGL/src/java/org/lwjgl/MemoryUtilSun.java
trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/StreamVBO.java
Added: trunk/LWJGL/src/java/org/lwjgl/MemoryUtil.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/MemoryUtil.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/MemoryUtil.java 2011-07-16 16:05:37 UTC (rev 3589)
@@ -0,0 +1,243 @@
+/*
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl;
+
+import java.lang.reflect.Field;
+import java.nio.*;
+
+/**
+ * [INTERNAL USE ONLY]
+ * <p/>
+ * This class provides utility methods for passing buffer addresses to JNI API calls.
+ *
+ * @author Spasi
+ */
+public final class MemoryUtil {
+
+ private static final Accessor memUtil;
+
+ static {
+ Accessor util;
+ try {
+ // Depends on java.nio.Buffer#address and sun.misc.Unsafe
+ //util = loadAccessor("org.lwjgl.MemoryUtilSun$AccessorUnsafe");
+ util = new AccessorJNI();
+ } catch (Exception e0) {
+ try {
+ // Depends on java.nio.Buffer#address and sun.reflect.FieldAccessor
+ util = loadAccessor("org.lwjgl.MemoryUtilSun$AccessorReflectFast");
+ } catch (Exception e1) {
+ try {
+ // Depends on java.nio.Buffer#address
+ util = new AccessorReflect();
+ } catch (Exception e2) {
+ LWJGLUtil.log("Unsupported JVM detected, this will likely result in low performance. Please inform LWJGL developers.");
+ util = new AccessorJNI();
+ }
+ }
+ }
+
+ LWJGLUtil.log("MemoryUtil Accessor: " + util.getClass().getSimpleName());
+ memUtil = util;
+
+ /*
+ BENCHMARK RESULTS - Oracle Server VM:
+
+ Unsafe: 4ns
+ ReflectFast: 8ns
+ Reflect: 10ns
+ JNI: 82ns
+
+ BENCHMARK RESULTS - Oracle Client VM:
+
+ Unsafe: 5ns
+ ReflectFast: 81ns
+ Reflect: 85ns
+ JNI: 87ns
+
+ On non-Oracle VMs, Unsafe should be the fastest implementation as well. In the absence
+ of Unsafe, performance will depend on how reflection and JNI are implemented. For now
+ we'll go with what we see on the Oracle VM (that is, we'll prefer reflection over JNI).
+ */
+ }
+
+ private MemoryUtil() {
+ }
+
+ public static String wrap(final String test) {
+ return "MemoryUtil.getAddress(" + test + ")";
+ }
+
+ /**
+ * Returns the memory address of the specified buffer. [INTERNAL USE ONLY]
+ *
+ * @param buffer the buffer
+ *
+ * @return the memory address
+ */
+ public static long getAddress0(Buffer buffer) { return memUtil.getAddress(buffer); }
+
+ public static long getAddress0Safe(Buffer buffer) { return buffer == null ? 0L : memUtil.getAddress(buffer); }
+
+ public static long getAddress0(PointerBuffer buffer) { return memUtil.getAddress(buffer.getBuffer()); }
+
+ public static long getAddress0Safe(PointerBuffer buffer) { return buffer == null ? 0L : memUtil.getAddress(buffer.getBuffer()); }
+
+ // --- [ API utilities ] ---
+
+ public static long getAddress(ByteBuffer buffer) { return getAddress(buffer, buffer.position()); }
+
+ public static long getAddress(ByteBuffer buffer, int position) { return getAddress0(buffer) + position; }
+
+ public static long getAddress(ShortBuffer buffer) { return getAddress(buffer, buffer.position()); }
+
+ public static long getAddress(ShortBuffer buffer, int position) { return getAddress0(buffer) + (position << 1); }
+
+ public static long getAddress(CharBuffer buffer) { return getAddress(buffer, buffer.position()); }
+
+ public static long getAddress(CharBuffer buffer, int position) { return getAddress0(buffer) + (position << 1); }
+
+ public static long getAddress(IntBuffer buffer) { return getAddress(buffer, buffer.position()); }
+
+ public static long getAddress(IntBuffer buffer, int position) { return getAddress0(buffer) + (position << 2); }
+
+ public static long getAddress(FloatBuffer buffer) { return getAddress(buffer, buffer.position()); }
+
+ public static long getAddress(FloatBuffer buffer, int position) { return getAddress0(buffer) + (position << 2); }
+
+ public static long getAddress(LongBuffer buffer) { return getAddress(buffer, buffer.position()); }
+
+ public static long getAddress(LongBuffer buffer, int position) { return getAddress0(buffer) + (position << 3); }
+
+ public static long getAddress(DoubleBuffer buffer) { return getAddress(buffer, buffer.position()); }
+
+ public static long getAddress(DoubleBuffer buffer, int position) { return getAddress0(buffer) + (position << 3); }
+
+ public static long getAddress(PointerBuffer buffer) { return getAddress(buffer, buffer.position()); }
+
+ public static long getAddress(PointerBuffer buffer, int position) { return getAddress0(buffer) + (position * PointerBuffer.getPointerSize()); }
+
+ // --- [ API utilities - Safe ] ---
+
+ public static long getAddressSafe(ByteBuffer buffer) { return buffer == null ? 0L : getAddress(buffer); }
+
+ public static long getAddressSafe(ByteBuffer buffer, int position) { return buffer == null ? 0L : getAddress(buffer, position); }
+
+ public static long getAddressSafe(ShortBuffer buffer) { return buffer == null ? 0L : getAddress(buffer); }
+
+ public static long getAddressSafe(ShortBuffer buffer, int position) { return buffer == null ? 0L : getAddress(buffer, position); }
+
+ public static long getAddressSafe(CharBuffer buffer) { return buffer == null ? 0L : getAddress(buffer); }
+
+ public static long getAddressSafe(CharBuffer buffer, int position) { return buffer == null ? 0L : getAddress(buffer, position); }
+
+ public static long getAddressSafe(IntBuffer buffer) { return buffer == null ? 0L : getAddress(buffer); }
+
+ public static long getAddressSafe(IntBuffer buffer, int position) { return buffer == null ? 0L : getAddress(buffer, position); }
+
+ public static long getAddressSafe(FloatBuffer buffer) { return buffer == null ? 0L : getAddress(buffer); }
+
+ public static long getAddressSafe(FloatBuffer buffer, int position) { return buffer == null ? 0L : getAddress(buffer, position); }
+
+ public static long getAddressSafe(LongBuffer buffer) { return buffer == null ? 0L : getAddress(buffer); }
+
+ public static long getAddressSafe(LongBuffer buffer, int position) { return buffer == null ? 0L : getAddress(buffer, position); }
+
+ public static long getAddressSafe(DoubleBuffer buffer) { return buffer == null ? 0L : getAddress(buffer); }
+
+ public static long getAddressSafe(DoubleBuffer buffer, int position) { return buffer == null ? 0L : getAddress(buffer, position); }
+
+ public static long getAddressSafe(PointerBuffer buffer) { return buffer == null ? 0L : getAddress(buffer); }
+
+ public static long getAddressSafe(PointerBuffer buffer, int position) { return buffer == null ? 0L : getAddress(buffer, position); }
+
+ interface Accessor {
+
+ long getAddress(Buffer buffer);
+
+ }
+
+ private static Accessor loadAccessor(final String className) throws Exception {
+ return (Accessor)Class.forName(className).newInstance();
+ }
+
+ /** Default implementation. */
+ private static class AccessorJNI implements Accessor {
+
+ public long getAddress(final Buffer buffer) {
+ return BufferUtils.getBufferAddress(buffer);
+ }
+
+ }
+
+ /** Implementation using reflection on ByteBuffer. */
+ private static class AccessorReflect implements Accessor {
+
+ private final Field address;
+
+ AccessorReflect() {
+ try {
+ address = getAddressField();
+ } catch (NoSuchFieldException e) {
+ throw new UnsupportedOperationException(e);
+ }
+ address.setAccessible(true);
+ }
+
+ public long getAddress(final Buffer buffer) {
+ try {
+ return address.getLong(buffer);
+ } catch (IllegalAccessException e) {
+ // cannot happen
+ return 0L;
+ }
+ }
+
+ }
+
+ static Field getAddressField() throws NoSuchFieldException {
+ return getDeclaredFieldRecursive(ByteBuffer.class, "address");
+ }
+
+ private static Field getDeclaredFieldRecursive(Class<?> type, final String fieldName) throws NoSuchFieldException {
+ while ( type != null ) {
+ try {
+ return type.getDeclaredField(fieldName);
+ } catch (NoSuchFieldException e) {
+ type = type.getSuperclass();
+ }
+ }
+
+ throw new NoSuchFieldException(fieldName + " does not exist in " + type.getSimpleName() + " or any of its superclasses.");
+ }
+
+}
\ No newline at end of file
Added: trunk/LWJGL/src/java/org/lwjgl/MemoryUtilSun.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/MemoryUtilSun.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/MemoryUtilSun.java 2011-07-16 16:05:37 UTC (rev 3589)
@@ -0,0 +1,135 @@
+/*
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.nio.Buffer;
+
+import sun.misc.Unsafe;
+import sun.reflect.FieldAccessor;
+
+/**
+ * MemoryUtil.Accessor implementations that depend on sun.misc.
+ * We use reflection to grab these, so that we can compile on JDKs
+ * that do not support sun.misc.
+ *
+ * @author Spasi
+ */
+final class MemoryUtilSun {
+
+ private MemoryUtilSun() {
+ }
+
+ /** Implementation using sun.misc.Unsafe. */
+ private static class AccessorUnsafe implements MemoryUtil.Accessor {
+
+ private final Unsafe unsafe;
+ private final long address;
+
+ AccessorUnsafe() {
+ try {
+ unsafe = getUnsafeInstance();
+ address = unsafe.objectFieldOffset(MemoryUtil.getAddressField());
+ } catch (Exception e) {
+ throw new UnsupportedOperationException(e);
+ }
+ }
+
+ public long getAddress(final Buffer buffer) {
+ return unsafe.getLong(buffer, address);
+ }
+
+ private static Unsafe getUnsafeInstance() {
+ final Field[] fields = Unsafe.class.getDeclaredFields();
+
+ /*
+ Different runtimes use different names for the Unsafe singleton,
+ so we cannot use .getDeclaredField and we scan instead. For example:
+
+ Oracle: theUnsafe
+ PERC : m_unsafe_instance
+ Android: THE_ONE
+ */
+ for ( Field field : fields ) {
+ if ( !field.getType().equals(Unsafe.class) )
+ continue;
+
+ final int modifiers = field.getModifiers();
+ if ( !(Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers)) )
+ continue;
+
+ field.setAccessible(true);
+ try {
+ return (Unsafe)field.get(null);
+ } catch (IllegalAccessException e) {
+ // ignore
+ }
+ break;
+ }
+
+ throw new UnsupportedOperationException();
+ }
+
+ }
+
+ /** Implementation using reflection on ByteBuffer, FieldAccessor is used directly. */
+ private static class AccessorReflectFast implements MemoryUtil.Accessor {
+
+ private final FieldAccessor addressAccessor;
+
+ AccessorReflectFast() {
+ Field address;
+ try {
+ address = MemoryUtil.getAddressField();
+ } catch (NoSuchFieldException e) {
+ throw new UnsupportedOperationException(e);
+ }
+ address.setAccessible(true);
+
+ try {
+ Method m = Field.class.getDeclaredMethod("acquireFieldAccessor", boolean.class);
+ m.setAccessible(true);
+ addressAccessor = (FieldAccessor)m.invoke(address, true);
+ } catch (Exception e) {
+ throw new UnsupportedOperationException(e);
+ }
+ }
+
+ public long getAddress(final Buffer buffer) {
+ return addressAccessor.getLong(buffer);
+ }
+
+ }
+
+}
\ No newline at end of file
Modified: trunk/LWJGL/src/java/org/lwjgl/PointerBuffer.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/PointerBuffer.java 2011-07-14 23:11:41 UTC (rev 3588)
+++ trunk/LWJGL/src/java/org/lwjgl/PointerBuffer.java 2011-07-16 16:05:37 UTC (rev 3589)
@@ -99,7 +99,7 @@
throw new IllegalArgumentException("The source buffer is not direct.");
final int alignment = is64Bit ? 8 : 4;
- if ( (BufferUtils.getBufferAddress(source) + source.position()) % alignment != 0 || source.remaining() % alignment != 0 )
+ if ( (MemoryUtil.getAddress0(source) + source.position()) % alignment != 0 || source.remaining() % alignment != 0 )
throw new IllegalArgumentException("The source buffer is not aligned to " + alignment + " bytes.");
}
Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/APIUtil.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opencl/APIUtil.java 2011-07-14 23:11:41 UTC (rev 3588)
+++ trunk/LWJGL/src/java/org/lwjgl/opencl/APIUtil.java 2011-07-16 16:05:37 UTC (rev 3589)
@@ -31,9 +31,7 @@
*/
package org.lwjgl.opencl;
-import org.lwjgl.BufferUtils;
-import org.lwjgl.LWJGLUtil;
-import org.lwjgl.PointerBuffer;
+import org.lwjgl.*;
import org.lwjgl.opencl.FastLongMap.Entry;
import java.nio.*;
@@ -53,7 +51,7 @@
*/
final class APIUtil {
- private static final int INITIAL_BUFFER_SIZE = 256;
+ private static final int INITIAL_BUFFER_SIZE = 256;
private static final int INITIAL_LENGTHS_SIZE = 4;
private static final int BUFFERS_SIZE = 32;
@@ -223,10 +221,10 @@
*
* @return the String as a ByteBuffer
*/
- static ByteBuffer getBuffer(final CharSequence string) {
+ static long getBuffer(final CharSequence string) {
final ByteBuffer buffer = encode(getBufferByte(string.length()), string);
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress0(buffer);
}
/**
@@ -236,10 +234,10 @@
*
* @return the String as a ByteBuffer
*/
- static ByteBuffer getBuffer(final CharSequence string, final int offset) {
+ static long getBuffer(final CharSequence string, final int offset) {
final ByteBuffer buffer = encode(getBufferByteOffset(offset + string.length()), string);
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress(buffer);
}
/**
@@ -249,11 +247,11 @@
*
* @return the String as a ByteBuffer
*/
- static ByteBuffer getBufferNT(final CharSequence string) {
+ static long getBufferNT(final CharSequence string) {
final ByteBuffer buffer = encode(getBufferByte(string.length() + 1), string);
buffer.put((byte)0);
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress0(buffer);
}
static int getTotalLength(final CharSequence[] strings) {
@@ -271,14 +269,14 @@
*
* @return the Strings as a ByteBuffer
*/
- static ByteBuffer getBuffer(final CharSequence[] strings) {
+ static long getBuffer(final CharSequence[] strings) {
final ByteBuffer buffer = getBufferByte(getTotalLength(strings));
for ( CharSequence string : strings )
encode(buffer, string);
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress0(buffer);
}
/**
@@ -288,7 +286,7 @@
*
* @return the Strings as a ByteBuffer
*/
- static ByteBuffer getBufferNT(final CharSequence[] strings) {
+ static long getBufferNT(final CharSequence[] strings) {
final ByteBuffer buffer = getBufferByte(getTotalLength(strings) + strings.length);
for ( CharSequence string : strings ) {
@@ -297,7 +295,7 @@
}
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress0(buffer);
}
/**
@@ -307,14 +305,14 @@
*
* @return the String lengths in a PointerBuffer
*/
- static PointerBuffer getLengths(final CharSequence[] strings) {
+ static long getLengths(final CharSequence[] strings) {
PointerBuffer buffer = getLengths(strings.length);
for ( CharSequence string : strings )
buffer.put(string.length());
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress0(buffer);
}
/**
@@ -324,14 +322,14 @@
*
* @return the buffer lengths in a PointerBuffer
*/
- static PointerBuffer getLengths(final ByteBuffer[] buffers) {
+ static long getLengths(final ByteBuffer[] buffers) {
PointerBuffer lengths = getLengths(buffers.length);
for ( ByteBuffer buffer : buffers )
lengths.put(buffer.remaining());
lengths.flip();
- return lengths;
+ return MemoryUtil.getAddress0(lengths);
}
static int getSize(final PointerBuffer lengths) {
@@ -342,14 +340,22 @@
return (int)size;
}
+ static long getPointer(final PointerWrapper pointer) {
+ return MemoryUtil.getAddress0(getBufferPointer().put(0, pointer));
+ }
+
+ static long getPointerSafe(final PointerWrapper pointer) {
+ return MemoryUtil.getAddress0(getBufferPointer().put(0, pointer == null ? 0L : pointer.getPointer()));
+ }
+
private static class Buffers {
final ShortBuffer shorts;
- final IntBuffer ints;
- final IntBuffer intsDebug;
- final LongBuffer longs;
+ final IntBuffer ints;
+ final IntBuffer intsDebug;
+ final LongBuffer longs;
- final FloatBuffer floats;
+ final FloatBuffer floats;
final DoubleBuffer doubles;
final PointerBuffer pointers;
@@ -513,25 +519,25 @@
}
}
- private static final ObjectDestructor<CLDevice> DESTRUCTOR_CLSubDevice = new ObjectDestructor<CLDevice>() {
+ private static final ObjectDestructor<CLDevice> DESTRUCTOR_CLSubDevice = new ObjectDestructor<CLDevice>() {
public void release(final CLDevice object) { clReleaseDeviceEXT(object); }
};
- private static final ObjectDestructor<CLMem> DESTRUCTOR_CLMem = new ObjectDestructor<CLMem>() {
+ private static final ObjectDestructor<CLMem> DESTRUCTOR_CLMem = new ObjectDestructor<CLMem>() {
public void release(final CLMem object) { clReleaseMemObject(object); }
};
private static final ObjectDestructor<CLCommandQueue> DESTRUCTOR_CLCommandQueue = new ObjectDestructor<CLCommandQueue>() {
public void release(final CLCommandQueue object) { clReleaseCommandQueue(object); }
};
- private static final ObjectDestructor<CLSampler> DESTRUCTOR_CLSampler = new ObjectDestructor<CLSampler>() {
+ private static final ObjectDestructor<CLSampler> DESTRUCTOR_CLSampler = new ObjectDestructor<CLSampler>() {
public void release(final CLSampler object) { clReleaseSampler(object); }
};
- private static final ObjectDestructor<CLProgram> DESTRUCTOR_CLProgram = new ObjectDestructor<CLProgram>() {
+ private static final ObjectDestructor<CLProgram> DESTRUCTOR_CLProgram = new ObjectDestructor<CLProgram>() {
public void release(final CLProgram object) { clReleaseProgram(object); }
};
- private static final ObjectDestructor<CLKernel> DESTRUCTOR_CLKernel = new ObjectDestructor<CLKernel>() {
+ private static final ObjectDestructor<CLKernel> DESTRUCTOR_CLKernel = new ObjectDestructor<CLKernel>() {
public void release(final CLKernel object) { clReleaseKernel(object); }
};
- private static final ObjectDestructor<CLEvent> DESTRUCTOR_CLEvent = new ObjectDestructor<CLEvent>() {
+ private static final ObjectDestructor<CLEvent> DESTRUCTOR_CLEvent = new ObjectDestructor<CLEvent>() {
public void release(final CLEvent object) { clReleaseEvent(object); }
};
Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/InfoUtilFactory.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opencl/InfoUtilFactory.java 2011-07-14 23:11:41 UTC (rev 3588)
+++ trunk/LWJGL/src/java/org/lwjgl/opencl/InfoUtilFactory.java 2011-07-16 16:05:37 UTC (rev 3589)
@@ -118,7 +118,7 @@
final long user_data = pfn_notify == null || pfn_notify.isCustom() ? 0 : CallbackUtil.createGlobalRef(pfn_notify);
CLContext __result = null;
try {
- __result = new CLContext(nclCreateContext(properties.getBuffer(), 0, devices.size(), properties.getBuffer(), propertyCount, pfn_notify == null ? 0 : pfn_notify.getPointer(), user_data, errcode_ret, errcode_ret != null ? errcode_ret.position() : 0, function_pointer), platform);
+ __result = new CLContext(nclCreateContext(MemoryUtil.getAddress0(properties.getBuffer()), devices.size(), MemoryUtil.getAddress(properties, propertyCount), pfn_notify == null ? 0 : pfn_notify.getPointer(), user_data, MemoryUtil.getAddressSafe(errcode_ret), function_pointer), platform);
if ( LWJGLUtil.DEBUG )
Util.checkCLError(errcode_ret.get(0));
return __result;
@@ -304,9 +304,9 @@
else if ( LWJGLUtil.DEBUG )
errcode_ret = APIUtil.getBufferInt();
- CLMem __result = new CLMem(nclCreateImage2D(context.getPointer(), flags, formatBuffer, 0, image_width, image_height, image_row_pitch, host_ptr,
- host_ptr != null ? BufferChecks.checkBuffer(host_ptr, CLChecks.calculateImage2DSize(formatBuffer, image_width, image_height, image_row_pitch)) : 0,
- errcode_ret, errcode_ret != null ? errcode_ret.position() : 0, function_pointer), context);
+ CLMem __result = new CLMem(nclCreateImage2D(context.getPointer(), flags, MemoryUtil.getAddress(formatBuffer, 0), image_width, image_height, image_row_pitch, MemoryUtil.getAddress0Safe(host_ptr) +
+ (host_ptr != null ? BufferChecks.checkBuffer(host_ptr, CLChecks.calculateImage2DSize(formatBuffer, image_width, image_height, image_row_pitch)) : 0),
+ MemoryUtil.getAddressSafe(errcode_ret), function_pointer), context);
if ( LWJGLUtil.DEBUG )
Util.checkCLError(errcode_ret.get(0));
return __result;
@@ -324,9 +324,9 @@
else if ( LWJGLUtil.DEBUG )
errcode_ret = APIUtil.getBufferInt();
- CLMem __result = new CLMem(nclCreateImage3D(context.getPointer(), flags, formatBuffer, 0, image_width, image_height, image_depth, image_row_pitch, image_slice_pitch, host_ptr,
- host_ptr != null ? BufferChecks.checkBuffer(host_ptr, CLChecks.calculateImage3DSize(formatBuffer, image_width, image_height, image_depth, image_row_pitch, image_slice_pitch)) : 0,
- errcode_ret, errcode_ret != null ? errcode_ret.position() : 0, function_pointer), context);
+ CLMem __result = new CLMem(nclCreateImage3D(context.getPointer(), flags, MemoryUtil.getAddress(formatBuffer, 0), image_width, image_height, image_depth, image_row_pitch, image_slice_pitch, MemoryUtil.getAddress0Safe(host_ptr) +
+ (host_ptr != null ? BufferChecks.checkBuffer(host_ptr, CLChecks.calculateImage3DSize(formatBuffer, image_width, image_height, image_depth, image_row_pitch, image_slice_pitch)) : 0),
+ MemoryUtil.getAddressSafe(errcode_ret), function_pointer), context);
if ( LWJGLUtil.DEBUG )
Util.checkCLError(errcode_ret.get(0));
return __result;
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/APIUtil.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/APIUtil.java 2011-07-14 23:11:41 UTC (rev 3588)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/APIUtil.java 2011-07-16 16:05:37 UTC (rev 3589)
@@ -33,6 +33,7 @@
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLUtil;
+import org.lwjgl.MemoryUtil;
import java.nio.*;
@@ -185,10 +186,10 @@
*
* @return the String as a ByteBuffer
*/
- static ByteBuffer getBuffer(final CharSequence string) {
+ static long getBuffer(final CharSequence string) {
final ByteBuffer buffer = encode(getBufferByte(string.length()), string);
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress0(buffer);
}
/**
@@ -198,10 +199,10 @@
*
* @return the String as a ByteBuffer
*/
- static ByteBuffer getBuffer(final CharSequence string, final int offset) {
+ static long getBuffer(final CharSequence string, final int offset) {
final ByteBuffer buffer = encode(getBufferByteOffset(offset + string.length()), string);
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress(buffer);
}
/**
@@ -211,11 +212,11 @@
*
* @return the String as a ByteBuffer
*/
- static ByteBuffer getBufferNT(final CharSequence string) {
+ static long getBufferNT(final CharSequence string) {
final ByteBuffer buffer = encode(getBufferByte(string.length() + 1), string);
buffer.put((byte)0);
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress0(buffer);
}
static int getTotalLength(final CharSequence[] strings) {
@@ -233,14 +234,14 @@
*
* @return the Strings as a ByteBuffer
*/
- static ByteBuffer getBuffer(final CharSequence[] strings) {
+ static long getBuffer(final CharSequence[] strings) {
final ByteBuffer buffer = getBufferByte(getTotalLength(strings));
for ( CharSequence string : strings )
encode(buffer, string);
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress0(buffer);
}
/**
@@ -250,7 +251,7 @@
*
* @return the Strings as a ByteBuffer
*/
- static ByteBuffer getBufferNT(final CharSequence[] strings) {
+ static long getBufferNT(final CharSequence[] strings) {
final ByteBuffer buffer = getBufferByte(getTotalLength(strings) + strings.length);
for ( CharSequence string : strings ) {
@@ -259,7 +260,7 @@
}
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress0(buffer);
}
/**
@@ -269,16 +270,24 @@
*
* @return the String lengths in an IntBuffer
*/
- static IntBuffer getLengths(final CharSequence[] strings) {
+ static long getLengths(final CharSequence[] strings) {
IntBuffer buffer = getLengths(strings.length);
for ( CharSequence string : strings )
buffer.put(string.length());
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress0(buffer);
}
+ static long getInt(final int value) {
+ return MemoryUtil.getAddress0(getBufferInt().put(0, value));
+ }
+
+ static long getBufferByte0() {
+ return MemoryUtil.getAddress0(getBufferByte(0));
+ }
+
private static class Buffers {
final ShortBuffer shorts;
Modified: trunk/LWJGL/src/java/org/lwjgl/opengles/APIUtil.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengles/APIUtil.java 2011-07-14 23:11:41 UTC (rev 3588)
+++ trunk/LWJGL/src/java/org/lwjgl/opengles/APIUtil.java 2011-07-16 16:05:37 UTC (rev 3589)
@@ -33,6 +33,7 @@
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLUtil;
+import org.lwjgl.MemoryUtil;
import org.lwjgl.PointerBuffer;
import java.nio.ByteBuffer;
@@ -207,10 +208,10 @@
*
* @return the String as a ByteBuffer
*/
- static ByteBuffer getBuffer(final CharSequence string) {
+ static long getBuffer(final CharSequence string) {
final ByteBuffer buffer = encode(getBufferByte(string.length()), string);
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress0(buffer);
}
/**
@@ -220,10 +221,10 @@
*
* @return the String as a ByteBuffer
*/
- static ByteBuffer getBuffer(final CharSequence string, final int offset) {
+ static long getBuffer(final CharSequence string, final int offset) {
final ByteBuffer buffer = encode(getBufferByteOffset(offset + string.length()), string);
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress(buffer);
}
/**
@@ -233,11 +234,11 @@
*
* @return the String as a ByteBuffer
*/
- static ByteBuffer getBufferNT(final CharSequence string) {
+ static long getBufferNT(final CharSequence string) {
final ByteBuffer buffer = encode(getBufferByte(string.length() + 1), string);
buffer.put((byte)0);
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress0(buffer);
}
static int getTotalLength(final CharSequence[] strings) {
@@ -255,14 +256,14 @@
*
* @return the Strings as a ByteBuffer
*/
- static ByteBuffer getBuffer(final CharSequence[] strings) {
+ static long getBuffer(final CharSequence[] strings) {
final ByteBuffer buffer = getBufferByte(getTotalLength(strings));
for ( CharSequence string : strings )
encode(buffer, string);
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress0(buffer);
}
/**
@@ -272,7 +273,7 @@
*
* @return the Strings as a ByteBuffer
*/
- static ByteBuffer getBufferNT(final CharSequence[] strings) {
+ static long getBufferNT(final CharSequence[] strings) {
final ByteBuffer buffer = getBufferByte(getTotalLength(strings) + strings.length);
for ( CharSequence string : strings ) {
@@ -281,7 +282,7 @@
}
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress0(buffer);
}
/**
@@ -291,16 +292,24 @@
*
* @return the String lengths in an IntBuffer
*/
- static IntBuffer getLengths(final CharSequence[] strings) {
+ static long getLengths(final CharSequence[] strings) {
IntBuffer buffer = getLengths(strings.length);
for ( CharSequence string : strings )
buffer.put(string.length());
buffer.flip();
- return buffer;
+ return MemoryUtil.getAddress0(buffer);
}
+ static long getInt(final int value) {
+ return MemoryUtil.getAddress(getBufferInt().put(0, value), 0);
+ }
+
+ static long getBufferByte0() {
+ return MemoryUtil.getAddress0(getBufferByte(0));
+ }
+
private static class Buffers {
final ShortBuffer shorts;
Modified: trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests3.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests3.java 2011-07-14 23:11:41 UTC (rev 3588)
+++ trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests3.java 2011-07-16 16:05:37 UTC (rev 3589)
@@ -118,6 +118,10 @@
set.view = 0;
assert (vec2.view == 0);
assert (vec3.view == 0);
+
+ set.next();
+ assert (vec2.view == 1);
+ assert (vec3.view == 1);
}
}
\ No newline at end of file
Modified: trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/SpriteShootout.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/SpriteShootout.java 2011-07-14 23:11:41 UTC (rev 3588)
+++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/SpriteShootout.java 2011-07-16 16:05:37 UTC (rev 3589)
@@ -1,3 +1,34 @@
+/*
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.test.opengl.sprites;
import org.lwjgl.BufferUtils;
@@ -33,8 +64,8 @@
*/
public final class SpriteShootout {
- private static final int SCREEN_WIDTH = 800;
- private static final int SCREEN_HEIGHT = 600;
+ static final int SCREEN_WIDTH = 800;
+ static final int SCREEN_HEIGHT = 600;
private static final int ANIMATION_TICKS = 60;
@@ -45,8 +76,8 @@
private boolean smooth;
private boolean vsync;
- private int ballSize = 42;
- private int ballCount = 100 * 1000;
+ int ballSize = 42;
+ int ballCount = 100 * 1000;
private SpriteRenderer renderer;
@@ -401,43 +432,45 @@
transform = newTransform;
}
- protected void animate(final FloatBuffer geom, final int ballIndex, final int batchSize, final int delta) {
- final float[] transform = this.transform;
-
+ protected void animate(
+ final float[] sprites,
+ final FloatBuffer spritesRender,
+ final int ballSize, final int ballIndex, final int batchSize, final int delta
+ ) {
final float ballRadius = ballSize * 0.5f;
final float boundW = SCREEN_WIDTH - ballRadius;
final float boundH = SCREEN_HEIGHT - ballRadius;
for ( int b = ballIndex * 4, len = (ballIndex + batchSize) * 4; b < len; b += 4 ) {
- float x = transform[b + 0];
- float dx = transform[b + 2];
+ float x = sprites[b + 0];
+ float dx = sprites[b + 2];
x += dx * delta;
if ( x < ballRadius ) {
x = ballRadius;
- transform[b + 2] = -dx;
+ sprites[b + 2] = -dx;
} else if ( x > boundW ) {
x = boundW;
- transform[b + 2] = -dx;
+ sprites[b + 2] = -dx;
}
- transform[b + 0] = x;
+ sprites[b + 0] = x;
- float y = transform[b + 1];
- float dy = transform[b + 3];
+ float y = sprites[b + 1];
+ float dy = sprites[b + 3];
y += dy * delta;
if ( y < ballRadius ) {
y = ballRadius;
- transform[b + 3] = -dy;
+ sprites[b + 3] = -dy;
} else if ( y > boundH ) {
y = boundH;
- transform[b + 3] = -dy;
+ sprites[b + 3] = -dy;
}
- transform[b + 1] = y;
+ sprites[b + 1] = y;
- geom.put(x).put(y);
+ spritesRender.put(x).put(y);
}
- geom.clear();
+ spritesRender.clear();
}
protected abstract void render(boolean render, boolean animate, int delta);
@@ -517,8 +550,9 @@
}
private void animate(final int ballIndex, final int batchSize, final int delta) {
- animate(geom, ballIndex, batchSize, delta);
+ animate(transform, geom, ballSize, ballIndex, batchSize, delta);
+ // Orphan current buffer and allocate a new one
glBufferData(GL_ARRAY_BUFFER, geom.capacity() * 4, GL_STREAM_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, geom);
}
@@ -526,11 +560,8 @@
private class SpriteRendererMapped extends SpriteRendererBatched {
- private ByteBuffer[] mapBuffer;
- private FloatBuffer[] geomBuffer;
+ private StreamVBO animVBO;
- protected int animVBO;
-
SpriteRendererMapped() {
System.out.println("Shootout Implementation: CPU animation & MapBufferRange");
}
@@ -538,41 +569,29 @@
public void updateBalls(final int count) {
super.updateBalls(count);
- final int batchCount = count / BALLS_PER_BATCH + (count % BALLS_PER_BATCH == 0 ? 0 : 1);
- mapBuffer = new ByteBuffer[batchCount];
- geomBuffer = new FloatBuffer[batchCount];
+ if ( animVBO != null )
+ animVBO.destroy();
- animVBO = glGenBuffers();
- glBindBuffer(GL_ARRAY_BUFFER, animVBO);
- glBufferData(GL_ARRAY_BUFFER, ballCount * (2 * 4), GL_DYNAMIC_DRAW);
- glVertexPointer(2, GL_FLOAT, 0, 0);
+ animVBO = new StreamVBO(GL_ARRAY_BUFFER, ballCount * (2 * 4));
}
public void render(final boolean render, final boolean animate, final int delta) {
int batchSize = Math.min(ballCount, BALLS_PER_BATCH);
int ballIndex = 0;
- int batchIndex = 0;
while ( ballIndex < ballCount ) {
if ( animate ) {
- final ByteBuffer buffer = glMapBufferRange(GL_ARRAY_BUFFER,
- ballIndex * (2 * 4),
- batchSize * (2 * 4),
- GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT,
- mapBuffer[batchIndex]);
- if ( buffer != mapBuffer[batchIndex] ) {
- mapBuffer[batchIndex] = buffer;
- geomBuffer[batchIndex] = mapBuffer[batchIndex].asFloatBuffer();
- }
+ final ByteBuffer buffer = animVBO.map(batchSize * (2 * 4));
- animate(geomBuffer[batchIndex], ballIndex, batchSize, delta);
+ animate(transform, buffer.asFloatBuffer(), ballSize, ballIndex, batchSize, delta);
- glUnmapBuffer(GL_ARRAY_BUFFER);
+ animVBO.unmap();
}
- if ( render )
- glDrawArrays(GL_POINTS, ballIndex, batchSize);
+ if ( render ) {
+ glVertexPointer(2, GL_FLOAT, 0, ballIndex * (2 * 4));
+ glDrawArrays(GL_POINTS, 0, batchSize);
+ }
- batchIndex++;
ballIndex += batchSize;
batchSize = Math.min(ballCount - ballIndex, BALLS_PER_BATCH);
}
@@ -653,6 +672,13 @@
}
public void updateBalls(final int count) {
+ if ( tfVBO[0] != 0 ) {
+ // Fetch current animation state
+ final FloatBuffer state = BufferUtils.createFloatBuffer(transform.length);
+ glGetBufferSubData(GL_TRANSFORM_FEEDBACK_BUFFER, 0, state);
+ state.get(transform);
+ }
+
super.updateBalls(count);
if ( tfVBO[0] != 0 ) {
@@ -660,14 +686,14 @@
glDeleteBuffers(tfVBO[i]);
}
- final FloatBuffer transform = BufferUtils.createFloatBuffer(count * 4);
- transform.put(this.transform);
- transform.flip();
+ final FloatBuffer state = BufferUtils.createFloatBuffer(count * 4);
+ state.put(transform);
+ state.flip();
for ( int i = 0; i < tfVBO.length; i++ ) {
tfVBO[i] = glGenBuffers();
glBindBuffer(GL_TRANSFORM_FEEDBACK_BUFFER, tfVBO[i]);
- glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, transform, GL_STATIC_DRAW);
+ glBufferData(GL_TRANSFORM_FEEDBACK_BUFFER, state, GL_STATIC_DRAW);
}
glBindBuffer(GL_ARRAY_BUFFER, tfVBO[0]);
Modified: trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/SpriteShootout2P.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/SpriteShootout2P.java 2011-07-14 23:11:41 UTC (rev 3588)
+++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/SpriteShootout2P.java 2011-07-16 16:05:37 UTC (rev 3589)
@@ -1,3 +1,34 @@
+/*
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.test.opengl.sprites;
import org.lwjgl.BufferUtils;
Modified: trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/SpriteShootoutCL.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/SpriteShootoutCL.java 2011-07-14 23:11:41 UTC (rev 3588)
+++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/SpriteShootoutCL.java 2011-07-16 16:05:37 UTC (rev 3589)
@@ -1,3 +1,34 @@
+/*
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.test.opengl.sprites;
import org.lwjgl.BufferUtils;
Added: trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/StreamVBO.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/StreamVBO.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/StreamVBO.java 2011-07-16 16:05:37 UTC (rev 3589)
@@ -0,0 +1,144 @@
+/*
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.test.opengl.sprites;
+
+import org.lwjgl.LWJGLUtil;
+
+import java.nio.ByteBuffer;
+
+import static java.lang.Math.*;
+import static org.lwjgl.opengl.GL15.*;
+import static org.lwjgl.opengl.GL30.*;
+
+/**
+ * This class implements VBO orphaning, useful for streaming
+ * dynamically generated geometry to the GPU. OpenGL 3.0 or
+ * higher is required. See
+ * {@url http://www.opengl.org/wiki/Buffer_Object_Streaming}
+ * under "Buffer update" for details.
+ *
+ * @author Spasi
+ */
+public class StreamVBO {
+
+ private final int target;
+ private final long size;
+ private final int padding;
+
+ private int ID;
+
+ private long cursor;
+
+ public StreamVBO(final int target, final int size) {
+ this(target, size, 64);
+ }
+
+ public StreamVBO(final int target, final int size, final int padding) {
+ this.target = target;
+ this.padding = padding;
+ this.size = max(pad(size), padding);
+
+ ID = glGenBuffers();
+
+ glBindBuffer(target, ID);
+ glBufferData(target, this.size, GL_STREAM_DRAW);
+ }
+
+ public int getTarget() {
+ return target;
+ }
+
+ public int getID() {
+ return ID;
+ }
+
+ public long getSize() {
+ return size;
+ }
+
+ public int getPadding() {
+ return padding;
+ }
+
+ public void bind() {
+ glBindBuffer(target, ID);
+ }
+
+ public void init(final int offset, final ByteBuffer data) {
+ glBufferSubData(target, offset, data);
+ }
+
+ public void unmap() {
+ glUnmapBuffer(target);
+ }
+
+ public void destroy() {
+ glBindBuffer(target, 0);
+ glDeleteBuffers(ID);
+ }
+
+ public void reset() {
+ // Orphan current buffer and allocate a new one
+ glBufferData(target, size, GL_STREAM_DRAW);
+ // Flush
+ cursor = 0;
+ }
+
+ public ByteBuffer map(final int bytes) {
+ return map(bytes, null);
+ }
+
+ public ByteBuffer map(final int bytes, final ByteBuffer old_buffer) {
+ return doMap(pad(bytes), old_buffer);
+ }
+
+ private int pad(int size) {
+ final int mod = size % padding;
+ if ( mod == 0 )
+ return size;
+
+ return size + padding - mod;
+ }
+
+ private ByteBuffer doMap(final int bytes, final ByteBuffer old_buffer) {
+ if ( LWJGLUtil.CHECKS && size < bytes )
+ throw new IllegalArgumentException(Integer.toString(bytes));
+
+ if ( size < cursor + bytes )
+ reset();
+
+ final ByteBuffer map = glMapBufferRange(target, cursor, bytes, GL_MAP_WRITE_BIT | GL_MAP_UNSYNCHRONIZED_BIT, old_buffer);
+ cursor += bytes;
+ return map;
+ }
+
+}
\ No newline at end of file
Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/JNITypeTranslator.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/generator/JNITypeTranslator.java 2011-07-14 23:11:41 UTC (rev 3588)
+++ trunk/LWJGL/src/java/org/lwjgl/util/generator/JNITypeTranslator.java 2011-07-16 16:05:37 UTC (rev 3589)
@@ -32,6 +32,10 @@
package org.lwjgl.util.generator;
+import org.lwjgl.PointerBuffer;
+
+import java.nio.Buffer;
+
import com.sun.mirror.type.*;
import com.sun.mirror.util.*;
@@ -45,12 +49,19 @@
* $Id$
*/
public class JNITypeTranslator implements TypeVisitor {
+
private final StringBuilder signature = new StringBuilder();
+ private boolean objectReturn;
+
public String getSignature() {
return signature.toString();
}
+ public String getReturnSignature() {
+ return objectReturn ? "jobject" : signature.toString();
+ }
+
public void visitAnnotationType(AnnotationType t) {
throw new RuntimeException(t + " is not allowed");
}
@@ -68,7 +79,12 @@
}
public void visitClassType(ClassType t) {
- signature.append("jobject");
+ final Class<?> type = Utils.getJavaType(t);
+ if ( Buffer.class.isAssignableFrom(type) || PointerBuffer.class.isAssignableFrom(type) ) {
+ signature.append("jlong");
+ objectReturn = true;
+ } else
+ signature.append("jobject");
}
public void visitDeclaredType(DeclaredType t) {
Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java 2011-07-14 23:11:41 UTC (rev 3588)
+++ trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java 2011-07-16 16:05:37 UTC (rev 3589)
@@ -194,8 +194,8 @@
writer.print("long ");
else {
Class type = type_info.getType();
- if ( native_stub && (type == CharSequence.class || type == CharSequence[].class || type == PointerBuffer.class) )
- writer.print("ByteBuffer ");
+ if ( native_stub && (type == CharSequence.class || type == CharSequence[].class || type == PointerBuffer.class || Buffer.class.isAssignableFrom(type) ) )
+ writer.print("long ");
else if ( printTypes )
writer.print(type_info.getType().getSimpleName() + " ");
}
@@ -203,8 +203,6 @@
if ( auto_size_annotation != null )
writer.print(auto_size_annotation.value() + "_");
writer.print(param.getSimpleName());
- if ( native_stub && buffer_type != null )
- writer.print(", int " + param.getSimpleName() + NativeMethodStubsGenerator.BUFFER_POSITION_POSTFIX);
}
return false;
}
@@ -490,7 +488,7 @@
Check check_annotation = param.getAnnotation(Check.class);
boolean hide_buffer = mode == Mode.AUTOS && getAutoTypeParameter(method, param) != null;
if (hide_buffer) {
- writer.print("null");
+ writer.print("0L");
} else {
if ( type == CharSequence.class || type == CharSequence[].class ) {
final String offset = Utils.getStringOffset(method, param);
@@ -502,48 +500,25 @@
if ( offset != null )
writer.print(", " + offset);
writer.print(")");
- hide_buffer = true;
} else {
final AutoSize auto_size_annotation = param.getAnnotation(AutoSize.class);
if ( auto_size_annotation != null )
writer.print(auto_size_annotation.value() + "_");
- writer.print(param.getSimpleName());
- if ( PointerBuffer.class.isAssignableFrom(type) ) {
+
+ final Class buffer_type = Utils.getNIOBufferType(param.getType());
+ if ( buffer_type == null )
+ writer.print(param.getSimpleName());
+ else {
+ writer.print("MemoryUtil.getAddress");
if ( check_annotation != null && check_annotation.canBeNull() )
- writer.print(" != null ? " + param.getSimpleName());
- writer.print(".getBuffer()");
- if ( check_annotation != null && check_annotation.canBeNull() )
- writer.print(" : null");
+ writer.print("Safe");
+ writer.print("(");
+ writer.print(param.getSimpleName());
+ writer.print(")");
}
}
}
- Class buffer_type = Utils.getNIOBufferType(param.getType());
- if (buffer_type != null) {
- writer.print(", ");
- if (!hide_buffer) {
- int shifting;
- if (Utils.getNIOBufferType(param.getType()).equals(Buffer.class)) {
- shifting = getBufferElementSizeExponent(type == Buffer.class ? ByteBuffer.class : type); // TODO: This will always throw an exception
- //shifting = 0;
- } else
- shifting = 0;
- writer.print(param.getSimpleName());
- if (check_annotation != null && check_annotation.canBeNull())
- writer.print(" != null ? " + param.getSimpleName());
- if ( type == PointerBuffer.class && param.getAnnotation(NativeType.class).value().endsWith("void") )
- writer.print(".positionByte()");
- else
- writer.print(".position()");
- if (shifting > 0)
- writer.print(" << " + shifting);
- if (check_annotation != null && check_annotation.canBeNull())
- writer.print(" : 0");
- } else if ( type == CharSequence.class || type == CharSequence[].class ) {
- final String offset = Utils.getStringOffset(method, param);
- writer.print(offset == null ? "0" : offset);
- } else
- writer.print("0");
- } else if ( type != long.class ) {
+ if ( type != long.class ) {
PointerWrapper pointer_annotation = param.getAnnotation(PointerWrapper.class);
if ( pointer_annotation != null ) {
if ( pointer_annotation.canBeNull() )
Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/NativeMethodStubsGenerator.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/generator/NativeMethodStubsGenerator.java 2011-07-14 23:11:41 UTC (rev 3588)
+++ trunk/LWJGL/src/java/org/lwjgl/util/generator/NativeMethodStubsGenerator.java 2011-07-16 16:05:37 UTC (rev 3589)
@@ -88,8 +88,6 @@
JNITypeTranslator translator = new JNITypeTranslator();
param.getType().accept(translator);
writer.print(translator.getSignature() + " " + param.getSimpleName());
- if (Utils.getNIOBufferType(param.getType()) != null)
- writer.print(", jint " + param.getSimpleName() + BUFFER_POSITION_POSTFIX);
}
}
@@ -108,7 +106,7 @@
} else {
JNITypeTranslator translator = new JNITypeTranslator();
result_type.accept(translator);
- writer.print(translator.getSignature());
+ writer.print(translator.getReturnSignature());
}
writer.print(" JNICALL ");
@@ -298,30 +296,17 @@
if ( !java_type.isArray() || CharSequence.class.isAssignableFrom(java_type.getComponentType()) ) {
writer.print("\t" + native_type + param.getSimpleName());
- writer.print(BUFFER_ADDRESS_POSTFIX + " = ((");
+ writer.print(BUFFER_ADDRESS_POSTFIX + " = (");
writer.print(native_type);
writer.print(")");
if (mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null) {
- writer.print("offsetToPointer(" + param.getSimpleNa...
[truncated message content] |
|
From: <sp...@us...> - 2011-07-14 23:11:47
|
Revision: 3588
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3588&view=rev
Author: spasi
Date: 2011-07-14 23:11:41 +0000 (Thu, 14 Jul 2011)
Log Message:
-----------
Fixed manual merge error.
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java 2011-07-14 16:54:25 UTC (rev 3587)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java 2011-07-14 23:11:41 UTC (rev 3588)
@@ -184,7 +184,7 @@
}
}
- return new MappedInstanceMethodAdapter(access, className, name, desc, super.visitMethod(access, name, desc, signature, exceptions));
+ return new MappedInstanceMethodAdapter(className, name, desc, super.visitMethod(access, name, desc, signature, exceptions));
}
@Override
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sp...@us...> - 2011-07-14 16:54:32
|
Revision: 3587
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3587&view=rev
Author: spasi
Date: 2011-07-14 16:54:25 +0000 (Thu, 14 Jul 2011)
Log Message:
-----------
Implemented .next() with bytecode transformation, 4x faster now.
Made method transformation a bit faster.
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java
Modified: trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java 2011-07-13 22:15:35 UTC (rev 3586)
+++ trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java 2011-07-14 16:54:25 UTC (rev 3587)
@@ -89,6 +89,15 @@
vecs.view = 0;
}
+ // manipulate 'view' with next()
+ {
+ assert (vecs.view == 0);
+ vecs.next();
+ assert (vecs.view == 1);
+ assert (vecs.value != 1.1f); // old view
+ vecs.view = 0;
+ }
+
// test bounds checking
{
assert (vecs.view == 0);
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java 2011-07-13 22:15:35 UTC (rev 3586)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java 2011-07-14 16:54:25 UTC (rev 3587)
@@ -87,6 +87,10 @@
return (int)(mapped.viewAddress - mapped.baseAddress) / sizeof;
}
+ public static void put_view_next(MappedObject mapped, int sizeof) {
+ mapped.setViewAddress(mapped.viewAddress + sizeof);
+ }
+
public static MappedObject dup(MappedObject src, MappedObject dst) {
dst.baseAddress = src.baseAddress;
dst.viewAddress = src.viewAddress;
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java 2011-07-13 22:15:35 UTC (rev 3586)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java 2011-07-14 16:54:25 UTC (rev 3587)
@@ -86,12 +86,7 @@
*/
public int view;
- /** Moves the current view to the next element. */
- public final void next() {
- setViewAddress(this.viewAddress + this.sizeof);
- }
-
- final void setViewAddress(final long address) {
+ public final void setViewAddress(final long address) {
if ( CHECKS )
checkAddress(address);
this.viewAddress = address;
@@ -99,8 +94,9 @@
final void checkAddress(final long address) {
final long base = MappedObjectUnsafe.getBufferBaseAddress(preventGC);
- if ( address < base || preventGC.capacity() < (address - base + this.sizeof) )
- throw new IndexOutOfBoundsException();
+ final int offset = (int)(address - base);
+ if ( address < base || preventGC.capacity() < (offset + this.sizeof) )
+ throw new IndexOutOfBoundsException(Integer.toString(offset / sizeof));
}
final void checkRange(final int bytes) {
@@ -186,6 +182,12 @@
throw new InternalError("type not registered");
}
+ /** Moves the current view to the next element. */
+ public final void next() {
+ // any method that calls this method will have its call-site modified
+ throw new InternalError("type not registered");
+ }
+
/**
* Copies and amount of <code>SIZEOF</code> bytes, from the current
* mapped object, to the specified mapped object.
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java 2011-07-13 22:15:35 UTC (rev 3586)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java 2011-07-14 16:54:25 UTC (rev 3587)
@@ -38,6 +38,9 @@
static final Map<String, MappedSubtypeInfo> className_to_subtype;
+ static final String MAPPED_OBJECT_JVM = jvmClassName(MappedObject.class);
+ static final String MAPPED_HELPER_JVM = jvmClassName(MappedHelper.class);
+
static {
className_to_subtype = new HashMap<String, MappedSubtypeInfo>();
@@ -56,7 +59,7 @@
// => IADD
// => PUTFIELD MyMappedType.view
//
- MappedSubtypeInfo info = new MappedSubtypeInfo(jvmClassName(MappedObject.class), -1, -1);
+ MappedSubtypeInfo info = new MappedSubtypeInfo(MAPPED_OBJECT_JVM, -1, -1);
className_to_subtype.put(info.className, info);
}
@@ -162,7 +165,7 @@
{
MappedSubtypeInfo mappedSubtype = className_to_subtype.get(className);
- if ( mappedSubtype != null && !mappedSubtype.className.equals(jvmClassName(MappedObject.class)) ) {
+ if ( mappedSubtype != null && !mappedSubtype.className.equals(MAPPED_OBJECT_JVM) ) {
if ( "<init>".equals(name) ) {
if ( !"()V".equals(desc) )
throw new IllegalStateException(className + " can only have a default constructor, found: " + desc);
@@ -170,7 +173,7 @@
MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
- mv.visitMethodInsn(INVOKESPECIAL, jvmClassName(MappedObject.class), "<init>", "()V");
+ mv.visitMethodInsn(INVOKESPECIAL, MAPPED_OBJECT_JVM, "<init>", "()V");
mv.visitInsn(RETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
@@ -181,7 +184,7 @@
}
}
- return new MappedInstanceMethodAdapter(className, name, desc, super.visitMethod(access, name, desc, signature, exceptions));
+ return new MappedInstanceMethodAdapter(access, className, name, desc, super.visitMethod(access, name, desc, signature, exceptions));
}
@Override
@@ -252,18 +255,26 @@
@Override
public void visitMethodInsn(int opcode, String className, String methodName, String signature) {
- if ( opcode == INVOKESPECIAL && className.equals(jvmClassName(MappedObject.class)) && "<init>".equals(methodName) && "()V".equals(signature) ) {
+ if ( opcode == INVOKESPECIAL && className.equals(MAPPED_OBJECT_JVM) && "<init>".equals(methodName) && "()V".equals(signature) ) {
// stack: instance
visitInsn(POP);
// stack: -
return;
}
- for ( MappedSubtypeInfo mappedType : className_to_subtype.values() ) {
- boolean isMapDirectMethod = (opcode == INVOKESTATIC && "map".equals(methodName) && className.equals(mappedType.className) && signature.equals("(JI)L" + jvmClassName(MappedObject.class) + ";"));
- boolean isMapBufferMethod = (opcode == INVOKESTATIC && "map".equals(methodName) && className.equals(mappedType.className) && signature.equals("(Ljava/nio/ByteBuffer;)L" + jvmClassName(MappedObject.class) + ";"));
- boolean isMallocMethod = (opcode == INVOKESTATIC && "malloc".equals(methodName) && className.equals(mappedType.className) && signature.equals("(I)L" + jvmClassName(MappedObject.class) + ";"));
+ MappedSubtypeInfo mappedType = className_to_subtype.get(className);
+ if ( mappedType != null && visitMappedMethod(opcode, className, methodName, signature, mappedType) )
+ return;
+ super.visitMethodInsn(opcode, className, methodName, signature);
+ }
+
+ private boolean visitMappedMethod(final int opcode, final String className, final String methodName, final String signature, final MappedSubtypeInfo mappedType) {
+ if ( opcode == INVOKESTATIC ) {
+ boolean isMapDirectMethod = "map".equals(methodName) && signature.equals("(JI)L" + MAPPED_OBJECT_JVM + ";");
+ boolean isMapBufferMethod = "map".equals(methodName) && signature.equals("(Ljava/nio/ByteBuffer;)L" + MAPPED_OBJECT_JVM + ";");
+ boolean isMallocMethod = "malloc".equals(methodName) && signature.equals("(I)L" + MAPPED_OBJECT_JVM + ";");
+
if ( (isMapDirectMethod || isMapBufferMethod) || isMallocMethod ) {
if ( isMallocMethod ) {
// stack: count
@@ -275,7 +286,7 @@
// stack: buffer
} else if ( isMapDirectMethod ) {
// stack: capacity, address
- super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "newBuffer", "(JI)L" + jvmClassName(ByteBuffer.class) + ";");
+ super.visitMethodInsn(INVOKESTATIC, MAPPED_HELPER_JVM, "newBuffer", "(JI)L" + jvmClassName(ByteBuffer.class) + ";");
// stack: buffer
}
@@ -294,12 +305,12 @@
// stack: int, buffer, new, new
pushInt(super.mv, mappedType.sizeof);
// stack: int, int, buffer, new, new
- super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "setup", "(L" + jvmClassName(MappedObject.class) + ";Ljava/nio/ByteBuffer;II)V");
+ super.visitMethodInsn(INVOKESTATIC, MAPPED_HELPER_JVM, "setup", "(L" + MAPPED_OBJECT_JVM + ";Ljava/nio/ByteBuffer;II)V");
// stack: new
- return;
+ return true;
}
-
- if ( opcode == INVOKEVIRTUAL && "dup".equals(methodName) && className.equals(mappedType.className) && signature.equals("()L" + jvmClassName(MappedObject.class) + ";") ) {
+ } else if ( opcode == INVOKEVIRTUAL ) {
+ if ( "dup".equals(methodName) && signature.equals("()L" + MAPPED_OBJECT_JVM + ";") ) {
// stack: this
super.visitTypeInsn(NEW, className);
// stack: new, this
@@ -307,12 +318,12 @@
// stack: new, new, this
super.visitMethodInsn(INVOKESPECIAL, className, "<init>", "()V");
// stack: new, this
- super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "dup", "(L" + jvmClassName(MappedObject.class) + ";L" + jvmClassName(MappedObject.class) + ";)L" + jvmClassName(MappedObject.class) + ";");
+ super.visitMethodInsn(INVOKESTATIC, MAPPED_HELPER_JVM, "dup", "(L" + MAPPED_OBJECT_JVM + ";L" + MAPPED_OBJECT_JVM + ";)L" + MAPPED_OBJECT_JVM + ";");
// stack: new
- return;
+ return true;
}
- if ( opcode == INVOKEVIRTUAL && "slice".equals(methodName) && className.equals(mappedType.className) && signature.equals("()L" + jvmClassName(MappedObject.class) + ";") ) {
+ if ( "slice".equals(methodName) && signature.equals("()L" + MAPPED_OBJECT_JVM + ";") ) {
// stack: this
super.visitTypeInsn(NEW, className);
// stack: new, this
@@ -320,46 +331,55 @@
// stack: new, new, this
super.visitMethodInsn(INVOKESPECIAL, className, "<init>", "()V");
// stack: new, this
- super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "slice", "(L" + jvmClassName(MappedObject.class) + ";L" + jvmClassName(MappedObject.class) + ";)L" + jvmClassName(MappedObject.class) + ";");
+ super.visitMethodInsn(INVOKESTATIC, MAPPED_HELPER_JVM, "slice", "(L" + MAPPED_OBJECT_JVM + ";L" + MAPPED_OBJECT_JVM + ";)L" + MAPPED_OBJECT_JVM + ";");
// stack: new
- return;
+ return true;
}
//
- if ( opcode == INVOKEVIRTUAL && "runViewConstructor".equals(methodName) && className.equals(mappedType.className) && "()V".equals(signature) ) {
+ if ( "runViewConstructor".equals(methodName) && "()V".equals(signature) ) {
// stack: this
super.visitInsn(DUP);
// stack: this, this
super.visitMethodInsn(INVOKEVIRTUAL, className, view_constructor_method, "()V");
// stack: this
- return;
+ return true;
}
//
- if ( opcode == INVOKEVIRTUAL && "copyTo".equals(methodName) && className.equals(mappedType.className) && signature.equals("(L" + jvmClassName(MappedObject.class) + ";)V") ) {
+ if ( "copyTo".equals(methodName) && signature.equals("(L" + MAPPED_OBJECT_JVM + ";)V") ) {
// stack: target, this
pushInt(super.mv, mappedType.sizeof);
// stack: sizeof, target, this
- super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "copy", "(L" + jvmClassName(MappedObject.class) + ";L" + jvmClassName(MappedObject.class) + ";I)V");
+ super.visitMethodInsn(INVOKESTATIC, MAPPED_HELPER_JVM, "copy", "(L" + MAPPED_OBJECT_JVM + ";L" + MAPPED_OBJECT_JVM + ";I)V");
// stack: -
- return;
+ return true;
}
- if ( opcode == INVOKEVIRTUAL && "copyRange".equals(methodName) && className.equals(mappedType.className) && signature.equals("(L" + jvmClassName(MappedObject.class) + ";I)V") ) {
+ if ( "copyRange".equals(methodName) && signature.equals("(L" + MAPPED_OBJECT_JVM + ";I)V") ) {
// stack: instances, target, this
pushInt(super.mv, mappedType.sizeof);
// stack: sizeof, instances, target, this
super.visitInsn(IMUL);
// stack: bytes, target, this
- super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "copy", "(L" + jvmClassName(MappedObject.class) + ";L" + jvmClassName(MappedObject.class) + ";I)V");
+ super.visitMethodInsn(INVOKESTATIC, MAPPED_HELPER_JVM, "copy", "(L" + MAPPED_OBJECT_JVM + ";L" + MAPPED_OBJECT_JVM + ";I)V");
// stack: -
- return;
+ return true;
}
+
+ if ( "next".equals(methodName) && "()V".equals(signature) ) {
+ // stack: this
+ pushInt(super.mv, mappedType.sizeof);
+ // stack: sizeof, this
+ super.visitMethodInsn(INVOKESTATIC, MAPPED_HELPER_JVM, "put_view_next", "(L" + MAPPED_OBJECT_JVM + ";I)V");
+ // stack: -
+ return true;
+ }
}
- super.visitMethodInsn(opcode, className, methodName, signature);
+ return false;
}
private static void throwAccessErrorOnReadOnlyField(String className, String fieldName) {
@@ -384,11 +404,11 @@
if ( false )
break outer;
else if ( className.equals(jvmClassName(MappedSet2.class)) )
- super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "put_views", "(L" + jvmClassName(MappedSet2.class) + ";I)V");
+ super.visitMethodInsn(INVOKESTATIC, MAPPED_HELPER_JVM, "put_views", "(L" + jvmClassName(MappedSet2.class) + ";I)V");
else if ( className.equals(jvmClassName(MappedSet3.class)) )
- super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "put_views", "(L" + jvmClassName(MappedSet3.class) + ";I)V");
+ super.visitMethodInsn(INVOKESTATIC, MAPPED_HELPER_JVM, "put_views", "(L" + jvmClassName(MappedSet3.class) + ";I)V");
else if ( className.equals(jvmClassName(MappedSet4.class)) )
- super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "put_views", "(L" + jvmClassName(MappedSet4.class) + ";I)V");
+ super.visitMethodInsn(INVOKESTATIC, MAPPED_HELPER_JVM, "put_views", "(L" + jvmClassName(MappedSet4.class) + ";I)V");
else
break outer;
// stack: -
@@ -421,7 +441,7 @@
// stack: instance
pushInt(super.mv, mappedSubtype.sizeof);
// stack: sizeof, instance
- super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "get_view", "(L" + jvmClassName(MappedObject.class) + ";I)I");
+ super.visitMethodInsn(INVOKESTATIC, MAPPED_HELPER_JVM, "get_view", "(L" + MAPPED_OBJECT_JVM + ";I)I");
// stack: view
return;
}
@@ -429,7 +449,7 @@
// stack: view, instance
pushInt(super.mv, mappedSubtype.sizeof);
// stack: sizeof, view, instance
- super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "put_view", "(L" + jvmClassName(MappedObject.class) + ";II)V");
+ super.visitMethodInsn(INVOKESTATIC, MAPPED_HELPER_JVM, "put_view", "(L" + MAPPED_OBJECT_JVM + ";II)V");
// stack: -
return;
}
@@ -494,7 +514,7 @@
// stack: long, long
super.visitInsn(L2I);
// stack: int, long
- super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "newBuffer", "(JI)L" + jvmClassName(ByteBuffer.class) + ";");
+ super.visitMethodInsn(INVOKESTATIC, MAPPED_HELPER_JVM, "newBuffer", "(JI)L" + jvmClassName(ByteBuffer.class) + ";");
// stack: buffer
return;
}
@@ -512,7 +532,7 @@
// stack: offset, viewAddr, value
super.visitInsn(LADD);
// stack: fieldAddr, value
- super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), typeName.toLowerCase() + "put", "(" + typeName + "J)V");
+ super.visitMethodInsn(INVOKESTATIC, MAPPED_HELPER_JVM, typeName.toLowerCase() + "put", "(" + typeName + "J)V");
// stack -
return;
@@ -525,7 +545,7 @@
// stack: fieldOffset, viewAddr
super.visitInsn(LADD);
// stack: fieldAddr
- super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), typeName.toLowerCase() + "get", "(J)" + typeName);
+ super.visitMethodInsn(INVOKESTATIC, MAPPED_HELPER_JVM, typeName.toLowerCase() + "get", "(J)" + typeName);
// stack: value
return;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2011-07-13 22:15:41
|
Revision: 3586
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3586&view=rev
Author: kappa1
Date: 2011-07-13 22:15:35 +0000 (Wed, 13 Jul 2011)
Log Message:
-----------
Implement Resizing Display API for OS X
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java
trunk/LWJGL/src/java/org/lwjgl/opengl/DisplayImplementation.java
trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java
trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXCanvasListener.java
trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java
trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXFrame.java
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2011-07-13 22:15:25 UTC (rev 3585)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2011-07-13 22:15:35 UTC (rev 3586)
@@ -93,6 +93,12 @@
* unlike GL, where it is typically at the bottom of the display.
*/
private static int y = -1;
+
+ /** the width of the Display window */
+ private static int width = 0;
+
+ /** the height of the Display window */
+ private static int height = 0;
/** Title of the window (never null) */
private static String title = "Game";
@@ -109,6 +115,10 @@
private static boolean window_created;
private static boolean parent_resized;
+
+ private static boolean window_resized;
+
+ private static boolean window_resizable;
/** Initial Background Color of Display */
private static float r, g, b;
@@ -295,6 +305,9 @@
DisplayMode mode = getEffectiveMode();
display_impl.createWindow(drawable, mode, tmp_parent, getWindowX(), getWindowY());
window_created = true;
+
+ width = Display.getDisplayMode().getWidth();
+ height = Display.getDisplayMode().getHeight();
setTitle(title);
initControls();
@@ -661,6 +674,13 @@
throw new RuntimeException(e);
}
}
+
+ window_resized = !isFullscreen() && parent == null && display_impl.wasResized();
+
+ if ( window_resized ) {
+ width = display_impl.getWidth();
+ height = display_impl.getHeight();
+ }
if ( parent_resized ) {
reshape();
@@ -1257,14 +1277,17 @@
* false to disable resizing on the Display window.
*/
public static void setResizable(boolean resizable) {
-
+ window_resizable = resizable;
+ if ( isCreated() ) {
+ display_impl.setResizable(resizable);
+ }
}
/**
* @return true if the Display window is resizable.
*/
public static boolean isResizable() {
- return false;
+ return window_resizable;
}
/**
@@ -1274,7 +1297,7 @@
* This will return false if running in fullscreen or with Display.setParent(Canvas parent)
*/
public static boolean wasResized() {
- return false;
+ return window_resized;
}
/**
@@ -1287,7 +1310,16 @@
* This value will be updated after a call to Display.update().
*/
public static int getWidth() {
- return 0;
+
+ if (Display.isFullscreen()) {
+ return Display.getDisplayMode().getWidth();
+ }
+
+ if (parent != null) {
+ return parent.getWidth();
+ }
+
+ return width;
}
/**
@@ -1300,6 +1332,15 @@
* This value will be updated after a call to Display.update().
*/
public static int getHeight() {
- return 0;
+
+ if (Display.isFullscreen()) {
+ return Display.getDisplayMode().getHeight();
+ }
+
+ if (parent != null) {
+ return parent.getHeight();
+ }
+
+ return height;
}
}
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/DisplayImplementation.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/DisplayImplementation.java 2011-07-13 22:15:25 UTC (rev 3585)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/DisplayImplementation.java 2011-07-13 22:15:35 UTC (rev 3586)
@@ -169,13 +169,8 @@
void setResizable(boolean resizable);
/**
- * @return true if the Display window is resizable.
+ * @return true if the Display window has been resized since this method was last called.
*/
- boolean isResizable();
-
- /**
- * @return true if the Display window has been resized.
- */
boolean wasResized();
/**
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2011-07-13 22:15:25 UTC (rev 3585)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2011-07-13 22:15:35 UTC (rev 3586)
@@ -1361,10 +1361,6 @@
}
- public boolean isResizable() {
- return false;
- }
-
public boolean wasResized() {
return false;
}
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXCanvasListener.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXCanvasListener.java 2011-07-13 22:15:25 UTC (rev 3585)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXCanvasListener.java 2011-07-13 22:15:35 UTC (rev 3586)
@@ -47,6 +47,7 @@
private int width;
private int height;
private boolean context_update;
+ private boolean resized;
MacOSXCanvasListener(Canvas canvas) {
this.canvas = canvas;
@@ -102,6 +103,7 @@
public void componentResized(ComponentEvent e) {
setUpdate();
+ resized = true;
}
public void componentMoved(ComponentEvent e) {
@@ -111,4 +113,13 @@
public void hierarchyChanged(HierarchyEvent e) {
setUpdate();
}
+
+ public boolean wasResized() {
+ if (resized) {
+ resized = false;
+ return true;
+ }
+
+ return false;
+ }
}
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java 2011-07-13 22:15:25 UTC (rev 3585)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java 2011-07-13 22:15:35 UTC (rev 3586)
@@ -497,11 +497,11 @@
}
public int getWidth() {
- return Display.getDisplayMode().getWidth();
+ return frame.getWidth();
}
public int getHeight() {
- return Display.getDisplayMode().getHeight();
+ return frame.getHeight();
}
public boolean isInsideWindow() {
@@ -509,15 +509,11 @@
}
public void setResizable(boolean resizable) {
-
+ frame.setResizable(resizable);
}
- public boolean isResizable() {
- return false;
- }
-
public boolean wasResized() {
- return false;
+ return canvas_listener.wasResized();
}
}
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXFrame.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXFrame.java 2011-07-13 22:15:25 UTC (rev 3585)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXFrame.java 2011-07-13 22:15:35 UTC (rev 3586)
@@ -68,7 +68,7 @@
private boolean should_release_cursor;
MacOSXFrame(DisplayMode mode, final java.awt.DisplayMode requested_mode, boolean fullscreen, int x, int y) throws LWJGLException {
- setResizable(false);
+ setResizable(Display.isResizable());
addWindowListener(this);
addComponentListener(this);
canvas = new MacOSXGLCanvas();
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java 2011-07-13 22:15:25 UTC (rev 3585)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java 2011-07-13 22:15:35 UTC (rev 3586)
@@ -945,10 +945,6 @@
}
- public boolean isResizable() {
- return false;
- }
-
public boolean wasResized() {
return false;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sp...@us...> - 2011-07-13 22:15:32
|
Revision: 3585
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3585&view=rev
Author: spasi
Date: 2011-07-13 22:15:25 +0000 (Wed, 13 Jul 2011)
Log Message:
-----------
Removed stride and .configure. Mapped object view updates are now 50% faster. [Riven]
org.lwjgl.util.mapped.PrintBytecode is now functional. [Riven]
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java
trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests2.java
trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectWithLibrary.java
trunk/LWJGL/src/java/org/lwjgl/test/mapped/TestMappedObject.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedForeach.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet2.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet3.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet4.java
Modified: trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java 2011-07-13 19:29:15 UTC (rev 3584)
+++ trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java 2011-07-13 22:15:25 UTC (rev 3585)
@@ -59,8 +59,8 @@
{
MappedFloat vecs1 = MappedFloat.malloc(1234);
- assert (vecs1.stride == MappedFloat.SIZEOF);
- assert (vecs1.stride * 1234 == vecs1.backingByteBuffer().capacity());
+ assert (vecs1.sizeof == MappedFloat.SIZEOF);
+ assert (vecs1.sizeof * 1234 == vecs1.backingByteBuffer().capacity());
assert (MappedFloat.SIZEOF * 1234 == vecs1.backingByteBuffer().capacity());
}
@@ -132,31 +132,6 @@
}
}
- // test dup
- {
- int newStride = 16;
- int doOffset = 0;
-
- vecs.view = 0;
- MappedFloat.configure(vecs, newStride, doOffset);
- MappedFloat dec2 = vecs.dup();
- MappedFloat.configure(dec2, newStride, doOffset);
-
- String s1 = vecs.baseAddress + "," + vecs.viewAddress + "," + vecs.stride + "," + vecs.SIZEOF;
- String s2 = dec2.baseAddress + "," + dec2.viewAddress + "," + dec2.stride + "," + dec2.SIZEOF;
- // System.out.println(s1);
- // System.out.println(s2);
- assert (s1.equals(s2));
-
- dec2.view++;
-
- String s3 = vecs.baseAddress + "," + vecs.viewAddress + "," + vecs.stride + "," + vecs.SIZEOF;
- String s4 = dec2.baseAddress + "," + dec2.viewAddress + "," + dec2.stride + "," + dec2.SIZEOF;
- // System.out.println(s3);
- // System.out.println(s4);
- assert (!s3.equals(s4));
- }
-
// test newBuffer
{
long addr1 = MappedObjectUnsafe.getBufferBaseAddress(bb);
Modified: trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests2.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests2.java 2011-07-13 19:29:15 UTC (rev 3584)
+++ trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests2.java 2011-07-13 22:15:25 UTC (rev 3585)
@@ -91,40 +91,8 @@
vecs.view = 1;
long a2 = vecs.viewAddress;
assert (a2 - a1 == MappedVec3.SIZEOF);
- assert (a2 - a1 == vecs.stride);
+ assert (a2 - a1 == vecs.sizeof);
vecs.view = 0;
}
-
- int newStride = 16;
-
- MappedVec3.configure(vecs, newStride, +4);
- assert (vecs.z == 0.1234f); // vecs[1].x ended up in vecs[0].z due to 1float offset
-
- MappedVec3.configure(vecs, newStride, +8);
- assert (vecs.z == 0.0000f); // vecs[1].z ended up in vecs[0].z due to 2float offset
-
- // test new stride
- {
- long a1 = vecs.viewAddress;
- vecs.view = 1;
- long a2 = vecs.viewAddress;
- assert (a2 - a1 == newStride);
- vecs.view = 0;
- }
-
- // example: GPU => VBO => VTN
- {
- MappedVec3 v = MappedVec3.map(bb);
- MappedVec2 t = MappedVec2.map(bb);
- MappedVec3 n = MappedVec3.map(bb);
-
- int stride = MappedVec3.SIZEOF + MappedVec2.SIZEOF + MappedVec3.SIZEOF;
- assert (stride == 32);
-
- MappedVec3.configure(v, stride, 0);
- MappedVec2.configure(t, stride, MappedVec3.SIZEOF);
- MappedVec3.configure(n, stride, MappedVec3.SIZEOF + MappedVec2.SIZEOF);
- }
}
-
}
\ No newline at end of file
Modified: trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectWithLibrary.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectWithLibrary.java 2011-07-13 19:29:15 UTC (rev 3584)
+++ trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectWithLibrary.java 2011-07-13 22:15:25 UTC (rev 3585)
@@ -4,15 +4,14 @@
package org.lwjgl.test.mapped;
+import org.lwjgl.opengl.Display;
+
import java.io.File;
-import org.lwjgl.opengl.Display;
+public class MappedObjectWithLibrary {
-public class MappedObjectWithLibrary
-{
- public static void testLWJGL() throws Exception
- {
- System.out.println(new File(System.getProperty("java.library.path")).getCanonicalPath());
- Display.create();
- }
+ public static void testLWJGL() throws Exception {
+ System.out.println(new File(System.getProperty("java.library.path")).getCanonicalPath());
+ Display.create();
+ }
}
Modified: trunk/LWJGL/src/java/org/lwjgl/test/mapped/TestMappedObject.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/mapped/TestMappedObject.java 2011-07-13 19:29:15 UTC (rev 3584)
+++ trunk/LWJGL/src/java/org/lwjgl/test/mapped/TestMappedObject.java 2011-07-13 22:15:25 UTC (rev 3585)
@@ -35,6 +35,7 @@
import org.lwjgl.util.mapped.MappedObjectTransformer;
/** @author Riven */
+@SuppressWarnings("static-access")
public class TestMappedObject {
static {
@@ -49,7 +50,6 @@
MappedObjectTransformer.register(MappedVec2.class);
MappedObjectTransformer.register(MappedVec3.class);
MappedObjectTransformer.register(MappedSomething.class);
-
MappedObjectTransformer.register(MappedObjectTests3.Xyz.class);
if ( MappedObjectClassLoader.fork(TestMappedObject.class, args) ) {
@@ -70,8 +70,8 @@
MappedObjectTests3.testForeach();
MappedObjectTests3.testConstructor();
MappedObjectTests3.testMappedSet();
-
- MappedObjectWithLibrary.testLWJGL();
+
+ System.out.println("done");
}
}
\ No newline at end of file
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedForeach.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedForeach.java 2011-07-13 19:29:15 UTC (rev 3584)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedForeach.java 2011-07-13 22:15:25 UTC (rev 3585)
@@ -58,7 +58,7 @@
}
public T next() {
- MappedHelper.put_view(mapped, this.index++);
+ MappedHelper.put_view(mapped, this.index++, mapped.sizeof);
return mapped;
}
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java 2011-07-13 19:29:15 UTC (rev 3584)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java 2011-07-13 22:15:25 UTC (rev 3585)
@@ -58,7 +58,7 @@
if ( sizeof % align != 0 )
throw new IllegalStateException("sizeof not a multiple of alignment");
- mo.stride = sizeof;
+ mo.sizeof = sizeof;
long addr = MappedObjectUnsafe.getBufferBaseAddress(buffer) + buffer.position();
if ( addr % align != 0 )
@@ -79,19 +79,19 @@
set.view(view);
}
- public static void put_view(MappedObject mapped, int view) {
- mapped.setViewAddress(mapped.baseAddress + view * mapped.stride);
+ public static void put_view(MappedObject mapped, int view, int sizeof) {
+ mapped.setViewAddress(mapped.baseAddress + view * sizeof);
}
- public static int get_view(MappedObject mapped) {
- return (int)(mapped.viewAddress - mapped.baseAddress) / mapped.stride;
+ public static int get_view(MappedObject mapped, int sizeof) {
+ return (int)(mapped.viewAddress - mapped.baseAddress) / sizeof;
}
public static MappedObject dup(MappedObject src, MappedObject dst) {
dst.baseAddress = src.baseAddress;
dst.viewAddress = src.viewAddress;
- dst.stride = src.stride;
dst.align = src.align;
+ dst.sizeof = src.sizeof;
dst.preventGC = src.preventGC;
return dst;
}
@@ -99,8 +99,8 @@
public static MappedObject slice(MappedObject src, MappedObject dst) {
dst.baseAddress = src.viewAddress; // !
dst.viewAddress = src.viewAddress;
- dst.stride = src.stride;
dst.align = src.align;
+ dst.sizeof = src.sizeof;
dst.preventGC = src.preventGC;
return dst;
}
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java 2011-07-13 19:29:15 UTC (rev 3584)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java 2011-07-13 22:15:25 UTC (rev 3585)
@@ -63,12 +63,12 @@
/** The mapped object view memory address, in bytes. Read-only. */
public long viewAddress;
- /** The mapped object stride, in bytes. Read-only. */
- public int stride;
-
/** The mapped object memory alignment, in bytes. Read-only. */
public int align;
+ /** The mapped object memory sizeof, in bytes. Read-only. */
+ public int sizeof;
+
/**
* Holds the value of sizeof of the sub-type of this MappedObject<br>
* <br>
@@ -88,7 +88,7 @@
/** Moves the current view to the next element. */
public final void next() {
- setViewAddress(this.viewAddress + this.stride);
+ setViewAddress(this.viewAddress + this.sizeof);
}
final void setViewAddress(final long address) {
@@ -99,7 +99,7 @@
final void checkAddress(final long address) {
final long base = MappedObjectUnsafe.getBufferBaseAddress(preventGC);
- if ( address < base || preventGC.capacity() < (address - base + stride) )
+ if ( address < base || preventGC.capacity() < (address - base + this.sizeof) )
throw new IndexOutOfBoundsException();
}
@@ -218,32 +218,6 @@
return new MappedForeach<T>(mapped, elementCount);
}
- /**
- * Configures a newly initiated mapped object with the specified stride and offset.
- *
- * @throws IllegalStateException if view is not at index 0
- */
- public static <T extends MappedObject> T configure(T mapped, int stride, int offset) {
- if ( mapped.baseAddress != mapped.viewAddress )
- throw new IllegalStateException("view must be zero");
-
- if ( offset < 0 )
- throw new IllegalStateException("offset must not be negative: " + offset);
- if ( offset % mapped.align != 0 )
- throw new IllegalStateException("offset not a multiple of alignment: " + offset);
-
- if ( stride < mapped.stride )
- throw new IllegalStateException("new stride must not be smaller than current stride: " + stride);
- if ( stride % mapped.align != 0 )
- throw new IllegalStateException("stride not a multiple of alignment: " + stride);
-
- mapped.baseAddress += offset;
- mapped.viewAddress += offset;
- mapped.stride = stride;
-
- return mapped;
- }
-
ByteBuffer preventGC;
/**
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java 2011-07-13 19:29:15 UTC (rev 3584)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java 2011-07-13 22:15:25 UTC (rev 3585)
@@ -34,7 +34,7 @@
static final boolean PRINT_TIMING = LWJGLUtil.DEBUG && LWJGLUtil.getPrivilegedBoolean("org.lwjgl.util.mapped.PrintTiming");
static final boolean PRINT_ACTIVITY = LWJGLUtil.DEBUG && LWJGLUtil.getPrivilegedBoolean("org.lwjgl.util.mapped.PrintActivity");
- static final boolean PRINT_BYTECODE = false; //LWJGLUtil.DEBUG && LWJGLUtil.getPrivilegedBoolean("org.lwjgl.util.mapped.PrintBytecode");
+ static final boolean PRINT_BYTECODE = LWJGLUtil.DEBUG && LWJGLUtil.getPrivilegedBoolean("org.lwjgl.util.mapped.PrintBytecode");
static final Map<String, MappedSubtypeInfo> className_to_subtype;
@@ -372,6 +372,7 @@
if ( mappedSubtype == null ) {
String mappedSetPrefix = jvmClassName(MappedSet.class);
+ // MappedSet.view
outer:
if ( "view".equals(fieldName) && className.startsWith(mappedSetPrefix) ) {
if ( opcode == GETFIELD )
@@ -418,17 +419,23 @@
if ( opcode == GETFIELD ) {
// stack: instance
- super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "get_view", "(L" + jvmClassName(MappedObject.class) + ";)I");
+ pushInt(super.mv, mappedSubtype.sizeof);
+ // stack: sizeof, instance
+ super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "get_view", "(L" + jvmClassName(MappedObject.class) + ";I)I");
+ // stack: view
return;
}
if ( opcode == PUTFIELD ) {
- // stack: int, instance
- super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "put_view", "(L" + jvmClassName(MappedObject.class) + ";I)V");
+ // stack: view, instance
+ pushInt(super.mv, mappedSubtype.sizeof);
+ // stack: sizeof, view, instance
+ super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "put_view", "(L" + jvmClassName(MappedObject.class) + ";II)V");
+ // stack: -
return;
}
}
- if ( "align".equals(fieldName) ) {
+ if ( "align".equals(fieldName) || "sizeof".equals(fieldName) ) {
if ( !"I".equals(typeName) )
throw new IllegalStateException();
@@ -436,7 +443,10 @@
// stack: instance
super.visitInsn(POP);
// stack: -
- pushInt(super.mv, mappedSubtype.align);
+ if ( "sizeof".equals(fieldName) )
+ pushInt(super.mv, mappedSubtype.sizeof);
+ else if ( "align".equals(fieldName) )
+ pushInt(super.mv, mappedSubtype.align);
// stack: int
return;
}
@@ -445,18 +455,6 @@
}
}
- if ( "stride".equals(fieldName) ) {
- if ( !"I".equals(typeName) )
- throw new IllegalStateException();
-
- if ( opcode == GETFIELD ) {
- // do not change a thing
- }
- if ( opcode == PUTFIELD ) {
- throwAccessErrorOnReadOnlyField(className, fieldName);
- }
- }
-
if ( "baseAddress".equals(fieldName) || "viewAddress".equals(fieldName) ) {
if ( !"J".equals(typeName) )
throw new IllegalStateException();
@@ -476,6 +474,8 @@
return;
}
+ // now we're going to transform ByteBuffer-typed field access
+
if ( typeName.equals("L" + jvmClassName(ByteBuffer.class) + ";") ) {
if ( opcode == PUTFIELD ) {
throwAccessErrorOnReadOnlyField(className, fieldName);
@@ -500,30 +500,34 @@
}
}
+ // we're now going to transform the field access
+
if ( opcode == PUTFIELD ) {
// stack: value, ref
super.visitInsn(SWAP);
// stack: ref, value
super.visitFieldInsn(GETFIELD, mappedSubtype.className, "viewAddress", "J");
- // stack: long, value
+ // stack: viewAddr, value
super.visitLdcInsn(fieldOffset);
- // stack: long, long, value
+ // stack: offset, viewAddr, value
super.visitInsn(LADD);
- // stack: long, value
+ // stack: fieldAddr, value
super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), typeName.toLowerCase() + "put", "(" + typeName + "J)V");
// stack -
+
return;
}
if ( opcode == GETFIELD ) {
// stack: ref
super.visitFieldInsn(GETFIELD, mappedSubtype.className, "viewAddress", "J");
- // stack: long
+ // stack: viewAddr
super.visitLdcInsn(fieldOffset);
- // stack: long, long
+ // stack: fieldOffset, viewAddr
super.visitInsn(LADD);
- // stack: long
+ // stack: fieldAddr
super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), typeName.toLowerCase() + "get", "(J)" + typeName);
// stack: value
+
return;
}
@@ -553,7 +557,7 @@
else if ( value >= Short.MIN_VALUE && value <= Short.MAX_VALUE )
mv.visitIntInsn(SIPUSH, value);
else
- mv.visitLdcInsn(Integer.valueOf(value));
+ mv.visitLdcInsn(value);
}
static String jvmClassName(Class<?> type) {
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet2.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet2.java 2011-07-13 19:29:15 UTC (rev 3584)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet2.java 2011-07-13 22:15:25 UTC (rev 3585)
@@ -44,8 +44,8 @@
public int view;
void view(int view) {
- MappedHelper.put_view(this.a, view);
- MappedHelper.put_view(this.b, view);
+ MappedHelper.put_view(this.a, view, this.a.sizeof);
+ MappedHelper.put_view(this.b, view, this.b.sizeof);
}
public void next() {
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet3.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet3.java 2011-07-13 19:29:15 UTC (rev 3584)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet3.java 2011-07-13 22:15:25 UTC (rev 3585)
@@ -45,9 +45,9 @@
public int view;
void view(int view) {
- MappedHelper.put_view(this.a, view);
- MappedHelper.put_view(this.b, view);
- MappedHelper.put_view(this.c, view);
+ MappedHelper.put_view(this.a, view, this.a.sizeof);
+ MappedHelper.put_view(this.b, view, this.b.sizeof);
+ MappedHelper.put_view(this.c, view, this.c.sizeof);
}
public void next() {
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet4.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet4.java 2011-07-13 19:29:15 UTC (rev 3584)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet4.java 2011-07-13 22:15:25 UTC (rev 3585)
@@ -46,10 +46,10 @@
public int view;
void view(int view) {
- MappedHelper.put_view(this.a, view);
- MappedHelper.put_view(this.b, view);
- MappedHelper.put_view(this.c, view);
- MappedHelper.put_view(this.d, view);
+ MappedHelper.put_view(this.a, view, this.a.sizeof);
+ MappedHelper.put_view(this.b, view, this.b.sizeof);
+ MappedHelper.put_view(this.c, view, this.c.sizeof);
+ MappedHelper.put_view(this.d, view, this.d.sizeof);
}
public void next() {
@@ -58,5 +58,4 @@
this.c.next();
this.d.next();
}
-
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2011-07-13 19:29:21
|
Revision: 3584
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3584&view=rev
Author: kappa1
Date: 2011-07-13 19:29:15 +0000 (Wed, 13 Jul 2011)
Log Message:
-----------
Updated JavaDoc for the new resizing api to clarify behaviour when running in fullscreen or with Display.setParent().
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2011-07-13 12:44:25 UTC (rev 3583)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2011-07-13 19:29:15 UTC (rev 3584)
@@ -1270,6 +1270,8 @@
/**
* @return true if the Display window has been resized.
* This value will be updated after a call to Display.update().
+ *
+ * This will return false if running in fullscreen or with Display.setParent(Canvas parent)
*/
public static boolean wasResized() {
return false;
@@ -1278,6 +1280,10 @@
/**
* @return this method will return the width of the Display window.
*
+ * If running in fullscreen mode it will return the width of the current set DisplayMode.
+ * If running Display.setParent(Canvas parent) is being used, the width of the parent
+ * will be returned.
+ *
* This value will be updated after a call to Display.update().
*/
public static int getWidth() {
@@ -1286,6 +1292,10 @@
/**
* @return this method will return the height of the Display window.
+ *
+ * If running in fullscreen mode it will return the height of the current set DisplayMode.
+ * If running Display.setParent(Canvas parent) is being used, the height of the parent
+ * will be returned.
*
* This value will be updated after a call to Display.update().
*/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sp...@us...> - 2011-07-13 12:44:31
|
Revision: 3583
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3583&view=rev
Author: spasi
Date: 2011-07-13 12:44:25 +0000 (Wed, 13 Jul 2011)
Log Message:
-----------
Made MappedForeach package private (foreach returns Iterable now) and changed next() to go through the bounds check.
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedForeach.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedForeach.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedForeach.java 2011-07-12 22:07:32 UTC (rev 3582)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedForeach.java 2011-07-13 12:44:25 UTC (rev 3583)
@@ -38,7 +38,7 @@
*
* @author Riven
*/
-public class MappedForeach<T extends MappedObject> implements Iterable<T> {
+final class MappedForeach<T extends MappedObject> implements Iterable<T> {
final T mapped;
final int elementCount;
@@ -58,8 +58,7 @@
}
public T next() {
- mapped.viewAddress = mapped.baseAddress + (this.index++) * mapped.stride;
-
+ MappedHelper.put_view(mapped, this.index++);
return mapped;
}
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java 2011-07-12 22:07:32 UTC (rev 3582)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java 2011-07-13 12:44:25 UTC (rev 3583)
@@ -214,7 +214,7 @@
* For convenience you are encouraged to static-import this specific method:
* <code>import static org.lwjgl.util.mapped.MappedObject.foreach;</code>
*/
- public static <T extends MappedObject> MappedForeach<T> foreach(T mapped, int elementCount) {
+ public static <T extends MappedObject> Iterable<T> foreach(T mapped, int elementCount) {
return new MappedForeach<T>(mapped, elementCount);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ka...@us...> - 2011-07-12 22:07:38
|
Revision: 3582
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3582&view=rev
Author: kappa1
Date: 2011-07-12 22:07:32 +0000 (Tue, 12 Jul 2011)
Log Message:
-----------
Add placeholder methods for initial resizing api for the Display
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java
trunk/LWJGL/src/java/org/lwjgl/opengl/DisplayImplementation.java
trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java
trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java
trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2011-07-12 21:30:48 UTC (rev 3581)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/Display.java 2011-07-12 22:07:32 UTC (rev 3582)
@@ -1249,4 +1249,47 @@
}
}
}
+
+ /**
+ * Enable or disable the Display window to be resized.
+ *
+ * @param set true to make the Display window resizable;
+ * false to disable resizing on the Display window.
+ */
+ public static void setResizable(boolean resizable) {
+
+ }
+
+ /**
+ * @return true if the Display window is resizable.
+ */
+ public static boolean isResizable() {
+ return false;
+ }
+
+ /**
+ * @return true if the Display window has been resized.
+ * This value will be updated after a call to Display.update().
+ */
+ public static boolean wasResized() {
+ return false;
+ }
+
+ /**
+ * @return this method will return the width of the Display window.
+ *
+ * This value will be updated after a call to Display.update().
+ */
+ public static int getWidth() {
+ return 0;
+ }
+
+ /**
+ * @return this method will return the height of the Display window.
+ *
+ * This value will be updated after a call to Display.update().
+ */
+ public static int getHeight() {
+ return 0;
+ }
}
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/DisplayImplementation.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/DisplayImplementation.java 2011-07-12 21:30:48 UTC (rev 3581)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/DisplayImplementation.java 2011-07-12 22:07:32 UTC (rev 3582)
@@ -159,4 +159,32 @@
* @return number of icons used.
*/
int setIcon(ByteBuffer[] icons);
+
+ /**
+ * Enable or disable the Display window to be resized.
+ *
+ * @param set true to make the Display window resizable;
+ * false to disable resizing on the Display window.
+ */
+ void setResizable(boolean resizable);
+
+ /**
+ * @return true if the Display window is resizable.
+ */
+ boolean isResizable();
+
+ /**
+ * @return true if the Display window has been resized.
+ */
+ boolean wasResized();
+
+ /**
+ * @return this method will return a the width of the Display window.
+ */
+ int getWidth();
+
+ /**
+ * @return this method will return a the height of the Display window.
+ */
+ int getHeight();
}
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2011-07-12 21:30:48 UTC (rev 3581)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2011-07-12 22:07:32 UTC (rev 3582)
@@ -1356,6 +1356,18 @@
public boolean isInsideWindow() {
return mouseInside;
}
+
+ public void setResizable(boolean resizable) {
+
+ }
+
+ public boolean isResizable() {
+ return false;
+ }
+
+ public boolean wasResized() {
+ return false;
+ }
/**
* Helper class for managing Compiz's workarounds. We need this to enable Legacy
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java 2011-07-12 21:30:48 UTC (rev 3581)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java 2011-07-12 22:07:32 UTC (rev 3582)
@@ -504,7 +504,20 @@
return Display.getDisplayMode().getHeight();
}
- public boolean isInsideWindow() {
- return true;
- }
+ public boolean isInsideWindow() {
+ return true;
+ }
+
+ public void setResizable(boolean resizable) {
+
+ }
+
+ public boolean isResizable() {
+ return false;
+ }
+
+ public boolean wasResized() {
+ return false;
+ }
+
}
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java 2011-07-12 21:30:48 UTC (rev 3581)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java 2011-07-12 22:07:32 UTC (rev 3582)
@@ -935,11 +935,23 @@
return -1;
}
- private native boolean nTrackMouseEvent(long hwnd);
+ private native boolean nTrackMouseEvent(long hwnd);
- public boolean isInsideWindow() {
- return mouseInside;
- }
+ public boolean isInsideWindow() {
+ return mouseInside;
+ }
+
+ public void setResizable(boolean resizable) {
+
+ }
+
+ public boolean isResizable() {
+ return false;
+ }
+
+ public boolean wasResized() {
+ return false;
+ }
private static final class Rect {
public int top;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sp...@us...> - 2011-07-12 21:30:55
|
Revision: 3581
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3581&view=rev
Author: spasi
Date: 2011-07-12 21:30:48 +0000 (Tue, 12 Jul 2011)
Log Message:
-----------
Fixed stackmap and classloading bugs.
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java 2011-07-12 20:59:27 UTC (rev 3580)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java 2011-07-12 21:30:48 UTC (rev 3581)
@@ -51,7 +51,7 @@
*/
public class MappedObject {
- static final boolean CHECKS = false;//LWJGLUtil.getPrivilegedBoolean("org.lwjgl.util.mapped.Checks");
+ static final boolean CHECKS = LWJGLUtil.getPrivilegedBoolean("org.lwjgl.util.mapped.Checks");
public MappedObject() {
//
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java 2011-07-12 20:59:27 UTC (rev 3580)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java 2011-07-12 21:30:48 UTC (rev 3581)
@@ -8,13 +8,13 @@
import org.objectweb.asm.*;
import org.objectweb.asm.util.TraceClassVisitor;
-import java.io.PrintWriter;
-import java.io.StringWriter;
+import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
+import java.util.StringTokenizer;
import static org.objectweb.asm.Opcodes.*;
@@ -32,8 +32,8 @@
*/
public class MappedObjectTransformer {
- static final boolean PRINT_TIMING = false;//LWJGLUtil.DEBUG && LWJGLUtil.getPrivilegedBoolean("org.lwjgl.util.mapped.PrintTiming");
- static final boolean PRINT_ACTIVITY = false;//LWJGLUtil.DEBUG && LWJGLUtil.getPrivilegedBoolean("org.lwjgl.util.mapped.PrintActivity");
+ static final boolean PRINT_TIMING = LWJGLUtil.DEBUG && LWJGLUtil.getPrivilegedBoolean("org.lwjgl.util.mapped.PrintTiming");
+ static final boolean PRINT_ACTIVITY = LWJGLUtil.DEBUG && LWJGLUtil.getPrivilegedBoolean("org.lwjgl.util.mapped.PrintActivity");
static final boolean PRINT_BYTECODE = false; //LWJGLUtil.DEBUG && LWJGLUtil.getPrivilegedBoolean("org.lwjgl.util.mapped.PrintBytecode");
static final Map<String, MappedSubtypeInfo> className_to_subtype;
@@ -138,13 +138,24 @@
}
}
- static final String view_constructor_method = "_construct_view_";
+ static boolean is_currently_computing_frames = false;
+ static final String view_constructor_method = "_construct_view_";
static byte[] transformFieldAccess(final String className, byte[] bytecode) {
- int flags = 0;//ClassWriter.COMPUTE_FRAMES;
+ int flags = ClassWriter.COMPUTE_FRAMES;
- ClassWriter writer = new ClassWriter(flags);
+ ClassWriter writer = new ClassWriter(flags) {
+ // HACK: prevent user-code static-initialization-blocks to be executed
+ @Override
+ protected String getCommonSuperClass(String a, String b) {
+ if ( is_currently_computing_frames )
+ if ( !a.startsWith("java/") || !b.startsWith("java/") )
+ return "java/lang/Object";
+ return super.getCommonSuperClass(a, b);
+ }
+ };
+
ClassAdapter adapter = new ClassAdapter(writer) {
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
@@ -192,14 +203,14 @@
bytecode = writer.toByteArray();
if ( PRINT_BYTECODE )
- printBytecode(bytecode, adapter);
+ printBytecode(bytecode);
return bytecode;
}
- private static void printBytecode(byte[] bytecode, ClassAdapter adapter) {
+ private static void printBytecode(byte[] bytecode) {
StringWriter sw = new StringWriter();
- ClassVisitor tracer = new TraceClassVisitor(adapter, new PrintWriter(sw));
+ ClassVisitor tracer = new TraceClassVisitor(new ClassWriter(0), new PrintWriter(sw));
new ClassReader(bytecode).accept(tracer, 0);
String dump = sw.toString();
@@ -227,13 +238,16 @@
super.visitTypeInsn(opcode, typeName);
}
-
- private int requireExtraStack = 0;
-
+
@Override
- public void visitMaxs(int maxStack, int maxLocals)
- {
- super.visitMaxs(maxStack+this.requireExtraStack, maxLocals);
+ public void visitMaxs(int a, int b) {
+ try {
+ is_currently_computing_frames = true;
+
+ super.visitMaxs(a, b);
+ } finally {
+ is_currently_computing_frames = false;
+ }
}
@Override
@@ -252,7 +266,7 @@
if ( (isMapDirectMethod || isMapBufferMethod) || isMallocMethod ) {
if ( isMallocMethod ) {
- // stack: count
+ // stack: count
pushInt(super.mv, mappedType.sizeof);
// stack: sizeof, count
super.visitInsn(IMUL);
@@ -282,7 +296,6 @@
// stack: int, int, buffer, new, new
super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "setup", "(L" + jvmClassName(MappedObject.class) + ";Ljava/nio/ByteBuffer;II)V");
// stack: new
- this.requireExtraStack = 5;
return;
}
@@ -296,7 +309,6 @@
// stack: new, this
super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "dup", "(L" + jvmClassName(MappedObject.class) + ";L" + jvmClassName(MappedObject.class) + ";)L" + jvmClassName(MappedObject.class) + ";");
// stack: new
- this.requireExtraStack = 3;
return;
}
@@ -310,7 +322,6 @@
// stack: new, this
super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "slice", "(L" + jvmClassName(MappedObject.class) + ";L" + jvmClassName(MappedObject.class) + ";)L" + jvmClassName(MappedObject.class) + ";");
// stack: new
- this.requireExtraStack = 3;
return;
}
@@ -322,7 +333,6 @@
// stack: this, this
super.visitMethodInsn(INVOKEVIRTUAL, className, view_constructor_method, "()V");
// stack: this
- this.requireExtraStack = 2;
return;
}
@@ -334,7 +344,6 @@
// stack: sizeof, target, this
super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "copy", "(L" + jvmClassName(MappedObject.class) + ";L" + jvmClassName(MappedObject.class) + ";I)V");
// stack: -
- this.requireExtraStack = 3;
return;
}
@@ -346,7 +355,6 @@
// stack: bytes, target, this
super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "copy", "(L" + jvmClassName(MappedObject.class) + ";L" + jvmClassName(MappedObject.class) + ";I)V");
// stack: -
- this.requireExtraStack = 4;
return;
}
}
@@ -488,13 +496,12 @@
// stack: int, long
super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "newBuffer", "(JI)L" + jvmClassName(ByteBuffer.class) + ";");
// stack: buffer
- this.requireExtraStack = 4;
return;
}
}
if ( opcode == PUTFIELD ) {
- // stack: value, ref
+ // stack: value, ref
super.visitInsn(SWAP);
// stack: ref, value
super.visitFieldInsn(GETFIELD, mappedSubtype.className, "viewAddress", "J");
@@ -505,11 +512,10 @@
// stack: long, value
super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), typeName.toLowerCase() + "put", "(" + typeName + "J)V");
// stack -
- this.requireExtraStack = 4+(int)(mappedSubtype.fieldToLength.get(fieldName).longValue()>>2);
return;
}
if ( opcode == GETFIELD ) {
- // stack: ref
+ // stack: ref
super.visitFieldInsn(GETFIELD, mappedSubtype.className, "viewAddress", "J");
// stack: long
super.visitLdcInsn(fieldOffset);
@@ -518,7 +524,6 @@
// stack: long
super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), typeName.toLowerCase() + "get", "(J)" + typeName);
// stack: value
- this.requireExtraStack = 4;
return;
}
@@ -576,4 +581,59 @@
}
}
+ public static String exportConfiguration() {
+ StringBuilder sb = new StringBuilder();
+
+ for ( MappedSubtypeInfo info : className_to_subtype.values() ) {
+ sb.append("class\t" + info.className + "\t" + info.sizeof + "\t" + info.align + "\r\n");
+
+ for ( String fieldName : info.fieldToOffset.keySet() ) {
+ sb.append("field\t" + info.className + "\t" + fieldName + "\t" + info.fieldToOffset.get(fieldName) + "\t" + info.fieldToLength.get(fieldName) + "\r\n");
+ }
+ }
+
+ className_to_subtype.clear();
+
+ return sb.toString();
+ }
+
+ public static void importConfigation(String input) {
+ className_to_subtype.clear();
+
+ try {
+ BufferedReader br = new BufferedReader(new StringReader(input));
+
+ while ( true ) {
+ String line = br.readLine();
+ if ( line == null )
+ break;
+ if ( (line = line.trim()).isEmpty() )
+ continue;
+
+ StringTokenizer st = new StringTokenizer(line, "\t");
+
+ String type = st.nextToken();
+ if ( type.equals("class") ) {
+ String className = st.nextToken();
+ int sizeof = Integer.parseInt(st.nextToken());
+ int align = Integer.parseInt(st.nextToken());
+
+ className_to_subtype.put(className, new MappedSubtypeInfo(className, sizeof, align));
+ } else if ( type.equals("field") ) {
+ MappedObjectTransformer.MappedSubtypeInfo info = className_to_subtype.get(st.nextToken());
+ String methodName = st.nextToken();
+ int off = Integer.parseInt(st.nextToken());
+ int len = Integer.parseInt(st.nextToken());
+
+ info.fieldToOffset.put(methodName, Long.valueOf(off));
+ info.fieldToLength.put(methodName, Long.valueOf(len));
+ } else {
+ throw new IllegalStateException(type);
+ }
+ }
+ } catch (IOException exc) {
+ throw new IllegalStateException("never happens");
+ }
+ }
+
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sp...@us...> - 2011-07-12 20:59:34
|
Revision: 3580
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3580&view=rev
Author: spasi
Date: 2011-07-12 20:59:27 +0000 (Tue, 12 Jul 2011)
Log Message:
-----------
Added some new ES extensions.
Added Paths:
-----------
trunk/LWJGL/src/templates/org/lwjgl/opengles/EXT_unpack_subimage.java
trunk/LWJGL/src/templates/org/lwjgl/opengles/NV_draw_buffers.java
trunk/LWJGL/src/templates/org/lwjgl/opengles/NV_read_depth_stencil.java
trunk/LWJGL/src/templates/org/lwjgl/opengles/NV_texture_compression_s3tc_update.java
trunk/LWJGL/src/templates/org/lwjgl/opengles/NV_texture_npot_2D_mipmap.java
Added: trunk/LWJGL/src/templates/org/lwjgl/opengles/EXT_unpack_subimage.java
===================================================================
--- trunk/LWJGL/src/templates/org/lwjgl/opengles/EXT_unpack_subimage.java (rev 0)
+++ trunk/LWJGL/src/templates/org/lwjgl/opengles/EXT_unpack_subimage.java 2011-07-12 20:59:27 UTC (rev 3580)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.opengles;
+
+public interface EXT_unpack_subimage {
+
+ /**
+ * Accepted by the <pname> parameters of PixelStorei, GetIntegerv, and
+ * GetFloatv:
+ */
+ int GL_UNPACK_ROW_LENGTH = 0x0CF2,
+ GL_UNPACK_SKIP_ROWS = 0x0CF3,
+ GL_UNPACK_SKIP_PIXELS = 0x0CF4;
+
+}
\ No newline at end of file
Added: trunk/LWJGL/src/templates/org/lwjgl/opengles/NV_draw_buffers.java
===================================================================
--- trunk/LWJGL/src/templates/org/lwjgl/opengles/NV_draw_buffers.java (rev 0)
+++ trunk/LWJGL/src/templates/org/lwjgl/opengles/NV_draw_buffers.java 2011-07-12 20:59:27 UTC (rev 3580)
@@ -0,0 +1,90 @@
+/*
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.opengles;
+
+import org.lwjgl.util.generator.Alternate;
+import org.lwjgl.util.generator.AutoSize;
+import org.lwjgl.util.generator.Const;
+import org.lwjgl.util.generator.Constant;
+import org.lwjgl.util.generator.opengl.GLenum;
+import org.lwjgl.util.generator.opengl.GLsizei;
+
+import java.nio.IntBuffer;
+
+public interface NV_draw_buffers {
+
+ /**
+ * Accepted by the <pname> parameters of GetIntegerv, GetFloatv,
+ * and GetDoublev:
+ */
+ int GL_MAX_DRAW_BUFFERS_NV = 0x8824,
+ GL_DRAW_BUFFER0_NV = 0x8825,
+ GL_DRAW_BUFFER1_NV = 0x8826,
+ GL_DRAW_BUFFER2_NV = 0x8827,
+ GL_DRAW_BUFFER3_NV = 0x8828,
+ GL_DRAW_BUFFER4_NV = 0x8829,
+ GL_DRAW_BUFFER5_NV = 0x882A,
+ GL_DRAW_BUFFER6_NV = 0x882B,
+ GL_DRAW_BUFFER7_NV = 0x882C,
+ GL_DRAW_BUFFER8_NV = 0x882D,
+ GL_DRAW_BUFFER9_NV = 0x882E,
+ GL_DRAW_BUFFER10_NV = 0x882F,
+ GL_DRAW_BUFFER11_NV = 0x8830,
+ GL_DRAW_BUFFER12_NV = 0x8831,
+ GL_DRAW_BUFFER13_NV = 0x8832,
+ GL_DRAW_BUFFER14_NV = 0x8833,
+ GL_DRAW_BUFFER15_NV = 0x8834;
+
+ /** Accepted by the <bufs> parameter of DrawBuffersNV: */
+ int GL_COLOR_ATTACHMENT0_NV = 0x8CE0,
+ GL_COLOR_ATTACHMENT1_NV = 0x8CE1,
+ GL_COLOR_ATTACHMENT2_NV = 0x8CE2,
+ GL_COLOR_ATTACHMENT3_NV = 0x8CE3,
+ GL_COLOR_ATTACHMENT4_NV = 0x8CE4,
+ GL_COLOR_ATTACHMENT5_NV = 0x8CE5,
+ GL_COLOR_ATTACHMENT6_NV = 0x8CE6,
+ GL_COLOR_ATTACHMENT7_NV = 0x8CE7,
+ GL_COLOR_ATTACHMENT8_NV = 0x8CE8,
+ GL_COLOR_ATTACHMENT9_NV = 0x8CE9,
+ GL_COLOR_ATTACHMENT10_NV = 0x8CEA,
+ GL_COLOR_ATTACHMENT11_NV = 0x8CEB,
+ GL_COLOR_ATTACHMENT12_NV = 0x8CEC,
+ GL_COLOR_ATTACHMENT13_NV = 0x8CED,
+ GL_COLOR_ATTACHMENT14_NV = 0x8CEE,
+ GL_COLOR_ATTACHMENT15_NV = 0x8CEF;
+
+ void glDrawBuffersNV(@AutoSize("bufs") @GLsizei int n, @Const @GLenum IntBuffer bufs);
+
+ @Alternate("glDrawBuffersNV")
+ void glDrawBuffersNV(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getBufferInt().put(0, buf), 0", keepParam = true) int buf);
+
+}
\ No newline at end of file
Added: trunk/LWJGL/src/templates/org/lwjgl/opengles/NV_read_depth_stencil.java
===================================================================
--- trunk/LWJGL/src/templates/org/lwjgl/opengles/NV_read_depth_stencil.java (rev 0)
+++ trunk/LWJGL/src/templates/org/lwjgl/opengles/NV_read_depth_stencil.java 2011-07-12 20:59:27 UTC (rev 3580)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.opengles;
+
+public interface NV_read_depth_stencil {
+
+}
\ No newline at end of file
Added: trunk/LWJGL/src/templates/org/lwjgl/opengles/NV_texture_compression_s3tc_update.java
===================================================================
--- trunk/LWJGL/src/templates/org/lwjgl/opengles/NV_texture_compression_s3tc_update.java (rev 0)
+++ trunk/LWJGL/src/templates/org/lwjgl/opengles/NV_texture_compression_s3tc_update.java 2011-07-12 20:59:27 UTC (rev 3580)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.opengles;
+
+public interface NV_texture_compression_s3tc_update {
+
+}
\ No newline at end of file
Added: trunk/LWJGL/src/templates/org/lwjgl/opengles/NV_texture_npot_2D_mipmap.java
===================================================================
--- trunk/LWJGL/src/templates/org/lwjgl/opengles/NV_texture_npot_2D_mipmap.java (rev 0)
+++ trunk/LWJGL/src/templates/org/lwjgl/opengles/NV_texture_npot_2D_mipmap.java 2011-07-12 20:59:27 UTC (rev 3580)
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.opengles;
+
+public interface NV_texture_npot_2D_mipmap {
+
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sp...@us...> - 2011-07-12 20:47:52
|
Revision: 3579
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3579&view=rev
Author: spasi
Date: 2011-07-12 20:47:46 +0000 (Tue, 12 Jul 2011)
Log Message:
-----------
Added support for EXT_atomic_counter_32/64.
Added Paths:
-----------
trunk/LWJGL/src/templates/org/lwjgl/opencl/EXT_atomic_counters_32.java
trunk/LWJGL/src/templates/org/lwjgl/opencl/EXT_atomic_counters_64.java
Added: trunk/LWJGL/src/templates/org/lwjgl/opencl/EXT_atomic_counters_32.java
===================================================================
--- trunk/LWJGL/src/templates/org/lwjgl/opencl/EXT_atomic_counters_32.java (rev 0)
+++ trunk/LWJGL/src/templates/org/lwjgl/opencl/EXT_atomic_counters_32.java 2011-07-12 20:47:46 UTC (rev 3579)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.opencl;
+
+import org.lwjgl.util.generator.opencl.CLDeviceExtension;
+
+@CLDeviceExtension
+public interface EXT_atomic_counters_32 {
+
+ /** CLDevice query: Max number of atomic counters that can be used by a kernel. */
+ int CL_DEVICE_MAX_ATOMIC_COUNTERS_EXT = 0x4032;
+
+}
\ No newline at end of file
Added: trunk/LWJGL/src/templates/org/lwjgl/opencl/EXT_atomic_counters_64.java
===================================================================
--- trunk/LWJGL/src/templates/org/lwjgl/opencl/EXT_atomic_counters_64.java (rev 0)
+++ trunk/LWJGL/src/templates/org/lwjgl/opencl/EXT_atomic_counters_64.java 2011-07-12 20:47:46 UTC (rev 3579)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2002-2010 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.opencl;
+
+import org.lwjgl.util.generator.opencl.CLDeviceExtension;
+
+@CLDeviceExtension
+public interface EXT_atomic_counters_64 {
+
+ /** CLDevice query: Max number of atomic counters that can be used by a kernel. */
+ int CL_DEVICE_MAX_ATOMIC_COUNTERS_EXT = 0x4032;
+
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sp...@us...> - 2011-07-12 20:40:11
|
Revision: 3578
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3578&view=rev
Author: spasi
Date: 2011-07-12 20:40:05 +0000 (Tue, 12 Jul 2011)
Log Message:
-----------
Added bounds check to copyRange.
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java 2011-07-12 19:29:15 UTC (rev 3577)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java 2011-07-12 20:40:05 UTC (rev 3578)
@@ -106,6 +106,11 @@
}
public static void copy(MappedObject src, MappedObject dst, int bytes) {
+ if ( MappedObject.CHECKS ) {
+ src.checkRange(bytes);
+ dst.checkRange(bytes);
+ }
+
MappedObjectUnsafe.INSTANCE.copyMemory(src.viewAddress, dst.viewAddress, bytes);
}
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java 2011-07-12 19:29:15 UTC (rev 3577)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java 2011-07-12 20:40:05 UTC (rev 3578)
@@ -33,6 +33,7 @@
import org.lwjgl.LWJGLUtil;
+import java.nio.BufferOverflowException;
import java.nio.ByteBuffer;
/**
@@ -97,10 +98,19 @@
}
final void checkAddress(final long address) {
- if ( preventGC.capacity() < (address - MappedObjectUnsafe.getBufferBaseAddress(preventGC) + stride) )
+ final long base = MappedObjectUnsafe.getBufferBaseAddress(preventGC);
+ if ( address < base || preventGC.capacity() < (address - base + stride) )
throw new IndexOutOfBoundsException();
}
+ final void checkRange(final int bytes) {
+ if ( bytes < 0 )
+ throw new IllegalArgumentException();
+
+ if ( preventGC.capacity() < (viewAddress - MappedObjectUnsafe.getBufferBaseAddress(preventGC) + bytes) )
+ throw new BufferOverflowException();
+ }
+
/**
* Creates a MappedObject instance, mapping the memory region of the specified direct ByteBuffer.
* <p/>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sp...@us...> - 2011-07-12 19:29:22
|
Revision: 3577
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3577&view=rev
Author: spasi
Date: 2011-07-12 19:29:15 +0000 (Tue, 12 Jul 2011)
Log Message:
-----------
Added friendly error message when a non-static inner class is registered with the transformer.
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedForeach.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedForeach.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedForeach.java 2011-07-12 18:30:56 UTC (rev 3576)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedForeach.java 2011-07-12 19:29:15 UTC (rev 3577)
@@ -40,8 +40,8 @@
*/
public class MappedForeach<T extends MappedObject> implements Iterable<T> {
- private final T mapped;
- private final int elementCount;
+ final T mapped;
+ final int elementCount;
MappedForeach(T mapped, int elementCount) {
this.mapped = mapped;
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java 2011-07-12 18:30:56 UTC (rev 3576)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java 2011-07-12 19:29:15 UTC (rev 3577)
@@ -36,7 +36,7 @@
static final boolean PRINT_ACTIVITY = false;//LWJGLUtil.DEBUG && LWJGLUtil.getPrivilegedBoolean("org.lwjgl.util.mapped.PrintActivity");
static final boolean PRINT_BYTECODE = false; //LWJGLUtil.DEBUG && LWJGLUtil.getPrivilegedBoolean("org.lwjgl.util.mapped.PrintBytecode");
- private static final Map<String, MappedSubtypeInfo> className_to_subtype;
+ static final Map<String, MappedSubtypeInfo> className_to_subtype;
static {
className_to_subtype = new HashMap<String, MappedSubtypeInfo>();
@@ -80,6 +80,9 @@
if ( mapped == null )
throw new InternalError("missing " + MappedType.class.getName() + " annotation");
+ if ( type.getEnclosingClass() != null && !Modifier.isStatic(type.getModifiers()) )
+ throw new InternalError("only top-level or static inner classes are allowed");
+
String className = jvmClassName(type);
MappedSubtypeInfo mappedType = new MappedSubtypeInfo(className, mapped.sizeof(), mapped.align());
@@ -88,7 +91,7 @@
for ( Field field : type.getDeclaredFields() ) {
// static fields are never mapped
- if ( (field.getModifiers() & Modifier.STATIC) != 0 )
+ if ( Modifier.isStatic(field.getModifiers()) )
continue;
// we only support primitives and ByteBuffers
@@ -135,7 +138,7 @@
}
}
- private static final String view_constructor_method = "_construct_view_";
+ static final String view_constructor_method = "_construct_view_";
static byte[] transformFieldAccess(final String className, byte[] bytecode) {
int flags = 0;//ClassWriter.COMPUTE_FRAMES;
@@ -525,7 +528,7 @@
}
}
- private static void pushInt(MethodVisitor mv, int value) {
+ static void pushInt(MethodVisitor mv, int value) {
if ( value == -1 )
mv.visitInsn(ICONST_M1);
else if ( value == 0 )
@@ -548,7 +551,7 @@
mv.visitLdcInsn(Integer.valueOf(value));
}
- private static String jvmClassName(Class<?> type) {
+ static String jvmClassName(Class<?> type) {
return type.getName().replace('.', '/');
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <riv...@us...> - 2011-07-12 18:31:02
|
Revision: 3576
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3576&view=rev
Author: riven-lwjgl
Date: 2011-07-12 18:30:56 +0000 (Tue, 12 Jul 2011)
Log Message:
-----------
First attempt at manual computation of stack frames
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java 2011-07-12 17:49:58 UTC (rev 3575)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java 2011-07-12 18:30:56 UTC (rev 3576)
@@ -138,7 +138,7 @@
private static final String view_constructor_method = "_construct_view_";
static byte[] transformFieldAccess(final String className, byte[] bytecode) {
- int flags = ClassWriter.COMPUTE_FRAMES;
+ int flags = 0;//ClassWriter.COMPUTE_FRAMES;
ClassWriter writer = new ClassWriter(flags);
@@ -224,6 +224,14 @@
super.visitTypeInsn(opcode, typeName);
}
+
+ private int requireExtraStack = 0;
+
+ @Override
+ public void visitMaxs(int maxStack, int maxLocals)
+ {
+ super.visitMaxs(maxStack+this.requireExtraStack, maxLocals);
+ }
@Override
public void visitMethodInsn(int opcode, String className, String methodName, String signature) {
@@ -241,7 +249,7 @@
if ( (isMapDirectMethod || isMapBufferMethod) || isMallocMethod ) {
if ( isMallocMethod ) {
- // stack: count
+ // stack: count
pushInt(super.mv, mappedType.sizeof);
// stack: sizeof, count
super.visitInsn(IMUL);
@@ -271,6 +279,7 @@
// stack: int, int, buffer, new, new
super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "setup", "(L" + jvmClassName(MappedObject.class) + ";Ljava/nio/ByteBuffer;II)V");
// stack: new
+ this.requireExtraStack = 5;
return;
}
@@ -284,6 +293,7 @@
// stack: new, this
super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "dup", "(L" + jvmClassName(MappedObject.class) + ";L" + jvmClassName(MappedObject.class) + ";)L" + jvmClassName(MappedObject.class) + ";");
// stack: new
+ this.requireExtraStack = 3;
return;
}
@@ -297,6 +307,7 @@
// stack: new, this
super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "slice", "(L" + jvmClassName(MappedObject.class) + ";L" + jvmClassName(MappedObject.class) + ";)L" + jvmClassName(MappedObject.class) + ";");
// stack: new
+ this.requireExtraStack = 3;
return;
}
@@ -308,6 +319,7 @@
// stack: this, this
super.visitMethodInsn(INVOKEVIRTUAL, className, view_constructor_method, "()V");
// stack: this
+ this.requireExtraStack = 2;
return;
}
@@ -319,6 +331,7 @@
// stack: sizeof, target, this
super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "copy", "(L" + jvmClassName(MappedObject.class) + ";L" + jvmClassName(MappedObject.class) + ";I)V");
// stack: -
+ this.requireExtraStack = 3;
return;
}
@@ -330,6 +343,7 @@
// stack: bytes, target, this
super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "copy", "(L" + jvmClassName(MappedObject.class) + ";L" + jvmClassName(MappedObject.class) + ";I)V");
// stack: -
+ this.requireExtraStack = 4;
return;
}
}
@@ -458,30 +472,50 @@
if ( opcode == GETFIELD ) {
Long fieldLength = mappedSubtype.fieldToLength.get(fieldName);
+ // stack: ref
super.visitFieldInsn(GETFIELD, mappedSubtype.className, "viewAddress", "J");
+ // stack: long
super.visitLdcInsn(fieldOffset);
+ // stack: long, long
super.visitInsn(LADD);
+ // stack: long
super.visitLdcInsn(fieldLength);
+ // stack: long, long
super.visitInsn(L2I);
+ // stack: int, long
super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "newBuffer", "(JI)L" + jvmClassName(ByteBuffer.class) + ";");
-
+ // stack: buffer
+ this.requireExtraStack = 4;
return;
}
}
if ( opcode == PUTFIELD ) {
+ // stack: value, ref
super.visitInsn(SWAP);
+ // stack: ref, value
super.visitFieldInsn(GETFIELD, mappedSubtype.className, "viewAddress", "J");
+ // stack: long, value
super.visitLdcInsn(fieldOffset);
+ // stack: long, long, value
super.visitInsn(LADD);
+ // stack: long, value
super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), typeName.toLowerCase() + "put", "(" + typeName + "J)V");
+ // stack -
+ this.requireExtraStack = 4+(int)(mappedSubtype.fieldToLength.get(fieldName).longValue()>>2);
return;
}
if ( opcode == GETFIELD ) {
+ // stack: ref
super.visitFieldInsn(GETFIELD, mappedSubtype.className, "viewAddress", "J");
+ // stack: long
super.visitLdcInsn(fieldOffset);
+ // stack: long, long
super.visitInsn(LADD);
+ // stack: long
super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), typeName.toLowerCase() + "get", "(J)" + typeName);
+ // stack: value
+ this.requireExtraStack = 4;
return;
}
@@ -511,7 +545,7 @@
else if ( value >= Short.MIN_VALUE && value <= Short.MAX_VALUE )
mv.visitIntInsn(SIPUSH, value);
else
- mv.visitLdcInsn(value);
+ mv.visitLdcInsn(Integer.valueOf(value));
}
private static String jvmClassName(Class<?> type) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <riv...@us...> - 2011-07-12 17:50:04
|
Revision: 3575
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3575&view=rev
Author: riven-lwjgl
Date: 2011-07-12 17:49:58 +0000 (Tue, 12 Jul 2011)
Log Message:
-----------
Test case showing problems on loading library (64 vs 32 bit)
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/test/mapped/TestMappedObject.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java
Added Paths:
-----------
trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectWithLibrary.java
Added: trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectWithLibrary.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectWithLibrary.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectWithLibrary.java 2011-07-12 17:49:58 UTC (rev 3575)
@@ -0,0 +1,18 @@
+/*
+ * Created on Jul 12, 2011
+ */
+
+package org.lwjgl.test.mapped;
+
+import java.io.File;
+
+import org.lwjgl.opengl.Display;
+
+public class MappedObjectWithLibrary
+{
+ public static void testLWJGL() throws Exception
+ {
+ System.out.println(new File(System.getProperty("java.library.path")).getCanonicalPath());
+ Display.create();
+ }
+}
Modified: trunk/LWJGL/src/java/org/lwjgl/test/mapped/TestMappedObject.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/mapped/TestMappedObject.java 2011-07-12 15:36:16 UTC (rev 3574)
+++ trunk/LWJGL/src/java/org/lwjgl/test/mapped/TestMappedObject.java 2011-07-12 17:49:58 UTC (rev 3575)
@@ -44,7 +44,7 @@
throw new RuntimeException("Asserts must be enabled for this test.");
}
- public static void main(String[] args) {
+ public static void main(String[] args) throws Exception {
MappedObjectTransformer.register(MappedFloat.class);
MappedObjectTransformer.register(MappedVec2.class);
MappedObjectTransformer.register(MappedVec3.class);
@@ -70,6 +70,8 @@
MappedObjectTests3.testForeach();
MappedObjectTests3.testConstructor();
MappedObjectTests3.testMappedSet();
+
+ MappedObjectWithLibrary.testLWJGL();
}
}
\ No newline at end of file
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java 2011-07-12 15:36:16 UTC (rev 3574)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java 2011-07-12 17:49:58 UTC (rev 3575)
@@ -50,7 +50,7 @@
*/
public class MappedObject {
- static final boolean CHECKS = LWJGLUtil.getPrivilegedBoolean("org.lwjgl.util.mapped.Checks");
+ static final boolean CHECKS = false;//LWJGLUtil.getPrivilegedBoolean("org.lwjgl.util.mapped.Checks");
public MappedObject() {
//
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java 2011-07-12 15:36:16 UTC (rev 3574)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java 2011-07-12 17:49:58 UTC (rev 3575)
@@ -32,8 +32,8 @@
*/
public class MappedObjectTransformer {
- static final boolean PRINT_TIMING = LWJGLUtil.DEBUG && LWJGLUtil.getPrivilegedBoolean("org.lwjgl.util.mapped.PrintTiming");
- static final boolean PRINT_ACTIVITY = LWJGLUtil.DEBUG && LWJGLUtil.getPrivilegedBoolean("org.lwjgl.util.mapped.PrintActivity");
+ static final boolean PRINT_TIMING = false;//LWJGLUtil.DEBUG && LWJGLUtil.getPrivilegedBoolean("org.lwjgl.util.mapped.PrintTiming");
+ static final boolean PRINT_ACTIVITY = false;//LWJGLUtil.DEBUG && LWJGLUtil.getPrivilegedBoolean("org.lwjgl.util.mapped.PrintActivity");
static final boolean PRINT_BYTECODE = false; //LWJGLUtil.DEBUG && LWJGLUtil.getPrivilegedBoolean("org.lwjgl.util.mapped.PrintBytecode");
private static final Map<String, MappedSubtypeInfo> className_to_subtype;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sp...@us...> - 2011-07-12 15:36:22
|
Revision: 3574
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3574&view=rev
Author: spasi
Date: 2011-07-12 15:36:16 +0000 (Tue, 12 Jul 2011)
Log Message:
-----------
Added GLES classes on which Display depends to the main jar.
Modified Paths:
--------------
trunk/LWJGL/build.xml
trunk/LWJGL/src/java/org/lwjgl/opengl/DrawableGL.java
trunk/LWJGL/src/java/org/lwjgl/opengl/DrawableGLES.java
trunk/LWJGL/src/java/org/lwjgl/opengl/DrawableLWJGL.java
trunk/LWJGL/src/java/org/lwjgl/opengl/PixelFormatLWJGL.java
Modified: trunk/LWJGL/build.xml
===================================================================
--- trunk/LWJGL/build.xml 2011-07-12 14:21:29 UTC (rev 3573)
+++ trunk/LWJGL/build.xml 2011-07-12 15:36:16 UTC (rev 3574)
@@ -143,6 +143,12 @@
<!-- Create lwjgl.jar -->
<jar destfile="${lwjgl.temp}/jar/lwjgl.jar" taskname="lwjgl.jar">
<fileset refid="lwjgl.fileset" />
+ <fileset dir="${lwjgl.bin}"> <!-- Display has a dependency on these -->
+ <patternset>
+ <include name="org/lwjgl/opengles/ContextAttribs.*"/>
+ <include name="org/lwjgl/opengles/PixelFormat.*"/>
+ </patternset>
+ </fileset>
<manifest>
<attribute name="Sealed" value="true"/>
</manifest>
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/DrawableGL.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/DrawableGL.java 2011-07-12 14:21:29 UTC (rev 3573)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/DrawableGL.java 2011-07-12 15:36:16 UTC (rev 3574)
@@ -1,3 +1,34 @@
+/*
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.opengl;
import org.lwjgl.LWJGLException;
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/DrawableGLES.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/DrawableGLES.java 2011-07-12 14:21:29 UTC (rev 3573)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/DrawableGLES.java 2011-07-12 15:36:16 UTC (rev 3574)
@@ -1,3 +1,34 @@
+/*
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.opengl;
import org.lwjgl.LWJGLException;
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/DrawableLWJGL.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/DrawableLWJGL.java 2011-07-12 14:21:29 UTC (rev 3573)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/DrawableLWJGL.java 2011-07-12 15:36:16 UTC (rev 3574)
@@ -1,3 +1,34 @@
+/*
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.opengl;
import org.lwjgl.LWJGLException;
Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/PixelFormatLWJGL.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/opengl/PixelFormatLWJGL.java 2011-07-12 14:21:29 UTC (rev 3573)
+++ trunk/LWJGL/src/java/org/lwjgl/opengl/PixelFormatLWJGL.java 2011-07-12 15:36:16 UTC (rev 3574)
@@ -1,3 +1,34 @@
+/*
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.opengl;
/**
@@ -4,7 +35,6 @@
* [INTERNAL USE ONLY]
*
* @author Spasi
- * @since 15/5/2011
*/
public interface PixelFormatLWJGL {
// Marker interface
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sp...@us...> - 2011-07-12 14:21:36
|
Revision: 3573
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3573&view=rev
Author: spasi
Date: 2011-07-12 14:21:29 +0000 (Tue, 12 Jul 2011)
Log Message:
-----------
Changed mapping behavior to be consistent with the LWJGL API; it now starts at the buffer's current .position().
Reverted client JVM warning to use serr instead of LWJGLUtil.log, for extra visibility when Debug is disabled.
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java
Modified: trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java 2011-07-12 13:44:13 UTC (rev 3572)
+++ trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java 2011-07-12 14:21:29 UTC (rev 3573)
@@ -117,6 +117,19 @@
} catch (IndexOutOfBoundsException e) {
// expected, ignore
}
+
+ try {
+ ByteBuffer posTest = ByteBuffer.allocateDirect(200);
+ posTest.position(10 * MappedFloat.SIZEOF); // position > 0
+
+ MappedFloat vecs2 = MappedFloat.map(posTest);
+ vecs2.view = 39;
+ assert vecs2.view == 39;
+ vecs2.view = 40;
+ System.out.println("org.lwjgl.util.mapped.Checks is false or there is a bug in bounds checking.");
+ } catch (IndexOutOfBoundsException e) {
+ // expected, ignore
+ }
}
// test dup
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java 2011-07-12 13:44:13 UTC (rev 3572)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java 2011-07-12 14:21:29 UTC (rev 3573)
@@ -60,7 +60,7 @@
throw new IllegalStateException("sizeof not a multiple of alignment");
mo.stride = sizeof;
- long addr = MappedObjectUnsafe.getBufferBaseAddress(buffer);
+ long addr = MappedObjectUnsafe.getBufferBaseAddress(buffer) + buffer.position();
if ( addr % align != 0 )
throw new IllegalStateException("buffer address not aligned on " + align + " bytes");
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java 2011-07-12 13:44:13 UTC (rev 3572)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java 2011-07-12 14:21:29 UTC (rev 3573)
@@ -62,7 +62,7 @@
String vmName = System.getProperty("java.vm.name");
if ( vmName != null && !vmName.contains("Server") ) {
- LWJGLUtil.log("Warning: " + MappedObject.class.getSimpleName() + "s have inferiour performance on Client VMs, please consider switching to a Server VM.");
+ System.err.println("Warning: " + MappedObject.class.getSimpleName() + "s have inferiour performance on Client VMs, please consider switching to a Server VM.");
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sp...@us...> - 2011-07-12 13:44:19
|
Revision: 3572
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3572&view=rev
Author: spasi
Date: 2011-07-12 13:44:13 +0000 (Tue, 12 Jul 2011)
Log Message:
-----------
Fixed bounds checking to work with .sliced mapped objects.
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java
Modified: trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java 2011-07-12 13:29:04 UTC (rev 3571)
+++ trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java 2011-07-12 13:44:13 UTC (rev 3572)
@@ -89,17 +89,34 @@
vecs.view = 0;
}
- // test bound check
+ // test bounds checking
{
assert (vecs.view == 0);
try {
+ vecs.view = 49;
+ assert vecs.view == 49;
+ vecs.view = 0;
vecs.view = 50;
System.out.println("org.lwjgl.util.mapped.Checks is false or there is a bug in bounds checking.");
vecs.view = 0;
} catch (IndexOutOfBoundsException e) {
// expected, ignore
}
+
assert (vecs.view == 0);
+
+ try {
+ vecs.view = 10;
+ MappedFloat vecs2 = vecs.slice();
+ vecs.view = 0;
+
+ vecs2.view = 39;
+ assert vecs2.view == 39;
+ vecs2.view = 40;
+ System.out.println("org.lwjgl.util.mapped.Checks is false or there is a bug in bounds checking.");
+ } catch (IndexOutOfBoundsException e) {
+ // expected, ignore
+ }
}
// test dup
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java 2011-07-12 13:29:04 UTC (rev 3571)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java 2011-07-12 13:44:13 UTC (rev 3572)
@@ -97,7 +97,7 @@
}
final void checkAddress(final long address) {
- if ( preventGC.capacity() < (address + stride - baseAddress) )
+ if ( preventGC.capacity() < (address - MappedObjectUnsafe.getBufferBaseAddress(preventGC) + stride) )
throw new IndexOutOfBoundsException();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sp...@us...> - 2011-07-12 13:29:14
|
Revision: 3571
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3571&view=rev
Author: spasi
Date: 2011-07-12 13:29:04 +0000 (Tue, 12 Jul 2011)
Log Message:
-----------
Mapped object code improvements: added license, additional documentation, reformatted code, now using LWJGLUtil.log instead of System.err.
Added system properties for bytecode transformer debug output. (org.lwjgl.util.mapped.PrintTiming & org.lwjgl.util.mapped.PrintActivity)
Added support for bounds checking the view of mapped objects. Enabled with org.lwjgl.util.mapped.Checks
Added tests for mapped objects. (org.lwjgl.test.mapped package)
Added "[LWJGL] " prefix to all LWJGL generated debug messages.
Modified Paths:
--------------
trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedField.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedForeach.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectClassLoader.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectUnsafe.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet2.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet3.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet4.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedType.java
Added Paths:
-----------
trunk/LWJGL/src/java/org/lwjgl/test/mapped/
trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedFloat.java
trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectBench.java
trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java
trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests2.java
trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests3.java
trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedSomething.java
trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedVec2.java
trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedVec3.java
trunk/LWJGL/src/java/org/lwjgl/test/mapped/TestMappedObject.java
Modified: trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java 2011-07-12 07:27:00 UTC (rev 3570)
+++ trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java 2011-07-12 13:29:04 UTC (rev 3571)
@@ -448,7 +448,7 @@
/**
* Gets a boolean property as a privileged action.
*/
- private static boolean getPrivilegedBoolean(final String property_name) {
+ public static boolean getPrivilegedBoolean(final String property_name) {
Boolean value = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
public Boolean run() {
return Boolean.getBoolean(property_name);
@@ -464,7 +464,7 @@
*/
public static void log(String msg) {
if (DEBUG) {
- System.err.println(msg);
+ System.err.println("[LWJGL] " + msg);
}
}
Added: trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedFloat.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedFloat.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedFloat.java 2011-07-12 13:29:04 UTC (rev 3571)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.test.mapped;
+
+import org.lwjgl.util.mapped.MappedObject;
+import org.lwjgl.util.mapped.MappedType;
+
+/** @author Riven */
+@MappedType(sizeof = 4)
+public class MappedFloat extends MappedObject {
+
+ public MappedFloat() {
+ this.test();
+ }
+
+ public float value;
+
+ public void test() {
+ this.value = 4;
+ }
+
+ @Override
+ public String toString() {
+ return "MappedFloat[" + value + "]";
+ }
+
+}
\ No newline at end of file
Added: trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectBench.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectBench.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectBench.java 2011-07-12 13:29:04 UTC (rev 3571)
@@ -0,0 +1,237 @@
+/*
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.test.mapped;
+
+import org.lwjgl.util.mapped.MappedObjectUnsafe;
+
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+import static org.lwjgl.util.mapped.MappedHelper.*;
+
+/** @author Riven */
+@SuppressWarnings("static-access")
+public class MappedObjectBench {
+
+ static class InstanceVec3 {
+
+ float x, y, z;
+
+ @Override
+ public String toString() {
+ return "InstanceVec3[" + x + ", " + y + ", " + z + "]";
+ }
+ }
+
+ static class ArrayVec3 {
+
+ float[] a;
+ int i;
+
+ @Override
+ public String toString() {
+ return "ArrayVec3[" + a[i * 3 + 0] + ", " + a[i * 3 + 1] + ", " + a[i * 3 + 2] + "]";
+ }
+ }
+
+ static void benchmarkInstances() {
+ final int runs = 64;
+ final int iterations = 64 * 1024;
+
+ InstanceVec3 vec1 = new InstanceVec3();
+ InstanceVec3 vec2 = new InstanceVec3();
+ InstanceVec3 vec3 = new InstanceVec3();
+
+ long[] took = new long[runs];
+ for ( int run = 0; run < runs; run++ ) {
+ long t0 = System.nanoTime();
+ for ( int iteration = 0; iteration < iterations; iteration++ ) {
+ vec1.x = 13;
+ vec1.y += vec1.y * vec1.x + 0.3f;
+ vec1.z += vec2.y + vec1.x + 0.3f;
+ vec2.z += vec2.y + vec1.x;
+ vec3.z += vec2.z + vec1.y;
+ }
+ long t1 = System.nanoTime();
+ took[run] = t1 - t0;
+ }
+
+ Arrays.sort(took);
+ System.out.println("instance took: " + took[took.length / 2] / 1024 + "us");
+
+ System.out.println(vec1);
+ System.out.println(vec2);
+ System.out.println(vec3);
+ }
+
+ static void benchmarkMapped() {
+ final int runs = 64;
+ final int iterations = 64 * 1024;
+
+ ByteBuffer bb = ByteBuffer.allocateDirect(200);
+
+ MappedVec3 vecs = MappedVec3.map(bb);
+
+ MappedVec3 vec1 = vecs.dup();
+ MappedVec3 vec2 = vecs.dup();
+ MappedVec3 vec3 = vecs.dup();
+
+ vec1.view = 0;
+ vec2.view = 1;
+ vec3.view = 2;
+
+ long[] took = new long[runs];
+ for ( int run = 0; run < runs; run++ ) {
+ long t0 = System.nanoTime();
+ for ( int iteration = 0; iteration < iterations; iteration += 2 ) {
+ vec1.x = 13;
+ vec1.y += vec1.y * vec1.x + 0.3f;
+ vec1.z += vec2.y + vec1.x + 0.3f;
+ vec2.z += vec2.y + vec1.x;
+ vec3.z += vec2.z + vec1.y;
+
+ vec1.x = 13;
+ vec1.y += vec1.y * vec1.x + 0.3f;
+ vec1.z += vec2.y + vec1.x + 0.3f;
+ vec2.z += vec2.y + vec1.x;
+ vec3.z += vec2.z + vec1.y;
+ }
+ long t1 = System.nanoTime();
+ took[run] = t1 - t0;
+ }
+
+ Arrays.sort(took);
+ System.out.println("mapped took: " + took[took.length / 2] / 1024 + "us");
+
+ System.out.println(vec1);
+ System.out.println(vec2);
+ System.out.println(vec3);
+
+ System.out.println(bb);
+ }
+
+ static void benchmarkIndirectArray() {
+ final int runs = 64;
+ final int iterations = 64 * 1024;
+
+ float[] bb = new float[200];
+
+ ArrayVec3 vec1 = new ArrayVec3();
+ ArrayVec3 vec2 = new ArrayVec3();
+ ArrayVec3 vec3 = new ArrayVec3();
+
+ vec1.a = bb;
+ vec2.a = bb;
+ vec3.a = bb;
+
+ vec1.i = 0;
+ vec2.i = 1;
+ vec3.i = 2;
+
+ long[] took = new long[runs];
+ for ( int run = 0; run < runs; run++ ) {
+ long t0 = System.nanoTime();
+ for ( int iteration = 0; iteration < iterations; iteration++ ) {
+ vec1.a[vec1.i * 3 + 0] = 13;
+ vec1.a[vec1.i * 3 + 1] += vec1.a[vec1.i * 3 + 1] * vec1.a[vec1.i * 3 + 0] + 0.3f;
+ vec1.a[vec1.i * 3 + 2] += vec2.a[vec2.i * 3 + 1] + vec1.a[vec1.i * 3 + 0] + 0.3f;
+ vec2.a[vec2.i * 3 + 2] += vec2.a[vec2.i * 3 + 1] + vec1.a[vec1.i * 3 + 0];
+ vec3.a[vec3.i * 3 + 2] += vec2.a[vec2.i * 3 + 2] + vec2.a[vec2.i * 3 + 1];
+ }
+ long t1 = System.nanoTime();
+ took[run] = t1 - t0;
+ }
+
+ Arrays.sort(took);
+ System.out.println("array took: " + took[took.length / 2] / 1024 + "us");
+
+ System.out.println(vec1);
+ System.out.println(vec2);
+ System.out.println(vec3);
+
+ System.out.println(bb);
+ }
+
+ static void benchmarkDirectArray() {
+ final int runs = 64;
+ final int iterations = 64 * 1024;
+
+ float[] bb = new float[200];
+
+ long[] took = new long[runs];
+ for ( int run = 0; run < runs; run++ ) {
+ long t0 = System.nanoTime();
+ for ( int iteration = 0; iteration < iterations; iteration++ ) {
+ bb[1 * 3 + 0] = 13;
+ bb[1 * 3 + 1] += bb[1 * 3 + 1] * bb[1 * 3 + 0] + 0.3f;
+ bb[1 * 3 + 2] += bb[2 * 3 + 1] + bb[1 * 3 + 0] + 0.3f;
+ bb[2 * 3 + 2] += bb[2 * 3 + 1] + bb[1 * 3 + 0];
+ bb[3 * 3 + 2] += bb[2 * 3 + 2] + bb[2 * 3 + 1];
+ }
+ long t1 = System.nanoTime();
+ took[run] = t1 - t0;
+ }
+
+ Arrays.sort(took);
+ System.out.println("array2 took: " + took[took.length / 2] / 1024 + "us");
+
+ System.out.println(bb);
+ }
+
+ static void benchmarkUnsafe() {
+ final int runs = 64;
+ final int iterations = 64 * 1024;
+
+ ByteBuffer bb = ByteBuffer.allocateDirect(200);
+ long addr = MappedObjectUnsafe.getBufferBaseAddress(bb);
+
+ long[] took = new long[runs];
+ for ( int run = 0; run < runs; run++ ) {
+ long t0 = System.nanoTime();
+ for ( int iteration = 0; iteration < iterations; iteration++ ) {
+ fput(13, addr + (1 * 3 + 0) * 4);
+ fput(fget(addr + (1 * 3 + 1) * 4) + fget(addr + (1 * 3 + 1) * 4) * fget(addr + (1 * 3 + 0) * 4) + 0.3f, addr + (1 * 3 + 1) * 4);
+ fput(fget(addr + (1 * 3 + 2) * 4) + fget(addr + (2 * 3 + 1) * 4) + fget(addr + (1 * 3 + 0) * 4) + 0.3f, addr + (1 * 3 + 2) * 4);
+ fput(fget(addr + (2 * 3 + 2) * 4) + fget(addr + (2 * 3 + 1) * 4) + fget(addr + (1 * 3 + 0) * 4), addr + (2 * 3 + 2) * 4);
+ fput(fget(addr + (3 * 3 + 2) * 4) + fget(addr + (2 * 3 + 2) * 4) + fget(addr + (2 * 3 + 1) * 4), addr + (3 * 3 + 2) * 4);
+ }
+ long t1 = System.nanoTime();
+ took[run] = t1 - t0;
+ }
+
+ Arrays.sort(took);
+ System.out.println("unsafe took: " + took[took.length / 2] / 1024 + "us");
+
+ System.out.println(bb);
+ }
+
+}
\ No newline at end of file
Added: trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java 2011-07-12 13:29:04 UTC (rev 3571)
@@ -0,0 +1,159 @@
+/*
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.test.mapped;
+
+import org.lwjgl.util.mapped.MappedHelper;
+import org.lwjgl.util.mapped.MappedObjectUnsafe;
+
+import java.nio.ByteBuffer;
+
+/** @author Riven */
+@SuppressWarnings("static-access")
+public class MappedObjectTests1 {
+
+ static class Test {
+
+ int value;
+ }
+
+ static void testViewField() {
+ Test test = new Test();
+ test.value = 13;
+ test.value += 1;
+ test.value++;
+ System.out.println(test);
+
+ ByteBuffer bb = ByteBuffer.allocateDirect(200);
+ MappedFloat vecs = MappedFloat.map(bb);
+
+ // verify 'malloc' and SIZEOF
+ {
+ MappedFloat vecs1 = MappedFloat.malloc(1234);
+
+ assert (vecs1.stride == MappedFloat.SIZEOF);
+ assert (vecs1.stride * 1234 == vecs1.backingByteBuffer().capacity());
+ assert (MappedFloat.SIZEOF * 1234 == vecs1.backingByteBuffer().capacity());
+ }
+
+ // manipulate 'mapped.value'
+ {
+ assert (vecs.value == 0.0f); // 4.0 is set in constructor, but runViewConstructor is not called
+ vecs.value = 1.1f;
+ assert (vecs.value == 1.1f);
+ }
+
+ // manipulate 'view' with assignment
+ {
+ assert (vecs.view == 0);
+ vecs.view = 1;
+ assert (vecs.view == 1);
+ assert (vecs.value != 1.1f); // old view
+ vecs.view = 0;
+ }
+
+ // manipulate 'view' with iinc
+ {
+ assert (vecs.view == 0);
+ vecs.view++;
+ assert (vecs.view == 1);
+ assert (vecs.value != 1.1f); // old view
+ vecs.view = 0;
+ }
+
+ // test bound check
+ {
+ assert (vecs.view == 0);
+ try {
+ vecs.view = 50;
+ System.out.println("org.lwjgl.util.mapped.Checks is false or there is a bug in bounds checking.");
+ vecs.view = 0;
+ } catch (IndexOutOfBoundsException e) {
+ // expected, ignore
+ }
+ assert (vecs.view == 0);
+ }
+
+ // test dup
+ {
+ int newStride = 16;
+ int doOffset = 0;
+
+ vecs.view = 0;
+ MappedFloat.configure(vecs, newStride, doOffset);
+ MappedFloat dec2 = vecs.dup();
+ MappedFloat.configure(dec2, newStride, doOffset);
+
+ String s1 = vecs.baseAddress + "," + vecs.viewAddress + "," + vecs.stride + "," + vecs.SIZEOF;
+ String s2 = dec2.baseAddress + "," + dec2.viewAddress + "," + dec2.stride + "," + dec2.SIZEOF;
+ // System.out.println(s1);
+ // System.out.println(s2);
+ assert (s1.equals(s2));
+
+ dec2.view++;
+
+ String s3 = vecs.baseAddress + "," + vecs.viewAddress + "," + vecs.stride + "," + vecs.SIZEOF;
+ String s4 = dec2.baseAddress + "," + dec2.viewAddress + "," + dec2.stride + "," + dec2.SIZEOF;
+ // System.out.println(s3);
+ // System.out.println(s4);
+ assert (!s3.equals(s4));
+ }
+
+ // test newBuffer
+ {
+ long addr1 = MappedObjectUnsafe.getBufferBaseAddress(bb);
+ ByteBuffer bb2 = MappedHelper.newBuffer(addr1, bb.capacity());
+ long addr2 = MappedObjectUnsafe.getBufferBaseAddress(bb);
+
+ System.out.println(bb);
+ System.out.println(bb2);
+ System.out.println(addr1);
+ System.out.println(addr2);
+ }
+
+ // test 'copy'
+ {
+ vecs.value = 13.37f;
+ MappedFloat dec2 = vecs.dup();
+ dec2.view = 1;
+ System.out.println(vecs);
+ System.out.println(dec2);
+ vecs.copyTo(dec2);
+ System.out.println(vecs);
+ System.out.println(dec2);
+ assert (dec2.value == 13.37f);
+
+ vecs.value = 73.31f;
+ vecs.copyRange(dec2, 1);
+ assert (dec2.value == 73.31f);
+ }
+ }
+}
Added: trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests2.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests2.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests2.java 2011-07-12 13:29:04 UTC (rev 3571)
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.test.mapped;
+
+import java.nio.ByteBuffer;
+
+/** @author Riven */
+@SuppressWarnings("static-access")
+public class MappedObjectTests2 {
+
+ static void testWriteFieldAccess(MappedVec3 vecs) {
+ // write access results into a transform-time IllegalAccessException
+
+ System.out.println(vecs.baseAddress); // test read-access
+
+ System.out.println(vecs.viewAddress); // test read-access
+
+ System.out.println(vecs.align); // test read-access
+
+ System.out.println(MappedVec3.SIZEOF); // test read-access
+ }
+
+ static void testFields() {
+ ByteBuffer bb = ByteBuffer.allocateDirect(200);
+ MappedVec3 vecs = MappedVec3.map(bb);
+
+ testWriteFieldAccess(vecs);
+
+ vecs.x = 13.13f;
+ vecs.y = 14.14f;
+ vecs.z = 15.15f;
+
+ System.out.println(vecs.viewAddress);
+
+ assert (vecs.x == 13.13f);
+ assert (vecs.y == 14.14f);
+ assert (vecs.z == 15.15f);
+
+ vecs.view = 0;
+
+ assert (vecs.x == 13.13f);
+ assert (vecs.y == 14.14f);
+ assert (vecs.z == 15.15f);
+
+ System.out.println(vecs);
+ vecs.view = 1;
+ System.out.println(vecs);
+
+ assert (vecs.x == 0.0f);
+ assert (vecs.y == 0.0f);
+ assert (vecs.z == 0.0f);
+
+ // now it becomes weird: offsets and strides
+
+ vecs.view = 1;
+ vecs.x = 0.1234f;
+ vecs.view = 0;
+
+ // test stride & sizeof
+ {
+ long a1 = vecs.viewAddress;
+ vecs.view = 1;
+ long a2 = vecs.viewAddress;
+ assert (a2 - a1 == MappedVec3.SIZEOF);
+ assert (a2 - a1 == vecs.stride);
+ vecs.view = 0;
+ }
+
+ int newStride = 16;
+
+ MappedVec3.configure(vecs, newStride, +4);
+ assert (vecs.z == 0.1234f); // vecs[1].x ended up in vecs[0].z due to 1float offset
+
+ MappedVec3.configure(vecs, newStride, +8);
+ assert (vecs.z == 0.0000f); // vecs[1].z ended up in vecs[0].z due to 2float offset
+
+ // test new stride
+ {
+ long a1 = vecs.viewAddress;
+ vecs.view = 1;
+ long a2 = vecs.viewAddress;
+ assert (a2 - a1 == newStride);
+ vecs.view = 0;
+ }
+
+ // example: GPU => VBO => VTN
+ {
+ MappedVec3 v = MappedVec3.map(bb);
+ MappedVec2 t = MappedVec2.map(bb);
+ MappedVec3 n = MappedVec3.map(bb);
+
+ int stride = MappedVec3.SIZEOF + MappedVec2.SIZEOF + MappedVec3.SIZEOF;
+ assert (stride == 32);
+
+ MappedVec3.configure(v, stride, 0);
+ MappedVec2.configure(t, stride, MappedVec3.SIZEOF);
+ MappedVec3.configure(n, stride, MappedVec3.SIZEOF + MappedVec2.SIZEOF);
+ }
+ }
+
+}
\ No newline at end of file
Added: trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests3.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests3.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests3.java 2011-07-12 13:29:04 UTC (rev 3571)
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.test.mapped;
+
+import org.lwjgl.util.mapped.*;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+
+import static org.lwjgl.util.mapped.MappedObject.*;
+
+/** @author Riven */
+@SuppressWarnings("static-access")
+public class MappedObjectTests3 {
+
+ static void testMappedBuffer() {
+ int elementCount = 4;
+
+ MappedSomething some = MappedSomething.malloc(elementCount);
+
+ assert (some.data != some.data);
+
+ long addr1 = MappedObjectUnsafe.getBufferBaseAddress(some.backingByteBuffer());
+
+ ByteBuffer mapped = some.data; // creates new ByteBuffer instance
+ long addr2 = MappedObjectUnsafe.getBufferBaseAddress(mapped);
+
+ assert (addr2 - addr1 == 4);
+ assert (mapped.capacity() == MappedSomething.SIZEOF - 4);
+
+ some.view++;
+ mapped = some.data; // creates new ByteBuffer instance
+
+ long addr3 = MappedObjectUnsafe.getBufferBaseAddress(mapped);
+ assert (addr3 - addr1 == 4 + MappedSomething.SIZEOF);
+ assert (addr3 - addr2 == 0 + MappedSomething.SIZEOF);
+ assert (mapped.capacity() == MappedSomething.SIZEOF - 4);
+ }
+
+ static void testForeach() {
+ int elementCount = 4;
+ MappedSomething some = MappedSomething.malloc(elementCount);
+
+ int i = 0;
+ for ( MappedSomething item : foreach(some, elementCount) ) {
+ assert (item.view == i++);
+ }
+ assert (some.view != elementCount);
+ System.out.println("current.view=" + some.view + ", not " + elementCount + ", as you might expect");
+ }
+
+ @MappedType(sizeof = 12)
+ public static class Xyz extends MappedObject {
+
+ int x, y, z;
+ }
+
+ static void testConstructor() {
+ int capacity = 1024;
+ ByteBuffer bb = ByteBuffer.allocateDirect(capacity).order(ByteOrder.nativeOrder());
+ long address = MappedObjectUnsafe.getBufferBaseAddress(bb);
+
+ MappedFloat mf = MappedFloat.map(address, capacity);
+
+ assert (address == mf.baseAddress);
+
+ assert (mf.value == 0.0f);
+ mf.view = 1;
+ assert (mf.value == 0.0f);
+ mf.runViewConstructor();
+ assert (mf.value == 4.0f);
+
+ Xyz.malloc(3);
+ }
+
+ static void testMappedSet() {
+ MappedVec2 vec2 = MappedVec2.malloc(3);
+ MappedVec3 vec3 = MappedVec3.malloc(3);
+
+ MappedSet2 set = MappedSet.create(vec2, vec3);
+
+ assert (vec2.view == 0);
+ assert (vec3.view == 0);
+
+ set.view = 2;
+ assert (vec2.view == 2);
+ assert (vec3.view == 2);
+
+ set.view = 0;
+ assert (vec2.view == 0);
+ assert (vec3.view == 0);
+ }
+
+}
\ No newline at end of file
Added: trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedSomething.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedSomething.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedSomething.java 2011-07-12 13:29:04 UTC (rev 3571)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.test.mapped;
+
+import org.lwjgl.util.mapped.MappedField;
+import org.lwjgl.util.mapped.MappedObject;
+import org.lwjgl.util.mapped.MappedType;
+
+import java.nio.ByteBuffer;
+
+/** @author Riven */
+@MappedType(sizeof = 64)
+public class MappedSomething extends MappedObject {
+
+ @MappedField(byteOffset = 0)
+ public int used;
+
+ @MappedField(byteOffset = 4, byteLength = 64 - 4)
+ public ByteBuffer data;
+
+ @Override
+ public String toString() {
+ return "MappedSomething[" + used + "]";
+ }
+
+}
\ No newline at end of file
Added: trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedVec2.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedVec2.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedVec2.java 2011-07-12 13:29:04 UTC (rev 3571)
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.test.mapped;
+
+import org.lwjgl.util.mapped.MappedObject;
+import org.lwjgl.util.mapped.MappedType;
+
+/** @author Riven */
+@MappedType(sizeof = 8)
+public class MappedVec2 extends MappedObject {
+
+ public float x;
+
+ public float y;
+
+ @Override
+ public String toString() {
+ return "MappedVec2[" + x + "," + y + "]";
+ }
+
+}
\ No newline at end of file
Added: trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedVec3.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedVec3.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedVec3.java 2011-07-12 13:29:04 UTC (rev 3571)
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.test.mapped;
+
+import org.lwjgl.util.mapped.MappedObject;
+import org.lwjgl.util.mapped.MappedType;
+
+/** @author Riven */
+@MappedType(sizeof = 12)
+public class MappedVec3 extends MappedObject {
+
+ public float x;
+
+ public float y;
+
+ public float z;
+
+ @Override
+ public String toString() {
+ return "[" + x + "," + y + "," + z + "]";
+ }
+
+}
\ No newline at end of file
Added: trunk/LWJGL/src/java/org/lwjgl/test/mapped/TestMappedObject.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/test/mapped/TestMappedObject.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/test/mapped/TestMappedObject.java 2011-07-12 13:29:04 UTC (rev 3571)
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.test.mapped;
+
+import org.lwjgl.util.mapped.MappedObjectClassLoader;
+import org.lwjgl.util.mapped.MappedObjectTransformer;
+
+/** @author Riven */
+public class TestMappedObject {
+
+ static {
+ boolean assertsEnabled = false;
+ assert assertsEnabled = true; // Intentional side effect!!!
+ if ( !assertsEnabled )
+ throw new RuntimeException("Asserts must be enabled for this test.");
+ }
+
+ public static void main(String[] args) {
+ MappedObjectTransformer.register(MappedFloat.class);
+ MappedObjectTransformer.register(MappedVec2.class);
+ MappedObjectTransformer.register(MappedVec3.class);
+ MappedObjectTransformer.register(MappedSomething.class);
+
+ MappedObjectTransformer.register(MappedObjectTests3.Xyz.class);
+
+ if ( MappedObjectClassLoader.fork(TestMappedObject.class, args) ) {
+ return;
+ }
+
+ MappedObjectTests1.testViewField();
+
+ MappedObjectTests2.testFields();
+
+ // MappedObjectBench.benchmarkMapped();
+ // MappedObjectBench.benchmarkInstances();
+ // MappedObjectBench.benchmarkIndirectArray();
+ // MappedObjectBench.benchmarkDirectArray();
+ // MappedObjectBench.benchmarkUnsafe();
+
+ MappedObjectTests3.testMappedBuffer();
+ MappedObjectTests3.testForeach();
+ MappedObjectTests3.testConstructor();
+ MappedObjectTests3.testMappedSet();
+ }
+
+}
\ No newline at end of file
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedField.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedField.java 2011-07-12 07:27:00 UTC (rev 3570)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedField.java 2011-07-12 13:29:04 UTC (rev 3571)
@@ -1,19 +1,65 @@
/*
- * Created on Jun 24, 2011
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.util.mapped;
+import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
/**
+ * This annotation can be used on fields of {@link MappedType} classes,
+ * to manually specify byte offsets and lengths. This is useful when the
+ * mapped fields require custom alignment. {@link java.nio.ByteBuffer}
+ * fields are required to have this annotation with a hardcoded byte length.
+ *
* @author Riven
*/
-
@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.FIELD)
public @interface MappedField {
- long byteOffset();
- long byteLength() default -1;
-}
+ /**
+ * Specifies the field byte offset within the mapped object.
+ *
+ * @return the field byte offset
+ */
+ long byteOffset();
+
+ /**
+ * Specifies the field byte length. Required for {@link java.nio.ByteBuffer} fields.
+ *
+ * @return the field byte length
+ */
+ long byteLength() default -1;
+
+}
\ No newline at end of file
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedForeach.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedForeach.java 2011-07-12 07:27:00 UTC (rev 3570)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedForeach.java 2011-07-12 13:29:04 UTC (rev 3571)
@@ -1,52 +1,72 @@
/*
- * Created on Jul 4, 2011
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.util.mapped;
import java.util.Iterator;
/**
+ * Iterable implementation for {@link MappedObject}.
+ *
* @author Riven
*/
+public class MappedForeach<T extends MappedObject> implements Iterable<T> {
-public class MappedForeach<T extends MappedObject> implements Iterable<T>
-{
- final T mapped;
- final int elementCount;
+ private final T mapped;
+ private final int elementCount;
- MappedForeach(T mapped, int elementCount)
- {
- this.mapped = mapped;
- this.elementCount = elementCount;
- }
+ MappedForeach(T mapped, int elementCount) {
+ this.mapped = mapped;
+ this.elementCount = elementCount;
+ }
- @Override
- public Iterator<T> iterator()
- {
- return new Iterator<T>()
- {
- private int index = 0;
+ public Iterator<T> iterator() {
+ return new Iterator<T>() {
- @Override
- public boolean hasNext()
- {
- return this.index < (MappedForeach.this.elementCount);
- }
+ private int index;
- @Override
- public T next()
- {
- mapped.viewAddress = mapped.baseAddress + (this.index++) * mapped.stride;
+ public boolean hasNext() {
+ return this.index < (MappedForeach.this.elementCount);
+ }
- return mapped;
- }
+ public T next() {
+ mapped.viewAddress = mapped.baseAddress + (this.index++) * mapped.stride;
- @Override
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
- };
- }
-}
+ return mapped;
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+
+}
\ No newline at end of file
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java 2011-07-12 07:27:00 UTC (rev 3570)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java 2011-07-12 13:29:04 UTC (rev 3571)
@@ -1,181 +1,188 @@
/*
- * Created on Jun 28, 2011
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.util.mapped;
import java.nio.ByteBuffer;
/**
+ * [INTERNAL USE ONLY]
+ * <p/>
+ * Helper class used by the bytecode transformer.
+ *
* @author Riven
*/
+public class MappedHelper {
-public class MappedHelper
-{
- public static void setup(MappedObject mo, ByteBuffer buffer, int align, int sizeof)
- {
- if (mo.baseAddress != 0L)
- throw new IllegalStateException("this method should not be called by user-code");
+ public static void setup(MappedObject mo, ByteBuffer buffer, int align, int sizeof) {
+ if ( mo.baseAddress != 0L )
+ throw new IllegalStateException("this method should not be called by user-code");
- if (buffer == null)
- throw new NullPointerException("buffer");
- if (!buffer.isDirect())
- throw new IllegalArgumentException("bytebuffer must be direct");
- mo.preventGC = buffer;
+ if ( buffer == null )
+ throw new NullPointerException("buffer");
+ if ( !buffer.isDirect() )
+ throw new IllegalArgumentException("bytebuffer must be direct");
+ mo.preventGC = buffer;
- if (align <= 0)
- throw new IllegalArgumentException("invalid alignment");
- mo.align = align;
+ if ( align <= 0 )
+ throw new IllegalArgumentException("invalid alignment");
+ mo.align = align;
- if (sizeof % align != 0)
- throw new IllegalStateException("sizeof not a multiple of alignment");
- mo.stride = sizeof;
+ if ( sizeof % align != 0 )
+ throw new IllegalStateException("sizeof not a multiple of alignment");
+ mo.stride = sizeof;
- long addr = MappedObjectUnsafe.getBufferBaseAddress(buffer);
- if (addr % align != 0)
- throw new IllegalStateException("buffer address not aligned on " + align + " bytes");
+ long addr = MappedObjectUnsafe.getBufferBaseAddress(buffer);
+ if ( addr % align != 0 )
+ throw new IllegalStateException("buffer address not aligned on " + align + " bytes");
- mo.baseAddress = mo.viewAddress = addr;
- }
+ mo.baseAddress = mo.viewAddress = addr;
+ }
- public static void put_views(MappedSet2 set, int view)
- {
- set.view(view);
- }
+ public static void put_views(MappedSet2 set, int view) {
+ set.view(view);
+ }
- public static void put_views(MappedSet3 set, int view)
- {
- set.view(view);
- }
+ public static void put_views(MappedSet3 set, int view) {
+ set.view(view);
+ }
- public static void put_views(MappedSet4 set, int view)
- {
- set.view(view);
- }
+ public static void put_views(MappedSet4 set, int view) {
+ set.view(view);
+ }
- public static void put_view(MappedObject mapped, int view)
- {
- mapped.viewAddress = mapped.baseAddress + view * mapped.stride;
- }
+ public static void put_view(MappedObject mapped, int view) {
+ mapped.setViewAddress(mapped.baseAddress + view * mapped.stride);
+ }
- public static int get_view(MappedObject mapped)
- {
- return (int) (mapped.viewAddress - mapped.baseAddress) / mapped.stride;
- }
+ public static int get_view(MappedObject mapped) {
+ return (int)(mapped.viewAddress - mapped.baseAddress) / mapped.stride;
+ }
- public static MappedObject dup(MappedObject src, MappedObject dst)
- {
- dst.baseAddress = src.baseAddress;
- dst.viewAddress = src.viewAddress;
- dst.stride = src.stride;
- dst.align = src.align;
- dst.preventGC = src.preventGC;
- return dst;
- }
+ public static MappedObject dup(MappedObject src, MappedObject dst) {
+ dst.baseAddress = src.baseAddress;
+ dst.viewAddress = src.viewAddress;
+ dst.stride = src.stride;
+ dst.align = src.align;
+ dst.preventGC = src.preventGC;
+ return dst;
+ }
- public static MappedObject slice(MappedObject src, MappedObject dst)
- {
- dst.baseAddress = src.viewAddress; // !
- dst.viewAddress = src.viewAddress;
- dst.stride = src.stride;
- dst.align = src.align;
- dst.preventGC = src.preventGC;
- return dst;
- }
+ public static MappedObject slice(MappedObject src, MappedObject dst) {
+ dst.baseAddress = src.viewAddress; // !
+ dst.viewAddress = src.viewAddress;
+ dst.stride = src.stride;
+ dst.align = src.align;
+ dst.preventGC = src.preventGC;
+ return dst;
+ }
- public static void copy(MappedObject src, MappedObject dst, int bytes)
- {
- MappedObjectUnsafe.INSTANCE.copyMemory(src.viewAddress, dst.viewAddress, bytes);
- }
+ public static void copy(MappedObject src, MappedObject dst, int bytes) {
+ MappedObjectUnsafe.INSTANCE.copyMemory(src.viewAddress, dst.viewAddress, bytes);
+ }
- public static ByteBuffer newBuffer(long address, int capacity)
- {
- return MappedObjectUnsafe.newBuffer(address, capacity);
- }
+ public static ByteBuffer newBuffer(long address, int capacity) {
+ return MappedObjectUnsafe.newBuffer(address, capacity);
+ }
- // ---- primitive fields read/write
+ // ---- primitive fields read/write
- // byte
+ // byte
- public static void bput(byte value, long addr)
- {
- MappedObjectUnsafe.INSTANCE.putByte(addr, value);
- }
+ public static void bput(byte value, long addr) {
+ MappedObjectUnsafe.INSTANCE.putByte(addr, value);
+ }
- public static byte bget(long addr)
- {
- return MappedObjectUnsafe.INSTANCE.getByte(addr);
- }
+ public static byte bget(long addr) {
+ return MappedObjectUnsafe.INSTANCE.getByte(addr);
+ }
- // short
+ // short
- public static void sput(short value, long addr)
- {
- MappedObjectUnsafe.INSTANCE.putShort(addr, value);
- }
+ public static void sput(short value, long addr) {
+ MappedObjectUnsafe.INSTANCE.putShort(addr, value);
+ }
- public static short sget(long addr)
- {
- return MappedObjectUnsafe.INSTANCE.getShort(addr);
- }
+ public static short sget(long addr) {
+ return MappedObjectUnsafe.INSTANCE.getShort(addr);
+ }
- // char
+ // char
- public static void cput(char value, long addr)
- {
- MappedObjectUnsafe.INSTANCE.putChar(addr, value);
- }
+ public static void cput(char value, long addr) {
+ MappedObjectUnsafe.INSTANCE.putChar(addr, value);
+ }
- public static char cget(long addr)
- {
- return MappedObjectUnsafe.INSTANCE.getChar(addr);
- }
+ public static char cget(long addr) {
+ return MappedObjectUnsafe.INSTANCE.getChar(addr);
+ }
- // int
+ // int
- public static void iput(int value, long addr)
- {
- MappedObjectUnsafe.INSTANCE.putInt(addr, value);
- }
+ public static void iput(int value, long addr) {
+ MappedObjectUnsafe.INSTANCE.putInt(addr, value);
+ }
- public static int iget(long addr)
- {
- return MappedObjectUnsafe.INSTANCE.getInt(addr);
- }
+ public static int iget(long addr) {
+ return MappedObjectUnsafe.INSTANCE.getInt(addr);
+ }
- // float
+ // float
- public static void fput(float value, long addr)
- {
- MappedObjectUnsafe.INSTANCE.putFloat(addr, value);
- }
+ public static void fput(float value, long addr) {
+ MappedObjectUnsafe.INSTANCE.putFloat(addr, value);
+ }
- public static float fget(long addr)
- {
- return MappedObjectUnsafe.INSTANCE.getFloat(addr);
- }
+ public static float fget(long addr) {
+ return MappedObjectUnsafe.INSTANCE.getFloat(addr);
+ }
- // long
+ // long
- public static void jput(long value, long addr)
- {
- MappedObjectUnsafe.INSTANCE.putLong(addr, value);
- }
+ public static void jput(long value, long addr) {
+ MappedObjectUnsafe.INSTANCE.putLong(addr, value);
+ }
- public static long jget(long addr)
- {
- return MappedObjectUnsafe.INSTANCE.getLong(addr);
- }
+ public static long jget(long addr) {
+ return MappedObjectUnsafe.INSTANCE.getLong(addr);
+ }
- // double
+ // double
- public static void dput(double value, long addr)
- {
- MappedObjectUnsafe.INSTANCE.putDouble(addr, value);
- }
+ public static void dput(double value, long addr) {
+ MappedObjectUnsafe.INSTANCE.putDouble(addr, value);
+ }
- public static double dget(long addr)
- {
- return MappedObjectUnsafe.INSTANCE.getDouble(addr);
- }
+ public static double dget(long addr) {
+ return MappedObjectUnsafe.INSTANCE.getDouble(addr);
+ }
+
}
\ No newline at end of file
Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java 2011-07-12 07:27:00 UTC (rev 3570)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java 2011-07-12 13:29:04 UTC (rev 3571)
@@ -1,185 +1,248 @@
/*
- * Created on Jun 25, 2011
+ * Copyright (c) 2002-2011 LWJGL Project
+ * 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 'LWJGL' 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 org.lwjgl.util.mapped;
+import org.lwjgl.LWJGLUtil;
+
import java.nio.ByteBuffer;
/**
+ * Base superclass of all mapped objects. Classes that require
+ * data mapping should extend this class and also be annotated
+ * with {@link MappedType}.
+ * <p/>
+ * Subclasses may only specify the default constructor. Any code
+ * inside that constructor is optional, but will not run when the
+ * view is instantiated, see {@link #runViewConstructor()}.
+ * <p/>
+ * Bounds checking may be enabled through a JVM system property: org.lwjgl.util.mapped.Checks=true
+ *
* @author Riven
*/
+public class MappedObject {
-public class MappedObject
-{
- public MappedObject()
- {
- //
- }
+ static final boolean CHECKS = LWJGLUtil.getPrivilegedBoolean("org.lwjgl.util.mapped.Checks");
- // these fields are not assignable/writable by user-code
- public long baseAddress;
- public long viewAddress;
- public int stride;
- public int align;
+ public MappedObject() {
+ //
+ }
- /**
- * Holds the value of sizeof of the sub-type of this MappedObject<br>
- * <br>
- * The behavior of this (transformed) method does not follow the normal Java behavior.<br>
- * <code>Vec2.SIZEOF</code> will yield 8 (2 floats)<br>
- * <code>Vec3.SIZEOF</code> will yield 12 (3 floats)<br>
- * This (required) notation might cause compiler warnings, which can be suppressed with @SuppressWarnings("static-access").<br>
- * Using Java 5.0's static-import on this method will break functionality.
- */
+ /** The mapped object base memory address, in bytes. Read-only. */
+ public long baseAddress;
- // any method that calls these field will have its call-site modified
- public static int SIZEOF = -1; // 'final' per subtype
- public int view; // read/write
+ /** The mapped object view memory address, in bytes. Read-only. */
+ public long viewAddress;
- public final void next()
- {
- this.viewAddress += this.stride;
- }
+ /** The mapped object stride, in bytes. Read-only. */
+ public int stride;
- /**
- * Creates a MappedObject instance, mapping the memory region of the specified direct ByteBuffer.<br>
- * <br>
- * The behavior of this (transformed) method does not follow the normal Java behavior.<br>
- * <code>Vec2.map(buffer)</code> will return a mapped Vec2 instance.<br>
- * <code>Vec3.map(buffer)</code> will return a mapped Vec3 instance.<br>
- * This (required) notation might cause compiler warnings, which can be suppressed with @SuppressWarnings("static-access").<br>
- * Using Java 5.0's static-import on this method will break functionality.
- */
+ /** The mapped object memory alignment, in bytes. Read-only. */
+ public int align;
- @SuppressWarnings("unused")
- public static <T extends MappedObject> T map(ByteBuffer bb)
- {
- // any method that calls this method will have its call-site modified
- throw new InternalError("type not registered");
- }
+ /**
+ * Holds the value of sizeof of the sub-type of this MappedObject<br>
+ * <br>
+ * The behavior of this (transformed) method does not follow the normal Java behavior.<br>
+ * <code>Vec2.SIZEOF</code> will yield 8 (2 floats)<br>
+ * <code>Vec3.SIZEOF</code> will yield 12 (3 floats)<br>
+ * This (required) notation might cause compiler warnings, which can be suppressed with @SuppressWarnings("static-access").<br>
+ * Using Java 5.0's static-import on this method will break functionality.
+ */
+ public static int SIZEOF = -1; // any method that calls these field will have its call-site modified ('final' per subtype)
- @SuppressWarnings("unused")
- public static <T extends MappedObject> T map(long address, int capacity)
- {
- // any method that calls this method will have its call-site modified
- throw new InternalError("ty...
[truncated message content] |
|
From: <ma...@us...> - 2011-07-12 07:27:06
|
Revision: 3570
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3570&view=rev
Author: matzon
Date: 2011-07-12 07:27:00 +0000 (Tue, 12 Jul 2011)
Log Message:
-----------
reverse merging r3567
Removed Paths:
-------------
LWJGL/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <sp...@us...> - 2011-07-11 22:21:46
|
Revision: 3569
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3569&view=rev
Author: spasi
Date: 2011-07-11 22:21:40 +0000 (Mon, 11 Jul 2011)
Log Message:
-----------
Added ASM to compilation classpath.
Modified Paths:
--------------
trunk/LWJGL/build.xml
Modified: trunk/LWJGL/build.xml
===================================================================
--- trunk/LWJGL/build.xml 2011-07-11 21:46:00 UTC (rev 3568)
+++ trunk/LWJGL/build.xml 2011-07-11 22:21:40 UTC (rev 3569)
@@ -404,7 +404,7 @@
<!-- Compiles the Java source code -->
<target name="compile" description="Compiles the java source code" depends="-initialize">
- <javac debug="yes" destdir="${lwjgl.bin}" source="1.5" target="1.5" classpath="${lwjgl.lib}/jinput.jar:${lwjgl.lib}/AppleJavaExtensions.jar" taskname="core">
+ <javac debug="yes" destdir="${lwjgl.bin}" source="1.5" target="1.5" classpath="${lwjgl.lib}/jinput.jar:${lwjgl.lib}/AppleJavaExtensions.jar;${lwjgl.lib}/asm.jar;${lwjgl.lib}/asm-util.jar" taskname="core">
<!--<compilerarg value="-Xlint:unchecked"/>-->
<src path="${lwjgl.src}/java/"/>
<src path="${lwjgl.src}/generated/"/>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <riv...@us...> - 2011-07-11 21:46:08
|
Revision: 3568
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3568&view=rev
Author: riven-lwjgl
Date: 2011-07-11 21:46:00 +0000 (Mon, 11 Jul 2011)
Log Message:
-----------
Initial release of mapped objects library (v0.10) in LWJGL.
Added Paths:
-----------
trunk/LWJGL/libs/asm-util.jar
trunk/LWJGL/libs/asm.jar
trunk/LWJGL/src/java/org/lwjgl/util/mapped/
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedField.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedForeach.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectClassLoader.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectUnsafe.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet2.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet3.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet4.java
trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedType.java
Added: trunk/LWJGL/libs/asm-util.jar
===================================================================
(Binary files differ)
Property changes on: trunk/LWJGL/libs/asm-util.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Added: trunk/LWJGL/libs/asm.jar
===================================================================
(Binary files differ)
Property changes on: trunk/LWJGL/libs/asm.jar
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Property changes on: trunk/LWJGL/src/java/org/lwjgl/util/mapped
___________________________________________________________________
Added: bugtraq:number
+ true
Added: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedField.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedField.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedField.java 2011-07-11 21:46:00 UTC (rev 3568)
@@ -0,0 +1,19 @@
+/*
+ * Created on Jun 24, 2011
+ */
+
+package org.lwjgl.util.mapped;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * @author Riven
+ */
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface MappedField {
+ long byteOffset();
+
+ long byteLength() default -1;
+}
Added: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedForeach.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedForeach.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedForeach.java 2011-07-11 21:46:00 UTC (rev 3568)
@@ -0,0 +1,52 @@
+/*
+ * Created on Jul 4, 2011
+ */
+
+package org.lwjgl.util.mapped;
+
+import java.util.Iterator;
+
+/**
+ * @author Riven
+ */
+
+public class MappedForeach<T extends MappedObject> implements Iterable<T>
+{
+ final T mapped;
+ final int elementCount;
+
+ MappedForeach(T mapped, int elementCount)
+ {
+ this.mapped = mapped;
+ this.elementCount = elementCount;
+ }
+
+ @Override
+ public Iterator<T> iterator()
+ {
+ return new Iterator<T>()
+ {
+ private int index = 0;
+
+ @Override
+ public boolean hasNext()
+ {
+ return this.index < (MappedForeach.this.elementCount);
+ }
+
+ @Override
+ public T next()
+ {
+ mapped.viewAddress = mapped.baseAddress + (this.index++) * mapped.stride;
+
+ return mapped;
+ }
+
+ @Override
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+ };
+ }
+}
Added: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java 2011-07-11 21:46:00 UTC (rev 3568)
@@ -0,0 +1,181 @@
+/*
+ * Created on Jun 28, 2011
+ */
+
+package org.lwjgl.util.mapped;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author Riven
+ */
+
+public class MappedHelper
+{
+ public static void setup(MappedObject mo, ByteBuffer buffer, int align, int sizeof)
+ {
+ if (mo.baseAddress != 0L)
+ throw new IllegalStateException("this method should not be called by user-code");
+
+ if (buffer == null)
+ throw new NullPointerException("buffer");
+ if (!buffer.isDirect())
+ throw new IllegalArgumentException("bytebuffer must be direct");
+ mo.preventGC = buffer;
+
+ if (align <= 0)
+ throw new IllegalArgumentException("invalid alignment");
+ mo.align = align;
+
+ if (sizeof % align != 0)
+ throw new IllegalStateException("sizeof not a multiple of alignment");
+ mo.stride = sizeof;
+
+ long addr = MappedObjectUnsafe.getBufferBaseAddress(buffer);
+ if (addr % align != 0)
+ throw new IllegalStateException("buffer address not aligned on " + align + " bytes");
+
+ mo.baseAddress = mo.viewAddress = addr;
+ }
+
+ public static void put_views(MappedSet2 set, int view)
+ {
+ set.view(view);
+ }
+
+ public static void put_views(MappedSet3 set, int view)
+ {
+ set.view(view);
+ }
+
+ public static void put_views(MappedSet4 set, int view)
+ {
+ set.view(view);
+ }
+
+ public static void put_view(MappedObject mapped, int view)
+ {
+ mapped.viewAddress = mapped.baseAddress + view * mapped.stride;
+ }
+
+ public static int get_view(MappedObject mapped)
+ {
+ return (int) (mapped.viewAddress - mapped.baseAddress) / mapped.stride;
+ }
+
+ public static MappedObject dup(MappedObject src, MappedObject dst)
+ {
+ dst.baseAddress = src.baseAddress;
+ dst.viewAddress = src.viewAddress;
+ dst.stride = src.stride;
+ dst.align = src.align;
+ dst.preventGC = src.preventGC;
+ return dst;
+ }
+
+ public static MappedObject slice(MappedObject src, MappedObject dst)
+ {
+ dst.baseAddress = src.viewAddress; // !
+ dst.viewAddress = src.viewAddress;
+ dst.stride = src.stride;
+ dst.align = src.align;
+ dst.preventGC = src.preventGC;
+ return dst;
+ }
+
+ public static void copy(MappedObject src, MappedObject dst, int bytes)
+ {
+ MappedObjectUnsafe.INSTANCE.copyMemory(src.viewAddress, dst.viewAddress, bytes);
+ }
+
+ public static ByteBuffer newBuffer(long address, int capacity)
+ {
+ return MappedObjectUnsafe.newBuffer(address, capacity);
+ }
+
+ // ---- primitive fields read/write
+
+ // byte
+
+ public static void bput(byte value, long addr)
+ {
+ MappedObjectUnsafe.INSTANCE.putByte(addr, value);
+ }
+
+ public static byte bget(long addr)
+ {
+ return MappedObjectUnsafe.INSTANCE.getByte(addr);
+ }
+
+ // short
+
+ public static void sput(short value, long addr)
+ {
+ MappedObjectUnsafe.INSTANCE.putShort(addr, value);
+ }
+
+ public static short sget(long addr)
+ {
+ return MappedObjectUnsafe.INSTANCE.getShort(addr);
+ }
+
+ // char
+
+ public static void cput(char value, long addr)
+ {
+ MappedObjectUnsafe.INSTANCE.putChar(addr, value);
+ }
+
+ public static char cget(long addr)
+ {
+ return MappedObjectUnsafe.INSTANCE.getChar(addr);
+ }
+
+ // int
+
+ public static void iput(int value, long addr)
+ {
+ MappedObjectUnsafe.INSTANCE.putInt(addr, value);
+ }
+
+ public static int iget(long addr)
+ {
+ return MappedObjectUnsafe.INSTANCE.getInt(addr);
+ }
+
+ // float
+
+ public static void fput(float value, long addr)
+ {
+ MappedObjectUnsafe.INSTANCE.putFloat(addr, value);
+ }
+
+ public static float fget(long addr)
+ {
+ return MappedObjectUnsafe.INSTANCE.getFloat(addr);
+ }
+
+ // long
+
+ public static void jput(long value, long addr)
+ {
+ MappedObjectUnsafe.INSTANCE.putLong(addr, value);
+ }
+
+ public static long jget(long addr)
+ {
+ return MappedObjectUnsafe.INSTANCE.getLong(addr);
+ }
+
+ // double
+
+ public static void dput(double value, long addr)
+ {
+ MappedObjectUnsafe.INSTANCE.putDouble(addr, value);
+ }
+
+ public static double dget(long addr)
+ {
+ return MappedObjectUnsafe.INSTANCE.getDouble(addr);
+ }
+}
\ No newline at end of file
Added: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java 2011-07-11 21:46:00 UTC (rev 3568)
@@ -0,0 +1,185 @@
+/*
+ * Created on Jun 25, 2011
+ */
+
+package org.lwjgl.util.mapped;
+
+import java.nio.ByteBuffer;
+
+/**
+ * @author Riven
+ */
+
+public class MappedObject
+{
+ public MappedObject()
+ {
+ //
+ }
+
+ // these fields are not assignable/writable by user-code
+ public long baseAddress;
+ public long viewAddress;
+ public int stride;
+ public int align;
+
+ /**
+ * Holds the value of sizeof of the sub-type of this MappedObject<br>
+ * <br>
+ * The behavior of this (transformed) method does not follow the normal Java behavior.<br>
+ * <code>Vec2.SIZEOF</code> will yield 8 (2 floats)<br>
+ * <code>Vec3.SIZEOF</code> will yield 12 (3 floats)<br>
+ * This (required) notation might cause compiler warnings, which can be suppressed with @SuppressWarnings("static-access").<br>
+ * Using Java 5.0's static-import on this method will break functionality.
+ */
+
+ // any method that calls these field will have its call-site modified
+ public static int SIZEOF = -1; // 'final' per subtype
+ public int view; // read/write
+
+ public final void next()
+ {
+ this.viewAddress += this.stride;
+ }
+
+ /**
+ * Creates a MappedObject instance, mapping the memory region of the specified direct ByteBuffer.<br>
+ * <br>
+ * The behavior of this (transformed) method does not follow the normal Java behavior.<br>
+ * <code>Vec2.map(buffer)</code> will return a mapped Vec2 instance.<br>
+ * <code>Vec3.map(buffer)</code> will return a mapped Vec3 instance.<br>
+ * This (required) notation might cause compiler warnings, which can be suppressed with @SuppressWarnings("static-access").<br>
+ * Using Java 5.0's static-import on this method will break functionality.
+ */
+
+ @SuppressWarnings("unused")
+ public static <T extends MappedObject> T map(ByteBuffer bb)
+ {
+ // any method that calls this method will have its call-site modified
+ throw new InternalError("type not registered");
+ }
+
+ @SuppressWarnings("unused")
+ public static <T extends MappedObject> T map(long address, int capacity)
+ {
+ // any method that calls this method will have its call-site modified
+ throw new InternalError("type not registered");
+ }
+
+ /**
+ * Creates a MappedObject instance, mapping the memory region of an allocated direct ByteBuffer with a capacity of <code>elementCount*SIZEOF</code>
+ * <br>
+ * The behavior of this (transformed) method does not follow the normal Java behavior.<br>
+ * <code>Vec2.malloc(int)</code> will return a mapped Vec2 instance.<br>
+ * <code>Vec3.malloc(int)</code> will return a mapped Vec3 instance.<br>
+ * This (required) notation might cause compiler warnings, which can be suppressed with @SuppressWarnings("static-access").<br>
+ * Using Java 5.0's static-import on this method will break functionality.
+ */
+
+ @SuppressWarnings("unused")
+ public static <T extends MappedObject> T malloc(int elementCount)
+ {
+ // any method that calls this method will have its call-site modified
+ throw new InternalError("type not registered");
+ }
+
+ /**
+ * Creates an identical new MappedObject instance, comparable to the
+ * contract of ByteBuffer.duplicate()
+ */
+
+ public final <T extends MappedObject> T dup()
+ {
+ // any method that calls this method will have its call-site modified
+ throw new InternalError("type not registered");
+ }
+
+ /**
+ * Creates a new MappedObject instance, with a base offset equal to
+ * the offset of the current view, comparable to the contract of ByteBuffer.slice()
+ */
+
+ public final <T extends MappedObject> T slice()
+ {
+ // any method that calls this method will have its call-site modified
+ throw new InternalError("type not registered");
+ }
+
+ public final <T extends MappedObject> void runViewConstructor()
+ {
+ // any method that calls this method will have its call-site modified
+ throw new InternalError("type not registered");
+ }
+
+ /**
+ * Copies and amount of <code>SIZEOF</code> bytes, from the current
+ * mapped object, to the specified mapped object.
+ */
+
+ @SuppressWarnings("unused")
+ public final <T extends MappedObject> void copyTo(T target)
+ {
+ // any method that calls this method will have its call-site modified
+ throw new InternalError("type not registered");
+ }
+
+ /**
+ * Copies and amount of <code>SIZEOF*instances<c/ode> bytes, from the
+ * current mapped object, to the specified mapped object.
+ */
+
+ @SuppressWarnings("unused")
+ public final <T extends MappedObject> void copyRange(T target, int instances)
+ {
+ // any method that calls this method will have its call-site modified
+ throw new InternalError("type not registered");
+ }
+
+ /**
+ * Creates an Iterable<MappedObject> that will step through
+ * <code>elementCount</code> views, leaving the <code>view</code> at
+ * the last valid value.<br>
+ * <br>
+ * For convenience you are encouraged to static-import this specific method:
+ * <code>import static org.lwjgl.util.mapped.MappedObject.foreach;</code>
+ */
+
+ public static <T extends MappedObject> MappedForeach<T> foreach(T mapped, int elementCount)
+ {
+ return new MappedForeach<T>(mapped, elementCount);
+ }
+
+ /**
+ * Configures a newly initiated mapped object with the specified stride and offset.
+ * @throws IllegalStateException if view is not at index 0
+ */
+
+ public static final <T extends MappedObject> T configure(T mapped, int stride, int offset)
+ {
+ if (mapped.baseAddress != mapped.viewAddress)
+ throw new IllegalStateException("view must be zero");
+
+ if (offset < 0)
+ throw new IllegalStateException("offset must not be negative: " + offset);
+ if (offset % mapped.align != 0)
+ throw new IllegalStateException("offset not a multiple of alignment: " + offset);
+
+ if (stride < mapped.stride)
+ throw new IllegalStateException("new stride must not be smaller than current stride: " + stride);
+ if (stride % mapped.align != 0)
+ throw new IllegalStateException("stride not a multiple of alignment: " + stride);
+
+ mapped.baseAddress += offset;
+ mapped.viewAddress += offset;
+ mapped.stride = stride;
+
+ return mapped;
+ }
+
+ ByteBuffer preventGC;
+
+ public ByteBuffer backingByteBuffer()
+ {
+ return this.preventGC;
+ }
+}
Added: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectClassLoader.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectClassLoader.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectClassLoader.java 2011-07-11 21:46:00 UTC (rev 3568)
@@ -0,0 +1,136 @@
+/*
+ * Created on Jun 24, 2011
+ */
+
+package org.lwjgl.util.mapped;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URLClassLoader;
+import java.util.Arrays;
+
+/**
+ * @author Riven
+ */
+
+public class MappedObjectClassLoader extends URLClassLoader
+{
+ static final String MAPPEDOBJECT_PACKAGE_PREFIX;
+
+ static
+ {
+ MAPPEDOBJECT_PACKAGE_PREFIX = MappedObjectClassLoader.class.getPackage().getName() + ".";
+ }
+
+ static boolean FORKED = false;
+
+ public static boolean fork(Class< ? > mainClass, String[] args)
+ {
+ if (FORKED)
+ {
+ return false;
+ }
+
+ FORKED = true;
+
+ try
+ {
+ URLClassLoader loader = new MappedObjectClassLoader(mainClass);
+ Class< ? > replacedMainClass = loader.loadClass(mainClass.getName());
+ Method mainMethod = replacedMainClass.getMethod("main", String[].class);
+ mainMethod.invoke(null, new Object[] { args });
+ }
+ catch (InvocationTargetException exc)
+ {
+ Thread.currentThread().getUncaughtExceptionHandler().uncaughtException(Thread.currentThread(), exc.getCause());
+ }
+ catch (Throwable cause)
+ {
+ throw new Error("failed to fork", cause);
+ }
+
+ return true;
+ }
+
+ private MappedObjectClassLoader(Class< ? > mainClass)
+ {
+ super(((URLClassLoader) mainClass.getClassLoader()).getURLs());
+ }
+
+ private static long total_time_transforming;
+
+ @Override
+ protected synchronized Class< ? > loadClass(String name, boolean resolve) throws ClassNotFoundException
+ {
+ if (name.startsWith("java."))
+ return super.loadClass(name, resolve);
+ if (name.startsWith("javax."))
+ return super.loadClass(name, resolve);
+
+ if (name.startsWith("sun."))
+ return super.loadClass(name, resolve);
+ if (name.startsWith("sunw."))
+ return super.loadClass(name, resolve);
+
+ // never transform classes in this very package, sub-packages should be transformed
+ if (name.startsWith(MAPPEDOBJECT_PACKAGE_PREFIX))
+ if (name.substring(MAPPEDOBJECT_PACKAGE_PREFIX.length()).indexOf('.') == -1)
+ return super.loadClass(name, resolve);
+
+ String className = name.replace('.', '/');
+
+ if (MappedObjectTransformer.PRINT_ACTIVITY)
+ System.out.println(MappedObjectClassLoader.class.getSimpleName() + ": " + className);
+
+ byte[] bytecode = readStream(this.getResourceAsStream(className.concat(".class")));
+
+ long t0 = System.nanoTime();
+ bytecode = MappedObjectTransformer.transformFieldAccess(className, bytecode);
+ long t1 = System.nanoTime();
+ total_time_transforming += (t1 - t0);
+
+ if (MappedObjectTransformer.PRINT_TIMING)
+ System.out.println("transforming " + className + " took " + (t1 - t0) / 1000 + " micros (total: " + (total_time_transforming / 1000 / 1000) + "ms)");
+
+ Class< ? > clazz = super.defineClass(name, bytecode, 0, bytecode.length);
+ if (resolve)
+ resolveClass(clazz);
+ return clazz;
+ }
+
+ static byte[] readStream(InputStream in)
+ {
+ byte[] bytecode = new byte[256];
+ int len = 0;
+ try
+ {
+ while (true)
+ {
+ if (bytecode.length == len)
+ bytecode = Arrays.copyOf(bytecode, len * 2);
+ int got = in.read(bytecode, len, bytecode.length - len);
+ if (got == -1)
+ break;
+ len += got;
+ }
+ }
+ catch (IOException exc)
+ {
+ // stop!
+ }
+ finally
+ {
+ try
+ {
+ in.close();
+ }
+ catch (IOException exc)
+ {
+ // ignore...
+ }
+ }
+ return Arrays.copyOf(bytecode, len);
+ }
+}
Added: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java 2011-07-11 21:46:00 UTC (rev 3568)
@@ -0,0 +1,588 @@
+/*
+ * Created on Jun 23, 2011
+ */
+
+package org.lwjgl.util.mapped;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.nio.ByteBuffer;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.objectweb.asm.*;
+import org.objectweb.asm.util.TraceClassVisitor;
+import static org.objectweb.asm.Opcodes.*;
+
+/**
+ * @author Riven
+ */
+
+public class MappedObjectTransformer
+{
+ static final boolean PRINT_TIMING = true;
+ static final boolean PRINT_ACTIVITY = false;
+ static final boolean PRINT_BYTECODE = false;
+ static final Map<String, MappedSubtypeInfo> className_to_subtype;
+
+ static
+ {
+ className_to_subtype = new HashMap<String, MappedSubtypeInfo>();
+
+ {
+ // HACK: required for mapped.view++
+ //
+ // because the compiler generates:
+ // => GETFIELD MappedObject.view
+ // => ICONST_1
+ // => IADD
+ // => PUTFIELD MyMappedType.view
+ //
+ // instead of:
+ // => GETFIELD MyMappedType.view
+ // => ICONST_1
+ // => IADD
+ // => PUTFIELD MyMappedType.view
+ //
+ MappedSubtypeInfo info = new MappedSubtypeInfo(jvmClassName(MappedObject.class), -1, -1);
+ className_to_subtype.put(info.className, info);
+ }
+
+ String vmName = System.getProperty("java.vm.name");
+ if (vmName != null && !vmName.contains("Server"))
+ {
+ System.err.println("Warning: " + MappedObject.class.getSimpleName() + "s have inferiour performance on Client VMs, please consider switching to a Server VM.");
+ }
+ }
+
+ public static void register(Class< ? > type)
+ {
+ if (MappedObjectClassLoader.FORKED)
+ return;
+
+ MappedType mapped = type.getAnnotation(MappedType.class);
+ if (mapped == null)
+ throw new InternalError("missing " + MappedType.class.getName() + " annotation");
+
+ String className = jvmClassName(type);
+
+ MappedSubtypeInfo mappedType = new MappedSubtypeInfo(className, mapped.sizeof(), mapped.align());
+
+ int advancingOffset = 0;
+
+ for (Field field : type.getDeclaredFields())
+ {
+ // static fields are never mapped
+ if ((field.getModifiers() & Modifier.STATIC) != 0)
+ continue;
+
+ // we only support primitives and ByteBuffers
+ if (!field.getType().isPrimitive() && field.getType() != ByteBuffer.class)
+ throw new InternalError("field '" + className + "." + field.getName() + "' not supported: " + field.getType());
+
+ MappedField meta = field.getAnnotation(MappedField.class);
+ if (meta == null && !mapped.autoGenerateOffsets())
+ throw new InternalError("field '" + className + "." + field.getName() + "' missing annotation " + MappedField.class.getName() + ": " + className);
+
+ // quick hack
+ long byteOffset = meta == null ? advancingOffset : meta.byteOffset();
+ long byteLength;
+ if (field.getType() == long.class || field.getType() == double.class)
+ byteLength = 8;
+ else if (field.getType() == int.class || field.getType() == float.class)
+ byteLength = 4;
+ else if (field.getType() == char.class || field.getType() == short.class)
+ byteLength = 2;
+ else if (field.getType() == byte.class)
+ byteLength = 1;
+ else if (field.getType() == ByteBuffer.class)
+ byteLength = meta.byteLength();
+ else
+ throw new IllegalStateException(field.getType().getName());
+
+ if (field.getType() != ByteBuffer.class)
+ if ((advancingOffset % byteLength) != 0)
+ throw new IllegalStateException("misaligned mapped type: " + className + "." + field.getName());
+
+ if (PRINT_ACTIVITY)
+ System.out.println(MappedObjectTransformer.class.getSimpleName() + ": " + className + "." + field.getName() + " [type=" + field.getType().getSimpleName() + ", offset=" + byteOffset + "]");
+
+ mappedType.fieldToOffset.put(field.getName(), Long.valueOf(byteOffset));
+ mappedType.fieldToLength.put(field.getName(), Long.valueOf(byteLength));
+
+ advancingOffset += byteLength;
+ }
+
+ if (className_to_subtype.put(className, mappedType) != null)
+ {
+ throw new InternalError("duplicate mapped type: " + className);
+ }
+ }
+
+ public static final String view_constructor_method = "_construct_view_";
+
+ public static byte[] transformFieldAccess(final String className, byte[] bytecode)
+ {
+ int flags = ClassWriter.COMPUTE_FRAMES;
+
+ ClassWriter writer = new ClassWriter(flags);
+
+ ClassAdapter adapter = new ClassAdapter(writer)
+ {
+ @Override
+ public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions)
+ {
+ {
+ MappedSubtypeInfo mappedSubtype = className_to_subtype.get(className);
+
+ if (mappedSubtype != null && !mappedSubtype.className.equals(jvmClassName(MappedObject.class)))
+ {
+ if (name.equals("<init>"))
+ {
+ if (!desc.equals("()V"))
+ throw new IllegalStateException(className + " can only have a default constructor, found: " + desc);
+
+ MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
+ mv.visitCode();
+ mv.visitVarInsn(ALOAD, 0);
+ mv.visitMethodInsn(INVOKESPECIAL, jvmClassName(MappedObject.class), "<init>", "()V");
+ mv.visitInsn(RETURN);
+ mv.visitMaxs(1, 1);
+ mv.visitEnd();
+
+ // put the method body in another method
+ name = view_constructor_method;
+ }
+ }
+ }
+
+ return new MappedInstanceMethodAdapter(className, name, desc, super.visitMethod(access, name, desc, signature, exceptions));
+ }
+
+ @Override
+ public FieldVisitor visitField(int access, String fieldName, String typeName, String dunno, Object value)
+ {
+ // remove redirected fields
+ MappedSubtypeInfo mappedSubtype = className_to_subtype.get(className);
+
+ if (mappedSubtype != null && mappedSubtype.fieldToOffset.containsKey(fieldName))
+ {
+ if (PRINT_ACTIVITY)
+ System.out.println(MappedObjectTransformer.class.getSimpleName() + ": discarding field: " + className + "." + fieldName + ":" + typeName);
+ return null;
+ }
+
+ return super.visitField(access, fieldName, typeName, dunno, value);
+ }
+ };
+
+ new ClassReader(bytecode).accept(adapter, 0);
+ bytecode = writer.toByteArray();
+
+ if (PRINT_BYTECODE)
+ printBytecode(bytecode, adapter);
+
+ return bytecode;
+ }
+
+ static void printBytecode(byte[] bytecode, ClassAdapter adapter)
+ {
+ StringWriter sw = new StringWriter();
+ ClassVisitor tracer = new TraceClassVisitor(adapter, new PrintWriter(sw));
+ new ClassReader(bytecode).accept(tracer, 0);
+ String dump = sw.toString();
+
+ System.out.println(dump);
+ }
+
+ static void throwException0(MethodVisitor visitor, Class< ? > type, String msg)
+ {
+ String errorType = jvmClassName(type);
+
+ visitor.visitTypeInsn(NEW, errorType);
+ visitor.visitInsn(DUP);
+ visitor.visitLdcInsn(msg);
+ visitor.visitMethodInsn(INVOKESPECIAL, errorType, "<init>", "(Ljava/lang/String;)V");
+ visitor.visitInsn(ATHROW);
+ }
+
+ static class MappedInstanceMethodAdapter extends MethodAdapter
+ {
+ private final String className;
+ private final String methodName;
+ private final String descr;
+
+ public MappedInstanceMethodAdapter(String className, String methodName, String descr, MethodVisitor backing)
+ {
+ super(backing);
+ this.className = className;
+ this.methodName = methodName;
+ this.descr = descr;
+ }
+
+ @Override
+ public void visitTypeInsn(int opcode, String typeName)
+ {
+ if (opcode == NEW && className_to_subtype.containsKey(typeName))
+ {
+ throw new IllegalAccessError("must not manually create instances of " + typeName + " in method " + this.className + "." + this.methodName + this.descr);
+ }
+
+ super.visitTypeInsn(opcode, typeName);
+ }
+
+ @Override
+ public void visitMethodInsn(int opcode, String className, String methodName, String signature)
+ {
+ if (opcode == INVOKESPECIAL && className.equals(jvmClassName(MappedObject.class)) && methodName.equals("<init>") && signature.equals("()V"))
+ {
+ // stack: instance
+ visitInsn(POP);
+ // stack: -
+ return;
+ }
+
+ for (MappedSubtypeInfo mappedType : className_to_subtype.values())
+ {
+ boolean isMapDirectMethod = (opcode == INVOKESTATIC && methodName.equals("map") && className.equals(mappedType.className) && signature.equals("(JI)L" + jvmClassName(MappedObject.class) + ";"));
+ boolean isMapBufferMethod = (opcode == INVOKESTATIC && methodName.equals("map") && className.equals(mappedType.className) && signature.equals("(Ljava/nio/ByteBuffer;)L" + jvmClassName(MappedObject.class) + ";"));
+ boolean isMallocMethod = (opcode == INVOKESTATIC && methodName.equals("malloc") && className.equals(mappedType.className) && signature.equals("(I)L" + jvmClassName(MappedObject.class) + ";"));
+
+ if ((isMapDirectMethod || isMapBufferMethod) || isMallocMethod)
+ {
+ if (isMallocMethod)
+ {
+ // stack: count
+ pushInt(super.mv, mappedType.sizeof);
+ // stack: sizeof, count
+ super.visitInsn(IMUL);
+ // stack: bytes
+ super.visitMethodInsn(INVOKESTATIC, jvmClassName(ByteBuffer.class), "allocateDirect", "(I)L" + jvmClassName(ByteBuffer.class) + ";");
+ // stack: buffer
+ }
+ else if (isMapDirectMethod)
+ {
+ // stack: capacity, address
+ super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "newBuffer", "(JI)L" + jvmClassName(ByteBuffer.class) + ";");
+ // stack: buffer
+ }
+
+ // stack: buffer
+ super.visitTypeInsn(NEW, className);
+ // stack: new, buffer
+ super.visitInsn(DUP);
+ // stack: new, new, buffer
+ super.visitMethodInsn(INVOKESPECIAL, className, "<init>", "()V");
+ // stack: new, buffer
+ super.visitInsn(DUP_X1);
+ // stack: new, buffer, new
+ super.visitInsn(SWAP);
+ // stack: buffer, new, new
+ pushInt(super.mv, mappedType.align);
+ // stack: int, buffer, new, new
+ pushInt(super.mv, mappedType.sizeof);
+ // stack: int, int, buffer, new, new
+ super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "setup", "(L" + jvmClassName(MappedObject.class) + ";Ljava/nio/ByteBuffer;II)V");
+ // stack: new
+ return;
+ }
+
+ if (opcode == INVOKEVIRTUAL && methodName.equals("dup") && className.equals(mappedType.className) && signature.equals("()L" + jvmClassName(MappedObject.class) + ";"))
+ {
+ // stack: this
+ super.visitTypeInsn(NEW, className);
+ // stack: new, this
+ super.visitInsn(DUP);
+ // stack: new, new, this
+ super.visitMethodInsn(INVOKESPECIAL, className, "<init>", "()V");
+ // stack: new, this
+ super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "dup", "(L" + jvmClassName(MappedObject.class) + ";L" + jvmClassName(MappedObject.class) + ";)L" + jvmClassName(MappedObject.class) + ";");
+ // stack: new
+ return;
+ }
+
+ if (opcode == INVOKEVIRTUAL && methodName.equals("slice") && className.equals(mappedType.className) && signature.equals("()L" + jvmClassName(MappedObject.class) + ";"))
+ {
+ // stack: this
+ super.visitTypeInsn(NEW, className);
+ // stack: new, this
+ super.visitInsn(DUP);
+ // stack: new, new, this
+ super.visitMethodInsn(INVOKESPECIAL, className, "<init>", "()V");
+ // stack: new, this
+ super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "slice", "(L" + jvmClassName(MappedObject.class) + ";L" + jvmClassName(MappedObject.class) + ";)L" + jvmClassName(MappedObject.class) + ";");
+ // stack: new
+ return;
+ }
+
+ //
+
+ if (opcode == INVOKEVIRTUAL && methodName.equals("runViewConstructor") && className.equals(mappedType.className) && signature.equals("()V"))
+ {
+ // stack: this
+ super.visitInsn(DUP);
+ // stack: this, this
+ super.visitMethodInsn(INVOKEVIRTUAL, className, view_constructor_method, "()V");
+ // stack: this
+ return;
+ }
+
+ //
+
+ if (opcode == INVOKEVIRTUAL && methodName.equals("copyTo") && className.equals(mappedType.className) && signature.equals("(L" + jvmClassName(MappedObject.class) + ";)V"))
+ {
+ // stack: target, this
+ pushInt(super.mv, mappedType.sizeof);
+ // stack: sizeof, target, this
+ super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "copy", "(L" + jvmClassName(MappedObject.class) + ";L" + jvmClassName(MappedObject.class) + ";I)V");
+ // stack: -
+ return;
+ }
+
+ if (opcode == INVOKEVIRTUAL && methodName.equals("copyRange") && className.equals(mappedType.className) && signature.equals("(L" + jvmClassName(MappedObject.class) + ";I)V"))
+ {
+ // stack: instances, target, this
+ pushInt(super.mv, mappedType.sizeof);
+ // stack: sizeof, instances, target, this
+ super.visitInsn(IMUL);
+ // stack: bytes, target, this
+ super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "copy", "(L" + jvmClassName(MappedObject.class) + ";L" + jvmClassName(MappedObject.class) + ";I)V");
+ // stack: -
+ return;
+ }
+ }
+
+ super.visitMethodInsn(opcode, className, methodName, signature);
+ }
+
+ static void throwAccessErrorOnReadOnlyField(String className, String fieldName)
+ {
+ throw new IllegalAccessError("field '" + className + "." + fieldName + "' is final");
+ }
+
+ @Override
+ public void visitFieldInsn(int opcode, String className, String fieldName, String typeName)
+ {
+ MappedSubtypeInfo mappedSubtype = className_to_subtype.get(className);
+ if (mappedSubtype == null)
+ {
+ String mappedSetPrefix = jvmClassName(MappedSet.class);
+
+ outer: if (fieldName.equals("view") && className.startsWith(mappedSetPrefix))
+ {
+ if (opcode == GETFIELD)
+ throwAccessErrorOnReadOnlyField(className, fieldName);
+ if (opcode != PUTFIELD)
+ break outer;
+
+ // stack: index, this
+ if (false)
+ break outer;
+ else if (className.equals(jvmClassName(MappedSet2.class)))
+ super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "put_views", "(L" + jvmClassName(MappedSet2.class) + ";I)V");
+ else if (className.equals(jvmClassName(MappedSet3.class)))
+ super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "put_views", "(L" + jvmClassName(MappedSet3.class) + ";I)V");
+ else if (className.equals(jvmClassName(MappedSet4.class)))
+ super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "put_views", "(L" + jvmClassName(MappedSet4.class) + ";I)V");
+ else
+ break outer;
+ // stack: -
+ return;
+ }
+
+ // early out
+ super.visitFieldInsn(opcode, className, fieldName, typeName);
+ return;
+ }
+
+ if (fieldName.equals("SIZEOF"))
+ {
+ if (!typeName.equals("I"))
+ throw new IllegalStateException();
+
+ if (opcode == GETSTATIC)
+ {
+ pushInt(super.mv, mappedSubtype.sizeof);
+ return;
+ }
+ if (opcode == PUTSTATIC)
+ {
+ throwAccessErrorOnReadOnlyField(className, fieldName);
+ }
+ }
+
+ if (fieldName.equals("view"))
+ {
+ if (!typeName.equals("I"))
+ throw new IllegalStateException();
+
+ if (opcode == GETFIELD)
+ {
+ // stack: instance
+ super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "get_view", "(L" + jvmClassName(MappedObject.class) + ";)I");
+ return;
+ }
+ if (opcode == PUTFIELD)
+ {
+ // stack: int, instance
+ super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "put_view", "(L" + jvmClassName(MappedObject.class) + ";I)V");
+ return;
+ }
+ }
+
+ if (fieldName.equals("align"))
+ {
+ if (!typeName.equals("I"))
+ throw new IllegalStateException();
+
+ if (opcode == GETFIELD)
+ {
+ // stack: instance
+ super.visitInsn(POP);
+ // stack: -
+ pushInt(super.mv, mappedSubtype.align);
+ // stack: int
+ return;
+ }
+ if (opcode == PUTFIELD)
+ {
+ throwAccessErrorOnReadOnlyField(className, fieldName);
+ }
+ }
+
+ if (fieldName.equals("stride"))
+ {
+ if (!typeName.equals("I"))
+ throw new IllegalStateException();
+
+ if (opcode == GETFIELD)
+ {
+ // do not change a thing
+ }
+ if (opcode == PUTFIELD)
+ {
+ throwAccessErrorOnReadOnlyField(className, fieldName);
+ }
+ }
+
+ if (fieldName.equals("baseAddress") || fieldName.equals("viewAddress"))
+ {
+ if (!typeName.equals("J"))
+ throw new IllegalStateException();
+
+ if (opcode == GETFIELD)
+ {
+ // do not change a thing
+ }
+ if (opcode == PUTFIELD)
+ {
+ throwAccessErrorOnReadOnlyField(className, fieldName);
+ }
+ }
+
+ Long fieldOffset = mappedSubtype.fieldToOffset.get(fieldName);
+ if (fieldOffset == null)
+ {
+ // early out
+ super.visitFieldInsn(opcode, className, fieldName, typeName);
+ return;
+ }
+
+ if (typeName.equals("L" + jvmClassName(ByteBuffer.class) + ";"))
+ {
+ if (opcode == PUTFIELD)
+ {
+ throwAccessErrorOnReadOnlyField(className, fieldName);
+ }
+ if (opcode == GETFIELD)
+ {
+ Long fieldLength = mappedSubtype.fieldToLength.get(fieldName);
+
+ super.visitFieldInsn(GETFIELD, mappedSubtype.className, "viewAddress", "J");
+ super.visitLdcInsn(fieldOffset);
+ super.visitInsn(LADD);
+ super.visitLdcInsn(fieldLength);
+ super.visitInsn(L2I);
+ super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), "newBuffer", "(JI)L" + jvmClassName(ByteBuffer.class) + ";");
+
+ return;
+ }
+ }
+
+ if (opcode == PUTFIELD)
+ {
+ super.visitInsn(SWAP);
+ super.visitFieldInsn(GETFIELD, mappedSubtype.className, "viewAddress", "J");
+ super.visitLdcInsn(fieldOffset);
+ super.visitInsn(LADD);
+ super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), typeName.toLowerCase() + "put", "(" + typeName + "J)V");
+ return;
+ }
+ if (opcode == GETFIELD)
+ {
+ super.visitFieldInsn(GETFIELD, mappedSubtype.className, "viewAddress", "J");
+ super.visitLdcInsn(fieldOffset);
+ super.visitInsn(LADD);
+ super.visitMethodInsn(INVOKESTATIC, jvmClassName(MappedHelper.class), typeName.toLowerCase() + "get", "(J)" + typeName);
+ return;
+ }
+
+ // original field access
+ super.visitFieldInsn(opcode, className, fieldName, typeName);
+ return;
+ }
+ }
+
+ static void pushInt(MethodVisitor mv, int value)
+ {
+ if (value == -1)
+ mv.visitInsn(ICONST_M1);
+ else if (value == 0)
+ mv.visitInsn(ICONST_0);
+ else if (value == 1)
+ mv.visitInsn(ICONST_1);
+ else if (value == 2)
+ mv.visitInsn(ICONST_2);
+ else if (value == 3)
+ mv.visitInsn(ICONST_3);
+ else if (value == 4)
+ mv.visitInsn(ICONST_4);
+ else if (value == 5)
+ mv.visitInsn(ICONST_5);
+ else if (value >= Byte.MIN_VALUE && value <= Byte.MAX_VALUE)
+ mv.visitIntInsn(BIPUSH, value);
+ else if (value >= Short.MIN_VALUE && value <= Short.MAX_VALUE)
+ mv.visitIntInsn(SIPUSH, value);
+ else
+ mv.visitLdcInsn(Integer.valueOf(value));
+ }
+
+ static String jvmClassName(Class< ? > type)
+ {
+ return type.getName().replace('.', '/');
+ }
+
+ static class MappedSubtypeInfo
+ {
+ public final String className;
+
+ public int sizeof;
+ public int align;
+
+ public Map<String, Long> fieldToOffset;
+ public Map<String, Long> fieldToLength;
+
+ public MappedSubtypeInfo(String className, int sizeof, int align)
+ {
+ this.className = className;
+
+ this.sizeof = sizeof;
+ this.align = align;
+
+ this.fieldToOffset = new HashMap<String, Long>();
+ this.fieldToLength = new HashMap<String, Long>();
+ }
+ }
+}
\ No newline at end of file
Added: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectUnsafe.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectUnsafe.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectUnsafe.java 2011-07-11 21:46:00 UTC (rev 3568)
@@ -0,0 +1,83 @@
+/*
+ * Created on Jun 24, 2011
+ */
+
+package org.lwjgl.util.mapped;
+
+import java.lang.reflect.Field;
+import java.nio.Buffer;
+import java.nio.ByteBuffer;
+
+import sun.misc.Unsafe;
+
+/**
+ * @author Riven
+ */
+
+public class MappedObjectUnsafe
+{
+ public static final Unsafe INSTANCE = getUnsafeInstance();
+ public static final int ADDRESS_SIZE = INSTANCE.addressSize();
+ private static final Object[] ARRAY = new Object[1];
+ private static final long ARRAY_ELEMENT_OFFSET = INSTANCE.arrayBaseOffset(ARRAY.getClass());
+
+ private static final long BUFFER_ADDRESS_OFFSET = getObjectFieldOffset(ByteBuffer.class, "address");
+ private static final long BUFFER_CAPACITY_OFFSET = getObjectFieldOffset(ByteBuffer.class, "capacity");
+
+ //
+
+ public static long getBufferBaseAddress(Buffer buffer)
+ {
+ return INSTANCE.getLong(buffer, BUFFER_ADDRESS_OFFSET);
+ }
+
+ private static final ByteBuffer global = ByteBuffer.allocateDirect(4 * 1024);
+
+ public static ByteBuffer newBuffer(long address, int capacity)
+ {
+ if (address <= 0L || capacity < 0)
+ throw new IllegalStateException("you almost crashed the jvm");
+
+ ByteBuffer buffer = global.duplicate();
+ INSTANCE.putLong(buffer, BUFFER_ADDRESS_OFFSET, address);
+ INSTANCE.putInt(buffer, BUFFER_CAPACITY_OFFSET, capacity);
+ buffer.position(0);
+ buffer.limit(capacity);
+ return buffer;
+ }
+
+
+
+ private static long getObjectFieldOffset(Class< ? > type, String fieldName)
+ {
+ while (type != null)
+ {
+ try
+ {
+ return INSTANCE.objectFieldOffset(type.getDeclaredField(fieldName));
+ }
+ catch (Throwable t)
+ {
+ type = type.getSuperclass();
+ }
+ }
+ throw new InternalError();
+ }
+
+ private static Unsafe getUnsafeInstance()
+ {
+ try
+ {
+ ByteBuffer buffer = ByteBuffer.allocateDirect(1);
+ Field unsafeField = buffer.getClass().getDeclaredField("unsafe");
+ unsafeField.setAccessible(true);
+ Unsafe instance = (Unsafe) unsafeField.get(buffer);
+ buffer.flip(); // prevented 'buffer' from being gc'ed
+ return instance;
+ }
+ catch (Exception exc)
+ {
+ throw new InternalError();
+ }
+ }
+}
Added: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet.java 2011-07-11 21:46:00 UTC (rev 3568)
@@ -0,0 +1,23 @@
+/*
+ * Created on Jul 11, 2011
+ */
+
+package org.lwjgl.util.mapped;
+
+public class MappedSet
+{
+ public static MappedSet2 create(MappedObject a, MappedObject b)
+ {
+ return new MappedSet2(a, b);
+ }
+
+ public static MappedSet3 create(MappedObject a, MappedObject b, MappedObject c)
+ {
+ return new MappedSet3(a, b, c);
+ }
+
+ public static MappedSet4 create(MappedObject a, MappedObject b, MappedObject c, MappedObject d)
+ {
+ return new MappedSet4(a, b, c, d);
+ }
+}
Added: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet2.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet2.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet2.java 2011-07-11 21:46:00 UTC (rev 3568)
@@ -0,0 +1,30 @@
+/*
+ * Created on Jul 11, 2011
+ */
+
+package org.lwjgl.util.mapped;
+
+public class MappedSet2
+{
+ private final MappedObject a, b;
+
+ MappedSet2(MappedObject a, MappedObject b)
+ {
+ this.a = a;
+ this.b = b;
+ }
+
+ public int view;
+
+ void view(int view)
+ {
+ this.a.viewAddress = this.a.baseAddress + this.a.stride * view;
+ this.b.viewAddress = this.b.baseAddress + this.b.stride * view;
+ }
+
+ public void next()
+ {
+ this.a.viewAddress += this.a.stride;
+ this.b.viewAddress += this.b.stride;
+ }
+}
Added: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet3.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet3.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet3.java 2011-07-11 21:46:00 UTC (rev 3568)
@@ -0,0 +1,33 @@
+/*
+ * Created on Jul 11, 2011
+ */
+
+package org.lwjgl.util.mapped;
+
+public class MappedSet3
+{
+ private final MappedObject a, b, c;
+
+ MappedSet3(MappedObject a, MappedObject b, MappedObject c)
+ {
+ this.a = a;
+ this.b = b;
+ this.c = c;
+ }
+
+ public int view;
+
+ void view(int view)
+ {
+ this.a.viewAddress = this.a.baseAddress + this.a.stride * view;
+ this.b.viewAddress = this.b.baseAddress + this.b.stride * view;
+ this.c.viewAddress = this.c.baseAddress + this.c.stride * view;
+ }
+
+ public void next()
+ {
+ this.a.viewAddress += this.a.stride;
+ this.b.viewAddress += this.b.stride;
+ this.c.viewAddress += this.c.stride;
+ }
+}
Added: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet4.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet4.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedSet4.java 2011-07-11 21:46:00 UTC (rev 3568)
@@ -0,0 +1,36 @@
+/*
+ * Created on Jul 11, 2011
+ */
+
+package org.lwjgl.util.mapped;
+
+public class MappedSet4
+{
+ private final MappedObject a, b, c, d;
+
+ MappedSet4(MappedObject a, MappedObject b, MappedObject c, MappedObject d)
+ {
+ this.a = a;
+ this.b = b;
+ this.c = c;
+ this.d = d;
+ }
+
+ public int view;
+
+ void view(int view)
+ {
+ this.a.viewAddress = this.a.baseAddress + this.a.stride * view;
+ this.b.viewAddress = this.b.baseAddress + this.b.stride * view;
+ this.c.viewAddress = this.c.baseAddress + this.c.stride * view;
+ this.d.viewAddress = this.d.baseAddress + this.d.stride * view;
+ }
+
+ public void next()
+ {
+ this.a.viewAddress += this.a.stride;
+ this.b.viewAddress += this.b.stride;
+ this.c.viewAddress += this.c.stride;
+ this.d.viewAddress += this.d.stride;
+ }
+}
Added: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedType.java
===================================================================
--- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedType.java (rev 0)
+++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedType.java 2011-07-11 21:46:00 UTC (rev 3568)
@@ -0,0 +1,21 @@
+/*
+ * Created on Jun 24, 2011
+ */
+
+package org.lwjgl.util.mapped;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * @author Riven
+ */
+
+@Retention(RetentionPolicy.RUNTIME)
+public @interface MappedType {
+ int sizeof();
+
+ int align() default 4;
+
+ boolean autoGenerateOffsets() default true;
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <riv...@us...> - 2011-07-11 20:43:44
|
Revision: 3567
http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3567&view=rev
Author: riven-lwjgl
Date: 2011-07-11 20:43:38 +0000 (Mon, 11 Jul 2011)
Log Message:
-----------
Initial import.
Added Paths:
-----------
LWJGL/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|