From: <sp...@us...> - 2010-05-07 17:03:44
|
Revision: 3339 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3339&view=rev Author: spasi Date: 2010-05-07 17:03:36 +0000 (Fri, 07 May 2010) Log Message: ----------- Fix for OpenAL debug builds. Added alternate methods for NV_fence. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/generator/Utils.java trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_fence.java Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/Utils.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/Utils.java 2010-05-01 09:19:00 UTC (rev 3338) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/Utils.java 2010-05-07 17:03:36 UTC (rev 3339) @@ -166,7 +166,9 @@ return null; } + // DISABLED: We always generate indirect methods. (affects OpenAL only at the time of this change) public static boolean isMethodIndirect(boolean generate_error_checks, boolean context_specific, MethodDeclaration method) { + /* for (ParameterDeclaration param : method.getParameters()) { if (isAddressableType(param.getType()) || getParameterAutoAnnotation(param) != null || param.getAnnotation(Constant.class) != null) @@ -176,6 +178,8 @@ method.getAnnotation(CachedResult.class) != null || (generate_error_checks && method.getAnnotation(NoErrorCheck.class) == null) || context_specific; + */ + return true; } public static String getNativeQualifiedName(String qualified_name) { Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_fence.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_fence.java 2010-05-01 09:19:00 UTC (rev 3338) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_fence.java 2010-05-07 17:03:36 UTC (rev 3339) @@ -42,8 +42,15 @@ void glGenFencesNV(@AutoSize("piFences") @GLsizei int n, @OutParameter @GLuint IntBuffer piFences); + @Alternate("glGenFencesNV") + @GLreturn("piFences") + void glGenFencesNV2(@Constant("1") @GLsizei int n, @OutParameter @GLuint IntBuffer piFences); + void glDeleteFencesNV(@AutoSize("piFences") @GLsizei int n, @Const @GLuint IntBuffer piFences); + @Alternate("glDeleteFencesNV") + void glDeleteFencesNV(@Constant("1") @GLsizei int n, @Const @GLuint @Constant(value = "APIUtils.getBufferInt().put(0, fence), 0", keepParam = true) int fence); + void glSetFenceNV(@GLuint int fence, @GLenum int condition); boolean glTestFenceNV(@GLuint int fence); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sp...@us...> - 2010-07-07 12:37:47
|
Revision: 3366 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3366&view=rev Author: spasi Date: 2010-07-07 12:37:40 +0000 (Wed, 07 Jul 2010) Log Message: ----------- Added support for Compiz's legacy fullscreen workaround. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java trunk/LWJGL/src/java/org/lwjgl/opengl/XRandR.java trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_direct_state_access.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2010-07-04 18:24:53 UTC (rev 3365) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2010-07-07 12:37:40 UTC (rev 3366) @@ -39,6 +39,9 @@ */ import java.awt.Canvas; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; import java.nio.ByteBuffer; import java.nio.FloatBuffer; import java.nio.IntBuffer; @@ -410,6 +413,10 @@ ByteBuffer handle = peer_info.lockAndGetHandle(); try { current_window_mode = getWindowMode(Display.isFullscreen()); + // Try to enable Lecagy FullScreen Support in Compiz, else + // we may have trouble with stuff overlapping our fullscreen window. + if ( current_window_mode != WINDOWED ) + Compiz.setLegacyFullscreenSupport(true); // Setting _MOTIF_WM_HINTS in fullscreen mode is problematic for certain window // managers. We do not set MWM_HINTS_DECORATIONS in fullscreen mode anymore, // unless org.lwjgl.opengl.Window.undecorated_fs has been specified. @@ -490,6 +497,9 @@ ungrabKeyboard(); nDestroyWindow(getDisplay(), getWindow()); decDisplay(); + + if ( current_window_mode != WINDOWED ) + Compiz.setLegacyFullscreenSupport(false); } finally { unlockAWT(); } @@ -544,6 +554,8 @@ } if (isXF86VidModeSupported()) doSetGamma(saved_gamma); + + Compiz.setLegacyFullscreenSupport(false); } catch (LWJGLException e) { LWJGLUtil.log("Caught exception while resetting mode: " + e); } finally { @@ -618,6 +630,8 @@ public DisplayMode init() throws LWJGLException { lockAWT(); try { + Compiz.init(); + delete_atom = internAtom("WM_DELETE_WINDOW", false); current_displaymode_extension = getBestDisplayModeExtension(); if (current_displaymode_extension == NONE) @@ -1233,4 +1247,96 @@ public boolean isInsideWindow() { return true; } -} + + /** + * Helper class for managing Compiz's workarounds. + */ + private static final class Compiz { + + private static final String LEGACY_FULLSCREEN_SUPPORT = "/org/freedesktop/compiz/workarounds/allscreens/legacy_fullscreen"; + + private static boolean dbusAvailable; + + private static boolean legacyFullscreenSupport; + + private Compiz() { + } + + static void init() { + if ( Display.getPrivilegedBoolean("org.lwjgl.opengl.Window.nocompiz_lfs") ) + return; + + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + try { + legacyFullscreenSupport = getBoolean(LEGACY_FULLSCREEN_SUPPORT); + dbusAvailable = true; + } catch (LWJGLException e) { + LWJGLUtil.log("Compiz Dbus communication failed. Reason: " + e.getMessage()); + } + return null; + } + }); + } + + static void setLegacyFullscreenSupport(final boolean enabled) { + if ( !dbusAvailable || legacyFullscreenSupport ) + return; + + AccessController.doPrivileged(new PrivilegedAction() { + public Object run() { + try { + setBoolean(LEGACY_FULLSCREEN_SUPPORT, enabled); + } catch (LWJGLException e) { + LWJGLUtil.log("Failed to change Compiz Legacy Fullscreen Support. Reason: " + e.getMessage()); + } + return null; + } + }); + } + + private static boolean getBoolean(final String option) throws LWJGLException { + try { + final Process p = Runtime.getRuntime().exec(new String[] { + "dbus-send", "--print-reply", "--type=method_call", "--dest=org.freedesktop.compiz", option, "org.freedesktop.compiz.get" + }); + final int exitValue = p.waitFor(); + if ( exitValue != 0 ) + throw new LWJGLException("Dbus error."); + + final BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); + String reply = br.readLine(); // header + + if ( !reply.startsWith("method return") ) + throw new LWJGLException("Invalid Dbus reply."); + + reply = br.readLine().trim(); // value + if ( !reply.startsWith("boolean") ) + throw new LWJGLException("Invalid Dbus reply."); + + return "true".equalsIgnoreCase(reply.substring("boolean".length() + 1)); + } catch (IOException e) { + throw new LWJGLException("Dbus command failed.", e); + } catch (InterruptedException e) { + throw new LWJGLException("Dbus command failed.", e); + } + } + + private static void setBoolean(final String option, final boolean value) throws LWJGLException { + try { + final Process p = Runtime.getRuntime().exec(new String[] { + "dbus-send", "--type=method_call", "--dest=org.freedesktop.compiz", option, "org.freedesktop.compiz.set", "boolean:" + Boolean.toString(value) + }); + final int exitValue = p.waitFor(); + if ( exitValue != 0 ) + throw new LWJGLException("Dbus error."); + } catch (IOException e) { + throw new LWJGLException("Dbus command failed.", e); + } catch (InterruptedException e) { + throw new LWJGLException("Dbus command failed.", e); + } + } + + } + +} \ No newline at end of file Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/XRandR.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/XRandR.java 2010-07-04 18:24:53 UTC (rev 3365) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/XRandR.java 2010-07-07 12:37:40 UTC (rev 3366) @@ -219,7 +219,7 @@ * the list to add the Screen to if it's valid * @param name * the name of this screen - * @param conf + * @param what * config string, format either widthxheight or * widthxheight+xPos+yPos */ @@ -231,7 +231,7 @@ m = SCREEN_PATTERN2.matcher( what ); if( !m.matches() ) { - System.out.println( "Did not match: " + what ); + LWJGLUtil.log( "Did not match: " + what ); return; } } Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_direct_state_access.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_direct_state_access.java 2010-07-04 18:24:53 UTC (rev 3365) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_direct_state_access.java 2010-07-07 12:37:40 UTC (rev 3366) @@ -519,11 +519,11 @@ value parameters */ - @Optional(reason = "AMD does not expose this (last driver checked: 10.3)") + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") void glEnableClientStateiEXT(@GLenum int array, @GLuint int index); - @Optional(reason = "AMD does not expose this (last driver checked: 10.3)") + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") void glDisableClientStateiEXT(@GLenum int array, @GLuint int index); @@ -565,7 +565,7 @@ and before state value parameters */ - @Optional(reason = "AMD does not expose this (last driver checked: 10.3)") + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") @StripPostfix("params") void glGetFloati_vEXT(@GLenum int pname, @GLuint int index, @OutParameter @Check("16") FloatBuffer params); @@ -576,7 +576,7 @@ @StripPostfix("params") void glGetFloati_vEXT2(@GLenum int pname, @GLuint int index, @OutParameter FloatBuffer params); - @Optional(reason = "AMD does not expose this (last driver checked: 10.3)") + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") @StripPostfix("params") void glGetDoublei_vEXT(@GLenum int pname, @GLuint int index, @OutParameter @Check("16") DoubleBuffer params); @@ -587,7 +587,7 @@ @StripPostfix("params") void glGetDoublei_vEXT2(@GLenum int pname, @GLuint int index, @OutParameter DoubleBuffer params); - @Optional(reason = "AMD does not expose this (last driver checked: 10.3)") + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") @StripPostfix(value = "params", hasPostfix = false) void glGetPointeri_vEXT(@GLenum int pname, @GLuint int index, @Result @GLvoid ByteBuffer params); @@ -1343,6 +1343,7 @@ OpenGL 3.1: New buffer data copy command */ + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL31,GL_ARB_copy_buffer") void glNamedCopyBufferSubDataEXT(@GLuint int readBuffer, @GLuint int writeBuffer, @GLintptr long readoffset, @GLintptr long writeoffset, @GLsizeiptr long size); @@ -1386,44 +1387,55 @@ and change the final parameter from "const void *" to "intptr offset" */ + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") @DeprecatedGL void glVertexArrayVertexOffsetEXT(@GLuint int vaobj, @GLuint int buffer, int size, @GLenum int type, @GLsizei int stride, @GLintptr long offset); + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") @DeprecatedGL void glVertexArrayColorOffsetEXT(@GLuint int vaobj, @GLuint int buffer, int size, @GLenum int type, @GLsizei int stride, @GLintptr long offset); + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") @DeprecatedGL void glVertexArrayEdgeFlagOffsetEXT(@GLuint int vaobj, @GLuint int buffer, @GLsizei int stride, @GLintptr long offset); + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") void glVertexArrayIndexOffsetEXT(@GLuint int vaobj, @GLuint int buffer, @GLenum int type, @GLsizei int stride, @GLintptr long offset); + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") @DeprecatedGL void glVertexArrayNormalOffsetEXT(@GLuint int vaobj, @GLuint int buffer, @GLenum int type, @GLsizei int stride, @GLintptr long offset); + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") @DeprecatedGL void glVertexArrayTexCoordOffsetEXT(@GLuint int vaobj, @GLuint int buffer, int size, @GLenum int type, @GLsizei int stride, @GLintptr long offset); + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") @DeprecatedGL void glVertexArrayMultiTexCoordOffsetEXT(@GLuint int vaobj, @GLuint int buffer, @GLenum int texunit, int size, @GLenum int type, @GLsizei int stride, @GLintptr long offset); + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") @DeprecatedGL void glVertexArrayFogCoordOffsetEXT(@GLuint int vaobj, @GLuint int buffer, @GLenum int type, @GLsizei int stride, @GLintptr long offset); + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") @DeprecatedGL void glVertexArraySecondaryColorOffsetEXT(@GLuint int vaobj, @GLuint int buffer, int size, @GLenum int type, @GLsizei int stride, @GLintptr long offset); + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") void glVertexArrayVertexAttribOffsetEXT(@GLuint int vaobj, @GLuint int buffer, @GLuint int index, int size, @GLenum int type, boolean normalized, @GLsizei int stride, @GLintptr long offset); + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") void glVertexArrayVertexAttribIOffsetEXT(@GLuint int vaobj, @GLuint int buffer, @GLuint int index, int size, @GLenum int type, @GLsizei int stride, @GLintptr long offset); @@ -1433,9 +1445,11 @@ "uint vaobj" parameter */ + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") void glEnableVertexArrayEXT(@GLuint int vaobj, @GLenum int array); + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") void glDisableVertexArrayEXT(@GLuint int vaobj, @GLenum int array); @@ -1445,9 +1459,11 @@ and add an initial "uint vaobj" parameter */ + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") void glEnableVertexArrayAttribEXT(@GLuint int vaobj, @GLuint int index); + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") void glDisableVertexArrayAttribEXT(@GLuint int vaobj, @GLuint int index); @@ -1455,6 +1471,7 @@ OpenGL 3.0: New queries for vertex array objects */ + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") @StripPostfix("param") void glGetVertexArrayIntegervEXT(@GLuint int vaobj, @GLenum int pname, @OutParameter @Check("16") IntBuffer param); @@ -1465,10 +1482,12 @@ @StripPostfix("param") void glGetVertexArrayIntegervEXT2(@GLuint int vaobj, @GLenum int pname, @OutParameter IntBuffer param); + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") @StripPostfix("param") void glGetVertexArrayPointervEXT(@GLuint int vaobj, @GLenum int pname, @Result @GLvoid ByteBuffer param); + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") @StripPostfix(value = "param") void glGetVertexArrayIntegeri_vEXT(@GLuint int vaobj, @GLuint int index, @GLenum int pname, @OutParameter @Check("16") IntBuffer param); @@ -1479,6 +1498,7 @@ @StripPostfix(value = "param", postfix = "_v") void glGetVertexArrayIntegeri_vEXT2(@GLuint int vaobj, @GLuint int index, @GLenum int pname, @OutParameter IntBuffer param); + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") @StripPostfix(value = "param") void glGetVertexArrayPointeri_vEXT(@GLuint int vaobj, @GLuint int index, @GLenum int pname, @Result @GLvoid ByteBuffer param); @@ -1502,12 +1522,14 @@ * * @return A ByteBuffer representing the mapped buffer memory. */ + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") @CachedResult(isRange = true) @GLvoid @AutoResultSize("length") ByteBuffer glMapNamedBufferRangeEXT(@GLuint int buffer, @GLintptr long offset, @GLsizeiptr long length, @GLbitfield int access); + @Optional(reason = "AMD does not expose this (last driver checked: 10.5)") @Dependent("OpenGL30") void glFlushMappedNamedBufferRangeEXT(@GLuint int buffer, @GLintptr long offset, @GLsizeiptr long length); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ma...@us...> - 2010-07-14 13:12:34
|
Revision: 3380 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3380&view=rev Author: matzon Date: 2010-07-14 13:12:24 +0000 (Wed, 14 Jul 2010) Log Message: ----------- OAL patches by Ciardhubh Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/openal/ALC11.java trunk/LWJGL/src/java/org/lwjgl/test/openal/OpenALInfo.java trunk/LWJGL/src/native/common/org_lwjgl_openal_ALC10.c trunk/LWJGL/src/templates/org/lwjgl/openal/AL10.java Modified: trunk/LWJGL/src/java/org/lwjgl/openal/ALC11.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/openal/ALC11.java 2010-07-12 20:19:21 UTC (rev 3379) +++ trunk/LWJGL/src/java/org/lwjgl/openal/ALC11.java 2010-07-14 13:12:24 UTC (rev 3380) @@ -59,6 +59,9 @@ public static final int ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER = 0x311; public static final int ALC_CAPTURE_SAMPLES = 0x312; + public static final int ALC_MONO_SOURCES = 0x1010; + public static final int ALC_STEREO_SOURCES = 0x1011; + /** * The alcCaptureOpenDevice function allows the application to connect to a capture * device. To obtain a list of all available capture devices, use getCaptureDevices a list of all Modified: trunk/LWJGL/src/java/org/lwjgl/test/openal/OpenALInfo.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/openal/OpenALInfo.java 2010-07-12 20:19:21 UTC (rev 3379) +++ trunk/LWJGL/src/java/org/lwjgl/test/openal/OpenALInfo.java 2010-07-14 13:12:24 UTC (rev 3380) @@ -191,7 +191,7 @@ effects.put("Compressor", new Integer(EFX10.AL_EFFECT_COMPRESSOR)); effects.put("Equalizer", new Integer(EFX10.AL_EFFECT_EQUALIZER)); - entries = filters.entrySet(); + entries = effects.entrySet(); for(Iterator i = entries.iterator(); i.hasNext();) { Map.Entry entry = (Entry) i.next(); int value = ((Integer)entry.getValue()).intValue(); Modified: trunk/LWJGL/src/native/common/org_lwjgl_openal_ALC10.c =================================================================== --- trunk/LWJGL/src/native/common/org_lwjgl_openal_ALC10.c 2010-07-12 20:19:21 UTC (rev 3379) +++ trunk/LWJGL/src/native/common/org_lwjgl_openal_ALC10.c 2010-07-14 13:12:24 UTC (rev 3380) @@ -86,7 +86,7 @@ int length; int i=1; - if(alcString == NULL) { + if (alcString == NULL) { return NULL; } @@ -94,14 +94,21 @@ // These are encoded using \0 between elements and a finishing \0\0 switch(token) { case 0x1005: // ALC_DEVICE_SPECIFIER - case 0x310: // ALC_CAPTURE_DEVICE_SPECIFIER + case 0x310: // ALC_CAPTURE_DEVICE_SPECIFIER + // If deviceaddress is not 0, OpenAL returns a single device terminated by a + // single \0 character, if token is ALC_DEVICE_SPECIFIER or + // ALC_CAPTURE_DEVICE_SPECIFIER. + if (deviceaddress != 0) { + length = strlen(alcString); + break; + } case 0x1013: // ALC_ALL_DEVICES_SPECIFIER while (alcString[i - 1] != '\0' || alcString[i] != '\0') { i++; } length = i + 1; break; - default: + default: // e.g. ALC_DEFAULT_ALL_DEVICES_SPECIFIER length = strlen(alcString); } return NewStringNativeWithLength(env, alcString, length); Modified: trunk/LWJGL/src/templates/org/lwjgl/openal/AL10.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/openal/AL10.java 2010-07-12 20:19:21 UTC (rev 3379) +++ trunk/LWJGL/src/templates/org/lwjgl/openal/AL10.java 2010-07-14 13:12:24 UTC (rev 3380) @@ -250,35 +250,28 @@ int AL_FREQUENCY = 0x2001; /** - * Sound buffers: frequency, in units of Hertz [Hz]. - * This is the number of samples per second. Half of the - * sample frequency marks the maximum significant - * frequency component. + * Sound buffers: The number of bits per sample for the + * data contained in the buffer. */ int AL_BITS = 0x2002; /** - * Sound buffers: frequency, in units of Hertz [Hz]. - * This is the number of samples per second. Half of the - * sample frequency marks the maximum significant - * frequency component. + * Sound buffers: The number of channels for the data + * contained in the buffer. */ int AL_CHANNELS = 0x2003; /** - * Sound buffers: frequency, in units of Hertz [Hz]. - * This is the number of samples per second. Half of the - * sample frequency marks the maximum significant - * frequency component. + * Sound buffers: Size in bytes of the buffer data. */ int AL_SIZE = 0x2004; /** - * Sound buffers: frequency, in units of Hertz [Hz]. - * This is the number of samples per second. Half of the - * sample frequency marks the maximum significant - * frequency component. + * @deprecated This token is a relict of the early OpenAL days and is + * no longer supported. Neither the OpenAL spec nor OpenAL Soft define + * it. */ + @Deprecated int AL_DATA = 0x2005; /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sp...@us...> - 2010-09-30 17:21:59
|
Revision: 3419 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3419&view=rev Author: spasi Date: 2010-09-30 17:21:50 +0000 (Thu, 30 Sep 2010) Log Message: ----------- Misc GL/CL fixes and additions. Made native calls package private, we can now use them from the high-level API. Added support for "render-to-texture" in the fractal demo. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/BufferChecks.java trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java trunk/LWJGL/src/java/org/lwjgl/PointerWrapperAbstract.java trunk/LWJGL/src/java/org/lwjgl/opencl/APIUtil.java trunk/LWJGL/src/java/org/lwjgl/opencl/CLChecks.java trunk/LWJGL/src/java/org/lwjgl/opencl/CLContext.java trunk/LWJGL/src/java/org/lwjgl/opencl/CLMem.java trunk/LWJGL/src/java/org/lwjgl/opencl/CLProgram.java trunk/LWJGL/src/java/org/lwjgl/opencl/InfoUtilAbstract.java trunk/LWJGL/src/java/org/lwjgl/opencl/InfoUtilFactory.java trunk/LWJGL/src/java/org/lwjgl/opencl/Util.java trunk/LWJGL/src/java/org/lwjgl/test/opencl/gl/DemoFractal.java trunk/LWJGL/src/java/org/lwjgl/test/opencl/gl/Mandelbrot.cl trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_direct_state_access.java trunk/LWJGL/src/templates/org/lwjgl/opengl/GL40.java trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_half_float.java Added Paths: ----------- trunk/LWJGL/src/java/org/lwjgl/opencl/api/CLBufferRegion.java trunk/LWJGL/src/java/org/lwjgl/opencl/api/CLImageFormat.java Modified: trunk/LWJGL/src/java/org/lwjgl/BufferChecks.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/BufferChecks.java 2010-09-28 21:11:35 UTC (rev 3418) +++ trunk/LWJGL/src/java/org/lwjgl/BufferChecks.java 2010-09-30 17:21:50 UTC (rev 3419) @@ -31,13 +31,7 @@ */ package org.lwjgl; -import java.nio.Buffer; -import java.nio.ByteBuffer; -import java.nio.DoubleBuffer; -import java.nio.FloatBuffer; -import java.nio.IntBuffer; -import java.nio.ShortBuffer; -import java.nio.LongBuffer; +import java.nio.*; /** * <p>A class to check buffer boundaries in general. If there is unsufficient space @@ -89,21 +83,21 @@ /** Helper method to ensure an IntBuffer is null-terminated */ public static void checkNullTerminated(IntBuffer buf) { - if ( buf.get(buf.limit() - 1) != 0 ) { + if ( LWJGLUtil.CHECKS && buf.get(buf.limit() - 1) != 0 ) { throw new IllegalArgumentException("Missing null termination"); } } /** Helper method to ensure a LongBuffer is null-terminated */ public static void checkNullTerminated(LongBuffer buf) { - if ( buf.get(buf.limit() - 1) != 0 ) { + if ( LWJGLUtil.CHECKS && buf.get(buf.limit() - 1) != 0 ) { throw new IllegalArgumentException("Missing null termination"); } } /** Helper method to ensure a PointerBuffer is null-terminated */ public static void checkNullTerminated(PointerBuffer buf) { - if ( buf.get(buf.limit() - 1) != 0 ) { + if ( LWJGLUtil.CHECKS && buf.get(buf.limit() - 1) != 0 ) { throw new IllegalArgumentException("Missing null termination"); } } @@ -196,6 +190,41 @@ } } + /** + * Detects the buffer type and performs the corresponding check + * and also returns the buffer position in bytes. + * + * @param buffer the buffer to check + * @param size the size to check + * + * @return the buffer position in bytes + */ + public static int checkBuffer(final Buffer buffer, final int size) { + final int posShift; + if ( buffer instanceof ByteBuffer ) { + BufferChecks.checkBuffer((ByteBuffer)buffer, size); + posShift = 0; + } else if ( buffer instanceof ShortBuffer ) { + BufferChecks.checkBuffer((ShortBuffer)buffer, size); + posShift = 1; + } else if ( buffer instanceof IntBuffer ) { + BufferChecks.checkBuffer((IntBuffer)buffer, size); + posShift = 2; + } else if ( buffer instanceof LongBuffer ) { + BufferChecks.checkBuffer((LongBuffer)buffer, size); + posShift = 4; + } else if ( buffer instanceof FloatBuffer ) { + BufferChecks.checkBuffer((FloatBuffer)buffer, size); + posShift = 2; + } else if ( buffer instanceof DoubleBuffer ) { + BufferChecks.checkBuffer((DoubleBuffer)buffer, size); + posShift = 4; + } else + throw new IllegalArgumentException("Unsupported Buffer type specified: " + buffer.getClass()); + + return buffer.position() << posShift; + } + public static void checkBuffer(ByteBuffer buf, int size) { if ( LWJGLUtil.CHECKS ) { checkBufferSize(buf, size); Modified: trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java 2010-09-28 21:11:35 UTC (rev 3418) +++ trunk/LWJGL/src/java/org/lwjgl/LWJGLUtil.java 2010-09-30 17:21:50 UTC (rev 3419) @@ -32,17 +32,16 @@ package org.lwjgl; import java.io.File; +import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.nio.ByteBuffer; import java.security.AccessController; import java.security.PrivilegedAction; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; -import java.util.ArrayList; -import java.util.List; -import java.util.StringTokenizer; +import java.util.*; - /** * <p> * Internal library methods @@ -488,4 +487,92 @@ return major > major_required || (major == major_required && minor >= minor_required); } -} + /** + * Returns a map of public static final integer fields in the specified classes, to their String representations. + * An optional filter can be specified to only include specific fields. The target map may be null, in which + * case a new map is allocated and returned. + * <p> + * This method is useful when debugging to quickly identify values returned from the AL/GL/CL APIs. + * + * @param filter the filter to use (optional) + * @param target the target map (optional) + * @param tokenClasses an array of classes to get tokens from + * + * @return the token map + */ + + public static Map<Integer, String> getClassTokens(final TokenFilter filter, final Map<Integer, String> target, final Class ... tokenClasses) { + return getClassTokens(filter, target, Arrays.asList(tokenClasses)); + } + + /** + * Returns a map of public static final integer fields in the specified classes, to their String representations. + * An optional filter can be specified to only include specific fields. The target map may be null, in which + * case a new map is allocated and returned. + * <p> + * This method is useful when debugging to quickly identify values returned from the AL/GL/CL APIs. + * + * @param filter the filter to use (optional) + * @param target the target map (optional) + * @param tokenClasses the classes to get tokens from + * + * @return the token map + */ + public static Map<Integer, String> getClassTokens(final TokenFilter filter, Map<Integer, String> target, final Iterable<Class> tokenClasses) { + if ( target == null ) + target = new HashMap<Integer, String>(); + + final int TOKEN_MODIFIERS = Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL; + + for ( final Class tokenClass : tokenClasses ) { + for ( final Field field : tokenClass.getDeclaredFields() ) { + // Get only <public static final int> fields. + if ( (field.getModifiers() & TOKEN_MODIFIERS) == TOKEN_MODIFIERS && field.getType() == int.class ) { + try { + final int value = field.getInt(null); + if ( filter != null && !filter.accept(field, value) ) + continue; + + if ( target.containsKey(value) ) // Print colliding tokens in their hex representation. + target.put(value, toHexString(value)); + else + target.put(value, field.getName()); + } catch (IllegalAccessException e) { + // Ignore + } + } + } + } + + return target; + } + + /** + * Returns a string representation of the integer argument as an + * unsigned integer in base 16. The string will be uppercase + * and will have a leading '0x'. + * + * @param value the integer value + * + * @return the hex string representation + */ + public static String toHexString(final int value) { + return "0x" + Integer.toHexString(value).toUpperCase(); + } + + /** Simple interface for Field filtering. */ + public interface TokenFilter { + + /** + * Should return true if the specified Field passes the filter. + * + * @param field the Field to test + * @param value the integer value of the field + * + * @result true if the Field is accepted + */ + boolean accept(Field field, int value); + + } + +} \ No newline at end of file Modified: trunk/LWJGL/src/java/org/lwjgl/PointerWrapperAbstract.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/PointerWrapperAbstract.java 2010-09-28 21:11:35 UTC (rev 3418) +++ trunk/LWJGL/src/java/org/lwjgl/PointerWrapperAbstract.java 2010-09-30 17:21:50 UTC (rev 3419) @@ -63,7 +63,7 @@ */ public final void checkValid() { if ( LWJGLUtil.DEBUG && !isValid() ) - throw new IllegalStateException("This pointer is not valid."); + throw new IllegalStateException("This " + getClass().getSimpleName() + " pointer is not valid."); } public final long getPointer() { Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/APIUtil.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/APIUtil.java 2010-09-28 21:11:35 UTC (rev 3418) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/APIUtil.java 2010-09-30 17:21:50 UTC (rev 3419) @@ -35,18 +35,15 @@ import org.lwjgl.LWJGLUtil; import org.lwjgl.PointerBuffer; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; import java.nio.*; import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; -import java.util.*; +import java.util.HashSet; +import java.util.Set; +import java.util.StringTokenizer; -import static org.lwjgl.opencl.CL10.*; - /** * Utility class for OpenCL API calls. - * TODO: Remove useless stuff * * @author spasi */ @@ -356,38 +353,6 @@ return (int)size; } - static String toHexString(final int value) { - return "0x" + Integer.toHexString(value).toUpperCase(); - } - - static void getClassTokens(final Class[] tokenClasses, final Map<Integer, String> target, final TokenFilter filter) { - getClassTokens(Arrays.asList(tokenClasses), target, filter); - } - - static void getClassTokens(final Iterable<Class> tokenClasses, final Map<Integer, String> target, final TokenFilter filter) { - final int TOKEN_MODIFIERS = Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL; - - for ( final Class tokenClass : tokenClasses ) { - for ( final Field field : tokenClass.getDeclaredFields() ) { - // Get only <public static final int> fields. - if ( (field.getModifiers() & TOKEN_MODIFIERS) == TOKEN_MODIFIERS && field.getType() == int.class ) { - try { - final int value = field.getInt(null); - if ( filter != null && !filter.accept(field, value) ) - continue; - - if ( target.containsKey(value) ) // Print colliding tokens in their hex representation. - target.put(value, toHexString(value)); - else - target.put(value, field.getName()); - } catch (IllegalAccessException e) { - // Ignore - } - } - } - } - } - /** * A mutable CharSequence with very large initial length. We can wrap this in a re-usable CharBuffer for decoding. * We cannot subclass CharBuffer because of {@link java.nio.CharBuffer#toString(int,int)}. @@ -451,14 +416,6 @@ } - /** Simple interface for Field filtering */ - interface TokenFilter { - - /** Should return true if the specified Field passes the filter. */ - boolean accept(Field field, int value); - - } - /* ------------------------------------------------------------------------ --------------------------------------------------------------------------- OPENCL API UTILITIES BELOW Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/CLChecks.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/CLChecks.java 2010-09-28 21:11:35 UTC (rev 3418) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/CLChecks.java 2010-09-30 17:21:50 UTC (rev 3419) @@ -68,24 +68,24 @@ final long y = origin.get(1); final long z = origin.get(2); - if ( x < 0 || y < 0 || z < 0 ) + if ( LWJGLUtil.DEBUG && (x < 0 || y < 0 || z < 0) ) throw new IllegalArgumentException("Invalid cl_mem host origin: " + x + ", " + y + ", " + z); final long w = region.get(0); final long h = region.get(1); final long d = region.get(2); - if ( w < 1 || h < 1 || d < 1 ) + if ( LWJGLUtil.DEBUG && (w < 1 || h < 1 || d < 1) ) throw new IllegalArgumentException("Invalid cl_mem rectangle region dimensions: " + w + " x " + h + " x " + d); if ( row_pitch == 0 ) row_pitch = w; - else if ( row_pitch < w ) + else if ( LWJGLUtil.DEBUG && row_pitch < w ) throw new IllegalArgumentException("Invalid host row pitch specified: " + row_pitch); if ( slice_pitch == 0 ) slice_pitch = row_pitch * h; - else if ( slice_pitch < (row_pitch * h) ) + else if ( LWJGLUtil.DEBUG && slice_pitch < (row_pitch * h) ) throw new IllegalArgumentException("Invalid host slice pitch specified: " + slice_pitch); return (int)((z * slice_pitch + y * row_pitch + x) + (w * h * d)); @@ -110,17 +110,17 @@ final long h = region.get(1); final long d = region.get(2); - if ( w < 1 || h < 1 || d < 1 ) + if ( LWJGLUtil.DEBUG && (w < 1 || h < 1 || d < 1) ) throw new IllegalArgumentException("Invalid cl_mem image region dimensions: " + w + " x " + h + " x " + d); if ( row_pitch == 0 ) row_pitch = w; - else if ( row_pitch < w ) + else if ( LWJGLUtil.DEBUG && row_pitch < w ) throw new IllegalArgumentException("Invalid row pitch specified: " + row_pitch); if ( slice_pitch == 0 ) slice_pitch = row_pitch * h; - else if ( slice_pitch < (row_pitch * h) ) + else if ( LWJGLUtil.DEBUG && slice_pitch < (row_pitch * h) ) throw new IllegalArgumentException("Invalid slice pitch specified: " + slice_pitch); return (int)(slice_pitch * d); @@ -138,14 +138,17 @@ * @return the 2D image size in bytes */ static int calculateImage2DSize(final ByteBuffer format, final long w, final long h, long row_pitch) { - if ( LWJGLUtil.CHECKS && (w < 1 || h < 1) ) + if ( !LWJGLUtil.CHECKS ) + return 0; + + if ( LWJGLUtil.DEBUG && (w < 1 || h < 1) ) throw new IllegalArgumentException("Invalid 2D image dimensions: " + w + " x " + h); final int elementSize = getElementSize(format); if ( row_pitch == 0 ) row_pitch = w * elementSize; - else if ( LWJGLUtil.CHECKS && ((row_pitch < w * elementSize) || (row_pitch % elementSize != 0)) ) + else if ( LWJGLUtil.DEBUG && ((row_pitch < w * elementSize) || (row_pitch % elementSize != 0)) ) throw new IllegalArgumentException("Invalid image_row_pitch specified: " + row_pitch); return (int)(row_pitch * h); @@ -164,19 +167,22 @@ * @return the 3D image size in bytes */ static int calculateImage3DSize(final ByteBuffer format, final long w, final long h, final long d, long row_pitch, long slice_pitch) { - if ( LWJGLUtil.CHECKS && (w < 1 || h < 1 || d < 2) ) + if ( !LWJGLUtil.CHECKS ) + return 0; + + if ( LWJGLUtil.DEBUG && (w < 1 || h < 1 || d < 2) ) throw new IllegalArgumentException("Invalid 3D image dimensions: " + w + " x " + h + " x " + d); final int elementSize = getElementSize(format); if ( row_pitch == 0 ) row_pitch = w * elementSize; - else if ( LWJGLUtil.CHECKS && ((row_pitch < w * elementSize) || (row_pitch % elementSize != 0)) ) + else if ( LWJGLUtil.DEBUG && ((row_pitch < w * elementSize) || (row_pitch % elementSize != 0)) ) throw new IllegalArgumentException("Invalid image_row_pitch specified: " + row_pitch); if ( slice_pitch == 0 ) slice_pitch = row_pitch * h; - else if ( LWJGLUtil.CHECKS && ((row_pitch < row_pitch * h) || (slice_pitch % row_pitch != 0)) ) + else if ( LWJGLUtil.DEBUG && ((row_pitch < row_pitch * h) || (slice_pitch % row_pitch != 0)) ) throw new IllegalArgumentException("Invalid image_slice_pitch specified: " + row_pitch); return (int)(slice_pitch * d); @@ -223,7 +229,7 @@ case CL_ARGB: return 4; default: - throw new IllegalArgumentException("Invalid cl_channel_order specified: " + APIUtil.toHexString(channelOrder)); + throw new IllegalArgumentException("Invalid cl_channel_order specified: " + LWJGLUtil.toHexString(channelOrder)); } } @@ -255,7 +261,7 @@ case CL_FLOAT: return 4; default: - throw new IllegalArgumentException("Invalid cl_channel_type specified: " + APIUtil.toHexString(channelType)); + throw new IllegalArgumentException("Invalid cl_channel_type specified: " + LWJGLUtil.toHexString(channelType)); } } Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/CLContext.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/CLContext.java 2010-09-28 21:11:35 UTC (rev 3418) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/CLContext.java 2010-09-30 17:21:50 UTC (rev 3419) @@ -31,6 +31,12 @@ */ package org.lwjgl.opencl; +import org.lwjgl.LWJGLException; +import org.lwjgl.opencl.api.CLImageFormat; +import org.lwjgl.opencl.api.Filter; +import org.lwjgl.opengl.Drawable; + +import java.nio.IntBuffer; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -125,6 +131,100 @@ // ---------------[ UTILITY METHODS ]--------------- /** + * Creates a new CLContext. + * + * @param platform the platform to use + * @param devices the devices to use + * @param errcode_ret the error code result + * + * @return the new CLContext + * + * @throws LWJGLException if an exception occurs while creating the context + */ + public static CLContext create(final CLPlatform platform, final List<CLDevice> devices, final IntBuffer errcode_ret) throws LWJGLException { + return create(platform, devices, null, null, errcode_ret); + } + + /** + * Creates a new CLContext. + * + * @param platform the platform to use + * @param devices the devices to use + * @param pfn_notify the context callback function + * @param errcode_ret the error code result + * + * @return the new CLContext + * + * @throws LWJGLException if an exception occurs while creating the context + */ + public static CLContext create(final CLPlatform platform, final List<CLDevice> devices, final CLContextCallback pfn_notify, final IntBuffer errcode_ret) throws LWJGLException { + return create(platform, devices, pfn_notify, null, errcode_ret); + } + + /** + * Creates a new CLContext. + * + * @param platform the platform to use + * @param devices the devices to use + * @param share_drawable the OpenGL drawable to share objects with + * @param errcode_ret the error code result + * + * @return the new CLContext + * + * @throws LWJGLException if an exception occurs while creating the context + */ + public static CLContext create(final CLPlatform platform, final List<CLDevice> devices, final CLContextCallback pfn_notify, final Drawable share_drawable, final IntBuffer errcode_ret) throws LWJGLException { + return util.create(platform, devices, pfn_notify, share_drawable, errcode_ret); + } + + /** + * Creates a new CLContext. + * + * @param platform the platform to use + * @param device_type the device type to use + * @param errcode_ret the error code result + * + * @return the new CLContext + * + * @throws LWJGLException if an exception occurs while creating the context + */ + public static CLContext createFromType(final CLPlatform platform, final long device_type, final IntBuffer errcode_ret) throws LWJGLException { + return util.createFromType(platform, device_type, null, null, errcode_ret); + } + + /** + * Creates a new CLContext. + * + * @param platform the platform to use + * @param device_type the device type to use + * @param pfn_notify the context callback function + * @param errcode_ret the error code result + * + * @return the new CLContext + * + * @throws LWJGLException if an exception occurs while creating the context + */ + public static CLContext createFromType(final CLPlatform platform, final long device_type, final CLContextCallback pfn_notify, final IntBuffer errcode_ret) throws LWJGLException { + return util.createFromType(platform, device_type, pfn_notify, null, errcode_ret); + } + + /** + * Creates a new CLContext. + * + * @param platform the platform to use + * @param device_type the device type to use + * @param share_drawable the OpenGL drawable to share objects with + * @param errcode_ret the error code result + * + * @return the new CLContext + * + * @throws LWJGLException if an exception occurs while creating the context + */ + public static CLContext createFromType(final CLPlatform platform, final long device_type, final CLContextCallback pfn_notify, final Drawable share_drawable, final IntBuffer errcode_ret) throws LWJGLException { + return util.createFromType(platform, device_type, pfn_notify, share_drawable, errcode_ret); + } + + /** * Returns the integer value of the specified parameter. * * @param param_name the parameter @@ -144,11 +244,25 @@ return util.getInfoDevices(this); } + public List<CLImageFormat> getSupportedImageFormats(final long flags, final int image_type) { + return getSupportedImageFormats(flags, image_type, null); + } + + public List<CLImageFormat> getSupportedImageFormats(final long flags, final int image_type, final Filter<CLImageFormat> filter) { + return util.getSupportedImageFormats(this, flags, image_type, filter); + } + /** CLContext utility methods interface. */ interface CLContextUtil extends InfoUtil<CLContext> { List<CLDevice> getInfoDevices(CLContext context); + CLContext create(CLPlatform platform, List<CLDevice> devices, CLContextCallback pfn_notify, Drawable share_drawable, IntBuffer errcode_ret) throws LWJGLException; + + CLContext createFromType(CLPlatform platform, long device_type, CLContextCallback pfn_notify, Drawable share_drawable, IntBuffer errcode_ret) throws LWJGLException; + + List<CLImageFormat> getSupportedImageFormats(CLContext context, final long flags, final int image_type, Filter<CLImageFormat> filter); + } // -------[ IMPLEMENTATION STUFF BELOW ]------- Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/CLMem.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/CLMem.java 2010-09-28 21:11:35 UTC (rev 3418) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/CLMem.java 2010-09-30 17:21:50 UTC (rev 3419) @@ -31,7 +31,12 @@ */ package org.lwjgl.opencl; +import org.lwjgl.opencl.api.CLBufferRegion; +import org.lwjgl.opencl.api.CLImageFormat; + +import java.nio.Buffer; import java.nio.ByteBuffer; +import java.nio.IntBuffer; /** * This class is a wrapper around a cl_mem pointer. @@ -51,6 +56,52 @@ // ---------------[ UTILITY METHODS ]--------------- /** + * Creates a new 2D image object. + * + * @param context the context on which to create the image object + * @param flags the memory object flags + * @param image_format the image format + * @param image_width the image width + * @param image_height the image height + * @param image_row_pitch the image row pitch + * @param host_ptr the host buffer from which to read image data (optional) + * @param errcode_ret the error code result + * + * @return the new CLMem object + */ + public static CLMem createImage2D(final CLContext context, final long flags, final CLImageFormat image_format, + final long image_width, final long image_height, final long image_row_pitch, + final Buffer host_ptr, final IntBuffer errcode_ret) { + return util.createImage2D(context, flags, image_format, image_width, image_height, image_row_pitch, host_ptr, errcode_ret); + } + + /** + * Creates a new 3D image object. + * + * @param context the context on which to create the image object + * @param flags the memory object flags + * @param image_format the image format + * @param image_width the image width + * @param image_height the image height + * @param image_depth the image depth + * @param image_row_pitch the image row pitch + * @param image_slice_pitch the image slice pitch + * @param host_ptr the host buffer from which to read image data (optional) + * @param errcode_ret the error code result + * + * @return the new CLMem object + */ + public static CLMem createImage3D(final CLContext context, final long flags, final CLImageFormat image_format, + final long image_width, final long image_height, final long image_depth, final long image_row_pitch, final long image_slice_pitch, + final Buffer host_ptr, final IntBuffer errcode_ret) { + return util.createImage3D(context, flags, image_format, image_width, image_height, image_depth, image_row_pitch, image_slice_pitch, host_ptr, errcode_ret); + } + + public CLMem createSubBuffer(final long flags, final int buffer_create_type, final CLBufferRegion buffer_create_info, final IntBuffer errcode_ret) { + return util.createSubBuffer(this, flags, buffer_create_type, buffer_create_info, errcode_ret); + } + + /** * Returns the integer value of the specified parameter. * * @param param_name the parameter @@ -109,6 +160,15 @@ } /** + * Returns the image format. Applicable to image objects only. + * + * @return the parameter value + */ + public CLImageFormat getImageFormat() { + return util.getImageInfoFormat(this); + } + + /** * Returns the image channel order. Applicable to image objects only. * * @return the parameter value @@ -165,10 +225,18 @@ /** CLMem utility methods interface. */ interface CLMemUtil extends InfoUtil<CLMem> { + CLMem createImage2D(CLContext context, long flags, CLImageFormat image_format, long image_width, long image_height, long image_row_pitch, Buffer host_ptr, IntBuffer errcode_ret); + + CLMem createImage3D(CLContext context, long flags, CLImageFormat image_format, long image_width, long image_height, long image_depth, long image_row_pitch, long image_slice_pitch, Buffer host_ptr, IntBuffer errcode_ret); + + CLMem createSubBuffer(CLMem mem, long flags, int buffer_create_type, CLBufferRegion buffer_create_info, IntBuffer errcode_ret); + ByteBuffer getInfoHostBuffer(CLMem mem); long getImageInfoSize(CLMem mem, int param_name); + CLImageFormat getImageInfoFormat(CLMem mem); + int getImageInfoFormat(CLMem mem, int index); int getGLObjectType(CLMem mem); Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/CLProgram.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/CLProgram.java 2010-09-28 21:11:35 UTC (rev 3418) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/CLProgram.java 2010-09-30 17:21:50 UTC (rev 3419) @@ -70,6 +70,15 @@ // ---------------[ UTILITY METHODS ]--------------- /** + * Creates kernel objects for all kernels functions in this program. + * + * @return a CLKernel array + */ + public CLKernel[] createKernelsInProgram() { + return util.createKernelsInProgram(this); + } + + /** * Returns the String value of the specified parameter. * * @param param_name the parameter @@ -168,6 +177,8 @@ /** CLProgram utility methods interface. */ interface CLProgramUtil extends InfoUtil<CLProgram> { + CLKernel[] createKernelsInProgram(CLProgram program); + CLDevice[] getInfoDevices(CLProgram program); ByteBuffer getInfoBinaries(CLProgram program, ByteBuffer target); Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/InfoUtilAbstract.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/InfoUtilAbstract.java 2010-09-28 21:11:35 UTC (rev 3418) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/InfoUtilAbstract.java 2010-09-30 17:21:50 UTC (rev 3419) @@ -31,6 +31,7 @@ */ package org.lwjgl.opencl; +import org.lwjgl.LWJGLUtil; import org.lwjgl.PointerBuffer; import java.nio.ByteBuffer; @@ -112,8 +113,8 @@ object.checkValid(); final int bytes = getSizeRet(object, param_name); - if ( bytes == 0 ) - return ""; + if ( bytes <= 1 ) + return null; final ByteBuffer buffer = APIUtil.getBufferByte(bytes); getInfo(object, param_name, buffer, null); @@ -126,7 +127,7 @@ final PointerBuffer bytes = APIUtil.getBufferPointer(); final int errcode = getInfo(object, param_name, null, bytes); if ( errcode != CL_SUCCESS ) - throw new IllegalArgumentException("Invalid parameter specified: " + APIUtil.toHexString(param_name)); + throw new IllegalArgumentException("Invalid parameter specified: " + LWJGLUtil.toHexString(param_name)); return (int)bytes.get(0); } Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/InfoUtilFactory.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/InfoUtilFactory.java 2010-09-28 21:11:35 UTC (rev 3418) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/InfoUtilFactory.java 2010-09-30 17:21:50 UTC (rev 3419) @@ -32,8 +32,12 @@ package org.lwjgl.opencl; import org.lwjgl.*; +import org.lwjgl.opencl.api.CLBufferRegion; +import org.lwjgl.opencl.api.CLImageFormat; import org.lwjgl.opencl.api.Filter; +import org.lwjgl.opengl.Drawable; +import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.IntBuffer; import java.util.ArrayList; @@ -49,7 +53,6 @@ * so that they can be compiled for the generator. * * @author Spasi - * @since 28 \xD3\xE5\xF0 2010 */ final class InfoUtilFactory { @@ -92,6 +95,70 @@ } + /** Custom clCreateContext implementation (reuses APIUtil.getBufferPointer) */ + public CLContext create(final CLPlatform platform, final List<CLDevice> devices, final CLContextCallback pfn_notify, final Drawable share_drawable, final IntBuffer errcode_ret) throws LWJGLException { + final int propertyCount = 2 + (share_drawable == null ? 0 : 4) + 1; + + final PointerBuffer buffer = APIUtil.getBufferPointer(propertyCount + devices.size()); + buffer.put(CL_CONTEXT_PLATFORM).put(platform); + if ( share_drawable != null ) + share_drawable.setCLSharingProperties(buffer); + buffer.put(0); + + buffer.position(propertyCount); // Make sure we're at the right offset, setCLSharingProperties might not use all 4 positions. + for ( CLDevice device : devices ) + buffer.put(device); + + final long function_pointer = CLCapabilities.clCreateContext; + BufferChecks.checkFunctionAddress(function_pointer); + final long user_data = pfn_notify == null || pfn_notify.isCustom() ? 0 : CallbackUtil.createGlobalRef(pfn_notify); + CLContext __result = null; + try { + __result = new CLContext(nclCreateContext(buffer.getBuffer(), 0, devices.size(), buffer.getBuffer(), propertyCount * PointerBuffer.getPointerSize(), pfn_notify == null ? 0 : pfn_notify.getPointer(), user_data, errcode_ret, errcode_ret != null ? errcode_ret.position() : 0, function_pointer), platform); + return __result; + } finally { + CallbackUtil.registerCallback(__result, user_data); + } + } + + public CLContext createFromType(final CLPlatform platform, final long device_type, final CLContextCallback pfn_notify, final Drawable share_drawable, final IntBuffer errcode_ret) throws LWJGLException { + final int propertyCount = 2 + (share_drawable == null ? 0 : 4) + 1; + + final PointerBuffer properties = APIUtil.getBufferPointer(propertyCount); + properties.put(CL_CONTEXT_PLATFORM).put(platform); + if ( share_drawable != null ) + share_drawable.setCLSharingProperties(properties); + properties.put(0); + properties.flip(); + + return clCreateContextFromType(properties, device_type, pfn_notify, errcode_ret); + } + + public List<CLImageFormat> getSupportedImageFormats(final CLContext context, final long flags, final int image_type, final Filter<CLImageFormat> filter) { + final IntBuffer numBuffer = APIUtil.getBufferInt(); + clGetSupportedImageFormats(context, flags, image_type, null, numBuffer); + + final int num_image_formats = numBuffer.get(0); + if ( num_image_formats == 0 ) + return null; + + final ByteBuffer formatBuffer = BufferUtils.createByteBuffer(num_image_formats * CLImageFormat.STRUCT_SIZE); + clGetSupportedImageFormats(context, flags, image_type, formatBuffer, null); + + final List<CLImageFormat> formats = new ArrayList<CLImageFormat>(num_image_formats); + for ( int i = 0; i < num_image_formats; i++ ) { + final int offset = num_image_formats * CLImageFormat.STRUCT_SIZE; + final CLImageFormat format = new CLImageFormat( + formatBuffer.getInt(offset), + formatBuffer.getInt(offset + 4) + ); + if ( filter == null || filter.accept(format) ) + formats.add(format); + } + + return formats.size() == 0 ? null : formats; + } + } static final InfoUtil<CLDevice> CL_DEVICE_UTIL = new CLDeviceUtil(); @@ -106,7 +173,7 @@ case CL_DEVICE_MAX_WORK_ITEM_SIZES: return getInfoInt(device, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS); default: - throw new IllegalArgumentException("Unsupported parameter: " + APIUtil.toHexString(param_name)); + throw new IllegalArgumentException("Unsupported parameter: " + LWJGLUtil.toHexString(param_name)); } } @@ -183,7 +250,7 @@ size = 3; break; default: - throw new IllegalArgumentException("Unsupported parameter: " + APIUtil.toHexString(param_name)); + throw new IllegalArgumentException("Unsupported parameter: " + LWJGLUtil.toHexString(param_name)); } final PointerBuffer buffer = APIUtil.getBufferPointer(size); @@ -215,6 +282,44 @@ return clGetMemObjectInfo(mem, param_name, param_value, param_value_size_ret); } + public CLMem createImage2D(final CLContext context, final long flags, final CLImageFormat image_format, final long image_width, final long image_height, final long image_row_pitch, final Buffer host_ptr, final IntBuffer errcode_ret) { + final ByteBuffer formatBuffer = APIUtil.getBufferByte(2 * 4); + formatBuffer.putInt(0, image_format.getChannelOrder()); + formatBuffer.putInt(4, image_format.getChannelType()); + + final long function_pointer = CLCapabilities.clCreateImage2D; + BufferChecks.checkFunctionAddress(function_pointer); + if ( errcode_ret != null ) + BufferChecks.checkBuffer(errcode_ret, 1); + return 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); + } + + public CLMem createImage3D(final CLContext context, final long flags, final CLImageFormat image_format, final long image_width, final long image_height, final long image_depth, final long image_row_pitch, final long image_slice_pitch, final Buffer host_ptr, final IntBuffer errcode_ret) { + final ByteBuffer formatBuffer = APIUtil.getBufferByte(2 * 4); + formatBuffer.putInt(0, image_format.getChannelOrder()); + formatBuffer.putInt(4, image_format.getChannelType()); + + final long function_pointer = CLCapabilities.clCreateImage3D; + BufferChecks.checkFunctionAddress(function_pointer); + if ( errcode_ret != null ) + BufferChecks.checkBuffer(errcode_ret, 1); + return 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); + } + + public CLMem createSubBuffer(final CLMem mem, final long flags, final int buffer_create_type, final CLBufferRegion buffer_create_info, final IntBuffer errcode_ret) { + final PointerBuffer infoBuffer = APIUtil.getBufferPointer(2); + + infoBuffer.put(buffer_create_info.getOrigin()); + infoBuffer.put(buffer_create_info.getSize()); + + return clCreateSubBuffer(mem, flags, buffer_create_type, infoBuffer.getBuffer(), errcode_ret); + + } + public ByteBuffer getInfoHostBuffer(final CLMem mem) { mem.checkValid(); @@ -242,6 +347,16 @@ return buffer.get(0); } + public CLImageFormat getImageInfoFormat(final CLMem mem) { + mem.checkValid(); + + final ByteBuffer format = APIUtil.getBufferByte(2 * 4); + + clGetImageInfo(mem, CL_IMAGE_FORMAT, format, null); + + return new CLImageFormat(format.getInt(0), format.getInt(4)); + } + public int getImageInfoFormat(final CLMem mem, final int index) { mem.checkValid(); @@ -346,10 +461,28 @@ case CL_PROGRAM_BINARY_SIZES: return getInfoInt(program, CL_PROGRAM_NUM_DEVICES); default: - throw new IllegalArgumentException("Unsupported parameter: " + APIUtil.toHexString(param_name)); + throw new IllegalArgumentException("Unsupported parameter: " + LWJGLUtil.toHexString(param_name)); } } + public CLKernel[] createKernelsInProgram(final CLProgram program) { + final IntBuffer numBuffer = APIUtil.getBufferInt(); + clCreateKernelsInProgram(program, null, numBuffer); + + final int num_kernels = numBuffer.get(0); + if ( num_kernels == 0 ) + return null; + + final PointerBuffer kernelIDs = APIUtil.getBufferPointer(num_kernels); + clCreateKernelsInProgram(program, kernelIDs, null); + + final CLKernel[] kernels = new CLKernel[num_kernels]; + for ( int i = 0; i < num_kernels; i++ ) + kernels[i] = program.getCLKernel(kernelIDs.get(i)); + + return kernels; + } + public CLDevice[] getInfoDevices(final CLProgram program) { program.checkValid(); @@ -413,8 +546,8 @@ program.checkValid(); final int bytes = getBuildSizeRet(program, device, param_name); - if ( bytes == 0 ) - throw new IllegalArgumentException("Invalid parameter specified: " + APIUtil.toHexString(param_name)); + if ( bytes <= 1 ) + return null; final ByteBuffer buffer = APIUtil.getBufferByte(bytes); clGetProgramBuildInfo(program, device, param_name, buffer, null); @@ -435,8 +568,10 @@ private static int getBuildSizeRet(final CLProgram program, final CLDevice device, final int param_name) { final PointerBuffer bytes = APIUtil.getBufferPointer(); final int errcode = clGetProgramBuildInfo(program, device, param_name, null, bytes); + if ( errcode != CL_SUCCESS ) + throw new IllegalArgumentException("Invalid parameter specified: " + LWJGLUtil.toHexString(param_name)); - return errcode == CL_SUCCESS ? (int)bytes.get(0) : 0; + return (int)bytes.get(0); } } Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/Util.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/Util.java 2010-09-28 21:11:35 UTC (rev 3418) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/Util.java 2010-09-30 17:21:50 UTC (rev 3419) @@ -31,8 +31,9 @@ */ package org.lwjgl.opencl; +import org.lwjgl.LWJGLUtil; + import java.lang.reflect.Field; -import java.util.HashMap; import java.util.Map; /** @@ -43,21 +44,12 @@ public final class Util { /** Maps OpenCL error token values to their String representations. */ - private static final Map<Integer, String> CL_ERROR_TOKENS = new HashMap<Integer, String>(64); + private static final Map<Integer, String> CL_ERROR_TOKENS = LWJGLUtil.getClassTokens(new LWJGLUtil.TokenFilter() { + public boolean accept(final Field field, final int value) { + return value < 0; // Currently, all OpenCL errors have negative values. + } + }, null, CL10.class, CL11.class, KHRGLSharing.class, KHRICD.class, APPLEGLSharing.class, EXTDeviceFission.class); - static { - APIUtil.getClassTokens(new Class[] { - CL10.class, CL11.class, - KHRGLSharing.class, KHRICD.class, - APPLEGLSharing.class, - EXTDeviceFission.class, - }, CL_ERROR_TOKENS, new APIUtil.TokenFilter() { - public boolean accept(final Field field, final int value) { - return value < 0; // Currently, all OpenCL errors have negative values. - } - }); - } - private Util() { } @@ -70,7 +62,7 @@ String errname = CL_ERROR_TOKENS.get(errcode); if ( errname == null ) errname = "UNKNOWN"; - throw new OpenCLException("Error Code: " + errname + " (" + APIUtil.toHexString(errcode) + ")"); + throw new OpenCLException("Error Code: " + errname + " (" + LWJGLUtil.toHexString(errcode) + ")"); } } \ No newline at end of file Added: trunk/LWJGL/src/java/org/lwjgl/opencl/api/CLBufferRegion.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/api/CLBufferRegion.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/api/CLBufferRegion.java 2010-09-30 17:21:50 UTC (rev 3419) @@ -0,0 +1,62 @@ +/* + * 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.api; + +import org.lwjgl.PointerBuffer; + +/** + * Simple container for cl_buffer_region struct values. + * + * @author Spasi + */ +public final class CLBufferRegion { + + /** The cl_buffer_region struct size in bytes. */ + public static final int STRUCT_SIZE = 2 * PointerBuffer.getPointerSize(); + + private final int origin; + private final int size; + + public CLBufferRegion(final int origin, final int size) { + this.origin = origin; + this.size = size; + } + + public int getOrigin() { + return origin; + } + + public int getSize() { + return size; + } + +} \ No newline at end of file Added: trunk/LWJGL/src/java/org/lwjgl/opencl/api/CLImageFormat.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/api/CLImageFormat.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/api/CLImageFormat.java 2010-09-30 17:21:50 UTC (rev 3419) @@ -0,0 +1,60 @@ +/* + * 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.api; + +/** + * Simple container for cl_image_format struct values. + * + * @author Spasi + */ +public final class CLImageFormat { + + /** The cl_image_format struct size in bytes. */ + public static final int STRUCT_SIZE = 2 * 4; + + private final int channelOrder; + private final int channelType; + + public CLImageFormat(final int channelOrder, final int channelType) { + this.channelOrder = channelOrder; + this.channelType = channelType; + } + + public int getChannelOrder() { + return channelOrder; + } + + public int getChannelType() { + return channelType; + } + +} \ No newline at end of file Modified: trunk/LWJGL/src/java/org/lwjgl/test/opencl/gl/DemoFractal.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opencl/gl/DemoFractal.java 2010-09-28 21:11:35 UTC (rev 3418) +++ trunk/LWJGL/src/java/org/lwjgl/test/opencl/gl/DemoFractal.java 2010-09-30 17:21:50 UTC (rev 3419) @@ -43,18 +43,23 @@ import org.lwjgl.util.ReadableColor; import java.io.*; +import java.nio.ByteBuffer; import java.nio.IntBuffer; +import java.util.HashSet; import java.util.List; +import java.util.Set; import static java.lang.Math.*; import static org.lwjgl.opencl.CL10.*; import static org.lwjgl.opencl.CL10GL.*; import static org.lwjgl.opencl.KHRGLEvent.*; +import static org.lwjgl.opengl.AMDDebugOutput.*; import static org.lwjgl.opengl.ARBCLEvent.*; +import static org.lwjgl.opengl.ARBDebugOutput.*; import static org.lwjgl.opengl.ARBSync.*; import static org.lwjgl.opengl.GL11.*; -import static org.lwjgl.opengl.GL12.*; import static org.lwjgl.opengl.GL15.*; +import static org.lwjgl.opengl.GL20.*; import static org.lwjgl.opengl.GL21.*; /* @@ -118,25 +123,36 @@ // max number of used GPUs private static final int MAX_PARALLELISM_LEVEL = 8; - // max per pixel iterations to compute the fractal - private static final int MAX_ITERATIONS = 500; + private static final int COLOR_MAP_SIZE = 32 * 2 * 4; + private Set<String> params; + private CLContext clContext; private CLCommandQueue[] queues; private CLKernel[] kernels; private CLProgram[] programs; - private CLMem[] pboBuffers; - private IntBuffer pboIDs; + private CLMem[] glBuffers; + private IntBuffer glIDs; + private boolean useTextures; + + // Texture rendering + private int dlist; + private int vsh; + private int fsh; + private int program; + private CLMem[] colorMap; - private IntBuffer[] colorMapBuffer; private final PointerBuffer kernel2DGlobalWorkSize; - private int width; - private int height; + // max per pixel iterations to compute the fractal + private int maxIterations = 500; + private int width = 512; + private int height = 512; + private double minX = -2f; private double minY = -1.2f; private double maxX = 0.6f; @@ -174,135 +190,55 @@ private GLSync glSync; private CLEvent glEvent; - public DemoFractal(int width, int height) { - kernel2DGlobalWorkSize = BufferUtils.createPointerBuffer(2); + public DemoFractal(final String[] args) { + params = new HashSet<String>(); - this.width = width; - this.height = height; - } + for ( int i = 0; i < args.length; i++ ) { + final String arg = args[i]; - private void run() { - long startTime = System.currentTimeMillis() + 5000; - long fps = 0; + if ( arg.charAt(0) != '-' && arg.charAt(0) != '/' ) + throw new IllegalArgumentException("Invalid command-line argument: " + args[i]); - while ( run ) { - if ( !Display.isVisible() ) - Thread.yield(); + final String param = arg.substring(1); - handleIO(); - display(); + if ( "forcePBO".equalsIgnoreCase(param) ) + params.add("forcePBO"); + else if ( "forceCPU".equalsIgnoreCase(param) ) + params.add("forceCPU"); + else if ( "debugGL".equalsIgnoreCase(param) ) + params.add("debugGL"); + else if ( "iterations".equalsIgnoreCase(param) ) { + if ( args.length < i + 1 + 1 ) + throw new IllegalArgumentException("Invalid iterations argument specified."); - Display.update(); - if ( Display.isCloseRequested() ) - break; + try { + this.maxIterations = Integer.parseInt(args[++i]); + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Invalid number of iterations specified."); + } + } else if ( "res".equalsIgnoreCase(param) ) { + if ( args.length < i + 2 + 1 ) + throw new IllegalArgumentException("Invalid res argument specified."); - if ( startTime > System.currentTimeMillis() ) { - fps++; - } else { - long timeUsed = 5000 + (startTime - System.currentTimeMillis()); - startTime = System.currentTimeMillis() + 5000; - System.out.println(fps + " frames in 5 seconds = " + (fps / (timeUsed / 1000f))); - fps = 0; - } - } + try { + this.width = Integer.parseInt(args[++i]); + this.height = Integer.parseInt(args[++i]); - CL.destroy(); - Display.destroy(); - } - - private void handleIO() { - if ( Keyboard.getNumKeyboardEvents() != 0 ) { - while ( Keyboard.next() ) { - if ( Keyboard.getEventKeyState() ) - continue; - - final int key = Keyboard.getEventKey(); - - if ( Keyboard.KEY_1 <= key && key <= Keyboard.KEY_8 ) { - int number = key - Keyboard.KEY_1 + 1; - slices = min(number, min(queues.length, MAX_PARALLELISM_LEVEL)); - System.out.println("NEW PARALLELISM LEVEL: " + slices); - buffersInitialized = false; - } else { - switch ( Keyboard.getEventKey() ) { - case Keyboard.KEY_SPACE: - drawSeparator = !drawSeparator; - System.out.println("SEPARATOR DRAWING IS NOW: " + (drawSeparator ? "ON" : "OFF")); - break; - case Keyboard.KEY_D: - doublePrecision = !doublePrecision; - System.out.println("DOUBLE PRECISION IS NOW: " + (doublePrecision ? "ON" : "OFF")); - rebuild = true; - break; - case Keyboard.KEY_HOME: - minX = -2f; - minY = -1.2f; - maxX = 0.6f; - maxY = 1.3f; - break; - case Keyboard.KEY_ESCAPE: - run = false; - break; - } + if ( width < 1 || height < 1 ) + throw new IllegalArgumentException("Invalid res dimensions specified."); + } catch (NumberFormatException e) { + throw new IllegalArgumentException("Invalid res dimensions specified."); } } } - while ( Mouse.next() ) { - final int eventBtn = Mouse.getEventButton(); + kernel2DGlobalWorkSize = BufferUtils.createPointerBuffer(2); + } - final int x = Mouse.getX(); - final int y = Mouse.getY(); - - if ( Mouse.isButtonDown(0) && (x != mouseX || y != mouseY) ) { - if ( !dragging ) { - dragging = true; - - dragX = mouseX; - dragY = mouseY; - - dragMinX = minX; - dragMinY = minY; - dragMaxX = maxX; - dragMaxY = maxY; - } - - double offsetX = (x - dragX) * (maxX - minX) / width; - double offsetY = (y - dragY) * (maxY - minY) / height; - - minX = dragMinX - offsetX; - minY = dragMinY - offsetY; - - maxX = dragMaxX - offsetX; - maxY = dragMaxY - offsetY; - } else { - if ( dragging ) - dragging = false; - - if ( eventBtn == -1 ) { - final int dwheel = Mouse.getEventDWheel(); - if ( dwheel != 0 ) { - double scale = dwheel > 0 ? 0.05 : -0.05; - - double deltaX = scale * (maxX - minX); - double deltaY = scale * (maxY - minY); - - // offset for "zoom to cursor" - double offsetX = (x / (double)width - 0.5) * deltaX * 2.0; - double offsetY = (y / (double)height - 0.5) * deltaY * 2.0; - - minX += deltaX + offsetX; - minY += deltaY - offsetY; - - maxX += -deltaX + offsetX; - maxY += -deltaY - offsetY; - } - } - } - - mouseX = x; - mouseY = y; - } + public static void main(String args[]) { + DemoFractal demo = new DemoFractal(args); + demo.init(); + demo.run(); } public void init() { @@ -310,7 +246,8 @@ CL.create(); Display.setDisplayMode(new DisplayMode(width, height)); Display.setTitle("OpenCL Fractal Demo"); - Display.create(); + Display.setSwapInterval(0); + Display.create(new PixelFormat(), new ContextAttribs().withDebug(params.contains("debugGL"))); } catch (LWJGLException e) { throw new RuntimeException(e); } @@ -324,13 +261,12 @@ throw new RuntimeException(e); } - Display.setSwapInterval(0); glDisable(GL_DEPTH_TEST); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); initView(Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight()); - initPBO(); + initGLObjects(); glFinish(); setKernelConstants(); @@ -351,48 +287,40 @@ return caps.CL_KHR_gl_sharing; } }; - List<CLDevice> devices = platform.getDevices(CL_DEVICE_TYPE_GPU, glSharingFilter); + int device_type = params.contains("forceCPU") ? CL_DEVICE_TYPE_CPU : CL_DEVICE_TYPE_GPU; + List<CLDevice> devices = platform.getDevices(device_type, glSharingFilter); if ( devices == null ) { - devices = platform.getDevices(CL_DEVICE_TYPE_CPU, glSharingFilter); + device_type = CL_DEVICE_TYPE_CPU; + devices = platform.getDevices(device_type, glSharingFilter); if ( devices == null ) throw new RuntimeException("No OpenCL devices found with KHR_gl_sharing support."); } // Create the context - final PointerBuffer deviceIDs = BufferUtils.createPointerBuffer(devices.size()); - for ( CLDevice device : devices ) - deviceIDs.put(device); - deviceIDs.flip(); + clContext = CLContext.create(platform, devices, new CLContextCallback() { + protected void handleMessage(final String errinfo, final ByteBuffer private_info) { + System.out.println("[CONTEXT MESSAGE] " + errinfo); + } + }, drawable, null); - final PointerBuffer contextProps = BufferUtils.createPointerBuffer(2 + 4 + 1); - contextProps.put(CL_CONTEXT_PLATFORM).put(platform); - - drawable.setCLSharingProperties(contextProps); // Enable GL sharing - - contextProps.put(0); - contextProps.flip(); - clContext = clCreateContext(contextProps, deviceIDs, null, null); - slices = min(devices.size(), MAX_PARALLELISM_LEVEL); // create command queues for every GPU, setup colormap and init kernels queues = new CLCommandQueue[slices]; kernels = new CLKernel[slices]; colorMap = new CLMem[slices]; - colorMapBuffer = new IntBuffer[slices]; for ( int i = 0; i < slices; i++ ) { - colorMapBuffer[i] = BufferUtils.createIntBuffer(32 * 2); - colorMap[i] = clCreateBuffer(clContext, CL_MEM_READ_ONLY, colorMapBuffer[i].capacity() * 4, null); + colorMap[i] = clCreateBuffer(clContext, CL_MEM_READ_ONLY, COLOR_MAP_SIZE, null); colorMap[i].checkValid(); - initColorMap(colorMapBuffer[i], 32, Color.BLUE, Color.GREEN, Color.RED); - // create command queue and upload color map buffer on each used device queues[i] = clCreateCommandQueue(clContext, devices.get(i), CL_QUEUE_PROFILING_ENABLE, null); queues[i].checkValid(); - clEnqueueWriteBuffer(queues[i], colorMap[i], CL_TRUE, 0, colorMapBuffer[i], null, null); // blocking upload + final ByteBuffer colorMapBuffer = clEnqueueMapBuffer(queues[i], colorMap[i], CL_TRUE, CL_MAP_WRITE, 0, COLOR_MAP_SIZE, null, null, null); + initColorMap(colorMapBuffer.asIntBuffer(), 32, Color.BLUE, Color.GREEN, Color.RED); + clEnqueueUnmapMemObject(queues[i], colorMap[i], colorMapBuffer, null, null); } // check if we have 64bit FP support on all devices @@ -411,25 +339,51 @@ // load program(s) programs = new CLProgram[all64bit ? 1 : slices]; - buildPrograms(); - final ContextCapabilities caps = GLContext.getCapabilities(); - System.out.println("OpenGL caps.OpenGL32 = " + caps.OpenGL32); - System.out.println("OpenGL caps.GL_ARB_sync = " + caps.GL_ARB_sync); + if ( !caps.OpenGL20 ) + throw new RuntimeException("OpenGL 2.0 is required to run this demo."); + else if ( device_type == CL_DEVICE_TYPE_CPU && !caps.OpenGL21 ) + throw new RuntimeException("OpenGL 2.1 is required to run this demo."); + + if ( caps.GL_ARB_debug_output ) + glDebugMessageCallbackARB(new ARBDebugOutputCallback()); + else if ( caps.GL_AMD_debug_output ) + glDebugMessageCallbackAMD(new AMDDebugOutputCallback()); + + if ( device_type == CL_DEVICE_TYPE_GPU ) + System.out.println("OpenCL Device Type: GPU (Use -forceCPU to use CPU)"); + else + System.out.println("OpenCL Device Type: CPU"); + for ( int i = 0; i < devices.size(); i++ ) + System.out.println("OpenCL Device #" + (i + 1) + " supports KHR_gl_event = " + CLCapabilities.getDeviceCapabilities(devices.get(i)).CL_KHR_gl_event); + + System.out.println("\nMax Iterations: " + maxIterations + " (Use -iterations <count> to change)"); + System.out.println("Display resolution: " + width + "x" + height + " (Use -res <width> <height> to change)"); + + System.out.println("\nOpenGL caps.GL_ARB_sync = " + caps.GL_ARB_sync); System.out.println("OpenGL caps.GL_ARB_cl_event = " + caps.GL_ARB_cl_event); - for ( int i = 0; i < devices.size(); i++ ) { - System.out.println("Device #" + (i + 1) + " supports KHR_gl_event = " + CLCapabilities.getDeviceCapabilities(devices.get(i)).CL_KHR_gl_event); + + // Use PBO if we're on a CPU implementation + useTextures = device_type == CL_DEVICE_TYPE_GPU && (!caps.OpenGL21 || !params.contains("forcePBO")); + if ( useTextures ) { + System.out.println("\nCL/GL Sharing method: TEXTURES (use -forcePBO to use PBO + DrawPixels)"); + System.out.println("Rendering method: Shader on a fullscreen quad"); + } else { + System.out.println("\nCL/GL Sharing method: PIXEL BUFFER OBJECTS"); + System.out.println("Rendering method: DrawPixels"); } + buildPrograms(); + // Detect GLtoCL synchronization method syncGLtoCL = caps.GL_ARB_cl_event; // GL3.2 or ARB_sync implied if ( syncGLtoCL ) { clEvents = new CLEvent[slices]; clSyncs = new GLSync[slices]; - System.out.println("GL to CL sync: Using OpenCL events"); + System.out.println("\nGL to CL sync: Using OpenCL events"); } else - System.out.println("GL to CL sync: Using clFinish"); + System.out.println("\nGL to CL sync: Using clFinish"); // Detect CLtoGL synchronization method syncCLtoGL = caps.OpenGL32 || caps.GL_ARB_sync; @@ -445,92 +399,57 @@ System.out.println("CL to GL sync: Using OpenGL sync objects"); } else System.out.println("CL to GL sync: Using glFinish"); - } - private void createPrograms() throws IOException { - final String source = getProgramSource("Mandelbrot.cl"); - for ( int i = 0; i < programs.length; i++ ) - programs[i] = clCreateProgramWithSource(clContext, source, null); - } + if ( useTextures ) { + dlist = glGenLists(1); - private String getProgramSource(final String file) throws IOException { - InputStream source = getClass().getResourceAsStream(file); - if ( source == null ) // dev-mode - source = new FileInputStream("... [truncated message content] |
From: <sp...@us...> - 2010-09-30 19:04:31
|
Revision: 3421 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3421&view=rev Author: spasi Date: 2010-09-30 19:04:25 +0000 (Thu, 30 Sep 2010) Log Message: ----------- Added NV OpenCL extensions. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/test/opencl/HelloOpenCL.java trunk/LWJGL/src/templates/org/lwjgl/opencl/KHR_fp16.java Added Paths: ----------- trunk/LWJGL/src/templates/org/lwjgl/opencl/NV_compiler_options.java trunk/LWJGL/src/templates/org/lwjgl/opencl/NV_device_attribute_query.java trunk/LWJGL/src/templates/org/lwjgl/opencl/NV_pragma_unroll.java Modified: trunk/LWJGL/src/java/org/lwjgl/test/opencl/HelloOpenCL.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opencl/HelloOpenCL.java 2010-09-30 17:52:16 UTC (rev 3420) +++ trunk/LWJGL/src/java/org/lwjgl/test/opencl/HelloOpenCL.java 2010-09-30 19:04:25 UTC (rev 3421) @@ -94,6 +94,7 @@ printDeviceInfo(device, "CL_DRIVER_VERSION", CL_DRIVER_VERSION); printDeviceInfo(device, "CL_DEVICE_PROFILE", CL_DEVICE_PROFILE); printDeviceInfo(device, "CL_DEVICE_VERSION", CL_DEVICE_VERSION); + printDeviceInfo(device, "CL_DEVICE_EXTENSIONS", CL_DEVICE_EXTENSIONS); if ( caps.OpenCL11 ) printDeviceInfo(device, "CL_DEVICE_OPENCL_C_VERSION", CL_DEVICE_OPENCL_C_VERSION); Modified: trunk/LWJGL/src/templates/org/lwjgl/opencl/KHR_fp16.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opencl/KHR_fp16.java 2010-09-30 17:52:16 UTC (rev 3420) +++ trunk/LWJGL/src/templates/org/lwjgl/opencl/KHR_fp16.java 2010-09-30 19:04:25 UTC (rev 3421) @@ -36,4 +36,7 @@ @CLDeviceExtension public interface KHR_fp16 { + /** cl_device_info */ + int CL_DEVICE_HALF_FP_CONFIG = 0x1033; + } \ No newline at end of file Added: trunk/LWJGL/src/templates/org/lwjgl/opencl/NV_compiler_options.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opencl/NV_compiler_options.java (rev 0) +++ trunk/LWJGL/src/templates/org/lwjgl/opencl/NV_compiler_options.java 2010-09-30 19:04:25 UTC (rev 3421) @@ -0,0 +1,39 @@ +/* + * 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 NV_compiler_options { + +} \ No newline at end of file Added: trunk/LWJGL/src/templates/org/lwjgl/opencl/NV_device_attribute_query.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opencl/NV_device_attribute_query.java (rev 0) +++ trunk/LWJGL/src/templates/org/lwjgl/opencl/NV_device_attribute_query.java 2010-09-30 19:04:25 UTC (rev 3421) @@ -0,0 +1,48 @@ +/* + * 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 NV_device_attribute_query { + + /** Accepted as the <param_name> parameter of clGetDeviceInfo. */ + int CL_DEVICE_COMPUTE_CAPABILITY_MAJOR_NV = 0x4000, + CL_DEVICE_COMPUTE_CAPABILITY_MINOR_NV = 0x4001, + CL_DEVICE_REGISTERS_PER_BLOCK_NV = 0x4002, + CL_DEVICE_WARP_SIZE_NV = 0x4003, + CL_DEVICE_GPU_OVERLAP_NV = 0x4004, + CL_DEVICE_KERNEL_EXEC_TIMEOUT_NV = 0x4005, + CL_DEVICE_INTEGRATED_MEMORY_NV = 0x4006; + +} \ No newline at end of file Added: trunk/LWJGL/src/templates/org/lwjgl/opencl/NV_pragma_unroll.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opencl/NV_pragma_unroll.java (rev 0) +++ trunk/LWJGL/src/templates/org/lwjgl/opencl/NV_pragma_unroll.java 2010-09-30 19:04:25 UTC (rev 3421) @@ -0,0 +1,39 @@ +/* + * 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 NV_pragma_unroll { + +} \ 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...> - 2010-09-30 23:36:48
|
Revision: 3422 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3422&view=rev Author: spasi Date: 2010-09-30 23:36:37 +0000 (Thu, 30 Sep 2010) Log Message: ----------- Misc CL fixes. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/PointerBuffer.java trunk/LWJGL/src/java/org/lwjgl/PointerWrapperAbstract.java trunk/LWJGL/src/java/org/lwjgl/opencl/APIUtil.java trunk/LWJGL/src/java/org/lwjgl/opencl/CLPlatform.java trunk/LWJGL/src/java/org/lwjgl/opencl/InfoUtilFactory.java trunk/LWJGL/src/java/org/lwjgl/test/opencl/HelloOpenCL.java trunk/LWJGL/src/templates/org/lwjgl/opencl/APPLE_gl_sharing.java trunk/LWJGL/src/templates/org/lwjgl/opencl/CL10.java trunk/LWJGL/src/templates/org/lwjgl/opencl/KHR_gl_sharing.java Modified: trunk/LWJGL/src/java/org/lwjgl/PointerBuffer.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/PointerBuffer.java 2010-09-30 19:04:25 UTC (rev 3421) +++ trunk/LWJGL/src/java/org/lwjgl/PointerBuffer.java 2010-09-30 23:36:37 UTC (rev 3422) @@ -290,6 +290,16 @@ } /** + * Returns the number of bytes between the current position and the + * limit. </p> + * + * @return The number of bytes remaining in this buffer + */ + public final int remainingByte() { + return remaining() * getPointerSize(); + } + + /** * Tells whether there are any elements between the current position and * the limit. </p> * Modified: trunk/LWJGL/src/java/org/lwjgl/PointerWrapperAbstract.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/PointerWrapperAbstract.java 2010-09-30 19:04:25 UTC (rev 3421) +++ trunk/LWJGL/src/java/org/lwjgl/PointerWrapperAbstract.java 2010-09-30 23:36:37 UTC (rev 3422) @@ -87,6 +87,6 @@ } public String toString() { - return getClass().getSimpleName() + " pointer (0x" + Long.toHexString(pointer) + ")"; + return getClass().getSimpleName() + " pointer (0x" + Long.toHexString(pointer).toUpperCase() + ")"; } } \ No newline at end of file Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/APIUtil.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/APIUtil.java 2010-09-30 19:04:25 UTC (rev 3421) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/APIUtil.java 2010-09-30 23:36:37 UTC (rev 3422) @@ -42,6 +42,11 @@ import java.util.Set; import java.util.StringTokenizer; +import static org.lwjgl.opencl.APPLEGLSharing.*; +import static org.lwjgl.opencl.CL10.*; +import static org.lwjgl.opencl.EXTDeviceFission.*; +import static org.lwjgl.opencl.KHRGLSharing.*; + /** * Utility class for OpenCL API calls. * @@ -432,6 +437,19 @@ return extensions; } + static boolean isDevicesParam(final int param_name) { + switch ( param_name ) { + case CL_CONTEXT_DEVICES: + case CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR: + case CL_DEVICES_FOR_GL_CONTEXT_KHR: + case CL_CGL_DEVICE_FOR_CURRENT_VIRTUAL_SCREEN_APPLE: + case CL_CGL_DEVICES_FOR_SUPPORTED_VIRTUAL_SCREENS_APPLE: + return true; + } + + return false; + } + static CLPlatform getCLPlatform(final PointerBuffer properties) { long platformID = 0; @@ -441,7 +459,7 @@ if ( key == 0 ) break; - if ( key == 0x1084 ) { // CL_CONTEXT_PLATFORM + if ( key == CL_CONTEXT_PLATFORM ) { platformID = properties.get((k << 1) + 1); break; } @@ -452,7 +470,7 @@ final CLPlatform platform = CLPlatform.getCLPlatform(platformID); if ( platform == null ) - throw new IllegalStateException("Could not find a valid CLPlatform. Make sure clGetPlatformIDs has been used before creating a CLContext."); + throw new IllegalStateException("Could not find a valid CLPlatform. Make sure clGetPlatformIDs has been used before."); return platform; } @@ -546,25 +564,25 @@ } private static final ObjectDestructor<CLDevice> DESTRUCTOR_CLSubDevice = new ObjectDestructor<CLDevice>() { - public void release(final CLDevice object) { EXTDeviceFission.clReleaseDeviceEXT(object); } + public void release(final CLDevice object) { clReleaseDeviceEXT(object); } }; private static final ObjectDestructor<CLMem> DESTRUCTOR_CLMem = new ObjectDestructor<CLMem>() { - public void release(final CLMem object) { CL10.clReleaseMemObject(object); } + public void release(final CLMem object) { clReleaseMemObject(object); } }; private static final ObjectDestructor<CLCommandQueue> DESTRUCTOR_CLCommandQueue = new ObjectDestructor<CLCommandQueue>() { - public void release(final CLCommandQueue object) { CL10.clReleaseCommandQueue(object); } + public void release(final CLCommandQueue object) { clReleaseCommandQueue(object); } }; private static final ObjectDestructor<CLSampler> DESTRUCTOR_CLSampler = new ObjectDestructor<CLSampler>() { - public void release(final CLSampler object) { CL10.clReleaseSampler(object); } + public void release(final CLSampler object) { clReleaseSampler(object); } }; private static final ObjectDestructor<CLProgram> DESTRUCTOR_CLProgram = new ObjectDestructor<CLProgram>() { - public void release(final CLProgram object) { CL10.clReleaseProgram(object); } + public void release(final CLProgram object) { clReleaseProgram(object); } }; private static final ObjectDestructor<CLKernel> DESTRUCTOR_CLKernel = new ObjectDestructor<CLKernel>() { - public void release(final CLKernel object) { CL10.clReleaseKernel(object); } + public void release(final CLKernel object) { clReleaseKernel(object); } }; private static final ObjectDestructor<CLEvent> DESTRUCTOR_CLEvent = new ObjectDestructor<CLEvent>() { - public void release(final CLEvent object) { CL10.clReleaseEvent(object); } + public void release(final CLEvent object) { clReleaseEvent(object); } }; private interface ObjectDestructor<T extends CLObjectChild> { Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/CLPlatform.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/CLPlatform.java 2010-09-30 19:04:25 UTC (rev 3421) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/CLPlatform.java 2010-09-30 23:36:37 UTC (rev 3422) @@ -210,7 +210,7 @@ for ( int i = 0; i < count; i++ ) { final long id = devices.get(pos + i); if ( !clDevices.hasObject(id) ) - new CLDevice(devices.get(pos + i), this); + new CLDevice(id, this); } } @@ -226,7 +226,7 @@ final int offset = pos + (i * PointerBuffer.getPointerSize()); final long id = PointerBuffer.is64Bit() ? devices.getLong(offset) : devices.getInt(offset); if ( !clDevices.hasObject(id) ) - new CLDevice(devices.get(pos + i), this); + new CLDevice(id, this); } } Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/InfoUtilFactory.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/InfoUtilFactory.java 2010-09-30 19:04:25 UTC (rev 3421) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/InfoUtilFactory.java 2010-09-30 23:36:37 UTC (rev 3422) @@ -96,25 +96,31 @@ } /** Custom clCreateContext implementation (reuses APIUtil.getBufferPointer) */ - public CLContext create(final CLPlatform platform, final List<CLDevice> devices, final CLContextCallback pfn_notify, final Drawable share_drawable, final IntBuffer errcode_ret) throws LWJGLException { + public CLContext create(final CLPlatform platform, final List<CLDevice> devices, final CLContextCallback pfn_notify, final Drawable share_drawable, IntBuffer errcode_ret) throws LWJGLException { final int propertyCount = 2 + (share_drawable == null ? 0 : 4) + 1; - final PointerBuffer buffer = APIUtil.getBufferPointer(propertyCount + devices.size()); - buffer.put(CL_CONTEXT_PLATFORM).put(platform); + final PointerBuffer properties = APIUtil.getBufferPointer(propertyCount + devices.size()); + properties.put(CL_CONTEXT_PLATFORM).put(platform); if ( share_drawable != null ) - share_drawable.setCLSharingProperties(buffer); - buffer.put(0); + share_drawable.setCLSharingProperties(properties); + properties.put(0); - buffer.position(propertyCount); // Make sure we're at the right offset, setCLSharingProperties might not use all 4 positions. + properties.position(propertyCount); // Make sure we're at the right offset, setCLSharingProperties might not use all 4 positions. for ( CLDevice device : devices ) - buffer.put(device); + properties.put(device); final long function_pointer = CLCapabilities.clCreateContext; BufferChecks.checkFunctionAddress(function_pointer); + if ( errcode_ret != null ) + BufferChecks.checkBuffer(errcode_ret, 1); + else if ( LWJGLUtil.DEBUG ) + errcode_ret = APIUtil.getBufferInt(); final long user_data = pfn_notify == null || pfn_notify.isCustom() ? 0 : CallbackUtil.createGlobalRef(pfn_notify); CLContext __result = null; try { - __result = new CLContext(nclCreateContext(buffer.getBuffer(), 0, devices.size(), buffer.getBuffer(), propertyCount * PointerBuffer.getPointerSize(), 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(properties.getBuffer(), 0, devices.size(), properties.getBuffer(), propertyCount * PointerBuffer.getPointerSize(), pfn_notify == null ? 0 : pfn_notify.getPointer(), user_data, errcode_ret, errcode_ret != null ? errcode_ret.position() : 0, function_pointer), platform); + if ( LWJGLUtil.DEBUG ) + Util.checkCLError(errcode_ret.get(0)); return __result; } finally { CallbackUtil.registerCallback(__result, user_data); @@ -282,7 +288,7 @@ return clGetMemObjectInfo(mem, param_name, param_value, param_value_size_ret); } - public CLMem createImage2D(final CLContext context, final long flags, final CLImageFormat image_format, final long image_width, final long image_height, final long image_row_pitch, final Buffer host_ptr, final IntBuffer errcode_ret) { + public CLMem createImage2D(final CLContext context, final long flags, final CLImageFormat image_format, final long image_width, final long image_height, final long image_row_pitch, final Buffer host_ptr, IntBuffer errcode_ret) { final ByteBuffer formatBuffer = APIUtil.getBufferByte(2 * 4); formatBuffer.putInt(0, image_format.getChannelOrder()); formatBuffer.putInt(4, image_format.getChannelType()); @@ -291,12 +297,18 @@ BufferChecks.checkFunctionAddress(function_pointer); if ( errcode_ret != null ) BufferChecks.checkBuffer(errcode_ret, 1); - return 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); + 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); + if ( LWJGLUtil.DEBUG ) + Util.checkCLError(errcode_ret.get(0)); + return __result; } - public CLMem createImage3D(final CLContext context, final long flags, final CLImageFormat image_format, final long image_width, final long image_height, final long image_depth, final long image_row_pitch, final long image_slice_pitch, final Buffer host_ptr, final IntBuffer errcode_ret) { + public CLMem createImage3D(final CLContext context, final long flags, final CLImageFormat image_format, final long image_width, final long image_height, final long image_depth, final long image_row_pitch, final long image_slice_pitch, final Buffer host_ptr, IntBuffer errcode_ret) { final ByteBuffer formatBuffer = APIUtil.getBufferByte(2 * 4); formatBuffer.putInt(0, image_format.getChannelOrder()); formatBuffer.putInt(4, image_format.getChannelType()); @@ -305,9 +317,15 @@ BufferChecks.checkFunctionAddress(function_pointer); if ( errcode_ret != null ) BufferChecks.checkBuffer(errcode_ret, 1); - return 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); + 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); + if ( LWJGLUtil.DEBUG ) + Util.checkCLError(errcode_ret.get(0)); + return __result; } public CLMem createSubBuffer(final CLMem mem, final long flags, final int buffer_create_type, final CLBufferRegion buffer_create_info, final IntBuffer errcode_ret) { @@ -317,7 +335,6 @@ infoBuffer.put(buffer_create_info.getSize()); return clCreateSubBuffer(mem, flags, buffer_create_type, infoBuffer.getBuffer(), errcode_ret); - } public ByteBuffer getInfoHostBuffer(final CLMem mem) { Modified: trunk/LWJGL/src/java/org/lwjgl/test/opencl/HelloOpenCL.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opencl/HelloOpenCL.java 2010-09-30 19:04:25 UTC (rev 3421) +++ trunk/LWJGL/src/java/org/lwjgl/test/opencl/HelloOpenCL.java 2010-09-30 23:36:37 UTC (rev 3422) @@ -54,6 +54,9 @@ CL.create(); final List<CLPlatform> platforms = CLPlatform.getPlatforms(); + if ( platforms == null ) + throw new RuntimeException("No OpenCL platforms found."); + for ( CLPlatform platform : platforms ) { System.out.println("\n-------------------------"); System.out.println("NEW PLATFORM: " + platform.getPointer()); Modified: trunk/LWJGL/src/templates/org/lwjgl/opencl/APPLE_gl_sharing.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opencl/APPLE_gl_sharing.java 2010-09-30 19:04:25 UTC (rev 3421) +++ trunk/LWJGL/src/templates/org/lwjgl/opencl/APPLE_gl_sharing.java 2010-09-30 23:36:37 UTC (rev 3422) @@ -67,6 +67,10 @@ /** Error code returned by clGetGLContextInfoAPPLE if an invalid platform_gl_ctx is provided */ int CL_INVALID_GL_CONTEXT_APPLE = -1000; + @Code( + javaBeforeNative = "\t\tif ( param_value_size_ret == null && APIUtil.isDevicesParam(param_name) ) param_value_size_ret = APIUtil.getBufferPointer();", + javaAfterNative = "\t\tif ( __result == CL_SUCCESS && param_value != null && APIUtil.isDevicesParam(param_name) ) context.getParent().registerCLDevices(param_value, param_value_size_ret);" + ) @cl_int int clGetGLContextInfoAPPLE(@PointerWrapper("cl_context") CLContext context, @Check("1") @NativeType("cl_void") PointerBuffer platform_gl_ctx, Modified: trunk/LWJGL/src/templates/org/lwjgl/opencl/CL10.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opencl/CL10.java 2010-09-30 19:04:25 UTC (rev 3421) +++ trunk/LWJGL/src/templates/org/lwjgl/opencl/CL10.java 2010-09-30 23:36:37 UTC (rev 3422) @@ -456,8 +456,8 @@ int clReleaseContext(@PointerWrapper("cl_context") CLContext context); @Code( - javaBeforeNative = "\t\tif ( param_name == CL_CONTEXT_DEVICES && param_value_size_ret == null ) param_value_size_ret = APIUtil.getBufferPointer();", - javaAfterNative = "\t\tif ( param_name == CL_CONTEXT_DEVICES && __result == CL_SUCCESS && param_value != null ) context.getParent().registerCLDevices(param_value, param_value_size_ret);" + javaBeforeNative = "\t\tif ( param_value_size_ret == null && APIUtil.isDevicesParam(param_name) ) param_value_size_ret = APIUtil.getBufferPointer();", + javaAfterNative = "\t\tif ( __result == CL_SUCCESS && param_value != null && APIUtil.isDevicesParam(param_name) ) context.getParent().registerCLDevices(param_value, param_value_size_ret);" ) @cl_int int clGetContextInfo(@PointerWrapper("cl_context") CLContext context, @@ -915,7 +915,7 @@ @cl_int int clGetProgramInfo2(@PointerWrapper("cl_program") CLProgram program, @Constant("CL_PROGRAM_BINARIES") @NativeType("cl_program_info") int param_name, - @Constant("sizes.remaining() * PointerBuffer.getPointerSize()") @size_t long param_value_size, + @Constant("sizes.remainingByte()") @size_t long param_value_size, @Helper(passToNative = true) @Check("1") @Const @NativeType("size_t") PointerBuffer sizes, @OutParameter @Check("APIUtil.getSize(sizes)") @PointerArray(value = "param_value_size", lengths = "sizes") @NativeType("cl_uchar") ByteBuffer param_value, @OutParameter @Check(value = "1", canBeNull = true) @NativeType("size_t") PointerBuffer param_value_size_ret); Modified: trunk/LWJGL/src/templates/org/lwjgl/opencl/KHR_gl_sharing.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opencl/KHR_gl_sharing.java 2010-09-30 19:04:25 UTC (rev 3421) +++ trunk/LWJGL/src/templates/org/lwjgl/opencl/KHR_gl_sharing.java 2010-09-30 23:36:37 UTC (rev 3422) @@ -63,6 +63,10 @@ CL_WGL_HDC_KHR = 0x200B, CL_CGL_SHAREGROUP_KHR = 0x200C; + @Code( + javaBeforeNative = "\t\tif ( param_value_size_ret == null && APIUtil.isDevicesParam(param_name) ) param_value_size_ret = APIUtil.getBufferPointer();", + javaAfterNative = "\t\tif ( __result == CL_SUCCESS && param_value != null && APIUtil.isDevicesParam(param_name) ) APIUtil.getCLPlatform(properties).registerCLDevices(param_value, param_value_size_ret);" + ) @cl_int int clGetGLContextInfoKHR(@NullTerminated @Const @NativeType("cl_context_properties") PointerBuffer properties, @NativeType("cl_gl_context_info") int param_name, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sp...@us...> - 2010-10-01 17:00:24
|
Revision: 3425 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3425&view=rev Author: spasi Date: 2010-10-01 17:00:17 +0000 (Fri, 01 Oct 2010) Log Message: ----------- Fixed Mandelbrot.cl to not crash on Cuda. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/test/opencl/gl/DemoFractal.java trunk/LWJGL/src/java/org/lwjgl/test/opencl/gl/Mandelbrot.cl trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_viewport_array.java Modified: trunk/LWJGL/src/java/org/lwjgl/test/opencl/gl/DemoFractal.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opencl/gl/DemoFractal.java 2010-10-01 03:48:41 UTC (rev 3424) +++ trunk/LWJGL/src/java/org/lwjgl/test/opencl/gl/DemoFractal.java 2010-10-01 17:00:17 UTC (rev 3425) @@ -476,7 +476,7 @@ for ( int i = 0; i < programs.length; i++ ) { final CLDevice device = queues[i].getCLDevice(); - final StringBuilder options = new StringBuilder(useTextures ? " -D USE_TEXTURE" : ""); + final StringBuilder options = new StringBuilder(useTextures ? "-D USE_TEXTURE" : ""); final CLDeviceCapabilities caps = CLCapabilities.getDeviceCapabilities(device); if ( doublePrecision && isDoubleFPAvailable(device) ) { //cl_khr_fp64 Modified: trunk/LWJGL/src/java/org/lwjgl/test/opencl/gl/Mandelbrot.cl =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opencl/gl/Mandelbrot.cl 2010-10-01 03:48:41 UTC (rev 3424) +++ trunk/LWJGL/src/java/org/lwjgl/test/opencl/gl/Mandelbrot.cl 2010-10-01 17:00:17 UTC (rev 3425) @@ -4,15 +4,17 @@ #else #pragma OPENCL EXTENSION cl_khr_fp64 : enable #endif - typedef double varfloat; + #define varfloat double + #define _255 255.0 #else - typedef float varfloat; + #define varfloat float + #define _255 255.0f #endif #ifdef USE_TEXTURE - typedef __write_only image2d_t OUTPUT_TYPE; + #define OUTPUT_TYPE __write_only image2d_t #else - typedef global uint * OUTPUT_TYPE; + #define OUTPUT_TYPE global uint * #endif /** @@ -54,7 +56,7 @@ #else output[iy * width + ix] = 0; #endif - } else { + } else { varfloat alpha = (varfloat)iteration / maxIterations; int colorIndex = (int)(alpha * colorMapSize); #ifdef USE_TEXTURE @@ -67,9 +69,9 @@ (c & 0xFF) >> 0, (c & 0xFF00) >> 8, (c & 0xFF0000) >> 16, - 255.0 + _255 ); - write_imagef(output, (int2)(ix, iy), oc / 255.0); + write_imagef(output, (int2)(ix, iy), oc / _255); #else output[iy * width + ix] = colorMap[colorIndex]; #endif Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_viewport_array.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_viewport_array.java 2010-10-01 03:48:41 UTC (rev 3424) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_viewport_array.java 2010-10-01 17:00:17 UTC (rev 3425) @@ -122,17 +122,15 @@ @StripPostfix("data") void glGetDoublei_v2(@GLenum int target, @GLuint int index, @OutParameter DoubleBuffer data); - // TODO: It's glGetIntegerIndexedvEXT in EXT_draw_buffers2, spec typo? - //@Reuse(extension = "EXT_draw_buffers2", className = "EXTDrawBuffers2") + @Reuse("EXTDrawBuffers2") @StripPostfix(value = "v", extension = "EXT") - void glGetIntegerIndexedivEXT(@GLenum int target, @GLuint int index, @Check @OutParameter IntBuffer v); + void glGetIntegerIndexedvEXT(@GLenum int target, @GLuint int index, @Check @OutParameter IntBuffer v); - // TODO: It's glGetIntegerIndexedvEXT in EXT_draw_buffers2, spec typo? - //@Reuse(extension = "EXT_draw_buffers2", className = "EXTDrawBuffers2") + @Reuse("EXTDrawBuffers2") @Alternate("glGetIntegerIndexedivEXT") @GLreturn("v") @StripPostfix(value = "v", extension = "EXT") - void glGetIntegerIndexedivEXT2(@GLenum int target, @GLuint int index, @OutParameter IntBuffer v); + void glGetIntegerIndexedvEXT2(@GLenum int target, @GLuint int index, @OutParameter IntBuffer v); @Reuse("EXTDrawBuffers2") void glEnableIndexedEXT(@GLenum int target, @GLuint int index); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sp...@us...> - 2010-10-01 22:20:21
|
Revision: 3426 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3426&view=rev Author: spasi Date: 2010-10-01 22:20:14 +0000 (Fri, 01 Oct 2010) Log Message: ----------- OpenCL bug fixes on MacOS. Improved 64bit pointer detection. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/DefaultSysImplementation.java trunk/LWJGL/src/java/org/lwjgl/Sys.java trunk/LWJGL/src/java/org/lwjgl/SysImplementation.java trunk/LWJGL/src/java/org/lwjgl/opencl/APIUtil.java trunk/LWJGL/src/java/org/lwjgl/opencl/CallbackUtil.java trunk/LWJGL/src/java/org/lwjgl/test/opencl/HelloOpenCL.java trunk/LWJGL/src/native/common/common_tools.c Modified: trunk/LWJGL/src/java/org/lwjgl/DefaultSysImplementation.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/DefaultSysImplementation.java 2010-10-01 17:00:17 UTC (rev 3425) +++ trunk/LWJGL/src/java/org/lwjgl/DefaultSysImplementation.java 2010-10-01 22:20:14 UTC (rev 3426) @@ -40,6 +40,7 @@ */ abstract class DefaultSysImplementation implements SysImplementation { public native int getJNIVersion(); + public native int getPointerSize(); public native void setDebug(boolean debug); public long getTimerResolution() { Modified: trunk/LWJGL/src/java/org/lwjgl/Sys.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/Sys.java 2010-10-01 17:00:17 UTC (rev 3425) +++ trunk/LWJGL/src/java/org/lwjgl/Sys.java 2010-10-01 22:20:14 UTC (rev 3426) @@ -77,15 +77,13 @@ }); } - private static boolean loadLibrary(final String lib_name) { + private static void loadLibrary(final String lib_name) { try { doLoadLibrary(lib_name); - return false; } catch (UnsatisfiedLinkError e) { if (implementation.has64Bit()) { try { doLoadLibrary(lib_name + POSTFIX64BIT); - return true; } catch (UnsatisfiedLinkError e2) { LWJGLUtil.log("Failed to load 64 bit library: " + e2.getMessage()); } @@ -97,13 +95,14 @@ static { implementation = createImplementation(); - is64Bit = loadLibrary(JNI_LIBRARY_NAME); + loadLibrary(JNI_LIBRARY_NAME); + is64Bit = implementation.getPointerSize() == 8; int native_jni_version = implementation.getJNIVersion(); int required_version = implementation.getRequiredJNIVersion(); if (native_jni_version != required_version) throw new LinkageError("Version mismatch: jar version is '" + required_version + - "', native libary version is '" + native_jni_version + "'"); + "', native library version is '" + native_jni_version + "'"); implementation.setDebug(LWJGLUtil.DEBUG); } Modified: trunk/LWJGL/src/java/org/lwjgl/SysImplementation.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/SysImplementation.java 2010-10-01 17:00:17 UTC (rev 3425) +++ trunk/LWJGL/src/java/org/lwjgl/SysImplementation.java 2010-10-01 22:20:14 UTC (rev 3426) @@ -51,6 +51,11 @@ */ int getJNIVersion(); + /** + * Returns the platform's pointer size in bytes + */ + int getPointerSize(); + void setDebug(boolean debug); /** Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/APIUtil.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/APIUtil.java 2010-10-01 17:00:17 UTC (rev 3425) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/APIUtil.java 2010-10-01 22:20:14 UTC (rev 3426) @@ -430,9 +430,11 @@ static Set<String> getExtensions(final String extensionList) { final Set<String> extensions = new HashSet<String>(); - final StringTokenizer tokenizer = new StringTokenizer(extensionList); - while ( tokenizer.hasMoreTokens() ) - extensions.add(tokenizer.nextToken()); + if ( extensionList != null ) { + final StringTokenizer tokenizer = new StringTokenizer(extensionList); + while ( tokenizer.hasMoreTokens() ) + extensions.add(tokenizer.nextToken()); + } return extensions; } Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/CallbackUtil.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/CallbackUtil.java 2010-10-01 17:00:17 UTC (rev 3425) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/CallbackUtil.java 2010-10-01 22:20:14 UTC (rev 3426) @@ -34,6 +34,8 @@ import java.util.HashMap; import java.util.Map; +import static org.lwjgl.opencl.CL10.*; + /** * Utility class that handles OpenCL API callbacks. * @@ -79,7 +81,7 @@ * @param user_data the GlobalRef memory address */ static void checkCallback(final int errcode, final long user_data) { - if ( errcode != 0x0 && user_data != 0 ) + if ( errcode != CL_SUCCESS && user_data != 0 ) deleteGlobalRef(user_data); } @@ -107,7 +109,7 @@ * @param user_data the global reference pointer */ static void registerCallback(final CLContext context, final long user_data) { - if ( context.getPointer() == 0 ) { + if ( context.getPointerUnsafe() == 0 ) { if ( user_data != 0 ) deleteGlobalRef(user_data); return; Modified: trunk/LWJGL/src/java/org/lwjgl/test/opencl/HelloOpenCL.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opencl/HelloOpenCL.java 2010-10-01 17:00:17 UTC (rev 3425) +++ trunk/LWJGL/src/java/org/lwjgl/test/opencl/HelloOpenCL.java 2010-10-01 22:20:14 UTC (rev 3426) @@ -33,6 +33,7 @@ import org.lwjgl.BufferUtils; import org.lwjgl.LWJGLException; +import org.lwjgl.LWJGLUtil; import org.lwjgl.PointerBuffer; import org.lwjgl.opencl.*; import org.lwjgl.opencl.api.CLBufferRegion; @@ -49,7 +50,7 @@ public HelloOpenCL() { } - protected void execute() { + protected static void execute() { try { CL.create(); @@ -135,28 +136,31 @@ clRetainMemObject(buffer); - final long exec_caps = device.getInfoLong(CL_DEVICE_EXECUTION_CAPABILITIES); - if ( (exec_caps & CL_EXEC_NATIVE_KERNEL) == CL_EXEC_NATIVE_KERNEL ) { - System.out.println("-TRYING TO EXEC NATIVE KERNEL-"); - final CLCommandQueue queue = clCreateCommandQueue(context, device, 0, null); + if ( LWJGLUtil.getPlatform() != LWJGLUtil.PLATFORM_MACOSX ) { + // TODO: Native kernels crash on MacOSX, disable this until we can debug properly. + final long exec_caps = device.getInfoLong(CL_DEVICE_EXECUTION_CAPABILITIES); + if ( (exec_caps & CL_EXEC_NATIVE_KERNEL) == CL_EXEC_NATIVE_KERNEL ) { + System.out.println("-TRYING TO EXEC NATIVE KERNEL-"); + final CLCommandQueue queue = clCreateCommandQueue(context, device, 0, null); - clEnqueueNativeKernel(queue, new CLNativeKernel() { - protected void execute(final ByteBuffer[] memobjs) { - if ( memobjs == null ) - System.out.println("OK, it's null"); - else { - System.out.println("memobjs = " + memobjs.length); - for ( int k = 0; k < memobjs.length; k++ ) { - System.out.println("memobjs[" + k + "].remaining() = " + memobjs[k].remaining()); - for ( int l = memobjs[k].position(); l < memobjs[k].limit(); l++ ) { - memobjs[k].put(l, (byte)l); + clEnqueueNativeKernel(queue, new CLNativeKernel() { + protected void execute(final ByteBuffer[] memobjs) { + if ( memobjs == null ) + System.out.println("OK, it's null"); + else { + System.out.println("memobjs = " + memobjs.length); + for ( int k = 0; k < memobjs.length; k++ ) { + System.out.println("memobjs[" + k + "].remaining() = " + memobjs[k].remaining()); + for ( int l = memobjs[k].position(); l < memobjs[k].limit(); l++ ) { + memobjs[k].put(l, (byte)l); + } } } } - } - }, new CLMem[] { buffer }, new long[] { 128 }, null, null); + }, new CLMem[] { buffer }, new long[] { 128 }, null, null); - clFinish(queue); + clFinish(queue); + } } clReleaseMemObject(buffer); Modified: trunk/LWJGL/src/native/common/common_tools.c =================================================================== --- trunk/LWJGL/src/native/common/common_tools.c 2010-10-01 17:00:17 UTC (rev 3425) +++ trunk/LWJGL/src/native/common/common_tools.c 2010-10-01 22:20:14 UTC (rev 3426) @@ -61,6 +61,10 @@ list->current_index++; } +JNIEXPORT jint JNICALL Java_org_lwjgl_DefaultSysImplementation_getPointerSize(JNIEnv *env, jclass clazz) { + return (jint)sizeof(void *); +} + JNIEXPORT void JNICALL Java_org_lwjgl_DefaultSysImplementation_setDebug (JNIEnv *env, jobject ignored, jboolean enable) { debug = enable == JNI_TRUE ? true : false; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sp...@us...> - 2010-10-04 17:04:53
|
Revision: 3430 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3430&view=rev Author: spasi Date: 2010-10-04 17:04:46 +0000 (Mon, 04 Oct 2010) Log Message: ----------- Minor clean-up. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/util/generator/GeneratorProcessorFactory.java trunk/LWJGL/src/java/org/lwjgl/util/generator/GeneratorVisitor.java trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaTypeTranslator.java trunk/LWJGL/src/native/common/org_lwjgl_opencl_CallbackUtil.c Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/GeneratorProcessorFactory.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/GeneratorProcessorFactory.java 2010-10-02 13:07:46 UTC (rev 3429) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/GeneratorProcessorFactory.java 2010-10-04 17:04:46 UTC (rev 3430) @@ -38,8 +38,6 @@ import java.util.Collection; import java.util.Map; import java.util.Set; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import com.sun.mirror.apt.*; import com.sun.mirror.declaration.AnnotationTypeDeclaration; Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/GeneratorVisitor.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/GeneratorVisitor.java 2010-10-02 13:07:46 UTC (rev 3429) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/GeneratorVisitor.java 2010-10-04 17:04:46 UTC (rev 3430) @@ -110,10 +110,6 @@ NativeType native_type_annotation = NativeTypeTranslator.getAnnotation(annotation, NativeType.class); if (native_type_annotation != null) { Class<? extends Annotation> annotation_type = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType()); - /*System.out.println("\nYO:"); - System.out.println("annotation = " + annotation); - System.out.println("native_type_annotation = " + native_type_annotation); - System.out.println("annotation_type = " + annotation_type);*/ Class type = Utils.getJavaType(type_mirror); if (Buffer.class.equals(type)) continue; @@ -229,10 +225,8 @@ native_writer.println("#include <jni.h>"); type_map.printNativeIncludes(native_writer); native_writer.println(); - //if ( d.getAnnotation(NoTypeDefs.class) == null ) { TypedefsGenerator.generateNativeTypedefs(type_map, native_writer, d.getMethods()); native_writer.println(); - //} if (!context_specific) { generateMethodsNativePointers(native_writer, d.getMethods()); native_writer.println(); Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java 2010-10-02 13:07:46 UTC (rev 3429) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java 2010-10-04 17:04:46 UTC (rev 3430) @@ -134,7 +134,7 @@ first_parameter = false; if ( printTypes ) writer.print("boolean "); - writer.print( TypeInfo.UNSIGNED_PARAMETER_NAME); + writer.print(TypeInfo.UNSIGNED_PARAMETER_NAME); } } } else if ( Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaTypeTranslator.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaTypeTranslator.java 2010-10-02 13:07:46 UTC (rev 3429) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaTypeTranslator.java 2010-10-04 17:04:46 UTC (rev 3430) @@ -74,27 +74,6 @@ throw new RuntimeException(e); } } - - /* - final String className = t.getComponentType().toString(); - if ( "java.lang.CharSequence".equals(className) ) - type = CharSequence[].class; - else if ( "java.nio.ByteBuffer".equals(className) ) - type = ByteBuffer[].class; - else if ( "org.lwjgl.opencl.CLMem".equals(className) ) - type = CLMem[].class; - else - throw new RuntimeException(t + " is not allowed"); - //*/ - /* - try { - System.out.println("t = " + t); - System.out.println("t.getClass() = " + t.getClass()); - System.out.println("t.getComponentType() = " + t.getComponentType()); - type = Class.forName(t.toString()); - } catch (ClassNotFoundException e) { - throw new RuntimeException(e); - }*/ } public static Class getPrimitiveClassFromKind(PrimitiveType.Kind kind) { Modified: trunk/LWJGL/src/native/common/org_lwjgl_opencl_CallbackUtil.c =================================================================== --- trunk/LWJGL/src/native/common/org_lwjgl_opencl_CallbackUtil.c 2010-10-02 13:07:46 UTC (rev 3429) +++ trunk/LWJGL/src/native/common/org_lwjgl_opencl_CallbackUtil.c 2010-10-04 17:04:46 UTC (rev 3430) @@ -144,7 +144,7 @@ static void CL_USER_FUNC_CALLBACK nativeKernelCallback(void *args) { JNIEnv *env = attachCurrentThread(); - jobject user_func = (jobject)*(intptr_t *)args; + jobject user_func = (jobject)(intptr_t)*(jlong *)args; jint num_mem_objects = *(jint *)((char *)args + 8); jobjectArray memobjs = NULL; jobject buffer; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sp...@us...> - 2010-10-04 22:51:26
|
Revision: 3431 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3431&view=rev Author: spasi Date: 2010-10-04 22:51:19 +0000 (Mon, 04 Oct 2010) Log Message: ----------- Fixed 64bit loading. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/Sys.java Removed Paths: ------------- trunk/LWJGL/src/native/common/org_lwjgl_opencl_CL.h trunk/LWJGL/src/native/common/org_lwjgl_opencl_CallbackUtil.h trunk/LWJGL/src/native/common/org_lwjgl_opengl_CallbackUtil.h Modified: trunk/LWJGL/src/java/org/lwjgl/Sys.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/Sys.java 2010-10-04 17:04:46 UTC (rev 3430) +++ trunk/LWJGL/src/java/org/lwjgl/Sys.java 2010-10-04 22:51:19 UTC (rev 3431) @@ -84,6 +84,7 @@ if (implementation.has64Bit()) { try { doLoadLibrary(lib_name + POSTFIX64BIT); + return; } catch (UnsatisfiedLinkError e2) { LWJGLUtil.log("Failed to load 64 bit library: " + e2.getMessage()); } Deleted: trunk/LWJGL/src/native/common/org_lwjgl_opencl_CL.h =================================================================== --- trunk/LWJGL/src/native/common/org_lwjgl_opencl_CL.h 2010-10-04 17:04:46 UTC (rev 3430) +++ trunk/LWJGL/src/native/common/org_lwjgl_opencl_CL.h 2010-10-04 22:51:19 UTC (rev 3431) @@ -1,62 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include <jni.h> -/* Header for class org_lwjgl_opencl_CL */ - -#ifndef _Included_org_lwjgl_opencl_CL -#define _Included_org_lwjgl_opencl_CL -#ifdef __cplusplus -extern "C" { -#endif -/* Inaccessible static: created */ -/* - * Class: org_lwjgl_opencl_CL - * Method: nCreate - * Signature: (Ljava/lang/String;)V - */ -JNIEXPORT void JNICALL Java_org_lwjgl_opencl_CL_nCreate - (JNIEnv *, jclass, jstring); - -/* - * Class: org_lwjgl_opencl_CL - * Method: nCreateDefault - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_org_lwjgl_opencl_CL_nCreateDefault - (JNIEnv *, jclass); - -/* - * Class: org_lwjgl_opencl_CL - * Method: nDestroy - * Signature: ()V - */ -JNIEXPORT void JNICALL Java_org_lwjgl_opencl_CL_nDestroy - (JNIEnv *, jclass); - -/* - * Class: org_lwjgl_opencl_CL - * Method: getFunctionAddress - * Signature: (Ljava/lang/String;)J - */ -JNIEXPORT jlong JNICALL Java_org_lwjgl_opencl_CL_getFunctionAddress - (JNIEnv *, jclass, jstring); - -/* - * Class: org_lwjgl_opencl_CL - * Method: getHostBuffer - * Signature: (JI)Ljava/nio/ByteBuffer; - */ -JNIEXPORT jobject JNICALL Java_org_lwjgl_opencl_CL_getHostBuffer - (JNIEnv *, jclass, jlong, jint); - -/* - * Class: org_lwjgl_opencl_CL - * Method: resetNativeStubs - * Signature: (Ljava/lang/Class;)V - */ -JNIEXPORT void JNICALL Java_org_lwjgl_opencl_CL_resetNativeStubs - (JNIEnv *, jclass, jclass); - -#ifdef __cplusplus -} -#endif -#endif Deleted: trunk/LWJGL/src/native/common/org_lwjgl_opencl_CallbackUtil.h =================================================================== --- trunk/LWJGL/src/native/common/org_lwjgl_opencl_CallbackUtil.h 2010-10-04 17:04:46 UTC (rev 3430) +++ trunk/LWJGL/src/native/common/org_lwjgl_opencl_CallbackUtil.h 2010-10-04 22:51:19 UTC (rev 3431) @@ -1,94 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include <jni.h> -/* Header for class org_lwjgl_opencl_CallbackUtil */ - -#ifndef _Included_org_lwjgl_opencl_CallbackUtil -#define _Included_org_lwjgl_opencl_CallbackUtil -#ifdef __cplusplus -extern "C" { -#endif -/* Inaccessible static: contextUserData */ -/* - * Class: org_lwjgl_opencl_CallbackUtil - * Method: ncreateGlobalRef - * Signature: (Ljava/lang/Object;)J - */ -JNIEXPORT jlong JNICALL Java_org_lwjgl_opencl_CallbackUtil_ncreateGlobalRef - (JNIEnv *, jclass, jobject); - -/* - * Class: org_lwjgl_opencl_CallbackUtil - * Method: deleteGlobalRef - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_org_lwjgl_opencl_CallbackUtil_deleteGlobalRef - (JNIEnv *, jclass, jlong); - -/* - * Class: org_lwjgl_opencl_CallbackUtil - * Method: getContextCallback - * Signature: ()J - */ -JNIEXPORT jlong JNICALL Java_org_lwjgl_opencl_CallbackUtil_getContextCallback - (JNIEnv *, jclass); - -/* - * Class: org_lwjgl_opencl_CallbackUtil - * Method: getMemObjectDestructorCallback - * Signature: ()J - */ -JNIEXPORT jlong JNICALL Java_org_lwjgl_opencl_CallbackUtil_getMemObjectDestructorCallback - (JNIEnv *, jclass); - -/* - * Class: org_lwjgl_opencl_CallbackUtil - * Method: getBuildProgramCallback - * Signature: ()J - */ -JNIEXPORT jlong JNICALL Java_org_lwjgl_opencl_CallbackUtil_getBuildProgramCallback - (JNIEnv *, jclass); - -/* - * Class: org_lwjgl_opencl_CallbackUtil - * Method: getNativeKernelCallback - * Signature: ()J - */ -JNIEXPORT jlong JNICALL Java_org_lwjgl_opencl_CallbackUtil_getNativeKernelCallback - (JNIEnv *, jclass); - -/* - * Class: org_lwjgl_opencl_CallbackUtil - * Method: getEventCallback - * Signature: ()J - */ -JNIEXPORT jlong JNICALL Java_org_lwjgl_opencl_CallbackUtil_getEventCallback - (JNIEnv *, jclass); - -/* - * Class: org_lwjgl_opencl_CallbackUtil - * Method: getLogMessageToSystemLogAPPLE - * Signature: ()J - */ -JNIEXPORT jlong JNICALL Java_org_lwjgl_opencl_CallbackUtil_getLogMessageToSystemLogAPPLE - (JNIEnv *, jclass); - -/* - * Class: org_lwjgl_opencl_CallbackUtil - * Method: getLogMessageToStdoutAPPLE - * Signature: ()J - */ -JNIEXPORT jlong JNICALL Java_org_lwjgl_opencl_CallbackUtil_getLogMessageToStdoutAPPLE - (JNIEnv *, jclass); - -/* - * Class: org_lwjgl_opencl_CallbackUtil - * Method: getLogMessageToStderrAPPLE - * Signature: ()J - */ -JNIEXPORT jlong JNICALL Java_org_lwjgl_opencl_CallbackUtil_getLogMessageToStderrAPPLE - (JNIEnv *, jclass); - -#ifdef __cplusplus -} -#endif -#endif Deleted: trunk/LWJGL/src/native/common/org_lwjgl_opengl_CallbackUtil.h =================================================================== --- trunk/LWJGL/src/native/common/org_lwjgl_opengl_CallbackUtil.h 2010-10-04 17:04:46 UTC (rev 3430) +++ trunk/LWJGL/src/native/common/org_lwjgl_opengl_CallbackUtil.h 2010-10-04 22:51:19 UTC (rev 3431) @@ -1,47 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include <jni.h> -/* Header for class org_lwjgl_opengl_CallbackUtil */ - -#ifndef _Included_org_lwjgl_opengl_CallbackUtil -#define _Included_org_lwjgl_opengl_CallbackUtil -#ifdef __cplusplus -extern "C" { -#endif -/* Inaccessible static: contextUserParamsARB */ -/* Inaccessible static: contextUserParamsAMD */ -/* - * Class: org_lwjgl_opengl_CallbackUtil - * Method: ncreateGlobalRef - * Signature: (Ljava/lang/Object;)J - */ -JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_CallbackUtil_ncreateGlobalRef - (JNIEnv *, jclass, jobject); - -/* - * Class: org_lwjgl_opengl_CallbackUtil - * Method: deleteGlobalRef - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_CallbackUtil_deleteGlobalRef - (JNIEnv *, jclass, jlong); - -/* - * Class: org_lwjgl_opengl_CallbackUtil - * Method: getDebugOutputCallbackARB - * Signature: ()J - */ -JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_CallbackUtil_getDebugOutputCallbackARB - (JNIEnv *, jclass); - -/* - * Class: org_lwjgl_opengl_CallbackUtil - * Method: getDebugOutputCallbackAMD - * Signature: ()J - */ -JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_CallbackUtil_getDebugOutputCallbackAMD - (JNIEnv *, jclass); - -#ifdef __cplusplus -} -#endif -#endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sp...@us...> - 2010-10-12 01:35:40
|
Revision: 3436 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3436&view=rev Author: spasi Date: 2010-10-12 01:35:33 +0000 (Tue, 12 Oct 2010) Log Message: ----------- Replaced HashMap<Long, T> with FastLongMap in the OpenCL package. Replaced CharsetEncoder with simple ASCII encoding in APIUtil. Attempt to fix CL native kernels on x64. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opencl/APIUtil.java trunk/LWJGL/src/java/org/lwjgl/opencl/CLContext.java trunk/LWJGL/src/java/org/lwjgl/opencl/CLObjectRegistry.java trunk/LWJGL/src/java/org/lwjgl/opencl/CLObjectRegistryGlobal.java trunk/LWJGL/src/java/org/lwjgl/opencl/CLPlatform.java trunk/LWJGL/src/java/org/lwjgl/opengl/APIUtil.java trunk/LWJGL/src/native/common/org_lwjgl_opencl_CallbackUtil.c trunk/LWJGL/src/templates/org/lwjgl/opencl/CL10.java Added Paths: ----------- trunk/LWJGL/src/java/org/lwjgl/opencl/FastLongMap.java Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/APIUtil.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/APIUtil.java 2010-10-08 20:57:23 UTC (rev 3435) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/APIUtil.java 2010-10-12 01:35:33 UTC (rev 3436) @@ -34,10 +34,9 @@ import org.lwjgl.BufferUtils; import org.lwjgl.LWJGLUtil; import org.lwjgl.PointerBuffer; +import org.lwjgl.opencl.FastLongMap.Entry; import java.nio.*; -import java.nio.charset.Charset; -import java.nio.charset.CharsetEncoder; import java.util.HashSet; import java.util.Set; import java.util.StringTokenizer; @@ -75,16 +74,10 @@ protected PointerBuffer initialValue() { return BufferUtils.createPointerBuffer(INITIAL_LENGTHS_SIZE); } }; - private static final ThreadLocal<InfiniteCharSequence> infiniteSeqTL = new ThreadLocal<InfiniteCharSequence>() { - protected InfiniteCharSequence initialValue() { return new InfiniteCharSequence(); } - }; - private static final ThreadLocal<Buffers> buffersTL = new ThreadLocal<Buffers>() { protected Buffers initialValue() { return new Buffers(); } }; - private static final CharsetEncoder encoder = Charset.forName("US-ASCII").newEncoder(); - private APIUtil() { } @@ -188,15 +181,22 @@ return lengths; } - private static InfiniteCharSequence getInfiniteSeq() { - return infiniteSeqTL.get(); - } + /** + * Simple ASCII encoding. + * + * @param buffer The target buffer + * @param string The source string + */ + private static ByteBuffer encode(final ByteBuffer buffer, final CharSequence string) { + for ( int i = 0; i < string.length(); i++ ) { + final char c = string.charAt(i); + if ( LWJGLUtil.DEBUG && 0x80 <= c ) // Silently ignore and map to 0x1A. + buffer.put((byte)0x1A); + else + buffer.put((byte)c); + } - private static void encode(final ByteBuffer buffer, final CharSequence string) { - final InfiniteCharSequence infiniteSeq = getInfiniteSeq(); - infiniteSeq.setString(string); - encoder.encode(infiniteSeq.buffer, buffer, true); - infiniteSeq.clear(); + return buffer; } /** @@ -224,10 +224,7 @@ * @return the String as a ByteBuffer */ static ByteBuffer getBuffer(final CharSequence string) { - final ByteBuffer buffer = getBufferByte(string.length()); - - encode(buffer, string); - + final ByteBuffer buffer = encode(getBufferByte(string.length()), string); buffer.flip(); return buffer; } @@ -240,10 +237,7 @@ * @return the String as a ByteBuffer */ static ByteBuffer getBuffer(final CharSequence string, final int offset) { - final ByteBuffer buffer = getBufferByteOffset(offset + string.length()); - - encode(buffer, string); - + final ByteBuffer buffer = encode(getBufferByteOffset(offset + string.length()), string); buffer.flip(); return buffer; } @@ -256,10 +250,7 @@ * @return the String as a ByteBuffer */ static ByteBuffer getBufferNT(final CharSequence string) { - final ByteBuffer buffer = getBufferByte(string.length() + 1); - - encode(buffer, string); - + final ByteBuffer buffer = encode(getBufferByte(string.length() + 1), string); buffer.put((byte)0); buffer.flip(); return buffer; @@ -283,12 +274,8 @@ static ByteBuffer getBuffer(final CharSequence[] strings) { final ByteBuffer buffer = getBufferByte(getTotalLength(strings)); - final InfiniteCharSequence infiniteSeq = getInfiniteSeq(); - for ( CharSequence string : strings ) { - infiniteSeq.setString(string); - encoder.encode(infiniteSeq.buffer, buffer, true); - } - infiniteSeq.clear(); + for ( CharSequence string : strings ) + encode(buffer, string); buffer.flip(); return buffer; @@ -304,13 +291,10 @@ static ByteBuffer getBufferNT(final CharSequence[] strings) { final ByteBuffer buffer = getBufferByte(getTotalLength(strings) + strings.length); - final InfiniteCharSequence infiniteSeq = getInfiniteSeq(); for ( CharSequence string : strings ) { - infiniteSeq.setString(string); - encoder.encode(infiniteSeq.buffer, buffer, true); + encode(buffer, string); buffer.put((byte)0); } - infiniteSeq.clear(); buffer.flip(); return buffer; @@ -358,43 +342,6 @@ return (int)size; } - /** - * A mutable CharSequence with very large initial length. We can wrap this in a re-usable CharBuffer for decoding. - * We cannot subclass CharBuffer because of {@link java.nio.CharBuffer#toString(int,int)}. - */ - private static class InfiniteCharSequence implements CharSequence { - - final CharBuffer buffer; - - CharSequence string; - - InfiniteCharSequence() { - buffer = CharBuffer.wrap(this); - } - - void setString(final CharSequence string) { - this.string = string; - this.buffer.position(0); - this.buffer.limit(string.length()); - } - - void clear() { - this.string = null; - } - - public int length() { - return Integer.MAX_VALUE; - } - - public char charAt(final int index) { - return string.charAt(index); - } - - public CharSequence subSequence(final int start, final int end) { - return string.subSequence(start, end); - } - } - private static class Buffers { final ShortBuffer shorts; @@ -559,7 +506,8 @@ if ( registry.isEmpty() ) return; - for ( final T object : registry.getAll() ) { + for ( Entry<T> entry : registry.getAll() ) { + final T object = entry.value; while ( object.isValid() ) destructor.release(object); } Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/CLContext.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/CLContext.java 2010-10-08 20:57:23 UTC (rev 3435) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/CLContext.java 2010-10-12 01:35:33 UTC (rev 3436) @@ -37,9 +37,7 @@ import org.lwjgl.opengl.Drawable; import java.nio.IntBuffer; -import java.util.HashMap; import java.util.List; -import java.util.Map; /** * This class is a wrapper around a cl_context pointer. @@ -57,10 +55,10 @@ private final CLObjectRegistry<CLEvent> clEvents; /** Global registry for build callbacks. */ - static final Map<Long, CLProgram> clProgramsGlobal = new HashMap<Long, CLProgram>(); + static final FastLongMap<CLProgram> clProgramsGlobal = new FastLongMap<CLProgram>(); /** Global registry for event callbacks. */ - static final Map<Long, CLEvent> clEventsGlobal = new HashMap<Long, CLEvent>(); + static final FastLongMap<CLEvent> clEventsGlobal = new FastLongMap<CLEvent>(); CLContext(final long pointer, final CLPlatform platform) { super(pointer, platform); Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/CLObjectRegistry.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/CLObjectRegistry.java 2010-10-08 20:57:23 UTC (rev 3435) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/CLObjectRegistry.java 2010-10-12 01:35:33 UTC (rev 3436) @@ -2,11 +2,6 @@ import org.lwjgl.LWJGLUtil; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - /** * A CLObjectChild container. * @@ -14,7 +9,7 @@ */ class CLObjectRegistry<T extends CLObjectChild> { - private Map<Long, T> registry; + private FastLongMap<T> registry; CLObjectRegistry() { } @@ -31,12 +26,12 @@ return registry != null && registry.containsKey(id); } - final List<T> getAll() { - return registry == null ? null : new ArrayList<T>(registry.values()); + final Iterable<FastLongMap.Entry<T>> getAll() { + return registry; } void registerObject(final T object) { - final Map<Long, T> map = getMap(); + final FastLongMap<T> map = getMap(); final Long key = object.getPointer(); if ( LWJGLUtil.DEBUG && map.containsKey(key) ) @@ -49,9 +44,9 @@ getMap().remove(object.getPointerUnsafe()); } - private Map<Long, T> getMap() { + private FastLongMap<T> getMap() { if ( registry == null ) - registry = new HashMap<Long, T>(); + registry = new FastLongMap<T>(); return registry; } Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/CLObjectRegistryGlobal.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/CLObjectRegistryGlobal.java 2010-10-08 20:57:23 UTC (rev 3435) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/CLObjectRegistryGlobal.java 2010-10-12 01:35:33 UTC (rev 3436) @@ -31,8 +31,6 @@ */ package org.lwjgl.opencl; -import java.util.Map; - /** * A CLObject registry that also registers/unregisters objects to/from a global registry. * @@ -40,9 +38,9 @@ */ final class CLObjectRegistryGlobal<T extends CLObjectChild> extends CLObjectRegistry<T> { - private final Map<Long, T> globalRegistry; + private final FastLongMap<T> globalRegistry; - CLObjectRegistryGlobal(final Map<Long, T> globalRegistry) { + CLObjectRegistryGlobal(final FastLongMap<T> globalRegistry) { this.globalRegistry = globalRegistry; } Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/CLPlatform.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/CLPlatform.java 2010-10-08 20:57:23 UTC (rev 3435) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/CLPlatform.java 2010-10-12 01:35:33 UTC (rev 3436) @@ -36,9 +36,7 @@ import java.nio.ByteBuffer; import java.nio.IntBuffer; -import java.util.HashMap; import java.util.List; -import java.util.Map; import static java.lang.Math.*; @@ -51,12 +49,12 @@ private static final CLPlatformUtil util = (CLPlatformUtil)getInfoUtilInstance(CLPlatform.class, "CL_PLATFORM_UTIL"); - private static final Map<Long, CLPlatform> clPlatforms = new HashMap<Long, CLPlatform>(); + private static final FastLongMap<CLPlatform> clPlatforms = new FastLongMap<CLPlatform>(); private final CLObjectRegistry<CLDevice> clDevices; /** Global registry for build callbacks. */ - static final Map<Long, CLDevice> clDevicesGlobal = new HashMap<Long, CLDevice>(); + static final FastLongMap<CLDevice> clDevicesGlobal = new FastLongMap<CLDevice>(); private Object caps; Added: trunk/LWJGL/src/java/org/lwjgl/opencl/FastLongMap.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/FastLongMap.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/FastLongMap.java 2010-10-12 01:35:33 UTC (rev 3436) @@ -0,0 +1,239 @@ +/* + * Copyright 2002-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" + * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.lwjgl.opencl; + +import java.util.Iterator; + +/** + * A hash map using primitive longs as keys rather than objects. + * + * @author Justin Couch + * @author Alex Chaffee (al...@ap...) + * @author Stephen Colebourne + * @author Nathan Sweet + */ +final class FastLongMap<V> implements Iterable<FastLongMap.Entry<V>> { + + private Entry[] table; + private int size, mask, capacity, threshold; + + /** Same as: FastLongMap(16, 0.75f); */ + FastLongMap() { + this(16, 0.75f); + } + + /** Same as: FastLongMap(initialCapacity, 0.75f); */ + FastLongMap(int initialCapacity) { + this(initialCapacity, 0.75f); + } + + FastLongMap(int initialCapacity, float loadFactor) { + if ( initialCapacity > 1 << 30 ) throw new IllegalArgumentException("initialCapacity is too large."); + if ( initialCapacity < 0 ) throw new IllegalArgumentException("initialCapacity must be greater than zero."); + if ( loadFactor <= 0 ) throw new IllegalArgumentException("initialCapacity must be greater than zero."); + capacity = 1; + while ( capacity < initialCapacity ) + capacity <<= 1; + this.threshold = (int)(capacity * loadFactor); + this.table = new Entry[capacity]; + this.mask = capacity - 1; + } + + private int index(final long key) { + return index(key, mask); + } + + private static int index(final long key, final int mask) { + final int hash = (int)(key ^ (key >>> 32)); + return hash & mask; + } + + public V put(long key, V value) { + final Entry<V>[] table = this.table; + int index = index(key); + + // Check if key already exists. + for ( Entry<V> e = table[index]; e != null; e = e.next ) { + if ( e.key != key ) continue; + V oldValue = e.value; + e.value = value; + return oldValue; + } + + table[index] = new Entry<V>(key, value, table[index]); + + if ( size++ >= threshold ) + rehash(table); + + return null; + } + + private void rehash(final Entry<V>[] table) { + final int newCapacity = 2 * capacity; + final int newMask = newCapacity - 1; + + final Entry<V>[] newTable = new Entry[newCapacity]; + + for ( int i = 0, index; i < table.length; i++ ) { + Entry<V> e = table[i]; + if ( e == null ) continue; + do { + final Entry<V> next = e.next; + index = index(e.key, newMask); + e.next = newTable[index]; + newTable[index] = e; + e = next; + } while ( e != null ); + } + + this.table = newTable; + capacity = newCapacity; + mask = newMask; + threshold *= 2; + } + + public V get(long key) { + final int index = index(key); + for ( Entry<V> e = table[index]; e != null; e = e.next ) + if ( e.key == key ) return e.value; + return null; + } + + public boolean containsValue(Object value) { + final Entry<V>[] table = this.table; + for ( int i = table.length - 1; i >= 0; i-- ) + for ( Entry<V> e = table[i]; e != null; e = e.next ) + if ( e.value.equals(value) ) return true; + return false; + } + + public boolean containsKey(long key) { + final int index = index(key); + for ( Entry<V> e = table[index]; e != null; e = e.next ) + if ( e.key == key ) return true; + return false; + } + + public V remove(long key) { + final int index = index(key); + + Entry<V> prev = table[index]; + Entry<V> e = prev; + while ( e != null ) { + Entry<V> next = e.next; + if ( e.key == key ) { + size--; + if ( prev == e ) + table[index] = next; + else + prev.next = next; + return e.value; + } + prev = e; + e = next; + } + return null; + } + + public int size() { + return size; + } + + public boolean isEmpty() { + return size == 0; + } + + public void clear() { + final Entry<V>[] table = this.table; + for ( int index = table.length - 1; index >= 0; index-- ) + table[index] = null; + size = 0; + } + + public EntryIterator iterator() { + return new EntryIterator(); + } + + public class EntryIterator implements Iterator<Entry<V>> { + + private int nextIndex; + private Entry<V> current; + + EntryIterator() { + reset(); + } + + public void reset() { + current = null; + // Find first bucket. + final Entry<V>[] table = FastLongMap.this.table; + int i; + for ( i = table.length - 1; i >= 0; i-- ) + if ( table[i] != null ) break; + nextIndex = i; + } + + public boolean hasNext() { + if ( nextIndex >= 0 ) return true; + Entry e = current; + return e != null && e.next != null; + } + + public Entry<V> next() { + // Next entry in current bucket. + Entry<V> e = current; + if ( e != null ) { + e = e.next; + if ( e != null ) { + current = e; + return e; + } + } + // Use the bucket at nextIndex and find the next nextIndex. + final Entry<V>[] table = FastLongMap.this.table; + int i = nextIndex; + e = current = table[i]; + while ( --i >= 0 ) + if ( table[i] != null ) break; + nextIndex = i; + return e; + } + + public void remove() { + FastLongMap.this.remove(current.key); + } + } + + static final class Entry<T> { + + final long key; + T value; + Entry<T> next; + + Entry(long key, T value, Entry<T> next) { + this.key = key; + this.value = value; + this.next = next; + } + + public long getKey() { + return key; + } + + public T getValue() { + return value; + } + + } + +} \ No newline at end of file Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/APIUtil.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/APIUtil.java 2010-10-08 20:57:23 UTC (rev 3435) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/APIUtil.java 2010-10-12 01:35:33 UTC (rev 3436) @@ -32,10 +32,9 @@ package org.lwjgl.opengl; import org.lwjgl.BufferUtils; +import org.lwjgl.LWJGLUtil; import java.nio.*; -import java.nio.charset.Charset; -import java.nio.charset.CharsetEncoder; /** @author spasi */ final class APIUtil { @@ -57,16 +56,10 @@ protected IntBuffer initialValue() { return BufferUtils.createIntBuffer(INITIAL_LENGTHS_SIZE); } }; - private static final ThreadLocal<InfiniteCharSequence> infiniteSeqTL = new ThreadLocal<InfiniteCharSequence>() { - protected InfiniteCharSequence initialValue() { return new InfiniteCharSequence(); } - }; - private static final ThreadLocal<Buffers> buffersTL = new ThreadLocal<Buffers>() { protected Buffers initialValue() { return new Buffers(); } }; - private static CharsetEncoder encoder = Charset.forName("US-ASCII").newEncoder(); - private APIUtil() { } @@ -150,15 +143,22 @@ return lengths; } - private static InfiniteCharSequence getInfiniteSeq() { - return infiniteSeqTL.get(); - } + /** + * Simple ASCII encoding. + * + * @param buffer The target buffer + * @param string The source string + */ + private static ByteBuffer encode(final ByteBuffer buffer, final CharSequence string) { + for ( int i = 0; i < string.length(); i++ ) { + final char c = string.charAt(i); + if ( LWJGLUtil.DEBUG && 0x80 <= c ) // Silently ignore and map to 0x1A. + buffer.put((byte)0x1A); + else + buffer.put((byte)c); + } - private static void encode(final ByteBuffer buffer, final CharSequence string) { - final InfiniteCharSequence infiniteSeq = getInfiniteSeq(); - infiniteSeq.setString(string); - encoder.encode(infiniteSeq.buffer, buffer, true); - infiniteSeq.clear(); + return buffer; } /** @@ -186,10 +186,7 @@ * @return the String as a ByteBuffer */ static ByteBuffer getBuffer(final CharSequence string) { - final ByteBuffer buffer = getBufferByte(string.length()); - - encode(buffer, string); - + final ByteBuffer buffer = encode(getBufferByte(string.length()), string); buffer.flip(); return buffer; } @@ -202,10 +199,7 @@ * @return the String as a ByteBuffer */ static ByteBuffer getBuffer(final CharSequence string, final int offset) { - final ByteBuffer buffer = getBufferByteOffset(offset + string.length()); - - encode(buffer, string); - + final ByteBuffer buffer = encode(getBufferByteOffset(offset + string.length()), string); buffer.flip(); return buffer; } @@ -218,10 +212,7 @@ * @return the String as a ByteBuffer */ static ByteBuffer getBufferNT(final CharSequence string) { - final ByteBuffer buffer = getBufferByte(string.length() + 1); - - encode(buffer, string); - + final ByteBuffer buffer = encode(getBufferByte(string.length() + 1), string); buffer.put((byte)0); buffer.flip(); return buffer; @@ -245,12 +236,8 @@ static ByteBuffer getBuffer(final CharSequence[] strings) { final ByteBuffer buffer = getBufferByte(getTotalLength(strings)); - final InfiniteCharSequence infiniteSeq = getInfiniteSeq(); - for ( CharSequence string : strings ) { - infiniteSeq.setString(string); - encoder.encode(infiniteSeq.buffer, buffer, true); - } - infiniteSeq.clear(); + for ( CharSequence string : strings ) + encode(buffer, string); buffer.flip(); return buffer; @@ -266,13 +253,10 @@ static ByteBuffer getBufferNT(final CharSequence[] strings) { final ByteBuffer buffer = getBufferByte(getTotalLength(strings) + strings.length); - final InfiniteCharSequence infiniteSeq = getInfiniteSeq(); for ( CharSequence string : strings ) { - infiniteSeq.setString(string); - encoder.encode(infiniteSeq.buffer, buffer, true); + encode(buffer, string); buffer.put((byte)0); } - infiniteSeq.clear(); buffer.flip(); return buffer; @@ -295,43 +279,6 @@ return buffer; } - /** - * A mutable CharSequence with very large initial length. We can wrap this in a re-usable CharBuffer for decoding. - * We cannot subclass CharBuffer because of {@link CharBuffer#toString(int,int)}. - */ - private static class InfiniteCharSequence implements CharSequence { - - final CharBuffer buffer; - - CharSequence string; - - InfiniteCharSequence() { - buffer = CharBuffer.wrap(this); - } - - void setString(final CharSequence string) { - this.string = string; - this.buffer.position(0); - this.buffer.limit(string.length()); - } - - void clear() { - this.string = null; - } - - public int length() { - return Integer.MAX_VALUE; - } - - public char charAt(final int index) { - return string.charAt(index); - } - - public CharSequence subSequence(final int start, final int end) { - return string.subSequence(start, end); - } - } - private static class Buffers { final ShortBuffer shorts; Modified: trunk/LWJGL/src/native/common/org_lwjgl_opencl_CallbackUtil.c =================================================================== --- trunk/LWJGL/src/native/common/org_lwjgl_opencl_CallbackUtil.c 2010-10-08 20:57:23 UTC (rev 3435) +++ trunk/LWJGL/src/native/common/org_lwjgl_opencl_CallbackUtil.c 2010-10-12 01:35:33 UTC (rev 3436) @@ -156,9 +156,9 @@ for ( i = 0; i < num_mem_objects; i++ ) { buffer = (*env)->NewDirectByteBuffer(env, // Pointer to cl_mem buffer - (void *)((char *)args + (12 + 4 + (i * (4 + sizeof(size_t))))), + (void *)((char *)args + (12 + 4 + (i * (4 + sizeof(void *))))), // cl_mem buffer size - *((jint *)((char *)args + (12 + (i * (4 + sizeof(size_t)))))) + *((jint *)((char *)args + (12 + (i * (4 + sizeof(void *)))))) ); (*env)->SetObjectArrayElement(env, memobjs, i, buffer); } Modified: trunk/LWJGL/src/templates/org/lwjgl/opencl/CL10.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opencl/CL10.java 2010-10-08 20:57:23 UTC (rev 3435) +++ trunk/LWJGL/src/templates/org/lwjgl/opencl/CL10.java 2010-10-12 01:35:33 UTC (rev 3436) @@ -1061,7 +1061,7 @@ nativeAfterVars = "\tvoid **args_mem_loc = num_mem_objects == 0 ? NULL : (void **)malloc(num_mem_objects * sizeof(void *));", nativeBeforeCall = "\t_ptr_i = 0;\n" + "\twhile ( _ptr_i < num_mem_objects ) {\n" + - "\t\targs_mem_loc[_ptr_i] = (cl_void *)((char *)args_address + (4 + _ptr_i * (4 + sizeof(size_t))));\n" + + "\t\targs_mem_loc[_ptr_i] = (cl_void *)((char *)args_address + (4 + _ptr_i * (4 + sizeof(void *))));\n" + "\t\t_ptr_i++;\n" + "\t}", nativeAfterCall = "\tfree(args_mem_loc);" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ka...@us...> - 2010-10-28 21:40:01
|
Revision: 3453 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3453&view=rev Author: kappa1 Date: 2010-10-28 21:39:55 +0000 (Thu, 28 Oct 2010) Log Message: ----------- Implement preliminary support for Display.isInsideWindow() on linux Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxEvent.java trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2010-10-28 16:03:04 UTC (rev 3452) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2010-10-28 21:39:55 UTC (rev 3453) @@ -136,7 +136,8 @@ private long parent_window; private boolean xembedded; private boolean parent_focus; - + private boolean mouseInside = true; + private LinuxKeyboard keyboard; private LinuxMouse mouse; @@ -777,6 +778,12 @@ case LinuxEvent.Expose: dirty = true; break; + case LinuxEvent.EnterNotify: + mouseInside = true; + break; + case LinuxEvent.LeaveNotify: + mouseInside = false; + break; default: break; } @@ -1248,9 +1255,9 @@ return Display.getDisplayMode().getHeight(); } - public boolean isInsideWindow() { - return true; - } + public boolean isInsideWindow() { + return mouseInside; + } /** * Helper class for managing Compiz's workarounds. We need this to enable Legacy Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxEvent.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxEvent.java 2010-10-28 16:03:04 UTC (rev 3452) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxEvent.java 2010-10-28 21:39:55 UTC (rev 3453) @@ -46,12 +46,14 @@ public static final int KeyPress = 2; public static final int KeyRelease = 3; public static final int ButtonPress = 4; - public static final int ButtonRelease = 5; - public static final int MotionNotify = 6; + public static final int ButtonRelease = 5; + public static final int MotionNotify = 6; + public static final int EnterNotify = 7; + public static final int LeaveNotify = 8; public static final int UnmapNotify = 18; public static final int MapNotify = 19; public static final int Expose = 12; - public static final int ClientMessage = 33; + public static final int ClientMessage = 33; private final ByteBuffer event_buffer; Modified: trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c =================================================================== --- trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c 2010-10-28 16:03:04 UTC (rev 3452) +++ trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c 2010-10-28 21:39:55 UTC (rev 3453) @@ -307,7 +307,7 @@ cmap = XCreateColormap(disp, parent, vis_info->visual, AllocNone); attribs.colormap = cmap; attribs.border_pixel = 0; - attribs.event_mask = ExposureMask | FocusChangeMask | VisibilityChangeMask | StructureNotifyMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask; + attribs.event_mask = ExposureMask | FocusChangeMask | VisibilityChangeMask | StructureNotifyMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask| EnterWindowMask | LeaveWindowMask; attribmask = CWColormap | CWEventMask | CWBorderPixel; if (isLegacyFullscreen(window_mode)) { attribmask |= CWOverrideRedirect; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sp...@us...> - 2010-11-29 17:21:13
|
Revision: 3459 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3459&view=rev Author: spasi Date: 2010-11-29 17:21:05 +0000 (Mon, 29 Nov 2010) Log Message: ----------- Fixed ELEMENT_ARRAY_BUFFER_BINDING tracking when VAOs are used. Removed CachedReference tracking, we never check those. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/BaseReferences.java trunk/LWJGL/src/java/org/lwjgl/opengl/GLChecks.java trunk/LWJGL/src/java/org/lwjgl/opengl/ReferencesStack.java trunk/LWJGL/src/java/org/lwjgl/opengl/StateTracker.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_matrix_palette.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_attrib_64bit.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_blend.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_program.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_shader.java trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_fog_coord.java trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_gpu_shader4.java trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_secondary_color.java trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_vertex_attrib_64bit.java trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_vertex_shader.java trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_vertex_weighting.java trunk/LWJGL/src/templates/org/lwjgl/opengl/GL11.java trunk/LWJGL/src/templates/org/lwjgl/opengl/GL13.java trunk/LWJGL/src/templates/org/lwjgl/opengl/GL14.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/GL41.java trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_vertex_program.java Added Paths: ----------- trunk/LWJGL/src/java/org/lwjgl/opengl/FastIntMap.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/BaseReferences.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/BaseReferences.java 2010-11-27 09:38:48 UTC (rev 3458) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/BaseReferences.java 2010-11-29 17:21:05 UTC (rev 3459) @@ -31,27 +31,25 @@ */ package org.lwjgl.opengl; -import java.nio.Buffer; -import java.util.Arrays; - import static org.lwjgl.opengl.GL11.*; -import static org.lwjgl.opengl.GL13.*; -import static org.lwjgl.opengl.GL20.*; class BaseReferences { - int elementArrayBuffer; - int arrayBuffer; - final Buffer[] glVertexAttribPointer_buffer; - final Buffer[] glTexCoordPointer_buffer; - int glClientActiveTexture; + int elementArrayBuffer; + int arrayBuffer; + //final Buffer[] glVertexAttribPointer_buffer; + //final Buffer[] glTexCoordPointer_buffer; + //int glClientActiveTexture; + int vertexArrayObject; + int pixelPackBuffer; int pixelUnpackBuffer; int indirectBuffer; BaseReferences(ContextCapabilities caps) { + /* int max_vertex_attribs; if (caps.OpenGL20 || caps.GL_ARB_vertex_shader) max_vertex_attribs = glGetInteger(GL_MAX_VERTEX_ATTRIBS); @@ -67,35 +65,40 @@ else max_texture_units = 1; glTexCoordPointer_buffer = new Buffer[max_texture_units]; - } + */ + } - void clear() { - this.elementArrayBuffer = 0; - this.arrayBuffer = 0; - this.glClientActiveTexture = 0; - Arrays.fill(glVertexAttribPointer_buffer, null); - Arrays.fill(glTexCoordPointer_buffer, null); + void clear() { + this.elementArrayBuffer = 0; + this.arrayBuffer = 0; + //this.glClientActiveTexture = 0; + //Arrays.fill(glVertexAttribPointer_buffer, null); + //Arrays.fill(glTexCoordPointer_buffer, null); - this.pixelPackBuffer = 0; - this.pixelUnpackBuffer = 0; + this.vertexArrayObject = 0; - this.indirectBuffer = 0; - } + this.pixelPackBuffer = 0; + this.pixelUnpackBuffer = 0; - void copy(BaseReferences references, int mask) { - if ( (mask & GL_CLIENT_VERTEX_ARRAY_BIT) != 0 ) { - this.elementArrayBuffer = references.elementArrayBuffer; - this.arrayBuffer = references.arrayBuffer; - this.glClientActiveTexture = references.glClientActiveTexture; - System.arraycopy(references.glVertexAttribPointer_buffer, 0, glVertexAttribPointer_buffer, 0, glVertexAttribPointer_buffer.length); - System.arraycopy(references.glTexCoordPointer_buffer, 0, glTexCoordPointer_buffer, 0, glTexCoordPointer_buffer.length); + this.indirectBuffer = 0; + } - this.indirectBuffer = references.indirectBuffer; - } + void copy(BaseReferences references, int mask) { + if ( (mask & GL_CLIENT_VERTEX_ARRAY_BIT) != 0 ) { + this.elementArrayBuffer = references.elementArrayBuffer; + this.arrayBuffer = references.arrayBuffer; + //this.glClientActiveTexture = references.glClientActiveTexture; + //System.arraycopy(references.glVertexAttribPointer_buffer, 0, glVertexAttribPointer_buffer, 0, glVertexAttribPointer_buffer.length); + //System.arraycopy(references.glTexCoordPointer_buffer, 0, glTexCoordPointer_buffer, 0, glTexCoordPointer_buffer.length); - if ( (mask & GL_CLIENT_PIXEL_STORE_BIT) != 0 ) { + this.vertexArrayObject = references.vertexArrayObject; + + this.indirectBuffer = references.indirectBuffer; + } + + if ( (mask & GL_CLIENT_PIXEL_STORE_BIT) != 0 ) { this.pixelPackBuffer = references.pixelPackBuffer; this.pixelUnpackBuffer = references.pixelUnpackBuffer; - } - } + } + } } Added: trunk/LWJGL/src/java/org/lwjgl/opengl/FastIntMap.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/FastIntMap.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/FastIntMap.java 2010-11-29 17:21:05 UTC (rev 3459) @@ -0,0 +1,238 @@ +/* + * Copyright 2002-2004 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" + * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.lwjgl.opengl; + +import java.util.Iterator; + +/** + * A hash map using primitive ints as keys rather than objects. + * + * @author Justin Couch + * @author Alex Chaffee (al...@ap...) + * @author Stephen Colebourne + * @author Nathan Sweet + */ +final class FastIntMap<V> implements Iterable<FastIntMap.Entry<V>> { + + private Entry[] table; + private int size, mask, capacity, threshold; + + /** Same as: FastIntMap(16, 0.75f); */ + FastIntMap() { + this(16, 0.75f); + } + + /** Same as: FastIntMap(initialCapacity, 0.75f); */ + FastIntMap(int initialCapacity) { + this(initialCapacity, 0.75f); + } + + FastIntMap(int initialCapacity, float loadFactor) { + if ( initialCapacity > 1 << 30 ) throw new IllegalArgumentException("initialCapacity is too large."); + if ( initialCapacity < 0 ) throw new IllegalArgumentException("initialCapacity must be greater than zero."); + if ( loadFactor <= 0 ) throw new IllegalArgumentException("initialCapacity must be greater than zero."); + capacity = 1; + while ( capacity < initialCapacity ) + capacity <<= 1; + this.threshold = (int)(capacity * loadFactor); + this.table = new Entry[capacity]; + this.mask = capacity - 1; + } + + private int index(final int key) { + return index(key, mask); + } + + private static int index(final int key, final int mask) { + return key & mask; + } + + public V put(int key, V value) { + final Entry<V>[] table = this.table; + int index = index(key); + + // Check if key already exists. + for ( Entry<V> e = table[index]; e != null; e = e.next ) { + if ( e.key != key ) continue; + V oldValue = e.value; + e.value = value; + return oldValue; + } + + table[index] = new Entry<V>(key, value, table[index]); + + if ( size++ >= threshold ) + rehash(table); + + return null; + } + + private void rehash(final Entry<V>[] table) { + final int newCapacity = 2 * capacity; + final int newMask = newCapacity - 1; + + final Entry<V>[] newTable = new Entry[newCapacity]; + + for ( int i = 0, index; i < table.length; i++ ) { + Entry<V> e = table[i]; + if ( e == null ) continue; + do { + final Entry<V> next = e.next; + index = index(e.key, newMask); + e.next = newTable[index]; + newTable[index] = e; + e = next; + } while ( e != null ); + } + + this.table = newTable; + capacity = newCapacity; + mask = newMask; + threshold *= 2; + } + + public V get(int key) { + final int index = index(key); + for ( Entry<V> e = table[index]; e != null; e = e.next ) + if ( e.key == key ) return e.value; + return null; + } + + public boolean containsValue(Object value) { + final Entry<V>[] table = this.table; + for ( int i = table.length - 1; i >= 0; i-- ) + for ( Entry<V> e = table[i]; e != null; e = e.next ) + if ( e.value.equals(value) ) return true; + return false; + } + + public boolean containsKey(int key) { + final int index = index(key); + for ( Entry<V> e = table[index]; e != null; e = e.next ) + if ( e.key == key ) return true; + return false; + } + + public V remove(int key) { + final int index = index(key); + + Entry<V> prev = table[index]; + Entry<V> e = prev; + while ( e != null ) { + Entry<V> next = e.next; + if ( e.key == key ) { + size--; + if ( prev == e ) + table[index] = next; + else + prev.next = next; + return e.value; + } + prev = e; + e = next; + } + return null; + } + + public int size() { + return size; + } + + public boolean isEmpty() { + return size == 0; + } + + public void clear() { + final Entry<V>[] table = this.table; + for ( int index = table.length - 1; index >= 0; index-- ) + table[index] = null; + size = 0; + } + + public EntryIterator iterator() { + return new EntryIterator(); + } + + public class EntryIterator implements Iterator<Entry<V>> { + + private int nextIndex; + private Entry<V> current; + + EntryIterator() { + reset(); + } + + public void reset() { + current = null; + // Find first bucket. + final Entry<V>[] table = FastIntMap.this.table; + int i; + for ( i = table.length - 1; i >= 0; i-- ) + if ( table[i] != null ) break; + nextIndex = i; + } + + public boolean hasNext() { + if ( nextIndex >= 0 ) return true; + Entry e = current; + return e != null && e.next != null; + } + + public Entry<V> next() { + // Next entry in current bucket. + Entry<V> e = current; + if ( e != null ) { + e = e.next; + if ( e != null ) { + current = e; + return e; + } + } + // Use the bucket at nextIndex and find the next nextIndex. + final Entry<V>[] table = FastIntMap.this.table; + int i = nextIndex; + e = current = table[i]; + while ( --i >= 0 ) + if ( table[i] != null ) break; + nextIndex = i; + return e; + } + + public void remove() { + FastIntMap.this.remove(current.key); + } + } + + static final class Entry<T> { + + final int key; + T value; + Entry<T> next; + + Entry(int key, T value, Entry<T> next) { + this.key = key; + this.value = value; + this.next = next; + } + + public int getKey() { + return key; + } + + public T getValue() { + return value; + } + + } + +} \ No newline at end of file Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/GLChecks.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/GLChecks.java 2010-11-27 09:38:48 UTC (rev 3458) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/GLChecks.java 2010-11-29 17:21:05 UTC (rev 3459) @@ -63,10 +63,6 @@ private GLChecks() { } - static References getReferences(ContextCapabilities caps) { - return StateTracker.getReferencesStack(caps).getReferences(); - } - static int getBufferObjectSize(ContextCapabilities caps, int buffer_enum) { return glGetBufferParameter(buffer_enum, GL_BUFFER_SIZE); } @@ -85,61 +81,61 @@ /** Helper method to ensure that array buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */ static void ensureArrayVBOdisabled(ContextCapabilities caps) { - if( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().arrayBuffer != 0 ) + if( LWJGLUtil.CHECKS && StateTracker.getReferences(caps).arrayBuffer != 0 ) throw new OpenGLException("Cannot use Buffers when Array Buffer Object is enabled"); } /** Helper method to ensure that array buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */ static void ensureArrayVBOenabled(ContextCapabilities caps) { - if( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().arrayBuffer == 0 ) + if( LWJGLUtil.CHECKS && StateTracker.getReferences(caps).arrayBuffer == 0 ) throw new OpenGLException("Cannot use offsets when Array Buffer Object is disabled"); } /** Helper method to ensure that element array buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */ static void ensureElementVBOdisabled(ContextCapabilities caps) { - if( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().elementArrayBuffer != 0 ) + if( LWJGLUtil.CHECKS && StateTracker.getElementArrayBufferBound(caps) != 0 ) throw new OpenGLException("Cannot use Buffers when Element Array Buffer Object is enabled"); } /** Helper method to ensure that element array buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */ static void ensureElementVBOenabled(ContextCapabilities caps) { - if( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().elementArrayBuffer == 0 ) + if( LWJGLUtil.CHECKS && StateTracker.getElementArrayBufferBound(caps) == 0 ) throw new OpenGLException("Cannot use offsets when Element Array Buffer Object is disabled"); } /** Helper method to ensure that array buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */ static void ensureIndirectBOdisabled(ContextCapabilities caps) { - if ( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().indirectBuffer != 0 ) + if ( LWJGLUtil.CHECKS && StateTracker.getReferences(caps).indirectBuffer != 0 ) throw new OpenGLException("Cannot use Buffers when Draw Indirect Object is enabled"); } /** Helper method to ensure that array buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */ static void ensureIndirectBOenabled(ContextCapabilities caps) { - if ( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().indirectBuffer == 0 ) + if ( LWJGLUtil.CHECKS && StateTracker.getReferences(caps).indirectBuffer == 0 ) throw new OpenGLException("Cannot use offsets when Draw Indirect Object is disabled"); } /** Helper method to ensure that pixel pack buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */ static void ensurePackPBOdisabled(ContextCapabilities caps) { - if ( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().pixelPackBuffer != 0 ) + if ( LWJGLUtil.CHECKS && StateTracker.getReferences(caps).pixelPackBuffer != 0 ) throw new OpenGLException("Cannot use Buffers when Pixel Pack Buffer Object is enabled"); } /** Helper method to ensure that pixel pack buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */ static void ensurePackPBOenabled(ContextCapabilities caps) { - if ( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().pixelPackBuffer == 0 ) + if ( LWJGLUtil.CHECKS && StateTracker.getReferences(caps).pixelPackBuffer == 0 ) throw new OpenGLException("Cannot use offsets when Pixel Pack Buffer Object is disabled"); } /** Helper method to ensure that pixel unpack buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */ static void ensureUnpackPBOdisabled(ContextCapabilities caps) { - if ( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().pixelUnpackBuffer != 0 ) + if ( LWJGLUtil.CHECKS && StateTracker.getReferences(caps).pixelUnpackBuffer != 0 ) throw new OpenGLException("Cannot use Buffers when Pixel Unpack Buffer Object is enabled"); } /** Helper method to ensure that pixel unpack buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */ static void ensureUnpackPBOenabled(ContextCapabilities caps) { - if ( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().pixelUnpackBuffer == 0 ) + if ( LWJGLUtil.CHECKS && StateTracker.getReferences(caps).pixelUnpackBuffer == 0 ) throw new OpenGLException("Cannot use offsets when Pixel Unpack Buffer Object is disabled"); } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/ReferencesStack.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/ReferencesStack.java 2010-11-27 09:38:48 UTC (rev 3458) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/ReferencesStack.java 2010-11-29 17:21:05 UTC (rev 3459) @@ -34,10 +34,10 @@ import static org.lwjgl.opengl.GL11.*; class ReferencesStack { - private References[] references_stack; + private BaseReferences[] references_stack; private int stack_pos; - public References getReferences() { + public BaseReferences getReferences() { return references_stack[stack_pos]; } @@ -49,8 +49,8 @@ references_stack[pos].copy(references_stack[pos - 1], GL_ALL_CLIENT_ATTRIB_BITS); } - public References popState(int mask) { - References result = references_stack[stack_pos--]; + public BaseReferences popState(int mask) { + BaseReferences result = references_stack[stack_pos--]; references_stack[stack_pos].copy(result, ~mask); result.clear(); @@ -59,17 +59,17 @@ } private void growStack() { - References[] new_references_stack = new References[references_stack.length + 1]; + BaseReferences[] new_references_stack = new BaseReferences[references_stack.length + 1]; System.arraycopy(references_stack, 0, new_references_stack, 0, references_stack.length); references_stack = new_references_stack; - references_stack[references_stack.length - 1] = new References(GLContext.getCapabilities()); + references_stack[references_stack.length - 1] = new BaseReferences(GLContext.getCapabilities()); } ReferencesStack() { ContextCapabilities caps = GLContext.getCapabilities(); - references_stack = new References[1]; + references_stack = new BaseReferences[1]; stack_pos = 0; for (int i = 0; i < references_stack.length; i++) - references_stack[i] = new References(caps); + references_stack[i] = new BaseReferences(caps); } } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/StateTracker.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/StateTracker.java 2010-11-27 09:38:48 UTC (rev 3458) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/StateTracker.java 2010-11-29 17:21:05 UTC (rev 3459) @@ -31,16 +31,22 @@ */ package org.lwjgl.opengl; +import java.nio.IntBuffer; + import static org.lwjgl.opengl.GL15.*; import static org.lwjgl.opengl.GL21.*; import static org.lwjgl.opengl.GL40.*; final class StateTracker { + private ReferencesStack references_stack; private final StateStack attrib_stack; private boolean insideBeginEnd; + // VAOs are not shareable between contexts, no need to sync or make this static. + private final FastIntMap<VAOState> vaoMap = new FastIntMap<VAOState>(); + StateTracker() { attrib_stack = new StateStack(0); } @@ -75,29 +81,82 @@ references_stack.pushState(); } - static ReferencesStack getReferencesStack(ContextCapabilities caps) { - return caps.tracker.references_stack; + static BaseReferences getReferences(ContextCapabilities caps) { + return caps.tracker.references_stack.getReferences(); } - static void bindBuffer(ContextCapabilities caps, int target, int buffer) { - ReferencesStack references_stack = getReferencesStack(caps); - switch(target) { - case GL_ELEMENT_ARRAY_BUFFER: - references_stack.getReferences().elementArrayBuffer = buffer; - break; - case GL_ARRAY_BUFFER: - references_stack.getReferences().arrayBuffer = buffer; - break; - case GL_PIXEL_PACK_BUFFER: - references_stack.getReferences().pixelPackBuffer = buffer; - break; - case GL_PIXEL_UNPACK_BUFFER: - references_stack.getReferences().pixelUnpackBuffer = buffer; - break; - case GL_DRAW_INDIRECT_BUFFER: - references_stack.getReferences().indirectBuffer = buffer; - break; + static void bindBuffer(ContextCapabilities caps, int target, int buffer) { + final BaseReferences references = getReferences(caps); + switch ( target ) { + case GL_ARRAY_BUFFER: + references.arrayBuffer = buffer; + break; + case GL_ELEMENT_ARRAY_BUFFER: + // When a vertex array object is currently bound, update + // the VAO state instead of client state. + if ( references.vertexArrayObject != 0 ) + caps.tracker.vaoMap.get(references.vertexArrayObject).elementArrayBuffer = buffer; + else + references.elementArrayBuffer = buffer; + break; + case GL_PIXEL_PACK_BUFFER: + references.pixelPackBuffer = buffer; + break; + case GL_PIXEL_UNPACK_BUFFER: + references.pixelUnpackBuffer = buffer; + break; + case GL_DRAW_INDIRECT_BUFFER: + references.indirectBuffer = buffer; + break; + } + } - } - } -} + static void bindVAO(final ContextCapabilities caps, final int array) { + final FastIntMap<VAOState> vaoMap = caps.tracker.vaoMap; + if ( !vaoMap.containsKey(array) ) + vaoMap.put(array, new VAOState()); + + getReferences(caps).vertexArrayObject = array; + } + + static void deleteVAO(final ContextCapabilities caps, final IntBuffer arrays) { + for ( int i = arrays.position(); i < arrays.limit(); i++ ) + deleteVAO(caps, arrays.get(i)); + } + + static void deleteVAO(final ContextCapabilities caps, final int array) { + caps.tracker.vaoMap.remove(array); + + final BaseReferences references = getReferences(caps); + if ( references.vertexArrayObject == array ) + references.vertexArrayObject = 0; + } + + /** + * Returns the currently bound ELEMENT_ARRAY_BUFFER. If a vertex array + * object is currently bound, then the VAO state is returned instead + * of the client state. + * + * @return the currently bound ELEMENT_ARRAY_BUFFER. + */ + static int getElementArrayBufferBound(final ContextCapabilities caps) { + final BaseReferences references = getReferences(caps); + + if ( references.vertexArrayObject == 0 ) + return references.elementArrayBuffer; + else + return caps.tracker.vaoMap.get(references.vertexArrayObject).elementArrayBuffer; + } + + /** + * Simple class to help us track VAO state. Currently + * only ELEMENT_ARRAY_BUFFER_BINDING is tracked, since + * that's the only state we check from tables 6.6-6.9. + */ + private static class VAOState { + + int elementArrayBuffer; + + } + +} \ No newline at end of file Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_matrix_palette.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_matrix_palette.java 2010-11-27 09:38:48 UTC (rev 3458) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_matrix_palette.java 2010-11-29 17:21:05 UTC (rev 3459) @@ -52,7 +52,7 @@ void glCurrentPaletteMatrixARB(int index); void glMatrixIndexPointerARB(int size, @AutoType("pPointer") @GLenum int type, @GLsizei int stride, - @CachedReference + //@CachedReference @BufferObject(BufferKind.ArrayVBO) @Check @Const Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_attrib_64bit.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_attrib_64bit.java 2010-11-27 09:38:48 UTC (rev 3458) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_attrib_64bit.java 2010-11-29 17:21:05 UTC (rev 3459) @@ -85,7 +85,7 @@ @Reuse("GL41") void glVertexAttribLPointer(@GLuint int index, int size, @Constant("GL11.GL_DOUBLE") @GLenum int type, @GLsizei int stride, - @CachedReference(index = "index", name = "glVertexAttribPointer_buffer") + //@CachedReference(index = "index", name = "glVertexAttribPointer_buffer") @BufferObject(BufferKind.ArrayVBO) @Check @Const @GLdouble Buffer pointer); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_blend.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_blend.java 2010-11-27 09:38:48 UTC (rev 3458) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_blend.java 2010-11-29 17:21:05 UTC (rev 3459) @@ -106,7 +106,7 @@ void glWeightuivARB(@AutoSize("pWeights") int size, @GLuint IntBuffer pWeights); void glWeightPointerARB(int size, @AutoType("pPointer") @GLenum int type, @GLsizei int stride, - @CachedReference + //@CachedReference @BufferObject(BufferKind.ArrayVBO) @Check @Const Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_program.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_program.java 2010-11-27 09:38:48 UTC (rev 3458) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_program.java 2010-11-29 17:21:05 UTC (rev 3459) @@ -134,7 +134,7 @@ @Reuse("ARBVertexShader") void glVertexAttribPointerARB(@GLuint int index, int size, @AutoType("buffer") @GLenum int type, boolean normalized, @GLsizei int stride, - @CachedReference(index = "index", name = "glVertexAttribPointer_buffer") + //@CachedReference(index = "index", name = "glVertexAttribPointer_buffer") @BufferObject(BufferKind.ArrayVBO) @Check @Const Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_shader.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_shader.java 2010-11-27 09:38:48 UTC (rev 3458) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_shader.java 2010-11-29 17:21:05 UTC (rev 3459) @@ -129,7 +129,7 @@ void glVertexAttrib4NubARB(@GLuint int index, @GLubyte byte x, @GLubyte byte y, @GLubyte byte z, @GLubyte byte w); void glVertexAttribPointerARB(@GLuint int index, int size, @AutoType("buffer") @GLenum int type, boolean normalized, @GLsizei int stride, - @CachedReference(index = "index", name = "glVertexAttribPointer_buffer") + //@CachedReference(index = "index", name = "glVertexAttribPointer_buffer") @BufferObject(BufferKind.ArrayVBO) @Check @Const Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_fog_coord.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_fog_coord.java 2010-11-27 09:38:48 UTC (rev 3458) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_fog_coord.java 2010-11-29 17:21:05 UTC (rev 3459) @@ -54,7 +54,7 @@ void glFogCoorddEXT(double coord); void glFogCoordPointerEXT(@AutoType("data") @GLenum int type, @GLsizei int stride, - @CachedReference + //@CachedReference @BufferObject(BufferKind.ArrayVBO) @Check @Const Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_gpu_shader4.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_gpu_shader4.java 2010-11-27 09:38:48 UTC (rev 3458) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_gpu_shader4.java 2010-11-29 17:21:05 UTC (rev 3459) @@ -158,7 +158,7 @@ void glVertexAttribI4usvEXT(@GLuint int index, @Check("4") @Const @GLushort ShortBuffer v); void glVertexAttribIPointerEXT(@GLuint int index, int size, @GLenum int type, @GLsizei int stride, - @CachedReference + //@CachedReference @BufferObject(BufferKind.ArrayVBO) @Check @Const Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_secondary_color.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_secondary_color.java 2010-11-27 09:38:48 UTC (rev 3458) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_secondary_color.java 2010-11-29 17:21:05 UTC (rev 3459) @@ -55,7 +55,7 @@ void glSecondaryColor3ubEXT(@GLubyte byte red, @GLubyte byte green, @GLubyte byte blue); void glSecondaryColorPointerEXT(int size, @AutoType("pPointer") @GLenum int type, @GLsizei int stride, - @CachedReference + //@CachedReference @BufferObject(BufferKind.ArrayVBO) @Check @Const Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_vertex_attrib_64bit.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_vertex_attrib_64bit.java 2010-11-27 09:38:48 UTC (rev 3458) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_vertex_attrib_64bit.java 2010-11-29 17:21:05 UTC (rev 3459) @@ -75,7 +75,7 @@ void glVertexAttribL4dvEXT(@GLuint int index, @Const @Check("4") DoubleBuffer v); void glVertexAttribLPointerEXT(@GLuint int index, int size, @Constant("GL11.GL_DOUBLE") @GLenum int type, @GLsizei int stride, - @CachedReference(index = "index", name = "glVertexAttribPointer_buffer") + //@CachedReference(index = "index", name = "glVertexAttribPointer_buffer") @BufferObject(BufferKind.ArrayVBO) @Check @Const @GLdouble Buffer pointer); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_vertex_shader.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_vertex_shader.java 2010-11-27 09:38:48 UTC (rev 3458) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_vertex_shader.java 2010-11-29 17:21:05 UTC (rev 3459) @@ -225,7 +225,7 @@ void glVariantuivEXT(@GLuint int id, @Check("4") @Const @GLuint IntBuffer pAddr); void glVariantPointerEXT(@GLuint int id, @AutoType("pAddr") @GLenum int type, @GLuint int stride, - @CachedReference + //@CachedReference @BufferObject(BufferKind.ArrayVBO) @Check @Const Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_vertex_weighting.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_vertex_weighting.java 2010-11-27 09:38:48 UTC (rev 3458) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_vertex_weighting.java 2010-11-29 17:21:05 UTC (rev 3459) @@ -57,7 +57,7 @@ void glVertexWeightfEXT(float weight); void glVertexWeightPointerEXT(@GLsizei int size, @AutoType("pPointer") @GLenum int type, @GLsizei int stride, - @CachedReference + //@CachedReference @BufferObject(BufferKind.ArrayVBO) @Check @Const Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/GL11.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/GL11.java 2010-11-27 09:38:48 UTC (rev 3458) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/GL11.java 2010-11-29 17:21:05 UTC (rev 3459) @@ -800,7 +800,7 @@ @DeprecatedGL void glColorPointer(int size, @AutoType("pointer") @GLenum int type, @GLsizei int stride, - @CachedReference + //@CachedReference @Check @BufferObject(BufferKind.ArrayVBO) @Const @@ -889,7 +889,7 @@ @DeprecatedGL void glEdgeFlagPointer(int stride, - @CachedReference + //@CachedReference @BufferObject(BufferKind.ArrayVBO) @Check @Const @@ -1295,7 +1295,7 @@ @DeprecatedGL void glNormalPointer(@AutoType("pointer") @GLenum int type, @GLsizei int stride, - @CachedReference + //@CachedReference @BufferObject(BufferKind.ArrayVBO) @Check @Const @@ -1431,7 +1431,7 @@ @DeprecatedGL void glVertexPointer(int size, @AutoType("pointer") @GLenum int type, @GLsizei int stride, - @CachedReference + //@CachedReference @BufferObject(BufferKind.ArrayVBO) @Check @Const @@ -1565,7 +1565,7 @@ @DeprecatedGL void glTexCoordPointer(int size, @AutoType("pointer") @GLenum int type, @GLsizei int stride, - @CachedReference(index = "GLChecks.getReferences(caps).glClientActiveTexture", name = "glTexCoordPointer_buffer") + //@CachedReference(index = "GLChecks.getReferences(caps).glClientActiveTexture", name = "glTexCoordPointer_buffer") @BufferObject(BufferKind.ArrayVBO) @Check @Const Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/GL13.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/GL13.java 2010-11-27 09:38:48 UTC (rev 3458) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/GL13.java 2010-11-29 17:21:05 UTC (rev 3459) @@ -150,7 +150,7 @@ void glActiveTexture(@GLenum int texture); - @Code("\t\tGLChecks.getReferences(caps).glClientActiveTexture = texture - GL_TEXTURE0;") + //@Code("\t\tGLChecks.getReferences(caps).glClientActiveTexture = texture - GL_TEXTURE0;") @DeprecatedGL void glClientActiveTexture(@GLenum int texture); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/GL14.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/GL14.java 2010-11-27 09:38:48 UTC (rev 3458) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/GL14.java 2010-11-29 17:21:05 UTC (rev 3459) @@ -107,7 +107,7 @@ @DeprecatedGL void glFogCoordPointer(@AutoType("data") @GLenum int type, @GLsizei int stride, - @CachedReference + //@CachedReference @BufferObject(BufferKind.ArrayVBO) @Check @Const Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/GL20.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/GL20.java 2010-11-27 09:38:48 UTC (rev 3458) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/GL20.java 2010-11-29 17:21:05 UTC (rev 3459) @@ -338,7 +338,7 @@ void glVertexAttrib4Nub(@GLuint int index, @GLubyte byte x, @GLubyte byte y, @GLubyte byte z, @GLubyte byte w); void glVertexAttribPointer(@GLuint int index, int size, @AutoType("buffer") @GLenum int type, boolean normalized, @GLsizei int stride, - @CachedReference(index = "index", name = "glVertexAttribPointer_buffer") + //@CachedReference(index = "index", name = "glVertexAttribPointer_buffer") @BufferObject(BufferKind.ArrayVBO) @Check @Const Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/GL30.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/GL30.java 2010-11-27 09:38:48 UTC (rev 3458) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/GL30.java 2010-11-29 17:21:05 UTC (rev 3459) @@ -204,7 +204,7 @@ void glVertexAttribI4usv(@GLuint int index, @Check("4") @Const @GLushort ShortBuffer v); void glVertexAttribIPointer(@GLuint int index, int size, @GLenum int type, @GLsizei int stride, - @CachedReference + //@CachedReference @BufferObject(BufferKind.ArrayVBO) @Check @Const @@ -1011,11 +1011,14 @@ */ int GL_VERTEX_ARRAY_BINDING = 0x85B5; + @Code(" StateTracker.bindVAO(caps, array);") void glBindVertexArray(@GLuint int array); + @Code(" StateTracker.deleteVAO(caps, arrays);") void glDeleteVertexArrays(@AutoSize("arrays") @GLsizei int n, @Const @GLuint IntBuffer arrays); @Alternate("glDeleteVertexArrays") + @Code(" StateTracker.deleteVAO(caps, array);") void glDeleteVertexArrays(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getBufferInt().put(0, array), 0", keepParam = true) int array); void glGenVertexArrays(@AutoSize("arrays") @GLsizei int n, @OutParameter @GLuint IntBuffer arrays); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/GL41.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/GL41.java 2010-11-27 09:38:48 UTC (rev 3458) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/GL41.java 2010-11-29 17:21:05 UTC (rev 3459) @@ -390,7 +390,7 @@ @Optional(reason = "Not exposed in ATI Catalyst 10.10c") void glVertexAttribLPointer(@GLuint int index, int size, @Constant("GL11.GL_DOUBLE") @GLenum int type, @GLsizei int stride, - @CachedReference(index = "index", name = "glVertexAttribPointer_buffer") + //@CachedReference(index = "index", name = "glVertexAttribPointer_buffer") @BufferObject(BufferKind.ArrayVBO) @Check @Const @GLdouble Buffer pointer); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_vertex_program.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_vertex_program.java 2010-11-27 09:38:48 UTC (rev 3458) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_vertex_program.java 2010-11-29 17:21:05 UTC (rev 3459) @@ -229,7 +229,7 @@ void glTrackMatrixNV(@GLenum int target, @GLuint int address, @GLenum int matrix, @GLenum int transform); void glVertexAttribPointerNV(@GLuint int index, int size, @GLenum int type, @GLsizei int stride, - @CachedReference(index="index",name="glVertexAttribPointer_buffer") + //@CachedReference(index="index",name="glVertexAttribPointer_buffer") @BufferObject(BufferKind.ArrayVBO) @Check @Const This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sp...@us...> - 2010-11-29 18:25:35
|
Revision: 3460 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3460&view=rev Author: spasi Date: 2010-11-29 18:25:28 +0000 (Mon, 29 Nov 2010) Log Message: ----------- Reverted @CachedReference tracking removal. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/BaseReferences.java trunk/LWJGL/src/java/org/lwjgl/opengl/ReferencesStack.java trunk/LWJGL/src/java/org/lwjgl/opengl/StateTracker.java trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_matrix_palette.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_attrib_64bit.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_blend.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_program.java trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_shader.java trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_fog_coord.java trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_gpu_shader4.java trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_secondary_color.java trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_vertex_attrib_64bit.java trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_vertex_shader.java trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_vertex_weighting.java trunk/LWJGL/src/templates/org/lwjgl/opengl/GL11.java trunk/LWJGL/src/templates/org/lwjgl/opengl/GL13.java trunk/LWJGL/src/templates/org/lwjgl/opengl/GL14.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/GL41.java trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_vertex_program.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/BaseReferences.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/BaseReferences.java 2010-11-29 17:21:05 UTC (rev 3459) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/BaseReferences.java 2010-11-29 18:25:28 UTC (rev 3460) @@ -31,15 +31,20 @@ */ package org.lwjgl.opengl; +import java.nio.Buffer; +import java.util.Arrays; + import static org.lwjgl.opengl.GL11.*; +import static org.lwjgl.opengl.GL13.*; +import static org.lwjgl.opengl.GL20.*; class BaseReferences { int elementArrayBuffer; int arrayBuffer; - //final Buffer[] glVertexAttribPointer_buffer; - //final Buffer[] glTexCoordPointer_buffer; - //int glClientActiveTexture; + final Buffer[] glVertexAttribPointer_buffer; + final Buffer[] glTexCoordPointer_buffer; + int glClientActiveTexture; int vertexArrayObject; @@ -49,31 +54,29 @@ int indirectBuffer; BaseReferences(ContextCapabilities caps) { - /* int max_vertex_attribs; - if (caps.OpenGL20 || caps.GL_ARB_vertex_shader) + if ( caps.OpenGL20 || caps.GL_ARB_vertex_shader ) max_vertex_attribs = glGetInteger(GL_MAX_VERTEX_ATTRIBS); else max_vertex_attribs = 0; - glVertexAttribPointer_buffer = new Buffer[max_vertex_attribs]; + glVertexAttribPointer_buffer = new Buffer[max_vertex_attribs]; int max_texture_units; - if (caps.OpenGL20) + if ( caps.OpenGL20 ) max_texture_units = glGetInteger(GL_MAX_TEXTURE_IMAGE_UNITS); - else if (caps.OpenGL13 || caps.GL_ARB_multitexture) + else if ( caps.OpenGL13 || caps.GL_ARB_multitexture ) max_texture_units = glGetInteger(GL_MAX_TEXTURE_UNITS); else max_texture_units = 1; - glTexCoordPointer_buffer = new Buffer[max_texture_units]; - */ + glTexCoordPointer_buffer = new Buffer[max_texture_units]; } void clear() { this.elementArrayBuffer = 0; this.arrayBuffer = 0; - //this.glClientActiveTexture = 0; - //Arrays.fill(glVertexAttribPointer_buffer, null); - //Arrays.fill(glTexCoordPointer_buffer, null); + this.glClientActiveTexture = 0; + Arrays.fill(glVertexAttribPointer_buffer, null); + Arrays.fill(glTexCoordPointer_buffer, null); this.vertexArrayObject = 0; @@ -87,9 +90,9 @@ if ( (mask & GL_CLIENT_VERTEX_ARRAY_BIT) != 0 ) { this.elementArrayBuffer = references.elementArrayBuffer; this.arrayBuffer = references.arrayBuffer; - //this.glClientActiveTexture = references.glClientActiveTexture; - //System.arraycopy(references.glVertexAttribPointer_buffer, 0, glVertexAttribPointer_buffer, 0, glVertexAttribPointer_buffer.length); - //System.arraycopy(references.glTexCoordPointer_buffer, 0, glTexCoordPointer_buffer, 0, glTexCoordPointer_buffer.length); + this.glClientActiveTexture = references.glClientActiveTexture; + System.arraycopy(references.glVertexAttribPointer_buffer, 0, glVertexAttribPointer_buffer, 0, glVertexAttribPointer_buffer.length); + System.arraycopy(references.glTexCoordPointer_buffer, 0, glTexCoordPointer_buffer, 0, glTexCoordPointer_buffer.length); this.vertexArrayObject = references.vertexArrayObject; Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/ReferencesStack.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/ReferencesStack.java 2010-11-29 17:21:05 UTC (rev 3459) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/ReferencesStack.java 2010-11-29 18:25:28 UTC (rev 3460) @@ -34,10 +34,10 @@ import static org.lwjgl.opengl.GL11.*; class ReferencesStack { - private BaseReferences[] references_stack; + private References[] references_stack; private int stack_pos; - public BaseReferences getReferences() { + public References getReferences() { return references_stack[stack_pos]; } @@ -49,8 +49,8 @@ references_stack[pos].copy(references_stack[pos - 1], GL_ALL_CLIENT_ATTRIB_BITS); } - public BaseReferences popState(int mask) { - BaseReferences result = references_stack[stack_pos--]; + public References popState(int mask) { + References result = references_stack[stack_pos--]; references_stack[stack_pos].copy(result, ~mask); result.clear(); @@ -59,17 +59,17 @@ } private void growStack() { - BaseReferences[] new_references_stack = new BaseReferences[references_stack.length + 1]; + References[] new_references_stack = new References[references_stack.length + 1]; System.arraycopy(references_stack, 0, new_references_stack, 0, references_stack.length); references_stack = new_references_stack; - references_stack[references_stack.length - 1] = new BaseReferences(GLContext.getCapabilities()); + references_stack[references_stack.length - 1] = new References(GLContext.getCapabilities()); } ReferencesStack() { ContextCapabilities caps = GLContext.getCapabilities(); - references_stack = new BaseReferences[1]; + references_stack = new References[1]; stack_pos = 0; for (int i = 0; i < references_stack.length; i++) - references_stack[i] = new BaseReferences(caps); + references_stack[i] = new References(caps); } } Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/StateTracker.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/StateTracker.java 2010-11-29 17:21:05 UTC (rev 3459) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/StateTracker.java 2010-11-29 18:25:28 UTC (rev 3460) @@ -81,7 +81,7 @@ references_stack.pushState(); } - static BaseReferences getReferences(ContextCapabilities caps) { + static References getReferences(ContextCapabilities caps) { return caps.tracker.references_stack.getReferences(); } Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java 2010-11-29 17:21:05 UTC (rev 3459) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java 2010-11-29 18:25:28 UTC (rev 3460) @@ -596,7 +596,7 @@ cachedReference != null && (mode != Mode.BUFFEROBJECT || param.getAnnotation(BufferObject.class) == null) && param.getAnnotation(Result.class) == null) { - writer.print("\t\tif ( LWJGLUtil.CHECKS ) " + Utils.CHECKS_CLASS_NAME + ".getReferences(caps)."); + writer.print("\t\tif ( LWJGLUtil.CHECKS ) " + "StateTracker.getReferences(caps)."); if(cachedReference.name().length() > 0) { writer.print(cachedReference.name()); } else { Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_matrix_palette.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_matrix_palette.java 2010-11-29 17:21:05 UTC (rev 3459) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_matrix_palette.java 2010-11-29 18:25:28 UTC (rev 3460) @@ -52,7 +52,7 @@ void glCurrentPaletteMatrixARB(int index); void glMatrixIndexPointerARB(int size, @AutoType("pPointer") @GLenum int type, @GLsizei int stride, - //@CachedReference + @CachedReference @BufferObject(BufferKind.ArrayVBO) @Check @Const Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_attrib_64bit.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_attrib_64bit.java 2010-11-29 17:21:05 UTC (rev 3459) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_attrib_64bit.java 2010-11-29 18:25:28 UTC (rev 3460) @@ -85,7 +85,7 @@ @Reuse("GL41") void glVertexAttribLPointer(@GLuint int index, int size, @Constant("GL11.GL_DOUBLE") @GLenum int type, @GLsizei int stride, - //@CachedReference(index = "index", name = "glVertexAttribPointer_buffer") + @CachedReference(index = "index", name = "glVertexAttribPointer_buffer") @BufferObject(BufferKind.ArrayVBO) @Check @Const @GLdouble Buffer pointer); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_blend.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_blend.java 2010-11-29 17:21:05 UTC (rev 3459) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_blend.java 2010-11-29 18:25:28 UTC (rev 3460) @@ -106,7 +106,7 @@ void glWeightuivARB(@AutoSize("pWeights") int size, @GLuint IntBuffer pWeights); void glWeightPointerARB(int size, @AutoType("pPointer") @GLenum int type, @GLsizei int stride, - //@CachedReference + @CachedReference @BufferObject(BufferKind.ArrayVBO) @Check @Const Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_program.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_program.java 2010-11-29 17:21:05 UTC (rev 3459) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_program.java 2010-11-29 18:25:28 UTC (rev 3460) @@ -134,7 +134,7 @@ @Reuse("ARBVertexShader") void glVertexAttribPointerARB(@GLuint int index, int size, @AutoType("buffer") @GLenum int type, boolean normalized, @GLsizei int stride, - //@CachedReference(index = "index", name = "glVertexAttribPointer_buffer") + @CachedReference(index = "index", name = "glVertexAttribPointer_buffer") @BufferObject(BufferKind.ArrayVBO) @Check @Const Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_shader.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_shader.java 2010-11-29 17:21:05 UTC (rev 3459) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_shader.java 2010-11-29 18:25:28 UTC (rev 3460) @@ -129,7 +129,7 @@ void glVertexAttrib4NubARB(@GLuint int index, @GLubyte byte x, @GLubyte byte y, @GLubyte byte z, @GLubyte byte w); void glVertexAttribPointerARB(@GLuint int index, int size, @AutoType("buffer") @GLenum int type, boolean normalized, @GLsizei int stride, - //@CachedReference(index = "index", name = "glVertexAttribPointer_buffer") + @CachedReference(index = "index", name = "glVertexAttribPointer_buffer") @BufferObject(BufferKind.ArrayVBO) @Check @Const Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_fog_coord.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_fog_coord.java 2010-11-29 17:21:05 UTC (rev 3459) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_fog_coord.java 2010-11-29 18:25:28 UTC (rev 3460) @@ -54,7 +54,7 @@ void glFogCoorddEXT(double coord); void glFogCoordPointerEXT(@AutoType("data") @GLenum int type, @GLsizei int stride, - //@CachedReference + @CachedReference @BufferObject(BufferKind.ArrayVBO) @Check @Const Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_gpu_shader4.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_gpu_shader4.java 2010-11-29 17:21:05 UTC (rev 3459) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_gpu_shader4.java 2010-11-29 18:25:28 UTC (rev 3460) @@ -158,7 +158,7 @@ void glVertexAttribI4usvEXT(@GLuint int index, @Check("4") @Const @GLushort ShortBuffer v); void glVertexAttribIPointerEXT(@GLuint int index, int size, @GLenum int type, @GLsizei int stride, - //@CachedReference + @CachedReference @BufferObject(BufferKind.ArrayVBO) @Check @Const Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_secondary_color.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_secondary_color.java 2010-11-29 17:21:05 UTC (rev 3459) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_secondary_color.java 2010-11-29 18:25:28 UTC (rev 3460) @@ -55,7 +55,7 @@ void glSecondaryColor3ubEXT(@GLubyte byte red, @GLubyte byte green, @GLubyte byte blue); void glSecondaryColorPointerEXT(int size, @AutoType("pPointer") @GLenum int type, @GLsizei int stride, - //@CachedReference + @CachedReference @BufferObject(BufferKind.ArrayVBO) @Check @Const Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_vertex_attrib_64bit.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_vertex_attrib_64bit.java 2010-11-29 17:21:05 UTC (rev 3459) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_vertex_attrib_64bit.java 2010-11-29 18:25:28 UTC (rev 3460) @@ -75,7 +75,7 @@ void glVertexAttribL4dvEXT(@GLuint int index, @Const @Check("4") DoubleBuffer v); void glVertexAttribLPointerEXT(@GLuint int index, int size, @Constant("GL11.GL_DOUBLE") @GLenum int type, @GLsizei int stride, - //@CachedReference(index = "index", name = "glVertexAttribPointer_buffer") + @CachedReference(index = "index", name = "glVertexAttribPointer_buffer") @BufferObject(BufferKind.ArrayVBO) @Check @Const @GLdouble Buffer pointer); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_vertex_shader.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_vertex_shader.java 2010-11-29 17:21:05 UTC (rev 3459) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_vertex_shader.java 2010-11-29 18:25:28 UTC (rev 3460) @@ -225,7 +225,7 @@ void glVariantuivEXT(@GLuint int id, @Check("4") @Const @GLuint IntBuffer pAddr); void glVariantPointerEXT(@GLuint int id, @AutoType("pAddr") @GLenum int type, @GLuint int stride, - //@CachedReference + @CachedReference @BufferObject(BufferKind.ArrayVBO) @Check @Const Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_vertex_weighting.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_vertex_weighting.java 2010-11-29 17:21:05 UTC (rev 3459) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_vertex_weighting.java 2010-11-29 18:25:28 UTC (rev 3460) @@ -57,7 +57,7 @@ void glVertexWeightfEXT(float weight); void glVertexWeightPointerEXT(@GLsizei int size, @AutoType("pPointer") @GLenum int type, @GLsizei int stride, - //@CachedReference + @CachedReference @BufferObject(BufferKind.ArrayVBO) @Check @Const Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/GL11.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/GL11.java 2010-11-29 17:21:05 UTC (rev 3459) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/GL11.java 2010-11-29 18:25:28 UTC (rev 3460) @@ -800,7 +800,7 @@ @DeprecatedGL void glColorPointer(int size, @AutoType("pointer") @GLenum int type, @GLsizei int stride, - //@CachedReference + @CachedReference @Check @BufferObject(BufferKind.ArrayVBO) @Const @@ -889,7 +889,7 @@ @DeprecatedGL void glEdgeFlagPointer(int stride, - //@CachedReference + @CachedReference @BufferObject(BufferKind.ArrayVBO) @Check @Const @@ -1295,7 +1295,7 @@ @DeprecatedGL void glNormalPointer(@AutoType("pointer") @GLenum int type, @GLsizei int stride, - //@CachedReference + @CachedReference @BufferObject(BufferKind.ArrayVBO) @Check @Const @@ -1431,7 +1431,7 @@ @DeprecatedGL void glVertexPointer(int size, @AutoType("pointer") @GLenum int type, @GLsizei int stride, - //@CachedReference + @CachedReference @BufferObject(BufferKind.ArrayVBO) @Check @Const @@ -1565,7 +1565,7 @@ @DeprecatedGL void glTexCoordPointer(int size, @AutoType("pointer") @GLenum int type, @GLsizei int stride, - //@CachedReference(index = "GLChecks.getReferences(caps).glClientActiveTexture", name = "glTexCoordPointer_buffer") + @CachedReference(index = "StateTracker.getReferences(caps).glClientActiveTexture", name = "glTexCoordPointer_buffer") @BufferObject(BufferKind.ArrayVBO) @Check @Const Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/GL13.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/GL13.java 2010-11-29 17:21:05 UTC (rev 3459) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/GL13.java 2010-11-29 18:25:28 UTC (rev 3460) @@ -150,7 +150,7 @@ void glActiveTexture(@GLenum int texture); - //@Code("\t\tGLChecks.getReferences(caps).glClientActiveTexture = texture - GL_TEXTURE0;") + @Code("\t\tStateTracker.getReferences(caps).glClientActiveTexture = texture - GL_TEXTURE0;") @DeprecatedGL void glClientActiveTexture(@GLenum int texture); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/GL14.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/GL14.java 2010-11-29 17:21:05 UTC (rev 3459) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/GL14.java 2010-11-29 18:25:28 UTC (rev 3460) @@ -107,7 +107,7 @@ @DeprecatedGL void glFogCoordPointer(@AutoType("data") @GLenum int type, @GLsizei int stride, - //@CachedReference + @CachedReference @BufferObject(BufferKind.ArrayVBO) @Check @Const Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/GL20.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/GL20.java 2010-11-29 17:21:05 UTC (rev 3459) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/GL20.java 2010-11-29 18:25:28 UTC (rev 3460) @@ -338,7 +338,7 @@ void glVertexAttrib4Nub(@GLuint int index, @GLubyte byte x, @GLubyte byte y, @GLubyte byte z, @GLubyte byte w); void glVertexAttribPointer(@GLuint int index, int size, @AutoType("buffer") @GLenum int type, boolean normalized, @GLsizei int stride, - //@CachedReference(index = "index", name = "glVertexAttribPointer_buffer") + @CachedReference(index = "index", name = "glVertexAttribPointer_buffer") @BufferObject(BufferKind.ArrayVBO) @Check @Const Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/GL30.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/GL30.java 2010-11-29 17:21:05 UTC (rev 3459) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/GL30.java 2010-11-29 18:25:28 UTC (rev 3460) @@ -204,7 +204,7 @@ void glVertexAttribI4usv(@GLuint int index, @Check("4") @Const @GLushort ShortBuffer v); void glVertexAttribIPointer(@GLuint int index, int size, @GLenum int type, @GLsizei int stride, - //@CachedReference + @CachedReference @BufferObject(BufferKind.ArrayVBO) @Check @Const Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/GL41.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/GL41.java 2010-11-29 17:21:05 UTC (rev 3459) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/GL41.java 2010-11-29 18:25:28 UTC (rev 3460) @@ -390,7 +390,7 @@ @Optional(reason = "Not exposed in ATI Catalyst 10.10c") void glVertexAttribLPointer(@GLuint int index, int size, @Constant("GL11.GL_DOUBLE") @GLenum int type, @GLsizei int stride, - //@CachedReference(index = "index", name = "glVertexAttribPointer_buffer") + @CachedReference(index = "index", name = "glVertexAttribPointer_buffer") @BufferObject(BufferKind.ArrayVBO) @Check @Const @GLdouble Buffer pointer); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_vertex_program.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_vertex_program.java 2010-11-29 17:21:05 UTC (rev 3459) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_vertex_program.java 2010-11-29 18:25:28 UTC (rev 3460) @@ -229,7 +229,7 @@ void glTrackMatrixNV(@GLenum int target, @GLuint int address, @GLenum int matrix, @GLenum int transform); void glVertexAttribPointerNV(@GLuint int index, int size, @GLenum int type, @GLsizei int stride, - //@CachedReference(index="index",name="glVertexAttribPointer_buffer") + @CachedReference(index="index",name="glVertexAttribPointer_buffer") @BufferObject(BufferKind.ArrayVBO) @Check @Const This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sp...@us...> - 2010-12-06 15:58:18
|
Revision: 3461 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3461&view=rev Author: spasi Date: 2010-12-06 15:58:11 +0000 (Mon, 06 Dec 2010) Log Message: ----------- Added clSetKernelArg support for CLObject and __local arguments. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opencl/CLKernel.java trunk/LWJGL/src/java/org/lwjgl/opencl/InfoUtilFactory.java trunk/LWJGL/src/templates/org/lwjgl/opencl/CL10.java Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/CLKernel.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/CLKernel.java 2010-11-29 18:25:28 UTC (rev 3460) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/CLKernel.java 2010-12-06 15:58:11 UTC (rev 3461) @@ -31,8 +31,6 @@ */ package org.lwjgl.opencl; -import org.lwjgl.PointerWrapper; - /** * This class is a wrapper around a cl_kernel pointer. * @@ -145,11 +143,24 @@ * * @return this CLKernel object */ - public CLKernel setArg(final int index, final PointerWrapper value) { + public CLKernel setArg(final int index, final CLObject value) { util.setArg(this, index, value); return this; } + /** + * Sets the size of a __local kernel argument at the specified index. + * + * @param index the argument index + * @param size the argument size + * + * @return this CLKernel object + */ + public CLKernel setArgSize(final int index, final long size) { + util.setArgSize(this, index, size); + return this; + } + // clGetKernelInfo methods /** @@ -225,8 +236,10 @@ void setArg(CLKernel kernel, int index, double value); - void setArg(CLKernel kernel, int index, PointerWrapper pointer); + void setArg(CLKernel kernel, int index, CLObject pointer); + void setArgSize(CLKernel kernel, int index, long size); + long getWorkGroupInfoSize(CLKernel kernel, CLDevice device, int param_name); long[] getWorkGroupInfoSizeArray(CLKernel kernel, CLDevice device, int param_name); Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/InfoUtilFactory.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/InfoUtilFactory.java 2010-11-29 18:25:28 UTC (rev 3460) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/InfoUtilFactory.java 2010-12-06 15:58:11 UTC (rev 3461) @@ -230,10 +230,14 @@ clSetKernelArg(kernel, index, 8, APIUtil.getBufferDouble().put(0, value)); } - public void setArg(final CLKernel kernel, final int index, final PointerWrapper pointer) { - clSetKernelArg(kernel, index, PointerBuffer.getPointerSize(), APIUtil.getBufferPointer().put(0, pointer).getBuffer()); + public void setArg(final CLKernel kernel, final int index, final CLObject value) { + clSetKernelArg(kernel, index, value); } + public void setArgSize(final CLKernel kernel, final int index, final long size) { + clSetKernelArg(kernel, index, size); + } + protected int getInfo(final CLKernel kernel, final int param_name, final ByteBuffer param_value, final PointerBuffer param_value_size_ret) { return clGetKernelInfo(kernel, param_name, param_value, param_value_size_ret); } Modified: trunk/LWJGL/src/templates/org/lwjgl/opencl/CL10.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opencl/CL10.java 2010-11-29 18:25:28 UTC (rev 3460) +++ trunk/LWJGL/src/templates/org/lwjgl/opencl/CL10.java 2010-12-06 15:58:11 UTC (rev 3461) @@ -979,8 +979,8 @@ @cl_int int clSetKernelArg(@PointerWrapper("cl_kernel") CLKernel kernel, @cl_uint int arg_index, - @AutoSize(value = "arg_value", canBeNull = true) @size_t long arg_size, - @Check(canBeNull = true) @Const + @AutoSize("arg_value") @size_t long arg_size, + @Const @cl_byte @cl_short @cl_int @@ -988,17 +988,33 @@ @cl_float @cl_double Buffer arg_value); - // This is used by CLKernelImpl. Assumes arg_value.position() == 0. + @Alternate("clSetKernelArg") + @cl_int + int clSetKernelArg(@PointerWrapper("cl_kernel") CLKernel kernel, + @cl_uint int arg_index, + @Constant("PointerBuffer.getPointerSize()") @size_t long arg_size, + @Check(canBeNull = true) @Const + @Constant(value = "APIUtil.getBufferPointer().put(0, arg_value == null ? 0 : arg_value.getPointer()).getBuffer(), 0", keepParam = true) CLObject arg_value); + /** Sets the size of a __local kernel argument at the specified index. */ @Alternate("clSetKernelArg") - @Private @cl_int int clSetKernelArg2(@PointerWrapper("cl_kernel") CLKernel kernel, @cl_uint int arg_index, @size_t long arg_size, - @Check(value = "1") @Const Buffer arg_value); + @Constant("null, 0") Buffer arg_value); + // This is used by CLKernelUtil. Assumes arg_value.position() == 0. + + @Alternate("clSetKernelArg") + @Private @cl_int + int clSetKernelArg3(@PointerWrapper("cl_kernel") CLKernel kernel, + @cl_uint int arg_index, + @size_t long arg_size, + @Constant(value = "arg_value, 0", keepParam = true) Buffer arg_value); + + @cl_int int clGetKernelInfo(@PointerWrapper("cl_kernel") CLKernel kernel, @NativeType("cl_kernel_info") int param_name, @AutoSize(value = "param_value", canBeNull = true) @size_t long param_value_size, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sp...@us...> - 2011-04-07 21:36:27
|
Revision: 3513 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3513&view=rev Author: spasi Date: 2011-04-07 21:36:19 +0000 (Thu, 07 Apr 2011) Log Message: ----------- Added support for AMD_blend_minmax_factor & NV_texture_multisample. Added sprite rendering samples. Fixed ContextAttribs version checking for GL41. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/ContextAttribs.java trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/ShadersTest.java Added Paths: ----------- trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/ 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/templates/org/lwjgl/opengl/AMD_blend_minmax_factor.java trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_texture_multisample.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/ContextAttribs.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/ContextAttribs.java 2011-04-02 11:33:02 UTC (rev 3512) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/ContextAttribs.java 2011-04-07 21:36:19 UTC (rev 3513) @@ -87,7 +87,7 @@ public ContextAttribs(final int majorVersion, final int minorVersion) { if ( majorVersion < 0 || 4 < majorVersion || minorVersion < 0 || - (majorVersion == 4 && 0 < minorVersion) || + (majorVersion == 4 && 1 < minorVersion) || (majorVersion == 3 && 3 < minorVersion) || (majorVersion == 2 && 1 < minorVersion) || (majorVersion == 1 && 5 < minorVersion) ) Modified: trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/ShadersTest.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/ShadersTest.java 2011-04-02 11:33:02 UTC (rev 3512) +++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/shaders/ShadersTest.java 2011-04-07 21:36:19 UTC (rev 3513) @@ -137,7 +137,7 @@ System.out.println("Setting display mode to: " + displayMode); Display.setDisplayMode(displayMode); - Display.create(new PixelFormat(8, 24, 0), "UNI".equalsIgnoreCase(args[0]) ? new ContextAttribs(3, 1) : null); + Display.create(new PixelFormat(8, 24, 0)); ShadersTest.displayMode = displayMode; } catch (LWJGLException e) { kill(e.getMessage()); Added: trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/SpriteShootout.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/SpriteShootout.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/SpriteShootout.java 2011-04-07 21:36:19 UTC (rev 3513) @@ -0,0 +1,714 @@ +package org.lwjgl.test.opengl.sprites; + +import org.lwjgl.BufferUtils; +import org.lwjgl.LWJGLException; +import org.lwjgl.Sys; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.*; + +import java.awt.image.BufferedImage; +import java.awt.image.Raster; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.FloatBuffer; +import java.util.Random; +import javax.imageio.ImageIO; + +import static org.lwjgl.opengl.EXTTransformFeedback.*; +import static org.lwjgl.opengl.GL11.*; +import static org.lwjgl.opengl.GL12.*; +import static org.lwjgl.opengl.GL15.*; +import static org.lwjgl.opengl.GL20.*; +import static org.lwjgl.opengl.GL30.*; + +/** + * Sprite rendering demo. Three implementations are supported: + * a) CPU animation + BufferData VBO update. + * b) CPU animation + MapBufferRange VBO update. + * c) GPU animation using transform feedback with a vertex shader. + * + * @author Spasi + * @since 18/3/2011 + */ +public final class SpriteShootout { + + private static final int SCREEN_WIDTH = 800; + private static final int SCREEN_HEIGHT = 600; + + private static final int ANIMATION_TICKS = 60; + + private boolean run = true; + private boolean render = true; + private boolean colorMask = true; + private boolean animate = true; + private boolean smooth; + private boolean vsync; + + private int ballSize = 42; + private int ballCount = 100 * 1000; + + private SpriteRenderer renderer; + + // OpenGL stuff + private int texID; + private int texBigID; + private int texSmallID; + + private SpriteShootout() { + } + + public static void main(String[] args) { + try { + new SpriteShootout().start(); + } catch (LWJGLException e) { + e.printStackTrace(); + } + } + + private void start() throws LWJGLException { + try { + initGL(); + + final ContextCapabilities caps = GLContext.getCapabilities(); + if ( caps.OpenGL30 || caps.GL_EXT_transform_feedback ) + renderer = new SpriteRendererTF(); + else if ( caps.GL_ARB_map_buffer_range ) + renderer = new SpriteRendererMapped(); + else + renderer = new SpriteRendererPlain(); + + updateBalls(ballCount); + run(); + } catch (Throwable t) { + t.printStackTrace(); + } finally { + destroy(); + } + } + + private void initGL() throws LWJGLException { + Display.setLocation((Display.getDisplayMode().getWidth() - SCREEN_WIDTH) / 2, + (Display.getDisplayMode().getHeight() - SCREEN_HEIGHT) / 2); + Display.setDisplayMode(new DisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT)); + Display.setTitle("Sprite Shootout"); + Display.create(); + //Display.create(new PixelFormat(), new ContextAttribs(4, 1).withProfileCompatibility(true).withDebug(true)); + //AMDDebugOutput.glDebugMessageCallbackAMD(new AMDDebugOutputCallback()); + + if ( !GLContext.getCapabilities().OpenGL20 ) + throw new RuntimeException("OpenGL 2.0 is required for this demo."); + + // Setup viewport + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, SCREEN_WIDTH, 0, SCREEN_HEIGHT, -1.0, 1.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); + + glClearColor(1.0f, 1.0f, 1.0f, 0.0f); + + // Create textures + + try { + texSmallID = createTexture("res/ball_sm.png"); + texBigID = createTexture("res/ball.png"); + } catch (IOException e) { + e.printStackTrace(); + System.exit(-1); + } + texID = texBigID; + + // Setup rendering state + + glEnable(GL_BLEND); + glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + + glEnable(GL_ALPHA_TEST); + glAlphaFunc(GL_GREATER, 0.0f); + + glColorMask(colorMask, colorMask, colorMask, false); + glDepthMask(false); + glDisable(GL_DEPTH_TEST); + + // Setup geometry + + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + + Util.checkGLError(); + } + + private static int createTexture(final String path) throws IOException { + final BufferedImage img = ImageIO.read(SpriteShootout.class.getClassLoader().getResource(path)); + + final int w = img.getWidth(); + final int h = img.getHeight(); + + final ByteBuffer buffer = readImage(img); + + final int texID = glGenTextures(); + + glBindTexture(GL_TEXTURE_2D, texID); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, buffer); + + return texID; + } + + private static ByteBuffer readImage(final BufferedImage img) throws IOException { + final Raster raster = img.getRaster(); + + final int bands = raster.getNumBands(); + + final int w = img.getWidth(); + final int h = img.getHeight(); + + final int size = w * h * bands; + + final byte[] pixels = new byte[size]; + raster.getDataElements(0, 0, w, h, pixels); + + final ByteBuffer pbuffer = BufferUtils.createByteBuffer(size); + + if ( bands == 4 ) { + for ( int i = 0; i < (w * h * 4); i += 4 ) { + // Pre-multiply alpha + final float a = unpackUByte01(pixels[i + 3]); + pbuffer.put(packUByte01(unpackUByte01(pixels[i + 2]) * a)); + pbuffer.put(packUByte01(unpackUByte01(pixels[i + 1]) * a)); + pbuffer.put(packUByte01(unpackUByte01(pixels[i + 0]) * a)); + pbuffer.put(pixels[i + 3]); + } + } else if ( bands == 3 ) { + for ( int i = 0; i < (w * h * 3); i += 3 ) { + pbuffer.put(pixels[i + 2]); + pbuffer.put(pixels[i + 1]); + pbuffer.put(pixels[i + 0]); + } + } else + pbuffer.put(pixels, 0, size); + + pbuffer.flip(); + + return pbuffer; + } + + private static float unpackUByte01(final byte x) { + return (x & 0xFF) / 255.0f; + } + + private static byte packUByte01(final float x) { + return (byte)(x * 255.0f); + } + + private void updateBalls(final int count) { + System.out.println("NUMBER OF BALLS: " + count); + renderer.updateBalls(ballCount); + } + + private void run() { + long startTime = System.currentTimeMillis() + 5000; + long fps = 0; + + long time = Sys.getTime(); + final int ticksPerUpdate = (int)(Sys.getTimerResolution() / ANIMATION_TICKS); + + renderer.render(false, true, 0); + + while ( run ) { + Display.processMessages(); + handleInput(); + + glClear(GL_COLOR_BUFFER_BIT); + + final long currTime = Sys.getTime(); + final int delta = (int)(currTime - time); + if ( smooth || delta >= ticksPerUpdate ) { + renderer.render(render, animate, delta); + time = currTime; + } else + renderer.render(render, false, 0); + + Display.update(false); + //Display.sync(60); + + if ( startTime > System.currentTimeMillis() ) { + fps++; + } else { + long timeUsed = 5000 + (startTime - System.currentTimeMillis()); + startTime = System.currentTimeMillis() + 5000; + System.out.println("FPS: " + (Math.round(fps / (timeUsed / 1000.0) * 10) / 10.0) + ", Balls: " + ballCount); + fps = 0; + } + } + } + + private void handleInput() { + if ( Display.isCloseRequested() ) + run = false; + + while ( Keyboard.next() ) { + if ( Keyboard.getEventKeyState() ) + continue; + + switch ( Keyboard.getEventKey() ) { + case Keyboard.KEY_1: + case Keyboard.KEY_2: + case Keyboard.KEY_3: + case Keyboard.KEY_4: + case Keyboard.KEY_5: + case Keyboard.KEY_6: + case Keyboard.KEY_7: + case Keyboard.KEY_8: + case Keyboard.KEY_9: + case Keyboard.KEY_0: + ballCount = 1 << (Keyboard.getEventKey() - Keyboard.KEY_1); + updateBalls(ballCount); + break; + case Keyboard.KEY_ADD: + case Keyboard.KEY_SUBTRACT: + int mult; + if ( Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) ) + mult = 1000; + else if ( Keyboard.isKeyDown(Keyboard.KEY_LMENU) || Keyboard.isKeyDown(Keyboard.KEY_RMENU) ) + mult = 100; + else if ( Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL) ) + mult = 10; + else + mult = 1; + if ( Keyboard.getEventKey() == Keyboard.KEY_SUBTRACT ) + mult = -mult; + ballCount += mult * 100; + if ( ballCount <= 0 ) + ballCount = 1; + updateBalls(ballCount); + break; + case Keyboard.KEY_ESCAPE: + run = false; + break; + case Keyboard.KEY_A: + animate = !animate; + System.out.println("Animation is now " + (animate ? "on" : "off") + "."); + break; + case Keyboard.KEY_C: + colorMask = !colorMask; + glColorMask(colorMask, colorMask, colorMask, false); + System.out.println("Color mask is now " + (colorMask ? "on" : "off") + "."); + // Disable alpha test when color mask is off, else we get no benefit. + if ( colorMask ) { + glEnable(GL_BLEND); + glEnable(GL_ALPHA_TEST); + } else { + glDisable(GL_BLEND); + glDisable(GL_ALPHA_TEST); + } + break; + case Keyboard.KEY_R: + render = !render; + System.out.println("Rendering is now " + (render ? "on" : "off") + "."); + break; + case Keyboard.KEY_S: + smooth = !smooth; + System.out.println("Smooth animation is now " + (smooth ? "on" : "off") + "."); + break; + case Keyboard.KEY_T: + if ( texID == texBigID ) { + texID = texSmallID; + ballSize = 16; + } else { + texID = texBigID; + ballSize = 42; + } + renderer.updateBallSize(); + glBindTexture(GL_TEXTURE_2D, texID); + System.out.println("Now using the " + (texID == texBigID ? "big" : "small") + " texture."); + break; + case Keyboard.KEY_V: + vsync = !vsync; + Display.setVSyncEnabled(vsync); + System.out.println("VSYNC is now " + (vsync ? "enabled" : "disabled") + "."); + break; + } + } + + while ( Mouse.next() ) ; + } + + private void destroy() { + Display.destroy(); + } + + private abstract class SpriteRenderer { + + protected float[] transform = { }; + + protected int vshID; + protected int progID; + + protected void createProgram() { + final int fshID = glCreateShader(GL_FRAGMENT_SHADER); + glShaderSource(fshID, "uniform sampler2D COLOR_MAP;\n" + + "void main(void) {\n" + + " gl_FragColor = texture2D(COLOR_MAP, gl_PointCoord);\n" + + "}"); + glCompileShader(fshID); + if ( glGetShader(fshID, GL_COMPILE_STATUS) == GL_FALSE ) { + System.out.println(glGetShaderInfoLog(fshID, glGetShader(fshID, GL_INFO_LOG_LENGTH))); + throw new RuntimeException("Failed to compile fragment shader."); + } + + progID = glCreateProgram(); + glAttachShader(progID, vshID); + glAttachShader(progID, fshID); + glLinkProgram(progID); + if ( glGetProgram(progID, GL_LINK_STATUS) == GL_FALSE ) { + System.out.println(glGetProgramInfoLog(progID, glGetProgram(progID, GL_INFO_LOG_LENGTH))); + throw new RuntimeException("Failed to link shader program."); + } + + glUseProgram(progID); + glUniform1i(glGetUniformLocation(progID, "COLOR_MAP"), 0); + + updateBallSize(); + + glEnableClientState(GL_VERTEX_ARRAY); + } + + public void updateBallSize() { + glPointSize(ballSize); + } + + public void updateBalls(final int count) { + final Random random = new Random(); + + final float[] newTransform = new float[count * 4]; + System.arraycopy(transform, 0, newTransform, 0, Math.min(transform.length, newTransform.length)); + if ( newTransform.length > transform.length ) { + for ( int i = transform.length; i < newTransform.length; ) { + newTransform[i++] = (int)(random.nextFloat() * (SCREEN_WIDTH - ballSize) + ballSize * 0.5f); + newTransform[i++] = (int)(random.nextFloat() * (SCREEN_HEIGHT - ballSize) + ballSize * 0.5f); + newTransform[i++] = random.nextFloat() * 0.4f - 0.2f; + newTransform[i++] = random.nextFloat() * 0.4f - 0.2f; + } + } + transform = newTransform; + } + + protected void animate(final FloatBuffer geom, final int ballIndex, final int batchSize, final int delta) { + final float[] transform = this.transform; + + 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]; + + x += dx * delta; + if ( x < ballRadius ) { + x = ballRadius; + transform[b + 2] = -dx; + } else if ( x > boundW ) { + x = boundW; + transform[b + 2] = -dx; + } + transform[b + 0] = x; + + float y = transform[b + 1]; + float dy = transform[b + 3]; + + y += dy * delta; + if ( y < ballRadius ) { + y = ballRadius; + transform[b + 3] = -dy; + } else if ( y > boundH ) { + y = boundH; + transform[b + 3] = -dy; + } + transform[b + 1] = y; + + geom.put(x).put(y); + } + geom.clear(); + } + + protected abstract void render(boolean render, boolean animate, int delta); + + } + + private abstract class SpriteRendererBatched extends SpriteRenderer { + + protected static final int BALLS_PER_BATCH = 10 * 1000; + + SpriteRendererBatched() { + vshID = glCreateShader(GL_VERTEX_SHADER); + glShaderSource(vshID, "void main(void) {\n" + + " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" + + "}"); + glCompileShader(vshID); + if ( glGetShader(vshID, GL_COMPILE_STATUS) == GL_FALSE ) { + System.out.println(glGetShaderInfoLog(vshID, glGetShader(vshID, GL_INFO_LOG_LENGTH))); + throw new RuntimeException("Failed to compile vertex shader."); + } + + createProgram(); + } + + } + + private class SpriteRendererPlain extends SpriteRendererBatched { + + private final FloatBuffer geom; + + protected int[] animVBO; + + SpriteRendererPlain() { + System.out.println("Shootout Implementation: CPU animation & BufferData"); + geom = BufferUtils.createFloatBuffer(BALLS_PER_BATCH * 4 * 2); + } + + public void updateBalls(final int count) { + super.updateBalls(count); + + final int batchCount = count / BALLS_PER_BATCH + (count % BALLS_PER_BATCH == 0 ? 0 : 1); + if ( animVBO != null && batchCount == animVBO.length ) + return; + + final int[] newAnimVBO = new int[batchCount]; + if ( animVBO != null ) { + System.arraycopy(animVBO, 0, newAnimVBO, 0, Math.min(animVBO.length, newAnimVBO.length)); + for ( int i = newAnimVBO.length; i < animVBO.length; i++ ) + glDeleteBuffers(animVBO[i]); + } + for ( int i = animVBO == null ? 0 : animVBO.length; i < newAnimVBO.length; i++ ) { + newAnimVBO[i] = glGenBuffers(); + glBindBuffer(GL_ARRAY_BUFFER, newAnimVBO[i]); + } + + animVBO = newAnimVBO; + } + + public void render(final boolean render, final boolean animate, final int delta) { + int batchSize = Math.min(ballCount, BALLS_PER_BATCH); + int ballIndex = 0; + int vboIndex = 0; + while ( ballIndex < ballCount ) { + glBindBuffer(GL_ARRAY_BUFFER, animVBO[vboIndex++]); + + if ( animate ) + animate(ballIndex, batchSize, delta); + + if ( render ) { + glVertexPointer(2, GL_FLOAT, 0, 0); + glDrawArrays(GL_POINTS, 0, batchSize); + } + + ballIndex += batchSize; + batchSize = Math.min(ballCount - ballIndex, BALLS_PER_BATCH); + } + } + + private void animate(final int ballIndex, final int batchSize, final int delta) { + animate(geom, ballIndex, batchSize, delta); + + glBufferData(GL_ARRAY_BUFFER, geom.capacity() * 4, GL_STREAM_DRAW); + glBufferSubData(GL_ARRAY_BUFFER, 0, geom); + } + } + + private class SpriteRendererMapped extends SpriteRendererBatched { + + private ByteBuffer[] mapBuffer; + private FloatBuffer[] geomBuffer; + + protected int animVBO; + + SpriteRendererMapped() { + System.out.println("Shootout Implementation: CPU animation & MapBufferRange"); + } + + 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]; + + animVBO = glGenBuffers(); + glBindBuffer(GL_ARRAY_BUFFER, animVBO); + glBufferData(GL_ARRAY_BUFFER, ballCount * (2 * 4), GL_DYNAMIC_DRAW); + glVertexPointer(2, GL_FLOAT, 0, 0); + } + + 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(); + } + + animate(geomBuffer[batchIndex], ballIndex, batchSize, delta); + + glUnmapBuffer(GL_ARRAY_BUFFER); + } + + if ( render ) + glDrawArrays(GL_POINTS, ballIndex, batchSize); + + batchIndex++; + ballIndex += batchSize; + batchSize = Math.min(ballCount - ballIndex, BALLS_PER_BATCH); + } + } + } + + private class SpriteRendererTF extends SpriteRenderer { + + private int progIDTF; + private int ballSizeLoc; + private int deltaLoc; + + private int[] tfVBO = new int[2]; + private int currVBO; + + SpriteRendererTF() { + System.out.println("Shootout Implementation: TF GPU animation"); + + // Transform-feedback program + + final int vshID = glCreateShader(GL_VERTEX_SHADER); + glShaderSource(vshID, "#version 130\n" + + "const float WIDTH = " + SCREEN_WIDTH + ";\n" + + "const float HEIGHT = " + SCREEN_HEIGHT + ";\n" + + "uniform float ballSize;\n" + // ballSize / 2 + "uniform float delta;\n" + + "void main(void) {\n" + + " vec4 anim = gl_Vertex;\n" + + " anim.xy = anim.xy + anim.zw * delta;\n" + + " vec2 animC = clamp(anim.xy, vec2(ballSize), vec2(WIDTH - ballSize, HEIGHT - ballSize));\n" + + " if ( anim.x != animC.x ) anim.z = -anim.z;\n" + + " if ( anim.y != animC.y ) anim.w = -anim.w;\n" + + " gl_Position = vec4(animC, anim.zw);\n" + + "}"); + glCompileShader(vshID); + if ( glGetShader(vshID, GL_COMPILE_STATUS) == GL_FALSE ) { + System.out.println(glGetShaderInfoLog(vshID, glGetShader(vshID, GL_INFO_LOG_LENGTH))); + throw new RuntimeException("Failed to compile vertex shader."); + } + + progIDTF = glCreateProgram(); + glAttachShader(progIDTF, vshID); + glTransformFeedbackVaryings(progIDTF, new CharSequence[] { "gl_Position" }, GL_SEPARATE_ATTRIBS); + glLinkProgram(progIDTF); + if ( glGetProgram(progIDTF, GL_LINK_STATUS) == GL_FALSE ) { + System.out.println(glGetProgramInfoLog(progIDTF, glGetProgram(progIDTF, GL_INFO_LOG_LENGTH))); + throw new RuntimeException("Failed to link shader program."); + } + + glUseProgram(progIDTF); + + ballSizeLoc = glGetUniformLocation(progIDTF, "ballSize"); + deltaLoc = glGetUniformLocation(progIDTF, "delta"); + + glUniform1f(ballSizeLoc, ballSize * 0.5f); + + // ----------------- + + this.vshID = glCreateShader(GL_VERTEX_SHADER); + glShaderSource(this.vshID, "void main(void) {\n" + + " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" + + "}"); + glCompileShader(this.vshID); + if ( glGetShader(this.vshID, GL_COMPILE_STATUS) == GL_FALSE ) { + System.out.println(glGetShaderInfoLog(this.vshID, glGetShader(this.vshID, GL_INFO_LOG_LENGTH))); + throw new RuntimeException("Failed to compile vertex shader."); + } + + createProgram(); + } + + public void updateBallSize() { + glUseProgram(progIDTF); + glUniform1f(ballSizeLoc, ballSize * 0.5f); + + glUseProgram(progID); + super.updateBallSize(); + } + + public void updateBalls(final int count) { + super.updateBalls(count); + + if ( tfVBO[0] != 0 ) { + for ( int i = 0; i < tfVBO.length; i++ ) + glDeleteBuffers(tfVBO[i]); + } + + final FloatBuffer transform = BufferUtils.createFloatBuffer(count * 4); + transform.put(this.transform); + transform.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); + } + + glBindBuffer(GL_ARRAY_BUFFER, tfVBO[0]); + glVertexPointer(2, GL_FLOAT, (4 * 4), 0); + } + + public void render(final boolean render, final boolean animate, final int delta) { + if ( animate ) { + glUseProgram(progIDTF); + glUniform1f(deltaLoc, delta); + + final int vbo = currVBO; + currVBO = 1 - currVBO; + + glBindBuffer(GL_ARRAY_BUFFER, tfVBO[vbo]); + glVertexPointer(4, GL_FLOAT, 0, 0); + + glEnable(GL_RASTERIZER_DISCARD); + if ( GLContext.getCapabilities().OpenGL30 ) { + glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, tfVBO[1 - vbo]); + + glBeginTransformFeedback(GL_POINTS); + glDrawArrays(GL_POINTS, 0, ballCount); + glEndTransformFeedback(); + } else { + glBindBufferBaseEXT(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, 0, tfVBO[1 - vbo]); + + glBeginTransformFeedbackEXT(GL_POINTS); + glDrawArrays(GL_POINTS, 0, ballCount); + glEndTransformFeedbackEXT(); + } + glDisable(GL_RASTERIZER_DISCARD); + + glUseProgram(progID); + glVertexPointer(2, GL_FLOAT, (4 * 4), 0); + } + + if ( render ) + glDrawArrays(GL_POINTS, 0, ballCount); + } + + } + +} \ No newline at end of file Added: trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/SpriteShootout2P.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/SpriteShootout2P.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/SpriteShootout2P.java 2011-04-07 21:36:19 UTC (rev 3513) @@ -0,0 +1,591 @@ +package org.lwjgl.test.opengl.sprites; + +import org.lwjgl.BufferUtils; +import org.lwjgl.LWJGLException; +import org.lwjgl.Sys; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; +import org.lwjgl.opengl.*; + +import java.awt.image.BufferedImage; +import java.awt.image.Raster; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.FloatBuffer; +import java.util.Random; +import javax.imageio.ImageIO; + +import static org.lwjgl.opengl.EXTTransformFeedback.*; +import static org.lwjgl.opengl.GL11.*; +import static org.lwjgl.opengl.GL15.*; +import static org.lwjgl.opengl.GL20.*; +import static org.lwjgl.opengl.GL30.*; +import static org.lwjgl.opengl.GL32.*; + +/** + * Sprite rendering demo. In this version we're doing the animation + * computations on the GPU, using transform feedback and a vertex + * shader, then rendering is performed in 2 passes, with depth testing + * enabled: + * 1) Sprites are rendered front-to-back, opaque fragments only, blending is disabled. + * 2) Sprites are rendered back-to-front, transparent fragments only, blending is enabled. + * Sorting is free, because we're animating double the amount of sprites rendered, the + * first batch is sorted f2b, the second is sorted b2f. Ordering is achieved by modifying + * the z-axis position of the sprites in the vertex shader. + * + * @author Spasi + * @since 18/3/2011 + */ +public final class SpriteShootout2P { + + private static final int SCREEN_WIDTH = 800; + private static final int SCREEN_HEIGHT = 600; + + private static final int ANIMATION_TICKS = 60; + + private boolean run = true; + private boolean render = true; + private boolean colorMask = true; + private boolean animate = true; + private boolean smooth; + private boolean vsync; + + private int ballSize = 42; + private int ballCount = 100 * 1000; + + private SpriteRenderer renderer; + + // OpenGL stuff + private int texID; + private int texBigID; + private int texSmallID; + + private SpriteShootout2P() { + } + + public static void main(String[] args) { + try { + new SpriteShootout2P().start(); + } catch (LWJGLException e) { + e.printStackTrace(); + } + } + + private void start() throws LWJGLException { + try { + initGL(); + + renderer = new SpriteRendererTF(); + + updateBalls(ballCount); + run(); + } catch (Throwable t) { + t.printStackTrace(); + } finally { + destroy(); + } + } + + private void initGL() throws LWJGLException { + Display.setLocation((Display.getDisplayMode().getWidth() - SCREEN_WIDTH) / 2, + (Display.getDisplayMode().getHeight() - SCREEN_HEIGHT) / 2); + Display.setDisplayMode(new DisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT)); + Display.setTitle("Sprite Shootout 2-pass"); + Display.create(new PixelFormat(0, 24, 0)); + //Display.create(new PixelFormat(), new ContextAttribs(4, 1).withProfileCompatibility(true).withDebug(true)); + //AMDDebugOutput.glDebugMessageCallbackAMD(new AMDDebugOutputCallback()); + + final ContextCapabilities caps = GLContext.getCapabilities(); + if ( !(caps.OpenGL30 || (caps.OpenGL20 && caps.GL_EXT_transform_feedback)) ) + throw new RuntimeException("OpenGL 3.0 or 2.0 + EXT_transform_feedback is required for this demo."); + + // Setup viewport + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, SCREEN_WIDTH, 0, SCREEN_HEIGHT, -1.0, 1.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); + + glClearColor(1.0f, 1.0f, 1.0f, 0.0f); + + // Create textures + + try { + texSmallID = createTexture("res/ball_sm.png"); + texBigID = createTexture("res/ball.png"); + } catch (IOException e) { + e.printStackTrace(); + System.exit(-1); + } + texID = texBigID; + + // Setup rendering state + + glEnable(GL_BLEND); + glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + + glEnable(GL_ALPHA_TEST); + + glColorMask(colorMask, colorMask, colorMask, false); + glDepthMask(true); + glEnable(GL_DEPTH_TEST); + glDepthFunc(GL_LESS); + glClearDepth(1.0f); + + // Setup geometry + + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + + Util.checkGLError(); + } + + private static int createTexture(final String path) throws IOException { + final BufferedImage img = ImageIO.read(SpriteShootout2P.class.getClassLoader().getResource(path)); + + final int w = img.getWidth(); + final int h = img.getHeight(); + + final ByteBuffer buffer = readImage(img); + + final int texID = glGenTextures(); + + glBindTexture(GL_TEXTURE_2D, texID); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, buffer); + + return texID; + } + + private static ByteBuffer readImage(final BufferedImage img) throws IOException { + final Raster raster = img.getRaster(); + + final int bands = raster.getNumBands(); + + final int w = img.getWidth(); + final int h = img.getHeight(); + + final int size = w * h * bands; + + final byte[] pixels = new byte[size]; + raster.getDataElements(0, 0, w, h, pixels); + + final ByteBuffer pbuffer = BufferUtils.createByteBuffer(size); + + if ( bands == 4 ) { + for ( int i = 0; i < (w * h * 4); i += 4 ) { + // Pre-multiply alpha + final float a = unpackUByte01(pixels[i + 3]); + pbuffer.put(packUByte01(unpackUByte01(pixels[i + 2]) * a)); + pbuffer.put(packUByte01(unpackUByte01(pixels[i + 1]) * a)); + pbuffer.put(packUByte01(unpackUByte01(pixels[i + 0]) * a)); + pbuffer.put(pixels[i + 3]); + } + } else if ( bands == 3 ) { + for ( int i = 0; i < (w * h * 3); i += 3 ) { + pbuffer.put(pixels[i + 2]); + pbuffer.put(pixels[i + 1]); + pbuffer.put(pixels[i + 0]); + } + } else + pbuffer.put(pixels, 0, size); + + pbuffer.flip(); + + return pbuffer; + } + + private static float unpackUByte01(final byte x) { + return (x & 0xFF) / 255.0f; + } + + private static byte packUByte01(final float x) { + return (byte)(x * 255.0f); + } + + private void updateBalls(final int count) { + System.out.println("NUMBER OF BALLS: " + count); + renderer.updateBalls(ballCount); + } + + private void run() { + long startTime = System.currentTimeMillis() + 5000; + long fps = 0; + + long time = Sys.getTime(); + final int ticksPerUpdate = (int)(Sys.getTimerResolution() / ANIMATION_TICKS); + + renderer.render(false, true, 0); + + while ( run ) { + Display.processMessages(); + handleInput(); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + final long currTime = Sys.getTime(); + final int delta = (int)(currTime - time); + if ( smooth || delta >= ticksPerUpdate ) { + renderer.render(render, animate, delta); + time = currTime; + } else + renderer.render(render, false, 0); + + Display.update(false); + //Display.sync(60); + + if ( startTime > System.currentTimeMillis() ) { + fps++; + } else { + long timeUsed = 5000 + (startTime - System.currentTimeMillis()); + startTime = System.currentTimeMillis() + 5000; + System.out.println("FPS: " + (Math.round(fps / (timeUsed / 1000.0) * 10) / 10.0) + ", Balls: " + ballCount); + fps = 0; + } + } + } + + private void handleInput() { + if ( Display.isCloseRequested() ) + run = false; + + while ( Keyboard.next() ) { + if ( Keyboard.getEventKeyState() ) + continue; + + switch ( Keyboard.getEventKey() ) { + case Keyboard.KEY_1: + case Keyboard.KEY_2: + case Keyboard.KEY_3: + case Keyboard.KEY_4: + case Keyboard.KEY_5: + case Keyboard.KEY_6: + case Keyboard.KEY_7: + case Keyboard.KEY_8: + case Keyboard.KEY_9: + case Keyboard.KEY_0: + ballCount = 1 << (Keyboard.getEventKey() - Keyboard.KEY_1); + updateBalls(ballCount); + break; + case Keyboard.KEY_ADD: + case Keyboard.KEY_SUBTRACT: + int mult; + if ( Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) ) { + mult = 1000; + if ( Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL) ) + mult *= 5; + } else if ( Keyboard.isKeyDown(Keyboard.KEY_LMENU) || Keyboard.isKeyDown(Keyboard.KEY_RMENU) ) + mult = 100; + else if ( Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL) ) + mult = 10; + else + mult = 1; + if ( Keyboard.getEventKey() == Keyboard.KEY_SUBTRACT ) + mult = -mult; + ballCount += mult * 100; + if ( ballCount <= 0 ) + ballCount = 1; + updateBalls(ballCount); + break; + case Keyboard.KEY_ESCAPE: + run = false; + break; + case Keyboard.KEY_A: + animate = !animate; + System.out.println("Animation is now " + (animate ? "on" : "off") + "."); + break; + case Keyboard.KEY_C: + colorMask = !colorMask; + glColorMask(colorMask, colorMask, colorMask, false); + System.out.println("Color mask is now " + (colorMask ? "on" : "off") + "."); + // Disable alpha test when color mask is off, else we get no benefit. + if ( colorMask ) { + glEnable(GL_BLEND); + glEnable(GL_ALPHA_TEST); + } else { + glDisable(GL_BLEND); + glDisable(GL_ALPHA_TEST); + } + break; + case Keyboard.KEY_R: + render = !render; + System.out.println("Rendering is now " + (render ? "on" : "off") + "."); + break; + case Keyboard.KEY_S: + smooth = !smooth; + System.out.println("Smooth animation is now " + (smooth ? "on" : "off") + "."); + break; + case Keyboard.KEY_T: + if ( texID == texBigID ) { + texID = texSmallID; + ballSize = 16; + } else { + texID = texBigID; + ballSize = 42; + } + renderer.updateBallSize(); + glBindTexture(GL_TEXTURE_2D, texID); + System.out.println("Now using the " + (texID == texBigID ? "big" : "small") + " texture."); + break; + case Keyboard.KEY_V: + vsync = !vsync; + Display.setVSyncEnabled(vsync); + System.out.println("VSYNC is now " + (vsync ? "enabled" : "disabled") + "."); + break; + } + } + + while ( Mouse.next() ) ; + } + + private void destroy() { + Display.destroy(); + } + + private abstract class SpriteRenderer { + + protected int progID; + + protected void createPrograms(final int vshID) { + // Opaque pass + + final int fshID = glCreateShader(GL_FRAGMENT_SHADER); + glShaderSource(fshID, "uniform sampler2D COLOR_MAP;\n" + + "void main(void) {\n" + + " gl_FragColor = texture2D(COLOR_MAP, gl_PointCoord);\n" + + "}"); + glCompileShader(fshID); + if ( glGetShader(fshID, GL_COMPILE_STATUS) == GL_FALSE ) { + System.out.println(glGetShaderInfoLog(fshID, glGetShader(fshID, GL_INFO_LOG_LENGTH))); + throw new RuntimeException("Failed to compile fragment shader."); + } + + progID = glCreateProgram(); + glAttachShader(progID, vshID); + glAttachShader(progID, fshID); + glLinkProgram(progID); + if ( glGetProgram(progID, GL_LINK_STATUS) == GL_FALSE ) { + System.out.println(glGetProgramInfoLog(progID, glGetProgram(progID, GL_INFO_LOG_LENGTH))); + throw new RuntimeException("Failed to link shader program."); + } + + glUseProgram(progID); + glUniform1i(glGetUniformLocation(progID, "COLOR_MAP"), 0); + + updateBallSize(); + + glEnableClientState(GL_VERTEX_ARRAY); + } + + public void updateBallSize() { + glPointSize(ballSize); + } + + protected abstract void updateBalls(final int count); + + protected abstract void render(boolean render, boolean animate, int delta); + + } + + private class SpriteRendererTF extends SpriteRenderer { + + private int progIDTF; + private int ballSizeLoc; + private int deltaLoc; + + private int[] tfVBO = new int[2]; + private int currVBO; + + private int depthVBO; + private int depthLoc; + + SpriteRendererTF() { + System.out.println("Shootout Implementation: TF GPU animation & 2-pass rendering"); + + // Transform-feedback program + + int vshID = glCreateShader(GL_VERTEX_SHADER); + glShaderSource(vshID, "#version 130\n" + + "const float WIDTH = " + SCREEN_WIDTH + ";\n" + + "const float HEIGHT = " + SCREEN_HEIGHT + ";\n" + + "uniform float ballSize;\n" + // ballSize / 2 + "uniform float delta;\n" + + "void main(void) {\n" + + " vec4 anim = gl_Vertex;\n" + + " anim.xy = anim.xy + anim.zw * delta;\n" + + " vec2 animC = clamp(anim.xy, vec2(ballSize), vec2(WIDTH - ballSize, HEIGHT - ballSize));\n" + + " if ( anim.x != animC.x ) anim.z = -anim.z;\n" + + " if ( anim.y != animC.y ) anim.w = -anim.w;\n" + + " gl_Position = vec4(animC, anim.zw);\n" + + "}"); + glCompileShader(vshID); + if ( glGetShader(vshID, GL_COMPILE_STATUS) == GL_FALSE ) { + System.out.println(glGetShaderInfoLog(vshID, glGetShader(vshID, GL_INFO_LOG_LENGTH))); + throw new RuntimeException("Failed to compile vertex shader."); + } + + progIDTF = glCreateProgram(); + glAttachShader(progIDTF, vshID); + glTransformFeedbackVaryings(progIDTF, new CharSequence[] { "gl_Position" }, GL_SEPARATE_ATTRIBS); + glLinkProgram(progIDTF); + if ( glGetProgram(progIDTF, GL_LINK_STATUS) == GL_FALSE ) { + System.out.println(glGetProgramInfoLog(progIDTF, glGetProgram(progIDTF, GL_INFO_LOG_LENGTH))); + throw new RuntimeException("Failed to link shader program."); + } + + glUseProgram(progIDTF); + + ballSizeLoc = glGetUniformLocation(progIDTF, "ballSize"); + deltaLoc = glGetUniformLocation(progIDTF, "delta"); + + glUniform1f(ballSizeLoc, ballSize * 0.5f); + + // ----------------- + + vshID = glCreateShader(GL_VERTEX_SHADER); + glShaderSource(vshID, "#version 130\n" + + "in float depth;\n" + + "void main(void) {\n" + + " gl_Position = gl_ModelViewProjectionMatrix * vec4(gl_Vertex.xy, depth, gl_Vertex.w);\n" + + "}"); + glCompileShader(vshID); + if ( glGetShader(vshID, GL_COMPILE_STATUS) == GL_FALSE ) { + System.out.println(glGetShaderInfoLog(vshID, glGetShader(vshID, GL_INFO_LOG_LENGTH))); + throw new RuntimeException("Failed to compile vertex shader."); + } + + createPrograms(vshID); + + depthLoc = glGetAttribLocation(progID, "depth"); + + // ----------------- + } + + public void updateBallSize() { + glUseProgram(progIDTF); + glUniform1f(ballSizeLoc, ballSize * 0.5f); + + super.updateBallSize(); + } + + public void updateBalls(final int count) { + // Depth data + + final FloatBuffer depths = BufferUtils.createFloatBuffer(count * 2); + final float depthStep = 1.9f / count; + float depth = Math.nextAfter(1.0f, Float.MIN_VALUE); + // Front-to-back + for ( int i = 0; i < count; i++ ) { + depths.put(depth); + depth -= depthStep; + } + // Back-to-front + for ( int i = 0; i < count; i++ ) + depths.put(depths.get(count - 1 - i)); + depths.flip(); + + if ( depthVBO != 0 ) + glDeleteBuffers(depthVBO); + + depthVBO = glGenBuffers(); + glBindBuffer(GL_ARRAY_BUFFER, depthVBO); + glBufferData(GL_ARRAY_BUFFER, depths, GL_STATIC_DRAW); + + glEnableVertexAttribArray(depthLoc); + glVertexAttribPointer(depthLoc, 1, GL_FLOAT, false, 0, 0); + + // Animation data + + final FloatBuffer transform = BufferUtils.createFloatBuffer(count * 2 * 4); + // Front-to-back + final Random random = new Random(); + for ( int i = 0; i < count; i++ ) { + transform.put((int)(random.nextFloat() * (SCREEN_WIDTH - ballSize) + ballSize * 0.5f)); + transform.put((int)(random.nextFloat() * (SCREEN_HEIGHT - ballSize) + ballSize * 0.5f)); + transform.put(random.nextFloat() * 0.4f - 0.2f); + transform.put(random.nextFloat() * 0.4f - 0.2f); + } + // Back-to-front + for ( int i = 0; i < count; i++ ) { + final int offset = (count - 1 - i) * 4; + transform.put(transform.get(offset + 0)); + transform.put(transform.get(offset + 1)); + transform.put(transform.get(offset + 2)); + transform.put(transform.get(offset + 3)); + } + transform.flip(); + + if ( tfVBO[0] != 0 ) { + for ( int i = 0; i < tfVBO.length; i++ ) + glDeleteBuffers(tfVBO[i]); + } + + 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); + } + + glBindBuffer(GL_ARRAY_BUFFER, tfVBO[0]); + glVertexPointer(2, GL_FLOAT, (4 * 4), 0); + } + + public void render(final boolean render, final boolean animate, final int delta) { + if ( animate ) { + glDisableVertexAttribArray(depthLoc); + + final int vbo = currVBO; + currVBO = 1 - currVBO; + + glUseProgram(progIDTF); + glUniform1f(deltaLoc, delta); + + glBindBuffer(GL_ARRAY_BUFFER, tfVBO[vbo]); + glVertexPointer(4, GL_FLOAT, 0, 0); + + glEnable(GL_RASTERIZER_DISCARD); + if ( GLContext.getCapabilities().OpenGL30 ) { + glBindBufferBase(GL_TRANSFORM_FEEDBACK_BUFFER, 0, tfVBO[1 - vbo]); + + glBeginTransformFeedback(GL_POINTS); + glDrawArrays(GL_POINTS, 0, ballCount * 2); + glEndTransformFeedback(); + } else { + glBindBufferBaseEXT(GL_TRANSFORM_FEEDBACK_BUFFER_EXT, 0, tfVBO[1 - vbo]); + + glBeginTransformFeedbackEXT(GL_POINTS); + glDrawArrays(GL_POINTS, 0, ballCount * 2); + glEndTransformFeedbackEXT(); + } + glDisable(GL_RASTERIZER_DISCARD); + + glUseProgram(progID); + glVertexPointer(2, GL_FLOAT, (4 * 4), 0); + + glEnableVertexAttribArray(depthLoc); + } + + if ( render ) { + // Render front-to-back opaque pass + glAlphaFunc(GL_EQUAL, 1.0f); + glDisable(GL_BLEND); + glDrawArrays(GL_POINTS, 0, ballCount); + glEnable(GL_BLEND); + + // Render back-to-front transparent pass + glAlphaFunc(GL_GREATER, 0.0f); // Fragments with alpha == 1.0 are early-depth-rejected. + glDepthMask(false); + glDrawArrays(GL_POINTS, ballCount, ballCount); + glDepthMask(true); + } + } + + } + +} \ No newline at end of file Added: trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/SpriteShootoutCL.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/SpriteShootoutCL.java (rev 0) +++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/sprites/SpriteShootoutCL.java 2011-04-07 21:36:19 UTC (rev 3513) @@ -0,0 +1,559 @@ +package org.lwjgl.test.opengl.sprites; + +import org.lwjgl.BufferUtils; +import org.lwjgl.LWJGLException; +import org.lwjgl.PointerBuffer; +import org.lwjgl.Sys; +import org.lwjgl.input.Keyboard; +import org.lwjgl.input.Mouse; +import org.lwjgl.opencl.*; +import org.lwjgl.opencl.api.Filter; +import org.lwjgl.opengl.Display; +import org.lwjgl.opengl.DisplayMode; +import org.lwjgl.opengl.GLContext; +import org.lwjgl.opengl.Util; + +import java.awt.image.BufferedImage; +import java.awt.image.Raster; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; +import java.util.List; +import java.util.Random; +import javax.imageio.ImageIO; + +import static org.lwjgl.opencl.CL10.*; +import static org.lwjgl.opencl.CL10GL.*; +import static org.lwjgl.opengl.GL11.*; +import static org.lwjgl.opengl.GL12.*; +import static org.lwjgl.opengl.GL15.*; +import static org.lwjgl.opengl.GL20.*; + +/** + * Sprite rendering demo. In this version OpenCL is used for the animation + * computations. CL_KHR_gl_sharing is required for sharing the animation + * data with OpenGL for rendering. + * + * @author Spasi + * @since 18/3/2011 + */ +public final class SpriteShootoutCL { + + private static final int SCREEN_WIDTH = 800; + private static final int SCREEN_HEIGHT = 600; + + private static final int ANIMATION_TICKS = 60; + + private boolean run = true; + private boolean render = true; + private boolean colorMask = true; + private boolean animate = true; + private boolean smooth; + private boolean vsync; + + private int ballSize = 42; + private int ballCount = 100 * 1000; + + private SpriteRenderer renderer; + + // OpenGL stuff + private int texID; + private int texBigID; + private int texSmallID; + + // OpenCL stuff + + private IntBuffer errorCode = BufferUtils.createIntBuffer(1); + + private CLDevice clDevice; + private CLContext clContext; + private CLCommandQueue queue; + private CLProgram program; + private CLKernel kernel; + private CLMem clTransform; + + private PointerBuffer kernelGlobalWorkSize; + + private SpriteShootoutCL() { + } + + public static void main(String[] args) { + try { + new SpriteShootoutCL().start(); + } catch (LWJGLException e) { + e.printStackTrace(); + } + } + + private void start() throws LWJGLException { + try { + initGL(); + initCL(); + + renderer = new SpriteRendererDefault(); + + updateBalls(ballCount); + run(); + } catch (Throwable t) { + t.printStackTrace(); + } finally { + destroy(); + } + } + + private void initCL() throws LWJGLException { + CL.create(); + + final List<CLPlatform> platforms = CLPlatform.getPlatforms(); + if ( platforms == null ) + throw new RuntimeException("No OpenCL platforms found."); + + final CLPlatform platform = platforms.get(0); + + final PointerBuffer ctxProps = BufferUtils.createPointerBuffer(3); + ctxProps.put(CL_CONTEXT_PLATFORM).put(platform.getPointer()).put(0).flip(); + + // Find devices with GL sharing support + final Filter<CLDevice> glSharingFilter = new Filter<CLDevice>() { + public boolean accept(final CLDevice device) { + final CLDeviceCapabilities caps = CLCapabilities.getDeviceCapabilities(device); + return caps.CL_KHR_gl_sharing; + } + }; + final List<CLDevice> devices = platform.getDevices(CL_DEVICE_TYPE_GPU, glSharingFilter); + + if ( devices == null ) + throw new RuntimeException("No OpenCL GPU device found."); + + clDevice = devices.get(0); + // Make sure we use only 1 device + devices.clear(); + devices.add(clDevice); + + clContext = CLContext.create(platform, devices, new CLContextCallback() { + protected void handleMessage(final String errinfo, final ByteBuffer private_info) { + System.out.println("[CONTEXT MESSAGE] " + errinfo); + } + }, Display.getDrawable(), errorCode); + checkCLError(errorCode); + + queue = clCreateCommandQueue(clContext, clDevice, 0, errorCode); + checkCLError(errorCode); + } + + private void initGL() throws LWJGLException { + Display.setLocation((Display.getDisplayMode().getWidth() - SCREEN_WIDTH) / 2, + (Display.getDisplayMode().getHeight() - SCREEN_HEIGHT) / 2); + Display.setDisplayMode(new DisplayMode(SCREEN_WIDTH, SCREEN_HEIGHT)); + Display.setTitle("Sprite Shootout - CL"); + Display.create(); + + if ( !GLContext.getCapabilities().OpenGL20 ) + throw new RuntimeException("OpenGL 2.0 is required for this demo."); + + // Setup viewport + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, SCREEN_WIDTH, 0, SCREEN_HEIGHT, -1.0, 1.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); + + glClearColor(1.0f, 1.0f, 1.0f, 0.0f); + + // Create textures + + try { + texSmallID = createTexture("res/ball_sm.png"); + texBigID = createTexture("res/ball.png"); + } catch (IOException e) { + e.printStackTrace(); + System.exit(-1); + } + texID = texBigID; + + // Setup rendering state + + glEnable(GL_BLEND); + glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + + glEnable(GL_ALPHA_TEST); + glAlphaFunc(GL_GREATER, 0.0f); + + glColorMask(colorMask, colorMask, colorMask, false); + glDepthMask(false); + glDisable(GL_DEPTH_TEST); + + // Setup geometry + + Util.checkGLError(); + } + + private static int createTexture(final String path) throws IOException { + final BufferedImage img = ImageIO.read(SpriteShootoutCL.class.getClassLoader().getResource(path)); + + final int w = img.getWidth(); + final int h = img.getHeight(); + + final ByteBuffer buffer = readImage(img); + + final int texID = glGenTextures(); + + glBindTexture(GL_TEXTURE_2D, texID); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, buffer); + + return texID; + } + + private static ByteBuffer readImage(final BufferedImage img) throws IOException { + final Raster raster = img.getRaster(); + + final int bands = raster.getNumBands(); + + final int w = img.getWidth(); + final int h = img.getHeight(); + + final int size = w * h * bands; + + final byte[] pixels = new byte[size]; + raster.getDataElements(0, 0, w, h, pixels); + + final ByteBuffer pbuffer = BufferUtils.createByteBuffer(size); + + if ( bands == 4 ) { + for ( int i = 0; i < (w * h * 4); i += 4 ) { + // Pre-multiply alpha + final float a = unpackUByte01(pixels[i + 3]); + pbuffer.put(packUByte01(unpackUByte01(pixels[i + 2]) * a)); + pbuffer.put(packUByte01(unpackUByte01(pixels[i + 1]) * a)); + pbuffer.put(packUByte01(unpackUByte01(pixels[i + 0]) * a)); + pbuffer.put(pixels[i + 3]); + } + } else if ( bands == 3 ) { + for ( int i = 0; i < (w * h * 3); i += 3 ) { + pbuffer.put(pixels[i + 2]); + pbuffer.put(pixels[i + 1]); + pbuffer.put(pixels[i + 0]); + } + } else + pbuffer.put(pixels, 0, size); + + pbuffer.flip(); + + return pbuffer; + } + + private static float unpackUByte01(final byte x) { + return (x & 0xFF) / 255.0f; + } + + private static byte packUByte01(final float x) { + return (byte)(x * 255.0f); + } + + private void updateBalls(final int count) { + System.out.println("NUMBER OF BALLS: " + count); + renderer.updateBalls(ballCount); + } + + private void run() { + long startTime = System.currentTimeMillis() + 5000; + long fps = 0; + + long time = Sys.getTime(); + final int ticksPerUpdate = (int)(Sys.getTimerResolution() / ANIMATION_TICKS); + + renderer.render(false, true, 0); + + while ( run ) { + Display.processMessages(); + handleInput(); + + glClear(GL_COLOR_BUFFER_BIT); + + final long currTime = Sys.getTime(); + final int delta = (int)(currTime - time); + if ( smooth || delta >= ticksPerUpdate ) { + renderer.render(render, animate, delta); + time = currTime; + } else + renderer.render(render, false, 0); + + Display.update(false); + + if ( startTime > System.currentTimeMillis() ) { + fps++; + } else { + long timeUsed = 5000 + (startTime - System.currentTimeMillis()); + startTime = System.currentTimeMillis() + 5000; + System.out.println("FPS: " + (Math.round(fps / (timeUsed / 1000.0) * 10) / 10.0) + ", Balls: " + ballCount); + fps = 0; + } + } + } + + private void handleInput() { + if ( Display.isCloseRequested() ) + run = false; + + while ( Keyboard.next() ) { + if ( Keyboard.getEventKeyState() ) + continue; + + switch ( Keyboard.getEventKey() ) { + case Keyboard.KEY_1: + case Keyboard.KEY_2: + case Keyboard.KEY_3: + case Keyboard.KEY_4: + case Keyboard.KEY_5: + case Keyboard.KEY_6: + case Keyboard.KEY_7: + case Keyboard.KEY_8: + case Keyboard.KEY_9: + case Keyboard.KEY_0: + ballCount = 1 << (Keyboard.getEventKey() - Keyboard.KEY_1); + updateBalls(ballCount); + break; + case Keyboard.KEY_ADD: + case Keyboard.KEY_SUBTRACT: + int mult; + if ( Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) ) + mult = 1000; + else if ( Keyboard.isKeyDown(Keyboard.KEY_LMENU) || Keyboard.isKeyDown(Keyboard.KEY_RMENU) ) + mult = 100; + else if ( Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL) ) + mult = 10; + else + mult = 1; + if ( Keyboard.getEventKey() == Keyboard.KEY_SUBTRACT ) + mult = -mult; + ballCount += mult * 100; + if ( ballCount <= 0 ) + ballCount = 1; + updateBalls(ballCount); + break; + case Keyboard.KEY_ESCAPE: + run = false; + break; + case Keyboard.KEY_A: + animate = !animate; + System.out.println("Animation is now " + (animate ? "on" : "off") + "."); + break; + case Keyboard.KEY_C: + colorMask = !colorMask; + glColorMask(colorMask, colorMask, colorMask, false); + System.out.println("Color mask is now " + (colorMask ? "on" : "off") + "."); + // Disable alpha test when color mask is off, else we get no benefit. + if ( colorMask ) { + glEnable(GL_BLEND); + glEnable(GL_ALPHA_TEST); + } else { + glDisable(GL_BLEND); + glDisable(GL_ALPHA_TEST); + } + break; + case Keyboard.KEY_R: + render = !render; + System.out.println("Rendering is now " + (render ? "on" : "off") + "."); + break; + case Keyboard.KEY_S: + smooth = !smooth; + System.out.println("Smooth animation is now " + (smooth ? "on" : "off") + "."); + break; + case Keyboard.KEY_T: + if ( texID == texBigID ) { + texID = texSmallID; + ballSize = 16; + } else { + texID = texBigID; + ballSize = 42; + } + renderer.updateBallSize(); + glBindTexture(GL_TEXTURE_2D, texID); + System.out.println("Now using the " + (texID == texBigID ? "big" : "small") + " texture."); + break; + case Keyboard.KEY_V: + vsync = !vsync; + Display.setVSyncEnabled(vsync); + System.out.println("VSYNC is now " + (vsync ? "enabled" : "disabled") + "."); + break; + } + } + + while ( Mouse.next() ) ; + } + + private static void checkCLError(IntBuffer buffer) { + org.lwjgl.opencl.Util.checkCLError(buffer.get(0)); + } + + private void destroy() { + clReleaseContext(clContext); + Display.destroy(); + System.exit(0); + } + + private abstract class SpriteRenderer { + + protected int progID; + protected int animVBO; + + protected void createKernel(final String source) { + program = clCreateProgramWithSource(clContext, source, errorCode); + checkCLError(errorCode); + final int build = clBuildProgram(program, clDevice, "", null); + if ( build != CL_SUCCESS ) { + System.out.println("BUILD LOG: " + program.getBuildInfoString(clDevice, CL_PROGRAM_BUILD_LOG)); + throw new RuntimeException("Failed to build CL program, status: " + build); + } + + kernel = clCreateKernel(program, "animate", errorCode); + checkCLError(errorCode); + + kernelGlobalWorkSize = BufferUtils.createPointerBuffer(1); + kernelGlobalWorkSize.put(0, ballCount); + + kernel.setArg(0, SCREEN_WIDTH); + kernel.setArg(1, SCREEN_HEIGHT); + kernel.setArg(2, ballSize * 0.5f); + } + + protected void createProgram(final int vshID) { + final int fshID = glCreateShader(GL_FRAGMENT_SHADER); + glShaderSource(fshID, "#version 110\n" + + "uniform sampler2D COLOR_MAP;" + + "void main(void) {\n" + + " gl_FragColor = texture2D(COLOR_MAP, gl_PointCoord);\n" + + "}"); + glCompileShader(fshID); + if ( glGetShader(fshID, GL_COMPILE_STATUS) == GL_FALSE ) { + System.out.println(glGetShaderInfoLog(fshID, glGetShader(fshID, GL_INFO_LOG_LENGTH))); + throw new RuntimeException("Failed to compile fragment shader."); + } + + progID = glCreateProgram(); + glAttachShader(progID, vshID); + glAttachShader(progID, fshID); + glLinkProgram(progID); + if ( glGetProgram(progID, GL_LINK_STATUS) == GL_FALSE ) { + System.out.println(glGetProgramInfoLog(progID, glGetProgram(progID, GL_INFO_LOG_LENGTH))); + throw new RuntimeException("Failed to link shader program."); + } + + glUseProgram(progID); + glUniform1i(glGetUniformLocation(progID, "COLOR_MAP"), 0); + + glEnableClientState(GL_VERTEX_ARRAY); + } + + public void updateBallSize() { + glPointSize(ballSize); + kernel.setArg(2, ballSize * 0.5f); + } + + public void updateBalls(final int count) { + kernelGlobalWorkSize.put(0, ballCount); + + final FloatBuffer transform = BufferUtils.createFloatBuffer(count * 4); + + final Random random = new Random(); + for ( int i = 0; i < count; i++ ) { + transform.put((int)(random.nextFloat() * (SCREEN_WIDTH - ballSize)) + ballSize * 0.5f); + transform.put((int)(random.nextFloat() * (SCREEN_HEIGHT - ballSize)) + ballSize * 0.5f); + transform.put(random.nextFloat() * 0.4f - 0.2f); + transform.put(random.nextFloat() * 0.4f - 0.2f); + } + transform.flip(); + + if ( animVBO != 0 ) { + clReleaseMemObject(clTransform); + glDeleteBuffers(animVBO); + } + + animVBO = glGenBuffers(); + + glBindBuffer(GL_ARRAY_BUFFER, animVBO); + glBufferData(GL_ARRAY_BUFFER, transform, GL_STATIC_DRAW); + glVertexPointer(2, GL_FLOAT, (4 * 4), 0); + + clTransform = clCreateFromGLBuffer(clContext, CL_MEM_READ_WRITE, animVBO, errorCode); + checkCLError(errorCode); + kernel.setArg(4, clTransform); + } + + protected abstract void render(boolean render, boolean animate, int delta); + + } + + private class SpriteRendererDefault extends SpriteRenderer { + + SpriteRendererDefault() { + System.out.println("Shootout Implementation: OpenCL GPU animation"); + + final int vshID = glCreateShader(GL_VERTEX_SHADER); + glShaderSource(vshID, "#version 150\n" + + "void main(void) {\n" + + " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" + + "}"); + glCompileShader(vshID); + if ( glGetShader(vshID, GL_COMPILE_STATUS) == GL_FALSE ) { + System.out.println(glGetShaderInfoLog(vshID, glGetShader(vshID, GL_INFO_LOG_LENGTH))); + throw new RuntimeException("Failed to compile vertex shader."); + } + + createProgram(vshID); + + Util.checkGLError(); + + createKernel("kernel void animate(\n" + + " const int WIDTH,\n" + + " const int HEIGHT,\n" + + " const float radius,\n" + + " const int delta,\n" + + " global float4 *balls\n" + + ") {\n" + + " unsigned int b = get_global_id(0);\n" + + "\n" + + " float4 anim = balls[b];\n" + + " anim.xy = anim.xy + anim.zw * delta;\n" + + " float2 animC = clamp(anim.xy, (float2)radius, (float2)(WIDTH - radius, HEIGHT - radius));\n" + + " if ( anim.x != animC.x ) anim.z = -anim.z;\n" + + " if ( anim.y != animC.y ) anim.w = -anim.w;\n" + + "\n" + + " balls[b] = (float4)(animC, anim.zw);\n" + + "}"); + + updateBallSize(); + } + + publ... [truncated message content] |
From: <sp...@us...> - 2011-05-11 00:12:59
|
Revision: 3528 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3528&view=rev Author: spasi Date: 2011-05-11 00:12:52 +0000 (Wed, 11 May 2011) Log Message: ----------- Added alignment checks to PointerBuffer constructor. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/BufferUtils.java trunk/LWJGL/src/java/org/lwjgl/PointerBuffer.java trunk/LWJGL/src/native/common/org_lwjgl_BufferUtils.c Modified: trunk/LWJGL/src/java/org/lwjgl/BufferUtils.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/BufferUtils.java 2011-05-10 20:22:08 UTC (rev 3527) +++ trunk/LWJGL/src/java/org/lwjgl/BufferUtils.java 2011-05-11 00:12:52 UTC (rev 3528) @@ -192,4 +192,14 @@ /** Fill buffer with zeros from position to remaining */ private static native void zeroBuffer0(Buffer b, long off, long size); + + /** + * Returns the memory address of the specified buffer. + * + * @param buffer the buffer + * + * @return the memory address + */ + static native long getBufferAddress(Buffer buffer); + } Modified: trunk/LWJGL/src/java/org/lwjgl/PointerBuffer.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/PointerBuffer.java 2011-05-10 20:22:08 UTC (rev 3527) +++ trunk/LWJGL/src/java/org/lwjgl/PointerBuffer.java 2011-05-11 00:12:52 UTC (rev 3528) @@ -59,8 +59,8 @@ protected final ByteBuffer pointers; - protected final Buffer view; - protected final IntBuffer view32; + protected final Buffer view; + protected final IntBuffer view32; protected final LongBuffer view64; /** @@ -83,6 +83,10 @@ if ( !source.isDirect() ) throw new IllegalArgumentException("ByteBuffer is not direct"); + final int alignment = is64Bit ? 8 : 4; + if ( (BufferUtils.getBufferAddress(source) + source.position()) % alignment != 0 || source.remaining() % alignment != 0 ) + throw new IllegalArgumentException("The source buffer is not aligned to " + alignment + " bytes."); + pointers = source.slice().order(source.order()); if ( is64Bit ) { Modified: trunk/LWJGL/src/native/common/org_lwjgl_BufferUtils.c =================================================================== --- trunk/LWJGL/src/native/common/org_lwjgl_BufferUtils.c 2011-05-10 20:22:08 UTC (rev 3527) +++ trunk/LWJGL/src/native/common/org_lwjgl_BufferUtils.c 2011-05-11 00:12:52 UTC (rev 3528) @@ -2,4 +2,8 @@ JNIEXPORT void JNICALL Java_org_lwjgl_BufferUtils_zeroBuffer0(JNIEnv *env, jclass clazz, jobject buffer, jlong offset, jlong size) { memset((char*)(*env)->GetDirectBufferAddress(env, buffer) + (size_t)offset, 0, (size_t)size); +} + +JNIEXPORT jlong JNICALL Java_org_lwjgl_BufferUtils_getBufferAddress(JNIEnv *env, jclass clazz, jobject buffer) { + return (uintptr_t)(*env)->GetDirectBufferAddress(env, buffer); } \ 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-05-11 14:22:05
|
Revision: 3530 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3530&view=rev Author: spasi Date: 2011-05-11 14:21:59 +0000 (Wed, 11 May 2011) Log Message: ----------- Added missing include. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/PointerBuffer.java trunk/LWJGL/src/native/common/org_lwjgl_BufferUtils.c Modified: trunk/LWJGL/src/java/org/lwjgl/PointerBuffer.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/PointerBuffer.java 2011-05-11 09:50:50 UTC (rev 3529) +++ trunk/LWJGL/src/java/org/lwjgl/PointerBuffer.java 2011-05-11 14:21:59 UTC (rev 3530) @@ -80,13 +80,9 @@ * @param source the source buffer */ public PointerBuffer(final ByteBuffer source) { - if ( !source.isDirect() ) - throw new IllegalArgumentException("ByteBuffer is not direct"); + if ( LWJGLUtil.CHECKS ) + checkSource(source); - final int alignment = is64Bit ? 8 : 4; - if ( (BufferUtils.getBufferAddress(source) + source.position()) % alignment != 0 || source.remaining() % alignment != 0 ) - throw new IllegalArgumentException("The source buffer is not aligned to " + alignment + " bytes."); - pointers = source.slice().order(source.order()); if ( is64Bit ) { @@ -98,6 +94,15 @@ } } + private static void checkSource(final ByteBuffer source) { + if ( !source.isDirect() ) + 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 ) + throw new IllegalArgumentException("The source buffer is not aligned to " + alignment + " bytes."); + } + /** * Returns the ByteBuffer that backs this PointerBuffer. * Modified: trunk/LWJGL/src/native/common/org_lwjgl_BufferUtils.c =================================================================== --- trunk/LWJGL/src/native/common/org_lwjgl_BufferUtils.c 2011-05-11 09:50:50 UTC (rev 3529) +++ trunk/LWJGL/src/native/common/org_lwjgl_BufferUtils.c 2011-05-11 14:21:59 UTC (rev 3530) @@ -1,4 +1,5 @@ #include "org_lwjgl_BufferUtils.h" +#include "common_tools.h" JNIEXPORT void JNICALL Java_org_lwjgl_BufferUtils_zeroBuffer0(JNIEnv *env, jclass clazz, jobject buffer, jlong offset, jlong size) { memset((char*)(*env)->GetDirectBufferAddress(env, buffer) + (size_t)offset, 0, (size_t)size); @@ -6,4 +7,4 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_BufferUtils_getBufferAddress(JNIEnv *env, jclass clazz, jobject buffer) { return (intptr_t)(*env)->GetDirectBufferAddress(env, buffer); -} \ 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-02 20:50:33
|
Revision: 3555 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3555&view=rev Author: kappa1 Date: 2011-07-02 20:50:27 +0000 (Sat, 02 Jul 2011) Log Message: ----------- LinuxDisplay - fix remaining issues with focus handling when running in xembed mode. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2011-06-26 11:50:23 UTC (rev 3554) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/LinuxDisplay.java 2011-07-02 20:50:27 UTC (rev 3555) @@ -136,11 +136,14 @@ private boolean close_requested; private long current_cursor; private long blank_cursor; + private boolean mouseInside = true; + private Canvas parent; private long parent_window; private boolean xembedded; - private boolean parent_focus; - private boolean mouseInside = true; + private long parent_proxy_focus_window; + private boolean parent_focused; + private long last_window_focus = 0; private LinuxKeyboard keyboard; private LinuxMouse mouse; @@ -148,12 +151,12 @@ private final FocusListener focus_listener = new FocusListener() { public void focusGained(FocusEvent e) { synchronized (GlobalLock.lock) { - focused = true; + parent_focused = true; } } public void focusLost(FocusEvent e) { synchronized (GlobalLock.lock) { - focused = false; + parent_focused = false; } } }; @@ -460,9 +463,7 @@ if (parent != null) { parent.addFocusListener(focus_listener); if (parent.isFocusOwner()) { - nGrabKeyboard(getDisplay(), current_window); - focused = true; - input_released = false; + parent_focused = true; } } } finally { @@ -480,9 +481,12 @@ private static native long getRootWindow(long display, int screen); private static native boolean hasProperty(long display, long window, long property); private static native long getParentWindow(long display, long window) throws LWJGLException; + private static native int getChildCount(long display, long window) throws LWJGLException; private static native void mapRaised(long display, long window); private static native void reparentWindow(long display, long window, long parent, int x, int y); - + private static native long nGetInputFocus(long display) throws LWJGLException; + private static native void nSetInputFocus(long display, long window, long time); + private static boolean isAncestorXEmbedded(long window) throws LWJGLException { long xembed_atom = internAtom("_XEMBED_INFO", true); if (xembed_atom != None) { @@ -743,8 +747,6 @@ return peer_info; } - static native void setInputFocus(long display, long window, long time); - private void relayEventToParent(LinuxEvent event_buffer, int event_mask) { tmp_event_buffer.copyFrom(event_buffer); tmp_event_buffer.setWindow(parent_window); @@ -900,22 +902,97 @@ unlockAWT(); } } - + private void checkInput() { if (parent == null) return; - if (focused != keyboard_grabbed) { - if (focused) { - grabKeyboard(); - input_released = false; + if (xembedded) { + long current_focus_window = 0; + + try { + current_focus_window = nGetInputFocus(getDisplay()); + } catch (LWJGLException e) { + return; // fail silently as it can fail whilst splitting browser tabs } - else { - ungrabKeyboard(); - input_released = true; + + if (last_window_focus != current_focus_window || parent_focused != focused) { + if (isParentWindowActive(current_focus_window)) { + if (parent_focused) { + nSetInputFocus(getDisplay(), current_window, CurrentTime); + last_window_focus = current_window; + focused = true; + } + else { + // return focus to the parent proxy focus window + nSetInputFocus(getDisplay(), parent_proxy_focus_window, CurrentTime); + last_window_focus = parent_proxy_focus_window; + focused = false; + } + } + else { + last_window_focus = current_focus_window; + focused = false; + } } } + else { + if (parent_focused != keyboard_grabbed) { + if (parent_focused) { + grabKeyboard(); + input_released = false; + focused = true; + } + else { + ungrabKeyboard(); + input_released = true; + focused = false; + } + } + } } + /** + * This method will check if the parent window is active when running + * in xembed mode. Every xembed embedder window has a focus proxy + * window that recieves all the input. This method will test whether + * the provided window handle is the focus proxy, if so it will get its + * parent window and then test whether this is indeed the window that + * belongs to our current_window. If so then parent window is active. + * + * @param window - the window handle to test + */ + private boolean isParentWindowActive(long window) { + try { + // parent window already active as window is current_window + if (window == current_window) return true; + + // xembed focus proxy will have no children + if (getChildCount(getDisplay(), window) != 0) return false; + + // get parent, will be xembed embedder window and ancestor of current_window + long parent_window = getParentWindow(getDisplay(), window); + + // parent must not be None + if (parent_window == None) return false; + + // scroll current_window's ancestors to find parent_window + long w = current_window; + + while (w != None) { + w = getParentWindow(getDisplay(), w); + if (w == parent_window) { + parent_proxy_focus_window = window; // save focus proxy window + return true; + } + } + } catch (LWJGLException e) { + LWJGLUtil.log("Failed to detect if parent window is active: " + e.getMessage()); + return true; // on failure assume still active + } + + return false; // failed to find an active parent window + } + private void setFocused(boolean got_focus, int focus_detail) { if (focused == got_focus || focus_detail == NotifyDetailNone || focus_detail == NotifyPointer || focus_detail == NotifyPointerRoot || parent != null) return; @@ -928,8 +1005,6 @@ releaseInput(); } } - - static native long nGetInputFocus(long display); private void releaseInput() { if (isLegacyFullscreen() || input_released) Modified: trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c =================================================================== --- trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c 2011-06-26 11:50:23 UTC (rev 3554) +++ trunk/LWJGL/src/native/linux/org_lwjgl_opengl_Display.c 2011-07-02 20:50:27 UTC (rev 3555) @@ -380,6 +380,22 @@ return parent; } +JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_LinuxDisplay_getChildCount(JNIEnv *env, jclass unused, jlong display, jlong window_ptr) { + Display *disp = (Display *)(intptr_t)display; + Window window = (Window)window_ptr; + Window root, parent; + Window *children; + unsigned int nchildren; + if (XQueryTree(disp, window, &root, &parent, &children, &nchildren) == 0) { + throwException(env, "XQueryTree failed"); + return None; + } + if (children != NULL) + XFree(children); + + return nchildren; +} + JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_LinuxDisplay_hasProperty(JNIEnv *env, jclass unusued, jlong display, jlong window_ptr, jlong property_ptr) { Display *disp = (Display *)(intptr_t)display; Window window = (Window)window_ptr; @@ -399,7 +415,15 @@ return result; } -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_setInputFocus(JNIEnv *env, jclass clazz, jlong display, jlong window_ptr, jlong time) { +JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetInputFocus(JNIEnv *env, jclass unused, jlong display_ptr) { + Display *disp = (Display *)(intptr_t)display_ptr; + int revert_mode; + Window win; + XGetInputFocus(disp, &win, &revert_mode); + return win; +} + +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nSetInputFocus(JNIEnv *env, jclass clazz, jlong display, jlong window_ptr, jlong time) { Display *disp = (Display *)(intptr_t)display; Window window = (Window)window_ptr; XSetInputFocus(disp, window, RevertToParent, time); @@ -574,14 +598,6 @@ return cursor; } -JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nGetInputFocus(JNIEnv *env, jclass unused, jlong display_ptr) { - Display *disp = (Display *)(intptr_t)display_ptr; - int revert_mode; - Window win; - XGetInputFocus(disp, &win, &revert_mode); - return win; -} - JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxDisplay_nIconifyWindow(JNIEnv *env, jclass unused, jlong display_ptr, jlong window_ptr, jint screen) { Display *disp = (Display *)(intptr_t)display_ptr; Window win = (Window)window_ptr; 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-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 22:26:54
|
Revision: 3593 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3593&view=rev Author: spasi Date: 2011-07-16 22:26:46 +0000 (Sat, 16 Jul 2011) Log Message: ----------- Converted GL APIUtil to a per ContextCapabilities instance. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/APIUtil.java trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java trunk/LWJGL/src/java/org/lwjgl/util/generator/TypeMap.java trunk/LWJGL/src/java/org/lwjgl/util/generator/Utils.java trunk/LWJGL/src/java/org/lwjgl/util/generator/openal/ALTypeMap.java trunk/LWJGL/src/java/org/lwjgl/util/generator/opencl/CLTypeMap.java trunk/LWJGL/src/java/org/lwjgl/util/generator/opengl/GLCapabilitiesGenerator.java trunk/LWJGL/src/java/org/lwjgl/util/generator/opengl/GLESTypeMap.java trunk/LWJGL/src/java/org/lwjgl/util/generator/opengl/GLTypeMap.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/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/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 Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/APIUtil.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/APIUtil.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/APIUtil.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -1,5 +1,5 @@ /* - * Copyright (c) 2002-2008 LWJGL Project + * Copyright (c) 2002-2011 LWJGL Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -37,35 +37,33 @@ import java.nio.*; -/** @author spasi */ +/** + * Utility class for OpenGL API calls. Instances of APIUtil are created in ContextCapabilities, + * so we have an instance per OpenGL context. + * + * @author spasi + */ 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; - private static final ThreadLocal<char[]> arrayTL = new ThreadLocal<char[]>() { - protected char[] initialValue() { return new char[INITIAL_BUFFER_SIZE]; } - }; + private char[] arrayTL; + private ByteBuffer bufferTL; + private IntBuffer lengthsTL; + private final Buffers buffersTL; - private static final ThreadLocal<ByteBuffer> bufferTL = new ThreadLocal<ByteBuffer>() { - protected ByteBuffer initialValue() { return BufferUtils.createByteBuffer(INITIAL_BUFFER_SIZE); } - }; - - private static final ThreadLocal<IntBuffer> lengthsTL = new ThreadLocal<IntBuffer>() { - protected IntBuffer initialValue() { return BufferUtils.createIntBuffer(INITIAL_LENGTHS_SIZE); } - }; - - private static final ThreadLocal<Buffers> buffersTL = new ThreadLocal<Buffers>() { - protected Buffers initialValue() { return new Buffers(); } - }; - - private APIUtil() { + APIUtil() { + arrayTL = new char[INITIAL_BUFFER_SIZE]; + bufferTL = BufferUtils.createByteBuffer(INITIAL_BUFFER_SIZE); + lengthsTL = BufferUtils.createIntBuffer(INITIAL_LENGTHS_SIZE); + buffersTL = new Buffers(); } - private static char[] getArray(final int size) { - char[] array = arrayTL.get(); + private static char[] getArray(final ContextCapabilities caps, final int size) { + char[] array = caps.util.arrayTL; if ( array.length < size ) { int sizeNew = array.length << 1; @@ -73,14 +71,14 @@ sizeNew <<= 1; array = new char[size]; - arrayTL.set(array); + caps.util.arrayTL = array; } return array; } - static ByteBuffer getBufferByte(final int size) { - ByteBuffer buffer = bufferTL.get(); + static ByteBuffer getBufferByte(final ContextCapabilities caps, final int size) { + ByteBuffer buffer = caps.util.bufferTL; if ( buffer.capacity() < size ) { int sizeNew = buffer.capacity() << 1; @@ -88,15 +86,15 @@ sizeNew <<= 1; buffer = BufferUtils.createByteBuffer(size); - bufferTL.set(buffer); + caps.util.bufferTL = buffer; } else buffer.clear(); return buffer; } - private static ByteBuffer getBufferByteOffset(final int size) { - ByteBuffer buffer = bufferTL.get(); + private static ByteBuffer getBufferByteOffset(final ContextCapabilities caps, final int size) { + ByteBuffer buffer = caps.util.bufferTL; if ( buffer.capacity() < size ) { int sizeNew = buffer.capacity() << 1; @@ -105,7 +103,7 @@ final ByteBuffer bufferNew = BufferUtils.createByteBuffer(size); bufferNew.put(buffer); - bufferTL.set(buffer = bufferNew); + caps.util.bufferTL = (buffer = bufferNew); } else { buffer.position(buffer.limit()); buffer.limit(buffer.capacity()); @@ -114,22 +112,22 @@ return buffer; } - static ShortBuffer getBufferShort() { return buffersTL.get().shorts; } + static ShortBuffer getBufferShort(final ContextCapabilities caps) { return caps.util.buffersTL.shorts; } - static IntBuffer getBufferInt() { return buffersTL.get().ints; } + static IntBuffer getBufferInt(final ContextCapabilities caps) { return caps.util.buffersTL.ints; } - static LongBuffer getBufferLong() { return buffersTL.get().longs; } + static LongBuffer getBufferLong(final ContextCapabilities caps) { return caps.util.buffersTL.longs; } - static FloatBuffer getBufferFloat() { return buffersTL.get().floats; } + static FloatBuffer getBufferFloat(final ContextCapabilities caps) { return caps.util.buffersTL.floats; } - static DoubleBuffer getBufferDouble() { return buffersTL.get().doubles; } + static DoubleBuffer getBufferDouble(final ContextCapabilities caps) { return caps.util.buffersTL.doubles; } - static IntBuffer getLengths() { - return getLengths(1); + static IntBuffer getLengths(final ContextCapabilities caps) { + return getLengths(caps, 1); } - static IntBuffer getLengths(final int size) { - IntBuffer lengths = lengthsTL.get(); + static IntBuffer getLengths(final ContextCapabilities caps, final int size) { + IntBuffer lengths = caps.util.lengthsTL; if ( lengths.capacity() < size ) { int sizeNew = lengths.capacity(); @@ -137,7 +135,7 @@ sizeNew <<= 1; lengths = BufferUtils.createIntBuffer(size); - lengthsTL.set(lengths); + caps.util.lengthsTL = lengths; } else lengths.clear(); @@ -169,9 +167,9 @@ * * @return the buffer as a String. */ - static String getString(final ByteBuffer buffer) { + static String getString(final ContextCapabilities caps, final ByteBuffer buffer) { final int length = buffer.remaining(); - final char[] charArray = getArray(length); + final char[] charArray = getArray(caps, length); for ( int i = buffer.position(); i < buffer.limit(); i++ ) charArray[i - buffer.position()] = (char)buffer.get(i); @@ -186,8 +184,8 @@ * * @return the String as a ByteBuffer */ - static long getBuffer(final CharSequence string) { - final ByteBuffer buffer = encode(getBufferByte(string.length()), string); + static long getBuffer(final ContextCapabilities caps, final CharSequence string) { + final ByteBuffer buffer = encode(getBufferByte(caps, string.length()), string); buffer.flip(); return MemoryUtil.getAddress0(buffer); } @@ -199,8 +197,8 @@ * * @return the String as a ByteBuffer */ - static long getBuffer(final CharSequence string, final int offset) { - final ByteBuffer buffer = encode(getBufferByteOffset(offset + string.length()), string); + static long getBuffer(final ContextCapabilities caps, final CharSequence string, final int offset) { + final ByteBuffer buffer = encode(getBufferByteOffset(caps, offset + string.length()), string); buffer.flip(); return MemoryUtil.getAddress(buffer); } @@ -212,8 +210,8 @@ * * @return the String as a ByteBuffer */ - static long getBufferNT(final CharSequence string) { - final ByteBuffer buffer = encode(getBufferByte(string.length() + 1), string); + static long getBufferNT(final ContextCapabilities caps, final CharSequence string) { + final ByteBuffer buffer = encode(getBufferByte(caps, string.length() + 1), string); buffer.put((byte)0); buffer.flip(); return MemoryUtil.getAddress0(buffer); @@ -234,8 +232,8 @@ * * @return the Strings as a ByteBuffer */ - static long getBuffer(final CharSequence[] strings) { - final ByteBuffer buffer = getBufferByte(getTotalLength(strings)); + static long getBuffer(final ContextCapabilities caps, final CharSequence[] strings) { + final ByteBuffer buffer = getBufferByte(caps, getTotalLength(strings)); for ( CharSequence string : strings ) encode(buffer, string); @@ -251,8 +249,8 @@ * * @return the Strings as a ByteBuffer */ - static long getBufferNT(final CharSequence[] strings) { - final ByteBuffer buffer = getBufferByte(getTotalLength(strings) + strings.length); + static long getBufferNT(final ContextCapabilities caps, final CharSequence[] strings) { + final ByteBuffer buffer = getBufferByte(caps, getTotalLength(strings) + strings.length); for ( CharSequence string : strings ) { encode(buffer, string); @@ -270,8 +268,8 @@ * * @return the String lengths in an IntBuffer */ - static long getLengths(final CharSequence[] strings) { - IntBuffer buffer = getLengths(strings.length); + static long getLengths(final ContextCapabilities caps, final CharSequence[] strings) { + IntBuffer buffer = getLengths(caps, strings.length); for ( CharSequence string : strings ) buffer.put(string.length()); @@ -280,21 +278,21 @@ return MemoryUtil.getAddress0(buffer); } - static long getInt(final int value) { - return MemoryUtil.getAddress0(getBufferInt().put(0, value)); + static long getInt(final ContextCapabilities caps, final int value) { + return MemoryUtil.getAddress0(getBufferInt(caps).put(0, value)); } - static long getBufferByte0() { - return MemoryUtil.getAddress0(getBufferByte(0)); + static long getBufferByte0(final ContextCapabilities caps) { + return MemoryUtil.getAddress0(getBufferByte(caps, 0)); } private static class Buffers { final ShortBuffer shorts; - final IntBuffer ints; - final LongBuffer longs; + final IntBuffer ints; + final LongBuffer longs; - final FloatBuffer floats; + final FloatBuffer floats; final DoubleBuffer doubles; Buffers() { Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -301,13 +301,13 @@ } } else if ( method.getAnnotation(GLreturn.class) != null ) { has_result = true; - Utils.printGLReturnPre(writer, method, method.getAnnotation(GLreturn.class)); + Utils.printGLReturnPre(writer, method, method.getAnnotation(GLreturn.class), type_map); } writer.print(Utils.getSimpleNativeMethodName(method, generate_error_checks, context_specific)); if (mode == Mode.BUFFEROBJECT) writer.print(Utils.BUFFER_OBJECT_METHOD_POSTFIX); writer.print("("); - boolean first_parameter = printMethodCallArguments(writer, method, typeinfos_instance, mode); + boolean first_parameter = printMethodCallArguments(writer, method, typeinfos_instance, mode, type_map); if (context_specific) { if (!first_parameter) writer.print(", "); @@ -335,7 +335,7 @@ else writer.println(tabs + "return " + Utils.RESULT_VAR_NAME + ";"); } else - Utils.printGLReturnPost(writer, method, method.getAnnotation(GLreturn.class)); + Utils.printGLReturnPost(writer, method, method.getAnnotation(GLreturn.class), type_map); } if ( code_annotation != null && code_annotation.tryBlock() ) { @@ -439,7 +439,7 @@ throw new RuntimeException(c + " is not allowed"); } - private static boolean printMethodCallArgument(PrintWriter writer, MethodDeclaration method, ParameterDeclaration param, Map<ParameterDeclaration, TypeInfo> typeinfos_instance, Mode mode, boolean first_parameter) { + private static boolean printMethodCallArgument(PrintWriter writer, MethodDeclaration method, ParameterDeclaration param, Map<ParameterDeclaration, TypeInfo> typeinfos_instance, Mode mode, boolean first_parameter, TypeMap type_map) { if (!first_parameter) writer.print(", "); @@ -496,7 +496,9 @@ writer.print("APIUtil.getBuffer"); if ( param.getAnnotation(NullTerminated.class) != null ) writer.print("NT"); - writer.print("(" + param.getSimpleName()); + writer.print('('); + writer.print(type_map.getAPIUtilParam(true)); + writer.print(param.getSimpleName()); if ( offset != null ) writer.print(", " + offset); writer.print(")"); @@ -531,7 +533,7 @@ return false; } - private static boolean printMethodCallArguments(PrintWriter writer, MethodDeclaration method, Map<ParameterDeclaration, TypeInfo> typeinfos_instance, Mode mode) { + private static boolean printMethodCallArguments(PrintWriter writer, MethodDeclaration method, Map<ParameterDeclaration, TypeInfo> typeinfos_instance, Mode mode, TypeMap type_map) { boolean first_parameter = true; for ( ParameterDeclaration param : method.getParameters() ) { if ( param.getAnnotation(Result.class) != null || (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative()) ) @@ -539,7 +541,7 @@ final Constant constant_annotation = param.getAnnotation(Constant.class); if ( constant_annotation== null || !constant_annotation.isNative() ) - first_parameter = printMethodCallArgument(writer, method, param, typeinfos_instance, mode, first_parameter); + first_parameter = printMethodCallArgument(writer, method, param, typeinfos_instance, mode, first_parameter, type_map); } if (Utils.getNIOBufferType(Utils.getMethodReturnType(method)) != null) { if (method.getAnnotation(CachedResult.class) != null && method.getAnnotation(CachedResult.class).isRange()) { Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/TypeMap.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/TypeMap.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/TypeMap.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -50,6 +50,7 @@ public interface TypeMap { void printCapabilitiesInit(PrintWriter writer); String getCapabilities(); + String getAPIUtilParam(boolean comma); void printErrorCheckMethod(PrintWriter writer, MethodDeclaration method, String tabs); String getRegisterNativesFunctionName(); PrimitiveType.Kind getPrimitiveTypeFromNativeType(Class<? extends Annotation> native_type); Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/Utils.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/Utils.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/Utils.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -57,19 +57,19 @@ public class Utils { - public static final String TYPEDEF_POSTFIX = "PROC"; - public static final String FUNCTION_POINTER_VAR_NAME = "function_pointer"; - public static final String FUNCTION_POINTER_POSTFIX = "_pointer"; - public static final String CHECKS_CLASS_NAME = "GLChecks"; - public static final String CONTEXT_CAPS_CLASS_NAME = "ContextCapabilities"; - public static final String STUB_INITIALIZER_NAME = "initNativeStubs"; - public static final String BUFFER_OBJECT_METHOD_POSTFIX = "BO"; - public static final String BUFFER_OBJECT_PARAMETER_POSTFIX = "_buffer_offset"; - public static final String RESULT_SIZE_NAME = "result_size"; - public static final String RESULT_VAR_NAME = "__result"; - public static final String CACHED_BUFFER_LENGTH_NAME = "length"; - public static final String CACHED_BUFFER_NAME = "old_buffer"; - private static final String OVERLOADED_METHOD_PREFIX = "n"; + public static final String TYPEDEF_POSTFIX = "PROC"; + public static final String FUNCTION_POINTER_VAR_NAME = "function_pointer"; + public static final String FUNCTION_POINTER_POSTFIX = "_pointer"; + public static final String CHECKS_CLASS_NAME = "GLChecks"; + public static final String CONTEXT_CAPS_CLASS_NAME = "ContextCapabilities"; + public static final String STUB_INITIALIZER_NAME = "initNativeStubs"; + public static final String BUFFER_OBJECT_METHOD_POSTFIX = "BO"; + public static final String BUFFER_OBJECT_PARAMETER_POSTFIX = "_buffer_offset"; + public static final String RESULT_SIZE_NAME = "result_size"; + public static final String RESULT_VAR_NAME = "__result"; + public static final String CACHED_BUFFER_LENGTH_NAME = "length"; + public static final String CACHED_BUFFER_NAME = "old_buffer"; + private static final String OVERLOADED_METHOD_PREFIX = "n"; public static String getTypedefName(MethodDeclaration method) { Alternate alt_annotation = method.getAnnotation(Alternate.class); @@ -102,6 +102,7 @@ } private static class AnnotationMirrorComparator implements Comparator<AnnotationMirror> { + public int compare(AnnotationMirror a1, AnnotationMirror a2) { String n1 = a1.getAnnotationType().getDeclaration().getQualifiedName(); String n2 = a2.getAnnotationType().getDeclaration().getQualifiedName(); @@ -148,22 +149,22 @@ private static boolean hasParameterMultipleTypes(ParameterDeclaration param) { int num_native_annotations = 0; - for (AnnotationMirror annotation : param.getAnnotationMirrors()) - if (NativeTypeTranslator.getAnnotation(annotation, NativeType.class) != null) + for ( AnnotationMirror annotation : param.getAnnotationMirrors() ) + if ( NativeTypeTranslator.getAnnotation(annotation, NativeType.class) != null ) num_native_annotations++; return num_native_annotations > 1; } public static boolean isParameterMultiTyped(ParameterDeclaration param) { boolean result = Buffer.class.equals(Utils.getJavaType(param.getType())); - if (!result && hasParameterMultipleTypes(param)) + if ( !result && hasParameterMultipleTypes(param) ) throw new RuntimeException(param + " not defined as java.nio.Buffer but has multiple types"); return result; } public static ParameterDeclaration findParameter(MethodDeclaration method, String name) { - for (ParameterDeclaration param : method.getParameters()) - if (param.getSimpleName().equals(name)) + for ( ParameterDeclaration param : method.getParameters() ) + if ( param.getSimpleName().equals(name) ) return param; throw new RuntimeException("Parameter " + name + " not found"); } @@ -176,7 +177,7 @@ overloadsComment = null; String doc_comment = decl.getDocComment(); - if (doc_comment != null) { + if ( doc_comment != null ) { final String tab = decl instanceof InterfaceDeclaration ? "" : "\t"; writer.println(tab + "/**"); @@ -187,7 +188,7 @@ final StringTokenizer doc_lines = new StringTokenizer(doc_comment, "\n", true); boolean lastWasNL = false; - while (doc_lines.hasMoreTokens()) { + while ( doc_lines.hasMoreTokens() ) { final String t = doc_lines.nextToken(); if ( "\n".equals(t) ) { if ( lastWasNL ) @@ -205,8 +206,8 @@ } public static AnnotationMirror getParameterAutoAnnotation(ParameterDeclaration param) { - for (AnnotationMirror annotation : param.getAnnotationMirrors()) - if (NativeTypeTranslator.getAnnotation(annotation, Auto.class) != null) + for ( AnnotationMirror annotation : param.getAnnotationMirrors() ) + if ( NativeTypeTranslator.getAnnotation(annotation, Auto.class) != null ) return annotation; return null; } @@ -242,9 +243,9 @@ public static ParameterDeclaration getResultParameter(MethodDeclaration method) { ParameterDeclaration result_param = null; - for (ParameterDeclaration param : method.getParameters()) { - if (param.getAnnotation(Result.class) != null) { - if (result_param != null) + for ( ParameterDeclaration param : method.getParameters() ) { + if ( param.getAnnotation(Result.class) != null ) { + if ( result_param != null ) throw new RuntimeException("Multiple parameters annotated with Result in method " + method); result_param = param; } @@ -255,7 +256,7 @@ public static TypeMirror getMethodReturnType(MethodDeclaration method) { TypeMirror result_type; ParameterDeclaration result_param = getResultParameter(method); - if (result_param != null) { + if ( result_param != null ) { result_type = result_param.getType(); } else result_type = method.getReturnType(); @@ -291,20 +292,20 @@ public static void printExtraCallArguments(PrintWriter writer, MethodDeclaration method, String size_parameter_name) { writer.print(size_parameter_name); - if (method.getAnnotation(CachedResult.class) != null) { + if ( method.getAnnotation(CachedResult.class) != null ) { writer.print(", " + CACHED_BUFFER_NAME); } } private static String getClassName(InterfaceDeclaration interface_decl, String opengl_name) { Extension extension_annotation = interface_decl.getAnnotation(Extension.class); - if (extension_annotation != null && !"".equals(extension_annotation.className())) { + if ( extension_annotation != null && !"".equals(extension_annotation.className()) ) { return extension_annotation.className(); } StringBuilder result = new StringBuilder(); - for (int i = 0; i < opengl_name.length(); i++) { + for ( int i = 0; i < opengl_name.length(); i++ ) { int ch = opengl_name.codePointAt(i); - if (ch == '_') { + if ( ch == '_' ) { i++; result.appendCodePoint(Character.toUpperCase(opengl_name.codePointAt(i))); } else @@ -314,8 +315,8 @@ } public static boolean hasMethodBufferObjectParameter(MethodDeclaration method) { - for (ParameterDeclaration param : method.getParameters()) { - if (param.getAnnotation(BufferObject.class) != null) { + for ( ParameterDeclaration param : method.getParameters() ) { + if ( param.getAnnotation(BufferObject.class) != null ) { return true; } } @@ -332,7 +333,7 @@ public static Class<?> getNIOBufferType(TypeMirror t) { Class<?> param_type = getJavaType(t); - if (Buffer.class.isAssignableFrom(param_type)) + if ( Buffer.class.isAssignableFrom(param_type) ) return param_type; else if ( param_type == CharSequence.class || param_type == CharSequence[].class || param_type == PointerBuffer.class ) return ByteBuffer.class; @@ -344,7 +345,7 @@ String method_name; Alternate alt_annotation = method.getAnnotation(Alternate.class); method_name = alt_annotation == null || alt_annotation.nativeAlt() ? method.getSimpleName() : alt_annotation.value(); - if (isMethodIndirect(generate_error_checks, context_specific, method)) + if ( isMethodIndirect(generate_error_checks, context_specific, method) ) method_name = OVERLOADED_METHOD_PREFIX + method_name; return method_name; } @@ -392,15 +393,15 @@ return offset; } - static void printGLReturnPre(PrintWriter writer, MethodDeclaration method, GLreturn return_annotation) { + static void printGLReturnPre(PrintWriter writer, MethodDeclaration method, GLreturn return_annotation, TypeMap type_map) { final String return_type = getMethodReturnType(method, return_annotation, true); if ( "String".equals(return_type) ) { if ( !return_annotation.forceMaxLength() ) { - writer.println("IntBuffer " + return_annotation.value() + "_length = APIUtil.getLengths();"); + writer.println("IntBuffer " + return_annotation.value() + "_length = APIUtil.getLengths(" + type_map.getAPIUtilParam(false) + ");"); writer.print("\t\t"); } - writer.print("ByteBuffer " + return_annotation.value() + " = APIUtil.getBufferByte(" + return_annotation.maxLength()); + writer.print("ByteBuffer " + return_annotation.value() + " = APIUtil.getBufferByte(" + type_map.getAPIUtilParam(true) + return_annotation.maxLength()); /* Params that use the return buffer will advance its position while filling it. When we return, the position will be at the right spot for grabbing the returned string bytes. We only have to make sure that the original buffer was @@ -412,9 +413,9 @@ writer.println(");"); } else { final String buffer_type = "Boolean".equals(return_type) ? "Byte" : return_type; - writer.print(buffer_type + "Buffer " + return_annotation.value() + " = APIUtil.getBuffer" + buffer_type + "("); + writer.print(buffer_type + "Buffer " + return_annotation.value() + " = APIUtil.getBuffer" + buffer_type + "(" + type_map.getAPIUtilParam(false)); if ( "Byte".equals(buffer_type) ) - writer.print('1'); + writer.print((type_map.getAPIUtilParam(false).length() > 0 ? ", " : "") + "1"); writer.println(");"); } @@ -426,20 +427,20 @@ writer.print("\t\t"); } - static void printGLReturnPost(PrintWriter writer, MethodDeclaration method, GLreturn return_annotation) { + static void printGLReturnPost(PrintWriter writer, MethodDeclaration method, GLreturn return_annotation, TypeMap type_map) { final String return_type = getMethodReturnType(method, return_annotation, true); if ( "String".equals(return_type) ) { writer.print("\t\t" + return_annotation.value() + ".limit("); final String offset = getStringOffset(method, null); - if ( offset != null) + if ( offset != null ) writer.print(offset + " + "); if ( return_annotation.forceMaxLength() ) writer.print(return_annotation.maxLength()); else writer.print(return_annotation.value() + "_length.get(0)"); writer.println(");"); - writer.println("\t\treturn APIUtil.getString(" + return_annotation.value() + ");"); + writer.println("\t\treturn APIUtil.getString(" + type_map.getAPIUtilParam(true) + return_annotation.value() + ");"); } else { writer.print("\t\treturn " + return_annotation.value() + ".get(0)"); if ( "Boolean".equals(return_type) ) Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/openal/ALTypeMap.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/openal/ALTypeMap.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/openal/ALTypeMap.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -178,6 +178,10 @@ throw new UnsupportedOperationException(); } + public String getAPIUtilParam(boolean comma) { + return ""; + } + public void printErrorCheckMethod(final PrintWriter writer, final MethodDeclaration method, final String tabs) { writer.println(tabs + "Util.checkALError();"); } Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/opencl/CLTypeMap.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/opencl/CLTypeMap.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/opencl/CLTypeMap.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -89,6 +89,10 @@ return "CLCapabilities"; } + public String getAPIUtilParam(boolean comma) { + return ""; + } + public void printErrorCheckMethod(final PrintWriter writer, final MethodDeclaration method, final String tabs) { final Check check = method.getAnnotation(Check.class); if ( check != null ) // Get the error code from an IntBuffer output parameter Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/opengl/GLCapabilitiesGenerator.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/opengl/GLCapabilitiesGenerator.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/opengl/GLCapabilitiesGenerator.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -64,6 +64,7 @@ public static void generateClassPrologue(PrintWriter writer, boolean context_specific, boolean generate_error_checks) { writer.println("public class " + Utils.CONTEXT_CAPS_CLASS_NAME + " {"); writer.println("\tstatic final boolean DEBUG = " + Boolean.toString(generate_error_checks) + ";"); + writer.println("\tfinal APIUtil util = new APIUtil();"); writer.println("\tfinal StateTracker tracker = new StateTracker();"); writer.println(); if ( !context_specific ) { Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/opengl/GLESTypeMap.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/opengl/GLESTypeMap.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/opengl/GLESTypeMap.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -97,6 +97,10 @@ return "caps"; } + public String getAPIUtilParam(boolean comma) { + return ""; + } + public void printErrorCheckMethod(final PrintWriter writer, final MethodDeclaration method, final String tabs) { writer.println(tabs + "Util.checkGLError();"); } Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/opengl/GLTypeMap.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/opengl/GLTypeMap.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/opengl/GLTypeMap.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -106,6 +106,10 @@ return "caps"; } + public String getAPIUtilParam(boolean comma) { + return comma ? "caps, " : "caps"; + } + public void printErrorCheckMethod(final PrintWriter writer, final MethodDeclaration method, final String tabs) { writer.println(tabs + "Util.checkGLError();"); } Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/AMD_name_gen_delete.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/AMD_name_gen_delete.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/AMD_name_gen_delete.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -58,7 +58,7 @@ void glDeleteNamesAMD(@GLenum int identifier, @AutoSize("names") @GLsizei int num, @Const @GLuint IntBuffer names); @Alternate("glDeleteNamesAMD") - void glDeleteNamesAMD(@GLenum int identifier, @Constant("1") @GLsizei int num, @Constant(value = "APIUtil.getInt(name)", keepParam = true) int name); + void glDeleteNamesAMD(@GLenum int identifier, @Constant("1") @GLsizei int num, @Constant(value = "APIUtil.getInt(caps, name)", keepParam = true) int name); boolean glIsNameAMD(@GLenum int identifier, @GLuint int name); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/AMD_performance_monitor.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/AMD_performance_monitor.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/AMD_performance_monitor.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -100,12 +100,12 @@ void glDeletePerfMonitorsAMD(@AutoSize("monitors") @GLsizei int n, @GLuint IntBuffer monitors); @Alternate("glDeletePerfMonitorsAMD") - void glDeletePerfMonitorsAMD(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getInt(monitor)", keepParam = true) int monitor); + void glDeletePerfMonitorsAMD(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getInt(caps, monitor)", keepParam = true) int monitor); void glSelectPerfMonitorCountersAMD(@GLuint int monitor, boolean enable, @GLuint int group, @AutoSize("counterList") int numCounters, @GLuint IntBuffer counterList); @Alternate("glSelectPerfMonitorCountersAMD") - void glSelectPerfMonitorCountersAMD(@GLuint int monitor, boolean enable, @GLuint int group, @Constant("1") int numCounters, @Constant(value = "APIUtil.getInt(counter)", keepParam = true) int counter); + void glSelectPerfMonitorCountersAMD(@GLuint int monitor, boolean enable, @GLuint int group, @Constant("1") int numCounters, @Constant(value = "APIUtil.getInt(caps, counter)", keepParam = true) int counter); void glBeginPerfMonitorAMD(@GLuint int monitor); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/APPLE_fence.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/APPLE_fence.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/APPLE_fence.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -55,7 +55,7 @@ void glDeleteFencesAPPLE(@AutoSize("fences") @GLsizei int n, @Const @GLuint IntBuffer fences); @Alternate("glDeleteFencesAPPLE") - void glDeleteFencesAPPLE(@Constant("1") @GLsizei int n, @Const @GLuint @Constant(value = "APIUtil.getInt(fence)", keepParam = true) int fence); + void glDeleteFencesAPPLE(@Constant("1") @GLsizei int n, @Const @GLuint @Constant(value = "APIUtil.getInt(caps, fence)", keepParam = true) int fence); void glSetFenceAPPLE(@GLuint int fence); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/APPLE_vertex_array_object.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/APPLE_vertex_array_object.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/APPLE_vertex_array_object.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -52,7 +52,7 @@ void glDeleteVertexArraysAPPLE(@AutoSize("arrays") @GLsizei int n, @Const @GLuint IntBuffer arrays); @Alternate("glDeleteVertexArraysAPPLE") - void glDeleteVertexArraysAPPLE(@Constant("1") @GLsizei int n, @Const @GLuint @Constant(value = "APIUtil.getInt(array)", keepParam = true) int array); + void glDeleteVertexArraysAPPLE(@Constant("1") @GLsizei int n, @Const @GLuint @Constant(value = "APIUtil.getInt(caps, array)", keepParam = true) int array); void glGenVertexArraysAPPLE(@AutoSize("arrays") @GLsizei int n, @OutParameter @GLuint IntBuffer arrays); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_buffer_object.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_buffer_object.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_buffer_object.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -71,7 +71,7 @@ void glDeleteBuffersARB(@AutoSize("buffers") @GLsizei int n, @Const @GLuint IntBuffer buffers); @Alternate("glDeleteBuffersARB") - void glDeleteBuffersARB(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getInt(buffer)", keepParam = true) int buffer); + void glDeleteBuffersARB(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getInt(caps, buffer)", keepParam = true) int buffer); void glGenBuffersARB(@AutoSize("buffers") @GLsizei int n, @OutParameter @GLuint IntBuffer buffers); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_draw_buffers.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_draw_buffers.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_draw_buffers.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -65,5 +65,5 @@ void glDrawBuffersARB(@AutoSize("buffers") @GLsizei int size, @Const @GLenum IntBuffer buffers); @Alternate("glDrawBuffersARB") - void glDrawBuffersARB(@Constant("1") @GLsizei int size, @Constant(value = "APIUtil.getInt(buffer)", keepParam = true) int buffer); + void glDrawBuffersARB(@Constant("1") @GLsizei int size, @Constant(value = "APIUtil.getInt(caps, buffer)", keepParam = true) int buffer); } Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_framebuffer_object.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_framebuffer_object.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_framebuffer_object.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -197,7 +197,7 @@ @Reuse("GL30") @Alternate("glDeleteRenderbuffers") - void glDeleteRenderbuffers(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getInt(renderbuffer)", keepParam = true) int renderbuffer); + void glDeleteRenderbuffers(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getInt(caps, renderbuffer)", keepParam = true) int renderbuffer); @Reuse("GL30") void glGenRenderbuffers(@AutoSize("renderbuffers") @GLsizei int n, @OutParameter @GLuint IntBuffer renderbuffers); @@ -237,7 +237,7 @@ @Reuse("GL30") @Alternate("glDeleteFramebuffers") - void glDeleteFramebuffers(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getInt(framebuffer)", keepParam = true) int framebuffer); + void glDeleteFramebuffers(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getInt(caps, framebuffer)", keepParam = true) int framebuffer); @Reuse("GL30") void glGenFramebuffers(@AutoSize("framebuffers") @GLsizei int n, @OutParameter @GLuint IntBuffer framebuffers); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_occlusion_query.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_occlusion_query.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_occlusion_query.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -68,7 +68,7 @@ void glDeleteQueriesARB(@AutoSize("ids") @GLsizei int n, @GLuint IntBuffer ids); @Alternate("glDeleteQueriesARB") - void glDeleteQueriesARB(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getInt(id)", keepParam = true) int id); + void glDeleteQueriesARB(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getInt(caps, id)", keepParam = true) int id); boolean glIsQueryARB(@GLuint int id); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_program.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_program.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_program.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -128,7 +128,7 @@ void glDeleteProgramsARB(@AutoSize("programs") @GLsizei int n, @Const @GLuint IntBuffer programs); @Alternate("glDeleteProgramsARB") - void glDeleteProgramsARB(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getInt(program)", keepParam = true) int program); + void glDeleteProgramsARB(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getInt(caps, program)", keepParam = true) int program); void glGenProgramsARB(@AutoSize("programs") @GLsizei int n, @OutParameter @GLuint IntBuffer programs); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_sampler_objects.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_sampler_objects.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_sampler_objects.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -63,7 +63,7 @@ @Reuse("GL33") @Alternate("glDeleteSamplers") - void glDeleteSamplers(@Constant("1") @GLsizei int count, @Constant(value = "APIUtil.getInt(sampler)", keepParam = true) int sampler); + void glDeleteSamplers(@Constant("1") @GLsizei int count, @Constant(value = "APIUtil.getInt(caps, sampler)", keepParam = true) int sampler); @Reuse("GL33") boolean glIsSampler(@GLuint int sampler); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_separate_shader_objects.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_separate_shader_objects.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_separate_shader_objects.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -98,7 +98,7 @@ @Reuse("GL41") @Alternate("glDeleteProgramPipelines") - void glDeleteProgramPipelines(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getInt(pipeline)", keepParam = true) int pipeline); + void glDeleteProgramPipelines(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getInt(caps, pipeline)", keepParam = true) int pipeline); @Reuse("GL41") void glGenProgramPipelines(@AutoSize("pipelines") @GLsizei int n, @OutParameter @GLuint IntBuffer pipelines); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_shader_objects.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_shader_objects.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_shader_objects.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -110,7 +110,7 @@ @Alternate(value = "glShaderSourceARB", nativeAlt = true) void glShaderSourceARB3(@GLhandleARB int shader, @Constant("strings.length") @GLsizei int count, @Const @PointerArray(value = "count", lengths = "length") CharSequence[] strings, - @Constant("APIUtil.getLengths(strings)") @Const IntBuffer length); + @Constant("APIUtil.getLengths(caps, strings)") @Const IntBuffer length); void glCompileShaderARB(@GLhandleARB int shaderObj); @@ -234,7 +234,7 @@ @Alternate(value = "glGetActiveUniformARB", javaAlt = true) @GLreturn(value = "name", maxLength = "maxLength") void glGetActiveUniformARB(@GLhandleARB int programObj, @GLuint int index, @GLsizei int maxLength, - @OutParameter @GLsizei @Constant("MemoryUtil.getAddress0(name_length), MemoryUtil.getAddress0(APIUtil.getBufferInt()), MemoryUtil.getAddress(APIUtil.getBufferInt(), 1)") IntBuffer length, + @OutParameter @GLsizei @Constant("MemoryUtil.getAddress0(name_length), MemoryUtil.getAddress0(APIUtil.getBufferInt(caps)), MemoryUtil.getAddress(APIUtil.getBufferInt(caps), 1)") IntBuffer length, @OutParameter @GLcharARB ByteBuffer name); /** Overloads glGetActiveUniformARB. This version returns only the uniform size. */ @@ -244,7 +244,7 @@ @OutParameter @GLsizei @Constant("0L") IntBuffer length, @OutParameter IntBuffer size, @OutParameter @GLenum @Constant("MemoryUtil.getAddress(size, 1)") IntBuffer type, // Reuse size buffer and ignore - @OutParameter @GLcharARB @Constant("APIUtil.getBufferByte0()") ByteBuffer name); + @OutParameter @GLcharARB @Constant("APIUtil.getBufferByte0(caps)") ByteBuffer name); /** Overloads glGetActiveUniformARB. This version returns only the uniform type. */ @Alternate(value = "glGetActiveUniformARB", javaAlt = true) @@ -253,7 +253,7 @@ @OutParameter @GLsizei @Constant("0L") IntBuffer length, @OutParameter @Constant("MemoryUtil.getAddress(type, 1)") IntBuffer size, // Reuse type buffer and ignore @OutParameter @GLenum IntBuffer type, - @OutParameter @GLcharARB @Constant("APIUtil.getBufferByte0()") ByteBuffer name); + @OutParameter @GLcharARB @Constant("APIUtil.getBufferByte0(caps)") ByteBuffer name); @StripPostfix("params") void glGetUniformfvARB(@GLhandleARB int programObj, int location, @OutParameter @Check FloatBuffer params); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_shading_language_include.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_shading_language_include.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_shading_language_include.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -68,7 +68,7 @@ @Alternate(value = "glCompileShaderIncludeARB", nativeAlt = true) void glCompileShaderIncludeARB2(@GLuint int shader, @Constant("path.length") @GLsizei int count, @Const @PointerArray(value = "count", lengths = "length") CharSequence[] path, - @Constant("APIUtil.getLengths(path)") @Const IntBuffer length); + @Constant("APIUtil.getLengths(caps, path)") @Const IntBuffer length); boolean glIsNamedStringARB(@AutoSize("name") int namelen, @Const @GLchar ByteBuffer name); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_transform_feedback2.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_transform_feedback2.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_transform_feedback2.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -61,7 +61,7 @@ @Reuse("GL40") @Alternate("glDeleteTransformFeedbacks") - void glDeleteTransformFeedbacks(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getInt(id)", keepParam = true) int id); + void glDeleteTransformFeedbacks(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getInt(caps, id)", keepParam = true) int id); @Reuse("GL40") void glGenTransformFeedbacks(@AutoSize("ids") @GLsizei int n, @OutParameter @GLuint IntBuffer ids); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_array_object.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_array_object.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_array_object.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -55,7 +55,7 @@ @Reuse("GL30") @Alternate("glDeleteVertexArrays") - void glDeleteVertexArrays(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getInt(array)", keepParam = true) int array); + void glDeleteVertexArrays(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getInt(caps, array)", keepParam = true) int array); @Reuse("GL30") void glGenVertexArrays(@AutoSize("arrays") @GLsizei int n, @OutParameter @GLuint IntBuffer arrays); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_shader.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_shader.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/ARB_vertex_shader.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -170,7 +170,7 @@ @Alternate(value = "glGetActiveAttribARB", javaAlt = true) @GLreturn(value = "name", maxLength = "maxLength") void glGetActiveAttribARB(@GLhandleARB int programObj, @GLuint int index, @GLsizei int maxLength, - @OutParameter @GLsizei @Constant("MemoryUtil.getAddress0(name_length), MemoryUtil.getAddress0(APIUtil.getBufferInt()), MemoryUtil.getAddress(APIUtil.getBufferInt(), 1)") IntBuffer length, + @OutParameter @GLsizei @Constant("MemoryUtil.getAddress0(name_length), MemoryUtil.getAddress0(APIUtil.getBufferInt(caps)), MemoryUtil.getAddress(APIUtil.getBufferInt(caps), 1)") IntBuffer length, @OutParameter @GLcharARB ByteBuffer name); /** Overloads glGetActiveAttribARB. This version returns only the attrib size. */ @@ -180,7 +180,7 @@ @OutParameter @GLsizei @Constant("0L") IntBuffer length, @OutParameter IntBuffer size, @OutParameter @GLenum @Constant("MemoryUtil.getAddress(size, 1)") IntBuffer type, // Reuse size buffer and ignore - @OutParameter @GLcharARB @Constant("APIUtil.getBufferByte0()") ByteBuffer name); + @OutParameter @GLcharARB @Constant("APIUtil.getBufferByte0(caps)") ByteBuffer name); /** Overloads glGetActiveAttribARB. This version returns only the attrib type. */ @Alternate(value = "glGetActiveAttribARB", javaAlt = true) @@ -189,7 +189,7 @@ @OutParameter @GLsizei @Constant("0L") IntBuffer length, @OutParameter @Constant("MemoryUtil.getAddress(type, 1)") IntBuffer size, // Reuse type buffer and ignore @OutParameter @GLenum IntBuffer type, - @OutParameter @GLcharARB @Constant("APIUtil.getBufferByte0()") ByteBuffer name); + @OutParameter @GLcharARB @Constant("APIUtil.getBufferByte0(caps)") ByteBuffer name); int glGetAttribLocationARB(@GLhandleARB int programObj, @NullTerminated @Const @GLcharARB ByteBuffer name); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/ATI_draw_buffers.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/ATI_draw_buffers.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/ATI_draw_buffers.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -65,5 +65,5 @@ void glDrawBuffersATI(@AutoSize("buffers") @GLsizei int size, @Const @GLenum IntBuffer buffers); @Alternate("glDrawBuffersATI") - void glDrawBuffersATI(@Constant("1") @GLsizei int size, @Constant(value = "APIUtil.getInt(buffer)", keepParam = true) int buffer); + void glDrawBuffersATI(@Constant("1") @GLsizei int size, @Constant(value = "APIUtil.getInt(caps, buffer)", keepParam = true) int buffer); } Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_direct_state_access.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_direct_state_access.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_direct_state_access.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -1075,7 +1075,7 @@ @Alternate("glTextureParameterIivEXT") @Dependent("GL_EXT_texture_integer") @StripPostfix("param") - void glTextureParameterIivEXT(@GLuint int texture, @GLenum int target, @GLenum int pname, @Constant(value = "APIUtil.getInt(param)", keepParam = true) int param); + void glTextureParameterIivEXT(@GLuint int texture, @GLenum int target, @GLenum int pname, @Constant(value = "APIUtil.getInt(caps, param)", keepParam = true) int param); @Dependent("GL_EXT_texture_integer") @StripPostfix("params") @@ -1084,7 +1084,7 @@ @Alternate("glTextureParameterIuivEXT") @Dependent("GL_EXT_texture_integer") @StripPostfix("param") - void glTextureParameterIuivEXT(@GLuint int texture, @GLenum int target, @GLenum int pname, @Constant(value = "APIUtil.getInt(param)", keepParam = true) @GLuint int param); + void glTextureParameterIuivEXT(@GLuint int texture, @GLenum int target, @GLenum int pname, @Constant(value = "APIUtil.getInt(caps, param)", keepParam = true) @GLuint int param); @Dependent("GL_EXT_texture_integer") @StripPostfix("params") @@ -1119,7 +1119,7 @@ @Alternate("glMultiTexParameterIivEXT") @Dependent("GL_EXT_texture_integer") @StripPostfix("param") - void glMultiTexParameterIivEXT(@GLenum int texunit, @GLenum int target, @GLenum int pname, @Constant(value = "APIUtil.getInt(param)", keepParam = true) int param); + void glMultiTexParameterIivEXT(@GLenum int texunit, @GLenum int target, @GLenum int pname, @Constant(value = "APIUtil.getInt(caps, param)", keepParam = true) int param); @Dependent("GL_EXT_texture_integer") @StripPostfix("params") @@ -1128,7 +1128,7 @@ @Alternate("glMultiTexParameterIuivEXT") @Dependent("GL_EXT_texture_integer") @StripPostfix("param") - void glMultiTexParameterIuivEXT(@GLenum int texunit, @GLenum int target, @GLenum int pname, @Constant(value = "APIUtil.getInt(param)", keepParam = true) int param); + void glMultiTexParameterIuivEXT(@GLenum int texunit, @GLenum int target, @GLenum int pname, @Constant(value = "APIUtil.getInt(caps, param)", keepParam = true) int param); @Dependent("GL_EXT_texture_integer") @StripPostfix("params") Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_framebuffer_object.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_framebuffer_object.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_framebuffer_object.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -136,7 +136,7 @@ void glDeleteRenderbuffersEXT(@AutoSize("renderbuffers") int n, @Const @GLuint IntBuffer renderbuffers); @Alternate("glDeleteRenderbuffersEXT") - void glDeleteRenderbuffersEXT(@Constant("1") int n, @Constant(value = "APIUtil.getInt(renderbuffer)", keepParam = true) int renderbuffer); + void glDeleteRenderbuffersEXT(@Constant("1") int n, @Constant(value = "APIUtil.getInt(caps, renderbuffer)", keepParam = true) int renderbuffer); void glGenRenderbuffersEXT(@AutoSize("renderbuffers") int n, @OutParameter @GLuint IntBuffer renderbuffers); @@ -161,7 +161,7 @@ void glDeleteFramebuffersEXT(@AutoSize("framebuffers") int n, @Const @GLuint IntBuffer framebuffers); @Alternate("glDeleteFramebuffersEXT") - void glDeleteFramebuffersEXT(@Constant("1") int n, @Constant(value = "APIUtil.getInt(framebuffer)", keepParam = true) int framebuffer); + void glDeleteFramebuffersEXT(@Constant("1") int n, @Constant(value = "APIUtil.getInt(caps, framebuffer)", keepParam = true) int framebuffer); void glGenFramebuffersEXT(@AutoSize("framebuffers") int n, @OutParameter @GLuint IntBuffer framebuffers); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_texture_integer.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_texture_integer.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/EXT_texture_integer.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -118,14 +118,14 @@ @Alternate("glTexParameterIivEXT") @StripPostfix(value = "param", postfix = "v") - void glTexParameterIivEXT(@GLenum int target, @GLenum int pname, @Constant(value = "APIUtil.getInt(param)", keepParam = true) int param); + void glTexParameterIivEXT(@GLenum int target, @GLenum int pname, @Constant(value = "APIUtil.getInt(caps, param)", keepParam = true) int param); @StripPostfix("params") void glTexParameterIuivEXT(@GLenum int target, @GLenum int pname, @Check("4") @GLuint IntBuffer params); @Alternate("glTexParameterIuivEXT") @StripPostfix(value = "param", postfix = "v") - void glTexParameterIuivEXT(@GLenum int target, @GLenum int pname, @Constant(value = "APIUtil.getInt(param)", keepParam = true) int param); + void glTexParameterIuivEXT(@GLenum int target, @GLenum int pname, @Constant(value = "APIUtil.getInt(caps, param)", keepParam = true) int param); @StripPostfix("params") void glGetTexParameterIivEXT(@GLenum int target, @GLenum int pname, @OutParameter @Check("4") IntBuffer params); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/GL11.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/GL11.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/GL11.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -784,7 +784,7 @@ void glDeleteTextures(@AutoSize("textures") @GLsizei int n, @Const @GLuint IntBuffer textures); @Alternate("glDeleteTextures") - void glDeleteTextures(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getInt(texture)", keepParam = true) int texture); + void glDeleteTextures(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getInt(caps, texture)", keepParam = true) int texture); void glCullFace(@GLenum int mode); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/GL15.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/GL15.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/GL15.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -97,7 +97,7 @@ void glDeleteBuffers(@AutoSize("buffers") @GLsizei int n, @Const @GLuint IntBuffer buffers); @Alternate("glDeleteBuffers") - void glDeleteBuffers(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getInt(buffer)", keepParam = true) int buffer); + void glDeleteBuffers(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getInt(caps, buffer)", keepParam = true) int buffer); void glGenBuffers(@AutoSize("buffers") @GLsizei int n, @OutParameter @GLuint IntBuffer buffers); @@ -205,7 +205,7 @@ void glDeleteQueries(@AutoSize("ids") @GLsizei int n, @GLuint IntBuffer ids); @Alternate("glDeleteQueries") - void glDeleteQueries(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getInt(id)", keepParam = true) int id); + void glDeleteQueries(@Constant("1") @GLsizei int n, @Constant(value = "APIUtil.getInt(caps, id)", keepParam = true) int id); boolean glIsQuery(@GLuint int id); Modified: trunk/LWJGL/src/templates/org/lwjgl/opengl/GL20.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/GL20.java 2011-07-16 19:40:16 UTC (rev 3592) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/GL20.java 2011-07-16 22:26:46 UTC (rev 3593) @@ -108,7 +108,7 @@ @Alternate(value = "glShaderSource", nativeAlt = true) void glShaderSource3(@GLuint int shader, @Constant("strings.length") @GLsizei int count, @Const @PointerArray(value = "count", lengths = "length") CharSequence[] strings, - @Constant("APIUtil.getLengths(strings)") @Const IntBuffer length); + @Constant("APIUtil.getLengths(caps, strings)") @Const IntBuffer length); int glCreateShader(@GLuint int type); @@ -257,7 +257,7 @@ @Alternate(value = "glGetActiveUniform", javaAlt = true) @GLreturn(value = "name", maxLength = "maxLength") void glGetActiveUniform(@GLuint int program, @GLuint int index, @GLsizei int maxLength, - @OutParameter @GLsizei @Constant("MemoryUtil.getAddress0(name_length), MemoryUtil.getAddress0(APIUtil.getBufferInt()), MemoryUtil.getAddress(APIUtil.getBufferInt(), 1)") IntBuffer length, + @OutParameter @GLsizei @Constant("MemoryUtil.getAddress0(name_length), MemoryUtil.getAddress0(APIUtil.getBufferInt(caps)), MemoryUtil.getAddress(APIUtil.getBufferInt(caps), 1)") IntBuffer length, @OutParameter @GLchar ByteBuffer name); /** Overloads glGetActiveUniform. This version returns only the uniform size. */ @@ -267,7 +267,7 @@ @OutParameter @GLsizei @Constant("0L") IntBuffer length, ... [truncated message content] |
From: <ma...@us...> - 2011-07-21 22:52:23
|
Revision: 3596 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3596&view=rev Author: matzon Date: 2011-07-21 22:52:16 +0000 (Thu, 21 Jul 2011) Log Message: ----------- Initial stab at win32 resize api Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java trunk/LWJGL/src/java/org/lwjgl/test/input/MouseTest.java trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Display.c Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java 2011-07-17 09:37:35 UTC (rev 3595) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/WindowsDisplay.java 2011-07-21 22:52:16 UTC (rev 3596) @@ -41,6 +41,7 @@ import java.nio.ByteBuffer; import java.nio.FloatBuffer; import java.nio.IntBuffer; +import java.nio.LongBuffer; import java.awt.Canvas; import org.lwjgl.LWJGLException; @@ -66,7 +67,10 @@ private static final int WM_MBUTTONDBLCLK = 0x0209; private static final int WM_MOUSEWHEEL = 0x020A; private static final int WM_CAPTURECHANGED = 0x0215; - private static final int WM_MOUSELEAVE = 0x02A3; + private static final int WM_MOUSELEAVE = 0x02A3; + private static final int WM_ENTERSIZEMOVE = 0x0231; + private static final int WM_EXITSIZEMOVE = 0x0232; + private static final int WM_SIZING = 0x0214; private static final int WM_KEYDOWN = 256; private static final int WM_KEYUP = 257; private static final int WM_SYSKEYUP = 261; @@ -115,6 +119,7 @@ private static final int WA_INACTIVE = 0; private static final int WA_ACTIVE = 1; private static final int WA_CLICKACTIVE = 2; + private static final int SW_NORMAL = 1; private static final int SW_SHOWMINNOACTIVE = 7; private static final int SW_SHOWDEFAULT = 10; private static final int SW_RESTORE = 9; @@ -124,6 +129,23 @@ private static final IntBuffer rect_buffer = BufferUtils.createIntBuffer(4); private static final Rect rect = new Rect(); + + private static final long HWND_TOP = 0; + private static final long HWND_BOTTOM = 1; + private static final long HWND_TOPMOST = -1; + private static final long HWND_NOTOPMOST = -2; + + private static final int SWP_NOSIZE = 0x0001; + private static final int SWP_NOMOVE = 0x0002; + private static final int SWP_NOZORDER = 0x0004; + private static final int SWP_FRAMECHANGED = 0x0020; + + private static final int GWL_STYLE = -16; + private static final int GWL_EXSTYLE = -20; + + private static final int WS_THICKFRAME = 0x00040000; + + private static WindowsDisplay current_display; private static boolean cursor_clipped; @@ -147,6 +169,10 @@ private boolean isFocused; private boolean did_maximize; private boolean inAppActivate; + private boolean resized; + private boolean resizable; + private int width; + private int height; private long hwnd; private long hdc; @@ -191,7 +217,13 @@ } peer_info.initDC(getHwnd(), getHdc()); showWindow(getHwnd(), SW_SHOWDEFAULT); + + updateWidthAndHeight(); + if ( parent == null ) { + if(Display.isResizable()) { + setResizable(true); + } setForegroundWindow(getHwnd()); setFocus(getHwnd()); } @@ -201,6 +233,14 @@ throw e; } } + + private void updateWidthAndHeight() { + getClientRect(hwnd, rect_buffer); + rect.copyFromBuffer(rect_buffer); + width = rect.right - rect.left; + height = rect.bottom - rect.top; + } + private static native long nCreateWindow(int x, int y, int width, int height, boolean undecorated, boolean child_window, long parent_hwnd) throws LWJGLException; private static boolean isUndecorated() { @@ -695,6 +735,9 @@ private static native long createIcon(int width, int height, IntBuffer icon); private static native void destroyIcon(long handle); private static native long sendMessage(long hwnd, long msg, long wparam, long lparam); + private static native long setWindowLongPtr(long hwnd, int nindex, long longPtr); + private static native long getWindowLongPtr(long hwnd, int nindex); + private static native boolean setWindowPos(long hwnd, long hwnd_after, int x, int y, int cx, int cy, long uflags); private void handleMouseButton(int button, int state, long millis) { if (mouse != null) { @@ -820,6 +863,14 @@ break; } return defWindowProc(hwnd, msg, wParam, lParam); + case WM_ENTERSIZEMOVE: + return defWindowProc(hwnd, msg, wParam, lParam); + case WM_EXITSIZEMOVE: + return defWindowProc(hwnd, msg, wParam, lParam); + case WM_SIZING: + resized = true; + updateWidthAndHeight(); + return defWindowProc(hwnd, msg, wParam, lParam); case WM_KILLFOCUS: appActivate(false); return 0; @@ -900,10 +951,10 @@ case WM_PAINT: is_dirty = true; return defWindowProc(hwnd, msg, wParam, lParam); - case WM_MOUSELEAVE: - mouseInside = false; - trackingMouse = false; - return defWindowProc(hwnd, msg, wParam, lParam); + case WM_MOUSELEAVE: + mouseInside = false; + trackingMouse = false; + return defWindowProc(hwnd, msg, wParam, lParam); case WM_CANCELMODE: nReleaseCapture(); /* fall through */ @@ -919,11 +970,11 @@ } public int getWidth() { - return Display.getDisplayMode().getWidth(); + return width; } public int getHeight() { - return Display.getDisplayMode().getHeight(); + return height; } private int firstMouseButtonDown() { @@ -942,10 +993,40 @@ } public void setResizable(boolean resizable) { - + if(this.resizable != resizable) { + long style = getWindowLongPtr(hwnd, GWL_STYLE); + long styleex = getWindowLongPtr(hwnd, GWL_EXSTYLE); + + // update frame style + if(resizable) { + setWindowLongPtr(hwnd, GWL_STYLE, style |= WS_THICKFRAME); + } else { + setWindowLongPtr(hwnd, GWL_STYLE, style &= ~WS_THICKFRAME); + } + + // from the existing client rect, determine the new window rect + // based on the style changes - using AdjustWindowRectEx. + getClientRect(hwnd, rect_buffer); + rect.copyFromBuffer(rect_buffer); + adjustWindowRectEx(rect_buffer, style, false, styleex); + rect.copyFromBuffer(rect_buffer); + + // force a frame update and resize accordingly + setWindowPos(hwnd, HWND_TOP, 0, 0, rect.right - rect.left, rect.bottom - rect.top, SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED); + + updateWidthAndHeight(); + resized = false; + } + this.resizable = resizable; } + private native boolean adjustWindowRectEx(IntBuffer rectBuffer, long style, boolean menu, long styleex); + public boolean wasResized() { + if(resized) { + resized = false; + return true; + } return false; } @@ -981,7 +1062,7 @@ } public String toString() { - return "Rect: top = " + top + " bottom = " + bottom + " left = " + left + " right = " + right; + return "Rect: top = " + top + " bottom = " + bottom + " left = " + left + " right = " + right + ", width: " + (right - left) + ", height: " + (bottom - top); } } } Modified: trunk/LWJGL/src/java/org/lwjgl/test/input/MouseTest.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/input/MouseTest.java 2011-07-17 09:37:35 UTC (rev 3595) +++ trunk/LWJGL/src/java/org/lwjgl/test/input/MouseTest.java 2011-07-21 22:52:16 UTC (rev 3596) @@ -354,6 +354,10 @@ if(Keyboard.getEventKey() == Keyboard.KEY_SPACE && Keyboard.getEventKeyState()) { Mouse.setGrabbed(!Mouse.isGrabbed()); } + + if(Keyboard.getEventKey() == Keyboard.KEY_R && Keyboard.getEventKeyState()) { + Display.setResizable(!Display.isResizable()); + } } } Modified: trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Display.c =================================================================== --- trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Display.c 2011-07-17 09:37:35 UTC (rev 3595) +++ trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Display.c 2011-07-21 22:52:16 UTC (rev 3596) @@ -427,6 +427,32 @@ return SendMessage(hwnd, (UINT)msg, (WPARAM)wparam, (LPARAM)lparam); } +JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_WindowsDisplay_setWindowLongPtr + (JNIEnv *env, jclass clazz, jlong hwnd_ptr, jint nindex, jlong longPtr) { + + HWND hwnd = (HWND)(INT_PTR)hwnd_ptr; + return SetWindowLongPtr(hwnd, nindex, (LONG_PTR) longPtr); +} + +JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_WindowsDisplay_getWindowLongPtr + (JNIEnv *env, jclass clazz, jlong hwnd_ptr, jint nindex) { + + HWND hwnd = (HWND)(INT_PTR)hwnd_ptr; + jlong result = GetWindowLongPtr(hwnd, nindex); + return result; +} + +JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_WindowsDisplay_setWindowPos + (JNIEnv *env, jclass clazz, jlong hwnd_ptr, jlong hwnd_after_ptr, jint x, jint y, jint width, jint height, jlong uflags) { + + jboolean result; + HWND hwnd = (HWND)(INT_PTR)hwnd_ptr; + HWND hwnd_after = (HWND)(INT_PTR)hwnd_after_ptr; + + result = SetWindowPos(hwnd, hwnd_after, x, y, width, height, (UINT) uflags); + return result; +} + JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nSetCursorPosition (JNIEnv * env, jclass unused, jint x, jint y) { if (!SetCursorPos(x, y)) @@ -441,6 +467,16 @@ copyRectToBuffer(env, &clientRect, rect_buffer); } +JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_WindowsDisplay_adjustWindowRectEx + (JNIEnv *env, jclass unused, jobject rect_buffer, jlong style, jboolean menu, jlong styleex) { + jboolean result; + RECT clientRect; + copyBufferToRect(env, rect_buffer, &clientRect); + result = AdjustWindowRectEx(&clientRect, style, menu, styleex); + copyRectToBuffer(env, &clientRect, rect_buffer); + return result; +} + JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplay_nSetNativeCursor (JNIEnv *env, jclass unused, jlong hwnd_int, jobject handle_buffer) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sp...@us...> - 2011-07-29 11:30:22
|
Revision: 3602 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3602&view=rev Author: spasi Date: 2011-07-29 11:30:14 +0000 (Fri, 29 Jul 2011) Log Message: ----------- Added support for NV_path_rendering. Made MappedObjectUnsafe package private. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opengl/GLChecks.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/util/generator/AutoSize.java trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectUnsafe.java Added Paths: ----------- trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_path_rendering.java Modified: trunk/LWJGL/src/java/org/lwjgl/opengl/GLChecks.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opengl/GLChecks.java 2011-07-24 09:38:46 UTC (rev 3601) +++ trunk/LWJGL/src/java/org/lwjgl/opengl/GLChecks.java 2011-07-29 11:30:14 UTC (rev 3602) @@ -31,11 +31,12 @@ */ package org.lwjgl.opengl; -import java.nio.Buffer; - import org.lwjgl.BufferUtils; import org.lwjgl.LWJGLUtil; +import java.nio.Buffer; +import java.nio.FloatBuffer; + import static org.lwjgl.opengl.ARBBufferObject.*; import static org.lwjgl.opengl.ATIVertexArrayObject.*; import static org.lwjgl.opengl.EXTAbgr.*; @@ -43,6 +44,7 @@ import static org.lwjgl.opengl.EXTDirectStateAccess.*; import static org.lwjgl.opengl.GL11.*; import static org.lwjgl.opengl.GL15.*; +import static org.lwjgl.opengl.NVPathRendering.*; /** * A class to check buffer boundaries in GL methods. Many GL @@ -55,7 +57,7 @@ * * @author cix_foo <ci...@us...> * @version $Revision$ - * $Id$ + * $Id$ */ class GLChecks { @@ -81,25 +83,25 @@ /** Helper method to ensure that array buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */ static void ensureArrayVBOdisabled(ContextCapabilities caps) { - if( LWJGLUtil.CHECKS && StateTracker.getReferences(caps).arrayBuffer != 0 ) + if ( LWJGLUtil.CHECKS && StateTracker.getReferences(caps).arrayBuffer != 0 ) throw new OpenGLException("Cannot use Buffers when Array Buffer Object is enabled"); } /** Helper method to ensure that array buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */ static void ensureArrayVBOenabled(ContextCapabilities caps) { - if( LWJGLUtil.CHECKS && StateTracker.getReferences(caps).arrayBuffer == 0 ) + if ( LWJGLUtil.CHECKS && StateTracker.getReferences(caps).arrayBuffer == 0 ) throw new OpenGLException("Cannot use offsets when Array Buffer Object is disabled"); } /** Helper method to ensure that element array buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */ static void ensureElementVBOdisabled(ContextCapabilities caps) { - if( LWJGLUtil.CHECKS && StateTracker.getElementArrayBufferBound(caps) != 0 ) + if ( LWJGLUtil.CHECKS && StateTracker.getElementArrayBufferBound(caps) != 0 ) throw new OpenGLException("Cannot use Buffers when Element Array Buffer Object is enabled"); } /** Helper method to ensure that element array buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */ static void ensureElementVBOenabled(ContextCapabilities caps) { - if( LWJGLUtil.CHECKS && StateTracker.getElementArrayBufferBound(caps) == 0 ) + if ( LWJGLUtil.CHECKS && StateTracker.getElementArrayBufferBound(caps) == 0 ) throw new OpenGLException("Cannot use offsets when Element Array Buffer Object is disabled"); } @@ -209,10 +211,10 @@ case GL_FLOAT: bpe = 4; break; - default : + default: // TODO: Add more types (like the GL12 types GL_UNSIGNED_INT_8_8_8_8 return 0; - // throw new IllegalArgumentException("Unknown type " + type); + // throw new IllegalArgumentException("Unknown type " + type); } int epp; switch ( format ) { @@ -233,7 +235,7 @@ case GL_BGRA_EXT: epp = 4; break; - default : + default: // TODO: Add more formats. Assuming 4 is too wasteful on buffer sizes where e.g. 1 is enough (like GL_DEPTH_COMPONENT) return 0; /* // Assume 4 elements per pixel @@ -242,4 +244,116 @@ return bpe * epp; } -} + + // NV_path_rendering checks + + static int calculateBytesPerCharCode(int type) { + switch ( type ) { + case GL_UNSIGNED_BYTE: + case GL_UTF8_NV: + return 1; + case GL_UNSIGNED_SHORT: + case GL_2_BYTES: + case GL_UTF16_NV: + return 2; + case GL_3_BYTES: + return 3; + case GL_4_BYTES: + return 4; + default: + throw new IllegalArgumentException("Unsupported charcode type: " + type); + } + } + + static int calculateBytesPerPathName(int pathNameType) { + switch ( pathNameType ) { + case GL_BYTE: + case GL_UNSIGNED_BYTE: + case GL_UTF8_NV: + return 1; + case GL_SHORT: + case GL_UNSIGNED_SHORT: + case GL_2_BYTES: + case GL_UTF16_NV: + return 2; + case GL_3_BYTES: + return 3; + case GL_INT: + case GL_UNSIGNED_INT: + case GL_FLOAT: + case GL_4_BYTES: + return 4; + default: + throw new IllegalArgumentException("Unsupported path name type: " + pathNameType); + } + } + + static int calculateTransformPathValues(int transformType) { + switch ( transformType ) { + case GL_NONE: + return 0; + case GL_TRANSLATE_X_NV: + case GL_TRANSLATE_Y_NV: + return 1; + case GL_TRANSLATE_2D_NV: + return 2; + case GL_TRANSLATE_3D_NV: + return 3; + case GL_AFFINE_2D_NV: + case GL_TRANSPOSE_AFFINE_2D_NV: + return 6; + case GL_AFFINE_3D_NV: + case GL_TRANSPOSE_AFFINE_3D_NV: + return 12; + default: + throw new IllegalArgumentException("Unsupported transform type: " + transformType); + } + } + + static int calculatePathColorGenCoeffsCount(int genMode, int colorFormat) { + final int coeffsPerComponent = calculatePathGenCoeffsPerComponent(genMode); + + switch ( colorFormat ) { + case GL_RGB: + return 3 * coeffsPerComponent; + case GL_RGBA: + return 4 * coeffsPerComponent; + default: + return coeffsPerComponent; + } + } + + static int calculatePathTextGenCoeffsPerComponent(FloatBuffer coeffs, int genMode) { + if ( genMode == GL_NONE ) + return 0; + + return coeffs.remaining() / calculatePathGenCoeffsPerComponent(genMode); + } + + private static int calculatePathGenCoeffsPerComponent(int genMode) { + switch ( genMode ) { + case GL_NONE: + return 0; + case GL_OBJECT_LINEAR: + case GL_PATH_OBJECT_BOUNDING_BOX_NV: + return 3; + case GL_EYE_LINEAR: + return 4; + default: + throw new IllegalArgumentException("Unsupported gen mode: " + genMode); + } + } + + static int calculateMetricsSize(int metricQueryMask, int stride) { + if ( LWJGLUtil.DEBUG && (stride < 0 || (stride % 4) != 0) ) + throw new IllegalArgumentException("Invalid stride value: " + stride); + + final int metrics = Integer.bitCount(metricQueryMask); + + if ( LWJGLUtil.DEBUG && (stride >> 2) < metrics ) + throw new IllegalArgumentException("The queried metrics do not fit in the specified stride: " + stride); + + return stride == 0 ? metrics : (stride >> 2); + } + +} \ No newline at end of file Modified: trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectBench.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectBench.java 2011-07-24 09:38:46 UTC (rev 3601) +++ trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectBench.java 2011-07-29 11:30:14 UTC (rev 3602) @@ -32,7 +32,6 @@ package org.lwjgl.test.mapped; import org.lwjgl.MemoryUtil; -import org.lwjgl.util.mapped.MappedObjectUnsafe; import java.nio.ByteBuffer; import java.util.Arrays; Modified: trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java 2011-07-24 09:38:46 UTC (rev 3601) +++ trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java 2011-07-29 11:30:14 UTC (rev 3602) @@ -33,7 +33,6 @@ import org.lwjgl.MemoryUtil; import org.lwjgl.util.mapped.MappedHelper; -import org.lwjgl.util.mapped.MappedObjectUnsafe; import java.nio.ByteBuffer; Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/AutoSize.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/AutoSize.java 2011-07-24 09:38:46 UTC (rev 3601) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/AutoSize.java 2011-07-29 11:30:14 UTC (rev 3602) @@ -49,6 +49,7 @@ public @interface AutoSize { String value(); // The name of the Buffer parameter String expression() default ""; // This value is added after the argument + boolean useExpression() default false; // When this is true, the expression result will be used directly. boolean canBeNull() default false; // When this is true and the Buffer parameter is null, 0 will be used. boolean isNative() default false; // When this is true, auto-sizing will be performed in native code. } Modified: trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java 2011-07-24 09:38:46 UTC (rev 3601) +++ trunk/LWJGL/src/java/org/lwjgl/util/generator/JavaMethodsGenerator.java 2011-07-29 11:30:14 UTC (rev 3602) @@ -458,25 +458,27 @@ writer.print(auto_type); } else if (AutoSize.class.equals(param_type)) { final AutoSize auto_size_annotation = param.getAnnotation(AutoSize.class); - final String auto_parameter_name = auto_size_annotation.value(); - final ParameterDeclaration auto_target_param = Utils.findParameter(method, auto_parameter_name); - final TypeInfo auto_target_type_info = typeinfos_instance.get(auto_target_param); - final boolean shift_remaining = !hasAnyParameterAutoTypeAnnotation(method, auto_target_param) && Utils.isParameterMultiTyped(auto_target_param); - int shifting = 0; - if ( shift_remaining ) { - shifting = getBufferElementSizeExponent(auto_target_type_info.getType()); - if ( shifting > 0 ) - writer.print("("); + if ( !auto_size_annotation.useExpression() ) { + final String auto_parameter_name = auto_size_annotation.value(); + final ParameterDeclaration auto_target_param = Utils.findParameter(method, auto_parameter_name); + final TypeInfo auto_target_type_info = typeinfos_instance.get(auto_target_param); + final boolean shift_remaining = !hasAnyParameterAutoTypeAnnotation(method, auto_target_param) && Utils.isParameterMultiTyped(auto_target_param); + int shifting = 0; + if ( shift_remaining ) { + shifting = getBufferElementSizeExponent(auto_target_type_info.getType()); + if ( shifting > 0 ) + writer.print("("); + } + if ( auto_size_annotation.canBeNull() ) + writer.print("(" + auto_parameter_name + " == null ? 0 : " + auto_parameter_name + ".remaining())"); + else + writer.print(auto_parameter_name + ".remaining()"); + // Shift the remaining if the target parameter is multityped and there's no AutoType to track type + if (shift_remaining && shifting > 0) { + writer.print(" << " + shifting); + writer.print(")"); + } } - if ( auto_size_annotation.canBeNull() ) - writer.print("(" + auto_parameter_name + " == null ? 0 : " + auto_parameter_name + ".remaining())"); - else - writer.print(auto_parameter_name + ".remaining()"); - // Shift the remaining if the target parameter is multityped and there's no AutoType to track type - if (shift_remaining && shifting > 0) { - writer.print(" << " + shifting); - writer.print(")"); - } writer.print(auto_size_annotation.expression()); } else throw new RuntimeException("Unknown auto annotation " + param_type); Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java 2011-07-24 09:38:46 UTC (rev 3601) +++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedHelper.java 2011-07-29 11:30:14 UTC (rev 3602) @@ -36,6 +36,8 @@ import java.nio.ByteBuffer; +import static org.lwjgl.util.mapped.MappedObjectUnsafe.*; + /** * [INTERNAL USE ONLY] * <p/> @@ -122,7 +124,7 @@ dst.checkRange(bytes); } - MappedObjectUnsafe.INSTANCE.copyMemory(src.viewAddress, dst.viewAddress, bytes); + INSTANCE.copyMemory(src.viewAddress, dst.viewAddress, bytes); } public static ByteBuffer newBuffer(long address, int capacity) { @@ -134,257 +136,257 @@ // byte public static void bput(byte value, long addr) { - MappedObjectUnsafe.INSTANCE.putByte(addr, value); + INSTANCE.putByte(addr, value); } public static void bput(MappedObject mapped, byte value, int fieldOffset) { - MappedObjectUnsafe.INSTANCE.putByte(mapped.viewAddress + fieldOffset, value); + INSTANCE.putByte(mapped.viewAddress + fieldOffset, value); } public static byte bget(long addr) { - return MappedObjectUnsafe.INSTANCE.getByte(addr); + return INSTANCE.getByte(addr); } public static byte bget(MappedObject mapped, int fieldOffset) { - return MappedObjectUnsafe.INSTANCE.getByte(mapped.viewAddress + fieldOffset); + return INSTANCE.getByte(mapped.viewAddress + fieldOffset); } public static void bvput(byte value, long addr) { - MappedObjectUnsafe.INSTANCE.putByteVolatile(null, addr, value); + INSTANCE.putByteVolatile(null, addr, value); } public static void bvput(MappedObject mapped, byte value, int fieldOffset) { - MappedObjectUnsafe.INSTANCE.putByteVolatile(null, mapped.viewAddress + fieldOffset, value); + INSTANCE.putByteVolatile(null, mapped.viewAddress + fieldOffset, value); } public static byte bvget(long addr) { - return MappedObjectUnsafe.INSTANCE.getByteVolatile(null, addr); + return INSTANCE.getByteVolatile(null, addr); } public static byte bvget(MappedObject mapped, int fieldOffset) { - return MappedObjectUnsafe.INSTANCE.getByteVolatile(null, mapped.viewAddress + fieldOffset); + return INSTANCE.getByteVolatile(null, mapped.viewAddress + fieldOffset); } // short public static void sput(short value, long addr) { - MappedObjectUnsafe.INSTANCE.putShort(addr, value); + INSTANCE.putShort(addr, value); } public static void sput(MappedObject mapped, short value, int fieldOffset) { - MappedObjectUnsafe.INSTANCE.putShort(mapped.viewAddress + fieldOffset, value); + INSTANCE.putShort(mapped.viewAddress + fieldOffset, value); } public static short sget(long addr) { - return MappedObjectUnsafe.INSTANCE.getShort(addr); + return INSTANCE.getShort(addr); } public static short sget(MappedObject mapped, int fieldOffset) { - return MappedObjectUnsafe.INSTANCE.getShort(mapped.viewAddress + fieldOffset); + return INSTANCE.getShort(mapped.viewAddress + fieldOffset); } public static void svput(short value, long addr) { - MappedObjectUnsafe.INSTANCE.putShortVolatile(null, addr, value); + INSTANCE.putShortVolatile(null, addr, value); } public static void svput(MappedObject mapped, short value, int fieldOffset) { - MappedObjectUnsafe.INSTANCE.putShortVolatile(null, mapped.viewAddress + fieldOffset, value); + INSTANCE.putShortVolatile(null, mapped.viewAddress + fieldOffset, value); } public static short svget(long addr) { - return MappedObjectUnsafe.INSTANCE.getShortVolatile(null, addr); + return INSTANCE.getShortVolatile(null, addr); } public static short svget(MappedObject mapped, int fieldOffset) { - return MappedObjectUnsafe.INSTANCE.getShortVolatile(null, mapped.viewAddress + fieldOffset); + return INSTANCE.getShortVolatile(null, mapped.viewAddress + fieldOffset); } // char public static void cput(char value, long addr) { - MappedObjectUnsafe.INSTANCE.putChar(addr, value); + INSTANCE.putChar(addr, value); } public static void cput(MappedObject mapped, char value, int fieldOffset) { - MappedObjectUnsafe.INSTANCE.putChar(mapped.viewAddress + fieldOffset, value); + INSTANCE.putChar(mapped.viewAddress + fieldOffset, value); } public static char cget(long addr) { - return MappedObjectUnsafe.INSTANCE.getChar(addr); + return INSTANCE.getChar(addr); } public static char cget(MappedObject mapped, int fieldOffset) { - return MappedObjectUnsafe.INSTANCE.getChar(mapped.viewAddress + fieldOffset); + return INSTANCE.getChar(mapped.viewAddress + fieldOffset); } public static void cvput(char value, long addr) { - MappedObjectUnsafe.INSTANCE.putCharVolatile(null, addr, value); + INSTANCE.putCharVolatile(null, addr, value); } public static void cvput(MappedObject mapped, char value, int fieldOffset) { - MappedObjectUnsafe.INSTANCE.putCharVolatile(null, mapped.viewAddress + fieldOffset, value); + INSTANCE.putCharVolatile(null, mapped.viewAddress + fieldOffset, value); } public static char cvget(long addr) { - return MappedObjectUnsafe.INSTANCE.getCharVolatile(null, addr); + return INSTANCE.getCharVolatile(null, addr); } public static char cvget(MappedObject mapped, int fieldOffset) { - return MappedObjectUnsafe.INSTANCE.getCharVolatile(null, mapped.viewAddress + fieldOffset); + return INSTANCE.getCharVolatile(null, mapped.viewAddress + fieldOffset); } // int public static void iput(int value, long addr) { - MappedObjectUnsafe.INSTANCE.putInt(addr, value); + INSTANCE.putInt(addr, value); } public static void iput(MappedObject mapped, int value, int fieldOffset) { - MappedObjectUnsafe.INSTANCE.putInt(mapped.viewAddress + fieldOffset, value); + INSTANCE.putInt(mapped.viewAddress + fieldOffset, value); } public static int iget(long address) { - return MappedObjectUnsafe.INSTANCE.getInt(address); + return INSTANCE.getInt(address); } public static int iget(MappedObject mapped, int fieldOffset) { - return MappedObjectUnsafe.INSTANCE.getInt(mapped.viewAddress + fieldOffset); + return INSTANCE.getInt(mapped.viewAddress + fieldOffset); } public static void ivput(int value, long addr) { - MappedObjectUnsafe.INSTANCE.putIntVolatile(null, addr, value); + INSTANCE.putIntVolatile(null, addr, value); } public static void ivput(MappedObject mapped, int value, int fieldOffset) { - MappedObjectUnsafe.INSTANCE.putIntVolatile(null, mapped.viewAddress + fieldOffset, value); + INSTANCE.putIntVolatile(null, mapped.viewAddress + fieldOffset, value); } public static int ivget(long address) { - return MappedObjectUnsafe.INSTANCE.getIntVolatile(null, address); + return INSTANCE.getIntVolatile(null, address); } public static int ivget(MappedObject mapped, int fieldOffset) { - return MappedObjectUnsafe.INSTANCE.getIntVolatile(null, mapped.viewAddress + fieldOffset); + return INSTANCE.getIntVolatile(null, mapped.viewAddress + fieldOffset); } // float public static void fput(float value, long addr) { - MappedObjectUnsafe.INSTANCE.putFloat(addr, value); + INSTANCE.putFloat(addr, value); } public static void fput(MappedObject mapped, float value, int fieldOffset) { - MappedObjectUnsafe.INSTANCE.putFloat(mapped.viewAddress + fieldOffset, value); + INSTANCE.putFloat(mapped.viewAddress + fieldOffset, value); } public static float fget(long addr) { - return MappedObjectUnsafe.INSTANCE.getFloat(addr); + return INSTANCE.getFloat(addr); } public static float fget(MappedObject mapped, int fieldOffset) { - return MappedObjectUnsafe.INSTANCE.getFloat(mapped.viewAddress + fieldOffset); + return INSTANCE.getFloat(mapped.viewAddress + fieldOffset); } public static void fvput(float value, long addr) { - MappedObjectUnsafe.INSTANCE.putFloatVolatile(null, addr, value); + INSTANCE.putFloatVolatile(null, addr, value); } public static void fvput(MappedObject mapped, float value, int fieldOffset) { - MappedObjectUnsafe.INSTANCE.putFloatVolatile(null, mapped.viewAddress + fieldOffset, value); + INSTANCE.putFloatVolatile(null, mapped.viewAddress + fieldOffset, value); } public static float fvget(long addr) { - return MappedObjectUnsafe.INSTANCE.getFloatVolatile(null, addr); + return INSTANCE.getFloatVolatile(null, addr); } public static float fvget(MappedObject mapped, int fieldOffset) { - return MappedObjectUnsafe.INSTANCE.getFloatVolatile(null, mapped.viewAddress + fieldOffset); + return INSTANCE.getFloatVolatile(null, mapped.viewAddress + fieldOffset); } // long public static void jput(long value, long addr) { - MappedObjectUnsafe.INSTANCE.putLong(addr, value); + INSTANCE.putLong(addr, value); } public static void jput(MappedObject mapped, long value, int fieldOffset) { - MappedObjectUnsafe.INSTANCE.putLong(mapped.viewAddress + fieldOffset, value); + INSTANCE.putLong(mapped.viewAddress + fieldOffset, value); } public static long jget(long addr) { - return MappedObjectUnsafe.INSTANCE.getLong(addr); + return INSTANCE.getLong(addr); } public static long lget(MappedObject mapped, int fieldOffset) { - return MappedObjectUnsafe.INSTANCE.getLong(mapped.viewAddress + fieldOffset); + return INSTANCE.getLong(mapped.viewAddress + fieldOffset); } public static void jvput(long value, long addr) { - MappedObjectUnsafe.INSTANCE.putLongVolatile(null, addr, value); + INSTANCE.putLongVolatile(null, addr, value); } public static void jvput(MappedObject mapped, long value, int fieldOffset) { - MappedObjectUnsafe.INSTANCE.putLongVolatile(null, mapped.viewAddress + fieldOffset, value); + INSTANCE.putLongVolatile(null, mapped.viewAddress + fieldOffset, value); } public static long jvget(long addr) { - return MappedObjectUnsafe.INSTANCE.getLongVolatile(null, addr); + return INSTANCE.getLongVolatile(null, addr); } public static long lvget(MappedObject mapped, int fieldOffset) { - return MappedObjectUnsafe.INSTANCE.getLongVolatile(null, mapped.viewAddress + fieldOffset); + return INSTANCE.getLongVolatile(null, mapped.viewAddress + fieldOffset); } // address public static void aput(long value, long addr) { - MappedObjectUnsafe.INSTANCE.putAddress(addr, value); + INSTANCE.putAddress(addr, value); } public static void aput(MappedObject mapped, long value, int fieldOffset) { - MappedObjectUnsafe.INSTANCE.putAddress(mapped.viewAddress + fieldOffset, value); + INSTANCE.putAddress(mapped.viewAddress + fieldOffset, value); } public static long aget(long addr) { - return MappedObjectUnsafe.INSTANCE.getAddress(addr); + return INSTANCE.getAddress(addr); } public static long aget(MappedObject mapped, int fieldOffset) { - return MappedObjectUnsafe.INSTANCE.getAddress(mapped.viewAddress + fieldOffset); + return INSTANCE.getAddress(mapped.viewAddress + fieldOffset); } // double public static void dput(double value, long addr) { - MappedObjectUnsafe.INSTANCE.putDouble(addr, value); + INSTANCE.putDouble(addr, value); } public static void dput(MappedObject mapped, double value, int fieldOffset) { - MappedObjectUnsafe.INSTANCE.putDouble(mapped.viewAddress + fieldOffset, value); + INSTANCE.putDouble(mapped.viewAddress + fieldOffset, value); } public static double dget(long addr) { - return MappedObjectUnsafe.INSTANCE.getDouble(addr); + return INSTANCE.getDouble(addr); } public static double dget(MappedObject mapped, int fieldOffset) { - return MappedObjectUnsafe.INSTANCE.getDouble(mapped.viewAddress + fieldOffset); + return INSTANCE.getDouble(mapped.viewAddress + fieldOffset); } public static void dvput(double value, long addr) { - MappedObjectUnsafe.INSTANCE.putDoubleVolatile(null, addr, value); + INSTANCE.putDoubleVolatile(null, addr, value); } public static void dvput(MappedObject mapped, double value, int fieldOffset) { - MappedObjectUnsafe.INSTANCE.putDoubleVolatile(null, mapped.viewAddress + fieldOffset, value); + INSTANCE.putDoubleVolatile(null, mapped.viewAddress + fieldOffset, value); } public static double dvget(long addr) { - return MappedObjectUnsafe.INSTANCE.getDoubleVolatile(null, addr); + return INSTANCE.getDoubleVolatile(null, addr); } public static double dvget(MappedObject mapped, int fieldOffset) { - return MappedObjectUnsafe.INSTANCE.getDoubleVolatile(null, mapped.viewAddress + fieldOffset); + return INSTANCE.getDoubleVolatile(null, mapped.viewAddress + fieldOffset); } } \ No newline at end of file Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java 2011-07-24 09:38:46 UTC (rev 3601) +++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java 2011-07-29 11:30:14 UTC (rev 3602) @@ -549,10 +549,10 @@ final Map<Integer, MappedSubtypeInfo> arrayVars = new HashMap<Integer, MappedSubtypeInfo>(); /* - We need this map because we insert/remove instructions from the stream and we need a way - to match each original instruction with the corresponding frame. - TODO: Can we keep track of everything more efficiently without a map? - */ + We need this map because we insert/remove instructions from the stream and we need a way + to match each original instruction with the corresponding frame. + TODO: Can we keep track of everything more efficiently without a map? + */ final Map<AbstractInsnNode, Frame<BasicValue>> frameMap = new HashMap<AbstractInsnNode, Frame<BasicValue>>(); for ( int i = 0; i < frames.length; i++ ) frameMap.put(instructions.get(i), frames[i]); Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectUnsafe.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectUnsafe.java 2011-07-24 09:38:46 UTC (rev 3601) +++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectUnsafe.java 2011-07-29 11:30:14 UTC (rev 3602) @@ -42,9 +42,9 @@ * * @author Riven */ -public class MappedObjectUnsafe { +final class MappedObjectUnsafe { - public static final Unsafe INSTANCE = getUnsafeInstance(); + static final Unsafe INSTANCE = getUnsafeInstance(); private static final long BUFFER_ADDRESS_OFFSET = getObjectFieldOffset(ByteBuffer.class, "address"); private static final long BUFFER_CAPACITY_OFFSET = getObjectFieldOffset(ByteBuffer.class, "capacity"); Added: trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_path_rendering.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_path_rendering.java (rev 0) +++ trunk/LWJGL/src/templates/org/lwjgl/opengl/NV_path_rendering.java 2011-07-29 11:30:14 UTC (rev 3602) @@ -0,0 +1,515 @@ +/* + * 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.util.generator.*; +import org.lwjgl.util.generator.opengl.*; + +import java.nio.ByteBuffer; +import java.nio.FloatBuffer; +import java.nio.IntBuffer; + +public interface NV_path_rendering { + + /** + * Accepted in elements of the <commands> array parameter of + * PathCommandsNV and PathSubCommandsNV: + */ + int GL_CLOSE_PATH_NV = 0x00, + GL_MOVE_TO_NV = 0x02, + GL_RELATIVE_MOVE_TO_NV = 0x03, + GL_LINE_TO_NV = 0x04, + GL_RELATIVE_LINE_TO_NV = 0x05, + GL_HORIZONTAL_LINE_TO_NV = 0x06, + GL_RELATIVE_HORIZONTAL_LINE_TO_NV = 0x07, + GL_VERTICAL_LINE_TO_NV = 0x08, + GL_RELATIVE_VERTICAL_LINE_TO_NV = 0x09, + GL_QUADRATIC_CURVE_TO_NV = 0x0A, + GL_RELATIVE_QUADRATIC_CURVE_TO_NV = 0x0B, + GL_CUBIC_CURVE_TO_NV = 0x0C, + GL_RELATIVE_CUBIC_CURVE_TO_NV = 0x0D, + GL_SMOOTH_QUADRATIC_CURVE_TO_NV = 0x0E, + GL_RELATIVE_SMOOTH_QUADRATIC_CURVE_TO_NV = 0x0F, + GL_SMOOTH_CUBIC_CURVE_TO_NV = 0x10, + GL_RELATIVE_SMOOTH_CUBIC_CURVE_TO_NV = 0x11, + GL_SMALL_CCW_ARC_TO_NV = 0x12, + GL_RELATIVE_SMALL_CCW_ARC_TO_NV = 0x13, + GL_SMALL_CW_ARC_TO_NV = 0x14, + GL_RELATIVE_SMALL_CW_ARC_TO_NV = 0x15, + GL_LARGE_CCW_ARC_TO_NV = 0x16, + GL_RELATIVE_LARGE_CCW_ARC_TO_NV = 0x17, + GL_LARGE_CW_ARC_TO_NV = 0x18, + GL_RELATIVE_LARGE_CW_ARC_TO_NV = 0x19, + GL_CIRCULAR_CCW_ARC_TO_NV = 0xF8, + GL_CIRCULAR_CW_ARC_TO_NV = 0xFA, + GL_CIRCULAR_TANGENT_ARC_TO_NV = 0xFC, + GL_ARC_TO_NV = 0xFE, + GL_RELATIVE_ARC_TO_NV = 0xFF; + + /** Accepted by the <format> parameter of PathStringNV: */ + int GL_PATH_FORMAT_SVG_NV = 0x9070, + GL_PATH_FORMAT_PS_NV = 0x9071; + + /** + * Accepted by the <fontTarget> parameter of PathGlyphsNV and + * PathGlyphRangeNV: + */ + int GL_STANDARD_FONT_NAME_NV = 0x9072, + GL_SYSTEM_FONT_NAME_NV = 0x9073, + GL_FILE_NAME_NV = 0x9074; + + /** + * Accepted by the <handleMissingGlyph> parameter of PathGlyphsNV and + * PathGlyphRangeNV: + */ + int GL_SKIP_MISSING_GLYPH_NV = 0x90A9, + GL_USE_MISSING_GLYPH_NV = 0x90AA; + + /** + * Accepted by the <pname> parameter of PathParameterfNV, + * PathParameterfvNV, GetPathParameterfvNV, PathParameteriNV, + * PathParameterivNV, and GetPathParameterivNV: + */ + int GL_PATH_STROKE_WIDTH_NV = 0x9075, + GL_PATH_INITIAL_END_CAP_NV = 0x9077, + GL_PATH_TERMINAL_END_CAP_NV = 0x9078, + GL_PATH_JOIN_STYLE_NV = 0x9079, + GL_PATH_MITER_LIMIT_NV = 0x907A, + GL_PATH_INITIAL_DASH_CAP_NV = 0x907C, + GL_PATH_TERMINAL_DASH_CAP_NV = 0x907D, + GL_PATH_DASH_OFFSET_NV = 0x907E, + GL_PATH_CLIENT_LENGTH_NV = 0x907F, + GL_PATH_DASH_OFFSET_RESET_NV = 0x90B4, + + GL_PATH_FILL_MODE_NV = 0x9080, + GL_PATH_FILL_MASK_NV = 0x9081, + GL_PATH_FILL_COVER_MODE_NV = 0x9082, + GL_PATH_STROKE_COVER_MODE_NV = 0x9083, + GL_PATH_STROKE_MASK_NV = 0x9084; + + /** + * Accepted by the <pname> parameter of PathParameterfNV and + * PathParameterfvNV: + */ + int GL_PATH_END_CAPS_NV = 0x9076, + GL_PATH_DASH_CAPS_NV = 0x907B; + + /** + * Accepted by the <fillMode> parameter of StencilFillPathNV and + * StencilFillPathInstancedNV: + */ + int GL_COUNT_UP_NV = 0x9088, + GL_COUNT_DOWN_NV = 0x9089; + + /** + * Accepted by the <color> parameter of PathColorGenNV, + * GetPathColorGenivNV, and GetPathColorGenfvNV: + */ + int GL_PRIMARY_COLOR = 0x8577, // from OpenGL 1.3 + GL_PRIMARY_COLOR_NV = 0x852C, // from NV_register_combiners + GL_SECONDARY_COLOR_NV = 0x852D; // from NV_register_combiners + + /** + * Accepted by the <genMode> parameter of PathColorGenNV and + * PathTexGenNV: + */ + int GL_PATH_OBJECT_BOUNDING_BOX_NV = 0x908A; + + /** + * Accepted by the <coverMode> parameter of CoverFillPathNV and + * CoverFillPathInstancedNV: + */ + int GL_CONVEX_HULL_NV = 0x908B, + GL_BOUNDING_BOX_NV = 0x908D; + + /** + * Accepted by the <transformType> parameter of + * StencilFillPathInstancedNV, StencilStrokePathInstancedNV, + * CoverFillPathInstancedNV, and CoverStrokePathInstancedNV: + */ + int GL_TRANSLATE_X_NV = 0x908E, + GL_TRANSLATE_Y_NV = 0x908F, + GL_TRANSLATE_2D_NV = 0x9090, + GL_TRANSLATE_3D_NV = 0x9091, + GL_AFFINE_2D_NV = 0x9092, + GL_AFFINE_3D_NV = 0x9094, + GL_TRANSPOSE_AFFINE_2D_NV = 0x9096, + GL_TRANSPOSE_AFFINE_3D_NV = 0x9098; + + /** + * Accepted by the <type> or <pathNameType> parameter of CallLists, + * StencilFillPathInstancedNV, StencilStrokePathInstancedNV, + * CoverFillPathInstancedNV, CoverStrokePathInstancedNV, + * GetPathMetricsNV, and GetPathSpacingNV: + */ + int GL_UTF8_NV = 0x909A, + GL_UTF16_NV = 0x909B; + + /** Accepted by the <coverMode> parameter of CoverFillPathInstancedNV: */ + int GL_BOUNDING_BOX_OF_BOUNDING_BOXES_NV = 0x909C; + + /** + * Accepted by the <pname> parameter of GetPathParameterfvNV and + * GetPathParameterivNV: + */ + int GL_PATH_COMMAND_COUNT_NV = 0x909D, + GL_PATH_COORD_COUNT_NV = 0x909E, + GL_PATH_DASH_ARRAY_COUNT_NV = 0x909F, + GL_PATH_COMPUTED_LENGTH_NV = 0x90A0, + GL_PATH_FILL_BOUNDING_BOX_NV = 0x90A1, + GL_PATH_STROKE_BOUNDING_BOX_NV = 0x90A2; + + /** + * Accepted by the <value> parameter of PathParameterfNV, + * PathParameterfvNV, PathParameteriNV, and PathParameterivNV + * when <pname> is one of PATH_END_CAPS_NV, PATH_INTIAL_END_CAP_NV, + * PATH_TERMINAL_END_CAP_NV, PATH_DASH_CAPS_NV, PATH_INITIAL_DASH_CAP_NV, + * and PATH_TERMINAL_DASH_CAP_NV: + */ + int GL_SQUARE_NV = 0x90A3, + GL_ROUND_NV = 0x90A4, + GL_TRIANGULAR_NV = 0x90A5; + + /** + * Accepted by the <value> parameter of PathParameterfNV, + * PathParameterfvNV, PathParameteriNV, and PathParameterivNV + * when <pname> is PATH_JOIN_STYLE_NV: + */ + int GL_BEVEL_NV = 0x90A6, + GL_MITER_REVERT_NV = 0x90A7, + GL_MITER_TRUNCATE_NV = 0x90A8; + + /** + * Accepted by the <value> parameter of PathParameterfNV, + * PathParameterfvNV, PathParameteriNV, and PathParameterivNV when + * <pname> is PATH_DASH_OFFSET_RESET_NV + */ + int GL_MOVE_TO_RESETS_NV = 0x90B5, + GL_MOVE_TO_CONTINUES_NV = 0x90B6; + + /** Accepted by the <fontStyle> parameter of PathStringNV: */ + int GL_BOLD_BIT_NV = 0x01, + GL_ITALIC_BIT_NV = 0x02; + + /** + * Accepted by the <pname> parameter of GetBooleanv, GetIntegerv, + * GetInteger64v, GetFloatv, and GetDoublev: + */ + int GL_PATH_ERROR_POSITION_NV = 0x90AB, + + GL_PATH_FOG_GEN_MODE_NV = 0x90AC, + + GL_PATH_STENCIL_FUNC_NV = 0x90B7, + GL_PATH_STENCIL_REF_NV = 0x90B8, + GL_PATH_STENCIL_VALUE_MASK_NV = 0x90B9, + + GL_PATH_STENCIL_DEPTH_OFFSET_FACTOR_NV = 0x90BD, + GL_PATH_STENCIL_DEPTH_OFFSET_UNITS_NV = 0x90BE, + + GL_PATH_COVER_DEPTH_FUNC_NV = 0x90BF; + + /** + * Accepted as a bit within the <metricQueryMask> parameter of + * GetPathMetricRangeNV or GetPathMetricsNV: + */ + + int GL_GLYPH_WIDTH_BIT_NV = 0x01, // per-glyph metrics + GL_GLYPH_HEIGHT_BIT_NV = 0x02, + GL_GLYPH_HORIZONTAL_BEARING_X_BIT_NV = 0x04, + GL_GLYPH_HORIZONTAL_BEARING_Y_BIT_NV = 0x08, + GL_GLYPH_HORIZONTAL_BEARING_ADVANCE_BIT_NV = 0x10, + GL_GLYPH_VERTICAL_BEARING_X_BIT_NV = 0x20, + GL_GLYPH_VERTICAL_BEARING_Y_BIT_NV = 0x40, + GL_GLYPH_VERTICAL_BEARING_ADVANCE_BIT_NV = 0x80, + GL_GLYPH_HAS_KERNING_NV = 0x100, + GL_FONT_X_MIN_BOUNDS_NV = 0x00010000, // per-font face metrics + GL_FONT_Y_MIN_BOUNDS_NV = 0x00020000, + GL_FONT_X_MAX_BOUNDS_NV = 0x00040000, + GL_FONT_Y_MAX_BOUNDS_NV = 0x00080000, + GL_FONT_UNITS_PER_EM_NV = 0x00100000, + GL_FONT_ASCENDER_NV = 0x00200000, + GL_FONT_DESCENDER_NV = 0x00400000, + GL_FONT_HEIGHT_NV = 0x00800000, + GL_FONT_MAX_ADVANCE_WIDTH_NV = 0x01000000, + GL_FONT_MAX_ADVANCE_HEIGHT_NV = 0x02000000, + GL_FONT_UNDERLINE_POSITION_NV = 0x04000000, + GL_FONT_UNDERLINE_THICKNESS_NV = 0x08000000, + GL_FONT_HAS_KERNING_NV = 0x10000000; + + /** Accepted by the <pathListMode> parameter of GetPathSpacingNV: */ + int GL_ACCUM_ADJACENT_PAIRS_NV = 0x90AD, + GL_ADJACENT_PAIRS_NV = 0x90AE, + GL_FIRST_TO_REST_NV = 0x90AF; + + /** + * Accepted by the <pname> parameter of GetPathColorGenivNV, + * GetPathColorGenfvNV, GetPathTexGenivNV and GetPathTexGenfvNV: + */ + int GL_PATH_GEN_MODE_NV = 0x90B0, + GL_PATH_GEN_COEFF_NV = 0x90B1, + GL_PATH_GEN_COLOR_FORMAT_NV = 0x90B2, + GL_PATH_GEN_COMPONENTS_NV = 0x90B3; + + void glPathCommandsNV(@GLuint int path, + @AutoSize("commands") @GLsizei int numCommands, @Const @GLubyte ByteBuffer commands, + @AutoSize("coords") @GLsizei int numCoords, @GLenum int coordType, + @Const @GLvoid ByteBuffer coords); + + void glPathCoordsNV(@GLuint int path, + @AutoSize("coords") @GLsizei int numCoords, @GLenum int coordType, + @Const @GLvoid ByteBuffer coords); + + void glPathSubCommandsNV(@GLuint int path, + @GLsizei int commandStart, @GLsizei int commandsToDelete, + @AutoSize("commands") @GLsizei int numCommands, @Const @GLubyte ByteBuffer commands, + @AutoSize("coords") @GLsizei int numCoords, @GLenum int coordType, + @Const @GLvoid ByteBuffer coords); + + void glPathSubCoordsNV(@GLuint int path, + @GLsizei int coordStart, + @AutoSize("coords") @GLsizei int numCoords, @GLenum int coordType, + @Const @GLvoid ByteBuffer coords); + + void glPathStringNV(@GLuint int path, @GLenum int format, + @AutoSize("pathString") @GLsizei int length, @Const @GLvoid ByteBuffer pathString); + + void glPathGlyphsNV(@GLuint int firstPathName, + @GLenum int fontTarget, + @NullTerminated @Const @GLvoid ByteBuffer fontName, + @GLbitfield int fontStyle, + @AutoSize(value = "charcodes", expression = " / GLChecks.calculateBytesPerCharCode(type)") @GLsizei int numGlyphs, @GLenum int type, + @Const @GLvoid ByteBuffer charcodes, + @GLenum int handleMissingGlyphs, + @GLuint int pathParameterTemplate, + float emScale); + + void glPathGlyphRangeNV(@GLuint int firstPathName, + @GLenum int fontTarget, + @NullTerminated @Const @GLvoid ByteBuffer fontName, + @GLbitfield int fontStyle, + @GLuint int firstGlyph, + @GLsizei int numGlyphs, + @GLenum int handleMissingGlyphs, + @GLuint int pathParameterTemplate, + float emScale); + + void glWeightPathsNV(@GLuint int resultPath, + @AutoSize("paths") @GLsizei int numPaths, + @Const @GLuint IntBuffer paths, @Check("paths.remaining()") @Const FloatBuffer weights); + + void glCopyPathNV(@GLuint int resultPath, @GLuint int srcPath); + + void glInterpolatePathsNV(@GLuint int resultPath, + @GLuint int pathA, @GLuint int pathB, + float weight); + + void glTransformPathNV(@GLuint int resultPath, + @GLuint int srcPath, + @GLenum int transformType, + @Check(value = "GLChecks.calculateTransformPathValues(transformType)", canBeNull = true) @Const FloatBuffer transformValues); + + @StripPostfix("value") + void glPathParameterivNV(@GLuint int path, @GLenum int pname, @Check("4") @Const IntBuffer value); + + void glPathParameteriNV(@GLuint int path, @GLenum int pname, int value); + + @StripPostfix("value") + void glPathParameterfvNV(@GLuint int path, @GLenum int pname, @Check("4") @Const IntBuffer value); + + void glPathParameterfNV(@GLuint int path, @GLenum int pname, float value); + + void glPathDashArrayNV(@GLuint int path, + @AutoSize("dashArray") @GLsizei int dashCount, @Const FloatBuffer dashArray); + + // PATH NAME MANAGEMENT + + @GLuint + int glGenPathsNV(@GLsizei int range); + + void glDeletePathsNV(@GLuint int path, @GLsizei int range); + + boolean glIsPathNV(@GLuint int path); + + // PATH STENCILING + + void glPathStencilFuncNV(@GLenum int func, int ref, @GLuint int mask); + + void glPathStencilDepthOffsetNV(float factor, int units); + + void glStencilFillPathNV(@GLuint int path, + @GLenum int fillMode, @GLuint int mask); + + void glStencilStrokePathNV(@GLuint int path, + int reference, @GLuint int mask); + + void glStencilFillPathInstancedNV(@AutoSize(value="paths", expression = " / GLChecks.calculateBytesPerPathName(pathNameType)") @GLsizei int numPaths, + @GLenum int pathNameType, @Const @GLvoid ByteBuffer paths, + @Constant("0") @GLuint int pathBase, + @GLenum int fillMode, @GLuint int mask, + @GLenum int transformType, + @Check(value = "GLChecks.calculateTransformPathValues(transformType)", canBeNull = true) @Const FloatBuffer transformValues); + + void glStencilStrokePathInstancedNV(@AutoSize(value = "paths", expression = " / GLChecks.calculateBytesPerPathName(pathNameType)") @GLsizei int numPaths, + @GLenum int pathNameType, @Const @GLvoid ByteBuffer paths, + @Constant("0") @GLuint int pathBase, + int reference, @GLuint int mask, + @GLenum int transformType, + @Check(value = "GLChecks.calculateTransformPathValues(transformType)", canBeNull = true) @Const FloatBuffer transformValues); + + // PATH COVERING + + void glPathCoverDepthFuncNV(@GLenum int zfunc); + + void glPathColorGenNV(@GLenum int color, + @GLenum int genMode, + @GLenum int colorFormat, @Check(value = "GLChecks.calculatePathColorGenCoeffsCount(genMode, colorFormat)", canBeNull = true) @Const FloatBuffer coeffs); + + void glPathTexGenNV(@GLenum int texCoordSet, + @GLenum int genMode, + @AutoSize(value="coeffs", expression="GLChecks.calculatePathTextGenCoeffsPerComponent(coeffs, genMode)", useExpression = true, canBeNull = true) int components, @Check(canBeNull = true) @Const FloatBuffer coeffs); + + void glPathFogGenNV(@GLenum int genMode); + + void glCoverFillPathNV(@GLuint int path, @GLenum int coverMode); + + void glCoverStrokePathNV(@GLuint int name, @GLenum int coverMode); + + void glCoverFillPathInstancedNV(@AutoSize(value = "paths", expression = " / GLChecks.calculateBytesPerPathName(pathNameType)") @GLsizei int numPaths, + @GLenum int pathNameType, @Const @GLvoid ByteBuffer paths, + @Constant("0") @GLuint int pathBase, + @GLenum int coverMode, + @GLenum int transformType, + @Check(value = "GLChecks.calculateTransformPathValues(transformType)", canBeNull = true) @Const FloatBuffer transformValues); + + void glCoverStrokePathInstancedNV(@AutoSize(value = "paths", expression = " / GLChecks.calculateBytesPerPathName(pathNameType)") @GLsizei int numPaths, + @GLenum int pathNameType, @Const @GLvoid ByteBuffer paths, + @Constant("0") @GLuint int pathBase, + @GLenum int coverMode, + @GLenum int transformType, + @Check(value = "GLChecks.calculateTransformPathValues(transformType)", canBeNull = true) @Const FloatBuffer transformValues); + + // PATH QUERIES + + @StripPostfix("value") + void glGetPathParameterivNV(@GLuint int name, @GLenum int param, @Check("4") @OutParameter IntBuffer value); + + @Alternate("glGetPathParameterivNV") + @GLreturn("value") + @StripPostfix(value = "value", postfix = "v") + void glGetPathParameterivNV2(@GLuint int name, @GLenum int param, @OutParameter IntBuffer value); + + void glGetPathParameterfvNV(@GLuint int name, @GLenum int param, @Check("4") @OutParameter FloatBuffer value); + + @Alternate("glGetPathParameterfvNV") + @GLreturn("value") + @StripPostfix(value = "value", postfix = "v") + void glGetPathParameterfvNV2(@GLuint int name, @GLenum int param, @OutParameter FloatBuffer value); + + void glGetPathCommandsNV(@GLuint int name, @Check @OutParameter @GLubyte ByteBuffer commands); + + void glGetPathCoordsNV(@GLuint int name, @Check @OutParameter FloatBuffer coords); + + void glGetPathDashArrayNV(@GLuint int name, @Check @OutParameter FloatBuffer dashArray); + + void glGetPathMetricsNV(@GLbitfield int metricQueryMask, + @AutoSize(value = "paths", expression = " / GLChecks.calculateBytesPerPathName(pathNameType)") @GLsizei int numPaths, + @GLenum int pathNameType, @Const @GLvoid ByteBuffer paths, + @Constant("0") @GLuint int pathBase, + @GLsizei int stride, + @Check("GLChecks.calculateMetricsSize(metricQueryMask, stride)") @OutParameter FloatBuffer metrics); + + void glGetPathMetricRangeNV(@GLbitfield int metricQueryMask, + @GLuint int fistPathName, + @GLsizei int numPaths, + @GLsizei int stride, + @Check("GLChecks.calculateMetricsSize(metricQueryMask, stride)") @OutParameter FloatBuffer metrics); + + @Code("\t\tint numPaths = paths.remaining() / GLChecks.calculateBytesPerPathName(pathNameType);") + void glGetPathSpacingNV(@GLenum int pathListMode, + @AutoSize(value = "paths", expression = "numPaths", useExpression = true) @GLsizei int numPaths, + @GLenum int pathNameType, @Const @GLvoid ByteBuffer paths, + @Constant("0") @GLuint int pathBase, + float advanceScale, + float kerningScale, + @GLenum int transformType, + @Check("numPaths - 1") @OutParameter FloatBuffer returnedSpacing); + + @StripPostfix("value") + void glGetPathColorGenivNV(@GLenum int color, @GLenum int pname, @Check("16") @OutParameter IntBuffer value); + + @Alternate("glGetPathColorGenivNV") + @GLreturn("value") + @StripPostfix(value = "value", postfix = "v") + void glGetPathColorGenivNV2(@GLenum int color, @GLenum int pname, @OutParameter IntBuffer value); + + @StripPostfix("value") + void glGetPathColorGenfvNV(@GLenum int color, @GLenum int pname, @Check("16") @OutParameter FloatBuffer value); + + @Alternate("glGetPathColorGenfvNV") + @GLreturn("value") + @StripPostfix(value = "value", postfix = "v") + void glGetPathColorGenfvNV2(@GLenum int color, @GLenum int pname, @OutParameter FloatBuffer value); + + @StripPostfix("value") + void glGetPathTexGenivNV(@GLenum int texCoordSet, @GLenum int pname, @Check("16") @OutParameter IntBuffer value); + + @Alternate("glGetPathTexGenivNV") + @GLreturn("value") + @StripPostfix(value = "value", postfix = "v") + void glGetPathTexGenivNV2(@GLenum int texCoordSet, @GLenum int pname, @OutParameter IntBuffer value); + + @StripPostfix("value") + void glGetPathTexGenfvNV(@GLenum int texCoordSet, @GLenum int pname, @Check("16") @OutParameter FloatBuffer value); + + @Alternate("glGetPathTexGenfvNV") + @GLreturn("value") + @StripPostfix(value = "value", postfix = "v") + void glGetPathTexGenfvNV2(@GLenum int texCoordSet, @GLenum int pname, @OutParameter FloatBuffer value); + + boolean glIsPointInFillPathNV(@GLuint int path, + @GLuint int mask, float x, float y); + + boolean glIsPointInStrokePathNV(@GLuint int path, + float x, float y); + + float glGetPathLengthNV(@GLuint int path, + @GLsizei int startSegment, @GLsizei int numSegments); + + boolean glPointAlongPathNV(@GLuint int path, + @GLsizei int startSegment, @GLsizei int numSegments, + float distance, + @Check(value = "1", canBeNull = true) @OutParameter FloatBuffer x, + @Check(value = "1", canBeNull = true) @OutParameter FloatBuffer y, + @Check(value = "1", canBeNull = true) @OutParameter FloatBuffer tangentX, + @Check(value = "1", canBeNull = true) @OutParameter FloatBuffer tangentY); + +} \ 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-08-02 23:45:26
|
Revision: 3603 http://java-game-lib.svn.sourceforge.net/java-game-lib/?rev=3603&view=rev Author: spasi Date: 2011-08-02 23:45:19 +0000 (Tue, 02 Aug 2011) Log Message: ----------- CL: Cleaned-up callbacks and object registries. Mapped: Added .capacity() and .foreach() with default elementCount. Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/opencl/CLBuildProgramCallback.java trunk/LWJGL/src/java/org/lwjgl/opencl/CLCommandQueue.java trunk/LWJGL/src/java/org/lwjgl/opencl/CLContext.java trunk/LWJGL/src/java/org/lwjgl/opencl/CLEvent.java trunk/LWJGL/src/java/org/lwjgl/opencl/CLEventCallback.java trunk/LWJGL/src/java/org/lwjgl/opencl/CLMemObjectDestructorCallback.java trunk/LWJGL/src/java/org/lwjgl/opencl/CLNativeKernel.java trunk/LWJGL/src/java/org/lwjgl/opencl/CLPlatform.java trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests3.java trunk/LWJGL/src/java/org/lwjgl/test/opencl/HelloOpenCL.java trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java trunk/LWJGL/src/templates/org/lwjgl/opencl/CL10.java trunk/LWJGL/src/templates/org/lwjgl/opencl/CL11.java Removed Paths: ------------- trunk/LWJGL/src/java/org/lwjgl/opencl/CLCallback.java trunk/LWJGL/src/java/org/lwjgl/opencl/CLObjectRegistryGlobal.java Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/CLBuildProgramCallback.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/CLBuildProgramCallback.java 2011-07-29 11:30:14 UTC (rev 3602) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/CLBuildProgramCallback.java 2011-08-02 23:45:19 UTC (rev 3603) @@ -31,24 +31,39 @@ */ package org.lwjgl.opencl; +import org.lwjgl.PointerWrapperAbstract; + /** * Instances of this class can be used to receive OpenCL program build notifications. + * A single CLBuildProgramCallback instance should only be used with programs created + * in the same CLContext. * * @author Spasi */ -public abstract class CLBuildProgramCallback extends CLCallback { +public abstract class CLBuildProgramCallback extends PointerWrapperAbstract { + private CLContext context; + protected CLBuildProgramCallback() { super(CallbackUtil.getBuildProgramCallback()); } /** + * Sets the context that contains the CLPrograms to which we're registered. + * + * @param context the CLContext object + */ + void setContext(final CLContext context) { + this.context = context; + } + + /** * Called from native code. * * @param program_address the CLProgram object pointer */ private void handleMessage(long program_address) { - handleMessage(CLContext.getCLProgramGlobal(program_address)); + handleMessage(context.getCLProgram(program_address)); } /** Deleted: trunk/LWJGL/src/java/org/lwjgl/opencl/CLCallback.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/CLCallback.java 2011-07-29 11:30:14 UTC (rev 3602) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/CLCallback.java 2011-08-02 23:45:19 UTC (rev 3603) @@ -1,59 +0,0 @@ -/* - * 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.PointerWrapperAbstract; - -/** - * Base class for OpenCL callback objects. - * - * @author Spasi - */ -abstract class CLCallback extends PointerWrapperAbstract { - - private final boolean custom; - - protected CLCallback(final long pointer) { - this(pointer, false); - } - - protected CLCallback(final long pointer, final boolean custom) { - super(pointer); - - this.custom = custom; - } - - final boolean isCustom() { - return custom; - } - -} \ No newline at end of file Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/CLCommandQueue.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/CLCommandQueue.java 2011-07-29 11:30:14 UTC (rev 3602) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/CLCommandQueue.java 2011-08-02 23:45:19 UTC (rev 3603) @@ -50,7 +50,7 @@ super(pointer, context); if ( isValid() ) { this.device = device; - this.clEvents = new CLObjectRegistryGlobal<CLEvent>(CLContext.clEventsGlobal); + this.clEvents = new CLObjectRegistry<CLEvent>(); context.getCLCommandQueueRegistry().registerObject(this); } else { this.device = null; Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/CLContext.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/CLContext.java 2011-07-29 11:30:14 UTC (rev 3602) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/CLContext.java 2011-08-02 23:45:19 UTC (rev 3603) @@ -54,12 +54,6 @@ private final CLObjectRegistry<CLProgram> clPrograms; private final CLObjectRegistry<CLEvent> clEvents; - /** Global registry for build callbacks. */ - static final FastLongMap<CLProgram> clProgramsGlobal = new FastLongMap<CLProgram>(); - - /** Global registry for event callbacks. */ - static final FastLongMap<CLEvent> clEventsGlobal = new FastLongMap<CLEvent>(); - CLContext(final long pointer, final CLPlatform platform) { super(pointer, platform); @@ -70,8 +64,8 @@ clCommandQueues = new CLObjectRegistry<CLCommandQueue>(); clMems = new CLObjectRegistry<CLMem>(); clSamplers = new CLObjectRegistry<CLSampler>(); - clPrograms = new CLObjectRegistryGlobal<CLProgram>(clProgramsGlobal); - clEvents = new CLObjectRegistryGlobal<CLEvent>(clEventsGlobal); + clPrograms = new CLObjectRegistry<CLProgram>(); + clEvents = new CLObjectRegistry<CLEvent>(); } else { clCommandQueues = null; clMems = null; @@ -275,8 +269,4 @@ CLObjectRegistry<CLEvent> getCLEventRegistry() { return clEvents; } - static CLProgram getCLProgramGlobal(final long id) { return clProgramsGlobal.get(id); } - - static CLEvent getCLEventGlobal(final long id) { return clEventsGlobal.get(id); } - } \ No newline at end of file Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/CLEvent.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/CLEvent.java 2011-07-29 11:30:14 UTC (rev 3602) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/CLEvent.java 2011-08-02 23:45:19 UTC (rev 3603) @@ -108,6 +108,13 @@ // -------[ IMPLEMENTATION STUFF BELOW ]------- + CLObjectRegistry<CLEvent> getParentRegistry() { + if ( queue == null ) + return getParent().getCLEventRegistry(); + else + return queue.getCLEventRegistry(); + } + int release() { try { return super.release(); Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/CLEventCallback.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/CLEventCallback.java 2011-07-29 11:30:14 UTC (rev 3602) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/CLEventCallback.java 2011-08-02 23:45:19 UTC (rev 3603) @@ -31,30 +31,46 @@ */ package org.lwjgl.opencl; +import org.lwjgl.PointerWrapperAbstract; + /** - * Instances of this class can be used to receive OpenCL memory object destruction notifications. + * Instances of this class can be used to handle OpenCL event callbacks. A single + * CLEventCallback instance should only be used on events generated from the same + * CLCommandQueue or on user events associated with the same CLContext. * * @author Spasi */ -public abstract class CLEventCallback extends CLCallback { +public abstract class CLEventCallback extends PointerWrapperAbstract { + private CLObjectRegistry<CLEvent> eventRegistry; + protected CLEventCallback() { super(CallbackUtil.getEventCallback()); } /** + * Sets the eventRegistry that contains the CLEvents to which we're registered. + * + * @param eventRegistry the CLEvent object registry + */ + void setRegistry(final CLObjectRegistry<CLEvent> eventRegistry) { + this.eventRegistry = eventRegistry; + } + + /** * Called from native code. * * @param event_address the CLEvent object pointer */ private void handleMessage(long event_address, int event_command_exec_status) { - handleMessage(CLContext.getCLEventGlobal(event_address), event_command_exec_status); + handleMessage(eventRegistry.getObject(event_address), event_command_exec_status); } /** * The callback method. * - * @param event the CLEvent object + * @param event the CLEvent object + * @param event_command_exec_status the execution status */ protected abstract void handleMessage(CLEvent event, int event_command_exec_status); Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/CLMemObjectDestructorCallback.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/CLMemObjectDestructorCallback.java 2011-07-29 11:30:14 UTC (rev 3602) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/CLMemObjectDestructorCallback.java 2011-08-02 23:45:19 UTC (rev 3603) @@ -31,12 +31,14 @@ */ package org.lwjgl.opencl; +import org.lwjgl.PointerWrapperAbstract; + /** * Instances of this class can be used to receive OpenCL memory object destruction notifications. * * @author Spasi */ -public abstract class CLMemObjectDestructorCallback extends CLCallback { +public abstract class CLMemObjectDestructorCallback extends PointerWrapperAbstract { protected CLMemObjectDestructorCallback() { super(CallbackUtil.getMemObjectDestructorCallback()); Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/CLNativeKernel.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/CLNativeKernel.java 2011-07-29 11:30:14 UTC (rev 3602) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/CLNativeKernel.java 2011-08-02 23:45:19 UTC (rev 3603) @@ -31,6 +31,8 @@ */ package org.lwjgl.opencl; +import org.lwjgl.PointerWrapperAbstract; + import java.nio.ByteBuffer; /** @@ -43,7 +45,7 @@ * @see CL10#clEnqueueNativeKernel * @see #execute(java.nio.ByteBuffer[]) */ -public abstract class CLNativeKernel extends CLCallback { +public abstract class CLNativeKernel extends PointerWrapperAbstract { protected CLNativeKernel() { super(CallbackUtil.getNativeKernelCallback()); Deleted: trunk/LWJGL/src/java/org/lwjgl/opencl/CLObjectRegistryGlobal.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/CLObjectRegistryGlobal.java 2011-07-29 11:30:14 UTC (rev 3602) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/CLObjectRegistryGlobal.java 2011-08-02 23:45:19 UTC (rev 3603) @@ -1,57 +0,0 @@ -/* - * 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; - -/** - * A CLObject registry that also registers/unregisters objects to/from a global registry. - * - * @author Spasi - */ -final class CLObjectRegistryGlobal<T extends CLObjectChild> extends CLObjectRegistry<T> { - - private final FastLongMap<T> globalRegistry; - - CLObjectRegistryGlobal(final FastLongMap<T> globalRegistry) { - this.globalRegistry = globalRegistry; - } - - void registerObject(final T object) { - super.registerObject(object); - globalRegistry.put(object.getPointer(), object); - } - - void unregisterObject(final T object) { - super.unregisterObject(object); - globalRegistry.remove(object.getPointerUnsafe()); - } - -} \ No newline at end of file Modified: trunk/LWJGL/src/java/org/lwjgl/opencl/CLPlatform.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/opencl/CLPlatform.java 2011-07-29 11:30:14 UTC (rev 3602) +++ trunk/LWJGL/src/java/org/lwjgl/opencl/CLPlatform.java 2011-08-02 23:45:19 UTC (rev 3603) @@ -53,9 +53,6 @@ private final CLObjectRegistry<CLDevice> clDevices; - /** Global registry for build callbacks. */ - static final FastLongMap<CLDevice> clDevicesGlobal = new FastLongMap<CLDevice>(); - private Object caps; CLPlatform(final long pointer) { @@ -63,7 +60,7 @@ if ( isValid() ) { clPlatforms.put(pointer, this); - clDevices = new CLObjectRegistryGlobal<CLDevice>(clDevicesGlobal); + clDevices = new CLObjectRegistry<CLDevice>(); } else clDevices = null; } @@ -195,8 +192,6 @@ CLObjectRegistry<CLDevice> getCLDeviceRegistry() { return clDevices; } - static CLDevice getCLDeviceGlobal(final long id) { return clDevicesGlobal.get(id); } - /** * Called from <code>clGetDeviceIDs</code> to register new devices. * Modified: trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java 2011-07-29 11:30:14 UTC (rev 3602) +++ trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests1.java 2011-08-02 23:45:19 UTC (rev 3603) @@ -55,13 +55,20 @@ ByteBuffer bb = ByteBuffer.allocateDirect(200); MappedFloat vecs = MappedFloat.map(bb); - // verify 'malloc' and SIZEOF + // verify 'malloc', SIZEOF and capacity() { MappedFloat vecs1 = MappedFloat.malloc(1234); assert (vecs1.getSizeof() == MappedFloat.SIZEOF); assert (vecs1.getSizeof() * 1234 == vecs1.backingByteBuffer().capacity()); assert (MappedFloat.SIZEOF * 1234 == vecs1.backingByteBuffer().capacity()); + assert(vecs1.capacity() == vecs1.backingByteBuffer().capacity() / MappedFloat.SIZEOF); + + ByteBuffer buf = ByteBuffer.allocateDirect(200); + buf.position(10 * MappedFloat.SIZEOF); + + MappedFloat vecs2 = MappedFloat.map(buf); + assert(vecs2.capacity() == (vecs2.backingByteBuffer().capacity() / MappedFloat.SIZEOF) - 10); } // manipulate 'mapped.value' Modified: trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests3.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests3.java 2011-07-29 11:30:14 UTC (rev 3602) +++ trunk/LWJGL/src/java/org/lwjgl/test/mapped/MappedObjectTests3.java 2011-08-02 23:45:19 UTC (rev 3603) @@ -70,15 +70,21 @@ } static void testForeach() { - int elementCount = 4; + int elementCount = 10; MappedSomething some = MappedSomething.malloc(elementCount); int i = 0; - for ( MappedSomething item : foreach(some, elementCount) ) { + for ( MappedSomething item : foreach(some, elementCount / 2) ) { assert (item.view == i++); } - assert (some.view != elementCount); - System.out.println("current.view=" + some.view + ", not " + elementCount + ", as you might expect"); + assert (some.view == (elementCount / 2) - 1); + System.out.println("current.view=" + some.view + ", not " + (elementCount / 2) + ", as you might expect"); + + i = 0; + for ( MappedSomething item : foreach(some) ) { + assert (item.view == i++); + } + assert (some.view == elementCount - 1); } public static class Xyz extends MappedObject { Modified: trunk/LWJGL/src/java/org/lwjgl/test/opencl/HelloOpenCL.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opencl/HelloOpenCL.java 2011-07-29 11:30:14 UTC (rev 3602) +++ trunk/LWJGL/src/java/org/lwjgl/test/opencl/HelloOpenCL.java 2011-08-02 23:45:19 UTC (rev 3603) @@ -143,23 +143,41 @@ System.out.println("-TRYING TO EXEC NATIVE KERNEL-"); final CLCommandQueue queue = clCreateCommandQueue(context, device, 0, null); + final PointerBuffer ev = BufferUtils.createPointerBuffer(1); + clEnqueueNativeKernel(queue, new CLNativeKernel() { protected void execute(final ByteBuffer[] memobjs) { - if ( memobjs == null ) - System.out.println("OK, it's null"); - else { - System.out.println("memobjs = " + memobjs.length); - for ( int k = 0; k < memobjs.length; k++ ) { - System.out.println("memobjs[" + k + "].remaining() = " + memobjs[k].remaining()); - for ( int l = memobjs[k].position(); l < memobjs[k].limit(); l++ ) { - memobjs[k].put(l, (byte)l); - } + System.out.println("\tmemobjs.length = " + memobjs.length); + for ( int k = 0; k < memobjs.length; k++ ) { + System.out.println("\tmemobjs[" + k + "].remaining() = " + memobjs[k].remaining()); + for ( int l = memobjs[k].position(); l < memobjs[k].limit(); l++ ) { + memobjs[k].put(l, (byte)l); } } + System.out.println("\tNative kernel done."); } - }, new CLMem[] { buffer }, new long[] { 128 }, null, null); + }, new CLMem[] { buffer }, new long[] { 128 }, null, ev); - clFinish(queue); + final CLEvent e = queue.getCLEvent(ev.get(0)); + + clSetEventCallback(e, CL_COMPLETE, new CLEventCallback() { + protected void handleMessage(final CLEvent event, final int event_command_exec_status) { + System.out.println("\t\tEvent callback status: " + getEventStatusName(event_command_exec_status)); + } + }); + + int status = e.getInfoInt(CL_EVENT_COMMAND_EXECUTION_STATUS); + System.out.println("NATIVE KERNEL STATUS: " + getEventStatusName(status)); + clFlush(queue); + do { + int newStatus = e.getInfoInt(CL_EVENT_COMMAND_EXECUTION_STATUS); + if ( newStatus != status ) { + status = newStatus; + System.out.println("NATIVE KERNEL STATUS: " + getEventStatusName(status)); + } + } while ( status != CL_SUCCESS ); // Busy-spin until we're done + + clReleaseEvent(e); } } @@ -182,6 +200,19 @@ System.out.println("\t" + param_name + " = " + device.getInfoString(param)); } + private static String getEventStatusName(final int status) { + switch ( status ) { + case CL_QUEUED: + return "CL_QUEUED"; + case CL_SUBMITTED: + return "CL_SUBMITTED"; + case CL_RUNNING: + return "CL_RUNNING"; + default: + return "CL_COMPLETE"; + } + } + private static void die(String kind, String description) { System.out.println(kind + " error " + description + " occured"); } Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java 2011-07-29 11:30:14 UTC (rev 3602) +++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObject.java 2011-08-02 23:45:19 UTC (rev 3603) @@ -133,6 +133,16 @@ } /** + * Returns the number of mapped objects that fit in the mapped buffer. + * + * @return the mapped object capacity + */ + public final int capacity() { + // No call-site modification for this, we override in every subclass instead. + throw new InternalError("type not registered"); + } + + /** * Creates a MappedObject instance, mapping the memory region of the specified direct ByteBuffer. * <p/> * The behavior of this (transformed) method does not follow the normal Java behavior.<br> @@ -200,7 +210,7 @@ /** * Any code in the default constructor will not run automatically. This method - * can be used to run execute that code on the current view. + * can be used to execute that code on the current view. */ public final void runViewConstructor() { // any method that calls this method will have its call-site modified @@ -237,6 +247,18 @@ /** * Creates an {@link Iterable} <MappedObject> that will step through + * <code>capacity()</code> views, leaving the <code>view</code> at + * the last valid value.<br> + * <p/> + * 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> Iterable<T> foreach(T mapped) { + return foreach(mapped, mapped.capacity()); + } + + /** + * Creates an {@link Iterable} <MappedObject> that will step through * <code>elementCount</code> views, leaving the <code>view</code> at * the last valid value.<br> * <p/> Modified: trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java 2011-07-29 11:30:14 UTC (rev 3602) +++ trunk/LWJGL/src/java/org/lwjgl/util/mapped/MappedObjectTransformer.java 2011-08-02 23:45:19 UTC (rev 3603) @@ -32,6 +32,7 @@ package org.lwjgl.util.mapped; import org.lwjgl.LWJGLUtil; +import org.lwjgl.MemoryUtil; import org.objectweb.asm.*; import org.objectweb.asm.tree.*; import org.objectweb.asm.tree.analysis.*; @@ -42,6 +43,7 @@ import java.io.StringWriter; import java.lang.reflect.Field; import java.lang.reflect.Modifier; +import java.nio.Buffer; import java.nio.ByteBuffer; import java.util.HashMap; import java.util.Map; @@ -82,9 +84,9 @@ static final String NEXT_METHOD_NAME = "next"; static final String ALIGN_METHOD_NAME = "getAlign"; static final String SIZEOF_METHOD_NAME = "getSizeof"; + static final String CAPACITY_METHOD_NAME = "capacity"; // Used for .asArray().length // Internal methods - static final String LENGTH_METHOD_NAME = "length$LWJGL"; // Used for .asArray().length static final String VIEW_CONSTRUCTOR_NAME = "constructView$LWJGL"; // Used by runViewConstructor static final Map<Integer, String> OPCODE_TO_NAME = new HashMap<Integer, String>(); @@ -228,6 +230,7 @@ NEXT_METHOD_NAME, ALIGN_METHOD_NAME, SIZEOF_METHOD_NAME, + CAPACITY_METHOD_NAME, }; public MethodVisitor visitMethod(int access, final String name, final String desc, final String signature, final String[] exceptions) { @@ -285,7 +288,7 @@ final MappedSubtypeInfo mappedSubtype = className_to_subtype.get(className); generateViewAddressGetter(); - generateLengthGetter(); + generateCapacity(); generateAlignGetter(mappedSubtype); generateSizeofGetter(); generateNext(); @@ -329,16 +332,25 @@ mv.visitEnd(); } - private void generateLengthGetter() { - MethodVisitor mv = super.visitMethod(ACC_PUBLIC | ACC_STATIC, LENGTH_METHOD_NAME, "(L" + className + ";)I", null, null); + private void generateCapacity() { + // return (backingByteBuffer().capacity() + (int)(MemoryUtil.getAddress0(backingByteBuffer()) - baseAddress)) / SIZEOF; + MethodVisitor mv = super.visitMethod(ACC_PUBLIC, CAPACITY_METHOD_NAME, "()I", null, null); mv.visitCode(); mv.visitVarInsn(ALOAD, 0); mv.visitMethodInsn(INVOKEVIRTUAL, MAPPED_OBJECT_JVM, "backingByteBuffer", "()L" + jvmClassName(ByteBuffer.class) + ";"); + mv.visitInsn(DUP); mv.visitMethodInsn(INVOKEVIRTUAL, jvmClassName(ByteBuffer.class), "capacity", "()I"); + mv.visitInsn(SWAP); + mv.visitMethodInsn(INVOKESTATIC, jvmClassName(MemoryUtil.class), "getAddress0", "(L" + jvmClassName(Buffer.class) + ";)J"); + mv.visitVarInsn(ALOAD, 0); + mv.visitFieldInsn(GETFIELD, MAPPED_OBJECT_JVM, "baseAddress", "J"); + mv.visitInsn(LSUB); + mv.visitInsn(L2I); + mv.visitInsn(IADD); mv.visitFieldInsn(GETSTATIC, className, "SIZEOF", "I"); mv.visitInsn(IDIV); mv.visitInsn(IRETURN); - mv.visitMaxs(2, 1); + mv.visitMaxs(3, 1); mv.visitEnd(); } @@ -1037,7 +1049,7 @@ instructions.remove(nextInsn); loadInsn.var = var; - instructions.insert(loadInsn, new MethodInsnNode(INVOKESTATIC, mappedSubtype.className, LENGTH_METHOD_NAME, "(L" + mappedSubtype.className + ";)I")); + instructions.insert(loadInsn, new MethodInsnNode(INVOKEVIRTUAL, mappedSubtype.className, CAPACITY_METHOD_NAME, "()I")); return i + 1; } else if ( stackSize < loadStackSize ) // Consumed by something other than AALOAD or ARRAYLENGTH Modified: trunk/LWJGL/src/templates/org/lwjgl/opencl/CL10.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opencl/CL10.java 2011-07-29 11:30:14 UTC (rev 3602) +++ trunk/LWJGL/src/templates/org/lwjgl/opencl/CL10.java 2011-08-02 23:45:19 UTC (rev 3603) @@ -432,7 +432,7 @@ @Code( tryBlock = true, // Create a GlobalRef to the callback object. - javaBeforeNative = "\t\tlong user_data = CallbackUtil.createGlobalRef(pfn_notify);", + javaBeforeNative = "\t\tlong user_data = pfn_notify == null || pfn_notify.isCustom() ? 0 : CallbackUtil.createGlobalRef(pfn_notify);", // Associate context with the GlobalRef, so we can delete it later. javaFinally = "\t\t\tCallbackUtil.registerCallback(__result, user_data);" ) @@ -845,7 +845,8 @@ @Code( tryBlock = true, // Create a GlobalRef to the callback object. - javaBeforeNative = "\t\tlong user_data = CallbackUtil.createGlobalRef(pfn_notify);", + javaBeforeNative = "\t\tlong user_data = CallbackUtil.createGlobalRef(pfn_notify);\n" + + "\t\tif ( pfn_notify != null ) pfn_notify.setContext(program.getParent());", // Check if we need to delete the GlobalRef. javaFinally = "\t\t\tCallbackUtil.checkCallback(__result, user_data);" ) @@ -861,7 +862,8 @@ @Code( tryBlock = true, // Create a GlobalRef to the callback object. - javaBeforeNative = "\t\tlong user_data = CallbackUtil.createGlobalRef(pfn_notify);", + javaBeforeNative = "\t\tlong user_data = CallbackUtil.createGlobalRef(pfn_notify);\n" + + "\t\tif ( pfn_notify != null ) pfn_notify.setContext(program.getParent());", // Check if we need to delete the GlobalRef. javaFinally = "\t\t\tCallbackUtil.checkCallback(__result, user_data);" ) @@ -877,7 +879,8 @@ @Code( tryBlock = true, // Create a GlobalRef to the callback object. - javaBeforeNative = "\t\tlong user_data = CallbackUtil.createGlobalRef(pfn_notify);", + javaBeforeNative = "\t\tlong user_data = CallbackUtil.createGlobalRef(pfn_notify);\n" + + "\t\tif ( pfn_notify != null ) pfn_notify.setContext(program.getParent());", // Check if we need to delete the GlobalRef. javaFinally = "\t\t\tCallbackUtil.checkCallback(__result, user_data);" ) Modified: trunk/LWJGL/src/templates/org/lwjgl/opencl/CL11.java =================================================================== --- trunk/LWJGL/src/templates/org/lwjgl/opencl/CL11.java 2011-07-29 11:30:14 UTC (rev 3602) +++ trunk/LWJGL/src/templates/org/lwjgl/opencl/CL11.java 2011-08-02 23:45:19 UTC (rev 3603) @@ -190,7 +190,8 @@ @Code( tryBlock = true, // Create a GlobalRef to the callback object. - javaBeforeNative = "\t\tlong user_data = CallbackUtil.createGlobalRef(pfn_notify);", + javaBeforeNative = "\t\tlong user_data = CallbackUtil.createGlobalRef(pfn_notify);\n" + + "\t\tpfn_notify.setRegistry(event.getParentRegistry());", // Check if we need to delete the GlobalRef. javaFinally = "\t\t\tCallbackUtil.checkCallback(__result, user_data);" ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |