mirror of
https://github.com/shadowfacts/lwjgl2-arm64.git
synced 2026-01-01 22:39:58 +01:00
Compare commits
No commits in common. "master" and "lwjgl2.9.1" have entirely different histories.
master
...
lwjgl2.9.1
17
.github/CONTRIBUTING.md
vendored
17
.github/CONTRIBUTING.md
vendored
|
|
@ -1,17 +0,0 @@
|
|||
## WARNING
|
||||
|
||||
This is the repository of the original LWJGL, which is no longer actively maintained. Unless you have released a product that uses LWJGL 2.x, you should probably be looking at [LWJGL 3](https://github.com/LWJGL/lwjgl3).
|
||||
|
||||
If you decide to proceed, it is very likely that:
|
||||
|
||||
- LWJGL maintainers won't be able to address your issue. Your best hope is an external contribution, which happens very rarely.
|
||||
- Your issue is not an issue in LWJGL 3.
|
||||
- Your issue has already been fixed in LWJGL 3.
|
||||
|
||||
If it is impossible for you to migrate to LWJGL 3, make sure to:
|
||||
|
||||
- Describe your issue as clearly as possible.
|
||||
- Include information about your system/environment.
|
||||
- Include a minimal code sample that reproduces the issue.
|
||||
|
||||
In any case, feature requests will almost certainly be ignored. If you need new features, you're very welcome to open an issue in the LWJGL 3 repository.
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -17,6 +17,3 @@
|
|||
/src/native/*/org_lwjgl_*.h
|
||||
/src/native/*/*/org_lwjgl_*.h
|
||||
/src/native/linux/org_lwjgl_opengl_Display.c
|
||||
|
||||
nbproject/project.xml
|
||||
/nbproject/private/
|
||||
10
README.md
10
README.md
|
|
@ -1,17 +1,13 @@
|
|||
[LEGACY] LWJGL - Lightweight Java Game Library
|
||||
LWJGL - Lightweight Java Game Library
|
||||
======
|
||||
|
||||
> **WARNING**
|
||||
>
|
||||
> This is the repository of the original LWJGL, which is no longer actively maintained. Unless you have released a product that uses LWJGL 2.x, you should probably be looking at [LWJGL 3](https://github.com/LWJGL/lwjgl3).
|
||||
|
||||
The Lightweight Java Game Library (LWJGL) is a solution aimed directly at professional and amateur Java programmers alike to enable commercial quality games to be written in Java.
|
||||
LWJGL provides developers access to high performance crossplatform libraries such as OpenGL (Open Graphics Library), OpenCL (Open Computing Language) and OpenAL (Open Audio Library) allowing for state of the art 3D games and 3D sound.
|
||||
Additionally LWJGL provides access to controllers such as Gamepads, Steering wheel and Joysticks.
|
||||
All in a simple and straight forward API.
|
||||
|
||||
Website: [http://legacy.lwjgl.org](http://legacy.lwjgl.org)
|
||||
Forum: [http://forum.lwjgl.org](http://forum.lwjgl.org)
|
||||
Website: [http://lwjgl.org](http://lwjgl.org)
|
||||
Forum: [http://lwjgl.org/forum](http://lwjgl.org/forum)
|
||||
Bugs/Suggestions: [https://github.com/LWJGL/lwjgl/issues](https://github.com/LWJGL/lwjgl/issues)
|
||||
|
||||
Compilation
|
||||
|
|
|
|||
300
build.xml
300
build.xml
|
|
@ -33,7 +33,6 @@
|
|||
<mkdir dir="${lwjgl.temp}/native/windows" taskname="initialiazing temp/windows folder" />
|
||||
<mkdir dir="${lwjgl.temp}/native/linux" taskname="initialiazing temp/linux folder" />
|
||||
<mkdir dir="${lwjgl.temp}/native/freebsd" taskname="initialiazing temp/freebsd folder" />
|
||||
<mkdir dir="${lwjgl.temp}/native/openbsd" taskname="initialiazing temp/openbsd folder" />
|
||||
<mkdir dir="${lwjgl.temp}/native/macosx" taskname="initialiazing temp/macosx folder" />
|
||||
<mkdir dir="${lwjgl.temp}/native/solaris" taskname="initialiazing temp/solaris folder" />
|
||||
</target>
|
||||
|
|
@ -88,8 +87,8 @@
|
|||
<antcall target="-createjars" />
|
||||
|
||||
<antcall target="-jars_NoDEP" />
|
||||
<!-- <antcall target="javadoc" /> -->
|
||||
<!-- <antcall target="applet-release" /> -->
|
||||
<antcall target="javadoc" />
|
||||
<antcall target="applet-release" />
|
||||
|
||||
<!-- copy resources to res folder -->
|
||||
<copy todir="${lwjgl.temp}/res">
|
||||
|
|
@ -97,15 +96,15 @@
|
|||
</copy>
|
||||
|
||||
<!-- copy docs -->
|
||||
<!-- <copy todir="${lwjgl.temp}/doc"> -->
|
||||
<!-- <fileset dir="${lwjgl.docs}"> -->
|
||||
<!-- <patternset refid="lwjgl-docs.fileset" /> -->
|
||||
<!-- </fileset> -->
|
||||
<!-- </copy> -->
|
||||
<copy todir="${lwjgl.temp}/doc">
|
||||
<fileset dir="${lwjgl.docs}">
|
||||
<patternset refid="lwjgl-docs.fileset" />
|
||||
</fileset>
|
||||
</copy>
|
||||
|
||||
<!-- create distribution from files in libs/ and temp/ -->
|
||||
<!-- <antcall target="-distribution_javadoc" /> -->
|
||||
<!-- <antcall target="-distribution_source" /> -->
|
||||
<antcall target="-distribution_javadoc" />
|
||||
<antcall target="-distribution_source" />
|
||||
<antcall target="-distribute" />
|
||||
</target>
|
||||
|
||||
|
|
@ -163,7 +162,7 @@
|
|||
<attribute name="Permissions" value="all-permissions"/>
|
||||
<attribute name="Codebase" value="*"/>
|
||||
<attribute name="Caller-Allowable-Codebase" value="*"/>
|
||||
<attribute name="Application-Library-Allowable-Codebase" value="*"/>
|
||||
<attribute name="Application-Library-Allowable-Codebase" value="true"/>
|
||||
</manifest>
|
||||
</jar>
|
||||
|
||||
|
|
@ -250,11 +249,6 @@
|
|||
<patternset refid="lwjgl-freebsd.fileset" />
|
||||
</fileset>
|
||||
</copy>
|
||||
<copy todir="${lwjgl.temp}/native/openbsd" failonerror="false">
|
||||
<fileset dir="${lwjgl.lib}/openbsd">
|
||||
<patternset refid="lwjgl-openbsd.fileset" />
|
||||
</fileset>
|
||||
</copy>
|
||||
<copy todir="${lwjgl.temp}/native/macosx">
|
||||
<fileset dir="${lwjgl.lib}/macosx">
|
||||
<patternset refid="lwjgl-macosx.fileset" />
|
||||
|
|
@ -295,88 +289,82 @@
|
|||
|
||||
<!-- Generates the native headers from source files -->
|
||||
<target name="headers" description="invokes javah on java classes" depends="compile">
|
||||
<!-- <javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/linux"> -->
|
||||
<!-- <class name="org.lwjgl.LinuxSysImplementation" /> -->
|
||||
<!-- <class name="org.lwjgl.opengl.LinuxEvent" /> -->
|
||||
<!-- <class name="org.lwjgl.opengl.LinuxMouse" /> -->
|
||||
<!-- <class name="org.lwjgl.opengl.LinuxKeyboard" /> -->
|
||||
<!-- <class name="org.lwjgl.opengl.LinuxDisplay" /> -->
|
||||
<!-- <class name="org.lwjgl.opengl.LinuxPeerInfo" /> -->
|
||||
<!-- </javah> -->
|
||||
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/linux">
|
||||
<class name="org.lwjgl.LinuxSysImplementation" />
|
||||
<class name="org.lwjgl.opengl.LinuxEvent" />
|
||||
<class name="org.lwjgl.opengl.LinuxMouse" />
|
||||
<class name="org.lwjgl.opengl.LinuxKeyboard" />
|
||||
<class name="org.lwjgl.opengl.LinuxDisplay" />
|
||||
<class name="org.lwjgl.opengl.LinuxPeerInfo" />
|
||||
</javah>
|
||||
|
||||
<!-- <javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/linux/opengl"> -->
|
||||
<!-- <class name="org.lwjgl.opengl.LinuxPbufferPeerInfo"/> -->
|
||||
<!-- <class name="org.lwjgl.opengl.LinuxDisplayPeerInfo"/> -->
|
||||
<!-- <class name="org.lwjgl.opengl.LinuxAWTGLCanvasPeerInfo"/> -->
|
||||
<!-- <class name="org.lwjgl.opengl.LinuxContextImplementation"/> -->
|
||||
<!-- <class name="org.lwjgl.opengl.LinuxCanvasImplementation"/> -->
|
||||
<!-- </javah> -->
|
||||
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/linux/opengl">
|
||||
<class name="org.lwjgl.opengl.LinuxPbufferPeerInfo"/>
|
||||
<class name="org.lwjgl.opengl.LinuxDisplayPeerInfo"/>
|
||||
<class name="org.lwjgl.opengl.LinuxAWTGLCanvasPeerInfo"/>
|
||||
<class name="org.lwjgl.opengl.LinuxContextImplementation"/>
|
||||
<class name="org.lwjgl.opengl.LinuxCanvasImplementation"/>
|
||||
</javah>
|
||||
|
||||
<!-- <javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/windows"> -->
|
||||
<!-- <class name="org.lwjgl.WindowsSysImplementation"/> -->
|
||||
<!-- <class name="org.lwjgl.opengl.WindowsKeyboard" /> -->
|
||||
<!-- <class name="org.lwjgl.opengl.WindowsRegistry" /> -->
|
||||
<!-- <class name="org.lwjgl.opengl.WindowsDisplay"/> -->
|
||||
<!-- <class name="org.lwjgl.opengl.WindowsDisplayPeerInfo"/> -->
|
||||
<!-- <class name="org.lwjgl.opengl.WindowsAWTGLCanvasPeerInfo"/> -->
|
||||
<!-- </javah> -->
|
||||
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/windows">
|
||||
<class name="org.lwjgl.WindowsSysImplementation"/>
|
||||
<class name="org.lwjgl.opengl.WindowsKeyboard" />
|
||||
<class name="org.lwjgl.opengl.WindowsRegistry" />
|
||||
<class name="org.lwjgl.opengl.WindowsDisplay"/>
|
||||
<class name="org.lwjgl.opengl.WindowsDisplayPeerInfo"/>
|
||||
<class name="org.lwjgl.opengl.WindowsAWTGLCanvasPeerInfo"/>
|
||||
</javah>
|
||||
|
||||
<!-- <javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/windows/opengl"> -->
|
||||
<!-- <class name="org.lwjgl.opengl.WindowsPbufferPeerInfo"/> -->
|
||||
<!-- <class name="org.lwjgl.opengl.WindowsPeerInfo"/> -->
|
||||
<!-- <class name="org.lwjgl.opengl.WindowsContextImplementation"/> -->
|
||||
<!-- </javah> -->
|
||||
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/windows/opengl">
|
||||
<class name="org.lwjgl.opengl.WindowsPbufferPeerInfo"/>
|
||||
<class name="org.lwjgl.opengl.WindowsPeerInfo"/>
|
||||
<class name="org.lwjgl.opengl.WindowsContextImplementation"/>
|
||||
</javah>
|
||||
|
||||
<!-- <javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/windows/opengles"> -->
|
||||
<!-- <class name="org.lwjgl.opengl.WindowsPeerInfo"/> -->
|
||||
<!-- </javah> -->
|
||||
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/windows/opengles">
|
||||
<class name="org.lwjgl.opengl.WindowsPeerInfo"/>
|
||||
</javah>
|
||||
|
||||
<echo>lwjgl.src.headers = ${lwjgl.src.headers}</echo>
|
||||
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.native}/macosx">
|
||||
<class name="org.lwjgl.MacOSXSysImplementation" />
|
||||
<class name="org.lwjgl.opengl.MacOSXCanvasPeerInfo" />
|
||||
<class name="org.lwjgl.opengl.MacOSXPeerInfo" />
|
||||
<class name="org.lwjgl.opengl.MacOSXPbufferPeerInfo" />
|
||||
<class name="org.lwjgl.opengl.MacOSXDisplay" />
|
||||
<class name="org.lwjgl.opengl.MacOSXContextImplementation" />
|
||||
<class name="org.lwjgl.opengl.MacOSXNativeKeyboard" />
|
||||
<class name="org.lwjgl.opengl.MacOSXNativeMouse" />
|
||||
<class name="org.lwjgl.opengl.MacOSXMouseEventQueue" />
|
||||
</javah>
|
||||
|
||||
<javac classpath="${lwjgl.bin}" srcdir="${lwjgl.src}" nativeheaderdir="${lwjgl.src.native}/macosx">
|
||||
<compilerarg line="-h ${lwjgl.src.native}/macosx" />
|
||||
<include name="java/org/lwjgl/MacOSXSysImplementation.java" />
|
||||
<include name="java/org/lwjgl/opengl/MacOSXCanvasPeerInfo.java" />
|
||||
<include name="java/org/lwjgl/opengl/MacOSXPeerInfo.java" />
|
||||
<include name="java/org/lwjgl/opengl/MacOSXPbufferPeerInfo.java" />
|
||||
<include name="java/org/lwjgl/opengl/MacOSXDisplay.java" />
|
||||
<include name="java/org/lwjgl/opengl/MacOSXContextImplementation.java" />
|
||||
<include name="java/org/lwjgl/opengl/MacOSXNativeKeyboard.java" />
|
||||
<include name="java/org/lwjgl/opengl/MacOSXNativeMouse.java" />
|
||||
<include name="java/org/lwjgl/opengl/MacOSXMouseEventQueue.java" />
|
||||
</javac>
|
||||
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.headers}">
|
||||
<class name="org.lwjgl.opengl.AWTSurfaceLock" />
|
||||
<class name="org.lwjgl.DefaultSysImplementation" />
|
||||
<class name="org.lwjgl.input.Cursor" />
|
||||
<class name="org.lwjgl.input.Keyboard" />
|
||||
<class name="org.lwjgl.input.Mouse" />
|
||||
<class name="org.lwjgl.openal.AL" />
|
||||
<class name="org.lwjgl.opencl.CL" />
|
||||
<class name="org.lwjgl.opencl.CallbackUtil" />
|
||||
<class name="org.lwjgl.BufferUtils" />
|
||||
</javah>
|
||||
|
||||
<javac classpath="${lwjgl.bin}" srcdir="${lwjgl.src}" nativeheaderdir="${lwjgl.src.headers}">
|
||||
<compilerarg line="-h ${lwjgl.src.headers}" />
|
||||
<include name="java/org/lwjgl/opengl/AWTSurfaceLock.java" />
|
||||
<include name="java/org/lwjgl/DefaultSysImplementation.java" />
|
||||
<include name="java/org/lwjgl/input/Cursor.java" />
|
||||
<include name="java/org/lwjgl/input/Keyboard.java" />
|
||||
<include name="java/org/lwjgl/input/Mouse.java" />
|
||||
<include name="java/org/lwjgl/openal/AL.java" />
|
||||
<include name="java/org/lwjgl/opencl/CL.java" />
|
||||
<include name="java/org/lwjgl/opencl/CallbackUtil.java" />
|
||||
<include name="java/org/lwjgl/BufferUtils.java" />
|
||||
</javac>
|
||||
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.headers}/opengl">
|
||||
<class name="org.lwjgl.opengl.GLContext"/>
|
||||
<class name="org.lwjgl.opengl.Pbuffer"/>
|
||||
<class name="org.lwjgl.opengl.CallbackUtil"/>
|
||||
<class name="org.lwjgl.opengl.NVPresentVideoUtil"/>
|
||||
<class name="org.lwjgl.opengl.NVVideoCaptureUtil"/>
|
||||
</javah>
|
||||
|
||||
<javac classpath="${lwjgl.bin}" srcdir="${lwjgl.src}" nativeheaderdir="${lwjgl.src.headers}/opengl">
|
||||
<compilerarg line="-h ${lwjgl.src.headers}/opengl" />
|
||||
<include name="java/org/lwjgl/opengl/GLContext.java"/>
|
||||
<include name="java/org/lwjgl/opengl/Pbuffer.java"/>
|
||||
<include name="java/org/lwjgl/opengl/CallbackUtil.java"/>
|
||||
<include name="java/org/lwjgl/opengl/NVPresentVideoUtil.java"/>
|
||||
<include name="java/org/lwjgl/opengl/NVVideoCaptureUtil.java"/>
|
||||
</javac>
|
||||
|
||||
<javac classpath="${lwjgl.bin}" srcdir="${lwjgl.src}" nativeheaderdir="${lwjgl.src.headers}/opengles">
|
||||
<compilerarg line="-h ${lwjgl.src.headers}/opengles" />
|
||||
<include name="java/org/lwjgl/opengles/EGL.java"/>
|
||||
<include name="java/org/lwjgl/opengles/EGLKHRFenceSync.java"/>
|
||||
<include name="java/org/lwjgl/opengles/EGLKHRReusableSync.java"/>
|
||||
<include name="java/org/lwjgl/opengles/EGLNVSync.java"/>
|
||||
<include name="java/org/lwjgl/opengles/GLContext.java"/>
|
||||
<include name="java/org/lwjgl/opengles/CallbackUtil.java"/>
|
||||
</javac>
|
||||
<javah classpath="${lwjgl.bin}" destdir="${lwjgl.src.headers}/opengles">
|
||||
<class name="org.lwjgl.opengles.EGL"/>
|
||||
<class name="org.lwjgl.opengles.EGLKHRFenceSync"/>
|
||||
<class name="org.lwjgl.opengles.EGLKHRReusableSync"/>
|
||||
<class name="org.lwjgl.opengles.EGLNVSync"/>
|
||||
<class name="org.lwjgl.opengles.GLContext"/>
|
||||
<class name="org.lwjgl.opengles.CallbackUtil"/>
|
||||
</javah>
|
||||
</target>
|
||||
|
||||
<target name="touch-version">
|
||||
|
|
@ -386,60 +374,58 @@
|
|||
</target>
|
||||
|
||||
<target name="version-mismatch">
|
||||
<!-- <loadfile srcfile="${lwjgl.src}/java/org/lwjgl/WindowsSysImplementation.java" property="lwjgl.java.windows.version"> -->
|
||||
<!-- <filterchain> -->
|
||||
<!-- <tokenfilter> -->
|
||||
<!-- <containsstring contains="JNI_VERSION ="/> -->
|
||||
<!-- </tokenfilter> -->
|
||||
<!-- </filterchain> -->
|
||||
<!-- </loadfile> -->
|
||||
<!-- <loadfile srcfile="${lwjgl.src}/java/org/lwjgl/LinuxSysImplementation.java" property="lwjgl.java.linux.version"> -->
|
||||
<!-- <filterchain> -->
|
||||
<!-- <tokenfilter> -->
|
||||
<!-- <containsstring contains="JNI_VERSION ="/> -->
|
||||
<!-- </tokenfilter> -->
|
||||
<!-- </filterchain> -->
|
||||
<!-- </loadfile> -->
|
||||
<!-- <loadfile srcfile="${lwjgl.src}/java/org/lwjgl/MacOSXSysImplementation.java" property="lwjgl.java.macosx.version"> -->
|
||||
<!-- <filterchain> -->
|
||||
<!-- <tokenfilter> -->
|
||||
<!-- <containsstring contains="JNI_VERSION ="/> -->
|
||||
<!-- </tokenfilter> -->
|
||||
<!-- </filterchain> -->
|
||||
<!-- </loadfile> -->
|
||||
<!-- <loadfile srcfile="${lwjgl.src.native}/windows/org_lwjgl_WindowsSysImplementation.h" property="lwjgl.native.windows.version"> -->
|
||||
<!-- <filterchain> -->
|
||||
<!-- <tokenfilter> -->
|
||||
<!-- <containsstring contains="#define org_lwjgl_WindowsSysImplementation_JNI_VERSION"/> -->
|
||||
<!-- </tokenfilter> -->
|
||||
<!-- </filterchain> -->
|
||||
<!-- </loadfile> -->
|
||||
<!-- <loadfile srcfile="${lwjgl.src.native}/linux/org_lwjgl_LinuxSysImplementation.h" property="lwjgl.native.linux.version"> -->
|
||||
<!-- <filterchain> -->
|
||||
<!-- <tokenfilter> -->
|
||||
<!-- <containsstring contains="#define org_lwjgl_LinuxSysImplementation_JNI_VERSION"/> -->
|
||||
<!-- </tokenfilter> -->
|
||||
<!-- </filterchain> -->
|
||||
<!-- </loadfile> -->
|
||||
<!-- <loadfile srcfile="${lwjgl.src.native}/macosx/org_lwjgl_MacOSXSysImplementation.h" property="lwjgl.native.macosx.version"> -->
|
||||
<!-- <filterchain> -->
|
||||
<!-- <tokenfilter> -->
|
||||
<!-- <containsstring contains="#define org_lwjgl_MacOSXSysImplementation_JNI_VERSION"/> -->
|
||||
<!-- </tokenfilter> -->
|
||||
<!-- </filterchain> -->
|
||||
<!-- </loadfile> -->
|
||||
<!-- <echo> -->
|
||||
<!-- lwjgl.java.windows.version = ${lwjgl.java.windows.version} -->
|
||||
<!-- lwjgl.native.windows.version = ${lwjgl.native.windows.version} -->
|
||||
<!-- lwjgl.java.linux.version = ${lwjgl.java.linux.version} -->
|
||||
<!-- lwjgl.native.linux.version = ${lwjgl.native.linux.version} -->
|
||||
<!-- lwjgl.java.freebsd.version = ${lwjgl.java.linux.version} -->
|
||||
<!-- lwjgl.native.freebsd.version = ${lwjgl.native.linux.version} -->
|
||||
<!-- lwjgl.java.openbsd.version = ${lwjgl.java.linux.version} -->
|
||||
<!-- lwjgl.native.openbsd.version = ${lwjgl.native.linux.version} -->
|
||||
<!-- lwjgl.java.macosx.version = ${lwjgl.java.macosx.version} -->
|
||||
<!-- lwjgl.native.macosx.version = ${lwjgl.native.macosx.version} -->
|
||||
<!-- </echo> -->
|
||||
<loadfile srcfile="${lwjgl.src}/java/org/lwjgl/WindowsSysImplementation.java" property="lwjgl.java.windows.version">
|
||||
<filterchain>
|
||||
<tokenfilter>
|
||||
<containsstring contains="JNI_VERSION ="/>
|
||||
</tokenfilter>
|
||||
</filterchain>
|
||||
</loadfile>
|
||||
<loadfile srcfile="${lwjgl.src}/java/org/lwjgl/LinuxSysImplementation.java" property="lwjgl.java.linux.version">
|
||||
<filterchain>
|
||||
<tokenfilter>
|
||||
<containsstring contains="JNI_VERSION ="/>
|
||||
</tokenfilter>
|
||||
</filterchain>
|
||||
</loadfile>
|
||||
<loadfile srcfile="${lwjgl.src}/java/org/lwjgl/MacOSXSysImplementation.java" property="lwjgl.java.macosx.version">
|
||||
<filterchain>
|
||||
<tokenfilter>
|
||||
<containsstring contains="JNI_VERSION ="/>
|
||||
</tokenfilter>
|
||||
</filterchain>
|
||||
</loadfile>
|
||||
<loadfile srcfile="${lwjgl.src.native}/windows/org_lwjgl_WindowsSysImplementation.h" property="lwjgl.native.windows.version">
|
||||
<filterchain>
|
||||
<tokenfilter>
|
||||
<containsstring contains="#define org_lwjgl_WindowsSysImplementation_JNI_VERSION"/>
|
||||
</tokenfilter>
|
||||
</filterchain>
|
||||
</loadfile>
|
||||
<loadfile srcfile="${lwjgl.src.native}/linux/org_lwjgl_LinuxSysImplementation.h" property="lwjgl.native.linux.version">
|
||||
<filterchain>
|
||||
<tokenfilter>
|
||||
<containsstring contains="#define org_lwjgl_LinuxSysImplementation_JNI_VERSION"/>
|
||||
</tokenfilter>
|
||||
</filterchain>
|
||||
</loadfile>
|
||||
<loadfile srcfile="${lwjgl.src.native}/macosx/org_lwjgl_MacOSXSysImplementation.h" property="lwjgl.native.macosx.version">
|
||||
<filterchain>
|
||||
<tokenfilter>
|
||||
<containsstring contains="#define org_lwjgl_MacOSXSysImplementation_JNI_VERSION"/>
|
||||
</tokenfilter>
|
||||
</filterchain>
|
||||
</loadfile>
|
||||
<echo>
|
||||
lwjgl.java.windows.version = ${lwjgl.java.windows.version}
|
||||
lwjgl.native.windows.version = ${lwjgl.native.windows.version}
|
||||
lwjgl.java.linux.version = ${lwjgl.java.linux.version}
|
||||
lwjgl.native.linux.version = ${lwjgl.native.linux.version}
|
||||
lwjgl.java.freebsd.version = ${lwjgl.java.linux.version}
|
||||
lwjgl.native.freebsd.version = ${lwjgl.native.linux.version}
|
||||
lwjgl.java.macosx.version = ${lwjgl.java.macosx.version}
|
||||
lwjgl.native.macosx.version = ${lwjgl.native.macosx.version}
|
||||
</echo>
|
||||
</target>
|
||||
|
||||
<macrodef name="version-check">
|
||||
|
|
@ -468,7 +454,7 @@
|
|||
|
||||
<!-- Compiles the Java source code -->
|
||||
<target name="compile" description="Compiles the java source code" depends="-initialize">
|
||||
<javac debug="yes" destdir="${lwjgl.bin}" source="1.7" target="1.7" classpath="${lwjgl.lib}/jinput.jar:${lwjgl.lib}/AppleJavaExtensions.jar:${lwjgl.lib}/asm-debug-all.jar" taskname="core">
|
||||
<javac debug="yes" destdir="${lwjgl.bin}" source="1.5" target="1.5" classpath="${lwjgl.lib}/jinput.jar:${lwjgl.lib}/AppleJavaExtensions.jar:${lwjgl.lib}/asm-debug-all.jar" taskname="core">
|
||||
<!--<compilerarg value="-Xlint:unchecked"/>-->
|
||||
<src path="${lwjgl.src}/java/"/>
|
||||
<src path="${lwjgl.src}/generated/"/>
|
||||
|
|
@ -481,8 +467,8 @@
|
|||
<include name="org/lwjgl/util/**"/>
|
||||
<exclude name="org/lwjgl/util/generator/**"/>
|
||||
</javac>
|
||||
<javac debug="yes" srcdir="${lwjgl.src}/java/" destdir="${lwjgl.bin}" includes="org/lwjgl/test/**" source="1.7" target="1.7" taskname="test" />
|
||||
<javac debug="yes" srcdir="${lwjgl.src}/java/" destdir="${lwjgl.bin}" includes="org/lwjgl/examples/**" source="1.7" target="1.7" taskname="examples" />
|
||||
<javac debug="yes" srcdir="${lwjgl.src}/java/" destdir="${lwjgl.bin}" includes="org/lwjgl/test/**" source="1.5" target="1.5" taskname="test" />
|
||||
<javac debug="yes" srcdir="${lwjgl.src}/java/" destdir="${lwjgl.bin}" includes="org/lwjgl/examples/**" source="1.5" target="1.5" taskname="examples" />
|
||||
</target>
|
||||
|
||||
<target name="compile_native" depends="-initialize, headers, touch-version, version-mismatch" description="Compiles the native files">
|
||||
|
|
@ -501,11 +487,6 @@
|
|||
</condition>
|
||||
<antcall target="-compile_native_freebsd" />
|
||||
|
||||
<condition property="lwjgl.platform.openbsd">
|
||||
<os name="OpenBSD" />
|
||||
</condition>
|
||||
<antcall target="-compile_native_openbsd" />
|
||||
|
||||
<condition property="lwjgl.platform.solaris">
|
||||
<os name="SunOS" />
|
||||
</condition>
|
||||
|
|
@ -543,15 +524,6 @@
|
|||
</copy>
|
||||
</target>
|
||||
|
||||
<!-- Compiles LWJGL on OpenBSD platforms -->
|
||||
<target name="-compile_native_openbsd" if="lwjgl.platform.openbsd">
|
||||
<ant antfile="platform_build/bsd_ant/build.xml" inheritAll="false"/>
|
||||
<copy todir="${lwjgl.lib}/openbsd">
|
||||
<fileset dir="${lwjgl.bin}/lwjgl" includes="liblwjgl*.so"/>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
|
||||
<!-- Compiles LWJGL on solaris platforms -->
|
||||
<target name="-compile_native_solaris" if="lwjgl.platform.solaris">
|
||||
<!-- Reusing the linux ant task, but copy the output to solaris -->
|
||||
|
|
@ -565,8 +537,8 @@
|
|||
<!-- Compiles LWJGL on Mac platforms -->
|
||||
<target name="-compile_native_macosx" if="lwjgl.platform.macosx">
|
||||
<ant antfile="platform_build/macosx_ant/build.xml" inheritAll="false"/>
|
||||
<copy file="${lwjgl.bin}/lwjgl/liblwjgl.dylib" todir="${lwjgl.lib}/macosx"/>
|
||||
<!-- <version-check platform="macosx"/> -->
|
||||
<copy file="${lwjgl.bin}/lwjgl/liblwjgl.jnilib" todir="${lwjgl.lib}/macosx"/>
|
||||
<version-check platform="macosx"/>
|
||||
</target>
|
||||
|
||||
<target name="compile_native_es" depends="-initialize, headers, touch-version, version-mismatch" description="Compiles the native files">
|
||||
|
|
@ -687,7 +659,7 @@
|
|||
<!-- get and copy nightly binaries into libs folder -->
|
||||
<target name="copy-nightly-binaries" depends="-initialize" description="Copies latest successful nightly binaries into appropriate libs folder">
|
||||
<delete file="${lwjgl.temp}/lwjgl-${lwjgl.version}.zip" failonerror="false"/>
|
||||
<get src="http://ci.newdawnsoftware.com/job/LWJGL-git-dist/lastBuild/artifact/dist/lwjgl-${lwjgl.version}.zip" dest="${lwjgl.temp}" verbose="true"/>
|
||||
<get src="http://ci.newdawnsoftware.com/view/LWJGL/job/LWJGL-git-dist/lastSuccessfulBuild/artifact/dist/lwjgl-${lwjgl.version}.zip" dest="${lwjgl.temp}" verbose="true"/>
|
||||
<unzip src="${lwjgl.temp}/lwjgl-${lwjgl.version}.zip" dest="${lwjgl.lib}" overwrite="true">
|
||||
<patternset>
|
||||
<include name="**/native/**/*lwjgl*"/>
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@
|
|||
<property name="native" location="../../src/native"/>
|
||||
<property name="libname32" value="liblwjgl.so"/>
|
||||
<property name="libname64" value="liblwjgl64.so"/>
|
||||
<property name="libs32" value="-L/usr/X11R6/lib -L/usr/local/lib -lm -lX11 -lXext -lXcursor -lXrandr -pthread -L${java.home}/lib/i386 -ljawt" />
|
||||
<property name="libs64" value="-L/usr/X11R6/lib -L/usr/local/lib -lm -lX11 -lXext -lXcursor -lXrandr -lXxf86vm -pthread -L${java.home}/lib/amd64 -ljawt" />
|
||||
<property name="libs32" value="-L/usr/local/lib -lm -lX11 -lXext -lXcursor -lXrandr -pthread -L${java.home}/lib/i386 -ljawt" />
|
||||
<property name="libs64" value="-L/usr/local/lib -lm -lX11 -lXext -lXcursor -lXrandr -lXxf86vm -pthread -L${java.home}/lib/amd64 -ljawt" />
|
||||
<property name="cflags32" value="-O2 -Wall -c -fPIC -std=c99 -Wunused"/>
|
||||
|
||||
<target name="clean">
|
||||
|
|
@ -49,13 +49,6 @@
|
|||
</and>
|
||||
</condition>
|
||||
|
||||
<condition property="build.32bit.only">
|
||||
<and>
|
||||
<os name="OpenBSD"/>
|
||||
<equals arg1="${hwplatform}" arg2="i386"/>
|
||||
</and>
|
||||
</condition>
|
||||
|
||||
<!-- On freebsd, the 64 bit jre doesn't have the 32 bit libs -->
|
||||
<condition property="build.64bit.only">
|
||||
<and>
|
||||
|
|
@ -64,13 +57,6 @@
|
|||
</and>
|
||||
</condition>
|
||||
|
||||
<condition property="build.64bit.only">
|
||||
<and>
|
||||
<os name="OpenBSD"/>
|
||||
<equals arg1="${hwplatform}" arg2="amd64"/>
|
||||
</and>
|
||||
</condition>
|
||||
|
||||
<antcall target="compile32"/>
|
||||
<antcall target="compile64"/>
|
||||
</target>
|
||||
|
|
@ -81,12 +67,9 @@
|
|||
<arg line="${cflags32} ${cflags_pthread}"/>
|
||||
<arg value="-I${java.home}/include"/>
|
||||
<arg value="-I${java.home}/include/freebsd"/>
|
||||
<arg value="-I${java.home}/include/openbsd"/>
|
||||
<arg value="-I${java.home}/../include"/>
|
||||
<arg value="-I${java.home}/../include/freebsd"/>
|
||||
<arg value="-I${java.home}/../include/openbsd"/>
|
||||
<arg value="-I/usr/local/include"/>
|
||||
<arg value="-I/usr/X11R6/include"/>
|
||||
<arg value="-I${native}/common"/>
|
||||
<arg value="-I${native}/common/opengl"/>
|
||||
<arg value="-I${native}/linux"/>
|
||||
|
|
@ -116,12 +99,9 @@
|
|||
<arg line="${cflags64} ${cflags_pthread}"/>
|
||||
<arg value="-I${java.home}/include"/>
|
||||
<arg value="-I${java.home}/include/freebsd"/>
|
||||
<arg value="-I${java.home}/include/openbsd"/>
|
||||
<arg value="-I${java.home}/../include"/>
|
||||
<arg value="-I${java.home}/../include/freebsd"/>
|
||||
<arg value="-I${java.home}/../include/openbsd"/>
|
||||
<arg value="-I/usr/local/include"/>
|
||||
<arg value="-I/usr/X11R6/include"/>
|
||||
<arg value="-I${native}/common"/>
|
||||
<arg value="-I${native}/common/opengl"/>
|
||||
<arg value="-I${native}/linux"/>
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
<property name="lwjgl.docs" location="doc" />
|
||||
<property name="lwjgl.temp" location="temp" />
|
||||
<property name="lwjgl.res" location="res" />
|
||||
<property name="lwjgl.version" value="2.9.4" />
|
||||
<property name="lwjgl.version" value="2.9.1" />
|
||||
<property name="lwjgl.web" location="www" />
|
||||
|
||||
<property name="lwjgl.src.templates.al" location="${lwjgl.src.templates}/org/lwjgl/openal"/>
|
||||
|
|
@ -147,12 +147,12 @@
|
|||
<!-- Files to include in mac os x package -->
|
||||
<patternset id="lwjgl-macosx.fileset">
|
||||
<patternset id="lwjgl-macosx-lwjgl.fileset">
|
||||
<include name="liblwjgl.dylib" />
|
||||
<include name="liblwjgl.jnilib" />
|
||||
<include name="openal.dylib" />
|
||||
</patternset>
|
||||
<patternset id="lwjgl-macosx-jinput.fileset">
|
||||
<include name="libjinput-osx.dylib" />
|
||||
<include name="libjinput-osx-legacy.dylib" />
|
||||
<include name="libjinput-osx.jnilib" />
|
||||
<include name="libjinput-osx-legacy.jnilib" />
|
||||
</patternset>
|
||||
</patternset>
|
||||
|
||||
|
|
|
|||
|
|
@ -16,24 +16,16 @@
|
|||
</target>
|
||||
|
||||
<!-- Compiles the Java generator source code -->
|
||||
<target name="generators" description="Compiles the native method generators">
|
||||
<mkdir dir="${lwjgl.src}/generated/"/>
|
||||
<mkdir dir="${lwjgl.src.native}/generated/openal"/>
|
||||
<mkdir dir="${lwjgl.src.native}/generated/opengl"/>
|
||||
<mkdir dir="${lwjgl.src.native}/generated/opengles"/>
|
||||
<mkdir dir="${lwjgl.src.native}/generated/opencl"/>
|
||||
<mkdir dir="${lwjgl.bin}"/>
|
||||
|
||||
<javac debug="yes" srcdir="${lwjgl.src}/java/" destdir="${lwjgl.bin}" source="1.7" target="1.7" includes="org/lwjgl/util/generator/**.java" taskname="generator">
|
||||
<target name="generators" description="Compiles the native method generators">
|
||||
<javac debug="yes" srcdir="${lwjgl.src}/java/" destdir="${lwjgl.bin}" includes="org/lwjgl/util/generator/**.java" source="1.5" target="1.5" taskname="generator">
|
||||
<include name="org/lwjgl/util/generator/openal/**.java"/>
|
||||
<include name="org/lwjgl/util/generator/opengl/**.java"/>
|
||||
<include name="org/lwjgl/util/generator/opengles/**.java"/>
|
||||
<include name="org/lwjgl/util/generator/opencl/**.java"/>
|
||||
<compilerarg value="-Xlint:none"/>
|
||||
</javac>
|
||||
|
||||
<!-- Compile helper classes used by the templates -->
|
||||
<javac debug="yes" srcdir="${lwjgl.src}/java/" destdir="${lwjgl.bin}" source="1.7" target="1.7" taskname="generator">
|
||||
<!-- Compile helper classes used by the templates -->
|
||||
<javac debug="yes" srcdir="${lwjgl.src}/java/" destdir="${lwjgl.bin}" source="1.5" target="1.5" taskname="generator">
|
||||
<include name="org/lwjgl/PointerWrapper.java"/>
|
||||
<include name="org/lwjgl/PointerBuffer.java"/>
|
||||
<!-- OpenGL -->
|
||||
|
|
@ -68,48 +60,40 @@
|
|||
**************************************************************************** -->
|
||||
|
||||
<!-- Generate OpenAL -->
|
||||
<target name="generate-openal" depends="generators" description="Generates java and native source for AL">
|
||||
<javac destdir="${lwjgl.bin}" source="1.7" target="1.7" srcdir="${lwjgl.src.templates.al}" fork="true" taskname="processor">
|
||||
<compilerarg value="-proc:only"/>
|
||||
<compilerarg value="-processor"/>
|
||||
<compilerarg value="org.lwjgl.util.generator.GeneratorProcessor"/>
|
||||
<compilerarg value="-cp"/>
|
||||
<compilerarg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.src}/generated"/>
|
||||
<compilerarg value="-d"/>
|
||||
<compilerarg path="${lwjgl.src.native}/generated/openal"/>
|
||||
<compilerarg value="-Abinpath=${lwjgl.bin}"/>
|
||||
<compilerarg value="-Atypemap=org.lwjgl.util.generator.openal.ALTypeMap"/>
|
||||
<src>
|
||||
<fileset dir="${lwjgl.src.templates.al}">
|
||||
<include name="${openal-template-pattern}"/>
|
||||
</fileset>
|
||||
</src>
|
||||
</javac>
|
||||
<target name="generate-openal" depends="generators" description="Generates java and native source for AL">
|
||||
<apply executable="apt" parallel="true" dir="${lwjgl.src.templates.al}" relative="true">
|
||||
<arg value="-nocompile"/>
|
||||
<arg value="-factory"/>
|
||||
<arg value="org.lwjgl.util.generator.GeneratorProcessorFactory"/>
|
||||
<arg value="-cp"/>
|
||||
<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<arg value="-s"/>
|
||||
<arg path="${lwjgl.src}/generated"/>
|
||||
<arg value="-d"/>
|
||||
<arg path="${lwjgl.src.native}/generated/openal"/>
|
||||
<arg value="-Abinpath=${lwjgl.bin}"/>
|
||||
<arg value="-Atypemap=org.lwjgl.util.generator.openal.ALTypeMap"/>
|
||||
<fileset dir="${lwjgl.src.templates.al}" includes="${openal-template-pattern}"/>
|
||||
</apply>
|
||||
</target>
|
||||
|
||||
<!-- Generate OpenAL [DEBUG] -->
|
||||
<target name="generate-openal-debug" depends="generators" description="Generates java and native source for AL">
|
||||
<javac destdir="${lwjgl.bin}" source="1.7" target="1.7" srcdir="${lwjgl.src.templates.al}" fork="true" taskname="processor">
|
||||
<compilerarg value="-proc:only"/>
|
||||
<compilerarg value="-processor"/>
|
||||
<compilerarg value="org.lwjgl.util.generator.GeneratorProcessor"/>
|
||||
<compilerarg value="-cp"/>
|
||||
<compilerarg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.src}/generated"/>
|
||||
<compilerarg value="-d"/>
|
||||
<compilerarg path="${lwjgl.src.native}/generated/openal"/>
|
||||
<compilerarg value="-Abinpath=${lwjgl.bin}"/>
|
||||
<compilerarg value="-Atypemap=org.lwjgl.util.generator.openal.ALTypeMap"/>
|
||||
<compilerarg value="-Ageneratechecks"/>
|
||||
<src>
|
||||
<fileset dir="${lwjgl.src.templates.al}">
|
||||
<include name="${openal-template-pattern}"/>
|
||||
</fileset>
|
||||
</src>
|
||||
</javac>
|
||||
<apply executable="apt" parallel="true" dir="${lwjgl.src.templates.al}" relative="true">
|
||||
<arg value="-nocompile"/>
|
||||
<arg value="-factory"/>
|
||||
<arg value="org.lwjgl.util.generator.GeneratorProcessorFactory"/>
|
||||
<arg value="-cp"/>
|
||||
<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<arg value="-s"/>
|
||||
<arg path="${lwjgl.src}/generated"/>
|
||||
<arg value="-d"/>
|
||||
<arg path="${lwjgl.src.native}/generated/openal"/>
|
||||
<arg value="-Abinpath=${lwjgl.bin}"/>
|
||||
<arg value="-Atypemap=org.lwjgl.util.generator.openal.ALTypeMap"/>
|
||||
<arg value="-Ageneratechecks"/>
|
||||
<fileset dir="${lwjgl.src.templates.al}" includes="${openal-template-pattern}"/>
|
||||
</apply>
|
||||
</target>
|
||||
|
||||
<!-- ********************************************************************************
|
||||
|
|
@ -120,106 +104,86 @@
|
|||
|
||||
<!-- Generate OpenGL -->
|
||||
<target name="generate-opengl" depends="generators" description="Generates java and native source for GL">
|
||||
<javac destdir="${lwjgl.bin}" source="1.7" target="1.7" srcdir="${lwjgl.src.templates.gl}" fork="true" taskname="processorGL">
|
||||
<compilerarg value="-proc:only"/>
|
||||
<compilerarg value="-processor"/>
|
||||
<compilerarg value="org.lwjgl.util.generator.GeneratorProcessor"/>
|
||||
<compilerarg value="-cp"/>
|
||||
<compilerarg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.src}/generated"/>
|
||||
<compilerarg value="-d"/>
|
||||
<compilerarg path="${lwjgl.src.native}/generated/opengl"/>
|
||||
<compilerarg value="-Abinpath=${lwjgl.bin}"/>
|
||||
<compilerarg value="-Atypemap=org.lwjgl.util.generator.opengl.GLTypeMap"/>
|
||||
<compilerarg value="-Acontextspecific"/>
|
||||
<src>
|
||||
<fileset dir="${lwjgl.src.templates.gl}">
|
||||
<include name="${opengl-template-pattern}"/>
|
||||
</fileset>
|
||||
</src>
|
||||
</javac>
|
||||
<apply executable="apt" parallel="true" dir="${lwjgl.src.templates.gl}" relative="true">
|
||||
<arg value="-nocompile"/>
|
||||
<arg value="-factory"/>
|
||||
<arg value="org.lwjgl.util.generator.GeneratorProcessorFactory"/>
|
||||
<arg value="-cp"/>
|
||||
<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<arg value="-s"/>
|
||||
<arg path="${lwjgl.src}/generated"/>
|
||||
<arg value="-d"/>
|
||||
<arg path="${lwjgl.src.native}/generated/opengl"/>
|
||||
<arg value="-Abinpath=${lwjgl.bin}"/>
|
||||
<arg value="-Acontextspecific"/>
|
||||
<arg value="-Atypemap=org.lwjgl.util.generator.opengl.GLTypeMap"/>
|
||||
<fileset dir="${lwjgl.src.templates.gl}" includes="${opengl-template-pattern}"/>
|
||||
</apply>
|
||||
</target>
|
||||
|
||||
<!-- Generate OpenGL [DEBUG] -->
|
||||
<target name="generate-opengl-debug" depends="generators" description="Generates debug java and native source for GL">
|
||||
<javac destdir="${lwjgl.bin}" source="1.7" target="1.7" srcdir="${lwjgl.src.templates.gl}" fork="true" taskname="processor">
|
||||
<compilerarg value="-proc:only"/>
|
||||
<compilerarg value="-processor"/>
|
||||
<compilerarg value="org.lwjgl.util.generator.GeneratorProcessor"/>
|
||||
<compilerarg value="-cp"/>
|
||||
<compilerarg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.src}/generated"/>
|
||||
<compilerarg value="-d"/>
|
||||
<compilerarg path="${lwjgl.src.native}/generated/opengl"/>
|
||||
<compilerarg value="-Abinpath=${lwjgl.bin}"/>
|
||||
<compilerarg value="-Ageneratechecks"/>
|
||||
<compilerarg value="-Acontextspecific"/>
|
||||
<compilerarg value="-Atypemap=org.lwjgl.util.generator.opengl.GLTypeMap"/>
|
||||
<src>
|
||||
<fileset dir="${lwjgl.src.templates.gl}">
|
||||
<include name="${opengl-template-pattern}"/>
|
||||
</fileset>
|
||||
</src>
|
||||
</javac>
|
||||
<apply executable="apt" parallel="true" dir="${lwjgl.src.templates.gl}" relative="true">
|
||||
<arg value="-nocompile"/>
|
||||
<arg value="-factory"/>
|
||||
<arg value="org.lwjgl.util.generator.GeneratorProcessorFactory"/>
|
||||
<arg value="-cp"/>
|
||||
<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<arg value="-s"/>
|
||||
<arg path="${lwjgl.src}/generated"/>
|
||||
<arg value="-d"/>
|
||||
<arg path="${lwjgl.src.native}/generated/opengl"/>
|
||||
<arg value="-Abinpath=${lwjgl.bin}"/>
|
||||
<arg value="-Ageneratechecks"/>
|
||||
<arg value="-Acontextspecific"/>
|
||||
<arg value="-Atypemap=org.lwjgl.util.generator.opengl.GLTypeMap"/>
|
||||
<fileset dir="${lwjgl.src.templates.gl}" includes="${opengl-template-pattern}"/>
|
||||
</apply>
|
||||
</target>
|
||||
|
||||
<!-- Generate OpenGL references -->
|
||||
<target name="generate-opengl-references" depends="generators" description="Generates java and native source for GL">
|
||||
<javac destdir="${lwjgl.bin}" source="1.7" target="1.7" srcdir="${lwjgl.src.templates.gl}" fork="true" taskname="processor">
|
||||
<compilerarg value="-proc:only"/>
|
||||
<compilerarg value="-processor"/>
|
||||
<compilerarg value="org.lwjgl.util.generator.opengl.GLReferencesGeneratorProcessor"/>
|
||||
<compilerarg value="-cp"/>
|
||||
<compilerarg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.src}/generated"/>
|
||||
<src>
|
||||
<fileset dir="${lwjgl.src.templates.gl}">
|
||||
<include name="${opengl-template-pattern}"/>
|
||||
</fileset>
|
||||
</src>
|
||||
</javac>
|
||||
<apply executable="apt" parallel="true" dir="${lwjgl.src.templates.gl}" relative="true">
|
||||
<arg value="-nocompile"/>
|
||||
<arg value="-factory"/>
|
||||
<arg value="org.lwjgl.util.generator.opengl.GLReferencesGeneratorProcessorFactory"/>
|
||||
<arg value="-cp"/>
|
||||
<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<arg value="-s"/>
|
||||
<arg path="${lwjgl.src}/generated"/>
|
||||
<fileset dir="${lwjgl.src.templates.gl}" includes="${opengl-template-pattern}"/>
|
||||
</apply>
|
||||
</target>
|
||||
|
||||
<!-- Generate OpenGL context capabilities -->
|
||||
<target name="generate-opengl-capabilities" depends="generators" description="Generates java and native source for GL">
|
||||
<javac destdir="${lwjgl.bin}" source="1.7" target="1.7" srcdir="${lwjgl.src.templates.gl}" fork="true" taskname="processor">
|
||||
<compilerarg value="-proc:only"/>
|
||||
<compilerarg value="-processor"/>
|
||||
<compilerarg value="org.lwjgl.util.generator.opengl.GLGeneratorProcessor"/>
|
||||
<compilerarg value="-cp"/>
|
||||
<compilerarg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.src}/generated"/>
|
||||
<compilerarg value="-Acontextspecific"/>
|
||||
<src>
|
||||
<fileset dir="${lwjgl.src.templates.gl}">
|
||||
<include name="${opengl-template-pattern}"/>
|
||||
</fileset>
|
||||
</src>
|
||||
</javac>
|
||||
<apply executable="apt" parallel="true" dir="${lwjgl.src.templates.gl}" relative="true">
|
||||
<arg value="-nocompile"/>
|
||||
<arg value="-factory"/>
|
||||
<arg value="org.lwjgl.util.generator.opengl.GLGeneratorProcessorFactory"/>
|
||||
<arg value="-cp"/>
|
||||
<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<arg value="-s"/>
|
||||
<arg path="${lwjgl.src}/generated"/>
|
||||
<arg value="-Acontextspecific"/>
|
||||
<fileset dir="${lwjgl.src.templates.gl}" includes="${opengl-template-pattern}"/>
|
||||
</apply>
|
||||
</target>
|
||||
|
||||
<!-- Generate OpenGL context capabilities [DEBUG] -->
|
||||
<target name="generate-opengl-capabilities-debug" depends="generators" description="Generates debug java and native source for GL">
|
||||
<javac destdir="${lwjgl.bin}" source="1.7" target="1.7" srcdir="${lwjgl.src.templates.gl}" fork="true" taskname="processor">
|
||||
<compilerarg value="-proc:only"/>
|
||||
<compilerarg value="-processor"/>
|
||||
<compilerarg value="org.lwjgl.util.generator.opengl.GLGeneratorProcessor"/>
|
||||
<compilerarg value="-cp"/>
|
||||
<compilerarg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.src}/generated"/>
|
||||
<compilerarg value="-Ageneratechecks"/>
|
||||
<compilerarg value="-Acontextspecific"/>
|
||||
<src>
|
||||
<fileset dir="${lwjgl.src.templates.gl}">
|
||||
<include name="${opengl-template-pattern}"/>
|
||||
</fileset>
|
||||
</src>
|
||||
</javac>
|
||||
<apply executable="apt" parallel="true" dir="${lwjgl.src.templates.gl}" relative="true">
|
||||
<arg value="-nocompile"/>
|
||||
<arg value="-factory"/>
|
||||
<arg value="org.lwjgl.util.generator.opengl.GLGeneratorProcessorFactory"/>
|
||||
<arg value="-cp"/>
|
||||
<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<arg value="-s"/>
|
||||
<arg path="${lwjgl.src}/generated"/>
|
||||
<arg value="-Ageneratechecks"/>
|
||||
<arg value="-Acontextspecific"/>
|
||||
<fileset dir="${lwjgl.src.templates.gl}" includes="${opengl-template-pattern}"/>
|
||||
</apply>
|
||||
</target>
|
||||
|
||||
<!-- ********************************************************************************
|
||||
|
|
@ -230,88 +194,72 @@
|
|||
|
||||
<!-- Generate OpenGL ES -->
|
||||
<target name="generate-opengles" depends="generators" description="Generates java and native source for GL ES">
|
||||
<javac destdir="${lwjgl.bin}" source="1.7" target="1.7" srcdir="${lwjgl.src.templates.gles}" fork="true" taskname="processor">
|
||||
<compilerarg value="-proc:only"/>
|
||||
<compilerarg value="-processor"/>
|
||||
<compilerarg value="org.lwjgl.util.generator.GeneratorProcessor"/>
|
||||
<compilerarg value="-cp"/>
|
||||
<compilerarg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.src}/generated"/>
|
||||
<compilerarg value="-d"/>
|
||||
<compilerarg path="${lwjgl.src.native}/generated/opengles"/>
|
||||
<compilerarg value="-Abinpath=${lwjgl.bin}"/>
|
||||
<!--<compilerarg value="-Acontextspecific"/>-->
|
||||
<compilerarg value="-Atypemap=org.lwjgl.util.generator.opengl.GLESTypeMap"/>
|
||||
<src>
|
||||
<fileset dir="${lwjgl.src.templates.gles}">
|
||||
<include name="${opengles-template-pattern}"/>
|
||||
</fileset>
|
||||
</src>
|
||||
</javac>
|
||||
<apply executable="apt" parallel="true" dir="${lwjgl.src.templates.gles}" relative="true">
|
||||
<arg value="-nocompile"/>
|
||||
<arg value="-factory"/>
|
||||
<arg value="org.lwjgl.util.generator.GeneratorProcessorFactory"/>
|
||||
<arg value="-cp"/>
|
||||
<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<arg value="-s"/>
|
||||
<arg path="${lwjgl.src}/generated"/>
|
||||
<arg value="-d"/>
|
||||
<arg path="${lwjgl.src.native}/generated/opengles"/>
|
||||
<arg value="-Abinpath=${lwjgl.bin}"/>
|
||||
<!--<arg value="-Acontextspecific"/>-->
|
||||
<arg value="-Atypemap=org.lwjgl.util.generator.opengl.GLESTypeMap"/>
|
||||
<fileset dir="${lwjgl.src.templates.gles}" includes="${opengles-template-pattern}"/>
|
||||
</apply>
|
||||
</target>
|
||||
|
||||
<!-- Generate OpenGL ES [DEBUG] -->
|
||||
<target name="generate-opengles-debug" depends="generators" description="Generates debug java and native source for GL ES">
|
||||
<javac destdir="${lwjgl.bin}" source="1.7" target="1.7" srcdir="${lwjgl.src.templates.gles}" fork="true" taskname="processor">
|
||||
<compilerarg value="-proc:only"/>
|
||||
<compilerarg value="-processor"/>
|
||||
<compilerarg value="org.lwjgl.util.generator.GeneratorProcessor"/>
|
||||
<compilerarg value="-cp"/>
|
||||
<compilerarg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.src}/generated"/>
|
||||
<compilerarg value="-d"/>
|
||||
<compilerarg path="${lwjgl.src.native}/generated/opengles"/>
|
||||
<compilerarg value="-Abinpath=${lwjgl.bin}"/>
|
||||
<compilerarg value="-Ageneratechecks"/>
|
||||
<!--<compilerarg value="-Acontextspecific"/>-->
|
||||
<compilerarg value="-Atypemap=org.lwjgl.util.generator.opengl.GLESTypeMap"/>
|
||||
<src>
|
||||
<fileset dir="${lwjgl.src.templates.gles}">
|
||||
<include name="${opengles-template-pattern}"/>
|
||||
</fileset>
|
||||
</src>
|
||||
</javac>
|
||||
<apply executable="apt" parallel="true" dir="${lwjgl.src.templates.gles}" relative="true">
|
||||
<arg value="-nocompile"/>
|
||||
<arg value="-factory"/>
|
||||
<arg value="org.lwjgl.util.generator.GeneratorProcessorFactory"/>
|
||||
<arg value="-cp"/>
|
||||
<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<arg value="-s"/>
|
||||
<arg path="${lwjgl.src}/generated"/>
|
||||
<arg value="-d"/>
|
||||
<arg path="${lwjgl.src.native}/generated/opengles"/>
|
||||
<arg value="-Abinpath=${lwjgl.bin}"/>
|
||||
<arg value="-Ageneratechecks"/>
|
||||
<!--<arg value="-Acontextspecific"/>-->
|
||||
<arg value="-Atypemap=org.lwjgl.util.generator.opengl.GLESTypeMap"/>
|
||||
<fileset dir="${lwjgl.src.templates.gles}" includes="${opengles-template-pattern}"/>
|
||||
</apply>
|
||||
</target>
|
||||
|
||||
<!-- Generate OpenGL ES context capabilities -->
|
||||
<target name="generate-opengles-capabilities" depends="generators" description="Generates java and native source for GL ES">
|
||||
<javac destdir="${lwjgl.bin}" source="1.7" target="1.7" srcdir="${lwjgl.src.templates.gles}" fork="true" taskname="processor">
|
||||
<compilerarg value="-proc:only"/>
|
||||
<compilerarg value="-processor"/>
|
||||
<compilerarg value="org.lwjgl.util.generator.opengl.GLESGeneratorProcessor"/>
|
||||
<compilerarg value="-cp"/>
|
||||
<compilerarg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.src}/generated"/>
|
||||
<!--<compilerarg value="-Acontextspecific"/>-->
|
||||
<src>
|
||||
<fileset dir="${lwjgl.src.templates.gles}">
|
||||
<include name="${opengles-template-pattern}"/>
|
||||
</fileset>
|
||||
</src>
|
||||
</javac>
|
||||
<apply executable="apt" parallel="true" dir="${lwjgl.src.templates.gles}" relative="true">
|
||||
<arg value="-nocompile"/>
|
||||
<arg value="-factory"/>
|
||||
<arg value="org.lwjgl.util.generator.opengl.GLESGeneratorProcessorFactory"/>
|
||||
<arg value="-cp"/>
|
||||
<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<arg value="-s"/>
|
||||
<arg path="${lwjgl.src}/generated"/>
|
||||
<!--<arg value="-Acontextspecific"/>-->
|
||||
<fileset dir="${lwjgl.src.templates.gles}" includes="${opengles-template-pattern}"/>
|
||||
</apply>
|
||||
</target>
|
||||
|
||||
<!-- Generate OpenGL ES context capabilities [DEBUG] -->
|
||||
<target name="generate-opengles-capabilities-debug" depends="generators" description="Generates debug java and native source for GL ES">
|
||||
<javac destdir="${lwjgl.bin}" source="1.7" target="1.7" srcdir="${lwjgl.src.templates.gles}" fork="true" taskname="processor">
|
||||
<compilerarg value="-proc:only"/>
|
||||
<compilerarg value="-processor"/>
|
||||
<compilerarg value="org.lwjgl.util.generator.opengl.GLESGeneratorProcessor"/>
|
||||
<compilerarg value="-cp"/>
|
||||
<compilerarg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.src}/generated"/>
|
||||
<compilerarg value="-Ageneratechecks"/>
|
||||
<!--<compilerarg value="-Acontextspecific"/>-->
|
||||
<src>
|
||||
<fileset dir="${lwjgl.src.templates.gles}">
|
||||
<include name="${opengles-template-pattern}"/>
|
||||
</fileset>
|
||||
</src>
|
||||
</javac>
|
||||
<apply executable="apt" parallel="true" dir="${lwjgl.src.templates.gles}" relative="true">
|
||||
<arg value="-nocompile"/>
|
||||
<arg value="-factory"/>
|
||||
<arg value="org.lwjgl.util.generator.opengl.GLESGeneratorProcessorFactory"/>
|
||||
<arg value="-cp"/>
|
||||
<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<arg value="-s"/>
|
||||
<arg path="${lwjgl.src}/generated"/>
|
||||
<arg value="-Ageneratechecks"/>
|
||||
<!--<arg value="-Acontextspecific"/>-->
|
||||
<fileset dir="${lwjgl.src.templates.gles}" includes="${opengles-template-pattern}"/>
|
||||
</apply>
|
||||
</target>
|
||||
|
||||
<!-- ********************************************************************************
|
||||
|
|
@ -322,87 +270,71 @@
|
|||
|
||||
<!-- Generate OpenCL -->
|
||||
<target name="generate-opencl" depends="generators" description="Generates java and native source for CL">
|
||||
<javac destdir="${lwjgl.bin}" source="1.7" target="1.7" srcdir="${lwjgl.src.templates.cl}" fork="true" taskname="processor">
|
||||
<compilerarg value="-proc:only"/>
|
||||
<compilerarg value="-processor"/>
|
||||
<compilerarg value="org.lwjgl.util.generator.GeneratorProcessor"/>
|
||||
<compilerarg value="-cp"/>
|
||||
<compilerarg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.src}/generated"/>
|
||||
<compilerarg value="-d"/>
|
||||
<compilerarg path="${lwjgl.src.native}/generated/opencl"/>
|
||||
<compilerarg value="-Abinpath=${lwjgl.bin}"/>
|
||||
<compilerarg value="-Acontextspecific"/>
|
||||
<compilerarg value="-Atypemap=org.lwjgl.util.generator.opencl.CLTypeMap"/>
|
||||
<src>
|
||||
<fileset dir="${lwjgl.src.templates.cl}">
|
||||
<include name="${opencl-template-pattern}"/>
|
||||
</fileset>
|
||||
</src>
|
||||
</javac>
|
||||
<apply executable="apt" parallel="true" dir="${lwjgl.src.templates.cl}" relative="true">
|
||||
<arg value="-nocompile"/>
|
||||
<arg value="-factory"/>
|
||||
<arg value="org.lwjgl.util.generator.GeneratorProcessorFactory"/>
|
||||
<arg value="-cp"/>
|
||||
<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<arg value="-s"/>
|
||||
<arg path="${lwjgl.src}/generated"/>
|
||||
<arg value="-d"/>
|
||||
<arg path="${lwjgl.src.native}/generated/opencl"/>
|
||||
<arg value="-Abinpath=${lwjgl.bin}"/>
|
||||
<arg value="-Acontextspecific"/>
|
||||
<arg value="-Atypemap=org.lwjgl.util.generator.opencl.CLTypeMap"/>
|
||||
<fileset dir="${lwjgl.src.templates.cl}" includes="${opencl-template-pattern}"/>
|
||||
</apply>
|
||||
</target>
|
||||
|
||||
<!-- Generate OpenCL [DEBUG] -->
|
||||
<target name="generate-opencl-debug" depends="generators" description="Generates debug java and native source for CL">
|
||||
<javac destdir="${lwjgl.bin}" source="1.7" target="1.7" srcdir="${lwjgl.src.templates.cl}" fork="true" taskname="processor">
|
||||
<compilerarg value="-proc:only"/>
|
||||
<compilerarg value="-processor"/>
|
||||
<compilerarg value="org.lwjgl.util.generator.GeneratorProcessor"/>
|
||||
<compilerarg value="-cp"/>
|
||||
<compilerarg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.src}/generated"/>
|
||||
<compilerarg value="-d"/>
|
||||
<compilerarg path="${lwjgl.src.native}/generated/opencl"/>
|
||||
<compilerarg value="-Abinpath=${lwjgl.bin}"/>
|
||||
<compilerarg value="-Ageneratechecks"/>
|
||||
<compilerarg value="-Acontextspecific"/>
|
||||
<compilerarg value="-Atypemap=org.lwjgl.util.generator.opencl.CLTypeMap"/>
|
||||
<src>
|
||||
<fileset dir="${lwjgl.src.templates.cl}">
|
||||
<include name="${opencl-template-pattern}"/>
|
||||
</fileset>
|
||||
</src>
|
||||
</javac>
|
||||
<apply executable="apt" parallel="true" dir="${lwjgl.src.templates.cl}" relative="true">
|
||||
<arg value="-nocompile"/>
|
||||
<arg value="-factory"/>
|
||||
<arg value="org.lwjgl.util.generator.GeneratorProcessorFactory"/>
|
||||
<arg value="-cp"/>
|
||||
<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<arg value="-s"/>
|
||||
<arg path="${lwjgl.src}/generated"/>
|
||||
<arg value="-d"/>
|
||||
<arg path="${lwjgl.src.native}/generated/opencl"/>
|
||||
<arg value="-Abinpath=${lwjgl.bin}"/>
|
||||
<arg value="-Ageneratechecks"/>
|
||||
<arg value="-Acontextspecific"/>
|
||||
<arg value="-Atypemap=org.lwjgl.util.generator.opencl.CLTypeMap"/>
|
||||
<fileset dir="${lwjgl.src.templates.cl}" includes="${opencl-template-pattern}"/>
|
||||
</apply>
|
||||
</target>
|
||||
|
||||
<!-- Generate OpenCL capabilities -->
|
||||
<target name="generate-opencl-capabilities" depends="generators" description="Generates capabilities for CL">
|
||||
<javac destdir="${lwjgl.bin}" source="1.7" target="1.7" srcdir="${lwjgl.src.templates.cl}" fork="true" taskname="processor">
|
||||
<compilerarg value="-proc:only"/>
|
||||
<compilerarg value="-processor"/>
|
||||
<compilerarg value="org.lwjgl.util.generator.opencl.CLGeneratorProcessor"/>
|
||||
<compilerarg value="-cp"/>
|
||||
<compilerarg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.src}/generated"/>
|
||||
<compilerarg value="-Acontextspecific"/>
|
||||
<src>
|
||||
<fileset dir="${lwjgl.src.templates.cl}">
|
||||
<include name="${opencl-template-pattern}"/>
|
||||
</fileset>
|
||||
</src>
|
||||
</javac>
|
||||
<apply executable="apt" parallel="true" dir="${lwjgl.src.templates.cl}" relative="true">
|
||||
<arg value="-nocompile"/>
|
||||
<arg value="-factory"/>
|
||||
<arg value="org.lwjgl.util.generator.opencl.CLGeneratorProcessorFactory"/>
|
||||
<arg value="-cp"/>
|
||||
<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<arg value="-s"/>
|
||||
<arg path="${lwjgl.src}/generated"/>
|
||||
<arg value="-Acontextspecific"/>
|
||||
<fileset dir="${lwjgl.src.templates.cl}" includes="${opencl-template-pattern}"/>
|
||||
</apply>
|
||||
</target>
|
||||
|
||||
<!-- Generate OpenCL capabilities [DEBUG] -->
|
||||
<target name="generate-opencl-capabilities-debug" depends="generators" description="Generates debug capabilities for CL">
|
||||
<javac destdir="${lwjgl.bin}" source="1.7" target="1.7" srcdir="${lwjgl.src.templates.cl}" fork="true" taskname="processor">
|
||||
<compilerarg value="-proc:only"/>
|
||||
<compilerarg value="-processor"/>
|
||||
<compilerarg value="org.lwjgl.util.generator.opencl.CLGeneratorProcessor"/>
|
||||
<compilerarg value="-cp"/>
|
||||
<compilerarg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<compilerarg value="-s"/>
|
||||
<compilerarg path="${lwjgl.src}/generated"/>
|
||||
<compilerarg value="-Ageneratechecks"/>
|
||||
<compilerarg value="-Acontextspecific"/>
|
||||
<src>
|
||||
<fileset dir="${lwjgl.src.templates.cl}">
|
||||
<include name="${opencl-template-pattern}"/>
|
||||
</fileset>
|
||||
</src>
|
||||
</javac>
|
||||
<apply executable="apt" parallel="true" dir="${lwjgl.src.templates.cl}" relative="true">
|
||||
<arg value="-nocompile"/>
|
||||
<arg value="-factory"/>
|
||||
<arg value="org.lwjgl.util.generator.opencl.CLGeneratorProcessorFactory"/>
|
||||
<arg value="-cp"/>
|
||||
<arg path="${lwjgl.src}/java:${lwjgl.src.templates}:${lwjgl.bin}:${java.class.path}"/>
|
||||
<arg value="-s"/>
|
||||
<arg path="${lwjgl.src}/generated"/>
|
||||
<arg value="-Ageneratechecks"/>
|
||||
<arg value="-Acontextspecific"/>
|
||||
<fileset dir="${lwjgl.src.templates.cl}" includes="${opencl-template-pattern}"/>
|
||||
</apply>
|
||||
</target>
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@
|
|||
|
||||
<target name="compile32" unless="build.64bit.only">
|
||||
<mkdir dir="x32"/>
|
||||
<apply dir="x32" executable="gcc" skipemptyfilesets="true" failonerror="true" parallel="true">
|
||||
<apply dir="x32" executable="gcc" skipemptyfilesets="true" failonerror="true">
|
||||
<arg line="${cflags32} ${cflags_pthread}"/>
|
||||
<arg value="-I${java.home}/include"/>
|
||||
<arg value="-I${java.home}/include/linux"/>
|
||||
|
|
@ -94,7 +94,7 @@
|
|||
|
||||
<target name="compile64" unless="build.32bit.only">
|
||||
<mkdir dir="x64"/>
|
||||
<apply dir="x64" executable="gcc" skipemptyfilesets="true" failonerror="true" parallel="true">
|
||||
<apply dir="x64" executable="gcc" skipemptyfilesets="true" failonerror="true">
|
||||
<arg line="${cflags64} ${cflags_pthread}"/>
|
||||
<arg value="-I${java.home}/include"/>
|
||||
<arg value="-I${java.home}/include/linux"/>
|
||||
|
|
|
|||
|
|
@ -4,8 +4,7 @@
|
|||
<property name="native" location="../../src/native"/>
|
||||
<property name="libname32" value="liblwjgl.so"/>
|
||||
<property name="libname64" value="liblwjgl64.so"/>
|
||||
<property name="lib_folder" value="${lwjgl.lib}/linux"/>
|
||||
<property name="libs32" value="-L${lib_folder} -lEGL -L/usr/X11R6/lib -L/usr/X11/lib -lm -lX11 -lXext -lXcursor -lXrandr -lXxf86vm -lpthread -L${java.home}/lib/i386 -ljawt" />
|
||||
<property name="libs32" value="-L/home/spasi/lwjgl/libs/linux -lEGL -L/usr/X11R6/lib -L/usr/X11/lib -lm -lX11 -lXext -lXcursor -lXrandr -lpthread -L${java.home}/lib/i386 -ljawt" />
|
||||
<property name="libs64" value="-L${lib_folder}/x64 -lEGL -L/usr/X11R6/lib64 -L/usr/X11/lib64 -lm -lX11 -lXext -lXcursor -lXrandr -lXxf86vm -lpthread -L${java.home}/lib/amd64 -ljawt" />
|
||||
<property name="cflags32" value="-O2 -Wall -c -fPIC -std=c99 -Wunused"/>
|
||||
|
||||
|
|
@ -22,6 +21,9 @@
|
|||
<exec executable="uname" outputproperty="hwplatform">
|
||||
<arg value="-m"/>
|
||||
</exec>
|
||||
<condition property="xf86vm_lib" value="-lXxf86vm" else="-Wl,-static,-lXxf86vm,-call_shared">
|
||||
<os name="SunOS" />
|
||||
</condition>
|
||||
<condition property="cflags_pthread" value="-pthreads" else="-pthread">
|
||||
<os name="SunOS" />
|
||||
</condition>
|
||||
|
|
@ -37,8 +39,8 @@
|
|||
<os name="SunOS" />
|
||||
</condition>
|
||||
|
||||
<property name="linker_flags32" value="${version_script_flags32} -shared -O2 -Wall -o ${libname32} ${libs32}"/>
|
||||
<property name="linker_flags64" value="${version_script_flags64} -shared -O2 -Wall -o ${libname64} ${libs64}"/>
|
||||
<property name="linker_flags32" value="${version_script_flags32} -shared -O2 -Wall -o ${libname32} ${libs32} ${xf86vm_lib}"/>
|
||||
<property name="linker_flags64" value="${version_script_flags64} -shared -O2 -Wall -o ${libname64} ${libs64} ${xf86vm_lib}"/>
|
||||
|
||||
<condition property="build.32bit.only">
|
||||
<not>
|
||||
|
|
@ -124,4 +126,4 @@
|
|||
<fileset file="${libname64}"/>
|
||||
</apply>
|
||||
</target>
|
||||
</project>
|
||||
</project>
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#!/bin/sh
|
||||
|
||||
nm -j -g "$1"/*.o | grep -E "J(ava|NI)_[^.]*$"
|
||||
nm -g "$1"/*.o | grep "Java_" | cut -d ' ' -f3 | cut -c 1-
|
||||
nm -g "$1"/*.o | grep "JNI_" | cut -d ' ' -f3 | cut -c 1-
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -272,7 +272,7 @@ public class LWJGLUtil {
|
|||
final String osName = getPrivilegedProperty("os.name");
|
||||
if ( osName.startsWith("Windows") )
|
||||
PLATFORM = PLATFORM_WINDOWS;
|
||||
else if ( osName.startsWith("Linux") || osName.startsWith("FreeBSD") || osName.startsWith("OpenBSD") || osName.startsWith("SunOS") || osName.startsWith("Unix") )
|
||||
else if ( osName.startsWith("Linux") || osName.startsWith("FreeBSD") || osName.startsWith("SunOS") || osName.startsWith("Unix") )
|
||||
PLATFORM = PLATFORM_LINUX;
|
||||
else if ( osName.startsWith("Mac OS X") || osName.startsWith("Darwin") )
|
||||
PLATFORM = PLATFORM_MACOSX;
|
||||
|
|
@ -319,21 +319,6 @@ public class LWJGLUtil {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps {@link System#mapLibraryName}. On OS X with JDK 6, the .jnilib file
|
||||
* extension will be replaced with .dylib.
|
||||
*
|
||||
* @param name the name of the library.
|
||||
*
|
||||
* @return a platform-dependent native library name.
|
||||
*/
|
||||
public static String mapLibraryName(String name) {
|
||||
String libName = System.mapLibraryName(name);
|
||||
return LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_MACOSX && libName.endsWith(".jnilib")
|
||||
? libName.substring(0, libName.length() - ".jnilib".length()) + ".dylib"
|
||||
: libName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Locates the paths required by a library.
|
||||
*
|
||||
|
|
@ -436,7 +421,7 @@ public class LWJGLUtil {
|
|||
*/
|
||||
private static String getPathFromClassLoader(final String libname, final ClassLoader classloader) {
|
||||
Class<?> c = null;
|
||||
|
||||
|
||||
try {
|
||||
log("getPathFromClassLoader: searching for: " + libname);
|
||||
c = classloader.getClass();
|
||||
|
|
@ -620,7 +605,7 @@ public class LWJGLUtil {
|
|||
* @param field the Field to test
|
||||
* @param value the integer value of the field
|
||||
*
|
||||
* @return true if the Field is accepted
|
||||
* @result true if the Field is accepted
|
||||
*/
|
||||
boolean accept(Field field, int value);
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
*/
|
||||
package org.lwjgl;
|
||||
|
||||
import com.apple.eio.FileManager;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
|
|
@ -54,5 +55,13 @@ final class MacOSXSysImplementation extends J2SESysImplementation {
|
|||
return JNI_VERSION;
|
||||
}
|
||||
|
||||
public native boolean openURL(String url);
|
||||
public boolean openURL(String url) {
|
||||
try {
|
||||
FileManager.openURL(url);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
LWJGLUtil.log("Exception occurred while trying to invoke browser: " + e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,10 +62,10 @@ public final class MemoryUtil {
|
|||
// Depends on java.nio.Buffer#address and sun.misc.Unsafe
|
||||
util = loadAccessor("org.lwjgl.MemoryUtilSun$AccessorUnsafe");
|
||||
} 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 and sun.reflect.FieldAccessor
|
||||
util = loadAccessor("org.lwjgl.MemoryUtilSun$AccessorReflectFast");
|
||||
} catch (Exception e1) {
|
||||
try {
|
||||
// Depends on java.nio.Buffer#address
|
||||
util = new AccessorReflect();
|
||||
|
|
@ -73,7 +73,7 @@ public final class MemoryUtil {
|
|||
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());
|
||||
|
|
@ -282,8 +282,7 @@ public final class MemoryUtil {
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
// cast to use Buffer's implementation of flip even when compiling against versions of java that have ByteBuffer::flip
|
||||
((Buffer)out).flip();
|
||||
out.flip();
|
||||
return out;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ import java.lang.reflect.Modifier;
|
|||
import java.nio.Buffer;
|
||||
|
||||
import sun.misc.Unsafe;
|
||||
// import sun.reflect.FieldAccessor;
|
||||
import sun.reflect.FieldAccessor;
|
||||
|
||||
/**
|
||||
* MemoryUtil.Accessor implementations that depend on sun.misc.
|
||||
|
|
@ -104,32 +104,32 @@ final class MemoryUtilSun {
|
|||
}
|
||||
|
||||
/** Implementation using reflection on ByteBuffer, FieldAccessor is used directly. */
|
||||
// private static class AccessorReflectFast implements MemoryUtil.Accessor {
|
||||
private static class AccessorReflectFast implements MemoryUtil.Accessor {
|
||||
|
||||
// private final FieldAccessor addressAccessor;
|
||||
private final FieldAccessor addressAccessor;
|
||||
|
||||
// AccessorReflectFast() {
|
||||
// Field address;
|
||||
// try {
|
||||
// address = MemoryUtil.getAddressField();
|
||||
// } catch (NoSuchFieldException e) {
|
||||
// throw new UnsupportedOperationException(e);
|
||||
// }
|
||||
// address.setAccessible(true);
|
||||
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);
|
||||
// }
|
||||
// }
|
||||
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);
|
||||
// }
|
||||
public long getAddress(final Buffer buffer) {
|
||||
return addressAccessor.getLong(buffer);
|
||||
}
|
||||
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -54,7 +54,7 @@ public final class Sys {
|
|||
private static final String JNI_LIBRARY_NAME = "lwjgl";
|
||||
|
||||
/** Current version of library */
|
||||
private static final String VERSION = "2.9.4";
|
||||
private static final String VERSION = "2.9.1";
|
||||
|
||||
private static final String POSTFIX64BIT = "64";
|
||||
|
||||
|
|
@ -67,7 +67,8 @@ public final class Sys {
|
|||
public Object run() {
|
||||
String library_path = System.getProperty("org.lwjgl.librarypath");
|
||||
if (library_path != null) {
|
||||
System.load(library_path + File.separator + LWJGLUtil.mapLibraryName(lib_name));
|
||||
System.load(library_path + File.separator +
|
||||
System.mapLibraryName(lib_name));
|
||||
} else {
|
||||
System.loadLibrary(lib_name);
|
||||
}
|
||||
|
|
@ -79,15 +80,13 @@ public final class Sys {
|
|||
private static void loadLibrary(final String lib_name) {
|
||||
// actively try to load 64bit libs on 64bit architectures first
|
||||
String osArch = System.getProperty("os.arch");
|
||||
boolean try64First = LWJGLUtil.getPlatform() != LWJGLUtil.PLATFORM_MACOSX && ("amd64".equals(osArch) || "x86_64".equals(osArch));
|
||||
|
||||
Error err = null;
|
||||
if ( try64First ) {
|
||||
boolean is64bit = "amd64".equals(osArch) || "x86_64".equals(osArch);
|
||||
if(is64bit) {
|
||||
try {
|
||||
doLoadLibrary(lib_name + POSTFIX64BIT);
|
||||
return;
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
err = e;
|
||||
LWJGLUtil.log("Failed to load 64 bit library: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -95,9 +94,6 @@ public final class Sys {
|
|||
try {
|
||||
doLoadLibrary(lib_name);
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
if ( try64First )
|
||||
throw err;
|
||||
|
||||
if (implementation.has64Bit()) {
|
||||
try {
|
||||
doLoadLibrary(lib_name + POSTFIX64BIT);
|
||||
|
|
@ -106,7 +102,6 @@ public final class Sys {
|
|||
LWJGLUtil.log("Failed to load 64 bit library: " + e2.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Throw original error
|
||||
throw e;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,6 @@ package org.lwjgl.input;
|
|||
|
||||
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;
|
||||
|
|
@ -332,7 +331,7 @@ public class Keyboard {
|
|||
}
|
||||
|
||||
private static void reset() {
|
||||
((Buffer)readBuffer).limit(0);
|
||||
readBuffer.limit(0);
|
||||
for (int i = 0; i < keyDownBuffer.remaining(); i++)
|
||||
keyDownBuffer.put(i, (byte)0);
|
||||
current_event.reset();
|
||||
|
|
@ -393,7 +392,7 @@ public class Keyboard {
|
|||
private static void read() {
|
||||
readBuffer.compact();
|
||||
implementation.readKeyboard(readBuffer);
|
||||
((Buffer)readBuffer).flip();
|
||||
readBuffer.flip();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -454,7 +453,7 @@ public class Keyboard {
|
|||
int num_events = 0;
|
||||
while (readNext(tmp_event) && (!tmp_event.repeat || repeat_enabled))
|
||||
num_events++;
|
||||
((Buffer)readBuffer).position(old_position);
|
||||
readBuffer.position(old_position);
|
||||
return num_events;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@
|
|||
*/
|
||||
package org.lwjgl.input;
|
||||
|
||||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.security.AccessController;
|
||||
|
|
@ -250,7 +249,7 @@ public class Mouse {
|
|||
|
||||
private static void resetMouse() {
|
||||
dx = dy = dwheel = 0;
|
||||
((Buffer)readBuffer).position(readBuffer.limit());
|
||||
readBuffer.position(readBuffer.limit());
|
||||
}
|
||||
|
||||
static InputImplementation getImplementation() {
|
||||
|
|
@ -280,7 +279,7 @@ public class Mouse {
|
|||
if (currentCursor != null && implementation.getNativeCursorCapabilities() != 0)
|
||||
setNativeCursor(currentCursor);
|
||||
readBuffer = ByteBuffer.allocate(EVENT_SIZE * BUFFER_SIZE);
|
||||
((Buffer)readBuffer).limit(0);
|
||||
readBuffer.limit(0);
|
||||
setGrabbed(isGrabbed);
|
||||
}
|
||||
|
||||
|
|
@ -384,7 +383,7 @@ public class Mouse {
|
|||
private static void read() {
|
||||
readBuffer.compact();
|
||||
implementation.readMouse(readBuffer);
|
||||
((Buffer)readBuffer).flip();
|
||||
readBuffer.flip();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -115,13 +115,8 @@ public final class AL {
|
|||
String[] library_names;
|
||||
switch (LWJGLUtil.getPlatform()) {
|
||||
case LWJGLUtil.PLATFORM_WINDOWS:
|
||||
if ( Sys.is64Bit() ) {
|
||||
libname = "OpenAL64";
|
||||
library_names = new String[]{"OpenAL64.dll"};
|
||||
} else {
|
||||
libname = "OpenAL32";
|
||||
library_names = new String[]{"OpenAL32.dll"};
|
||||
}
|
||||
libname = "OpenAL32";
|
||||
library_names = new String[]{"OpenAL64.dll", "OpenAL32.dll"};
|
||||
break;
|
||||
case LWJGLUtil.PLATFORM_LINUX:
|
||||
libname = "openal";
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@
|
|||
*/
|
||||
package org.lwjgl.openal;
|
||||
|
||||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
|
|
@ -178,7 +177,7 @@ public final class ALC11 {
|
|||
try {
|
||||
IntBuffer ib = BufferUtils.createIntBuffer(2);
|
||||
ALC10.alcGetInteger(AL.getDevice(), ALC10.ALC_MAJOR_VERSION, ib);
|
||||
((Buffer)ib).position(1);
|
||||
ib.position(1);
|
||||
ALC10.alcGetInteger(AL.getDevice(), ALC10.ALC_MINOR_VERSION, ib);
|
||||
|
||||
int major = ib.get(0);
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ public final class ALCcontext {
|
|||
* @param contextFrequency Frequency to add
|
||||
* @param contextRefresh Refresh rate to add
|
||||
* @param contextSynchronized Whether to synchronize the context
|
||||
* @return attribute list
|
||||
* @return
|
||||
*/
|
||||
static IntBuffer createAttributeList(int contextFrequency, int contextRefresh, int contextSynchronized) {
|
||||
IntBuffer attribList = BufferUtils.createIntBuffer(7);
|
||||
|
|
|
|||
|
|
@ -31,11 +31,9 @@
|
|||
*/
|
||||
package org.lwjgl.opencl;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.LWJGLUtil;
|
||||
import org.lwjgl.PointerBuffer;
|
||||
|
||||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import static org.lwjgl.opencl.CL10.*;
|
||||
|
|
@ -139,7 +137,7 @@ final class CLChecks {
|
|||
*
|
||||
* @return the 2D image size in bytes
|
||||
*/
|
||||
static int calculateImage2DSize(final Buffer host_ptr, final ByteBuffer format, final long w, final long h, long row_pitch) {
|
||||
static int calculateImage2DSize(final ByteBuffer format, final long w, final long h, long row_pitch) {
|
||||
if ( !LWJGLUtil.CHECKS )
|
||||
return 0;
|
||||
|
||||
|
|
@ -153,7 +151,7 @@ final class CLChecks {
|
|||
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) >> BufferUtils.getElementSizeExponent(host_ptr);
|
||||
return (int)(row_pitch * h);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -168,7 +166,7 @@ final class CLChecks {
|
|||
*
|
||||
* @return the 3D image size in bytes
|
||||
*/
|
||||
static int calculateImage3DSize(final Buffer host_ptr, final ByteBuffer format, final long w, final long h, final long d, long row_pitch, long slice_pitch) {
|
||||
static int calculateImage3DSize(final ByteBuffer format, final long w, final long h, final long d, long row_pitch, long slice_pitch) {
|
||||
if ( !LWJGLUtil.CHECKS )
|
||||
return 0;
|
||||
|
||||
|
|
@ -187,7 +185,7 @@ final class CLChecks {
|
|||
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) >> BufferUtils.getElementSizeExponent(host_ptr);
|
||||
return (int)(slice_pitch * d);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -305,7 +305,7 @@ final class InfoUtilFactory {
|
|||
errcode_ret = APIUtil.getBufferInt();
|
||||
|
||||
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(host_ptr, formatBuffer, image_width, image_height, image_row_pitch)) : 0),
|
||||
(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));
|
||||
|
|
@ -325,7 +325,7 @@ final class InfoUtilFactory {
|
|||
errcode_ret = APIUtil.getBufferInt();
|
||||
|
||||
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(host_ptr, formatBuffer, image_width, image_height, image_depth, image_row_pitch, image_slice_pitch)) : 0),
|
||||
(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));
|
||||
|
|
@ -603,4 +603,4 @@ final class InfoUtilFactory {
|
|||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -97,7 +97,7 @@ final class APIUtil {
|
|||
buffer = BufferUtils.createByteBuffer(size);
|
||||
caps.util.buffer = buffer;
|
||||
} else
|
||||
((Buffer)buffer).clear();
|
||||
buffer.clear();
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
|
@ -114,8 +114,8 @@ final class APIUtil {
|
|||
bufferNew.put(buffer);
|
||||
caps.util.buffer = (buffer = bufferNew);
|
||||
} else {
|
||||
((Buffer)buffer).position(buffer.limit());
|
||||
((Buffer)buffer).limit(buffer.capacity());
|
||||
buffer.position(buffer.limit());
|
||||
buffer.limit(buffer.capacity());
|
||||
}
|
||||
|
||||
return buffer;
|
||||
|
|
@ -193,7 +193,7 @@ final class APIUtil {
|
|||
*/
|
||||
static long getBuffer(final ContextCapabilities caps, final CharSequence string) {
|
||||
final ByteBuffer buffer = encode(getBufferByte(caps, string.length()), string);
|
||||
((Buffer)buffer).flip();
|
||||
buffer.flip();
|
||||
return MemoryUtil.getAddress0(buffer);
|
||||
}
|
||||
|
||||
|
|
@ -206,7 +206,7 @@ final class APIUtil {
|
|||
*/
|
||||
static long getBuffer(final ContextCapabilities caps, final CharSequence string, final int offset) {
|
||||
final ByteBuffer buffer = encode(getBufferByteOffset(caps, offset + string.length()), string);
|
||||
((Buffer)buffer).flip();
|
||||
buffer.flip();
|
||||
return MemoryUtil.getAddress(buffer);
|
||||
}
|
||||
|
||||
|
|
@ -220,7 +220,7 @@ final class APIUtil {
|
|||
static long getBufferNT(final ContextCapabilities caps, final CharSequence string) {
|
||||
final ByteBuffer buffer = encode(getBufferByte(caps, string.length() + 1), string);
|
||||
buffer.put((byte)0);
|
||||
((Buffer)buffer).flip();
|
||||
buffer.flip();
|
||||
return MemoryUtil.getAddress0(buffer);
|
||||
}
|
||||
|
||||
|
|
@ -245,7 +245,7 @@ final class APIUtil {
|
|||
for ( CharSequence string : strings )
|
||||
encode(buffer, string);
|
||||
|
||||
((Buffer)buffer).flip();
|
||||
buffer.flip();
|
||||
return MemoryUtil.getAddress0(buffer);
|
||||
}
|
||||
|
||||
|
|
@ -264,7 +264,7 @@ final class APIUtil {
|
|||
buffer.put((byte)0);
|
||||
}
|
||||
|
||||
((Buffer)buffer).flip();
|
||||
buffer.flip();
|
||||
return MemoryUtil.getAddress0(buffer);
|
||||
}
|
||||
|
||||
|
|
@ -281,7 +281,7 @@ final class APIUtil {
|
|||
for ( CharSequence string : strings )
|
||||
buffer.put(string.length());
|
||||
|
||||
((Buffer)buffer).flip();
|
||||
buffer.flip();
|
||||
return MemoryUtil.getAddress0(buffer);
|
||||
}
|
||||
|
||||
|
|
@ -293,4 +293,4 @@ final class APIUtil {
|
|||
return MemoryUtil.getAddress0(getBufferByte(caps, 0));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2014 LWJGL Project
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -35,399 +35,291 @@ import org.lwjgl.BufferUtils;
|
|||
import org.lwjgl.LWJGLUtil;
|
||||
|
||||
import java.nio.IntBuffer;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
/**
|
||||
* This class represents the context attributes passed to CreateContextAttribs of the ARB_create_context extension.
|
||||
* <p/>
|
||||
* The attributes supported are described in the following extensions:<br>
|
||||
* <ul>
|
||||
* <li><a href="http://www.opengl.org/registry/specs/ARB/wgl_create_context.txt">WGL_ARB_create_context(_profile)</a> and <a href="http://www.opengl.org/registry/specs/ARB/glx_create_context.txt">GLX_ARB_create_context(_profile)</a></li>
|
||||
* <li><a href="http://www.opengl.org/registry/specs/ARB/wgl_create_context_robustness.txt">WGL_ARB_create_context_robustness</a> and <a href="http://www.opengl.org/registry/specs/ARB/glx_create_context_robustness.txt">GLX_ARB_create_context_robustness</a></li>
|
||||
* <li><a href="http://www.opengl.org/registry/specs/ARB/wgl_robustness_isolation.txt">WGL_ARB_robustness_isolation</a> and <a href="http://www.opengl.org/registry/specs/ARB/glx_robustness_isolation.txt">GLX_ARB_robustness_isolation</a></li>
|
||||
* <li><a href="http://www.opengl.org/registry/specs/ARB/wgl_create_context_es2_profile.txt">WGL_EXT_create_context_es2_profile</a> and <a href="http://www.opengl.org/registry/specs/ARB/glx_create_context_es2_profile.txt">GLX_EXT_create_context_es2_profile</a></li>
|
||||
* <li><a href="http://www.opengl.org/registry/specs/ARB/context_flush_control.txt">KHR_context_flush_control</a></li>
|
||||
* </ul>
|
||||
* This class represents the context attributes passed to CreateContextAttribs of the ARB_create_context and
|
||||
* ARB_create_context_profile extensions.
|
||||
* These attributes can be used to indicate at context creation which OpenGL interface will be used. This includes the
|
||||
* OpenGL version, the layer plane on which rendering takes place and also optional debug and forward combatibility modes.
|
||||
* (read the ARB_create_context spec for details)
|
||||
* <p/>
|
||||
* Use of this class is optional. If an OpenGL context is created without passing an instance of this class
|
||||
* (or ARB_create_context is not supported), the old context creation code will be used. Support for debug and forward
|
||||
* compatible mobes is not guaranteed by the OpenGL implementation. Developers may encounter debug contexts being the same
|
||||
* as non-debug contexts or forward compatible contexts having support for deprecated functionality.
|
||||
* <p/>
|
||||
* If the {@link #CONTEXT_FORWARD_COMPATIBLE_BIT_ARB} flag is used, LWJGL will not load the deprecated functionality (as defined in the OpenGL 3.0
|
||||
* specification), even if the driver exposes the corresponding entry points.
|
||||
* If the forwardCompatible
|
||||
* attribute is used, LWJGL will not load the deprecated functionality (as defined in the OpenGL 3.0 specification). This
|
||||
* means that developers can start working on cleaning up their applications without an OpenGL 3.0 complaint driver.
|
||||
* <p/>
|
||||
* This extension is not supported on MacOS X. However, in order to enable the GL 3.2 context on MacOS X 10.7 or newer, an instance of this class must be passed
|
||||
* to LWJGL. The only valid configuration is <code>ContextAttribs(3, 2, CONTEXT_CORE_PROFILE_BIT_ARB)</code>, anything else will be ignored.
|
||||
* This extension is not supported on MacOS X. However, in order to enable the GL 3.2 context on MacOS X 10.7 or newer, an
|
||||
* instance of this class must be passed to LWJGL. The only valid configuration is <code>new ContextAttribs(3, 2).withProfileCore()</code>,
|
||||
* anything else will be ignored.
|
||||
*
|
||||
* @author spasi <spasi@users.sourceforge.net>
|
||||
*/
|
||||
public final class ContextAttribs {
|
||||
|
||||
// ATTRIBUTES
|
||||
// Same values for GLX & WGL
|
||||
private static final int CONTEXT_ES2_PROFILE_BIT_EXT = 0x00000004;
|
||||
|
||||
public static final int CONTEXT_MAJOR_VERSION_ARB = 0x2091;
|
||||
public static final int CONTEXT_MINOR_VERSION_ARB = 0x2092;
|
||||
private static final int CONTEXT_ROBUST_ACCESS_BIT_ARB = 0x00000004;
|
||||
private static final int CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB = 0x8256;
|
||||
private static final int
|
||||
NO_RESET_NOTIFICATION_ARB = 0x8261,
|
||||
LOSE_CONTEXT_ON_RESET_ARB = 0x8252;
|
||||
|
||||
public static final int CONTEXT_PROFILE_MASK_ARB = 0x9126,
|
||||
CONTEXT_CORE_PROFILE_BIT_ARB = 0x00000001,
|
||||
CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB = 0x00000002,
|
||||
CONTEXT_ES2_PROFILE_BIT_EXT = 0x00000004;
|
||||
|
||||
public static final int CONTEXT_FLAGS_ARB = 0x2094,
|
||||
CONTEXT_DEBUG_BIT_ARB = 0x0001,
|
||||
CONTEXT_FORWARD_COMPATIBLE_BIT_ARB = 0x0002,
|
||||
CONTEXT_ROBUST_ACCESS_BIT_ARB = 0x00000004,
|
||||
CONTEXT_RESET_ISOLATION_BIT_ARB = 0x00000008;
|
||||
|
||||
public static final int CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB = 0x8256,
|
||||
NO_RESET_NOTIFICATION_ARB = 0x8261,
|
||||
LOSE_CONTEXT_ON_RESET_ARB = 0x8252;
|
||||
|
||||
public static final int CONTEXT_RELEASE_BEHABIOR_ARB = 0x2097,
|
||||
CONTEXT_RELEASE_BEHAVIOR_NONE_ARB = 0x0000,
|
||||
CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB = 0x2098;
|
||||
|
||||
public static final int CONTEXT_LAYER_PLANE_ARB = 0x2093; // WGL-only
|
||||
|
||||
// STATE
|
||||
private static final int CONTEXT_RESET_ISOLATION_BIT_ARB = 0x00000008;
|
||||
|
||||
private int majorVersion;
|
||||
private int minorVersion;
|
||||
|
||||
private int profileMask;
|
||||
private int contextFlags;
|
||||
|
||||
private int contextResetNotificationStrategy = NO_RESET_NOTIFICATION_ARB;
|
||||
private int contextReleaseBehavior = CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB;
|
||||
|
||||
private int layerPlane;
|
||||
|
||||
// CONSTRUCTORS
|
||||
private boolean debug;
|
||||
private boolean forwardCompatible;
|
||||
private boolean robustAccess;
|
||||
|
||||
private boolean profileCore;
|
||||
private boolean profileCompatibility;
|
||||
private boolean profileES;
|
||||
|
||||
private boolean loseContextOnReset;
|
||||
private boolean contextResetIsolation;
|
||||
|
||||
/** Creates the default ContextAttribs instance. No special attributes will be used when creating the OpenGL context. */
|
||||
public ContextAttribs() {
|
||||
this(1, 0);
|
||||
}
|
||||
|
||||
/** Creates a ContextAttribs instance for the given OpenGL version. */
|
||||
public ContextAttribs(int majorVersion, int minorVersion) {
|
||||
this(majorVersion, minorVersion, 0, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new ContextAttribs instance with the given attributes.
|
||||
*
|
||||
* @param majorVersion the major OpenGL version
|
||||
* @param minorVersion the minor OpenGL version
|
||||
* @param profileMask the context profile mask. One of:<br>{@link #CONTEXT_CORE_PROFILE_BIT_ARB}, {@link #CONTEXT_FORWARD_COMPATIBLE_BIT_ARB}, {@link #CONTEXT_ES2_PROFILE_BIT_EXT}
|
||||
*/
|
||||
public ContextAttribs(int majorVersion, int minorVersion, int profileMask) {
|
||||
this(majorVersion, minorVersion, 0, profileMask);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new ContextAttribs instance with the given attributes.
|
||||
*
|
||||
* @param majorVersion the major OpenGL version
|
||||
* @param minorVersion the minor OpenGL version
|
||||
* @param profileMask the context profile mask. One of:<br>{@link #CONTEXT_CORE_PROFILE_BIT_ARB}, {@link #CONTEXT_FORWARD_COMPATIBLE_BIT_ARB}, {@link #CONTEXT_ES2_PROFILE_BIT_EXT}
|
||||
* @param contextFlags the context flags, a bitfield value. One or more of:<br>{@link #CONTEXT_DEBUG_BIT_ARB}, {@link #CONTEXT_FORWARD_COMPATIBLE_BIT_ARB}, {@link #CONTEXT_ROBUST_ACCESS_BIT_ARB}, {@link #CONTEXT_RESET_ISOLATION_BIT_ARB}
|
||||
*/
|
||||
public ContextAttribs(int majorVersion, int minorVersion, int profileMask, int contextFlags) {
|
||||
public ContextAttribs(final int majorVersion, final int minorVersion) {
|
||||
if ( majorVersion < 0 || 4 < majorVersion ||
|
||||
minorVersion < 0 ||
|
||||
(majorVersion == 4 && 5 < minorVersion) ||
|
||||
(majorVersion == 4 && 4 < minorVersion) ||
|
||||
(majorVersion == 3 && 3 < minorVersion) ||
|
||||
(majorVersion == 2 && 1 < minorVersion) ||
|
||||
(majorVersion == 1 && 5 < minorVersion) )
|
||||
throw new IllegalArgumentException("Invalid OpenGL version specified: " + majorVersion + '.' + minorVersion);
|
||||
|
||||
if ( LWJGLUtil.CHECKS ) {
|
||||
if ( 1 < Integer.bitCount(profileMask) || CONTEXT_ES2_PROFILE_BIT_EXT < profileMask )
|
||||
throw new IllegalArgumentException("Invalid profile mask specified: " + Integer.toBinaryString(profileMask));
|
||||
|
||||
if ( 0xF < contextFlags )
|
||||
throw new IllegalArgumentException("Invalid context flags specified: " + Integer.toBinaryString(profileMask));
|
||||
}
|
||||
|
||||
this.majorVersion = majorVersion;
|
||||
this.minorVersion = minorVersion;
|
||||
|
||||
this.profileMask = profileMask;
|
||||
this.contextFlags = contextFlags;
|
||||
}
|
||||
|
||||
// Copy constructor
|
||||
private ContextAttribs(ContextAttribs other) {
|
||||
this.majorVersion = other.majorVersion;
|
||||
this.minorVersion = other.minorVersion;
|
||||
private ContextAttribs(final ContextAttribs attribs) {
|
||||
this.majorVersion = attribs.majorVersion;
|
||||
this.minorVersion = attribs.minorVersion;
|
||||
|
||||
this.profileMask = other.profileMask;
|
||||
this.contextFlags = other.contextFlags;
|
||||
this.layerPlane = attribs.layerPlane;
|
||||
|
||||
this.contextResetNotificationStrategy = other.contextResetNotificationStrategy;
|
||||
this.contextReleaseBehavior = other.contextReleaseBehavior;
|
||||
this.debug = attribs.debug;
|
||||
this.forwardCompatible = attribs.forwardCompatible;
|
||||
this.robustAccess = attribs.robustAccess;
|
||||
|
||||
this.layerPlane = other.layerPlane;
|
||||
this.profileCore = attribs.profileCore;
|
||||
this.profileCompatibility = attribs.profileCompatibility;
|
||||
this.profileES = attribs.profileES;
|
||||
|
||||
this.loseContextOnReset = attribs.loseContextOnReset;
|
||||
}
|
||||
|
||||
// GETTERS
|
||||
|
||||
/** Returns the {@link #CONTEXT_MAJOR_VERSION_ARB} value. */
|
||||
public int getMajorVersion() {
|
||||
return majorVersion;
|
||||
}
|
||||
|
||||
/** Returns the {@link #CONTEXT_MINOR_VERSION_ARB} value. */
|
||||
public int getMinorVersion() {
|
||||
return minorVersion;
|
||||
}
|
||||
|
||||
/** Returns the {@link #CONTEXT_PROFILE_MASK_ARB} value. */
|
||||
public int getProfileMask() {
|
||||
return profileMask;
|
||||
}
|
||||
|
||||
private boolean hasMask(int mask) {
|
||||
return profileMask == mask;
|
||||
}
|
||||
|
||||
/** Returns true if the {@link #CONTEXT_CORE_PROFILE_BIT_ARB} has been set. */
|
||||
public boolean isProfileCore() {
|
||||
return hasMask(CONTEXT_CORE_PROFILE_BIT_ARB);
|
||||
}
|
||||
|
||||
/** Returns true if the {@link #CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB} has been set. */
|
||||
public boolean isProfileCompatibility() {
|
||||
return hasMask(CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB);
|
||||
}
|
||||
|
||||
/** Returns true if the {@link #CONTEXT_ES2_PROFILE_BIT_EXT} has been set. */
|
||||
public boolean isProfileES() {
|
||||
return hasMask(CONTEXT_ES2_PROFILE_BIT_EXT);
|
||||
}
|
||||
|
||||
/** Returns the {@link #CONTEXT_FLAGS_ARB} value. */
|
||||
public int getContextFlags() {
|
||||
return contextFlags;
|
||||
}
|
||||
|
||||
private boolean hasFlag(int flag) {
|
||||
return (contextFlags & flag) != 0;
|
||||
}
|
||||
|
||||
/** Returns true if the {@link #CONTEXT_DEBUG_BIT_ARB} has been set. */
|
||||
public boolean isDebug() {
|
||||
return hasFlag(CONTEXT_DEBUG_BIT_ARB);
|
||||
}
|
||||
|
||||
/** Returns true if the {@link #CONTEXT_FORWARD_COMPATIBLE_BIT_ARB} has been set. */
|
||||
public boolean isForwardCompatible() {
|
||||
return hasFlag(CONTEXT_FORWARD_COMPATIBLE_BIT_ARB);
|
||||
}
|
||||
|
||||
/** Returns true if the {@link #CONTEXT_ROBUST_ACCESS_BIT_ARB} has been set. */
|
||||
public boolean isRobustAccess() { return hasFlag(CONTEXT_ROBUST_ACCESS_BIT_ARB); }
|
||||
|
||||
/** Returns true if the {@link #CONTEXT_RESET_ISOLATION_BIT_ARB} has been set. */
|
||||
public boolean isContextResetIsolation() {
|
||||
return hasFlag(CONTEXT_RESET_ISOLATION_BIT_ARB);
|
||||
}
|
||||
|
||||
/** Returns the {@link #CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB} value. */
|
||||
public int getContextResetNotificationStrategy() {
|
||||
return contextResetNotificationStrategy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the {@link #CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB} has been set to {@link #LOSE_CONTEXT_ON_RESET_ARB}.
|
||||
*
|
||||
* @deprecated use {@link #getContextResetNotificationStrategy} instead
|
||||
*/
|
||||
public boolean isLoseContextOnReset() { return contextResetNotificationStrategy == LOSE_CONTEXT_ON_RESET_ARB; }
|
||||
|
||||
/** Returns the {@link #CONTEXT_RELEASE_BEHABIOR_ARB} value. */
|
||||
public int getContextReleaseBehavior() {
|
||||
return contextReleaseBehavior;
|
||||
}
|
||||
|
||||
/** Returns the {@link #CONTEXT_LAYER_PLANE_ARB} value. */
|
||||
public int getLayerPlane() {
|
||||
return layerPlane;
|
||||
}
|
||||
|
||||
// CHAIN CONFIGURATION PATTERN
|
||||
|
||||
private ContextAttribs toggleMask(int mask, boolean value) {
|
||||
if ( value == hasMask(mask) )
|
||||
return this;
|
||||
|
||||
ContextAttribs attribs = new ContextAttribs(this);
|
||||
attribs.profileMask = value ? mask : 0;
|
||||
return attribs;
|
||||
public boolean isDebug() {
|
||||
return debug;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new {@code ContextAttribs} instance with the {@link #CONTEXT_CORE_PROFILE_BIT_ARB} bit in {@link #CONTEXT_PROFILE_MASK_ARB} set to the given value.
|
||||
* If {@code profileCore} is true, all other bits in the mask are cleared.
|
||||
*/
|
||||
public ContextAttribs withProfileCore(boolean profileCore) {
|
||||
if ( majorVersion < 3 || (majorVersion == 3 && minorVersion < 2) )
|
||||
throw new IllegalArgumentException("Profiles are only supported on OpenGL version 3.2 or higher.");
|
||||
|
||||
return toggleMask(CONTEXT_CORE_PROFILE_BIT_ARB, profileCore);
|
||||
public boolean isForwardCompatible() {
|
||||
return forwardCompatible;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new {@code ContextAttribs} instance with the {@link #CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB} bit in {@link #CONTEXT_PROFILE_MASK_ARB} set to the given value.
|
||||
* If {@code profileCompatibility} is true, all other bits in the mask are cleared.
|
||||
*/
|
||||
public ContextAttribs withProfileCompatibility(boolean profileCompatibility) {
|
||||
if ( majorVersion < 3 || (majorVersion == 3 && minorVersion < 2) )
|
||||
throw new IllegalArgumentException("Profiles are only supported on OpenGL version 3.2 or higher.");
|
||||
|
||||
return toggleMask(CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, profileCompatibility);
|
||||
public boolean isProfileCore() {
|
||||
return profileCore;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new {@code ContextAttribs} instance with the {@link #CONTEXT_ES2_PROFILE_BIT_EXT} bit in {@link #CONTEXT_PROFILE_MASK_ARB} set to the given value.
|
||||
* If {@code profileES} is true, all other bits in the mask are cleared.
|
||||
*/
|
||||
public ContextAttribs withProfileES(boolean profileES) {
|
||||
if ( !(majorVersion == 2 && minorVersion == 0) )
|
||||
throw new IllegalArgumentException("The OpenGL ES profile is only supported on OpenGL version 2.0.");
|
||||
|
||||
return toggleMask(CONTEXT_ES2_PROFILE_BIT_EXT, profileES);
|
||||
public boolean isProfileCompatibility() {
|
||||
return profileCompatibility;
|
||||
}
|
||||
|
||||
private ContextAttribs toggleFlag(int flag, boolean value) {
|
||||
if ( value == hasFlag(flag) )
|
||||
return this;
|
||||
|
||||
ContextAttribs attribs = new ContextAttribs(this);
|
||||
attribs.contextFlags ^= flag; // toggle bit
|
||||
return attribs;
|
||||
public boolean isProfileES() {
|
||||
return profileES;
|
||||
}
|
||||
|
||||
/** Returns a new {@code ContextAttribs} instance with the {@link #CONTEXT_DEBUG_BIT_ARB} bit in {@link #CONTEXT_FLAGS_ARB} set to the given value. */
|
||||
public ContextAttribs withDebug(boolean debug) { return toggleFlag(CONTEXT_DEBUG_BIT_ARB, debug); }
|
||||
|
||||
/** Returns a new {@code ContextAttribs} instance with the {@link #CONTEXT_FORWARD_COMPATIBLE_BIT_ARB} bit in {@link #CONTEXT_FLAGS_ARB} set to the given value. */
|
||||
public ContextAttribs withForwardCompatible(boolean forwardCompatible) { return toggleFlag(CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, forwardCompatible); }
|
||||
|
||||
/** Returns a new {@code ContextAttribs} instance with the {@link #CONTEXT_ROBUST_ACCESS_BIT_ARB} bit in {@link #CONTEXT_FLAGS_ARB} set to the given value. */
|
||||
public ContextAttribs withRobustAccess(boolean robustAccess) { return toggleFlag(CONTEXT_ROBUST_ACCESS_BIT_ARB, robustAccess); }
|
||||
|
||||
/** Returns a new {@code ContextAttribs} instance with the {@link #CONTEXT_RESET_ISOLATION_BIT_ARB} bit in {@link #CONTEXT_FLAGS_ARB} set to the given value. */
|
||||
public ContextAttribs withContextResetIsolation(boolean contextResetIsolation) { return toggleFlag(CONTEXT_RESET_ISOLATION_BIT_ARB, contextResetIsolation); }
|
||||
|
||||
/**
|
||||
* Returns a ContextAttribs instance with {@link #CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB} set to the given strategy. The default context reset notification
|
||||
* strategy is {@link #NO_RESET_NOTIFICATION_ARB}.
|
||||
*
|
||||
* @param strategy the context reset notification strategy. One of:<br>{@link #NO_RESET_NOTIFICATION_ARB}, {@link #LOSE_CONTEXT_ON_RESET_ARB}
|
||||
*
|
||||
* @return the new ContextAttribs
|
||||
*/
|
||||
public ContextAttribs withResetNotificationStrategy(int strategy) {
|
||||
if ( strategy == contextResetNotificationStrategy )
|
||||
return this;
|
||||
|
||||
if ( LWJGLUtil.CHECKS && !(strategy == NO_RESET_NOTIFICATION_ARB || strategy == LOSE_CONTEXT_ON_RESET_ARB) )
|
||||
throw new IllegalArgumentException("Invalid context reset notification strategy specified: 0x" + LWJGLUtil.toHexString(strategy));
|
||||
|
||||
ContextAttribs attribs = new ContextAttribs(this);
|
||||
attribs.contextResetNotificationStrategy = strategy;
|
||||
return attribs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a ContextAttribs instance with {@link #CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB} set to {@link #LOSE_CONTEXT_ON_RESET_ARB} if the parameter is
|
||||
* true or to {@link #NO_RESET_NOTIFICATION_ARB} if the parameter is false.
|
||||
*
|
||||
* @param loseContextOnReset the context reset notification strategy
|
||||
*
|
||||
* @return the new ContextAttribs
|
||||
*
|
||||
* @deprecated use {@link #withResetNotificationStrategy} instead
|
||||
*/
|
||||
public ContextAttribs withLoseContextOnReset(boolean loseContextOnReset) {
|
||||
return withResetNotificationStrategy(loseContextOnReset ? LOSE_CONTEXT_ON_RESET_ARB : NO_RESET_NOTIFICATION_ARB);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a ContextAttribs instance with {@link #CONTEXT_RELEASE_BEHABIOR_ARB} set to the given behavior. The default context release behavior is
|
||||
* {@link #CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB}.
|
||||
*
|
||||
* @param behavior the context release behavior. One of:<br>{@link #CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB}, {@link #CONTEXT_RELEASE_BEHAVIOR_NONE_ARB}
|
||||
*
|
||||
* @return the new ContextAttribs
|
||||
*/
|
||||
public ContextAttribs withContextReleaseBehavior(int behavior) {
|
||||
if ( behavior == contextReleaseBehavior )
|
||||
return this;
|
||||
|
||||
if ( LWJGLUtil.CHECKS && !(behavior == CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB || behavior == CONTEXT_RELEASE_BEHAVIOR_NONE_ARB) )
|
||||
throw new IllegalArgumentException("Invalid context release behavior specified: 0x" + LWJGLUtil.toHexString(behavior));
|
||||
|
||||
ContextAttribs attribs = new ContextAttribs(this);
|
||||
attribs.contextReleaseBehavior = behavior;
|
||||
return attribs;
|
||||
}
|
||||
|
||||
/** Returns a new {@code ContextAttribs} instance with {@link #CONTEXT_LAYER_PLANE_ARB} set to the given value. */
|
||||
public ContextAttribs withLayer(int layerPlane) {
|
||||
if ( LWJGLUtil.getPlatform() != LWJGLUtil.PLATFORM_WINDOWS )
|
||||
throw new IllegalArgumentException("The CONTEXT_LAYER_PLANE_ARB attribute is supported only on the Windows platform.");
|
||||
public ContextAttribs withLayer(final int layerPlane) {
|
||||
if ( layerPlane < 0 )
|
||||
throw new IllegalArgumentException("Invalid layer plane specified: " + layerPlane);
|
||||
|
||||
if ( layerPlane == this.layerPlane )
|
||||
return this;
|
||||
|
||||
if ( layerPlane < 0 )
|
||||
throw new IllegalArgumentException("Invalid layer plane specified: " + layerPlane);
|
||||
|
||||
ContextAttribs attribs = new ContextAttribs(this);
|
||||
final ContextAttribs attribs = new ContextAttribs(this);
|
||||
attribs.layerPlane = layerPlane;
|
||||
return attribs;
|
||||
}
|
||||
|
||||
public ContextAttribs withDebug(final boolean debug) {
|
||||
if ( debug == this.debug )
|
||||
return this;
|
||||
|
||||
final ContextAttribs attribs = new ContextAttribs(this);
|
||||
attribs.debug = debug;
|
||||
return attribs;
|
||||
}
|
||||
|
||||
public ContextAttribs withForwardCompatible(final boolean forwardCompatible) {
|
||||
if ( forwardCompatible == this.forwardCompatible )
|
||||
return this;
|
||||
|
||||
final ContextAttribs attribs = new ContextAttribs(this);
|
||||
attribs.forwardCompatible = forwardCompatible;
|
||||
return attribs;
|
||||
}
|
||||
|
||||
public ContextAttribs withProfileCore(final boolean profileCore) {
|
||||
if ( majorVersion < 3 || (majorVersion == 3 && minorVersion < 2) )
|
||||
throw new IllegalArgumentException("Profiles are only supported on OpenGL version 3.2 or higher.");
|
||||
|
||||
if ( profileCore == this.profileCore )
|
||||
return this;
|
||||
|
||||
final ContextAttribs attribs = new ContextAttribs(this);
|
||||
attribs.profileCore = profileCore;
|
||||
if ( profileCore )
|
||||
attribs.profileCompatibility = false;
|
||||
|
||||
return attribs;
|
||||
}
|
||||
|
||||
public ContextAttribs withProfileCompatibility(final boolean profileCompatibility) {
|
||||
if ( majorVersion < 3 || (majorVersion == 3 && minorVersion < 2) )
|
||||
throw new IllegalArgumentException("Profiles are only supported on OpenGL version 3.2 or higher.");
|
||||
|
||||
if ( profileCompatibility == this.profileCompatibility )
|
||||
return this;
|
||||
|
||||
final ContextAttribs attribs = new ContextAttribs(this);
|
||||
attribs.profileCompatibility = profileCompatibility;
|
||||
if ( profileCompatibility )
|
||||
attribs.profileCore = false;
|
||||
|
||||
return attribs;
|
||||
}
|
||||
|
||||
public ContextAttribs withProfileES(final boolean profileES) {
|
||||
if ( !(majorVersion == 2 && minorVersion == 0) )
|
||||
throw new IllegalArgumentException("The OpenGL ES profiles is only supported for OpenGL version 2.0.");
|
||||
|
||||
if ( profileES == this.profileES )
|
||||
return this;
|
||||
|
||||
final ContextAttribs attribs = new ContextAttribs(this);
|
||||
attribs.profileES = profileES;
|
||||
|
||||
return attribs;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a ContextAttribs instance with CONTEXT_RESET_NOTIFICATION_STRATEGY set
|
||||
* to LOSE_CONTEXT_ON_RESET if the parameter is true or to NO_RESET_NOTIFICATION
|
||||
* if the parameter is false.
|
||||
*
|
||||
* @param loseContextOnReset
|
||||
*
|
||||
* @return the new ContextAttribs
|
||||
*/
|
||||
public ContextAttribs withLoseContextOnReset(final boolean loseContextOnReset) {
|
||||
if ( loseContextOnReset == this.loseContextOnReset )
|
||||
return this;
|
||||
|
||||
final ContextAttribs attribs = new ContextAttribs(this);
|
||||
attribs.loseContextOnReset = loseContextOnReset;
|
||||
return attribs;
|
||||
}
|
||||
|
||||
public ContextAttribs withContextResetIsolation(final boolean contextResetIsolation) {
|
||||
if ( contextResetIsolation == this.contextResetIsolation )
|
||||
return this;
|
||||
|
||||
final ContextAttribs attribs = new ContextAttribs(this);
|
||||
attribs.contextResetIsolation = contextResetIsolation;
|
||||
return attribs;
|
||||
}
|
||||
|
||||
private static ContextAttribsImplementation getImplementation() {
|
||||
switch ( LWJGLUtil.getPlatform() ) {
|
||||
case LWJGLUtil.PLATFORM_LINUX:
|
||||
return new LinuxContextAttribs();
|
||||
case LWJGLUtil.PLATFORM_WINDOWS:
|
||||
return new WindowsContextAttribs();
|
||||
default:
|
||||
throw new IllegalStateException("Unsupported platform");
|
||||
}
|
||||
}
|
||||
|
||||
IntBuffer getAttribList() {
|
||||
if ( LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_MACOSX )
|
||||
return null;
|
||||
|
||||
LinkedHashMap<Integer, Integer> map = new LinkedHashMap<Integer, Integer>(8);
|
||||
ContextAttribsImplementation implementation = getImplementation();
|
||||
|
||||
if ( !(majorVersion == 1 && minorVersion == 0) ) {
|
||||
map.put(CONTEXT_MAJOR_VERSION_ARB, majorVersion);
|
||||
map.put(CONTEXT_MINOR_VERSION_ARB, minorVersion);
|
||||
}
|
||||
int attribCount = 0;
|
||||
|
||||
if ( contextFlags != 0 )
|
||||
map.put(CONTEXT_FLAGS_ARB, contextFlags);
|
||||
if ( !(majorVersion == 1 && minorVersion == 0) )
|
||||
attribCount += 2;
|
||||
if ( 0 < layerPlane )
|
||||
attribCount++;
|
||||
|
||||
if ( profileMask != 0 )
|
||||
map.put(CONTEXT_PROFILE_MASK_ARB, profileMask);
|
||||
int flags = 0;
|
||||
if ( debug )
|
||||
flags |= implementation.getDebugBit();
|
||||
if ( forwardCompatible )
|
||||
flags |= implementation.getForwardCompatibleBit();
|
||||
if ( robustAccess )
|
||||
flags |= CONTEXT_ROBUST_ACCESS_BIT_ARB;
|
||||
if ( contextResetIsolation )
|
||||
flags |= CONTEXT_RESET_ISOLATION_BIT_ARB;
|
||||
if ( 0 < flags )
|
||||
attribCount++;
|
||||
|
||||
if ( contextResetNotificationStrategy != NO_RESET_NOTIFICATION_ARB )
|
||||
map.put(CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, contextResetNotificationStrategy);
|
||||
int profileMask = 0;
|
||||
if ( profileCore )
|
||||
profileMask |= implementation.getProfileCoreBit();
|
||||
else if ( profileCompatibility )
|
||||
profileMask |= implementation.getProfileCompatibilityBit();
|
||||
else if ( profileES )
|
||||
profileMask |= CONTEXT_ES2_PROFILE_BIT_EXT;
|
||||
if ( 0 < profileMask )
|
||||
attribCount++;
|
||||
|
||||
if ( contextReleaseBehavior != CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB )
|
||||
map.put(CONTEXT_RELEASE_BEHABIOR_ARB, contextReleaseBehavior);
|
||||
if ( loseContextOnReset )
|
||||
attribCount++;
|
||||
|
||||
if ( layerPlane != 0 )
|
||||
map.put(CONTEXT_LAYER_PLANE_ARB, layerPlane);
|
||||
|
||||
if ( map.isEmpty() )
|
||||
if ( attribCount == 0 )
|
||||
return null;
|
||||
|
||||
IntBuffer attribs = BufferUtils.createIntBuffer((map.size() * 2) + 1);
|
||||
for ( Entry<Integer, Integer> attrib : map.entrySet() ) {
|
||||
attribs
|
||||
.put(attrib.getKey())
|
||||
.put(attrib.getValue());
|
||||
final IntBuffer attribs = BufferUtils.createIntBuffer((attribCount * 2) + 1);
|
||||
|
||||
if ( !(majorVersion == 1 && minorVersion == 0) ) {
|
||||
attribs.put(implementation.getMajorVersionAttrib()).put(majorVersion);
|
||||
attribs.put(implementation.getMinorVersionAttrib()).put(minorVersion);
|
||||
}
|
||||
if ( 0 < layerPlane )
|
||||
attribs.put(implementation.getLayerPlaneAttrib()).put(layerPlane);
|
||||
if ( 0 < flags )
|
||||
attribs.put(implementation.getFlagsAttrib()).put(flags);
|
||||
if ( 0 < profileMask )
|
||||
attribs.put(implementation.getProfileMaskAttrib()).put(profileMask);
|
||||
if ( loseContextOnReset )
|
||||
attribs.put(CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB).put(LOSE_CONTEXT_ON_RESET_ARB);
|
||||
|
||||
attribs.put(0);
|
||||
attribs.rewind();
|
||||
return attribs;
|
||||
|
|
@ -438,37 +330,19 @@ public final class ContextAttribs {
|
|||
|
||||
sb.append("ContextAttribs:");
|
||||
sb.append(" Version=").append(majorVersion).append('.').append(minorVersion);
|
||||
|
||||
if ( profileMask != 0 ) {
|
||||
sb.append(", Profile=");
|
||||
if ( hasMask(CONTEXT_CORE_PROFILE_BIT_ARB) )
|
||||
sb.append("CORE");
|
||||
else if ( hasMask(CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB) )
|
||||
sb.append("COMPATIBLITY");
|
||||
else if ( hasMask(CONTEXT_ES2_PROFILE_BIT_EXT) )
|
||||
sb.append("ES2");
|
||||
else
|
||||
sb.append("*unknown*");
|
||||
}
|
||||
|
||||
if ( contextFlags != 0 ) {
|
||||
if ( hasFlag(CONTEXT_DEBUG_BIT_ARB) )
|
||||
sb.append(", DEBUG");
|
||||
if ( hasFlag(CONTEXT_FORWARD_COMPATIBLE_BIT_ARB) )
|
||||
sb.append(", FORWARD_COMPATIBLE");
|
||||
if ( hasFlag(CONTEXT_ROBUST_ACCESS_BIT_ARB) )
|
||||
sb.append(", ROBUST_ACCESS");
|
||||
if ( hasFlag(CONTEXT_RESET_ISOLATION_BIT_ARB) )
|
||||
sb.append(", RESET_ISOLATION");
|
||||
}
|
||||
|
||||
if ( contextResetNotificationStrategy != NO_RESET_NOTIFICATION_ARB )
|
||||
sb.append(", LOSE_CONTEXT_ON_RESET");
|
||||
if ( contextReleaseBehavior != CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB )
|
||||
sb.append(", RELEASE_BEHAVIOR_NONE");
|
||||
|
||||
if ( layerPlane != 0 )
|
||||
sb.append(", Layer=").append(layerPlane);
|
||||
sb.append(" - Layer=").append(layerPlane);
|
||||
sb.append(" - Debug=").append(debug);
|
||||
sb.append(" - ForwardCompatible=").append(forwardCompatible);
|
||||
sb.append(" - RobustAccess=").append(robustAccess);
|
||||
if ( robustAccess )
|
||||
sb.append(" (").append(loseContextOnReset ? "LOSE_CONTEXT_ON_RESET" : "NO_RESET_NOTIFICATION");
|
||||
sb.append(" - Profile=");
|
||||
if ( profileCore )
|
||||
sb.append("Core");
|
||||
else if ( profileCompatibility )
|
||||
sb.append("Compatibility");
|
||||
else
|
||||
sb.append("None");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2014 LWJGL Project
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -29,14 +29,28 @@
|
|||
* 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.Reuse;
|
||||
import org.lwjgl.util.generator.opengl.GLbitfield;
|
||||
/** @author spasi <spasi@users.sourceforge.net> */
|
||||
interface ContextAttribsImplementation {
|
||||
|
||||
public interface ARB_ES3_1_compatibility {
|
||||
int getMajorVersionAttrib();
|
||||
|
||||
@Reuse("GL45")
|
||||
void glMemoryBarrierByRegion(@GLbitfield int barriers);
|
||||
int getMinorVersionAttrib();
|
||||
|
||||
int getLayerPlaneAttrib();
|
||||
|
||||
int getFlagsAttrib();
|
||||
|
||||
int getDebugBit();
|
||||
|
||||
int getForwardCompatibleBit();
|
||||
|
||||
int getProfileMaskAttrib();
|
||||
|
||||
int getProfileCoreBit();
|
||||
|
||||
int getProfileCompatibilityBit();
|
||||
|
||||
}
|
||||
|
|
@ -253,12 +253,8 @@ final class ContextGL implements Context {
|
|||
boolean was_current = isCurrent();
|
||||
int error = GL_NO_ERROR;
|
||||
if ( was_current ) {
|
||||
try {
|
||||
// May fail on GLContext.getCapabilities()
|
||||
if ( GLContext.getCapabilities() != null && GLContext.getCapabilities().OpenGL11 )
|
||||
error = glGetError();
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
releaseCurrent();
|
||||
}
|
||||
checkDestroy();
|
||||
|
|
|
|||
|
|
@ -55,7 +55,6 @@ import java.awt.*;
|
|||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.ComponentListener;
|
||||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.FloatBuffer;
|
||||
import java.security.AccessController;
|
||||
|
|
@ -240,21 +239,21 @@ public final class Display {
|
|||
throw new NullPointerException("mode must be non-null");
|
||||
boolean was_fullscreen = isFullscreen();
|
||||
current_mode = mode;
|
||||
if ( !isCreated() || parent != null )
|
||||
return;
|
||||
destroyWindow();
|
||||
// If mode is not fullscreen capable, make sure we are in windowed mode
|
||||
try {
|
||||
if ( was_fullscreen && !isFullscreen() )
|
||||
if ( isCreated() ) {
|
||||
destroyWindow();
|
||||
// If mode is not fullscreen capable, make sure we are in windowed mode
|
||||
try {
|
||||
if ( was_fullscreen && !isFullscreen() )
|
||||
display_impl.resetDisplayMode();
|
||||
else if ( isFullscreen() )
|
||||
switchDisplayMode();
|
||||
createWindow();
|
||||
makeCurrentAndSetSwapInterval();
|
||||
} catch (LWJGLException e) {
|
||||
drawable.destroy();
|
||||
display_impl.resetDisplayMode();
|
||||
else if ( isFullscreen() )
|
||||
switchDisplayMode();
|
||||
createWindow();
|
||||
makeCurrentAndSetSwapInterval();
|
||||
} catch (LWJGLException e) {
|
||||
drawable.destroy();
|
||||
display_impl.resetDisplayMode();
|
||||
throw e;
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1223,8 +1222,8 @@ public final class Display {
|
|||
cached_icons[i] = BufferUtils.createByteBuffer(icons[i].capacity());
|
||||
int old_position = icons[i].position();
|
||||
cached_icons[i].put(icons[i]);
|
||||
((Buffer)icons[i]).position(old_position);
|
||||
((Buffer)cached_icons[i]).flip();
|
||||
icons[i].position(old_position);
|
||||
cached_icons[i].flip();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ public final class DisplayMode {
|
|||
this.fullscreen = fullscreen;
|
||||
}
|
||||
|
||||
/** True if this instance can be used for fullscreen modes */
|
||||
/** True iff this instance can be used for fullscreen modes */
|
||||
public boolean isFullscreenCapable() {
|
||||
return fullscreen;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ package org.lwjgl.opengl;
|
|||
* @author elias_naur
|
||||
*/
|
||||
|
||||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
class EventQueue {
|
||||
|
|
@ -59,12 +58,12 @@ class EventQueue {
|
|||
* Copy available events into the specified buffer.
|
||||
*/
|
||||
public synchronized void copyEvents(ByteBuffer dest) {
|
||||
((Buffer)queue).flip();
|
||||
queue.flip();
|
||||
int old_limit = queue.limit();
|
||||
if (dest.remaining() < queue.remaining())
|
||||
((Buffer)queue).limit(dest.remaining() + queue.position());
|
||||
queue.limit(dest.remaining() + queue.position());
|
||||
dest.put(queue);
|
||||
((Buffer)queue).limit(old_limit);
|
||||
queue.limit(old_limit);
|
||||
queue.compact();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,7 +43,6 @@ import static org.lwjgl.opengl.EXTAbgr.*;
|
|||
import static org.lwjgl.opengl.EXTBgra.*;
|
||||
import static org.lwjgl.opengl.EXTDirectStateAccess.*;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import static org.lwjgl.opengl.GL13.*;
|
||||
import static org.lwjgl.opengl.GL15.*;
|
||||
import static org.lwjgl.opengl.NVPathRendering.*;
|
||||
|
||||
|
|
@ -66,6 +65,22 @@ class GLChecks {
|
|||
private GLChecks() {
|
||||
}
|
||||
|
||||
static int getBufferObjectSize(ContextCapabilities caps, int buffer_enum) {
|
||||
return glGetBufferParameteri(buffer_enum, GL_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
static int getBufferObjectSizeARB(ContextCapabilities caps, int buffer_enum) {
|
||||
return glGetBufferParameteriARB(buffer_enum, GL_BUFFER_SIZE_ARB);
|
||||
}
|
||||
|
||||
static int getBufferObjectSizeATI(ContextCapabilities caps, int buffer) {
|
||||
return glGetObjectBufferiATI(buffer, GL_OBJECT_BUFFER_SIZE_ATI);
|
||||
}
|
||||
|
||||
static int getNamedBufferObjectSize(ContextCapabilities caps, int buffer) {
|
||||
return glGetNamedBufferParameterEXT(buffer, GL_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
/** 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 )
|
||||
|
|
@ -295,36 +310,37 @@ class GLChecks {
|
|||
}
|
||||
}
|
||||
|
||||
static int calculatePathColorGenModeElements(int genMode) {
|
||||
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_CONSTANT:
|
||||
return 1;
|
||||
case GL_OBJECT_LINEAR:
|
||||
case GL_PATH_OBJECT_BOUNDING_BOX_NV:
|
||||
return 3;
|
||||
case GL_EYE_LINEAR:
|
||||
return 4;
|
||||
default:
|
||||
throw new IllegalArgumentException(String.format("Unsupported genMode specified: 0x%X", genMode));
|
||||
}
|
||||
}
|
||||
|
||||
static int calculatePathColorGenFormatComponents(int colorFormat) {
|
||||
switch ( colorFormat ) {
|
||||
case GL_LUMINANCE:
|
||||
case GL_INTENSITY:
|
||||
case GL_ALPHA:
|
||||
return 1;
|
||||
case GL_LUMINANCE_ALPHA:
|
||||
return 2;
|
||||
case GL_RGB:
|
||||
return 3;
|
||||
case GL_RGBA:
|
||||
return 4;
|
||||
default:
|
||||
throw new IllegalArgumentException(String.format("Unsupported colorFormat specified: 0x%X", colorFormat));
|
||||
throw new IllegalArgumentException("Unsupported gen mode: " + genMode);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -243,10 +243,10 @@ public final class GLContext {
|
|||
}
|
||||
|
||||
final int[][] GL_VERSIONS = {
|
||||
{ 1, 2, 3, 4, 5 }, // OpenGL 1
|
||||
{ 0, 1 }, // OpenGL 2
|
||||
{ 0, 1, 2, 3 }, // OpenGL 3
|
||||
{ 0, 1, 2, 3, 4, 5 }, // OpenGL 4
|
||||
{ 1, 2, 3, 4, 5 }, // OpenGL 1
|
||||
{ 0, 1 }, // OpenGL 2
|
||||
{ 0, 1, 2, 3 }, // OpenGL 3
|
||||
{ 0, 1, 2, 3, 4 }, // OpenGL 4
|
||||
};
|
||||
|
||||
for ( int major = 1; major <= GL_VERSIONS.length; major++ ) {
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ public interface InputImplementation {
|
|||
void pollMouse(IntBuffer coord_buffer, ByteBuffer buttons);
|
||||
|
||||
/**
|
||||
* Method to read the mouse buffer
|
||||
* Method to read the keyboard buffer
|
||||
*/
|
||||
void readMouse(ByteBuffer buffer);
|
||||
|
||||
|
|
|
|||
91
src/java/org/lwjgl/opengl/LinuxContextAttribs.java
Normal file
91
src/java/org/lwjgl/opengl/LinuxContextAttribs.java
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* 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
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* An implementation of ContextAttribs using GLX_create_context.
|
||||
*
|
||||
* @author spasi <spasi@users.sourceforge.net>
|
||||
*/
|
||||
final class LinuxContextAttribs implements ContextAttribsImplementation {
|
||||
|
||||
private static final int GLX_CONTEXT_MAJOR_VERSION_ARB = 0x2091;
|
||||
private static final int GLX_CONTEXT_MINOR_VERSION_ARB = 0x2092;
|
||||
private static final int GLX_CONTEXT_FLAGS_ARB = 0x2094;
|
||||
private static final int GLX_CONTEXT_PROFILE_MASK_ARB = 0x9126;
|
||||
|
||||
private static final int GLX_CONTEXT_DEBUG_BIT_ARB = 0x0001;
|
||||
private static final int GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB = 0x0002;
|
||||
|
||||
private static final int GLX_CONTEXT_CORE_PROFILE_BIT_ARB = 0x00000001;
|
||||
private static final int GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB = 0x00000002;
|
||||
|
||||
LinuxContextAttribs() {
|
||||
}
|
||||
|
||||
public int getMajorVersionAttrib() {
|
||||
return GLX_CONTEXT_MAJOR_VERSION_ARB;
|
||||
}
|
||||
|
||||
public int getMinorVersionAttrib() {
|
||||
return GLX_CONTEXT_MINOR_VERSION_ARB;
|
||||
}
|
||||
|
||||
public int getLayerPlaneAttrib() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public int getFlagsAttrib() {
|
||||
return GLX_CONTEXT_FLAGS_ARB;
|
||||
}
|
||||
|
||||
public int getDebugBit() {
|
||||
return GLX_CONTEXT_DEBUG_BIT_ARB;
|
||||
}
|
||||
|
||||
public int getForwardCompatibleBit() {
|
||||
return GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
|
||||
}
|
||||
|
||||
public int getProfileMaskAttrib() {
|
||||
return GLX_CONTEXT_PROFILE_MASK_ARB;
|
||||
}
|
||||
|
||||
public int getProfileCoreBit() {
|
||||
return GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
|
||||
}
|
||||
|
||||
public int getProfileCompatibilityBit() {
|
||||
return GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -143,12 +143,10 @@ final class LinuxContextImplementation implements ContextImplementation {
|
|||
|
||||
public void setSwapInterval(int value) {
|
||||
ContextGL current_context = ContextGL.getCurrentContext();
|
||||
PeerInfo peer_info = current_context.getPeerInfo();
|
||||
|
||||
if ( current_context == null )
|
||||
throw new IllegalStateException("No context is current");
|
||||
|
||||
PeerInfo peer_info = current_context.getPeerInfo();
|
||||
|
||||
synchronized ( current_context ) {
|
||||
LinuxDisplay.lockAWT();
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -129,6 +129,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
private DisplayMode saved_mode;
|
||||
private DisplayMode current_mode;
|
||||
|
||||
private Screen[] savedXrandrConfig;
|
||||
|
||||
private boolean keyboard_grabbed;
|
||||
private boolean pointer_grabbed;
|
||||
|
|
@ -482,16 +483,7 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
window_y = y;
|
||||
window_width = mode.getWidth();
|
||||
window_height = mode.getHeight();
|
||||
|
||||
// overwrite arguments x and y - superclass always uses 0,0 for fullscreen windows
|
||||
// use the coordinates of XRandRs primary screen instead
|
||||
// this is required to let the fullscreen window appear on the primary screen
|
||||
if (mode.isFullscreenCapable() && current_displaymode_extension == XRANDR) {
|
||||
Screen primaryScreen = XRandR.DisplayModetoScreen(Display.getDisplayMode());
|
||||
x = primaryScreen.xPos;
|
||||
y = primaryScreen.yPos;
|
||||
}
|
||||
|
||||
|
||||
current_window = nCreateWindow(getDisplay(), getDefaultScreen(), handle, mode, current_window_mode, x, y, undecorated, parent_window, resizable);
|
||||
|
||||
// Set the WM_CLASS hint which is needed by some WM's e.g. Gnome Shell
|
||||
|
|
@ -611,17 +603,12 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
}
|
||||
|
||||
private void switchDisplayModeOnTmpDisplay(DisplayMode mode) throws LWJGLException {
|
||||
if (current_displaymode_extension == XRANDR) {
|
||||
// let Xrandr set the display mode
|
||||
XRandR.setConfiguration(false, XRandR.DisplayModetoScreen(mode));
|
||||
} else {
|
||||
incDisplay();
|
||||
try {
|
||||
nSwitchDisplayMode(getDisplay(), getDefaultScreen(), current_displaymode_extension, mode);
|
||||
} finally {
|
||||
decDisplay();
|
||||
}
|
||||
}
|
||||
incDisplay();
|
||||
try {
|
||||
nSwitchDisplayMode(getDisplay(), getDefaultScreen(), current_displaymode_extension, mode);
|
||||
} finally {
|
||||
decDisplay();
|
||||
}
|
||||
}
|
||||
private static native void nSwitchDisplayMode(long display, int screen, int extension, DisplayMode mode) throws LWJGLException;
|
||||
|
||||
|
|
@ -638,11 +625,11 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
public void resetDisplayMode() {
|
||||
lockAWT();
|
||||
try {
|
||||
if( current_displaymode_extension == XRANDR )
|
||||
if( current_displaymode_extension == XRANDR && savedXrandrConfig.length > 0 )
|
||||
{
|
||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
public Object run() {
|
||||
XRandR.restoreConfiguration();
|
||||
XRandR.setConfiguration( savedXrandrConfig );
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
|
@ -740,11 +727,12 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
throw new LWJGLException("No modes available");
|
||||
switch (current_displaymode_extension) {
|
||||
case XRANDR:
|
||||
saved_mode = AccessController.doPrivileged(new PrivilegedAction<DisplayMode>() {
|
||||
public DisplayMode run() {
|
||||
return XRandR.ScreentoDisplayMode(XRandR.getConfiguration());
|
||||
savedXrandrConfig = AccessController.doPrivileged(new PrivilegedAction<Screen[]>() {
|
||||
public Screen[] run() {
|
||||
return XRandR.getConfiguration();
|
||||
}
|
||||
});
|
||||
saved_mode = getCurrentXRandrMode();
|
||||
break;
|
||||
case XF86VIDMODE:
|
||||
saved_mode = modes[0];
|
||||
|
|
@ -786,6 +774,9 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
} finally {
|
||||
unlockAWT();
|
||||
}
|
||||
|
||||
// also update the class hint value as some WM's use it for the window title
|
||||
if (Display.isCreated()) setClassHint(title, wm_class);
|
||||
}
|
||||
private static native void nSetTitle(long display, long window, long title, int len);
|
||||
|
||||
|
|
@ -938,29 +929,13 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
public DisplayMode[] getAvailableDisplayModes() throws LWJGLException {
|
||||
lockAWT();
|
||||
try {
|
||||
incDisplay();
|
||||
if (current_displaymode_extension == XRANDR) {
|
||||
// nGetAvailableDisplayModes cannot be trusted. Use it only for bitsPerPixel
|
||||
DisplayMode[] nDisplayModes = nGetAvailableDisplayModes(getDisplay(), getDefaultScreen(), current_displaymode_extension);
|
||||
int bpp = 24;
|
||||
if (nDisplayModes.length > 0) {
|
||||
bpp = nDisplayModes[0].getBitsPerPixel();
|
||||
}
|
||||
// get the resolutions and frequencys from XRandR
|
||||
Screen[] resolutions = XRandR.getResolutions(XRandR.getScreenNames()[0]);
|
||||
DisplayMode[] modes = new DisplayMode[resolutions.length];
|
||||
for (int i = 0; i < modes.length; i++) {
|
||||
modes[i] = new DisplayMode(resolutions[i].width, resolutions[i].height, bpp, resolutions[i].freq);
|
||||
}
|
||||
return modes;
|
||||
} else {
|
||||
try {
|
||||
DisplayMode[] modes = nGetAvailableDisplayModes(getDisplay(), getDefaultScreen(), current_displaymode_extension);
|
||||
return modes;
|
||||
} finally {
|
||||
decDisplay();
|
||||
}
|
||||
}
|
||||
incDisplay();
|
||||
try {
|
||||
DisplayMode[] modes = nGetAvailableDisplayModes(getDisplay(), getDefaultScreen(), current_displaymode_extension);
|
||||
return modes;
|
||||
} finally {
|
||||
decDisplay();
|
||||
}
|
||||
} finally {
|
||||
unlockAWT();
|
||||
}
|
||||
|
|
@ -1121,18 +1096,16 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
private void releaseInput() {
|
||||
if (isLegacyFullscreen() || input_released)
|
||||
return;
|
||||
if ( keyboard != null )
|
||||
keyboard.releaseAll();
|
||||
input_released = true;
|
||||
updateInputGrab();
|
||||
if (current_window_mode == FULLSCREEN_NETWM) {
|
||||
nIconifyWindow(getDisplay(), getWindow(), getDefaultScreen());
|
||||
try {
|
||||
if( current_displaymode_extension == XRANDR )
|
||||
if( current_displaymode_extension == XRANDR && savedXrandrConfig.length > 0 )
|
||||
{
|
||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
public Object run() {
|
||||
XRandR.restoreConfiguration();
|
||||
XRandR.setConfiguration( savedXrandrConfig );
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -257,22 +257,46 @@ final class LinuxKeyboard {
|
|||
private static native long lookupKeysym(long event_ptr, int index);
|
||||
private static native long toUpper(long keysym);
|
||||
|
||||
private int getKeycode(long event_ptr, int event_state) {
|
||||
boolean shift = (event_state & (ShiftMask | shift_lock_mask)) != 0;
|
||||
int group = (event_state & modeswitch_mask) != 0 ? 1 : 0;
|
||||
private long mapEventToKeySym(long event_ptr, int event_state) {
|
||||
int group;
|
||||
long keysym;
|
||||
if ((event_state & modeswitch_mask) != 0)
|
||||
group = 1;
|
||||
else
|
||||
group = 0;
|
||||
if ((event_state & numlock_mask) != 0 && isKeypadKeysym(keysym = getKeySym(event_ptr, group, 1))) {
|
||||
if ( shift )
|
||||
keysym = getKeySym(event_ptr, group, 0);
|
||||
} else {
|
||||
if ((event_state & (ShiftMask | shift_lock_mask)) != 0) {
|
||||
return getKeySym(event_ptr, group, 0);
|
||||
} else {
|
||||
return keysym;
|
||||
}
|
||||
} else if ((event_state & (ShiftMask | LockMask)) == 0) {
|
||||
return getKeySym(event_ptr, group, 0);
|
||||
} else if ((event_state & ShiftMask) == 0) {
|
||||
keysym = getKeySym(event_ptr, group, 0);
|
||||
if ( shift ^ ((event_state & caps_lock_mask) != 0) )
|
||||
if ((event_state & caps_lock_mask) != 0)
|
||||
keysym = toUpper(keysym);
|
||||
return keysym;
|
||||
} else {
|
||||
keysym = getKeySym(event_ptr, group, 1);
|
||||
if ((event_state & caps_lock_mask) != 0)
|
||||
keysym = toUpper(keysym);
|
||||
return keysym;
|
||||
}
|
||||
return LinuxKeycodes.mapKeySymToLWJGLKeyCode(keysym);
|
||||
}
|
||||
|
||||
private static byte getKeyState(int event_type) {
|
||||
private int getKeycode(long event_ptr, int event_state) {
|
||||
long keysym = mapEventToKeySym(event_ptr, event_state);
|
||||
int keycode = LinuxKeycodes.mapKeySymToLWJGLKeyCode(keysym);
|
||||
if (keycode == Keyboard.KEY_NONE) {
|
||||
// Try unshifted keysym mapping
|
||||
keysym = lookupKeysym(event_ptr, 0);
|
||||
keycode = LinuxKeycodes.mapKeySymToLWJGLKeyCode(keysym);
|
||||
}
|
||||
return keycode;
|
||||
}
|
||||
|
||||
private byte getKeyState(int event_type) {
|
||||
switch (event_type) {
|
||||
case LinuxEvent.KeyPress:
|
||||
return 1;
|
||||
|
|
@ -283,22 +307,10 @@ final class LinuxKeyboard {
|
|||
}
|
||||
}
|
||||
|
||||
/** This is called when the window loses focus: we release all currently pressed keys. */
|
||||
void releaseAll() {
|
||||
for ( int i = 0; i < key_down_buffer.length; i++ ) {
|
||||
if ( key_down_buffer[i] != 0 ) {
|
||||
key_down_buffer[i] = 0;
|
||||
putKeyboardEvent(i, (byte)0, 0, 0L, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleKeyEvent(long event_ptr, long millis, int event_type, int event_keycode, int event_state) {
|
||||
int keycode = getKeycode(event_ptr, event_state);
|
||||
byte key_state = getKeyState(event_type);
|
||||
boolean repeat = key_state == key_down_buffer[keycode];
|
||||
if ( repeat && event_type == LinuxEvent.KeyRelease ) // This can happen for modifier keys after losing and regaining focus.
|
||||
return;
|
||||
key_down_buffer[keycode] = key_state;
|
||||
long nanos = millis*1000000;
|
||||
if (event_type == LinuxEvent.KeyPress) {
|
||||
|
|
|
|||
|
|
@ -88,8 +88,26 @@ abstract class MacOSXCanvasPeerInfo extends MacOSXPeerInfo {
|
|||
// fix for CALayer position not covering Canvas due to a Java 7 bug
|
||||
// http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7172187
|
||||
addComponentListener(component);
|
||||
|
||||
if (SwingUtilities.getWindowAncestor(component.getParent()) != null) {
|
||||
Point componentPosition = SwingUtilities.convertPoint(component, component.getLocation(), null);
|
||||
Point parentPosition = SwingUtilities.convertPoint(component.getParent(), component.getLocation(), null);
|
||||
|
||||
if (componentPosition.getX() == parentPosition.getX() && componentPosition.getY() == parentPosition.getY()) {
|
||||
insets = getWindowInsets(component);
|
||||
|
||||
reSetLayerBounds(component, getHandle());
|
||||
top = insets != null ? insets.top : 0;
|
||||
left = insets != null ? insets.left : 0;
|
||||
|
||||
int x = (int)componentPosition.getX()-left;
|
||||
int y = (int)-componentPosition.getY()+top-component.getHeight();
|
||||
|
||||
int width = component.getWidth();
|
||||
int height = component.getHeight();
|
||||
|
||||
nSetLayerBounds(getHandle(), x, y, width, height);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -112,14 +130,54 @@ abstract class MacOSXCanvasPeerInfo extends MacOSXPeerInfo {
|
|||
|
||||
public void componentMoved(ComponentEvent e) {
|
||||
|
||||
if (SwingUtilities.getWindowAncestor(component.getParent()) != null) {
|
||||
Point componentPosition = SwingUtilities.convertPoint(component, component.getLocation(), null);
|
||||
Point parentPosition = SwingUtilities.convertPoint(component.getParent(), component.getLocation(), null);
|
||||
|
||||
if (componentPosition.getX() == parentPosition.getX() && componentPosition.getY() == parentPosition.getY()) {
|
||||
Insets insets = getWindowInsets(component);
|
||||
|
||||
int top = insets != null ? insets.top : 0;
|
||||
int left = insets != null ? insets.left : 0;
|
||||
|
||||
nSetLayerBounds(getHandle(), (int)componentPosition.getX()-left, (int)componentPosition.getY()-top, component.getWidth(), component.getHeight());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Insets insets = getInsets(component);
|
||||
|
||||
int top = insets != null ? insets.top : 0;
|
||||
int left = insets != null ? insets.left : 0;
|
||||
|
||||
//nSetLayerPosition(getHandle(), component.getX() - left, component.getY() - top);
|
||||
reSetLayerBounds(component, getHandle());
|
||||
nSetLayerBounds(getHandle(), component.getX() - left, component.getY() - top, component.getWidth(), component.getHeight());
|
||||
}
|
||||
|
||||
public void componentResized(ComponentEvent e) {
|
||||
|
||||
if (SwingUtilities.getWindowAncestor(component.getParent()) != null) {
|
||||
Point componentPosition = SwingUtilities.convertPoint(component, component.getLocation(), null);
|
||||
Point parentPosition = SwingUtilities.convertPoint(component.getParent(), component.getLocation(), null);
|
||||
|
||||
if (componentPosition.getX() == parentPosition.getX() && componentPosition.getY() == parentPosition.getY()) {
|
||||
Insets insets = getWindowInsets(component);
|
||||
|
||||
int top = insets != null ? insets.top : 0;
|
||||
int left = insets != null ? insets.left : 0;
|
||||
|
||||
nSetLayerBounds(getHandle(), (int)componentPosition.getX()-left, (int)componentPosition.getY()-top, component.getWidth(), component.getHeight());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Insets insets = getInsets(component);
|
||||
|
||||
int top = insets != null ? insets.top : 0;
|
||||
int left = insets != null ? insets.left : 0;
|
||||
|
||||
//nSetLayerPosition(getHandle(), component.getX() - left, component.getY() - top);
|
||||
reSetLayerBounds(component, getHandle());
|
||||
nSetLayerBounds(getHandle(), component.getX() - left, component.getY() - top, component.getWidth(), component.getHeight());
|
||||
}
|
||||
|
||||
public void componentShown(ComponentEvent e) {
|
||||
|
|
@ -140,43 +198,38 @@ abstract class MacOSXCanvasPeerInfo extends MacOSXPeerInfo {
|
|||
|
||||
private static native void nSetLayerBounds(ByteBuffer peer_info_handle, int x, int y, int width, int height);
|
||||
|
||||
/**
|
||||
* fix for CALayer position not covering Canvas due to a Java 7 bug
|
||||
* {@link http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7172187}
|
||||
* @param component
|
||||
* @param peer_info_handle
|
||||
*/
|
||||
private static void reSetLayerBounds(Canvas component, ByteBuffer peer_info_handle) {
|
||||
// report the root parent (peer).
|
||||
Component peer = SwingUtilities.getRoot(component);
|
||||
|
||||
Point rtLoc = SwingUtilities.convertPoint(component.getParent(), component.getLocation(), peer);
|
||||
int x = (int) rtLoc.getX(), y = (int) rtLoc.getY();
|
||||
|
||||
Insets insets = getInsets(component);
|
||||
x -= insets != null ? insets.left : 0;
|
||||
y -= insets != null ? insets.top : 0;
|
||||
|
||||
// http://hg.openjdk.java.net/jdk8/awt/jdk/rev/65d874d16d59
|
||||
y = (int) peer.getHeight() - y - (int) component.getHeight();
|
||||
|
||||
nSetLayerBounds(peer_info_handle, x, y, component.getWidth(), component.getHeight());
|
||||
}
|
||||
|
||||
protected void doUnlock() throws LWJGLException {
|
||||
awt_surface.unlock();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return rootpane insets (peer insets) values.
|
||||
*/
|
||||
private static Insets getInsets(Canvas component) {
|
||||
Container c = SwingUtilities.getRootPane(component);
|
||||
|
||||
if(c != null) {
|
||||
return c.getInsets();
|
||||
} else {
|
||||
return new Insets(0, 0, 0, 0);
|
||||
}
|
||||
/**
|
||||
* Return the Insets of the Window holding the Canvas
|
||||
*/
|
||||
private Insets getWindowInsets(Canvas canvas) {
|
||||
Container parent = canvas.getParent();
|
||||
|
||||
while (parent != null) {
|
||||
if(parent instanceof Window || parent instanceof java.applet.Applet) {
|
||||
return parent.getInsets();
|
||||
}
|
||||
|
||||
parent = parent.getParent();
|
||||
}
|
||||
|
||||
// if no parent Window or Applet found, return null
|
||||
return null;
|
||||
}
|
||||
|
||||
private Insets getInsets(Canvas component) {
|
||||
Component parent = component.getParent();
|
||||
|
||||
while (parent != null) {
|
||||
if (parent instanceof Container) {
|
||||
return ((Container)parent).getInsets();
|
||||
}
|
||||
parent = parent.getParent();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -163,8 +163,10 @@ final class MacOSXDisplay implements DisplayImplementation {
|
|||
// when going to fullscreen viewport is set to screen size by Cocoa, ignore this value
|
||||
skipViewportValue = true;
|
||||
// if starting in fullscreen then set initial viewport to displaymode size
|
||||
current_viewport.put(2, mode.getWidth());
|
||||
current_viewport.put(3, mode.getHeight());
|
||||
if (current_viewport.get(2) == 0 && current_viewport.get(3) == 0) {
|
||||
current_viewport.put(2, mode.getWidth());
|
||||
current_viewport.put(3, mode.getHeight());
|
||||
}
|
||||
}
|
||||
|
||||
native_mode = nIsNativeMode(peer_handle);
|
||||
|
|
@ -329,15 +331,10 @@ final class MacOSXDisplay implements DisplayImplementation {
|
|||
|
||||
DrawableGL drawable = (DrawableGL)Display.getDrawable();
|
||||
if (should_update) {
|
||||
|
||||
// Save the current viewport size as cocoa will automatically
|
||||
// set the viewport size to the window size on context update
|
||||
drawable.context.update();
|
||||
/* This is necessary to make sure the context won't "forget" about the view size */
|
||||
if (skipViewportValue) skipViewportValue = false;
|
||||
else glGetInteger(GL_VIEWPORT, current_viewport);
|
||||
|
||||
drawable.context.update();
|
||||
|
||||
// restore the original viewport size that was set before the update
|
||||
glViewport(current_viewport.get(0), current_viewport.get(1), current_viewport.get(2), current_viewport.get(3));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -38,8 +38,9 @@ package org.lwjgl.opengl;
|
|||
*/
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.util.HashMap;
|
||||
import java.nio.Buffer;
|
||||
import java.awt.Component;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
|
@ -73,132 +74,132 @@ final class MacOSXNativeKeyboard extends EventQueue {
|
|||
|
||||
// These are from: <HIToolbox/Events.h>
|
||||
private void initKeyboardMappings() {
|
||||
nativeToLwjglMap.put((short)0x1D, Keyboard.KEY_0);
|
||||
nativeToLwjglMap.put((short)0x12, Keyboard.KEY_1);
|
||||
nativeToLwjglMap.put((short)0x13, Keyboard.KEY_2);
|
||||
nativeToLwjglMap.put((short)0x14, Keyboard.KEY_3);
|
||||
nativeToLwjglMap.put((short)0x15, Keyboard.KEY_4);
|
||||
nativeToLwjglMap.put((short)0x17, Keyboard.KEY_5);
|
||||
nativeToLwjglMap.put((short)0x16, Keyboard.KEY_6);
|
||||
nativeToLwjglMap.put((short)0x1A, Keyboard.KEY_7);
|
||||
nativeToLwjglMap.put((short)0x1C, Keyboard.KEY_8);
|
||||
nativeToLwjglMap.put((short)0x19, Keyboard.KEY_9);
|
||||
nativeToLwjglMap.put((short)0x00, Keyboard.KEY_A);
|
||||
nativeToLwjglMap.put((short)0x0B, Keyboard.KEY_B);
|
||||
nativeToLwjglMap.put((short)0x08, Keyboard.KEY_C);
|
||||
nativeToLwjglMap.put((short)0x02, Keyboard.KEY_D);
|
||||
nativeToLwjglMap.put((short)0x0E, Keyboard.KEY_E);
|
||||
nativeToLwjglMap.put((short)0x03, Keyboard.KEY_F);
|
||||
nativeToLwjglMap.put((short)0x05, Keyboard.KEY_G);
|
||||
nativeToLwjglMap.put((short)0x04, Keyboard.KEY_H);
|
||||
nativeToLwjglMap.put((short)0x22, Keyboard.KEY_I);
|
||||
nativeToLwjglMap.put((short)0x26, Keyboard.KEY_J);
|
||||
nativeToLwjglMap.put((short)0x28, Keyboard.KEY_K);
|
||||
nativeToLwjglMap.put((short)0x25, Keyboard.KEY_L);
|
||||
nativeToLwjglMap.put((short)0x2E, Keyboard.KEY_M);
|
||||
nativeToLwjglMap.put((short)0x2D, Keyboard.KEY_N);
|
||||
nativeToLwjglMap.put((short)0x1F, Keyboard.KEY_O);
|
||||
nativeToLwjglMap.put((short)0x23, Keyboard.KEY_P);
|
||||
nativeToLwjglMap.put((short)0x0C, Keyboard.KEY_Q);
|
||||
nativeToLwjglMap.put((short)0x0F, Keyboard.KEY_R);
|
||||
nativeToLwjglMap.put((short)0x01, Keyboard.KEY_S);
|
||||
nativeToLwjglMap.put((short)0x11, Keyboard.KEY_T);
|
||||
nativeToLwjglMap.put((short)0x20, Keyboard.KEY_U);
|
||||
nativeToLwjglMap.put((short)0x09, Keyboard.KEY_V);
|
||||
nativeToLwjglMap.put((short)0x0D, Keyboard.KEY_W);
|
||||
nativeToLwjglMap.put((short)0x07, Keyboard.KEY_X);
|
||||
nativeToLwjglMap.put((short)0x10, Keyboard.KEY_Y);
|
||||
nativeToLwjglMap.put((short)0x06, Keyboard.KEY_Z);
|
||||
nativeToLwjglMap.put((Short)(short)0x1D, Keyboard.KEY_0);
|
||||
nativeToLwjglMap.put((Short)(short)0x12, Keyboard.KEY_1);
|
||||
nativeToLwjglMap.put((Short)(short)0x13, Keyboard.KEY_2);
|
||||
nativeToLwjglMap.put((Short)(short)0x14, Keyboard.KEY_3);
|
||||
nativeToLwjglMap.put((Short)(short)0x15, Keyboard.KEY_4);
|
||||
nativeToLwjglMap.put((Short)(short)0x17, Keyboard.KEY_5);
|
||||
nativeToLwjglMap.put((Short)(short)0x16, Keyboard.KEY_6);
|
||||
nativeToLwjglMap.put((Short)(short)0x1A, Keyboard.KEY_7);
|
||||
nativeToLwjglMap.put((Short)(short)0x1C, Keyboard.KEY_8);
|
||||
nativeToLwjglMap.put((Short)(short)0x19, Keyboard.KEY_9);
|
||||
nativeToLwjglMap.put((Short)(short)0x00, Keyboard.KEY_A);
|
||||
nativeToLwjglMap.put((Short)(short)0x0B, Keyboard.KEY_B);
|
||||
nativeToLwjglMap.put((Short)(short)0x08, Keyboard.KEY_C);
|
||||
nativeToLwjglMap.put((Short)(short)0x02, Keyboard.KEY_D);
|
||||
nativeToLwjglMap.put((Short)(short)0x0E, Keyboard.KEY_E);
|
||||
nativeToLwjglMap.put((Short)(short)0x03, Keyboard.KEY_F);
|
||||
nativeToLwjglMap.put((Short)(short)0x05, Keyboard.KEY_G);
|
||||
nativeToLwjglMap.put((Short)(short)0x04, Keyboard.KEY_H);
|
||||
nativeToLwjglMap.put((Short)(short)0x22, Keyboard.KEY_I);
|
||||
nativeToLwjglMap.put((Short)(short)0x26, Keyboard.KEY_J);
|
||||
nativeToLwjglMap.put((Short)(short)0x28, Keyboard.KEY_K);
|
||||
nativeToLwjglMap.put((Short)(short)0x25, Keyboard.KEY_L);
|
||||
nativeToLwjglMap.put((Short)(short)0x2E, Keyboard.KEY_M);
|
||||
nativeToLwjglMap.put((Short)(short)0x2D, Keyboard.KEY_N);
|
||||
nativeToLwjglMap.put((Short)(short)0x1F, Keyboard.KEY_O);
|
||||
nativeToLwjglMap.put((Short)(short)0x23, Keyboard.KEY_P);
|
||||
nativeToLwjglMap.put((Short)(short)0x0C, Keyboard.KEY_Q);
|
||||
nativeToLwjglMap.put((Short)(short)0x0F, Keyboard.KEY_R);
|
||||
nativeToLwjglMap.put((Short)(short)0x01, Keyboard.KEY_S);
|
||||
nativeToLwjglMap.put((Short)(short)0x11, Keyboard.KEY_T);
|
||||
nativeToLwjglMap.put((Short)(short)0x20, Keyboard.KEY_U);
|
||||
nativeToLwjglMap.put((Short)(short)0x09, Keyboard.KEY_V);
|
||||
nativeToLwjglMap.put((Short)(short)0x0D, Keyboard.KEY_W);
|
||||
nativeToLwjglMap.put((Short)(short)0x07, Keyboard.KEY_X);
|
||||
nativeToLwjglMap.put((Short)(short)0x10, Keyboard.KEY_Y);
|
||||
nativeToLwjglMap.put((Short)(short)0x06, Keyboard.KEY_Z);
|
||||
|
||||
nativeToLwjglMap.put((short)0x2A, Keyboard.KEY_BACKSLASH);
|
||||
nativeToLwjglMap.put((short)0x2B, Keyboard.KEY_COMMA);
|
||||
nativeToLwjglMap.put((short)0x18, Keyboard.KEY_EQUALS);
|
||||
nativeToLwjglMap.put((short)0x21, Keyboard.KEY_LBRACKET);
|
||||
nativeToLwjglMap.put((short)0x1B, Keyboard.KEY_MINUS);
|
||||
nativeToLwjglMap.put((short)0x27, Keyboard.KEY_APOSTROPHE);
|
||||
nativeToLwjglMap.put((short)0x1E, Keyboard.KEY_RBRACKET);
|
||||
nativeToLwjglMap.put((short)0x29, Keyboard.KEY_SEMICOLON);
|
||||
nativeToLwjglMap.put((short)0x2C, Keyboard.KEY_SLASH);
|
||||
nativeToLwjglMap.put((short)0x2F, Keyboard.KEY_PERIOD);
|
||||
nativeToLwjglMap.put((short)0x32, Keyboard.KEY_GRAVE);
|
||||
nativeToLwjglMap.put((Short)(short)0x2A, Keyboard.KEY_BACKSLASH);
|
||||
nativeToLwjglMap.put((Short)(short)0x2B, Keyboard.KEY_COMMA);
|
||||
nativeToLwjglMap.put((Short)(short)0x18, Keyboard.KEY_EQUALS);
|
||||
nativeToLwjglMap.put((Short)(short)0x21, Keyboard.KEY_LBRACKET);
|
||||
nativeToLwjglMap.put((Short)(short)0x1B, Keyboard.KEY_MINUS);
|
||||
nativeToLwjglMap.put((Short)(short)0x27, Keyboard.KEY_APOSTROPHE);
|
||||
nativeToLwjglMap.put((Short)(short)0x1E, Keyboard.KEY_RBRACKET);
|
||||
nativeToLwjglMap.put((Short)(short)0x29, Keyboard.KEY_SEMICOLON);
|
||||
nativeToLwjglMap.put((Short)(short)0x2C, Keyboard.KEY_SLASH);
|
||||
nativeToLwjglMap.put((Short)(short)0x2F, Keyboard.KEY_PERIOD);
|
||||
nativeToLwjglMap.put((Short)(short)0x32, Keyboard.KEY_CIRCUMFLEX);
|
||||
|
||||
nativeToLwjglMap.put((short)0x41, Keyboard.KEY_DECIMAL);
|
||||
nativeToLwjglMap.put((short)0x43, Keyboard.KEY_MULTIPLY);
|
||||
nativeToLwjglMap.put((short)0x45, Keyboard.KEY_ADD);
|
||||
nativeToLwjglMap.put((short)0x47, Keyboard.KEY_CLEAR);
|
||||
nativeToLwjglMap.put((short)0x4B, Keyboard.KEY_DIVIDE);
|
||||
nativeToLwjglMap.put((short)0x4C, Keyboard.KEY_NUMPADENTER);
|
||||
nativeToLwjglMap.put((short)0x4E, Keyboard.KEY_SUBTRACT);
|
||||
nativeToLwjglMap.put((short)0x51, Keyboard.KEY_NUMPADEQUALS);
|
||||
nativeToLwjglMap.put((Short)(short)0x41, Keyboard.KEY_DECIMAL);
|
||||
nativeToLwjglMap.put((Short)(short)0x43, Keyboard.KEY_MULTIPLY);
|
||||
nativeToLwjglMap.put((Short)(short)0x45, Keyboard.KEY_ADD);
|
||||
nativeToLwjglMap.put((Short)(short)0x47, Keyboard.KEY_CLEAR);
|
||||
nativeToLwjglMap.put((Short)(short)0x4B, Keyboard.KEY_DIVIDE);
|
||||
nativeToLwjglMap.put((Short)(short)0x4C, Keyboard.KEY_NUMPADENTER);
|
||||
nativeToLwjglMap.put((Short)(short)0x4E, Keyboard.KEY_SUBTRACT);
|
||||
nativeToLwjglMap.put((Short)(short)0x51, Keyboard.KEY_NUMPADEQUALS);
|
||||
|
||||
nativeToLwjglMap.put((short)0x52, Keyboard.KEY_NUMPAD0);
|
||||
nativeToLwjglMap.put((short)0x53, Keyboard.KEY_NUMPAD1);
|
||||
nativeToLwjglMap.put((short)0x54, Keyboard.KEY_NUMPAD2);
|
||||
nativeToLwjglMap.put((short)0x55, Keyboard.KEY_NUMPAD3);
|
||||
nativeToLwjglMap.put((short)0x56, Keyboard.KEY_NUMPAD4);
|
||||
nativeToLwjglMap.put((short)0x57, Keyboard.KEY_NUMPAD5);
|
||||
nativeToLwjglMap.put((short)0x58, Keyboard.KEY_NUMPAD6);
|
||||
nativeToLwjglMap.put((short)0x59, Keyboard.KEY_NUMPAD7);
|
||||
nativeToLwjglMap.put((short)0x5B, Keyboard.KEY_NUMPAD8);
|
||||
nativeToLwjglMap.put((short)0x5C, Keyboard.KEY_NUMPAD9);
|
||||
nativeToLwjglMap.put((Short)(short)0x52, Keyboard.KEY_NUMPAD0);
|
||||
nativeToLwjglMap.put((Short)(short)0x53, Keyboard.KEY_NUMPAD1);
|
||||
nativeToLwjglMap.put((Short)(short)0x54, Keyboard.KEY_NUMPAD2);
|
||||
nativeToLwjglMap.put((Short)(short)0x55, Keyboard.KEY_NUMPAD3);
|
||||
nativeToLwjglMap.put((Short)(short)0x56, Keyboard.KEY_NUMPAD4);
|
||||
nativeToLwjglMap.put((Short)(short)0x57, Keyboard.KEY_NUMPAD5);
|
||||
nativeToLwjglMap.put((Short)(short)0x58, Keyboard.KEY_NUMPAD6);
|
||||
nativeToLwjglMap.put((Short)(short)0x59, Keyboard.KEY_NUMPAD7);
|
||||
nativeToLwjglMap.put((Short)(short)0x5B, Keyboard.KEY_NUMPAD8);
|
||||
nativeToLwjglMap.put((Short)(short)0x5C, Keyboard.KEY_NUMPAD9);
|
||||
|
||||
|
||||
nativeToLwjglMap.put((short)0x24, Keyboard.KEY_RETURN);
|
||||
nativeToLwjglMap.put((short)0x30, Keyboard.KEY_TAB);
|
||||
nativeToLwjglMap.put((short)0x31, Keyboard.KEY_SPACE);
|
||||
nativeToLwjglMap.put((short)0x33, Keyboard.KEY_BACK);
|
||||
nativeToLwjglMap.put((short)0x35, Keyboard.KEY_ESCAPE);
|
||||
nativeToLwjglMap.put((short)0x36, Keyboard.KEY_RMETA); // not in Events.h - works on MBP
|
||||
nativeToLwjglMap.put((short)0x37, Keyboard.KEY_LMETA);
|
||||
nativeToLwjglMap.put((short)0x38, Keyboard.KEY_LSHIFT);
|
||||
nativeToLwjglMap.put((short)0x39, Keyboard.KEY_CAPITAL);
|
||||
nativeToLwjglMap.put((short)0x3A, Keyboard.KEY_LMENU);
|
||||
nativeToLwjglMap.put((short)0x3B, Keyboard.KEY_LCONTROL);
|
||||
nativeToLwjglMap.put((short)0x3C, Keyboard.KEY_RSHIFT);
|
||||
nativeToLwjglMap.put((short)0x3D, Keyboard.KEY_RMENU);
|
||||
nativeToLwjglMap.put((short)0x3E, Keyboard.KEY_RCONTROL);
|
||||
nativeToLwjglMap.put((Short)(short)0x24, Keyboard.KEY_RETURN);
|
||||
nativeToLwjglMap.put((Short)(short)0x30, Keyboard.KEY_TAB);
|
||||
nativeToLwjglMap.put((Short)(short)0x31, Keyboard.KEY_SPACE);
|
||||
nativeToLwjglMap.put((Short)(short)0x33, Keyboard.KEY_BACK);
|
||||
nativeToLwjglMap.put((Short)(short)0x35, Keyboard.KEY_ESCAPE);
|
||||
nativeToLwjglMap.put((Short)(short)0x36, Keyboard.KEY_RMETA); // not in Events.h - works on MBP
|
||||
nativeToLwjglMap.put((Short)(short)0x37, Keyboard.KEY_LMETA);
|
||||
nativeToLwjglMap.put((Short)(short)0x38, Keyboard.KEY_LSHIFT);
|
||||
nativeToLwjglMap.put((Short)(short)0x39, Keyboard.KEY_CAPITAL);
|
||||
nativeToLwjglMap.put((Short)(short)0x3A, Keyboard.KEY_LMENU);
|
||||
nativeToLwjglMap.put((Short)(short)0x3B, Keyboard.KEY_LCONTROL);
|
||||
nativeToLwjglMap.put((Short)(short)0x3C, Keyboard.KEY_RSHIFT);
|
||||
nativeToLwjglMap.put((Short)(short)0x3D, Keyboard.KEY_RMENU);
|
||||
nativeToLwjglMap.put((Short)(short)0x3E, Keyboard.KEY_RCONTROL);
|
||||
|
||||
nativeToLwjglMap.put((short)0x3F, Keyboard.KEY_FUNCTION);
|
||||
nativeToLwjglMap.put((short)0x77, Keyboard.KEY_END);
|
||||
nativeToLwjglMap.put((Short)(short)0x3F, Keyboard.KEY_FUNCTION);
|
||||
nativeToLwjglMap.put((Short)(short)0x77, Keyboard.KEY_END);
|
||||
|
||||
nativeToLwjglMap.put((short)0x7A, Keyboard.KEY_F1);
|
||||
nativeToLwjglMap.put((short)0x78, Keyboard.KEY_F2);
|
||||
nativeToLwjglMap.put((short)0x63, Keyboard.KEY_F3);
|
||||
nativeToLwjglMap.put((short)0x76, Keyboard.KEY_F4);
|
||||
nativeToLwjglMap.put((short)0x60, Keyboard.KEY_F5);
|
||||
nativeToLwjglMap.put((short)0x61, Keyboard.KEY_F6);
|
||||
nativeToLwjglMap.put((short)0x62, Keyboard.KEY_F7);
|
||||
nativeToLwjglMap.put((short)0x64, Keyboard.KEY_F8);
|
||||
nativeToLwjglMap.put((short)0x65, Keyboard.KEY_F9);
|
||||
nativeToLwjglMap.put((short)0x6D, Keyboard.KEY_F10);
|
||||
nativeToLwjglMap.put((short)0x67, Keyboard.KEY_F11);
|
||||
nativeToLwjglMap.put((short)0x6F, Keyboard.KEY_F12);
|
||||
nativeToLwjglMap.put((short)0x69, Keyboard.KEY_F13);
|
||||
nativeToLwjglMap.put((short)0x6B, Keyboard.KEY_F14);
|
||||
nativeToLwjglMap.put((short)0x71, Keyboard.KEY_F15);
|
||||
nativeToLwjglMap.put((short)0x6A, Keyboard.KEY_F16);
|
||||
nativeToLwjglMap.put((short)0x40, Keyboard.KEY_F17);
|
||||
nativeToLwjglMap.put((short)0x4F, Keyboard.KEY_F18);
|
||||
nativeToLwjglMap.put((short)0x50, Keyboard.KEY_F19);
|
||||
// nativeToLwjglMap.put((short)0x5A, Keyboard.KEY_F20);
|
||||
nativeToLwjglMap.put((Short)(short)0x7A, Keyboard.KEY_F1);
|
||||
nativeToLwjglMap.put((Short)(short)0x78, Keyboard.KEY_F2);
|
||||
nativeToLwjglMap.put((Short)(short)0x63, Keyboard.KEY_F3);
|
||||
nativeToLwjglMap.put((Short)(short)0x76, Keyboard.KEY_F4);
|
||||
nativeToLwjglMap.put((Short)(short)0x60, Keyboard.KEY_F5);
|
||||
nativeToLwjglMap.put((Short)(short)0x61, Keyboard.KEY_F6);
|
||||
nativeToLwjglMap.put((Short)(short)0x62, Keyboard.KEY_F7);
|
||||
nativeToLwjglMap.put((Short)(short)0x64, Keyboard.KEY_F8);
|
||||
nativeToLwjglMap.put((Short)(short)0x65, Keyboard.KEY_F9);
|
||||
nativeToLwjglMap.put((Short)(short)0x6D, Keyboard.KEY_F10);
|
||||
nativeToLwjglMap.put((Short)(short)0x67, Keyboard.KEY_F11);
|
||||
nativeToLwjglMap.put((Short)(short)0x6F, Keyboard.KEY_F12);
|
||||
nativeToLwjglMap.put((Short)(short)0x69, Keyboard.KEY_F13);
|
||||
nativeToLwjglMap.put((Short)(short)0x6B, Keyboard.KEY_F14);
|
||||
nativeToLwjglMap.put((Short)(short)0x71, Keyboard.KEY_F15);
|
||||
nativeToLwjglMap.put((Short)(short)0x6A, Keyboard.KEY_F16);
|
||||
nativeToLwjglMap.put((Short)(short)0x40, Keyboard.KEY_F17);
|
||||
nativeToLwjglMap.put((Short)(short)0x4F, Keyboard.KEY_F18);
|
||||
nativeToLwjglMap.put((Short)(short)0x50, Keyboard.KEY_F19);
|
||||
// nativeToLwjglMap.put((Short)(short)0x5A, Keyboard.KEY_F20);
|
||||
|
||||
nativeToLwjglMap.put((short)0x75, Keyboard.KEY_DELETE);
|
||||
nativeToLwjglMap.put((short)0x72, Keyboard.KEY_INSERT); // 'Help' in Events.h
|
||||
nativeToLwjglMap.put((short)0x73, Keyboard.KEY_HOME);
|
||||
// nativeToLwjglMap.put((short)0xA4, Keyboard.KEY_MUTE);
|
||||
nativeToLwjglMap.put((short)0x79, Keyboard.KEY_NEXT);
|
||||
nativeToLwjglMap.put((short)0x74, Keyboard.KEY_PRIOR);
|
||||
// nativeToLwjglMap.put((short)0x49, Keyboard.KEY_VOLUMEDOWN);
|
||||
// nativeToLwjglMap.put((short)0x48, Keyboard.KEY_VOLUMEUP);
|
||||
nativeToLwjglMap.put((short)0x7B, Keyboard.KEY_LEFT);
|
||||
nativeToLwjglMap.put((short)0x7C, Keyboard.KEY_RIGHT);
|
||||
nativeToLwjglMap.put((short)0x7D, Keyboard.KEY_DOWN);
|
||||
nativeToLwjglMap.put((short)0x7E, Keyboard.KEY_UP);
|
||||
nativeToLwjglMap.put((Short)(short)0x75, Keyboard.KEY_DELETE);
|
||||
nativeToLwjglMap.put((Short)(short)0x72, Keyboard.KEY_INSERT); // 'Help' in Events.h
|
||||
nativeToLwjglMap.put((Short)(short)0x73, Keyboard.KEY_HOME);
|
||||
// nativeToLwjglMap.put((Short)(short)0xA4, Keyboard.KEY_MUTE);
|
||||
nativeToLwjglMap.put((Short)(short)0x79, Keyboard.KEY_NEXT);
|
||||
nativeToLwjglMap.put((Short)(short)0x74, Keyboard.KEY_PRIOR);
|
||||
// nativeToLwjglMap.put((Short)(short)0x49, Keyboard.KEY_VOLUMEDOWN);
|
||||
// nativeToLwjglMap.put((Short)(short)0x48, Keyboard.KEY_VOLUMEUP);
|
||||
nativeToLwjglMap.put((Short)(short)0x7B, Keyboard.KEY_LEFT);
|
||||
nativeToLwjglMap.put((Short)(short)0x7C, Keyboard.KEY_RIGHT);
|
||||
nativeToLwjglMap.put((Short)(short)0x7D, Keyboard.KEY_DOWN);
|
||||
nativeToLwjglMap.put((Short)(short)0x7E, Keyboard.KEY_UP);
|
||||
|
||||
nativeToLwjglMap.put((short)0x0A, Keyboard.KEY_SECTION);
|
||||
nativeToLwjglMap.put((Short)(short)0x0A, Keyboard.KEY_SECTION);
|
||||
|
||||
nativeToLwjglMap.put((short)0x6E, Keyboard.KEY_APPS); // not in Events.h
|
||||
nativeToLwjglMap.put((short)0x129, Keyboard.KEY_COLON); // not in Events.h -- do we need it?
|
||||
nativeToLwjglMap.put((Short)(short)0x6E, Keyboard.KEY_APPS); // not in Events.h
|
||||
nativeToLwjglMap.put((Short)(short)0x129, Keyboard.KEY_COLON); // not in Events.h -- do we need it?
|
||||
}
|
||||
|
||||
public void register() {
|
||||
|
|
@ -210,9 +211,9 @@ final class MacOSXNativeKeyboard extends EventQueue {
|
|||
}
|
||||
|
||||
public void putKeyboardEvent(int key_code, byte state, int character, long nanos, boolean repeat) {
|
||||
((Buffer)event).clear();
|
||||
event.clear();
|
||||
event.putInt(key_code).put(state).putInt(character).putLong(nanos).put(repeat ? (byte)1 : (byte)0);
|
||||
((Buffer)event).flip();
|
||||
event.flip();
|
||||
putEvent(event);
|
||||
}
|
||||
|
||||
|
|
@ -220,7 +221,7 @@ final class MacOSXNativeKeyboard extends EventQueue {
|
|||
flushDeferredEvent();
|
||||
int old_position = key_down_buffer.position();
|
||||
key_down_buffer.put(key_states);
|
||||
((Buffer)key_down_buffer).position(old_position);
|
||||
key_down_buffer.position(old_position);
|
||||
}
|
||||
|
||||
public synchronized void copyEvents(ByteBuffer dest) {
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ package org.lwjgl.opengl;
|
|||
* @author kappaOne <one.kappa@gmail.com>
|
||||
*/
|
||||
|
||||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
|
|
@ -157,9 +156,9 @@ final class MacOSXNativeMouse extends EventQueue {
|
|||
}
|
||||
|
||||
protected void putMouseEventWithCoords(byte button, byte state, int coord1, int coord2, int dz, long nanos) {
|
||||
((Buffer)event).clear();
|
||||
event.clear();
|
||||
event.put(button).put(state).putInt(coord1).putInt(coord2).putInt(dz).putLong(nanos);
|
||||
((Buffer)event).flip();
|
||||
event.flip();
|
||||
putEvent(event);
|
||||
}
|
||||
|
||||
|
|
@ -175,7 +174,7 @@ final class MacOSXNativeMouse extends EventQueue {
|
|||
accum_dx = accum_dy = accum_dz = 0;
|
||||
int old_position = buttons_buffer.position();
|
||||
buttons_buffer.put(buttons, 0, buttons.length);
|
||||
((Buffer)buttons_buffer).position(old_position);
|
||||
buttons_buffer.position(old_position);
|
||||
}
|
||||
|
||||
private void setCursorPos(float x, float y, long nanos) {
|
||||
|
|
|
|||
|
|
@ -45,10 +45,10 @@ import org.lwjgl.LWJGLUtil;
|
|||
abstract class MacOSXPeerInfo extends PeerInfo {
|
||||
MacOSXPeerInfo(PixelFormat pixel_format, ContextAttribs attribs, boolean use_display_bpp, boolean support_window, boolean support_pbuffer, boolean double_buffered) throws LWJGLException {
|
||||
super(createHandle());
|
||||
|
||||
boolean gl32 = attribs != null && (3 < attribs.getMajorVersion() || (attribs.getMajorVersion() == 3 && 2 <= attribs.getMinorVersion())) && attribs.isProfileCore();
|
||||
|
||||
boolean gl32 = attribs != null && attribs.getMajorVersion() == 3 && attribs.getMinorVersion() == 2 && attribs.isProfileCore();
|
||||
if ( gl32 && !LWJGLUtil.isMacOSXEqualsOrBetterThan(10, 7) )
|
||||
throw new LWJGLException("OpenGL 3.2+ requested, but it requires MacOS X 10.7 or newer");
|
||||
throw new LWJGLException("OpenGL 3.2 requested, but it requires MacOS X 10.7 or newer");
|
||||
|
||||
choosePixelFormat(pixel_format, gl32, use_display_bpp, support_window, support_pbuffer, double_buffered);
|
||||
}
|
||||
|
|
|
|||
92
src/java/org/lwjgl/opengl/WindowsContextAttribs.java
Normal file
92
src/java/org/lwjgl/opengl/WindowsContextAttribs.java
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* 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
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* An implementation of ContextAttribs using WGL_create_context.
|
||||
*
|
||||
* @author spasi <spasi@users.sourceforge.net>
|
||||
*/
|
||||
final class WindowsContextAttribs implements ContextAttribsImplementation {
|
||||
|
||||
private static final int WGL_CONTEXT_MAJOR_VERSION_ARB = 0x2091;
|
||||
private static final int WGL_CONTEXT_MINOR_VERSION_ARB = 0x2092;
|
||||
private static final int WGL_CONTEXT_LAYER_PLANE_ARB = 0x2093;
|
||||
private static final int WGL_CONTEXT_FLAGS_ARB = 0x2094;
|
||||
private static final int WGL_CONTEXT_PROFILE_MASK_ARB = 0x9126;
|
||||
|
||||
private static final int WGL_CONTEXT_DEBUG_BIT_ARB = 0x0001;
|
||||
private static final int WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB = 0x0002;
|
||||
|
||||
private static final int WGL_CONTEXT_CORE_PROFILE_BIT_ARB = 0x00000001;
|
||||
private static final int WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB = 0x00000002;
|
||||
|
||||
WindowsContextAttribs() {
|
||||
}
|
||||
|
||||
public int getMajorVersionAttrib() {
|
||||
return WGL_CONTEXT_MAJOR_VERSION_ARB;
|
||||
}
|
||||
|
||||
public int getMinorVersionAttrib() {
|
||||
return WGL_CONTEXT_MINOR_VERSION_ARB;
|
||||
}
|
||||
|
||||
public int getLayerPlaneAttrib() {
|
||||
return WGL_CONTEXT_LAYER_PLANE_ARB;
|
||||
}
|
||||
|
||||
public int getFlagsAttrib() {
|
||||
return WGL_CONTEXT_FLAGS_ARB;
|
||||
}
|
||||
|
||||
public int getDebugBit() {
|
||||
return WGL_CONTEXT_DEBUG_BIT_ARB;
|
||||
}
|
||||
|
||||
public int getForwardCompatibleBit() {
|
||||
return WGL_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB;
|
||||
}
|
||||
|
||||
public int getProfileMaskAttrib() {
|
||||
return WGL_CONTEXT_PROFILE_MASK_ARB;
|
||||
}
|
||||
|
||||
public int getProfileCoreBit() {
|
||||
return WGL_CONTEXT_CORE_PROFILE_BIT_ARB;
|
||||
}
|
||||
|
||||
public int getProfileCompatibilityBit() {
|
||||
return WGL_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -196,6 +196,7 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
private boolean inAppActivate;
|
||||
private boolean resized;
|
||||
private boolean resizable;
|
||||
private boolean maximized;
|
||||
private int x;
|
||||
private int y;
|
||||
private int width;
|
||||
|
|
@ -209,6 +210,7 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
private boolean iconsLoaded;
|
||||
|
||||
private int captureMouse = -1;
|
||||
private boolean trackingMouse;
|
||||
private boolean mouseInside;
|
||||
|
||||
static {
|
||||
|
|
@ -225,14 +227,17 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
}
|
||||
|
||||
public void createWindow(DrawableLWJGL drawable, DisplayMode mode, Canvas parent, int x, int y) throws LWJGLException {
|
||||
close_requested = false;
|
||||
is_dirty = false;
|
||||
isMinimized = false;
|
||||
isFocused = false;
|
||||
redoMakeContextCurrent = false;
|
||||
maximized = false;
|
||||
this.parent = parent;
|
||||
hasParent = parent != null;
|
||||
parent_hwnd = parent != null ? getHwnd(parent) : 0;
|
||||
this.hwnd = nCreateWindow(x, y, mode.getWidth(), mode.getHeight(), Display.isFullscreen() || isUndecorated(), parent != null, parent_hwnd);
|
||||
if ( Display.isResizable() && parent == null ) {
|
||||
setResizable(true);
|
||||
}
|
||||
|
||||
this.resizable=false;
|
||||
if (hwnd == 0) {
|
||||
throw new LWJGLException("Failed to create window");
|
||||
}
|
||||
|
|
@ -256,6 +261,9 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
updateWidthAndHeight();
|
||||
|
||||
if ( parent == null ) {
|
||||
if(Display.isResizable()) {
|
||||
setResizable(true);
|
||||
}
|
||||
setForegroundWindow(getHwnd());
|
||||
} else {
|
||||
parent_focused = new AtomicBoolean(false);
|
||||
|
|
@ -314,15 +322,6 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
freeLargeIcon();
|
||||
freeSmallIcon();
|
||||
resetCursorClipping();
|
||||
|
||||
// reset state
|
||||
close_requested = false;
|
||||
is_dirty = false;
|
||||
isMinimized = false;
|
||||
isFocused = false;
|
||||
redoMakeContextCurrent = false;
|
||||
resizable = false;
|
||||
mouseInside = false;
|
||||
}
|
||||
private static native void nReleaseDC(long hwnd, long hdc);
|
||||
private static native void nDestroyWindow(long hwnd);
|
||||
|
|
@ -365,7 +364,7 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
/*
|
||||
* Called when the application is alt-tabbed to or from
|
||||
*/
|
||||
private void appActivate(boolean active, long millis) {
|
||||
private void appActivate(boolean active) {
|
||||
if (inAppActivate) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -380,14 +379,16 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
}
|
||||
setFocus(getHwnd());
|
||||
redoMakeContextCurrent = true;
|
||||
} else {
|
||||
if (Display.isFullscreen())
|
||||
updateClipping();
|
||||
|
||||
if ( keyboard != null )
|
||||
keyboard.releaseAll(millis);
|
||||
if ( Display.isFullscreen() ) {
|
||||
showWindow(getHwnd(), SW_SHOWMINNOACTIVE);
|
||||
resetDisplayMode();
|
||||
}
|
||||
}
|
||||
keyboard.fireLostKeyEvents();
|
||||
} else if (Display.isFullscreen()) {
|
||||
showWindow(getHwnd(), SW_SHOWMINNOACTIVE);
|
||||
resetDisplayMode();
|
||||
} else
|
||||
updateClipping();
|
||||
updateCursor();
|
||||
inAppActivate = false;
|
||||
}
|
||||
|
|
@ -600,7 +601,7 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
}
|
||||
|
||||
public void pollMouse(IntBuffer coord_buffer, ByteBuffer buttons) {
|
||||
mouse.poll(coord_buffer, buttons, this);
|
||||
mouse.poll(coord_buffer, buttons);
|
||||
}
|
||||
|
||||
public void readMouse(ByteBuffer buffer) {
|
||||
|
|
@ -608,7 +609,7 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
}
|
||||
|
||||
public void grabMouse(boolean grab) {
|
||||
mouse.grab(grab);
|
||||
mouse.grab(grab, shouldGrab());
|
||||
updateCursor();
|
||||
}
|
||||
|
||||
|
|
@ -632,15 +633,13 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
|
||||
private void updateCursor() {
|
||||
try {
|
||||
if (mouse != null && shouldGrab()) {
|
||||
centerCursor(hwnd);
|
||||
if (mouse != null && shouldGrab())
|
||||
nSetNativeCursor(getHwnd(), mouse.getBlankCursor());
|
||||
} else
|
||||
else
|
||||
nSetNativeCursor(getHwnd(), current_cursor);
|
||||
} catch (LWJGLException e) {
|
||||
LWJGLUtil.log("Failed to update cursor: " + e);
|
||||
}
|
||||
updateClipping();
|
||||
}
|
||||
static native void nSetNativeCursor(long hwnd, Object handle) throws LWJGLException;
|
||||
|
||||
|
|
@ -861,6 +860,12 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
return !isMinimized && isFocused && Mouse.isGrabbed();
|
||||
}
|
||||
|
||||
private void handleMouseMoved(int x, int y, long millis) {
|
||||
if (mouse != null) {
|
||||
mouse.handleMouseMoved(x, y, millis, shouldGrab());
|
||||
}
|
||||
}
|
||||
|
||||
private static native long nSetCapture(long hwnd);
|
||||
private static native boolean nReleaseCapture();
|
||||
|
||||
|
|
@ -911,6 +916,10 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
|
||||
private static native long defWindowProc(long hwnd, int msg, long wParam, long lParam);
|
||||
|
||||
private void checkCursorState() {
|
||||
updateClipping();
|
||||
}
|
||||
|
||||
private void updateClipping() {
|
||||
if ((Display.isFullscreen() || (mouse != null && mouse.isGrabbed())) && !isMinimized && isFocused && (getForegroundWindow() == getHwnd() || hasParent)) {
|
||||
try {
|
||||
|
|
@ -924,10 +933,8 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
}
|
||||
|
||||
private void setMinimized(boolean m) {
|
||||
if ( m != isMinimized ) {
|
||||
isMinimized = m;
|
||||
updateClipping();
|
||||
}
|
||||
isMinimized = m;
|
||||
checkCursorState();
|
||||
}
|
||||
|
||||
private long doHandleMessage(long hwnd, int msg, long wParam, long lParam, long millis) {
|
||||
|
|
@ -968,6 +975,7 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
switch ((int)wParam) {
|
||||
case SIZE_RESTORED:
|
||||
case SIZE_MAXIMIZED:
|
||||
maximized = ((int)wParam) == SIZE_MAXIMIZED;
|
||||
resized = true;
|
||||
updateWidthAndHeight();
|
||||
setMinimized(false);
|
||||
|
|
@ -981,11 +989,21 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
resized = true;
|
||||
updateWidthAndHeight();
|
||||
break;
|
||||
case WM_SETCURSOR:
|
||||
if((lParam & 0xFFFF) == HTCLIENT) {
|
||||
// if the cursor is inside the client area, reset it
|
||||
// to the current LWJGL-cursor
|
||||
updateCursor();
|
||||
return -1; //TRUE
|
||||
} else {
|
||||
// let Windows handle cursors outside the client area for resizing, etc.
|
||||
return defWindowProc(hwnd, msg, wParam, lParam);
|
||||
}
|
||||
case WM_KILLFOCUS:
|
||||
appActivate(false, millis);
|
||||
appActivate(false);
|
||||
return 0L;
|
||||
case WM_SETFOCUS:
|
||||
appActivate(true, millis);
|
||||
appActivate(true);
|
||||
return 0L;
|
||||
case WM_MOUSEACTIVATE:
|
||||
if ( parent != null ) {
|
||||
|
|
@ -995,16 +1013,14 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
}
|
||||
break;
|
||||
case WM_MOUSEMOVE:
|
||||
if ( mouse != null ) {
|
||||
int xPos = (short)(lParam & 0xFFFF);
|
||||
int yPos = transformY(getHwnd(), (short)(lParam >>> 16));
|
||||
mouse.handleMouseMoved(xPos, yPos, millis);
|
||||
}
|
||||
if ( !mouseInside ) {
|
||||
mouseInside = true;
|
||||
updateCursor();
|
||||
nTrackMouseEvent(hwnd);
|
||||
}
|
||||
int xPos = (int)(short)(lParam & 0xFFFF);
|
||||
int yPos = transformY(getHwnd(), (int)(short)((lParam >> 16) & 0xFFFF));
|
||||
handleMouseMoved(xPos, yPos, millis);
|
||||
checkCursorState();
|
||||
mouseInside = true;
|
||||
if(!trackingMouse) {
|
||||
trackingMouse = nTrackMouseEvent(hwnd);
|
||||
}
|
||||
return 0L;
|
||||
case WM_MOUSEWHEEL:
|
||||
int dwheel = (int)(short)((wParam >> 16) & 0xFFFF);
|
||||
|
|
@ -1047,11 +1063,6 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
handleChar(wParam, lParam, millis);
|
||||
return 0L;
|
||||
case WM_SYSKEYUP:
|
||||
// Disable WM_SYSCOMMAND/SC_KEYMENU
|
||||
if ( wParam == WindowsKeycodes.VK_MENU || wParam == WindowsKeycodes.VK_F10 ) {
|
||||
handleKeyButton(wParam, lParam, millis);
|
||||
return 0L;
|
||||
}
|
||||
/* Fall through */
|
||||
case WM_KEYUP:
|
||||
// SysRq apparently only generates WM_KEYUP, so we'll fake a WM_KEYDOWN
|
||||
|
|
@ -1074,12 +1085,16 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
return 0L;
|
||||
case WM_SYSCOMMAND:
|
||||
switch ((int)(wParam & 0xfff0)) {
|
||||
case SC_KEYMENU:
|
||||
case SC_MOUSEMENU:
|
||||
case SC_SCREENSAVE:
|
||||
case SC_MONITORPOWER:
|
||||
return 0L;
|
||||
case SC_CLOSE:
|
||||
close_requested = true;
|
||||
return 0L;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case WM_PAINT:
|
||||
|
|
@ -1087,6 +1102,7 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
break;
|
||||
case WM_MOUSELEAVE:
|
||||
mouseInside = false;
|
||||
trackingMouse = false;
|
||||
break;
|
||||
case WM_CANCELMODE:
|
||||
nReleaseCapture();
|
||||
|
|
@ -1100,8 +1116,8 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
case WM_WINDOWPOSCHANGED:
|
||||
if(getWindowRect(hwnd, rect_buffer)) {
|
||||
rect.copyFromBuffer(rect_buffer);
|
||||
x = rect.left;
|
||||
y = rect.top;
|
||||
x = rect.top;
|
||||
y = rect.bottom;
|
||||
} else {
|
||||
LWJGLUtil.log("WM_WINDOWPOSCHANGED: Unable to get window rect");
|
||||
}
|
||||
|
|
@ -1139,42 +1155,31 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
}
|
||||
|
||||
public void setResizable(boolean resizable) {
|
||||
if ( this.resizable == resizable )
|
||||
return;
|
||||
if(this.resizable != resizable) {
|
||||
int style = (int)getWindowLongPtr(hwnd, GWL_STYLE);
|
||||
int styleex = (int)getWindowLongPtr(hwnd, GWL_EXSTYLE);
|
||||
|
||||
this.resized = false;
|
||||
// update frame style
|
||||
if(resizable && !Display.isFullscreen()) {
|
||||
setWindowLongPtr(hwnd, GWL_STYLE, style |= (WS_THICKFRAME | WS_MAXIMIZEBOX));
|
||||
} else {
|
||||
setWindowLongPtr(hwnd, GWL_STYLE, style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX));
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
int style = (int)getWindowLongPtr(hwnd, GWL_STYLE);
|
||||
int styleex = (int)getWindowLongPtr(hwnd, GWL_EXSTYLE);
|
||||
|
||||
// update frame style
|
||||
setWindowLongPtr(
|
||||
hwnd,
|
||||
GWL_STYLE,
|
||||
style = resizable && !Display.isFullscreen()
|
||||
? (style | (WS_THICKFRAME | WS_MAXIMIZEBOX))
|
||||
: (style & ~(WS_THICKFRAME | WS_MAXIMIZEBOX))
|
||||
);
|
||||
|
||||
// from the existing client rect, determine the new window rect
|
||||
// based on the style changes - using AdjustWindowRectEx.
|
||||
getGlobalClientRect(hwnd, rect);
|
||||
rect.copyToBuffer(rect_buffer);
|
||||
adjustWindowRectEx(rect_buffer, style, false, styleex);
|
||||
rect.copyFromBuffer(rect_buffer);
|
||||
|
||||
// Apply the style changes
|
||||
setWindowPos(
|
||||
hwnd, 0L,
|
||||
rect.left,
|
||||
rect.top,
|
||||
rect.right - rect.left,
|
||||
rect.bottom - rect.top,
|
||||
SWP_NOZORDER | SWP_FRAMECHANGED
|
||||
);
|
||||
|
||||
updateWidthAndHeight();
|
||||
}
|
||||
|
||||
private native boolean adjustWindowRectEx(IntBuffer rectBuffer, int style, boolean menu, int styleex);
|
||||
|
|
@ -1186,50 +1191,44 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public float getPixelScaleFactor() {
|
||||
return 1f;
|
||||
}
|
||||
|
||||
private static final class Rect {
|
||||
|
||||
public int
|
||||
left,
|
||||
top,
|
||||
right,
|
||||
bottom;
|
||||
public int top;
|
||||
public int bottom;
|
||||
public int left;
|
||||
public int right;
|
||||
|
||||
public void copyToBuffer(IntBuffer buffer) {
|
||||
buffer
|
||||
.put(0, left)
|
||||
.put(1, top)
|
||||
.put(2, right)
|
||||
.put(3, bottom);
|
||||
buffer.put(0, top).put(1, bottom).put(2, left).put(3, right);
|
||||
}
|
||||
|
||||
public void copyFromBuffer(IntBuffer buffer) {
|
||||
left = buffer.get(0);
|
||||
top = buffer.get(1);
|
||||
right = buffer.get(2);
|
||||
bottom = buffer.get(3);
|
||||
top = buffer.get(0);
|
||||
bottom = buffer.get(1);
|
||||
left = buffer.get(2);
|
||||
right = buffer.get(3);
|
||||
}
|
||||
|
||||
public void offset(int offset_x, int offset_y) {
|
||||
left += offset_x;
|
||||
top += offset_y;
|
||||
right += offset_x;
|
||||
top += offset_y;
|
||||
bottom += offset_y;
|
||||
}
|
||||
|
||||
public static void intersect(Rect r1, Rect r2, Rect dst) {
|
||||
dst.left = Math.max(r1.left, r2.left);
|
||||
dst.top = Math.max(r1.top, r2.top);
|
||||
dst.right = Math.min(r1.right, r2.right);
|
||||
dst.bottom = Math.min(r1.bottom, r2.bottom);
|
||||
dst.left = Math.max(r1.left, r2.left);
|
||||
dst.right = Math.min(r1.right, r2.right);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Rect: left = " + left + " top = " + top + " right = " + right + " bottom = " + bottom + ", width: " + (right - left) + ", height: " + (bottom - top);
|
||||
return "Rect: top = " + top + " bottom = " + bottom + " left = " + left + " right = " + right + ", width: " + (right - left) + ", height: " + (bottom - top);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,11 +70,10 @@ final class WindowsKeyboard {
|
|||
// Windows will not send an up event for the first button that was released in this case.
|
||||
// There will only be one up event, for the last button only. We handle this problem
|
||||
// here, using asynchronous state queries.
|
||||
if ( isKeyDown(Keyboard.KEY_LSHIFT) && !isKeyPressedAsync(WindowsKeycodes.VK_LSHIFT) )
|
||||
handleKey(WindowsKeycodes.VK_SHIFT, Keyboard.KEY_LSHIFT, false, (byte)0, 0L, false);
|
||||
|
||||
if ( isKeyDown(Keyboard.KEY_RSHIFT) && !isKeyPressedAsync(WindowsKeycodes.VK_RSHIFT) )
|
||||
handleKey(WindowsKeycodes.VK_SHIFT, Keyboard.KEY_RSHIFT, false, (byte)0, 0L, false);
|
||||
if ( isKeyDown(Keyboard.KEY_LSHIFT) && isKeyDown(Keyboard.KEY_RSHIFT) ) {
|
||||
if ( !isKeyPressedAsync(WindowsKeycodes.VK_LSHIFT) ) handleKey(WindowsKeycodes.VK_SHIFT, Keyboard.KEY_LSHIFT, false, (byte)0, 0L, false);
|
||||
if ( !isKeyPressedAsync(WindowsKeycodes.VK_RSHIFT) ) handleKey(WindowsKeycodes.VK_SHIFT, Keyboard.KEY_RSHIFT, false, (byte)0, 0L, false);
|
||||
}
|
||||
|
||||
int old_position = keyDownBuffer.position();
|
||||
keyDownBuffer.put(key_down_buffer);
|
||||
|
|
@ -123,18 +122,6 @@ final class WindowsKeyboard {
|
|||
return (GetAsyncKeyState(virt_key) & 0x8000) != 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called when the window loses focus: we release all currently pressed keys. If a key has been pressed (or hasn't been released at all), before we
|
||||
* regain focus, we'll start receiving repeat press events. We'll treat the first of those as a non-repeat press.
|
||||
*/
|
||||
void releaseAll(long millis) {
|
||||
for ( int i = 0; i < virt_key_down_buffer.length; i++ ) {
|
||||
if ( isKeyPressed(virt_key_down_buffer[i]) ) {
|
||||
handleKey(i, 0, false, (byte)0, millis, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void handleKey(int virt_key, int scan_code, boolean extended, byte event_state, long millis, boolean repeat) {
|
||||
virt_key = translateExtended(virt_key, scan_code, extended);
|
||||
if ( !repeat && isKeyPressed(event_state) == isKeyPressed(virt_key_down_buffer[virt_key]) )
|
||||
|
|
@ -145,7 +132,6 @@ final class WindowsKeyboard {
|
|||
int keycode = WindowsKeycodes.mapVirtualKeyToLWJGLCode(virt_key);
|
||||
if (keycode < key_down_buffer.length) {
|
||||
key_down_buffer[keycode] = event_state;
|
||||
repeat &= isKeyPressed(virt_key_down_buffer[virt_key]); // Treat the first repeat event after releaseAll() as a non-repeat press.
|
||||
virt_key_down_buffer[virt_key] = event_state;
|
||||
}
|
||||
retained_key_code = keycode;
|
||||
|
|
@ -155,6 +141,13 @@ final class WindowsKeyboard {
|
|||
retained_repeat = repeat;
|
||||
}
|
||||
|
||||
void fireLostKeyEvents() {
|
||||
for ( int i = 0; i < virt_key_down_buffer.length; i++ ) {
|
||||
if ( isKeyPressed(virt_key_down_buffer[i]) && !isKeyPressedAsync(i) )
|
||||
handleKey(i, 0, false, (byte)0, 0L, false);
|
||||
}
|
||||
}
|
||||
|
||||
void handleChar(int event_char, long millis, boolean repeat) {
|
||||
if (has_retained_event && retained_char != 0)
|
||||
flushRetained();
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ final class WindowsMouse {
|
|||
return mouse_button_count;
|
||||
}
|
||||
|
||||
public void poll(IntBuffer coord_buffer, ByteBuffer buttons, WindowsDisplay display) {
|
||||
public void poll(IntBuffer coord_buffer, ByteBuffer buttons) {
|
||||
for (int i = 0; i < coord_buffer.remaining(); i++)
|
||||
coord_buffer.put(coord_buffer.position() + i, 0);
|
||||
int num_buttons = mouse_button_count;
|
||||
|
|
@ -103,9 +103,6 @@ final class WindowsMouse {
|
|||
if (isGrabbed()) {
|
||||
coord_buffer.put(coord_buffer.position() + 0, accum_dx);
|
||||
coord_buffer.put(coord_buffer.position() + 1, accum_dy);
|
||||
|
||||
if ( display.isActive() && display.isVisible() && (accum_dx != 0 || accum_dy != 0) )
|
||||
WindowsDisplay.centerCursor(hwnd);
|
||||
} else {
|
||||
coord_buffer.put(coord_buffer.position() + 0, last_x);
|
||||
coord_buffer.put(coord_buffer.position() + 1, last_y);
|
||||
|
|
@ -135,8 +132,25 @@ final class WindowsMouse {
|
|||
return blank_cursor;
|
||||
}
|
||||
|
||||
public void grab(boolean grab) {
|
||||
mouse_grabbed = grab;
|
||||
public void grab(boolean grab, boolean should_center) {
|
||||
if (grab) {
|
||||
if (!mouse_grabbed) {
|
||||
mouse_grabbed = true;
|
||||
if (should_center) {
|
||||
try {
|
||||
WindowsDisplay.setupCursorClipping(hwnd);
|
||||
} catch (LWJGLException e) {
|
||||
LWJGLUtil.log("Failed to setup cursor clipping: " + e);
|
||||
}
|
||||
centerCursor();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (mouse_grabbed) {
|
||||
mouse_grabbed = false;
|
||||
WindowsDisplay.resetCursorClipping();
|
||||
}
|
||||
}
|
||||
event_queue.clearEvents();
|
||||
}
|
||||
|
||||
|
|
@ -145,6 +159,10 @@ final class WindowsMouse {
|
|||
putMouseEvent((byte)-1, (byte)0, event_dwheel, millis*1000000);
|
||||
}
|
||||
|
||||
private void centerCursor() {
|
||||
WindowsDisplay.centerCursor(hwnd);
|
||||
}
|
||||
|
||||
public void setPosition(int x, int y) {
|
||||
this.last_x = x;
|
||||
this.last_y = y;
|
||||
|
|
@ -154,7 +172,7 @@ final class WindowsMouse {
|
|||
WindowsDisplay.doDestroyCursor(blank_cursor);
|
||||
}
|
||||
|
||||
public void handleMouseMoved(int x, int y, long millis) {
|
||||
public void handleMouseMoved(int x, int y, long millis, boolean should_center) {
|
||||
int dx = x - last_x;
|
||||
int dy = y - last_y;
|
||||
if (dx != 0 || dy != 0) {
|
||||
|
|
@ -165,6 +183,8 @@ final class WindowsMouse {
|
|||
long nanos = millis*1000000;
|
||||
if (mouse_grabbed) {
|
||||
putMouseEventWithCoords((byte)-1, (byte)0, dx, dy, 0, nanos);
|
||||
if (should_center)
|
||||
centerCursor();
|
||||
} else {
|
||||
putMouseEventWithCoords((byte)-1, (byte)0, x, y, 0, nanos);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,178 +27,126 @@
|
|||
|
||||
package org.lwjgl.opengl;
|
||||
|
||||
import org.lwjgl.LWJGLUtil;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.lwjgl.LWJGLUtil;
|
||||
|
||||
/**
|
||||
* Utility for working with the xrandr commmand-line utility. Assumes
|
||||
* xrandr v1.2 or higher.
|
||||
*
|
||||
* @author ryanm
|
||||
*/
|
||||
public class XRandR {
|
||||
|
||||
public class XRandR
|
||||
{
|
||||
private static Screen[] current;
|
||||
|
||||
/**
|
||||
* Either the screen marked as "primary" (if it is turned on)
|
||||
* or the one with the largest (current) resolution.
|
||||
*/
|
||||
private static String primaryScreenIdentifier;
|
||||
|
||||
/**
|
||||
* Used to save the configuration of all output devices to
|
||||
* restore it on exit or in case of crash.
|
||||
*/
|
||||
private static Screen[] savedConfiguration;
|
||||
|
||||
private static Map<String, Screen[]> screens;
|
||||
|
||||
private static final Pattern WHITESPACE_PATTERN = Pattern.compile("\\s+");
|
||||
private static void populate()
|
||||
{
|
||||
if( screens == null )
|
||||
{
|
||||
screens = new HashMap<String, Screen[]>();
|
||||
|
||||
private static void populate() {
|
||||
if ( screens != null )
|
||||
return;
|
||||
// ProcessBuilder pb = new ProcessBuilder( "xrandr", "-q" );
|
||||
// pb.redirectErrorStream();
|
||||
try
|
||||
{
|
||||
// Process p= pb.start();
|
||||
Process p = Runtime.getRuntime().exec( new String[] { "xrandr", "-q" } );
|
||||
|
||||
screens = new HashMap<String, Screen[]>();
|
||||
List<Screen> currentList = new ArrayList<Screen>();
|
||||
List<Screen> possibles = new ArrayList<Screen>();
|
||||
String name = null;
|
||||
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(new String[] { "xrandr", "-q" });
|
||||
BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) );
|
||||
String line;
|
||||
while( ( line = br.readLine() ) != null )
|
||||
{
|
||||
line = line.trim();
|
||||
String[] sa = line.split( "\\s+" );
|
||||
|
||||
List<Screen> currentList = new ArrayList<Screen>();
|
||||
List<Screen> possibles = new ArrayList<Screen>();
|
||||
String name = null;
|
||||
// saves the position of the current screen. this is specified in the header of the screen block,
|
||||
// but required later when parsing the screen modelines
|
||||
int[] currentScreenPosition = new int[2];
|
||||
if( "connected".equals(sa[1]) )
|
||||
{
|
||||
// found a new screen block
|
||||
if( name != null )
|
||||
{
|
||||
screens.put( name, possibles.toArray( new Screen[ possibles.size() ] ) );
|
||||
possibles.clear();
|
||||
}
|
||||
name = sa[ 0 ];
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
String line;
|
||||
while ( (line = br.readLine()) != null ) {
|
||||
line = line.trim();
|
||||
String[] sa = WHITESPACE_PATTERN.split(line);
|
||||
|
||||
if ( "connected".equals(sa[1]) ) {
|
||||
// found a new screen block
|
||||
if ( name != null ) {
|
||||
screens.put(name, possibles.toArray(new Screen[possibles.size()]));
|
||||
possibles.clear();
|
||||
// record the current config
|
||||
parseScreen( currentList, name, "primary".equals(sa[ 2 ]) ? sa[ 3 ] : sa[ 2 ] );
|
||||
}
|
||||
name = sa[0];
|
||||
|
||||
// enabled?
|
||||
if (sa.length > 2) {
|
||||
// save position of this screen, will be used later when current modeline is parsed
|
||||
if ( "primary".equals(sa[2]) ) {
|
||||
parseScreenHeader(currentScreenPosition, sa[3]);
|
||||
// save primary
|
||||
primaryScreenIdentifier = name;
|
||||
} else {
|
||||
parseScreenHeader(currentScreenPosition, sa[2]);
|
||||
}
|
||||
} else {
|
||||
// disabled screen, no position info available
|
||||
currentScreenPosition[0] = 0;
|
||||
currentScreenPosition[1] = 0;
|
||||
}
|
||||
} else if ("disconnected".equals(sa[1])) {
|
||||
// previous screen block is over
|
||||
if (name != null) {
|
||||
screens.put(name, possibles.toArray(new Screen[possibles.size()]));
|
||||
name = null;
|
||||
}
|
||||
} else if (name != null) { // only read modelines after a valid screen identifier
|
||||
Matcher m = SCREEN_MODELINE_PATTERN.matcher(sa[0]);
|
||||
if ( m.matches() ) {
|
||||
else if( Pattern.matches( "\\d*x\\d*", sa[ 0 ] ) )
|
||||
{
|
||||
// found a new mode line
|
||||
parseScreenModeline(
|
||||
possibles, currentList, name,
|
||||
Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2)),
|
||||
sa, currentScreenPosition
|
||||
);
|
||||
parseScreen( possibles, name, sa[ 0 ] );
|
||||
}
|
||||
}
|
||||
|
||||
screens.put( name, possibles.toArray( new Screen[ possibles.size() ] ) );
|
||||
|
||||
current = currentList.toArray(new Screen[currentList.size()]);
|
||||
}
|
||||
|
||||
if (name != null) {
|
||||
screens.put(name, possibles.toArray(new Screen[possibles.size()]));
|
||||
}
|
||||
|
||||
current = currentList.toArray(new Screen[currentList.size()]);
|
||||
|
||||
// set primary to largest screen if not set yet
|
||||
if ( primaryScreenIdentifier == null ) {
|
||||
long totalPixels = Long.MIN_VALUE;
|
||||
for ( Screen screen : current ) {
|
||||
if ( 1l * screen.width * screen.height > totalPixels ) {
|
||||
primaryScreenIdentifier = screen.name;
|
||||
totalPixels = 1l * screen.width * screen.height;
|
||||
}
|
||||
}
|
||||
catch( Throwable e )
|
||||
{
|
||||
LWJGLUtil.log( "Exception in XRandR.populate(): " + e.getMessage() );
|
||||
screens.clear();
|
||||
current = new Screen[ 0 ];
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
LWJGLUtil.log("Exception in XRandR.populate(): " + e.getMessage());
|
||||
screens.clear();
|
||||
current = new Screen[0];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The current screen configuration of the primary device,
|
||||
* or an empty array if xrandr is not supported
|
||||
* @return The current screen configuration, or an empty array if
|
||||
* xrandr is not supported
|
||||
*/
|
||||
public static Screen[] getConfiguration() {
|
||||
public static Screen[] getConfiguration()
|
||||
{
|
||||
populate();
|
||||
|
||||
// find and return primary
|
||||
for ( Screen screen : current ) {
|
||||
if ( screen.name.equals(primaryScreenIdentifier) ) {
|
||||
return new Screen[] { screen };
|
||||
}
|
||||
}
|
||||
|
||||
// problem with primary device, fall back to old behaviour
|
||||
return current.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param disableOthers if screens not included in screens should be turned off (true) or left alone (false)
|
||||
* @param screens The desired screen set, may not be <code>null</code>
|
||||
*
|
||||
* @throws IllegalArgumentException if no screens are specified
|
||||
* @param screens
|
||||
* The desired screen set, may not be <code>null</code>
|
||||
* @throws IllegalArgumentException
|
||||
* if no screens are specified
|
||||
*/
|
||||
public static void setConfiguration(boolean disableOthers, Screen... screens) {
|
||||
if ( screens.length == 0 )
|
||||
throw new IllegalArgumentException("Must specify at least one screen");
|
||||
|
||||
if ( savedConfiguration == null )
|
||||
saveConfiguration();
|
||||
public static void setConfiguration(Screen... screens)
|
||||
{
|
||||
if( screens.length == 0 )
|
||||
throw new IllegalArgumentException( "Must specify at least one screen" );
|
||||
|
||||
List<String> cmd = new ArrayList<String>();
|
||||
cmd.add("xrandr");
|
||||
cmd.add( "xrandr" );
|
||||
|
||||
if ( disableOthers ) {
|
||||
// switch off those in the current set not in the new set
|
||||
for ( Screen screen : current ) {
|
||||
boolean disable = true;
|
||||
for ( Screen screen1 : screens ) {
|
||||
if ( screen1.name.equals(screen.name) ) {
|
||||
disable = false;
|
||||
break;
|
||||
}
|
||||
// switch off those in the current set not in the new set
|
||||
for ( Screen screen : current ) {
|
||||
boolean found = false;
|
||||
for ( Screen screen1 : screens ) {
|
||||
if ( screen1.name.equals(screen.name) ) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( disable ) {
|
||||
cmd.add("--output");
|
||||
cmd.add(screen.name);
|
||||
cmd.add("--off");
|
||||
}
|
||||
if ( !found ) {
|
||||
cmd.add("--output");
|
||||
cmd.add(screen.name);
|
||||
cmd.add("--off");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -206,196 +154,151 @@ public class XRandR {
|
|||
for ( Screen screen : screens )
|
||||
screen.getArgs(cmd);
|
||||
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(cmd.toArray(new String[cmd.size()]));
|
||||
try
|
||||
{
|
||||
// ProcessBuilder pb = new ProcessBuilder( cmd );
|
||||
// pb.redirectErrorStream();
|
||||
// Process p = pb.start();
|
||||
Process p =
|
||||
Runtime.getRuntime().exec( cmd.toArray( new String[ cmd.size() ] ) );
|
||||
// no output is expected, but check anyway
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) );
|
||||
String line;
|
||||
while ( (line = br.readLine()) != null ) {
|
||||
LWJGLUtil.log("Unexpected output from xrandr process: " + line);
|
||||
while( ( line = br.readLine() ) != null )
|
||||
{
|
||||
LWJGLUtil.log( "Unexpected output from xrandr process: " + line );
|
||||
}
|
||||
current = screens;
|
||||
} catch (IOException e) {
|
||||
LWJGLUtil.log("XRandR exception in setConfiguration(): " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the current configuration for all connected display devices.
|
||||
* This configuration can be restored on exit/crash by calling
|
||||
* restoreConfiguration()
|
||||
*/
|
||||
private static void saveConfiguration() {
|
||||
populate();
|
||||
savedConfiguration = current.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Restores the configuration for all connected display devices.
|
||||
* Used on exit or in case of a crash to reset all devices.
|
||||
*/
|
||||
public static void restoreConfiguration() {
|
||||
if ( savedConfiguration != null ) {
|
||||
setConfiguration(true, savedConfiguration);
|
||||
catch( IOException e )
|
||||
{
|
||||
LWJGLUtil.log( "XRandR exception in setConfiguration(): " + e.getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name of connected screens, or an empty array if
|
||||
* xrandr is not supported
|
||||
* xrandr is not supported
|
||||
*/
|
||||
public static String[] getScreenNames() {
|
||||
public static String[] getScreenNames()
|
||||
{
|
||||
populate();
|
||||
return screens.keySet().toArray(new String[screens.size()]);
|
||||
return screens.keySet().toArray( new String[ screens.size() ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*
|
||||
* @return the possible resolutions of the named screen, or
|
||||
* <code>null</code> if there is no such screen
|
||||
* <code>null</code> if there is no such screen
|
||||
*/
|
||||
public static Screen[] getResolutions(String name) {
|
||||
public static Screen[] getResolutions( String name )
|
||||
{
|
||||
populate();
|
||||
// clone the array to prevent held copies being altered
|
||||
return screens.get(name).clone();
|
||||
}
|
||||
|
||||
private static final Pattern SCREEN_HEADER_PATTERN = Pattern.compile("^(\\d+)x(\\d+)[+](\\d+)[+](\\d+)$");
|
||||
private static final Pattern SCREEN_MODELINE_PATTERN = Pattern.compile("^(\\d+)x(\\d+)$");
|
||||
private static final Pattern FREQ_PATTERN = Pattern.compile("^(\\d+[.]\\d+)(?:\\s*[*])?(?:\\s*[+])?$");
|
||||
private static final Pattern SCREEN_PATTERN1 =
|
||||
Pattern.compile( "^(\\d+)x(\\d+)\\+(\\d+)\\+(\\d+)$" );
|
||||
|
||||
private static final Pattern SCREEN_PATTERN2 = Pattern.compile( "^(\\d+)x(\\d+)$" );
|
||||
|
||||
/**
|
||||
* Parses a screen configuration and adds it to one of the lists if valid.
|
||||
* Parses a screen configuration and adds it to the list if it's
|
||||
* valid.
|
||||
*
|
||||
* @param allModes the list to add the Screen to if it's valid
|
||||
* @param current the list to add the current screen config to
|
||||
* @param name the name of this screen
|
||||
* @param modeLine config string
|
||||
* @param screenPosition position of this screen
|
||||
* @param list
|
||||
* the list to add the Screen to if it's valid
|
||||
* @param name
|
||||
* the name of this screen
|
||||
* @param what
|
||||
* config string, format either widthxheight or
|
||||
* widthxheight+xPos+yPos
|
||||
*/
|
||||
private static void parseScreenModeline(List<Screen> allModes, List<Screen> current, String name, int width, int height, String[] modeLine, int[] screenPosition) {
|
||||
for ( int i = 1; i < modeLine.length; i++ ) {
|
||||
String freqS = modeLine[i];
|
||||
if ( "+".equals(freqS) ) {
|
||||
// previous rate was the "preferred" refresh rate
|
||||
// no way to get this info to the application, so ignore it
|
||||
continue;
|
||||
}
|
||||
|
||||
Matcher m = FREQ_PATTERN.matcher(freqS);
|
||||
if ( !m.matches() ) {
|
||||
LWJGLUtil.log("Frequency match failed: " + Arrays.toString(modeLine));
|
||||
private static void parseScreen( List<Screen> list, String name, String what )
|
||||
{
|
||||
Matcher m = SCREEN_PATTERN1.matcher( what );
|
||||
if( !m.matches() )
|
||||
{
|
||||
m = SCREEN_PATTERN2.matcher( what );
|
||||
if( !m.matches() )
|
||||
{
|
||||
LWJGLUtil.log( "Did not match: " + what );
|
||||
return;
|
||||
}
|
||||
|
||||
String freq = m.group(1);
|
||||
|
||||
Screen s = new Screen(name, width, height, freq, 0, 0);
|
||||
if ( freqS.contains("*") ) {
|
||||
// current mode, save to current list with screen position
|
||||
current.add(new Screen(name, width, height, freq, screenPosition[0], screenPosition[1]));
|
||||
// make sure the current mode is always first
|
||||
allModes.add(0, s);
|
||||
} else {
|
||||
// always add to List of all modes without screen position
|
||||
allModes.add(s);
|
||||
}
|
||||
}
|
||||
int width = Integer.parseInt( m.group( 1 ) );
|
||||
int height = Integer.parseInt( m.group( 2 ) );
|
||||
int xpos, ypos;
|
||||
if( m.groupCount() > 3 )
|
||||
{
|
||||
xpos = Integer.parseInt( m.group( 3 ) );
|
||||
ypos = Integer.parseInt( m.group( 4 ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
xpos = 0;
|
||||
ypos = 0;
|
||||
}
|
||||
list.add( new Screen( name, width, height, xpos, ypos ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses a screen configuration header and extracts information about the position of the screen.
|
||||
*
|
||||
* @param screenPosition the int-array to write the position into
|
||||
* @param resPos String containing resolution and position, from xrandr
|
||||
*/
|
||||
private static void parseScreenHeader(int[] screenPosition, String resPos) {
|
||||
Matcher m = SCREEN_HEADER_PATTERN.matcher(resPos);
|
||||
if ( !m.matches() ) {
|
||||
// screen not active!
|
||||
screenPosition[0] = 0;
|
||||
screenPosition[1] = 0;
|
||||
return;
|
||||
}
|
||||
screenPosition[0] = Integer.parseInt(m.group(3));
|
||||
screenPosition[1] = Integer.parseInt(m.group(4));
|
||||
}
|
||||
|
||||
static Screen DisplayModetoScreen(DisplayMode mode) {
|
||||
populate();
|
||||
Screen primary = findPrimary(current);
|
||||
return new Screen(primary.name, mode.getWidth(), mode.getHeight(), Integer.toString(mode.getFrequency()), primary.xPos, primary.yPos);
|
||||
}
|
||||
|
||||
static DisplayMode ScreentoDisplayMode(Screen... screens) {
|
||||
populate();
|
||||
Screen primary = findPrimary(screens);
|
||||
return new DisplayMode(primary.width, primary.height, 24, primary.freq);
|
||||
}
|
||||
|
||||
private static Screen findPrimary(Screen... screens) {
|
||||
for ( Screen screen : screens ) {
|
||||
if ( screen.name.equals(primaryScreenIdentifier) ) {
|
||||
return screen;
|
||||
}
|
||||
}
|
||||
// fallback
|
||||
return screens[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Encapsulates the configuration of a monitor.
|
||||
* Resolution and freq are fixed, position is mutable
|
||||
* Encapsulates the configuration of a monitor. Resolution is
|
||||
* fixed, position is mutable
|
||||
*
|
||||
* @author ryanm
|
||||
*/
|
||||
public static class Screen implements Cloneable {
|
||||
/** Name for this output */
|
||||
public static class Screen implements Cloneable
|
||||
{
|
||||
/**
|
||||
* Name for this output
|
||||
*/
|
||||
public final String name;
|
||||
|
||||
/** Width in pixels */
|
||||
/**
|
||||
* Width in pixels
|
||||
*/
|
||||
public final int width;
|
||||
|
||||
/** Height in pixels */
|
||||
/**
|
||||
* Height in pixels
|
||||
*/
|
||||
public final int height;
|
||||
|
||||
/** Frequency in Hz */
|
||||
public final int freq;
|
||||
|
||||
/** Frequency in Hz, in the original decimal format */
|
||||
final String freqOriginal;
|
||||
|
||||
/** Position on the x-axis, in pixels */
|
||||
/**
|
||||
* Position on the x-axis, in pixels
|
||||
*/
|
||||
public int xPos;
|
||||
|
||||
/** Position on the y-axis, in pixels */
|
||||
/**
|
||||
* Position on the y-axis, in pixels
|
||||
*/
|
||||
public int yPos;
|
||||
|
||||
Screen(String name, int width, int height, String freq, int xPos, int yPos) {
|
||||
private Screen( String name, int width, int height, int xPos, int yPos )
|
||||
{
|
||||
this.name = name;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.freq = (int)Float.parseFloat(freq);
|
||||
this.freqOriginal = freq;
|
||||
this.xPos = xPos;
|
||||
this.yPos = yPos;
|
||||
}
|
||||
|
||||
private void getArgs(List<String> argList) {
|
||||
argList.add("--output");
|
||||
argList.add(name);
|
||||
argList.add("--mode");
|
||||
argList.add(width + "x" + height);
|
||||
argList.add("--rate");
|
||||
argList.add(freqOriginal);
|
||||
argList.add("--pos");
|
||||
argList.add(xPos + "x" + yPos);
|
||||
private void getArgs( List<String> argList )
|
||||
{
|
||||
argList.add( "--output" );
|
||||
argList.add( name );
|
||||
argList.add( "--mode" );
|
||||
argList.add( width + "x" + height );
|
||||
argList.add( "--pos" );
|
||||
argList.add( xPos + "x" + yPos );
|
||||
}
|
||||
|
||||
//@Override
|
||||
public String toString() {
|
||||
return name + " " + width + "x" + height + " @ " + xPos + "x" + yPos + " with " + freqOriginal + "Hz";
|
||||
public String toString()
|
||||
{
|
||||
return name + " " + width + "x" + height + " @ " + xPos + "x" + yPos;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -57,7 +57,11 @@ class GLChecks {
|
|||
/** Static methods only! */
|
||||
private GLChecks() {
|
||||
}
|
||||
|
||||
|
||||
static int getBufferObjectSize(int buffer_enum) {
|
||||
return glGetBufferParameteri(buffer_enum, GLES20.GL_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
/** Helper method to ensure that array buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */
|
||||
static void ensureArrayVBOdisabled() {
|
||||
if ( LWJGLUtil.CHECKS && StateTracker.getTracker().arrayBuffer != 0 )
|
||||
|
|
|
|||
|
|
@ -74,26 +74,18 @@ public final class VersionTest {
|
|||
|
||||
if ( 2 < args.length ) {
|
||||
for ( int i = 2; i < args.length; i++ ) {
|
||||
if ( "core".equalsIgnoreCase(args[i]) )
|
||||
if ( Pattern.matches("[0-9]+", args[i]) )
|
||||
ca = ca.withLayer(Integer.parseInt(args[i]));
|
||||
else if ( "debug".equalsIgnoreCase(args[i]) )
|
||||
ca = ca.withDebug(true);
|
||||
else if ( "fc".equalsIgnoreCase(args[i]) )
|
||||
ca = ca.withForwardCompatible(true);
|
||||
else if ( "core".equalsIgnoreCase(args[i]) )
|
||||
ca = ca.withProfileCore(true);
|
||||
else if ( "compatibility".equalsIgnoreCase(args[i]) )
|
||||
ca = ca.withProfileCompatibility(true);
|
||||
else if ( "es".equalsIgnoreCase(args[i]) )
|
||||
ca = ca.withProfileES(true);
|
||||
else if ( "debug".equalsIgnoreCase(args[i]) )
|
||||
ca = ca.withDebug(true);
|
||||
else if ( "fc".equalsIgnoreCase(args[i]) )
|
||||
ca = ca.withForwardCompatible(true);
|
||||
else if ( "robust".equalsIgnoreCase(args[i]) )
|
||||
ca = ca.withRobustAccess(true);
|
||||
else if ( "reset_isolation".equalsIgnoreCase(args[i]) )
|
||||
ca = ca.withContextResetIsolation(true);
|
||||
else if ( "reset_lose".equalsIgnoreCase(args[i]) )
|
||||
ca = ca.withResetNotificationStrategy(ContextAttribs.LOSE_CONTEXT_ON_RESET_ARB);
|
||||
else if ( "release_none".equalsIgnoreCase(args[i]) )
|
||||
ca = ca.withContextReleaseBehavior(ContextAttribs.CONTEXT_RELEASE_BEHAVIOR_NONE_ARB);
|
||||
else if ( Pattern.matches("[0-9]+", args[i]) )
|
||||
ca = ca.withLayer(Integer.parseInt(args[i]));
|
||||
else
|
||||
argsError("Unknown argument: \'" + args[i] + "\'");
|
||||
}
|
||||
|
|
@ -244,19 +236,15 @@ public final class VersionTest {
|
|||
|
||||
private static void argsError(final String msg) {
|
||||
System.out.println("\nInvalid arguments error: " + msg);
|
||||
System.out.println("\nUsage: VersionTest <majorVersion> <minorVersion> {'core'|'compatibility'|'es', 'debug', 'fc', 'robust', 'reset_isolation', 'reset_lose', 'release_none', <layer>}:\n");
|
||||
System.out.println("<majorVersion>\t- Major OpenGL version.");
|
||||
System.out.println("<majorVersion>\t- Minor OpenGL version.");
|
||||
System.out.println("\nUsage: VersionTest <majorVersion> <minorVersion> {'core'|'compatibility', <layer>, 'debug', 'fc'}:\n");
|
||||
System.out.println("majorVersion\t- Major OpenGL version.");
|
||||
System.out.println("majorVersion\t- Minor OpenGL version.");
|
||||
System.out.println("core\t- Sets the Core Profile bit (optional, requires 3.2+).");
|
||||
System.out.println("compatibility\t- Sets the Compatibility Profile bit (optional, requires 3.2+).");
|
||||
System.out.println("es\t- Sets the OpenGL ES Profile bit (optional, requires 2.0).");
|
||||
System.out.println("ws\t- Sets the OpenGL ES Profile bit (optional, requires 2.0).");
|
||||
System.out.println("layer\t- Layer plane (optional).");
|
||||
System.out.println("debug\t- Enables debug mode (optional).");
|
||||
System.out.println("fc\t- Enables forward compatibility mode (optional, requires 3.0+).");
|
||||
System.out.println("robust\t- Enables robust access (optional).");
|
||||
System.out.println("reset_isolation\t- Enables reset isolation (optional).");
|
||||
System.out.println("reset_lose\t- Enables lose context on reset (optional).");
|
||||
System.out.println("release_none\t- Enables release behavior = none (optional).");
|
||||
System.out.println("<layer>\t- Layer plane (optional).");
|
||||
|
||||
cleanup();
|
||||
System.exit(-1);
|
||||
|
|
|
|||
|
|
@ -174,6 +174,7 @@ public final class SpriteShootout {
|
|||
// Setup geometry
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
Util.checkGLError();
|
||||
}
|
||||
|
|
@ -415,6 +416,8 @@ public final class SpriteShootout {
|
|||
glUniform1i(glGetUniformLocation(progID, "COLOR_MAP"), 0);
|
||||
|
||||
updateBallSize();
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
}
|
||||
|
||||
public void updateBallSize() {
|
||||
|
|
|
|||
|
|
@ -172,6 +172,7 @@ public final class SpriteShootout2P {
|
|||
// Setup geometry
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
Util.checkGLError();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -181,6 +181,7 @@ public final class SpriteShootoutMapped {
|
|||
// Setup geometry
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
Util.checkGLError();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,8 +31,6 @@
|
|||
*/
|
||||
package org.lwjgl.util.applet;
|
||||
|
||||
import org.lwjgl.LWJGLUtil;
|
||||
|
||||
import java.applet.Applet;
|
||||
import java.applet.AppletStub;
|
||||
import java.awt.BorderLayout;
|
||||
|
|
@ -85,6 +83,7 @@ import java.util.concurrent.Future;
|
|||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.jar.JarOutputStream;
|
||||
import java.util.jar.Pack200;
|
||||
import java.util.zip.CRC32;
|
||||
import java.util.zip.CheckedInputStream;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
|
@ -112,7 +111,6 @@ import java.util.zip.ZipFile;
|
|||
* <li>al_mac - [String] Jar containing native files for mac.</li>
|
||||
* <li>al_solaris - [String] Jar containing native files for solaris.</li>
|
||||
* <li>al_freebsd - [String] Jar containing native files for freebsd.</li>
|
||||
* <li>al_openbsd - [String] Jar containing native files for openbsd.</li>
|
||||
* </ul>
|
||||
* </p>
|
||||
* <p>
|
||||
|
|
@ -375,12 +373,12 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
|
|||
}
|
||||
|
||||
// check pack200 support
|
||||
// try {
|
||||
// java.util.jar.Pack200.class.getSimpleName();
|
||||
// pack200Supported = true;
|
||||
// } catch (Throwable e) {
|
||||
// /* no pack200 support */
|
||||
// }
|
||||
try {
|
||||
java.util.jar.Pack200.class.getSimpleName();
|
||||
pack200Supported = true;
|
||||
} catch (Throwable e) {
|
||||
/* no pack200 support */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -777,8 +775,6 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
|
|||
nativeJarList = getParameter("al_solaris");
|
||||
} else if (osName.startsWith("FreeBSD")) {
|
||||
nativeJarList = getParameter("al_freebsd");
|
||||
} else if (osName.startsWith("OpenBSD")) {
|
||||
nativeJarList = getParameter("al_openbsd");
|
||||
} else {
|
||||
fatalErrorOccured("OS (" + osName + ") not supported", null);
|
||||
return;
|
||||
|
|
@ -1220,7 +1216,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
|
|||
|
||||
// allow non lwjgl native to be found from cache directory
|
||||
protected String findLibrary (String libname) {
|
||||
String libPath = path + "natives" + File.separator + LWJGLUtil.mapLibraryName(libname);
|
||||
String libPath = path + "natives" + File.separator + System.mapLibraryName(libname);
|
||||
|
||||
if (new File(libPath).exists()) {
|
||||
return libPath;
|
||||
|
|
@ -1679,21 +1675,20 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
|
|||
* @throws Exception if any errors occur
|
||||
*/
|
||||
protected void extractPack(String in, String out) throws Exception {
|
||||
throw new UnsupportedOperationException();
|
||||
// File f = new File(in);
|
||||
// FileOutputStream fostream = new FileOutputStream(out);
|
||||
// JarOutputStream jostream = new JarOutputStream(fostream);
|
||||
File f = new File(in);
|
||||
FileOutputStream fostream = new FileOutputStream(out);
|
||||
JarOutputStream jostream = new JarOutputStream(fostream);
|
||||
|
||||
// try {
|
||||
// Pack200.Unpacker unpacker = Pack200.newUnpacker();
|
||||
// unpacker.unpack(f, jostream);
|
||||
// } finally {
|
||||
// jostream.close();
|
||||
// fostream.close();
|
||||
// }
|
||||
try {
|
||||
Pack200.Unpacker unpacker = Pack200.newUnpacker();
|
||||
unpacker.unpack(f, jostream);
|
||||
} finally {
|
||||
jostream.close();
|
||||
fostream.close();
|
||||
}
|
||||
|
||||
// // delete pack file as its no longer needed
|
||||
// f.delete();
|
||||
// delete pack file as its no longer needed
|
||||
f.delete();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1872,8 +1867,8 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
|
|||
/**
|
||||
* Compare two certificate chains to see if they match
|
||||
*
|
||||
* @param certs1 first chain of certificates
|
||||
* @param certs2 second chain of certificates
|
||||
* @param cert1 first chain of certificates
|
||||
* @param cert2 second chain of certificates
|
||||
*
|
||||
* @return true if the certificate chains are the same
|
||||
*/
|
||||
|
|
@ -2229,7 +2224,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
|
|||
|
||||
/**
|
||||
* set the state of applet loader
|
||||
* @param state new state of applet loader
|
||||
* @param new state of applet loader
|
||||
* */
|
||||
protected void setState(int state) {
|
||||
this.state = state;
|
||||
|
|
@ -2261,4 +2256,4 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
|
|||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -46,7 +46,4 @@ public @interface Extension {
|
|||
String className() default "";
|
||||
boolean isFinal() default true;
|
||||
String postfix();
|
||||
|
||||
/** The extension name as it appears in the extension string. The default is the API prefix followed by the interface name, converted to lower-case. */
|
||||
String nativeName() default "";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,23 +29,22 @@
|
|||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.lwjgl.util.generator;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.lang.model.element.Modifier;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.type.PrimitiveType;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
|
||||
import com.sun.mirror.declaration.FieldDeclaration;
|
||||
import com.sun.mirror.declaration.Modifier;
|
||||
import com.sun.mirror.type.PrimitiveType;
|
||||
import com.sun.mirror.type.TypeMirror;
|
||||
|
||||
public class FieldsGenerator {
|
||||
|
||||
private static void validateField(VariableElement field) {
|
||||
private static void validateField(FieldDeclaration field) {
|
||||
// Check if field is "public static final"
|
||||
Set<Modifier> modifiers = field.getModifiers();
|
||||
Collection<Modifier> modifiers = field.getModifiers();
|
||||
if ( modifiers.size() != 3
|
||||
|| !modifiers.contains(Modifier.PUBLIC)
|
||||
|| !modifiers.contains(Modifier.STATIC)
|
||||
|
|
@ -54,17 +53,17 @@ public class FieldsGenerator {
|
|||
}
|
||||
|
||||
// Check suported types (int, long, float, String)
|
||||
TypeMirror field_type = field.asType();
|
||||
if ( "java.lang.String".equals(field_type.toString()) ) {
|
||||
} else if ( field_type instanceof PrimitiveType ) {
|
||||
TypeMirror field_type = field.getType();
|
||||
if ( field_type instanceof PrimitiveType ) {
|
||||
PrimitiveType field_type_prim = (PrimitiveType)field_type;
|
||||
TypeKind field_kind = field_type_prim.getKind();
|
||||
if ( field_kind != TypeKind.INT
|
||||
&& field_kind != TypeKind.LONG
|
||||
&& field_kind != TypeKind.FLOAT
|
||||
&& field_kind != TypeKind.BYTE ) {
|
||||
throw new RuntimeException("Field " + field.getSimpleName() + " is not of type 'int', 'long', 'float' or 'byte' " + field_kind.toString());
|
||||
PrimitiveType.Kind field_kind = field_type_prim.getKind();
|
||||
if ( field_kind != PrimitiveType.Kind.INT
|
||||
&& field_kind != PrimitiveType.Kind.LONG
|
||||
&& field_kind != PrimitiveType.Kind.FLOAT
|
||||
&& field_kind != PrimitiveType.Kind.BYTE ) {
|
||||
throw new RuntimeException("Field " + field.getSimpleName() + " is not of type 'int', 'long' or 'float'");
|
||||
}
|
||||
} else if ( "java.lang.String".equals(field_type.toString()) ) {
|
||||
} else {
|
||||
throw new RuntimeException("Field " + field.getSimpleName() + " is not a primitive type or String");
|
||||
}
|
||||
|
|
@ -75,7 +74,7 @@ public class FieldsGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
private static void generateField(PrintWriter writer, VariableElement field, VariableElement prev_field, ProcessingEnvironment env) {
|
||||
private static void generateField(PrintWriter writer, FieldDeclaration field, FieldDeclaration prev_field) {
|
||||
validateField(field);
|
||||
|
||||
Object value = field.getConstantValue();
|
||||
|
|
@ -95,33 +94,31 @@ public class FieldsGenerator {
|
|||
throw new RuntimeException("Field is of unexpected type. This means there is a bug in validateField().");
|
||||
}
|
||||
|
||||
boolean hadDoc = prev_field != null && env.getElementUtils().getDocComment(prev_field) != null;
|
||||
boolean hasDoc = env.getElementUtils().getDocComment(field) != null;
|
||||
boolean newBatch = prev_field == null || !prev_field.asType().equals(field.asType()) || (!hadDoc && env.getElementUtils().getDocComment(field) != null) || (hadDoc && hasDoc && !env.getElementUtils().getDocComment(prev_field).equals(env.getElementUtils().getDocComment(field)));
|
||||
boolean hadDoc = prev_field != null && prev_field.getDocComment() != null;
|
||||
boolean hasDoc = field.getDocComment() != null;
|
||||
boolean newBatch = prev_field == null || !prev_field.getType().equals(field.getType()) || (!hadDoc && field.getDocComment() != null) || (hadDoc && hasDoc && !prev_field.getDocComment().equals(field.getDocComment()));
|
||||
|
||||
// Print field declaration
|
||||
if ( newBatch ) {
|
||||
if ( prev_field != null ) {
|
||||
if ( prev_field != null )
|
||||
writer.println(";\n");
|
||||
}
|
||||
|
||||
Utils.printDocComment(writer, field, env);
|
||||
writer.print("\tpublic static final " + field.asType().toString() + " " + field.getSimpleName() + " = " + field_value_string);
|
||||
} else {
|
||||
Utils.printDocComment(writer, field);
|
||||
writer.print("\tpublic static final " + field.getType().toString() + " " + field.getSimpleName() + " = " + field_value_string);
|
||||
} else
|
||||
writer.print(",\n\t\t" + field.getSimpleName() + " = " + field_value_string);
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateFields(ProcessingEnvironment env, PrintWriter writer, Collection<? extends VariableElement> fields) {
|
||||
public static void generateFields(PrintWriter writer, Collection<FieldDeclaration> fields) {
|
||||
if ( 0 < fields.size() ) {
|
||||
writer.println();
|
||||
VariableElement prev_field = null;
|
||||
for ( VariableElement field : fields ) {
|
||||
generateField(writer, field, prev_field, env);
|
||||
FieldDeclaration prev_field = null;
|
||||
for ( FieldDeclaration field : fields ) {
|
||||
generateField(writer, field, prev_field);
|
||||
prev_field = field;
|
||||
}
|
||||
writer.println(";");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,140 +0,0 @@
|
|||
/*
|
||||
* 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
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.lwjgl.util.generator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.annotation.processing.*;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.util.ElementFilter;
|
||||
import javax.tools.Diagnostic;
|
||||
|
||||
/**
|
||||
* Generator tool for creating the java classes and native code from an
|
||||
* annotated template java interface.
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$ $Id$
|
||||
*/
|
||||
@SupportedAnnotationTypes({ "*" })
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_7)
|
||||
@SupportedOptions({ "binpath", "typemap", "generatechecks", "contextspecific" })
|
||||
public class GeneratorProcessor extends AbstractProcessor {
|
||||
|
||||
private static boolean first_round = true;
|
||||
|
||||
@Override
|
||||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||
if ( roundEnv.processingOver() || !first_round ) {
|
||||
System.exit(0);
|
||||
return true;
|
||||
}
|
||||
Map<String, String> options = processingEnv.getOptions();
|
||||
String typemap_classname = options.get("typemap");
|
||||
String bin_path = options.get("binpath");
|
||||
boolean generate_error_checks = options.containsKey("generatechecks");
|
||||
boolean context_specific = options.containsKey("contextspecific");
|
||||
if ( bin_path == null ) {
|
||||
throw new RuntimeException("No path specified for the bin directory with -Abinpath=<path>");
|
||||
}
|
||||
|
||||
if ( typemap_classname == null ) {
|
||||
throw new RuntimeException("No TypeMap class name specified with -Atypemap=<class-name>");
|
||||
}
|
||||
|
||||
Element lastFile = null;
|
||||
try {
|
||||
long generatorLM = getGeneratorLastModified(bin_path);
|
||||
TypeMap type_map = (TypeMap)(Class.forName(typemap_classname).newInstance());
|
||||
for ( Iterator<TypeElement> it = ElementFilter.typesIn(roundEnv.getRootElements()).iterator(); it.hasNext(); ) {
|
||||
lastFile = it.next();
|
||||
lastFile.accept(new GeneratorVisitor(processingEnv, type_map, generate_error_checks, context_specific, generatorLM), null);
|
||||
}
|
||||
first_round = false;
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
if ( lastFile == null ) {
|
||||
throw new RuntimeException(e);
|
||||
} else {
|
||||
throw new RuntimeException("\n-- Failed to process template: " + lastFile.asType().toString() + " --", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the time of the latest change on the Generator classes.
|
||||
*
|
||||
* @return time of the latest change
|
||||
*/
|
||||
private static long getGeneratorLastModified(final String bin_path) {
|
||||
long lastModified = getDirectoryLastModified(bin_path, "/org/lwjgl/util/generator");
|
||||
lastModified = Math.max(lastModified, getDirectoryLastModified(bin_path, "/org/lwjgl/util/generator/openal"));
|
||||
lastModified = Math.max(lastModified, getDirectoryLastModified(bin_path, "/org/lwjgl/util/generator/opengl"));
|
||||
lastModified = Math.max(lastModified, getDirectoryLastModified(bin_path, "/org/lwjgl/util/generator/opencl"));
|
||||
|
||||
return lastModified;
|
||||
}
|
||||
|
||||
private static long getDirectoryLastModified(final String bin_path, final String path) {
|
||||
final File pck = new File(bin_path + path);
|
||||
if ( !pck.exists() || !pck.isDirectory() ) {
|
||||
return Long.MAX_VALUE;
|
||||
}
|
||||
|
||||
final File[] classes = pck.listFiles(new FileFilter() {
|
||||
public boolean accept(final File pathname) {
|
||||
return pathname.isFile() && pathname.getName().endsWith(".class");
|
||||
}
|
||||
});
|
||||
|
||||
if ( classes == null || classes.length == 0 ) {
|
||||
return Long.MAX_VALUE;
|
||||
}
|
||||
|
||||
long lastModified = 0;
|
||||
|
||||
for ( File clazz : classes ) {
|
||||
long lm = clazz.lastModified();
|
||||
if ( lastModified < lm ) {
|
||||
lastModified = lm;
|
||||
}
|
||||
}
|
||||
|
||||
return lastModified;
|
||||
}
|
||||
|
||||
}
|
||||
176
src/java/org/lwjgl/util/generator/GeneratorProcessorFactory.java
Normal file
176
src/java/org/lwjgl/util/generator/GeneratorProcessorFactory.java
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
/*
|
||||
* 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
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.lwjgl.util.generator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileFilter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sun.mirror.apt.*;
|
||||
import com.sun.mirror.declaration.AnnotationTypeDeclaration;
|
||||
import com.sun.mirror.declaration.TypeDeclaration;
|
||||
|
||||
import static com.sun.mirror.util.DeclarationVisitors.*;
|
||||
import static java.util.Collections.*;
|
||||
|
||||
/**
|
||||
* Generator tool for creating the java classes and native code
|
||||
* from an annotated template java interface.
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
public class GeneratorProcessorFactory implements AnnotationProcessorFactory, RoundCompleteListener {
|
||||
|
||||
private static boolean first_round = true;
|
||||
|
||||
// Process any set of annotations
|
||||
private static final Collection<String> supportedAnnotations =
|
||||
unmodifiableCollection(Arrays.asList("*"));
|
||||
|
||||
private static final Collection<String> supportedOptions =
|
||||
unmodifiableCollection(Arrays.asList("-Atypemap", "-Ageneratechecks", "-Acontextspecific"));
|
||||
|
||||
public Collection<String> supportedAnnotationTypes() {
|
||||
return supportedAnnotations;
|
||||
}
|
||||
|
||||
public Collection<String> supportedOptions() {
|
||||
return supportedOptions;
|
||||
}
|
||||
|
||||
public void roundComplete(RoundCompleteEvent event) {
|
||||
first_round = false;
|
||||
}
|
||||
|
||||
public AnnotationProcessor getProcessorFor(Set<AnnotationTypeDeclaration> atds, AnnotationProcessorEnvironment env) {
|
||||
// Only process the initial types, not the generated ones
|
||||
if ( first_round ) {
|
||||
env.addListener(this);
|
||||
return new GeneratorProcessor(env);
|
||||
} else
|
||||
return AnnotationProcessors.NO_OP;
|
||||
}
|
||||
|
||||
private static class GeneratorProcessor implements AnnotationProcessor {
|
||||
|
||||
private final AnnotationProcessorEnvironment env;
|
||||
|
||||
GeneratorProcessor(AnnotationProcessorEnvironment env) {
|
||||
this.env = env;
|
||||
}
|
||||
|
||||
public void process() {
|
||||
Map<String, String> options = env.getOptions();
|
||||
String typemap_classname = null;
|
||||
String bin_path = null;
|
||||
boolean generate_error_checks = options.containsKey("-Ageneratechecks");
|
||||
boolean context_specific = options.containsKey("-Acontextspecific");
|
||||
for ( String k : options.keySet() ) {
|
||||
if ( !k.startsWith("-A") )
|
||||
continue;
|
||||
|
||||
int delimiter = k.indexOf('=');
|
||||
if ( delimiter != -1 ) {
|
||||
if ( k.startsWith("-Atypemap") ) {
|
||||
typemap_classname = k.substring(delimiter + 1);
|
||||
} else if ( k.startsWith("-Abinpath") ) {
|
||||
bin_path = k.substring(delimiter + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( typemap_classname == null )
|
||||
throw new RuntimeException("No TypeMap class name specified with -Atypemap=<class-name>");
|
||||
if ( bin_path == null )
|
||||
throw new RuntimeException("No path specified for the bin directory with -Abinpath=<path>");
|
||||
|
||||
TypeDeclaration lastFile = null;
|
||||
try {
|
||||
long generatorLM = getGeneratorLastModified(bin_path);
|
||||
TypeMap type_map = (TypeMap)(Class.forName(typemap_classname).newInstance());
|
||||
for ( TypeDeclaration typedecl : env.getSpecifiedTypeDeclarations() ) {
|
||||
lastFile = typedecl;
|
||||
typedecl.accept(getDeclarationScanner(new GeneratorVisitor(env, type_map, generate_error_checks, context_specific, generatorLM), NO_OP));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if ( lastFile == null )
|
||||
throw new RuntimeException(e);
|
||||
else
|
||||
throw new RuntimeException("\n-- Failed to process template: " + lastFile.getQualifiedName() + " --", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the time of the latest change on the Generator classes.
|
||||
*
|
||||
* @return time of the latest change
|
||||
*/
|
||||
private static long getGeneratorLastModified(final String bin_path) {
|
||||
long lastModified = getDirectoryLastModified(bin_path, "/org/lwjgl/util/generator");
|
||||
lastModified = Math.max(lastModified, getDirectoryLastModified(bin_path, "/org/lwjgl/util/generator/openal"));
|
||||
lastModified = Math.max(lastModified, getDirectoryLastModified(bin_path, "/org/lwjgl/util/generator/opengl"));
|
||||
lastModified = Math.max(lastModified, getDirectoryLastModified(bin_path, "/org/lwjgl/util/generator/opencl"));
|
||||
|
||||
return lastModified;
|
||||
}
|
||||
|
||||
private static long getDirectoryLastModified(final String bin_path, final String path) {
|
||||
final File pck = new File(bin_path + path);
|
||||
if ( !pck.exists() || !pck.isDirectory() )
|
||||
return Long.MAX_VALUE;
|
||||
|
||||
final File[] classes = pck.listFiles(new FileFilter() {
|
||||
public boolean accept(final File pathname) {
|
||||
return pathname.isFile() && pathname.getName().endsWith(".class");
|
||||
}
|
||||
});
|
||||
|
||||
if ( classes == null || classes.length == 0 )
|
||||
return Long.MAX_VALUE;
|
||||
|
||||
long lastModified = 0;
|
||||
|
||||
for ( File clazz : classes ) {
|
||||
long lm = clazz.lastModified();
|
||||
if ( lastModified < lm )
|
||||
lastModified = lm;
|
||||
}
|
||||
|
||||
return lastModified;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -29,43 +29,37 @@
|
|||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.lwjgl.util.generator;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import com.sun.mirror.apt.*;
|
||||
import com.sun.mirror.declaration.*;
|
||||
import com.sun.mirror.type.*;
|
||||
import com.sun.mirror.util.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.lang.model.element.*;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.lang.model.util.ElementKindVisitor6;
|
||||
import javax.tools.Diagnostic;
|
||||
import javax.tools.Diagnostic.Kind;
|
||||
import javax.tools.FileObject;
|
||||
import javax.tools.StandardLocation;
|
||||
import java.util.*;
|
||||
|
||||
import java.nio.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* Generator visitor for the generator tool
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$ $Id$
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
public class GeneratorVisitor extends ElementKindVisitor6<Void, Void> {
|
||||
public class GeneratorVisitor extends SimpleDeclarationVisitor {
|
||||
private final AnnotationProcessorEnvironment env;
|
||||
private final TypeMap type_map;
|
||||
private final boolean generate_error_checks;
|
||||
private final boolean context_specific;
|
||||
private final long generatorLM;
|
||||
|
||||
private final ProcessingEnvironment env;
|
||||
private final TypeMap type_map;
|
||||
private final boolean generate_error_checks;
|
||||
private final boolean context_specific;
|
||||
private final long generatorLM;
|
||||
|
||||
public GeneratorVisitor(ProcessingEnvironment env, TypeMap type_map, boolean generate_error_checks, boolean context_specific, long generatorLM) {
|
||||
public GeneratorVisitor(AnnotationProcessorEnvironment env, TypeMap type_map, boolean generate_error_checks, boolean context_specific, long generatorLM) {
|
||||
this.env = env;
|
||||
this.type_map = type_map;
|
||||
this.generate_error_checks = generate_error_checks;
|
||||
|
|
@ -73,166 +67,145 @@ public class GeneratorVisitor extends ElementKindVisitor6<Void, Void> {
|
|||
this.generatorLM = generatorLM;
|
||||
}
|
||||
|
||||
private void validateMethod(ExecutableElement method) {
|
||||
if ( method.isVarArgs() ) {
|
||||
private void validateMethod(MethodDeclaration method) {
|
||||
if (method.isVarArgs())
|
||||
throw new RuntimeException("Method " + method.getSimpleName() + " is variadic");
|
||||
}
|
||||
Collection<Modifier> modifiers = method.getModifiers();
|
||||
if ( !modifiers.contains(Modifier.PUBLIC) ) {
|
||||
if (!modifiers.contains(Modifier.PUBLIC))
|
||||
throw new RuntimeException("Method " + method.getSimpleName() + " is not public");
|
||||
}
|
||||
if ( method.getThrownTypes().size() > 0 ) {
|
||||
if (method.getThrownTypes().size() > 0)
|
||||
throw new RuntimeException("Method " + method.getSimpleName() + " throws checked exceptions");
|
||||
}
|
||||
validateParameters(method);
|
||||
StripPostfix strip_annotation = method.getAnnotation(StripPostfix.class);
|
||||
if ( strip_annotation != null && method.getAnnotation(Alternate.class) == null ) {
|
||||
if (strip_annotation != null && method.getAnnotation(Alternate.class) == null) {
|
||||
String postfix_param_name = strip_annotation.value();
|
||||
VariableElement postfix_param = Utils.findParameter(method, postfix_param_name);
|
||||
if ( Utils.isParameterMultiTyped(postfix_param) ) {
|
||||
ParameterDeclaration postfix_param = Utils.findParameter(method, postfix_param_name);
|
||||
if (Utils.isParameterMultiTyped(postfix_param))
|
||||
throw new RuntimeException("Postfix parameter can't be the same as a multityped parameter in method " + method);
|
||||
}
|
||||
if ( Utils.getNIOBufferType(postfix_param.asType()) == null ) {
|
||||
if (Utils.getNIOBufferType(postfix_param.getType()) == null)
|
||||
throw new RuntimeException("Postfix parameter type must be a nio Buffer");
|
||||
}
|
||||
}
|
||||
if ( Utils.getResultParameter(method) != null && !method.getReturnType().equals(env.getTypeUtils().getNoType(TypeKind.VOID)) ) {
|
||||
if (Utils.getResultParameter(method) != null && !method.getReturnType().equals(env.getTypeUtils().getVoidType()))
|
||||
throw new RuntimeException(method + " return type is not void but a parameter is annotated with Result");
|
||||
}
|
||||
if ( method.getAnnotation(CachedResult.class) != null ) {
|
||||
if ( Utils.getNIOBufferType(Utils.getMethodReturnType(method)) == null ) {
|
||||
if (method.getAnnotation(CachedResult.class) != null) {
|
||||
if (Utils.getNIOBufferType(Utils.getMethodReturnType(method)) == null)
|
||||
throw new RuntimeException(method + " return type is not a Buffer, but is annotated with CachedResult");
|
||||
}
|
||||
if ( method.getAnnotation(AutoSize.class) == null ) {
|
||||
if (method.getAnnotation(AutoSize.class) == null)
|
||||
throw new RuntimeException(method + " is annotated with CachedResult but misses an AutoSize annotation");
|
||||
}
|
||||
}
|
||||
validateTypes(method, method.getAnnotationMirrors(), method.getReturnType());
|
||||
}
|
||||
|
||||
private void validateType(ExecutableElement method, Class<? extends Annotation> annotation_type, Class type) {
|
||||
private void validateType(MethodDeclaration method, Class<?extends Annotation> annotation_type, Class type) {
|
||||
Class[] valid_types = type_map.getValidAnnotationTypes(type);
|
||||
for ( Class valid_type : valid_types ) {
|
||||
if ( valid_type.equals(annotation_type) ) {
|
||||
for ( Class valid_type : valid_types )
|
||||
if ( valid_type.equals(annotation_type) )
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException(type + " is annotated with invalid native type " + annotation_type
|
||||
+ " in method " + method);
|
||||
throw new RuntimeException(type + " is annotated with invalid native type " + annotation_type +
|
||||
" in method " + method);
|
||||
}
|
||||
|
||||
private void validateTypes(ExecutableElement method, List<? extends AnnotationMirror> annotations, TypeMirror type_mirror) {
|
||||
for ( AnnotationMirror annotation : annotations ) {
|
||||
private void validateTypes(MethodDeclaration method, Collection<AnnotationMirror> annotations, TypeMirror type_mirror) {
|
||||
for (AnnotationMirror annotation : annotations) {
|
||||
NativeType native_type_annotation = NativeTypeTranslator.getAnnotation(annotation, NativeType.class);
|
||||
if ( native_type_annotation != null ) {
|
||||
if (native_type_annotation != null) {
|
||||
Class<? extends Annotation> annotation_type = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
|
||||
Class type = Utils.getJavaType(type_mirror);
|
||||
if ( Buffer.class.equals(type) ) {
|
||||
if (Buffer.class.equals(type))
|
||||
continue;
|
||||
}
|
||||
validateType(method, annotation_type, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void validateParameters(ExecutableElement method) {
|
||||
for ( VariableElement param : method.getParameters() ) {
|
||||
validateTypes(method, param.getAnnotationMirrors(), param.asType());
|
||||
Class<?> param_type = Utils.getJavaType(param.asType());
|
||||
if ( Utils.getNIOBufferType(param.asType()) != null && param_type != CharSequence.class && param_type != CharSequence[].class ) {
|
||||
private void validateParameters(MethodDeclaration method) {
|
||||
for (ParameterDeclaration param : method.getParameters()) {
|
||||
validateTypes(method, param.getAnnotationMirrors(), param.getType());
|
||||
Class<?> param_type = Utils.getJavaType(param.getType());
|
||||
if (Utils.getNIOBufferType(param.getType()) != null && param_type != CharSequence.class && param_type != CharSequence[].class) {
|
||||
Check parameter_check_annotation = param.getAnnotation(Check.class);
|
||||
NullTerminated null_terminated_annotation = param.getAnnotation(NullTerminated.class);
|
||||
if ( parameter_check_annotation == null && null_terminated_annotation == null ) {
|
||||
if (parameter_check_annotation == null && null_terminated_annotation == null) {
|
||||
boolean found_auto_size_param = false;
|
||||
for ( VariableElement inner_param : method.getParameters() ) {
|
||||
for (ParameterDeclaration inner_param : method.getParameters()) {
|
||||
AutoSize auto_size_annotation = inner_param.getAnnotation(AutoSize.class);
|
||||
if ( auto_size_annotation != null
|
||||
&& auto_size_annotation.value().equals(param.getSimpleName().toString()) ) {
|
||||
if (auto_size_annotation != null &&
|
||||
auto_size_annotation.value().equals(param.getSimpleName())) {
|
||||
found_auto_size_param = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( !found_auto_size_param
|
||||
&& param.getAnnotation(Result.class) == null
|
||||
&& param.getAnnotation(Constant.class) == null
|
||||
&& !Utils.isReturnParameter(method, param) ) {
|
||||
throw new RuntimeException(param + " has no Check, Result nor Constant annotation, is not the return parameter and no other parameter has"
|
||||
+ " an @AutoSize annotation on it in method " + method);
|
||||
}
|
||||
if (!found_auto_size_param
|
||||
&& param.getAnnotation(Result.class) == null
|
||||
&& param.getAnnotation(Constant.class) == null
|
||||
&& !Utils.isReturnParameter(method, param)
|
||||
)
|
||||
throw new RuntimeException(param + " has no Check, Result nor Constant annotation, is not the return parameter and no other parameter has" +
|
||||
" an @AutoSize annotation on it in method " + method);
|
||||
}
|
||||
if ( param.getAnnotation(CachedReference.class) != null && param.getAnnotation(Result.class) != null ) {
|
||||
if (param.getAnnotation(CachedReference.class) != null && param.getAnnotation(Result.class) != null)
|
||||
throw new RuntimeException(param + " can't be annotated with both CachedReference and Result");
|
||||
}
|
||||
if ( param.getAnnotation(BufferObject.class) != null && param.getAnnotation(Result.class) != null ) {
|
||||
if (param.getAnnotation(BufferObject.class) != null && param.getAnnotation(Result.class) != null)
|
||||
throw new RuntimeException(param + " can't be annotated with both BufferObject and Result");
|
||||
}
|
||||
//if (param.getAnnotation(Constant.class) != null)
|
||||
//throw new RuntimeException("Buffer parameter " + param + " cannot be Constant");
|
||||
//throw new RuntimeException("Buffer parameter " + param + " cannot be Constant");
|
||||
} else {
|
||||
if ( param.getAnnotation(BufferObject.class) != null ) {
|
||||
if (param.getAnnotation(BufferObject.class) != null)
|
||||
throw new RuntimeException(param + " type is not a buffer, but annotated as a BufferObject");
|
||||
}
|
||||
if ( param.getAnnotation(CachedReference.class) != null ) {
|
||||
if (param.getAnnotation(CachedReference.class) != null)
|
||||
throw new RuntimeException(param + " type is not a buffer, but annotated as a CachedReference");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateMethodsNativePointers(PrintWriter writer, Collection<? extends ExecutableElement> methods) {
|
||||
for ( ExecutableElement method : methods ) {
|
||||
if ( method.getAnnotation(Alternate.class) == null ) {
|
||||
private static void generateMethodsNativePointers(PrintWriter writer, Collection<? extends MethodDeclaration> methods) {
|
||||
for (MethodDeclaration method : methods) {
|
||||
if ( method.getAnnotation(Alternate.class) == null )
|
||||
generateMethodNativePointers(writer, method);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateMethodNativePointers(PrintWriter writer, ExecutableElement method) {
|
||||
if ( method.getAnnotation(Extern.class) == null ) {
|
||||
private static void generateMethodNativePointers(PrintWriter writer, MethodDeclaration method) {
|
||||
if ( method.getAnnotation(Extern.class) == null )
|
||||
writer.print("static ");
|
||||
}
|
||||
writer.println(Utils.getTypedefName(method) + " " + method.getSimpleName() + ";");
|
||||
}
|
||||
|
||||
private void generateJavaSource(TypeElement d, PrintWriter java_writer) throws IOException {
|
||||
private void generateJavaSource(InterfaceDeclaration d, PrintWriter java_writer) throws IOException {
|
||||
java_writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
|
||||
java_writer.println();
|
||||
java_writer.println("package " + env.getElementUtils().getPackageOf(d).getQualifiedName().toString() + ";");
|
||||
java_writer.println("package " + d.getPackage().getQualifiedName() + ";");
|
||||
java_writer.println();
|
||||
java_writer.println("import org.lwjgl.*;");
|
||||
java_writer.println("import java.nio.*;");
|
||||
Imports imports = d.getAnnotation(Imports.class);
|
||||
if ( imports != null ) {
|
||||
for ( String i : imports.value() ) {
|
||||
for ( String i : imports.value() )
|
||||
java_writer.println("import " + i + ";");
|
||||
}
|
||||
}
|
||||
java_writer.println();
|
||||
Utils.printDocComment(java_writer, d, env);
|
||||
if ( d.getAnnotation(Private.class) == null ) {
|
||||
Utils.printDocComment(java_writer, d);
|
||||
if ( d.getAnnotation(Private.class) == null )
|
||||
java_writer.print("public ");
|
||||
}
|
||||
boolean is_final = Utils.isFinal(d);
|
||||
if ( is_final ) {
|
||||
if (is_final)
|
||||
java_writer.write("final ");
|
||||
}
|
||||
java_writer.print("class " + Utils.getSimpleClassName(d));
|
||||
List<? extends TypeMirror> super_interfaces = d.getInterfaces();
|
||||
if ( super_interfaces.size() > 1 ) {
|
||||
Collection<InterfaceType> super_interfaces = d.getSuperinterfaces();
|
||||
if (super_interfaces.size() > 1)
|
||||
throw new RuntimeException(d + " extends more than one interface");
|
||||
}
|
||||
if ( super_interfaces.size() == 1 ) {
|
||||
TypeMirror super_interface = super_interfaces.iterator().next();
|
||||
java_writer.print(" extends " + Utils.getSimpleClassName(env.getElementUtils().getTypeElement(super_interface.toString())));
|
||||
if (super_interfaces.size() == 1) {
|
||||
InterfaceDeclaration super_interface = super_interfaces.iterator().next().getDeclaration();
|
||||
java_writer.print(" extends " + Utils.getSimpleClassName(super_interface));
|
||||
}
|
||||
java_writer.println(" {");
|
||||
FieldsGenerator.generateFields(env, java_writer, Utils.getFields(d));
|
||||
FieldsGenerator.generateFields(java_writer, d.getFields());
|
||||
java_writer.println();
|
||||
if ( is_final ) {
|
||||
if (is_final) {
|
||||
// Write private constructor to avoid instantiation
|
||||
java_writer.println("\tprivate " + Utils.getSimpleClassName(d) + "() {}");
|
||||
}
|
||||
if ( Utils.getMethods(d).size() > 0 && !context_specific ) {
|
||||
if (d.getMethods().size() > 0 && !context_specific) {
|
||||
java_writer.println();
|
||||
java_writer.println("\tstatic native void " + Utils.STUB_INITIALIZER_NAME + "() throws LWJGLException;");
|
||||
}
|
||||
|
|
@ -240,29 +213,26 @@ public class GeneratorVisitor extends ElementKindVisitor6<Void, Void> {
|
|||
java_writer.println("}");
|
||||
java_writer.close();
|
||||
String qualified_interface_name = Utils.getQualifiedClassName(d);
|
||||
env.getMessager().printMessage(Diagnostic.Kind.NOTE, "Generated class " + qualified_interface_name);
|
||||
env.getMessager().printNotice("Generated class " + qualified_interface_name);
|
||||
}
|
||||
|
||||
private void generateNativeSource(TypeElement d) throws IOException {
|
||||
if ( d.getKind().equals(ElementKind.ANNOTATION_TYPE) ) {
|
||||
return;
|
||||
}
|
||||
private void generateNativeSource(InterfaceDeclaration d) throws IOException {
|
||||
String qualified_interface_name = Utils.getQualifiedClassName(d);
|
||||
String qualified_native_name = Utils.getNativeQualifiedName(qualified_interface_name) + ".c";
|
||||
PrintWriter native_writer = new PrintWriter(env.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "", qualified_native_name).openWriter());
|
||||
String qualified_native_name = Utils.getNativeQualifiedName(qualified_interface_name)+ ".c";
|
||||
PrintWriter native_writer = env.getFiler().createTextFile(Filer.Location.CLASS_TREE, "", new File(qualified_native_name), "UTF-8");
|
||||
native_writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
|
||||
native_writer.println();
|
||||
native_writer.println("#include <jni.h>");
|
||||
type_map.printNativeIncludes(native_writer);
|
||||
native_writer.println();
|
||||
TypedefsGenerator.generateNativeTypedefs(type_map, native_writer, Utils.getMethods(d));
|
||||
TypedefsGenerator.generateNativeTypedefs(type_map, native_writer, d.getMethods());
|
||||
native_writer.println();
|
||||
if ( !context_specific ) {
|
||||
generateMethodsNativePointers(native_writer, Utils.getMethods(d));
|
||||
if (!context_specific) {
|
||||
generateMethodsNativePointers(native_writer, d.getMethods());
|
||||
native_writer.println();
|
||||
}
|
||||
NativeMethodStubsGenerator.generateNativeMethodStubs(env, type_map, native_writer, d, generate_error_checks, context_specific);
|
||||
if ( !context_specific ) {
|
||||
if (!context_specific) {
|
||||
native_writer.print("JNIEXPORT void JNICALL " + Utils.getQualifiedNativeMethodName(qualified_interface_name, Utils.STUB_INITIALIZER_NAME));
|
||||
native_writer.println("(JNIEnv *env, jclass clazz) {");
|
||||
native_writer.println("\tJavaMethodAndExtFunction functions[] = {");
|
||||
|
|
@ -275,63 +245,84 @@ public class GeneratorVisitor extends ElementKindVisitor6<Void, Void> {
|
|||
native_writer.println("}");
|
||||
}
|
||||
native_writer.close();
|
||||
env.getMessager().printMessage(Kind.NOTE, "Generated C source " + qualified_interface_name);
|
||||
env.getMessager().printNotice("Generated C source " + qualified_interface_name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitTypeAsInterface(TypeElement e, Void p) {
|
||||
final File input = new File("src/templates/" + e.getQualifiedName().toString().replace('.', '/') + ".java");
|
||||
final File outputJava = new File("src/generated/" + env.getElementUtils().getPackageOf(e).getQualifiedName().toString().replace('.', '/'), Utils.getSimpleClassName(e) + ".java");
|
||||
public void visitInterfaceDeclaration(InterfaceDeclaration d) {
|
||||
final File input = d.getPosition().file();
|
||||
final File outputJava = new File(env.getOptions().get("-s") + '/' + d.getPackage().getQualifiedName().replace('.', '/'), Utils.getSimpleClassName(d) + ".java");
|
||||
|
||||
PrintWriter java_writer = null;
|
||||
|
||||
try {
|
||||
final Collection<? extends ExecutableElement> methods = Utils.getMethods(e);
|
||||
if ( methods.isEmpty() && Utils.getFields(e).isEmpty() ) {
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
final Collection<? extends MethodDeclaration> methods = d.getMethods();
|
||||
if ( methods.size() == 0 && d.getFields().size() == 0 )
|
||||
return;
|
||||
|
||||
// Skip this class if the output exists and the input has not been modified.
|
||||
if ( outputJava.exists() && Math.max(input.lastModified(), generatorLM) < outputJava.lastModified() )
|
||||
return DEFAULT_VALUE;
|
||||
return;
|
||||
|
||||
//env.getMessager().printMessage(Kind.NOTE, "methods count : " + Utils.getMethods(e).size() + " fields count : " + Utils.getFields(e).size(), e);
|
||||
for ( final ExecutableElement method : methods ) {
|
||||
for ( final MethodDeclaration method : methods )
|
||||
validateMethod(method);
|
||||
}
|
||||
|
||||
// TODO: Back-port LWJGL 3's generation file handling (generate in-memory and avoid touching files if nothing has changed)
|
||||
// java_writer = new PrintWriter(env.getFiler().createSourceFile(Utils.getQualifiedClassName(e), env.getElementUtils().getPackageOf(e)).openWriter());
|
||||
outputJava.getParentFile().mkdirs();
|
||||
outputJava.createNewFile();
|
||||
java_writer = new PrintWriter(outputJava);
|
||||
generateJavaSource(e, java_writer);
|
||||
java_writer = env.getFiler().createTextFile(Filer.Location.SOURCE_TREE, d.getPackage().getQualifiedName(), new File(Utils.getSimpleClassName(d) + ".java"), null);
|
||||
generateJavaSource(d, java_writer);
|
||||
|
||||
if ( methods.size() > 0 ) {
|
||||
boolean noNative = true;
|
||||
for ( final ExecutableElement method : methods ) {
|
||||
for ( final MethodDeclaration method : methods ) {
|
||||
Alternate alt_annotation = method.getAnnotation(Alternate.class);
|
||||
if ( (alt_annotation == null || alt_annotation.nativeAlt()) && method.getAnnotation(Reuse.class) == null ) {
|
||||
noNative = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( noNative ) {
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
if ( noNative )
|
||||
return;
|
||||
|
||||
final String outputPath = env.getOptions().get("-d") + '/' + Utils.getNativeQualifiedName(Utils.getQualifiedClassName(d));
|
||||
final File outputNative = new File(outputPath + ".c");
|
||||
final File outputBackup = new File(outputPath + "_backup.c");
|
||||
|
||||
// If the native file exists, rename.
|
||||
final ByteBuffer nativeBefore;
|
||||
if ( outputNative.exists() ) {
|
||||
nativeBefore = readFile(outputNative);
|
||||
outputNative.renameTo(outputBackup);
|
||||
} else
|
||||
nativeBefore = null;
|
||||
|
||||
try {
|
||||
generateNativeSource(e);
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
generateNativeSource(d);
|
||||
|
||||
// If the native file did exist, compare with the new file. If they're the same,
|
||||
// reset the last modified time to avoid ridiculous C compilation times.
|
||||
if ( nativeBefore != null && outputNative.length() == nativeBefore.capacity() ) {
|
||||
final ByteBuffer nativeAfter = readFile(outputNative);
|
||||
boolean same = true;
|
||||
for ( int i = nativeBefore.position(); i < nativeBefore.limit(); i++ ) {
|
||||
if ( nativeBefore.get(i) != nativeAfter.get(i) ) {
|
||||
same = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( same ) {
|
||||
outputNative.delete();
|
||||
outputBackup.renameTo(outputNative);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if ( outputBackup.exists() )
|
||||
outputBackup.delete();
|
||||
}
|
||||
}
|
||||
return DEFAULT_VALUE;
|
||||
} catch (Exception ex) {
|
||||
} catch (Exception e) {
|
||||
// If anything goes wrong mid-gen, delete output to allow regen next time we run.
|
||||
if ( java_writer != null ) java_writer.close();
|
||||
if ( outputJava.exists() ) outputJava.delete();
|
||||
|
||||
throw new RuntimeException(ex);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,21 +35,20 @@ package org.lwjgl.util.generator;
|
|||
import org.lwjgl.PointerBuffer;
|
||||
|
||||
import java.nio.Buffer;
|
||||
import javax.lang.model.type.ArrayType;
|
||||
import javax.lang.model.type.DeclaredType;
|
||||
import javax.lang.model.type.NoType;
|
||||
import javax.lang.model.type.PrimitiveType;
|
||||
import javax.lang.model.util.SimpleTypeVisitor6;
|
||||
|
||||
import com.sun.mirror.type.*;
|
||||
import com.sun.mirror.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* A TypeVisitor that translates TypeMirrors to JNI
|
||||
* type strings.
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
* $Id$
|
||||
*/
|
||||
public class JNITypeTranslator extends SimpleTypeVisitor6<Void, Void> {
|
||||
public class JNITypeTranslator implements TypeVisitor {
|
||||
|
||||
private final StringBuilder signature = new StringBuilder();
|
||||
|
||||
|
|
@ -63,8 +62,11 @@ public class JNITypeTranslator extends SimpleTypeVisitor6<Void, Void> {
|
|||
return objectReturn ? "jobject" : signature.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitArray(ArrayType t, Void o) {
|
||||
public void visitAnnotationType(AnnotationType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitArrayType(ArrayType t) {
|
||||
final String className = t.getComponentType().toString();
|
||||
if ( "java.lang.CharSequence".equals(className) )
|
||||
signature.append("jlong");
|
||||
|
|
@ -74,10 +76,9 @@ public class JNITypeTranslator extends SimpleTypeVisitor6<Void, Void> {
|
|||
signature.append("jobjectArray");
|
||||
else
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
private void visitClassType(DeclaredType t) {
|
||||
public void visitClassType(ClassType t) {
|
||||
final Class<?> type = Utils.getJavaType(t);
|
||||
if ( Buffer.class.isAssignableFrom(type) || PointerBuffer.class.isAssignableFrom(type) ) {
|
||||
signature.append("jlong");
|
||||
|
|
@ -86,17 +87,21 @@ public class JNITypeTranslator extends SimpleTypeVisitor6<Void, Void> {
|
|||
signature.append("jobject");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitDeclared(DeclaredType t, Void o) {
|
||||
if ( t.asElement().getKind().isClass() )
|
||||
visitClassType(t);
|
||||
return DEFAULT_VALUE;
|
||||
public void visitDeclaredType(DeclaredType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitPrimitive(PrimitiveType t, Void o) {
|
||||
public void visitEnumType(EnumType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitInterfaceType(InterfaceType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitPrimitiveType(PrimitiveType t) {
|
||||
String type;
|
||||
switch ( t.getKind() ) {
|
||||
switch (t.getKind()) {
|
||||
case LONG:
|
||||
type = "jlong";
|
||||
break;
|
||||
|
|
@ -122,13 +127,25 @@ public class JNITypeTranslator extends SimpleTypeVisitor6<Void, Void> {
|
|||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
signature.append(type);
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitNoType(NoType t, Void o) {
|
||||
public void visitReferenceType(ReferenceType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitTypeMirror(TypeMirror t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitTypeVariable(TypeVariable t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitVoidType(VoidType t) {
|
||||
signature.append(t.toString());
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
public void visitWildcardType(WildcardType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.lwjgl.util.generator;
|
||||
|
||||
/**
|
||||
|
|
@ -36,45 +37,37 @@ package org.lwjgl.util.generator;
|
|||
* This class generates the methods in the generated java source files.
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$ $Id$
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
import org.lwjgl.PointerBuffer;
|
||||
import org.lwjgl.util.generator.opengl.GLreturn;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.*;
|
||||
import com.sun.mirror.apt.*;
|
||||
import com.sun.mirror.declaration.*;
|
||||
import com.sun.mirror.type.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import java.nio.*;
|
||||
|
||||
public class JavaMethodsGenerator {
|
||||
|
||||
private static final String SAVED_PARAMETER_POSTFIX = "_saved";
|
||||
|
||||
public static void generateMethodsJava(ProcessingEnvironment env, TypeMap type_map, PrintWriter writer, TypeElement interface_decl, boolean generate_error_checks, boolean context_specific) {
|
||||
for ( ExecutableElement method : Utils.getMethods(interface_decl) ) {
|
||||
public static void generateMethodsJava(AnnotationProcessorEnvironment env, TypeMap type_map, PrintWriter writer, InterfaceDeclaration interface_decl, boolean generate_error_checks, boolean context_specific) {
|
||||
for (MethodDeclaration method : interface_decl.getMethods())
|
||||
generateMethodJava(env, type_map, writer, interface_decl, method, generate_error_checks, context_specific);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO : fix info multi-type methods print.
|
||||
*/
|
||||
private static void generateMethodJava(ProcessingEnvironment env, TypeMap type_map, PrintWriter writer, TypeElement interface_decl, ExecutableElement method, boolean generate_error_checks, boolean context_specific) {
|
||||
private static void generateMethodJava(AnnotationProcessorEnvironment env, TypeMap type_map, PrintWriter writer, InterfaceDeclaration interface_decl, MethodDeclaration method, boolean generate_error_checks, boolean context_specific) {
|
||||
writer.println();
|
||||
if ( Utils.isMethodIndirect(generate_error_checks, context_specific, method) ) {
|
||||
if ( method.getAnnotation(GenerateAutos.class) != null ) {
|
||||
if (Utils.isMethodIndirect(generate_error_checks, context_specific, method)) {
|
||||
if (method.getAnnotation(GenerateAutos.class) != null) {
|
||||
printMethodWithMultiType(env, type_map, writer, interface_decl, method, TypeInfo.getDefaultTypeInfoMap(method), Mode.AUTOS, generate_error_checks, context_specific);
|
||||
}
|
||||
Collection<Map<VariableElement, TypeInfo>> cross_product = TypeInfo.getTypeInfoCrossProduct(type_map, method);
|
||||
for ( Map<VariableElement, TypeInfo> typeinfos_instance : cross_product ) {
|
||||
Collection<Map<ParameterDeclaration, TypeInfo>> cross_product = TypeInfo.getTypeInfoCrossProduct(type_map, method);
|
||||
for (Map<ParameterDeclaration, TypeInfo> typeinfos_instance : cross_product) {
|
||||
printMethodWithMultiType(env, type_map, writer, interface_decl, method, typeinfos_instance, Mode.NORMAL, generate_error_checks, context_specific);
|
||||
}
|
||||
}
|
||||
|
|
@ -85,147 +78,130 @@ public class JavaMethodsGenerator {
|
|||
Reuse reuse_annotation = method.getAnnotation(Reuse.class);
|
||||
Alternate alt_annotation = method.getAnnotation(Alternate.class);
|
||||
if ( alt_annotation == null || (alt_annotation.nativeAlt() && !alt_annotation.skipNative()) ) {
|
||||
if ( alt_annotation != null && method.getSimpleName().toString().equals(alt_annotation.value()) ) {
|
||||
if ( alt_annotation != null && method.getSimpleName().equals(alt_annotation.value()) )
|
||||
throw new RuntimeException("An alternate function with native code should have a different name than the main function.");
|
||||
}
|
||||
|
||||
if ( reuse_annotation == null ) {
|
||||
printJavaNativeStub(env, writer, method, Mode.NORMAL, generate_error_checks, context_specific);
|
||||
}
|
||||
if ( reuse_annotation == null )
|
||||
printJavaNativeStub(writer, method, Mode.NORMAL, generate_error_checks, context_specific);
|
||||
|
||||
if ( Utils.hasMethodBufferObjectParameter(method) ) {
|
||||
if (Utils.hasMethodBufferObjectParameter(method)) {
|
||||
printMethodWithMultiType(env, type_map, writer, interface_decl, method, TypeInfo.getDefaultTypeInfoMap(method), Mode.BUFFEROBJECT, generate_error_checks, context_specific);
|
||||
if ( reuse_annotation == null ) {
|
||||
printJavaNativeStub(env, writer, method, Mode.BUFFEROBJECT, generate_error_checks, context_specific);
|
||||
}
|
||||
if ( reuse_annotation == null )
|
||||
printJavaNativeStub(writer, method, Mode.BUFFEROBJECT, generate_error_checks, context_specific);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void printJavaNativeStub(ProcessingEnvironment env, PrintWriter writer, ExecutableElement method, Mode mode, boolean generate_error_checks, boolean context_specific) {
|
||||
if ( Utils.isMethodIndirect(generate_error_checks, context_specific, method) ) {
|
||||
private static void printJavaNativeStub(PrintWriter writer, MethodDeclaration method, Mode mode, boolean generate_error_checks, boolean context_specific) {
|
||||
if (Utils.isMethodIndirect(generate_error_checks, context_specific, method)) {
|
||||
writer.print("\tstatic native ");
|
||||
} else {
|
||||
Utils.printDocComment(writer, method, env);
|
||||
Utils.printDocComment(writer, method);
|
||||
writer.print("\tpublic static native ");
|
||||
}
|
||||
writer.print(getResultType(method, true));
|
||||
writer.print(" " + Utils.getSimpleNativeMethodName(method, generate_error_checks, context_specific));
|
||||
if ( mode == Mode.BUFFEROBJECT ) {
|
||||
if (mode == Mode.BUFFEROBJECT)
|
||||
writer.print(Utils.BUFFER_OBJECT_METHOD_POSTFIX);
|
||||
}
|
||||
writer.print("(");
|
||||
boolean first_parameter = generateParametersJava(writer, method, TypeInfo.getDefaultTypeInfoMap(method), true, true, mode);
|
||||
if ( context_specific ) {
|
||||
if ( !first_parameter ) {
|
||||
if (context_specific) {
|
||||
if (!first_parameter)
|
||||
writer.print(", ");
|
||||
}
|
||||
writer.print("long " + Utils.FUNCTION_POINTER_VAR_NAME);
|
||||
}
|
||||
writer.println(");");
|
||||
}
|
||||
|
||||
private static boolean generateParametersJava(PrintWriter writer, ExecutableElement method, Map<VariableElement, TypeInfo> typeinfos_instance, boolean native_stub, final boolean printTypes, Mode mode) {
|
||||
private static boolean generateParametersJava(PrintWriter writer, MethodDeclaration method, Map<ParameterDeclaration, TypeInfo> typeinfos_instance, boolean native_stub, final boolean printTypes, Mode mode) {
|
||||
boolean first_parameter = true;
|
||||
for ( VariableElement param : method.getParameters() ) {
|
||||
if ( native_stub && (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative()) ) {
|
||||
for (ParameterDeclaration param : method.getParameters()) {
|
||||
if ( native_stub && (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative()) )
|
||||
continue;
|
||||
}
|
||||
final Constant constant_annotation = param.getAnnotation(Constant.class);
|
||||
if ( constant_annotation != null && constant_annotation.isNative() ) {
|
||||
if ( constant_annotation != null && constant_annotation.isNative() )
|
||||
continue;
|
||||
}
|
||||
AnnotationMirror auto_annotation_mirror = Utils.getParameterAutoAnnotation(param);
|
||||
boolean hide_auto_parameter = mode == Mode.NORMAL && !native_stub && auto_annotation_mirror != null;
|
||||
if ( hide_auto_parameter ) {
|
||||
if (hide_auto_parameter) {
|
||||
AutoType auto_type_annotation = param.getAnnotation(AutoType.class);
|
||||
if ( auto_type_annotation != null ) {
|
||||
VariableElement auto_parameter = Utils.findParameter(method, auto_type_annotation.value());
|
||||
if (auto_type_annotation != null) {
|
||||
ParameterDeclaration auto_parameter = Utils.findParameter(method, auto_type_annotation.value());
|
||||
TypeInfo auto_param_type_info = typeinfos_instance.get(auto_parameter);
|
||||
if ( auto_param_type_info.getSignedness() == Signedness.BOTH ) {
|
||||
if ( !first_parameter ) {
|
||||
if (auto_param_type_info.getSignedness() == Signedness.BOTH) {
|
||||
if (!first_parameter)
|
||||
writer.print(", ");
|
||||
}
|
||||
first_parameter = false;
|
||||
if ( printTypes ) {
|
||||
if ( printTypes )
|
||||
writer.print("boolean ");
|
||||
}
|
||||
writer.print(TypeInfo.UNSIGNED_PARAMETER_NAME);
|
||||
}
|
||||
}
|
||||
} else if ( param.getAnnotation(Result.class) == null
|
||||
} else if (
|
||||
param.getAnnotation(Result.class) == null
|
||||
&& (native_stub || ((param.getAnnotation(Constant.class) == null || param.getAnnotation(Constant.class).keepParam()) && !Utils.isReturnParameter(method, param)))
|
||||
&& (mode != Mode.AUTOS || getAutoTypeParameter(method, param) == null) ) {
|
||||
&& (mode != Mode.AUTOS || getAutoTypeParameter(method, param) == null)
|
||||
) {
|
||||
first_parameter = generateParameterJava(writer, param, typeinfos_instance.get(param), native_stub, printTypes, first_parameter, mode);
|
||||
}
|
||||
}
|
||||
CachedResult cached_result_annotation = method.getAnnotation(CachedResult.class);
|
||||
TypeMirror result_type = Utils.getMethodReturnType(method);
|
||||
if ( (native_stub && Utils.getNIOBufferType(result_type) != null) || Utils.needResultSize(method) ) {
|
||||
if ((native_stub && Utils.getNIOBufferType(result_type) != null) || Utils.needResultSize(method)) {
|
||||
AutoSize auto_size_annotation = method.getAnnotation(AutoSize.class);
|
||||
if ( auto_size_annotation == null || !auto_size_annotation.isNative() ) {
|
||||
if ( cached_result_annotation == null || !cached_result_annotation.isRange() ) {
|
||||
if ( !first_parameter ) {
|
||||
if (cached_result_annotation == null || !cached_result_annotation.isRange()) {
|
||||
if (!first_parameter)
|
||||
writer.print(", ");
|
||||
}
|
||||
first_parameter = false;
|
||||
if ( printTypes ) {
|
||||
if ( printTypes )
|
||||
writer.print("long ");
|
||||
}
|
||||
writer.print(Utils.RESULT_SIZE_NAME);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( cached_result_annotation != null ) {
|
||||
if ( !first_parameter ) {
|
||||
if (cached_result_annotation != null) {
|
||||
if (!first_parameter)
|
||||
writer.print(", ");
|
||||
}
|
||||
|
||||
if ( mode == Mode.CACHEDRESULT ) {
|
||||
if ( printTypes ) {
|
||||
if ( printTypes )
|
||||
writer.print("long ");
|
||||
}
|
||||
writer.print(Utils.CACHED_BUFFER_LENGTH_NAME + ", ");
|
||||
}
|
||||
|
||||
first_parameter = false;
|
||||
if ( printTypes ) {
|
||||
if ( printTypes )
|
||||
writer.print(getResultType(method, native_stub));
|
||||
}
|
||||
writer.print(" " + Utils.CACHED_BUFFER_NAME);
|
||||
}
|
||||
return first_parameter;
|
||||
}
|
||||
|
||||
private static boolean generateParameterJava(PrintWriter writer, VariableElement param, TypeInfo type_info, boolean native_stub, final boolean printTypes, boolean first_parameter, Mode mode) {
|
||||
Class buffer_type = Utils.getNIOBufferType(param.asType());
|
||||
if ( !first_parameter ) {
|
||||
private static boolean generateParameterJava(PrintWriter writer, ParameterDeclaration param, TypeInfo type_info, boolean native_stub, final boolean printTypes, boolean first_parameter, Mode mode) {
|
||||
Class buffer_type = Utils.getNIOBufferType(param.getType());
|
||||
if (!first_parameter)
|
||||
writer.print(", ");
|
||||
}
|
||||
BufferObject bo_annotation = param.getAnnotation(BufferObject.class);
|
||||
if ( bo_annotation != null && mode == Mode.BUFFEROBJECT ) {
|
||||
if ( buffer_type == null ) {
|
||||
if (bo_annotation != null && mode == Mode.BUFFEROBJECT) {
|
||||
if (buffer_type == null)
|
||||
throw new RuntimeException("type of " + param + " is not a nio Buffer parameter but is annotated as buffer object");
|
||||
}
|
||||
if ( printTypes ) {
|
||||
if ( printTypes )
|
||||
writer.print("long ");
|
||||
}
|
||||
writer.print(param.getSimpleName() + Utils.BUFFER_OBJECT_PARAMETER_POSTFIX);
|
||||
} else {
|
||||
if ( native_stub && param.getAnnotation(PointerWrapper.class) != null ) {
|
||||
if ( native_stub && param.getAnnotation(PointerWrapper.class) != null )
|
||||
writer.print("long ");
|
||||
} else {
|
||||
else {
|
||||
Class type = type_info.getType();
|
||||
if ( native_stub && (type == CharSequence.class || type == CharSequence[].class || type == PointerBuffer.class || Buffer.class.isAssignableFrom(type)) ) {
|
||||
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.getSimpleName() + " ");
|
||||
}
|
||||
else if ( printTypes )
|
||||
writer.print(type_info.getType().getSimpleName() + " ");
|
||||
}
|
||||
AutoSize auto_size_annotation = param.getAnnotation(AutoSize.class);
|
||||
if ( auto_size_annotation != null ) {
|
||||
if ( auto_size_annotation != null )
|
||||
writer.print(auto_size_annotation.value() + "_");
|
||||
}
|
||||
writer.print(param.getSimpleName());
|
||||
}
|
||||
return false;
|
||||
|
|
@ -234,63 +210,55 @@ public class JavaMethodsGenerator {
|
|||
private static void printBufferObjectCheck(PrintWriter writer, BufferKind kind, Mode mode, boolean context_specific) {
|
||||
String bo_check_method_name = kind.toString();
|
||||
writer.print("\t\t" + Utils.CHECKS_CLASS_NAME + ".ensure" + bo_check_method_name);
|
||||
if ( mode == Mode.BUFFEROBJECT ) {
|
||||
if (mode == Mode.BUFFEROBJECT)
|
||||
writer.print("enabled");
|
||||
} else {
|
||||
else
|
||||
writer.print("disabled");
|
||||
}
|
||||
|
||||
if ( context_specific ) {
|
||||
if ( context_specific )
|
||||
writer.println("(caps);");
|
||||
} else {
|
||||
else
|
||||
writer.println("();");
|
||||
}
|
||||
}
|
||||
|
||||
private static void printBufferObjectChecks(PrintWriter writer, ExecutableElement method, Mode mode, boolean context_specific) {
|
||||
private static void printBufferObjectChecks(PrintWriter writer, MethodDeclaration method, Mode mode, boolean context_specific) {
|
||||
EnumSet<BufferKind> check_set = EnumSet.noneOf(BufferKind.class);
|
||||
for ( VariableElement param : method.getParameters() ) {
|
||||
for (ParameterDeclaration param : method.getParameters()) {
|
||||
BufferObject bo_annotation = param.getAnnotation(BufferObject.class);
|
||||
if ( bo_annotation != null ) {
|
||||
if (bo_annotation != null)
|
||||
check_set.add(bo_annotation.value());
|
||||
}
|
||||
}
|
||||
for ( BufferKind kind : check_set ) {
|
||||
for (BufferKind kind : check_set)
|
||||
printBufferObjectCheck(writer, kind, mode, context_specific);
|
||||
}
|
||||
}
|
||||
|
||||
private static void printMethodWithMultiType(ProcessingEnvironment env, TypeMap type_map, PrintWriter writer, TypeElement interface_decl, ExecutableElement method, Map<VariableElement, TypeInfo> typeinfos_instance, Mode mode, boolean generate_error_checks, boolean context_specific) {
|
||||
Utils.printDocComment(writer, method, env);
|
||||
if ( method.getAnnotation(Deprecated.class) != null ) {
|
||||
private static void printMethodWithMultiType(AnnotationProcessorEnvironment env, TypeMap type_map, PrintWriter writer, InterfaceDeclaration interface_decl, MethodDeclaration method, Map<ParameterDeclaration, TypeInfo> typeinfos_instance, Mode mode, boolean generate_error_checks, boolean context_specific) {
|
||||
Utils.printDocComment(writer, method);
|
||||
if ( method.getAnnotation(Deprecated.class) != null )
|
||||
writer.println("\t@Deprecated");
|
||||
}
|
||||
if ( interface_decl.getAnnotation(Private.class) == null && method.getAnnotation(Private.class) == null ) {
|
||||
if ( interface_decl.getAnnotation(Private.class) == null && method.getAnnotation(Private.class) == null )
|
||||
writer.print("\tpublic static ");
|
||||
} else {
|
||||
else
|
||||
writer.print("\tstatic ");
|
||||
}
|
||||
writer.print(getResultType(method, false));
|
||||
StripPostfix strip_annotation = method.getAnnotation(StripPostfix.class);
|
||||
String method_name;
|
||||
Alternate alt_annotation = method.getAnnotation(Alternate.class);
|
||||
method_name = alt_annotation == null || alt_annotation.javaAlt() ? method.getSimpleName().toString() : alt_annotation.value();
|
||||
if ( strip_annotation != null && mode == Mode.NORMAL ) {
|
||||
method_name = alt_annotation == null || alt_annotation.javaAlt() ? method.getSimpleName() : alt_annotation.value();
|
||||
if (strip_annotation != null && mode == Mode.NORMAL)
|
||||
method_name = getPostfixStrippedName(type_map, interface_decl, method);
|
||||
}
|
||||
writer.print(" " + method_name + "(");
|
||||
generateParametersJava(writer, method, typeinfos_instance, false, true, mode);
|
||||
writer.println(") {");
|
||||
|
||||
final TypeMirror result_type = Utils.getMethodReturnType(method);
|
||||
boolean has_result = !result_type.equals(env.getTypeUtils().getNoType(TypeKind.VOID));
|
||||
boolean has_result = !result_type.equals(env.getTypeUtils().getVoidType());
|
||||
|
||||
final Reuse reuse_annotation = method.getAnnotation(Reuse.class);
|
||||
if ( reuse_annotation != null ) {
|
||||
writer.print("\t\t");
|
||||
if ( has_result || method.getAnnotation(GLreturn.class) != null ) {
|
||||
if ( has_result || method.getAnnotation(GLreturn.class) != null )
|
||||
writer.print("return ");
|
||||
}
|
||||
|
||||
writer.print(reuse_annotation.value() + "." + (reuse_annotation.method().length() > 0 ? reuse_annotation.method() : method_name) + "(");
|
||||
generateParametersJava(writer, method, typeinfos_instance, false, false, mode);
|
||||
|
|
@ -298,7 +266,7 @@ public class JavaMethodsGenerator {
|
|||
return;
|
||||
}
|
||||
|
||||
if ( context_specific ) {
|
||||
if (context_specific) {
|
||||
type_map.printCapabilitiesInit(writer);
|
||||
writer.print("\t\tlong " + Utils.FUNCTION_POINTER_VAR_NAME + " = " + type_map.getCapabilities() + ".");
|
||||
writer.println(Utils.getFunctionAddressName(interface_decl, method, true) + ";");
|
||||
|
|
@ -306,20 +274,18 @@ public class JavaMethodsGenerator {
|
|||
writer.println(Utils.FUNCTION_POINTER_VAR_NAME + ");");
|
||||
}
|
||||
final Code code_annotation = method.getAnnotation(Code.class);
|
||||
if ( code_annotation != null && code_annotation.value().length() > 0 ) {
|
||||
if (code_annotation != null && code_annotation.value().length() > 0)
|
||||
writer.println(code_annotation.value());
|
||||
}
|
||||
printBufferObjectChecks(writer, method, mode, context_specific);
|
||||
printParameterChecks(writer, method, typeinfos_instance, mode, generate_error_checks);
|
||||
printParameterCaching(writer, interface_decl, method, mode, context_specific);
|
||||
|
||||
if ( code_annotation != null && code_annotation.javaBeforeNative().length() > 0 ) {
|
||||
if ( code_annotation != null && code_annotation.javaBeforeNative().length() > 0 )
|
||||
writer.println(code_annotation.javaBeforeNative());
|
||||
}
|
||||
writer.print("\t\t");
|
||||
|
||||
final PointerWrapper pointer_wrapper_annotation = method.getAnnotation(PointerWrapper.class);
|
||||
if ( has_result ) {
|
||||
if (has_result) {
|
||||
writer.print(getResultType(method, false) + " " + Utils.RESULT_VAR_NAME);
|
||||
|
||||
if ( code_annotation != null && code_annotation.tryBlock() ) {
|
||||
|
|
@ -330,56 +296,48 @@ public class JavaMethodsGenerator {
|
|||
|
||||
writer.print(" = ");
|
||||
if ( pointer_wrapper_annotation != null ) {
|
||||
if ( pointer_wrapper_annotation.factory().length() > 0 ) {
|
||||
if ( pointer_wrapper_annotation.factory().length() > 0 )
|
||||
writer.print(pointer_wrapper_annotation.factory() + "(");
|
||||
} else {
|
||||
else
|
||||
writer.print("new " + getResultType(method, false) + "(");
|
||||
}
|
||||
}
|
||||
} else if ( method.getAnnotation(GLreturn.class) != null ) {
|
||||
has_result = true;
|
||||
Utils.printGLReturnPre(writer, method, method.getAnnotation(GLreturn.class), type_map);
|
||||
}
|
||||
writer.print(Utils.getSimpleNativeMethodName(method, generate_error_checks, context_specific));
|
||||
if ( mode == Mode.BUFFEROBJECT ) {
|
||||
if (mode == Mode.BUFFEROBJECT)
|
||||
writer.print(Utils.BUFFER_OBJECT_METHOD_POSTFIX);
|
||||
}
|
||||
writer.print("(");
|
||||
boolean first_parameter = printMethodCallArguments(writer, method, typeinfos_instance, mode, type_map);
|
||||
if ( context_specific ) {
|
||||
if ( !first_parameter ) {
|
||||
if (context_specific) {
|
||||
if (!first_parameter)
|
||||
writer.print(", ");
|
||||
}
|
||||
writer.print(Utils.FUNCTION_POINTER_VAR_NAME);
|
||||
}
|
||||
if ( has_result && pointer_wrapper_annotation != null ) {
|
||||
writer.print(")");
|
||||
if ( pointer_wrapper_annotation.params().length() > 0 ) {
|
||||
if ( pointer_wrapper_annotation.params().length() > 0 )
|
||||
writer.print(", " + pointer_wrapper_annotation.params());
|
||||
}
|
||||
}
|
||||
writer.println(");");
|
||||
|
||||
if ( code_annotation != null && code_annotation.javaAfterNative().length() > 0 ) {
|
||||
if ( code_annotation != null && code_annotation.javaAfterNative().length() > 0 )
|
||||
writer.println(code_annotation.javaAfterNative());
|
||||
}
|
||||
|
||||
final String tabs = code_annotation != null && code_annotation.tryBlock() ? "\t\t\t" : "\t\t";
|
||||
if ( generate_error_checks && method.getAnnotation(NoErrorCheck.class) == null ) {
|
||||
if (generate_error_checks && method.getAnnotation(NoErrorCheck.class) == null)
|
||||
type_map.printErrorCheckMethod(writer, method, tabs);
|
||||
}
|
||||
// DISABLED: indirect buffer support
|
||||
//printNondirectParameterCopies(writer, method, mode);
|
||||
if ( has_result ) {
|
||||
if (has_result) {
|
||||
if ( method.getAnnotation(GLreturn.class) == null ) {
|
||||
if ( ByteBuffer.class.equals(Utils.getJavaType(result_type)) ) {
|
||||
if ( ByteBuffer.class.equals(Utils.getJavaType(result_type)) )
|
||||
writer.println(tabs + "return LWJGLUtil.CHECKS && " + Utils.RESULT_VAR_NAME + " == null ? null : " + Utils.RESULT_VAR_NAME + ".order(ByteOrder.nativeOrder());"); // safeNewBuffer returns a direct ByteBuffer with BIG_ENDIAN order.
|
||||
} else {
|
||||
else
|
||||
writer.println(tabs + "return " + Utils.RESULT_VAR_NAME + ";");
|
||||
}
|
||||
} else {
|
||||
} else
|
||||
Utils.printGLReturnPost(writer, method, method.getAnnotation(GLreturn.class), type_map);
|
||||
}
|
||||
}
|
||||
|
||||
if ( code_annotation != null && code_annotation.tryBlock() ) {
|
||||
|
|
@ -390,201 +348,176 @@ public class JavaMethodsGenerator {
|
|||
writer.println("\t}");
|
||||
}
|
||||
|
||||
private static String getExtensionPostfix(TypeElement interface_decl) {
|
||||
String interface_simple_name = interface_decl.getSimpleName().toString();
|
||||
private static String getExtensionPostfix(InterfaceDeclaration interface_decl) {
|
||||
String interface_simple_name = interface_decl.getSimpleName();
|
||||
Extension extension_annotation = interface_decl.getAnnotation(Extension.class);
|
||||
if ( extension_annotation == null ) {
|
||||
if (extension_annotation == null) {
|
||||
int underscore_index = interface_simple_name.indexOf("_");
|
||||
if ( underscore_index != -1 ) {
|
||||
if (underscore_index != -1)
|
||||
return interface_simple_name.substring(0, underscore_index);
|
||||
} else {
|
||||
else
|
||||
return "";
|
||||
}
|
||||
} else {
|
||||
} else
|
||||
return extension_annotation.postfix();
|
||||
}
|
||||
}
|
||||
|
||||
private static VariableElement getAutoTypeParameter(ExecutableElement method, VariableElement target_parameter) {
|
||||
for ( VariableElement param : method.getParameters() ) {
|
||||
private static ParameterDeclaration getAutoTypeParameter(MethodDeclaration method, ParameterDeclaration target_parameter) {
|
||||
for (ParameterDeclaration param : method.getParameters()) {
|
||||
AnnotationMirror auto_annotation = Utils.getParameterAutoAnnotation(param);
|
||||
if ( auto_annotation != null ) {
|
||||
if (auto_annotation != null) {
|
||||
Class annotation_type = NativeTypeTranslator.getClassFromType(auto_annotation.getAnnotationType());
|
||||
String parameter_name;
|
||||
if ( annotation_type.equals(AutoType.class) ) {
|
||||
if (annotation_type.equals(AutoType.class))
|
||||
parameter_name = param.getAnnotation(AutoType.class).value();
|
||||
} else if ( annotation_type.equals(AutoSize.class) ) {
|
||||
else if (annotation_type.equals(AutoSize.class))
|
||||
parameter_name = param.getAnnotation(AutoSize.class).value();
|
||||
} else {
|
||||
else
|
||||
throw new RuntimeException("Unknown annotation type " + annotation_type);
|
||||
}
|
||||
if ( target_parameter.getSimpleName().toString().equals(parameter_name) ) {
|
||||
if (target_parameter.getSimpleName().equals(parameter_name))
|
||||
return param;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean hasAnyParameterAutoTypeAnnotation(ExecutableElement method, VariableElement target_param) {
|
||||
for ( VariableElement param : method.getParameters() ) {
|
||||
private static boolean hasAnyParameterAutoTypeAnnotation(MethodDeclaration method, ParameterDeclaration target_param) {
|
||||
for (ParameterDeclaration param : method.getParameters()) {
|
||||
AutoType auto_type_annotation = param.getAnnotation(AutoType.class);
|
||||
if ( auto_type_annotation != null ) {
|
||||
VariableElement type_target_param = Utils.findParameter(method, auto_type_annotation.value());
|
||||
if ( target_param.equals(type_target_param) ) {
|
||||
if (auto_type_annotation != null) {
|
||||
ParameterDeclaration type_target_param = Utils.findParameter(method, auto_type_annotation.value());
|
||||
if (target_param.equals(type_target_param))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static final Map<String, Pattern> postfixPatterns = new HashMap<String, Pattern>();
|
||||
|
||||
private static Pattern getPostfixPattern(String regex) {
|
||||
Pattern pattern = postfixPatterns.get(regex);
|
||||
if ( pattern == null ) {
|
||||
postfixPatterns.put(regex, pattern = Pattern.compile(regex));
|
||||
}
|
||||
return pattern;
|
||||
}
|
||||
|
||||
private static String getPostfixStrippedName(TypeMap type_map, TypeElement interface_decl, ExecutableElement method) {
|
||||
private static String getPostfixStrippedName(TypeMap type_map, InterfaceDeclaration interface_decl, MethodDeclaration method) {
|
||||
StripPostfix strip_annotation = method.getAnnotation(StripPostfix.class);
|
||||
VariableElement postfix_parameter = Utils.findParameter(method, strip_annotation.value());
|
||||
ParameterDeclaration postfix_parameter = Utils.findParameter(method, strip_annotation.value());
|
||||
String postfix = strip_annotation.postfix();
|
||||
boolean postfixOverride = !("NULL".equals(postfix) && strip_annotation.hasPostfix());
|
||||
if ( !postfixOverride ) {
|
||||
if ( "NULL".equals(postfix) ) {
|
||||
PostfixTranslator translator = new PostfixTranslator(type_map, postfix_parameter);
|
||||
postfix_parameter.asType().accept(translator, null);
|
||||
postfix_parameter.getType().accept(translator);
|
||||
postfix = translator.getSignature();
|
||||
} else if ( !strip_annotation.hasPostfix() ) {
|
||||
postfix = "";
|
||||
}
|
||||
|
||||
String method_name;
|
||||
Alternate alt_annotation = method.getAnnotation(Alternate.class);
|
||||
method_name = alt_annotation == null || alt_annotation.javaAlt() ? method.getSimpleName().toString() : alt_annotation.value();
|
||||
method_name = alt_annotation == null || alt_annotation.javaAlt() ? method.getSimpleName() : alt_annotation.value();
|
||||
|
||||
String extension_postfix = "NULL".equals(strip_annotation.extension()) ? getExtensionPostfix(interface_decl) : strip_annotation.extension();
|
||||
String result;
|
||||
|
||||
Matcher matcher = getPostfixPattern(
|
||||
postfixOverride
|
||||
? (postfix + "(?:v)?" + extension_postfix + "$")
|
||||
: ("(?:" + postfix + "(?:v)?|i(?:64)?_v|v)" + extension_postfix + "$")
|
||||
).matcher(method_name);
|
||||
if ( strip_annotation.hasPostfix() && method_name.endsWith(postfix + "v" + extension_postfix))
|
||||
result = method_name.substring(0, method_name.length() - (postfix.length() + 1 + extension_postfix.length()));
|
||||
else if ( strip_annotation.hasPostfix() && method_name.endsWith(postfix + extension_postfix))
|
||||
result = method_name.substring(0, method_name.length() - (postfix.length() + extension_postfix.length()));
|
||||
else if ( strip_annotation.hasPostfix() && method_name.endsWith(postfix + "i_v" + extension_postfix) )
|
||||
result = method_name.substring(0, method_name.length() - (postfix.length() + 3 + extension_postfix.length()));
|
||||
else if ( method_name.endsWith("i_v" + extension_postfix) )
|
||||
result = method_name.substring(0, method_name.length() - (3 + extension_postfix.length()));
|
||||
else if (method_name.endsWith("v" + extension_postfix))
|
||||
result = method_name.substring(0, method_name.length() - (1 + extension_postfix.length()));
|
||||
else
|
||||
throw new RuntimeException(method + " is specified as being postfix stripped on parameter " + postfix_parameter + ", but it's postfix is not '" + postfix + "' nor 'v'");
|
||||
|
||||
if ( !matcher.find() ) {
|
||||
throw new RuntimeException(method_name + " is specified as being postfix stripped on parameter " + postfix_parameter + ", but it's postfix is neither '" + postfix + "' nor 'v'");
|
||||
}
|
||||
|
||||
return method_name.substring(0, matcher.start()) + extension_postfix;
|
||||
return result + extension_postfix;
|
||||
}
|
||||
|
||||
private static int getBufferElementSizeExponent(Class c) {
|
||||
if ( IntBuffer.class.equals(c) ) {
|
||||
if (IntBuffer.class.equals(c))
|
||||
return 2;
|
||||
} else if ( LongBuffer.class.equals(c) ) {
|
||||
else if (LongBuffer.class.equals(c))
|
||||
return 3;
|
||||
} else if ( DoubleBuffer.class.equals(c) ) {
|
||||
else if (DoubleBuffer.class.equals(c))
|
||||
return 3;
|
||||
} else if ( ShortBuffer.class.equals(c) ) {
|
||||
else if (ShortBuffer.class.equals(c))
|
||||
return 1;
|
||||
} else if ( ByteBuffer.class.equals(c) ) {
|
||||
else if (ByteBuffer.class.equals(c))
|
||||
return 0;
|
||||
} else if ( FloatBuffer.class.equals(c) ) {
|
||||
else if (FloatBuffer.class.equals(c))
|
||||
return 2;
|
||||
} else {
|
||||
else
|
||||
throw new RuntimeException(c + " is not allowed");
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean printMethodCallArgument(PrintWriter writer, ExecutableElement method, VariableElement param, Map<VariableElement, TypeInfo> typeinfos_instance, Mode mode, boolean first_parameter, TypeMap type_map) {
|
||||
if ( !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(", ");
|
||||
}
|
||||
|
||||
AnnotationMirror auto_annotation = Utils.getParameterAutoAnnotation(param);
|
||||
Constant constant_annotation = param.getAnnotation(Constant.class);
|
||||
if ( constant_annotation != null ) {
|
||||
if (constant_annotation != null) {
|
||||
writer.print(constant_annotation.value());
|
||||
} else if ( auto_annotation != null && mode == Mode.NORMAL ) {
|
||||
} else if (auto_annotation != null && mode == Mode.NORMAL) {
|
||||
Class param_type = NativeTypeTranslator.getClassFromType(auto_annotation.getAnnotationType());
|
||||
if ( AutoType.class.equals(param_type) ) {
|
||||
if (AutoType.class.equals(param_type)) {
|
||||
final AutoType auto_type_annotation = param.getAnnotation(AutoType.class);
|
||||
final VariableElement auto_parameter = Utils.findParameter(method, auto_type_annotation.value());
|
||||
final ParameterDeclaration auto_parameter = Utils.findParameter(method, auto_type_annotation.value());
|
||||
final String auto_type = typeinfos_instance.get(auto_parameter).getAutoType();
|
||||
if ( auto_type == null ) {
|
||||
if ( auto_type == null )
|
||||
throw new RuntimeException("No auto type for parameter " + param.getSimpleName() + " in method " + method);
|
||||
}
|
||||
writer.print(auto_type);
|
||||
} else if ( AutoSize.class.equals(param_type) ) {
|
||||
} else if (AutoSize.class.equals(param_type)) {
|
||||
final AutoSize auto_size_annotation = param.getAnnotation(AutoSize.class);
|
||||
if ( !auto_size_annotation.useExpression() ) {
|
||||
final String auto_parameter_name = auto_size_annotation.value();
|
||||
final VariableElement auto_target_param = Utils.findParameter(method, auto_parameter_name);
|
||||
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 ) {
|
||||
if ( shifting > 0 )
|
||||
writer.print("(");
|
||||
}
|
||||
}
|
||||
if ( auto_size_annotation.canBeNull() ) {
|
||||
if ( auto_size_annotation.canBeNull() )
|
||||
writer.print("(" + auto_parameter_name + " == null ? 0 : " + auto_parameter_name + ".remaining())");
|
||||
} else {
|
||||
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 ) {
|
||||
if (shift_remaining && shifting > 0) {
|
||||
writer.print(" << " + shifting);
|
||||
writer.print(")");
|
||||
}
|
||||
}
|
||||
writer.print(auto_size_annotation.expression());
|
||||
} else {
|
||||
} else
|
||||
throw new RuntimeException("Unknown auto annotation " + param_type);
|
||||
}
|
||||
} else {
|
||||
if ( mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null ) {
|
||||
if (mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null) {
|
||||
writer.print(param.getSimpleName() + Utils.BUFFER_OBJECT_PARAMETER_POSTFIX);
|
||||
} else {
|
||||
Class type = typeinfos_instance.get(param).getType();
|
||||
Check check_annotation = param.getAnnotation(Check.class);
|
||||
boolean hide_buffer = mode == Mode.AUTOS && getAutoTypeParameter(method, param) != null;
|
||||
if ( hide_buffer ) {
|
||||
if (hide_buffer) {
|
||||
writer.print("0L");
|
||||
} else {
|
||||
if ( type == CharSequence.class || type == CharSequence[].class ) {
|
||||
final String offset = Utils.getStringOffset(method, param);
|
||||
|
||||
writer.print("APIUtil.getBuffer");
|
||||
if ( param.getAnnotation(NullTerminated.class) != null ) {
|
||||
if ( param.getAnnotation(NullTerminated.class) != null )
|
||||
writer.print("NT");
|
||||
}
|
||||
writer.print('(');
|
||||
writer.print(type_map.getAPIUtilParam(true));
|
||||
writer.print(param.getSimpleName());
|
||||
if ( offset != null ) {
|
||||
if ( offset != null )
|
||||
writer.print(", " + offset);
|
||||
}
|
||||
writer.print(")");
|
||||
} else {
|
||||
final AutoSize auto_size_annotation = param.getAnnotation(AutoSize.class);
|
||||
if ( auto_size_annotation != null ) {
|
||||
if ( auto_size_annotation != null )
|
||||
writer.print(auto_size_annotation.value() + "_");
|
||||
}
|
||||
|
||||
final Class buffer_type = Utils.getNIOBufferType(param.asType());
|
||||
if ( buffer_type == null ) {
|
||||
final Class buffer_type = Utils.getNIOBufferType(param.getType());
|
||||
if ( buffer_type == null )
|
||||
writer.print(param.getSimpleName());
|
||||
} else {
|
||||
else {
|
||||
writer.print("MemoryUtil.getAddress");
|
||||
if ( check_annotation != null && check_annotation.canBeNull() ) {
|
||||
if ( check_annotation != null && check_annotation.canBeNull() )
|
||||
writer.print("Safe");
|
||||
}
|
||||
writer.print("(");
|
||||
writer.print(param.getSimpleName());
|
||||
writer.print(")");
|
||||
|
|
@ -594,9 +527,8 @@ public class JavaMethodsGenerator {
|
|||
if ( type != long.class ) {
|
||||
PointerWrapper pointer_annotation = param.getAnnotation(PointerWrapper.class);
|
||||
if ( pointer_annotation != null ) {
|
||||
if ( pointer_annotation.canBeNull() ) {
|
||||
if ( pointer_annotation.canBeNull() )
|
||||
writer.print(" == null ? 0 : " + param.getSimpleName());
|
||||
}
|
||||
writer.print(".getPointer()");
|
||||
}
|
||||
}
|
||||
|
|
@ -605,38 +537,34 @@ public class JavaMethodsGenerator {
|
|||
return false;
|
||||
}
|
||||
|
||||
private static boolean printMethodCallArguments(PrintWriter writer, ExecutableElement method, Map<VariableElement, TypeInfo> typeinfos_instance, Mode mode, TypeMap type_map) {
|
||||
private static boolean printMethodCallArguments(PrintWriter writer, MethodDeclaration method, Map<ParameterDeclaration, TypeInfo> typeinfos_instance, Mode mode, TypeMap type_map) {
|
||||
boolean first_parameter = true;
|
||||
for ( VariableElement param : method.getParameters() ) {
|
||||
if ( param.getAnnotation(Result.class) != null || (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative()) ) {
|
||||
for ( ParameterDeclaration param : method.getParameters() ) {
|
||||
if ( param.getAnnotation(Result.class) != null || (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative()) )
|
||||
continue;
|
||||
}
|
||||
|
||||
final Constant constant_annotation = param.getAnnotation(Constant.class);
|
||||
if ( constant_annotation == null || !constant_annotation.isNative() ) {
|
||||
if ( constant_annotation== null || !constant_annotation.isNative() )
|
||||
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() ) {
|
||||
if (Utils.getNIOBufferType(Utils.getMethodReturnType(method)) != null) {
|
||||
if (method.getAnnotation(CachedResult.class) != null && method.getAnnotation(CachedResult.class).isRange()) {
|
||||
first_parameter = false;
|
||||
Utils.printExtraCallArguments(writer, method, "");
|
||||
} else {
|
||||
AutoSize auto_size_annotation = method.getAnnotation(AutoSize.class);
|
||||
if ( auto_size_annotation == null || !auto_size_annotation.isNative() ) {
|
||||
if ( !first_parameter ) {
|
||||
if (!first_parameter)
|
||||
writer.print(", ");
|
||||
}
|
||||
first_parameter = false;
|
||||
|
||||
String result_size_expression;
|
||||
if ( mode == Mode.CACHEDRESULT ) {
|
||||
if ( mode == Mode.CACHEDRESULT )
|
||||
result_size_expression = Utils.CACHED_BUFFER_LENGTH_NAME;
|
||||
} else if ( auto_size_annotation == null ) {
|
||||
else if ( auto_size_annotation == null )
|
||||
result_size_expression = Utils.RESULT_SIZE_NAME;
|
||||
} else {
|
||||
else
|
||||
result_size_expression = auto_size_annotation.value();
|
||||
}
|
||||
|
||||
Utils.printExtraCallArguments(writer, method, result_size_expression);
|
||||
}
|
||||
|
|
@ -645,104 +573,99 @@ public class JavaMethodsGenerator {
|
|||
return first_parameter;
|
||||
}
|
||||
|
||||
private static void printParameterCaching(PrintWriter writer, TypeElement interface_decl, ExecutableElement method, Mode mode, boolean context_specific) {
|
||||
for ( VariableElement param : method.getParameters() ) {
|
||||
Class java_type = Utils.getJavaType(param.asType());
|
||||
CachedReference cachedReference = param.getAnnotation(CachedReference.class);
|
||||
if ( Buffer.class.isAssignableFrom(java_type)
|
||||
&& cachedReference != null
|
||||
&& (mode != Mode.BUFFEROBJECT || param.getAnnotation(BufferObject.class) == null)
|
||||
&& param.getAnnotation(Result.class) == null ) {
|
||||
private static void printParameterCaching(PrintWriter writer, InterfaceDeclaration interface_decl, MethodDeclaration method, Mode mode, boolean context_specific) {
|
||||
for (ParameterDeclaration param : method.getParameters()) {
|
||||
Class java_type = Utils.getJavaType(param.getType());
|
||||
CachedReference cachedReference = param.getAnnotation(CachedReference.class);
|
||||
if (Buffer.class.isAssignableFrom(java_type) &&
|
||||
cachedReference != null &&
|
||||
(mode != Mode.BUFFEROBJECT || param.getAnnotation(BufferObject.class) == null) &&
|
||||
param.getAnnotation(Result.class) == null) {
|
||||
writer.print("\t\tif ( LWJGLUtil.CHECKS ) StateTracker.");
|
||||
if ( context_specific ) {
|
||||
if ( context_specific )
|
||||
writer.print("getReferences(caps).");
|
||||
} else {
|
||||
else
|
||||
writer.print("getTracker().");
|
||||
}
|
||||
if ( cachedReference.name().length() > 0 ) {
|
||||
writer.print(cachedReference.name());
|
||||
} else {
|
||||
writer.print(Utils.getReferenceName(interface_decl, method, param));
|
||||
}
|
||||
if ( cachedReference.index().length() > 0 ) {
|
||||
writer.print("[" + cachedReference.index() + "]");
|
||||
}
|
||||
if(cachedReference.name().length() > 0) {
|
||||
writer.print(cachedReference.name());
|
||||
} else {
|
||||
writer.print(Utils.getReferenceName(interface_decl, method, param));
|
||||
}
|
||||
if(cachedReference.index().length() > 0) {
|
||||
writer.print("[" + cachedReference.index() + "]");
|
||||
}
|
||||
writer.println(" = " + param.getSimpleName() + ";");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void printParameterChecks(PrintWriter writer, ExecutableElement method, Map<VariableElement, TypeInfo> typeinfos, Mode mode, final boolean generate_error_checks) {
|
||||
private static void printParameterChecks(PrintWriter writer, MethodDeclaration method, Map<ParameterDeclaration, TypeInfo> typeinfos, Mode mode, final boolean generate_error_checks) {
|
||||
if ( mode == Mode.NORMAL ) {
|
||||
final GenerateAutos gen_autos_annotation = method.getAnnotation(GenerateAutos.class);
|
||||
if ( gen_autos_annotation != null && gen_autos_annotation.sizeVariables().length > 0 ) {
|
||||
// For the auto-generated parameters, declare and init a size variable (that can be reused by @Code)
|
||||
for ( final VariableElement param : method.getParameters() ) {
|
||||
if ( Arrays.binarySearch(gen_autos_annotation.sizeVariables(), param.getSimpleName().toString()) >= 0 ) {
|
||||
for ( final ParameterDeclaration param : method.getParameters() ) {
|
||||
if ( Arrays.binarySearch(gen_autos_annotation.sizeVariables(), param.getSimpleName()) >= 0 ) {
|
||||
final int shifting = getBufferElementSizeExponent(typeinfos.get(param).getType());
|
||||
final Check check_annotation = param.getAnnotation(Check.class);
|
||||
|
||||
writer.print("\t\tlong " + param.getSimpleName() + "_size = ");
|
||||
if ( check_annotation == null || !check_annotation.canBeNull() ) {
|
||||
if ( check_annotation == null || !check_annotation.canBeNull() )
|
||||
writer.println(param.getSimpleName() + ".remaining() << " + shifting + ";");
|
||||
} else {
|
||||
else
|
||||
writer.println(param.getSimpleName() + " == null ? 0 : " + param.getSimpleName() + ".remaining() << " + shifting + ";");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for ( VariableElement param : method.getParameters() ) {
|
||||
Class java_type = Utils.getJavaType(param.asType());
|
||||
if ( java_type.isArray() || (Utils.isAddressableType(java_type)
|
||||
&& (mode != Mode.BUFFEROBJECT || param.getAnnotation(BufferObject.class) == null)
|
||||
&& (mode != Mode.AUTOS || getAutoTypeParameter(method, param) == null)
|
||||
&& param.getAnnotation(Result.class) == null
|
||||
&& !Utils.isReturnParameter(method, param)) ) {
|
||||
for (ParameterDeclaration param : method.getParameters()) {
|
||||
Class java_type = Utils.getJavaType(param.getType());
|
||||
if ( java_type.isArray() || (Utils.isAddressableType(java_type) &&
|
||||
(mode != Mode.BUFFEROBJECT || param.getAnnotation(BufferObject.class) == null) &&
|
||||
(mode != Mode.AUTOS || getAutoTypeParameter(method, param) == null) &&
|
||||
param.getAnnotation(Result.class) == null &&
|
||||
!Utils.isReturnParameter(method, param)) ) {
|
||||
String check_value = null;
|
||||
boolean can_be_null = false;
|
||||
Check check_annotation = param.getAnnotation(Check.class);
|
||||
if ( check_annotation != null ) {
|
||||
if (check_annotation != null) {
|
||||
check_value = check_annotation.value();
|
||||
can_be_null = check_annotation.canBeNull();
|
||||
}
|
||||
if ( (Buffer.class.isAssignableFrom(java_type) || PointerBuffer.class.isAssignableFrom(java_type)) && param.getAnnotation(Constant.class) == null ) {
|
||||
if ((Buffer.class.isAssignableFrom(java_type) || PointerBuffer.class.isAssignableFrom(java_type)) && param.getAnnotation(Constant.class) == null) {
|
||||
boolean out_parameter = param.getAnnotation(OutParameter.class) != null;
|
||||
TypeInfo typeinfo = typeinfos.get(param);
|
||||
printParameterCheck(writer, method, param.getSimpleName().toString(), typeinfo.getType().getSimpleName(), check_value, can_be_null, param.getAnnotation(NullTerminated.class), generate_error_checks);
|
||||
} else if ( String.class.equals(java_type) ) {
|
||||
if ( !can_be_null ) {
|
||||
printParameterCheck(writer, method, param.getSimpleName(), typeinfo.getType().getSimpleName(), check_value, can_be_null, param.getAnnotation(NullTerminated.class), out_parameter, generate_error_checks);
|
||||
} else if ( String.class.equals(java_type)) {
|
||||
if (!can_be_null)
|
||||
writer.println("\t\tBufferChecks.checkNotNull(" + param.getSimpleName() + ");");
|
||||
}
|
||||
} else if ( java_type.isArray() ) {
|
||||
printArrayParameterCheck(writer, param.getSimpleName().toString(), check_value, can_be_null);
|
||||
final TypeInfo typeinfo = typeinfos.get(param);
|
||||
printArrayParameterCheck(writer, param.getSimpleName(), typeinfo.getType().getSimpleName(), check_value, can_be_null);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( method.getAnnotation(CachedResult.class) != null ) {
|
||||
printParameterCheck(writer, method, Utils.CACHED_BUFFER_NAME, null, null, true, null, generate_error_checks);
|
||||
}
|
||||
if (method.getAnnotation(CachedResult.class) != null)
|
||||
printParameterCheck(writer, method, Utils.CACHED_BUFFER_NAME, null, null, true, null, false, generate_error_checks);
|
||||
}
|
||||
|
||||
private static void printParameterCheck(PrintWriter writer, ExecutableElement method, String name, String type, String check_value, boolean can_be_null, NullTerminated null_terminated, boolean generate_error_checks) {
|
||||
private static void printParameterCheck(PrintWriter writer, MethodDeclaration method, String name, String type, String check_value, boolean can_be_null, NullTerminated null_terminated, boolean out_parameter, boolean generate_error_checks) {
|
||||
String tabs;
|
||||
if ( can_be_null ) {
|
||||
if (can_be_null) {
|
||||
writer.print("\t\tif (" + name + " != null)");
|
||||
if ( null_terminated != null ) {
|
||||
if ( null_terminated != null )
|
||||
writer.println(" {");
|
||||
} else {
|
||||
else
|
||||
writer.println();
|
||||
}
|
||||
tabs = "\t\t\t";
|
||||
} else {
|
||||
} else
|
||||
tabs = "\t\t";
|
||||
}
|
||||
writer.print(tabs + "BufferChecks.check");
|
||||
if ( check_value != null && check_value.length() > 0 ) {
|
||||
if (check_value != null && check_value.length() > 0) {
|
||||
writer.print("Buffer");
|
||||
if ( "Buffer".equals(type) ) {
|
||||
if ( "Buffer".equals(type) )
|
||||
writer.print("Size"); // Check size only, Buffer.isDirect() was added in 1.6, cannot use yet. TODO: Remove?
|
||||
}
|
||||
writer.print("(" + name + ", " + check_value);
|
||||
} else {
|
||||
writer.print("Direct(" + name);
|
||||
|
|
@ -755,7 +678,7 @@ public class JavaMethodsGenerator {
|
|||
writer.println("\t\t\t" + name + " = APIUtil.getBufferIntDebug();"); // Use an exclusive buffer here
|
||||
}
|
||||
}
|
||||
if ( null_terminated != null ) {
|
||||
if (null_terminated != null) {
|
||||
writer.print(tabs + "BufferChecks.checkNullTerminated(");
|
||||
writer.print(name);
|
||||
if ( null_terminated.value().length() > 0 ) {
|
||||
|
|
@ -763,59 +686,52 @@ public class JavaMethodsGenerator {
|
|||
writer.print(null_terminated.value());
|
||||
}
|
||||
writer.println(");");
|
||||
if ( can_be_null ) {
|
||||
if ( can_be_null )
|
||||
writer.println("\t\t}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void printArrayParameterCheck(PrintWriter writer, String name, String check_value, boolean can_be_null) {
|
||||
private static void printArrayParameterCheck(PrintWriter writer, String name, String type, String check_value, boolean can_be_null) {
|
||||
String tabs;
|
||||
if ( can_be_null ) {
|
||||
writer.println("\t\tif (" + name + " != null)");
|
||||
tabs = "\t\t\t";
|
||||
} else {
|
||||
} else
|
||||
tabs = "\t\t";
|
||||
}
|
||||
|
||||
writer.print(tabs + "BufferChecks.checkArray(" + name);
|
||||
if ( check_value != null && check_value.length() > 0 ) {
|
||||
if ( check_value != null && check_value.length() > 0)
|
||||
writer.print(", " + check_value);
|
||||
}
|
||||
writer.println(");");
|
||||
}
|
||||
|
||||
private static String getResultType(ExecutableElement method, boolean native_stub) {
|
||||
if ( native_stub && method.getAnnotation(PointerWrapper.class) != null ) {
|
||||
private static String getResultType(MethodDeclaration method, boolean native_stub) {
|
||||
if ( native_stub && method.getAnnotation(PointerWrapper.class) != null )
|
||||
return "long";
|
||||
} else if ( !native_stub && method.getAnnotation(GLreturn.class) != null ) {
|
||||
else if ( !native_stub && method.getAnnotation(GLreturn.class) != null )
|
||||
return Utils.getMethodReturnType(method, method.getAnnotation(GLreturn.class), false);
|
||||
} else {
|
||||
else
|
||||
return Utils.getJavaType(Utils.getMethodReturnType(method)).getSimpleName();
|
||||
}
|
||||
}
|
||||
|
||||
private static String getDefaultResultValue(ExecutableElement method) {
|
||||
private static String getDefaultResultValue(MethodDeclaration method) {
|
||||
if ( method.getAnnotation(GLreturn.class) != null ) {
|
||||
final String type = Utils.getMethodReturnType(method, method.getAnnotation(GLreturn.class), false);
|
||||
if ( "boolean".equals(type) ) {
|
||||
if ( "boolean".equals(type) )
|
||||
return "false";
|
||||
} else if ( Character.isLowerCase(type.charAt(0)) ) {
|
||||
else if ( Character.isLowerCase(type.charAt(0)) )
|
||||
return "0";
|
||||
} else {
|
||||
else
|
||||
return "null";
|
||||
}
|
||||
} else {
|
||||
final Class type = Utils.getJavaType(Utils.getMethodReturnType(method));
|
||||
if ( type.isPrimitive() ) {
|
||||
if ( type == boolean.class ) {
|
||||
if ( type == boolean.class )
|
||||
return "false";
|
||||
} else {
|
||||
else
|
||||
return "0";
|
||||
}
|
||||
} else {
|
||||
} else
|
||||
return "null";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -29,50 +29,54 @@
|
|||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.lwjgl.util.generator;
|
||||
|
||||
import org.lwjgl.opencl.CLMem;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import javax.lang.model.type.*;
|
||||
import javax.lang.model.util.SimpleTypeVisitor6;
|
||||
|
||||
import com.sun.mirror.type.*;
|
||||
import com.sun.mirror.util.*;
|
||||
|
||||
/**
|
||||
* A TypeVisitor that translates (annotated) TypeMirrors to java types
|
||||
* (represented by a Class)
|
||||
* A TypeVisitor that translates (annotated) TypeMirrors to
|
||||
* java types (represented by a Class)
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$ $Id$
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
public class JavaTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
|
||||
|
||||
public class JavaTypeTranslator implements TypeVisitor {
|
||||
private Class type;
|
||||
|
||||
public Class getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitArray(ArrayType t, Void o) {
|
||||
public void visitAnnotationType(AnnotationType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitArrayType(ArrayType t) {
|
||||
final TypeMirror componentType = t.getComponentType();
|
||||
try {
|
||||
final Class c = Class.forName(t.getComponentType().toString());
|
||||
if ( CharSequence.class.isAssignableFrom(c) || ByteBuffer.class.isAssignableFrom(c) || org.lwjgl.PointerWrapper.class.isAssignableFrom(c) ) {
|
||||
type = Class.forName("[L" + t.getComponentType() + ";");
|
||||
}
|
||||
} catch (ClassNotFoundException ex) {
|
||||
type = null;
|
||||
} finally {
|
||||
if ( type == null ) {
|
||||
if ( componentType instanceof PrimitiveType ) {
|
||||
type = getPrimitiveArrayClassFromKind(componentType.getKind());
|
||||
} else {
|
||||
if ( componentType instanceof PrimitiveType ) {
|
||||
type = getPrimitiveArrayClassFromKind(((PrimitiveType)componentType).getKind());
|
||||
} else {
|
||||
try {
|
||||
final Class c = Class.forName(t.getComponentType().toString());
|
||||
if ( CharSequence.class.isAssignableFrom(c) || ByteBuffer.class.isAssignableFrom(c) || org.lwjgl.PointerWrapper.class.isAssignableFrom(c) )
|
||||
type = Class.forName("[L" + t.getComponentType() + ";");
|
||||
else {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
public static Class getPrimitiveClassFromKind(TypeKind kind) {
|
||||
public static Class getPrimitiveClassFromKind(PrimitiveType.Kind kind) {
|
||||
switch ( kind ) {
|
||||
case LONG:
|
||||
return long.class;
|
||||
|
|
@ -93,7 +97,7 @@ public class JavaTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
|
|||
}
|
||||
}
|
||||
|
||||
private static Class getPrimitiveArrayClassFromKind(TypeKind kind) {
|
||||
private static Class getPrimitiveArrayClassFromKind(PrimitiveType.Kind kind) {
|
||||
switch ( kind ) {
|
||||
case LONG:
|
||||
return long[].class;
|
||||
|
|
@ -114,36 +118,43 @@ public class JavaTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitPrimitive(PrimitiveType t, Void p) {
|
||||
public void visitPrimitiveType(PrimitiveType t) {
|
||||
type = getPrimitiveClassFromKind(t.getKind());
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitDeclared(DeclaredType t, Void o) {
|
||||
if ( t.asElement().getKind().isClass() ) {
|
||||
visitClassType(t);
|
||||
} else if ( t.asElement().getKind().isInterface() ) {
|
||||
visitInterfaceType(t);
|
||||
} else {
|
||||
throw new RuntimeException(t.asElement().getKind() + " is not allowed");
|
||||
}
|
||||
return DEFAULT_VALUE;
|
||||
public void visitDeclaredType(DeclaredType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
private void visitClassType(DeclaredType t) {
|
||||
public void visitEnumType(EnumType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitClassType(ClassType t) {
|
||||
type = NativeTypeTranslator.getClassFromType(t);
|
||||
}
|
||||
|
||||
private void visitInterfaceType(DeclaredType t) {
|
||||
public void visitInterfaceType(InterfaceType t) {
|
||||
type = NativeTypeTranslator.getClassFromType(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitNoType(NoType t, Void p) {
|
||||
public void visitReferenceType(ReferenceType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitTypeMirror(TypeMirror t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitTypeVariable(TypeVariable t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitVoidType(VoidType t) {
|
||||
type = void.class;
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
public void visitWildcardType(WildcardType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,36 +43,33 @@ package org.lwjgl.util.generator;
|
|||
|
||||
import org.lwjgl.PointerBuffer;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.nio.Buffer;
|
||||
import java.util.List;
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import com.sun.mirror.apt.*;
|
||||
import com.sun.mirror.declaration.*;
|
||||
import com.sun.mirror.type.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.nio.*;
|
||||
|
||||
public class NativeMethodStubsGenerator {
|
||||
private static final String BUFFER_ADDRESS_POSTFIX = "_address";
|
||||
public static final String BUFFER_POSITION_POSTFIX = "_position";
|
||||
private static final String STRING_LIST_NAME = "_str";
|
||||
private static final String POINTER_LIST_NAME = "_ptr";
|
||||
private static final String BUFFER_ADDRESS_POSTFIX = "_address";
|
||||
public static final String BUFFER_POSITION_POSTFIX = "_position";
|
||||
private static final String STRING_LIST_NAME = "_str";
|
||||
private static final String POINTER_LIST_NAME = "_ptr";
|
||||
|
||||
public static void generateNativeMethodStubs(ProcessingEnvironment env, TypeMap type_map, PrintWriter writer, TypeElement d, boolean generate_error_checks, boolean context_specific) {
|
||||
for ( ExecutableElement method : Utils.getMethods(d) ) {
|
||||
public static void generateNativeMethodStubs(AnnotationProcessorEnvironment env, TypeMap type_map, PrintWriter writer, InterfaceDeclaration d, boolean generate_error_checks, boolean context_specific) {
|
||||
for (MethodDeclaration method : d.getMethods()) {
|
||||
Alternate alt_annotation = method.getAnnotation(Alternate.class);
|
||||
if ( (alt_annotation != null && (!alt_annotation.nativeAlt() || alt_annotation.skipNative())) || method.getAnnotation(Reuse.class) != null )
|
||||
continue;
|
||||
generateMethodStub(env, type_map, writer, Utils.getQualifiedClassName(d), method, Mode.NORMAL, generate_error_checks, context_specific);
|
||||
if ( Utils.hasMethodBufferObjectParameter(method) )
|
||||
if (Utils.hasMethodBufferObjectParameter(method))
|
||||
generateMethodStub(env, type_map, writer, Utils.getQualifiedClassName(d), method, Mode.BUFFEROBJECT, generate_error_checks, context_specific);
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateParameters(PrintWriter writer, List<? extends VariableElement> params, Mode mode) {
|
||||
for ( VariableElement param : params ) {
|
||||
private static void generateParameters(PrintWriter writer, Collection<ParameterDeclaration> params, Mode mode) {
|
||||
for (ParameterDeclaration param : params) {
|
||||
if ( param.getAnnotation(Result.class) != null || (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative()) )
|
||||
continue;
|
||||
final Constant constant_annotation = param.getAnnotation(Constant.class);
|
||||
|
|
@ -81,20 +78,20 @@ public class NativeMethodStubsGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
private static void generateParameter(PrintWriter writer, VariableElement param, Mode mode) {
|
||||
private static void generateParameter(PrintWriter writer, ParameterDeclaration param, Mode mode) {
|
||||
writer.print(", ");
|
||||
if ( mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null ) {
|
||||
if (mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null) {
|
||||
writer.print("jlong " + param.getSimpleName() + Utils.BUFFER_OBJECT_PARAMETER_POSTFIX);
|
||||
} else if ( param.getAnnotation(PointerWrapper.class) != null ) {
|
||||
writer.print("jlong " + param.getSimpleName());
|
||||
} else {
|
||||
JNITypeTranslator translator = new JNITypeTranslator();
|
||||
param.asType().accept(translator, null);
|
||||
param.getType().accept(translator);
|
||||
writer.print(translator.getSignature() + " " + param.getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateMethodStub(ProcessingEnvironment env, TypeMap type_map, PrintWriter writer, String interface_name, ExecutableElement method, Mode mode, boolean generate_error_checks, boolean context_specific) {
|
||||
private static void generateMethodStub(AnnotationProcessorEnvironment env, TypeMap type_map, PrintWriter writer, String interface_name, MethodDeclaration method, Mode mode, boolean generate_error_checks, boolean context_specific) {
|
||||
if ( !context_specific && method.getAnnotation(Alternate.class) == null )
|
||||
writer.print("static ");
|
||||
else
|
||||
|
|
@ -108,30 +105,30 @@ public class NativeMethodStubsGenerator {
|
|||
writer.print("jlong");
|
||||
} else {
|
||||
JNITypeTranslator translator = new JNITypeTranslator();
|
||||
result_type.accept(translator, null);
|
||||
result_type.accept(translator);
|
||||
writer.print(translator.getReturnSignature());
|
||||
}
|
||||
writer.print(" JNICALL ");
|
||||
|
||||
writer.print(Utils.getQualifiedNativeMethodName(interface_name, method, generate_error_checks, context_specific));
|
||||
if ( mode == Mode.BUFFEROBJECT )
|
||||
if (mode == Mode.BUFFEROBJECT)
|
||||
writer.print(Utils.BUFFER_OBJECT_METHOD_POSTFIX);
|
||||
writer.print("(JNIEnv *env, jclass clazz");
|
||||
generateParameters(writer, method.getParameters(), mode);
|
||||
if ( Utils.getNIOBufferType(result_type) != null ) {
|
||||
if (Utils.getNIOBufferType(result_type) != null) {
|
||||
if ( (cached_result_annotation == null || !cached_result_annotation.isRange()) && (auto_size_annotation == null || !auto_size_annotation.isNative()) )
|
||||
writer.print(", jlong " + Utils.RESULT_SIZE_NAME);
|
||||
if ( cached_result_annotation != null )
|
||||
if (cached_result_annotation != null)
|
||||
writer.print(", jobject " + Utils.CACHED_BUFFER_NAME);
|
||||
}
|
||||
if ( context_specific ) {
|
||||
if (context_specific) {
|
||||
writer.print(", jlong " + Utils.FUNCTION_POINTER_VAR_NAME);
|
||||
}
|
||||
writer.println(") {");
|
||||
|
||||
generateBufferParameterAddresses(type_map, writer, method, mode);
|
||||
Alternate alt_annotation = method.getAnnotation(Alternate.class);
|
||||
if ( context_specific ) {
|
||||
if (context_specific) {
|
||||
String typedef_name = Utils.getTypedefName(method);
|
||||
writer.print("\t" + typedef_name + " " + (alt_annotation == null ? method.getSimpleName() : alt_annotation.value()));
|
||||
writer.print(" = (" + typedef_name + ")((intptr_t)");
|
||||
|
|
@ -140,7 +137,7 @@ public class NativeMethodStubsGenerator {
|
|||
|
||||
final Code code_annotation = method.getAnnotation(Code.class);
|
||||
|
||||
final boolean hasResult = !result_type.equals(env.getTypeUtils().getNoType(TypeKind.VOID));
|
||||
final boolean hasResult = !result_type.equals(env.getTypeUtils().getVoidType());
|
||||
final boolean resultPreDeclare = hasResult && (hasPointerArrayInits(method.getParameters()) || (code_annotation != null && (code_annotation.nativeAfterVars().length() > 0 || code_annotation.nativeBeforeCall().length() > 0)));
|
||||
if ( resultPreDeclare )
|
||||
printResultParam(type_map, writer, method, result_type, true);
|
||||
|
|
@ -167,21 +164,21 @@ public class NativeMethodStubsGenerator {
|
|||
writer.println(code_annotation.nativeAfterCall());
|
||||
|
||||
generateStringDeallocations(writer, method.getParameters());
|
||||
if ( !result_type.equals(env.getTypeUtils().getNoType(TypeKind.VOID)) ) {
|
||||
if (!result_type.equals(env.getTypeUtils().getVoidType())) {
|
||||
writer.print("\treturn ");
|
||||
Class java_result_type = Utils.getJavaType(result_type);
|
||||
if ( Buffer.class.isAssignableFrom(java_result_type) ) {
|
||||
if ( cached_result_annotation != null )
|
||||
if (Buffer.class.isAssignableFrom(java_result_type)) {
|
||||
if (cached_result_annotation != null)
|
||||
writer.print("safeNewBufferCached(env, ");
|
||||
else
|
||||
writer.print("safeNewBuffer(env, ");
|
||||
} else if ( String.class.equals(java_result_type) ) {
|
||||
} else if (String.class.equals(java_result_type)) {
|
||||
writer.print("NewStringNativeUnsigned(env, ");
|
||||
} else if ( method.getAnnotation(PointerWrapper.class) != null ) {
|
||||
writer.print("(intptr_t)");
|
||||
}
|
||||
writer.print(Utils.RESULT_VAR_NAME);
|
||||
if ( Buffer.class.isAssignableFrom(java_result_type) ) {
|
||||
if (Buffer.class.isAssignableFrom(java_result_type)) {
|
||||
final String size_parameter_name;
|
||||
if ( auto_size_annotation != null && (auto_size_annotation.isNative() || (cached_result_annotation != null && cached_result_annotation.isRange())) )
|
||||
size_parameter_name = auto_size_annotation.value();
|
||||
|
|
@ -191,8 +188,8 @@ public class NativeMethodStubsGenerator {
|
|||
writer.print(", ");
|
||||
Utils.printExtraCallArguments(writer, method, size_parameter_name);
|
||||
}
|
||||
if ( Buffer.class.isAssignableFrom(java_result_type) ||
|
||||
String.class.equals(java_result_type) )
|
||||
if (Buffer.class.isAssignableFrom(java_result_type) ||
|
||||
String.class.equals(java_result_type))
|
||||
writer.print(")");
|
||||
writer.println(";");
|
||||
}
|
||||
|
|
@ -200,24 +197,24 @@ public class NativeMethodStubsGenerator {
|
|||
writer.println();
|
||||
}
|
||||
|
||||
private static void printResultParam(final TypeMap type_map, final PrintWriter writer, final ExecutableElement method, final TypeMirror result_type, final boolean preDeclare) {
|
||||
final VariableElement result_param = Utils.getResultParameter(method);
|
||||
final Element return_declaration = result_param == null ? method : result_param;
|
||||
private static void printResultParam(final TypeMap type_map, final PrintWriter writer, final MethodDeclaration method, final TypeMirror result_type, final boolean preDeclare) {
|
||||
final ParameterDeclaration result_param = Utils.getResultParameter(method);
|
||||
final Declaration return_declaration = result_param == null ? method : result_param;
|
||||
final NativeTypeTranslator result_translator = new NativeTypeTranslator(type_map, return_declaration);
|
||||
result_type.accept(result_translator, null);
|
||||
result_type.accept(result_translator);
|
||||
if ( preDeclare )
|
||||
writer.print("\t");
|
||||
writer.print(result_translator.getSignature() + " " + Utils.RESULT_VAR_NAME);
|
||||
if ( preDeclare )
|
||||
if ( preDeclare)
|
||||
writer.println(";");
|
||||
else
|
||||
writer.print(result_param == null ? " = " : ";\n\t");
|
||||
}
|
||||
|
||||
private static void generateCallParameters(PrintWriter writer, TypeMap type_map, List<? extends VariableElement> params) {
|
||||
if ( params.size() > 0 ) {
|
||||
private static void generateCallParameters(PrintWriter writer, TypeMap type_map, Collection<ParameterDeclaration> params) {
|
||||
if (params.size() > 0) {
|
||||
boolean first = true;
|
||||
for ( VariableElement param : params ) {
|
||||
for ( ParameterDeclaration param : params ) {
|
||||
if ( param.getAnnotation(Helper.class) != null )
|
||||
continue;
|
||||
|
||||
|
|
@ -231,7 +228,7 @@ public class NativeMethodStubsGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
private static void generateCallParameter(PrintWriter writer, TypeMap type_map, VariableElement param) {
|
||||
private static void generateCallParameter(PrintWriter writer, TypeMap type_map, ParameterDeclaration param) {
|
||||
if ( param.getAnnotation(Helper.class) != null )
|
||||
return;
|
||||
|
||||
|
|
@ -242,16 +239,16 @@ public class NativeMethodStubsGenerator {
|
|||
}
|
||||
|
||||
boolean is_indirect = param.getAnnotation(Indirect.class) != null;
|
||||
if ( is_indirect || param.getAnnotation(PointerArray.class) != null ) {
|
||||
if (is_indirect || param.getAnnotation(PointerArray.class) != null) {
|
||||
writer.print("(");
|
||||
final NativeTypeTranslator translator = new NativeTypeTranslator(type_map, param);
|
||||
param.asType().accept(translator, null);
|
||||
param.getType().accept(translator);
|
||||
writer.print(translator.getSignature());
|
||||
writer.print("*)");
|
||||
}
|
||||
if ( param.getAnnotation(PointerWrapper.class) != null )
|
||||
writer.print("(" + param.getAnnotation(PointerWrapper.class).value() + ")(intptr_t)");
|
||||
if ( param.getAnnotation(Result.class) != null || is_indirect )
|
||||
if (param.getAnnotation(Result.class) != null || is_indirect)
|
||||
writer.print("&");
|
||||
|
||||
if ( param.getAnnotation(Result.class) != null ) {
|
||||
|
|
@ -259,42 +256,42 @@ public class NativeMethodStubsGenerator {
|
|||
} else {
|
||||
writer.print(param.getSimpleName());
|
||||
if ( param.getAnnotation(PointerArray.class) != null )
|
||||
writer.print(getPointerArrayName(Utils.getJavaType(param.asType())));
|
||||
else if ( Utils.isAddressableType(param.asType()) )
|
||||
writer.print(getPointerArrayName(Utils.getJavaType(param.getType())));
|
||||
else if ( Utils.isAddressableType(param.getType()) )
|
||||
writer.print(BUFFER_ADDRESS_POSTFIX);
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateStringDeallocations(PrintWriter writer, List<? extends VariableElement> params) {
|
||||
for ( VariableElement param : params ) {
|
||||
final Class java_type = Utils.getJavaType(param.asType());
|
||||
private static void generateStringDeallocations(PrintWriter writer, Collection<ParameterDeclaration> params) {
|
||||
for (ParameterDeclaration param : params) {
|
||||
final Class java_type = Utils.getJavaType(param.getType());
|
||||
if ( java_type.equals(String.class) && param.getAnnotation(Result.class) == null )
|
||||
writer.println("\tfree(" + param.getSimpleName() + BUFFER_ADDRESS_POSTFIX + ");");
|
||||
else if ( param.getAnnotation(PointerArray.class) != null ) // Free the string array mem
|
||||
else if (param.getAnnotation(PointerArray.class) != null ) // Free the string array mem
|
||||
writer.println("\tfree(" + param.getSimpleName() + getPointerArrayName(java_type) + ");");
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateBufferParameterAddresses(TypeMap type_map, PrintWriter writer, ExecutableElement method, Mode mode) {
|
||||
private static void generateBufferParameterAddresses(TypeMap type_map, PrintWriter writer, MethodDeclaration method, Mode mode) {
|
||||
strLoopDeclared = false;
|
||||
ptrLoopDeclared = false;
|
||||
for ( VariableElement param : method.getParameters() ) {
|
||||
for ( ParameterDeclaration param : method.getParameters() ) {
|
||||
final Constant constant_annotation = param.getAnnotation(Constant.class);
|
||||
if ( param.getAnnotation(Result.class) == null && (constant_annotation == null || !constant_annotation.isNative()) && Utils.isAddressableType(param.asType()) )
|
||||
generateBufferParameterAddress(type_map, writer, param, mode);
|
||||
if ( param.getAnnotation(Result.class) == null && (constant_annotation == null || !constant_annotation.isNative()) && Utils.isAddressableType(param.getType()))
|
||||
generateBufferParameterAddress(type_map, writer, method, param, mode);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean strLoopDeclared;
|
||||
private static boolean ptrLoopDeclared;
|
||||
|
||||
private static void generateBufferParameterAddress(TypeMap type_map, PrintWriter writer, VariableElement param, Mode mode) {
|
||||
private static void generateBufferParameterAddress(TypeMap type_map, PrintWriter writer, MethodDeclaration method, ParameterDeclaration param, Mode mode) {
|
||||
final Check check_annotation = param.getAnnotation(Check.class);
|
||||
final PointerArray array_annotation = param.getAnnotation(PointerArray.class);
|
||||
final Class java_type = Utils.getJavaType(param.asType());
|
||||
final Class java_type = Utils.getJavaType(param.getType());
|
||||
|
||||
final NativeTypeTranslator translator = new NativeTypeTranslator(type_map, param);
|
||||
param.asType().accept(translator, null);
|
||||
param.getType().accept(translator);
|
||||
final String native_type = translator.getSignature();
|
||||
|
||||
if ( !java_type.isArray() || CharSequence.class.isAssignableFrom(java_type.getComponentType()) ) {
|
||||
|
|
@ -303,12 +300,12 @@ public class NativeMethodStubsGenerator {
|
|||
writer.print(native_type);
|
||||
writer.print(")(intptr_t)");
|
||||
|
||||
if ( mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null ) {
|
||||
if (mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null) {
|
||||
writer.print("offsetToPointer(" + param.getSimpleName() + Utils.BUFFER_OBJECT_PARAMETER_POSTFIX + ")");
|
||||
} else {
|
||||
if ( Buffer.class.isAssignableFrom(java_type) || java_type.equals(CharSequence.class) || java_type.equals(CharSequence[].class) || PointerBuffer.class.isAssignableFrom(java_type) ) {
|
||||
if (Buffer.class.isAssignableFrom(java_type) || java_type.equals(CharSequence.class) || java_type.equals(CharSequence[].class) || PointerBuffer.class.isAssignableFrom(java_type) ) {
|
||||
writer.print(param.getSimpleName());
|
||||
} else if ( java_type.equals(String.class) ) {
|
||||
} else if (java_type.equals(String.class)) {
|
||||
writer.print("GetStringNativeChars(env, " + param.getSimpleName() + ")");
|
||||
} else if ( array_annotation == null )
|
||||
throw new RuntimeException("Illegal type " + java_type);
|
||||
|
|
@ -320,7 +317,7 @@ public class NativeMethodStubsGenerator {
|
|||
final String n = getPointerArrayName(java_type);
|
||||
final String arrayType;
|
||||
if ( POINTER_LIST_NAME.equals(n) ) {
|
||||
if ( n.equals(param.getSimpleName().toString()) )
|
||||
if ( n.equals(param.getSimpleName()) )
|
||||
throw new RuntimeException("The name '" + n + "' is not valid for object array arguments annotated with PointerArray");
|
||||
|
||||
arrayType = translator.getSignature(true) + (org.lwjgl.PointerWrapper.class.isAssignableFrom(java_type.getComponentType()) ? " " : "");
|
||||
|
|
@ -332,7 +329,7 @@ public class NativeMethodStubsGenerator {
|
|||
ptrLoopDeclared = true;
|
||||
}
|
||||
} else {
|
||||
if ( n.equals(param.getSimpleName().toString()) )
|
||||
if ( n.equals(param.getSimpleName()) )
|
||||
throw new RuntimeException("The name '" + n + "' is not valid for arguments annotated with PointerArray");
|
||||
|
||||
arrayType = translator.getSignature(true);
|
||||
|
|
@ -360,8 +357,8 @@ public class NativeMethodStubsGenerator {
|
|||
return STRING_LIST_NAME;
|
||||
}
|
||||
|
||||
private static boolean hasPointerArrayInits(List<? extends VariableElement> params) {
|
||||
for ( VariableElement param : params ) {
|
||||
private static boolean hasPointerArrayInits(Collection<ParameterDeclaration> params) {
|
||||
for ( ParameterDeclaration param : params ) {
|
||||
PointerArray pointerArray_annotation = param.getAnnotation(PointerArray.class);
|
||||
if ( pointerArray_annotation != null )
|
||||
return true;
|
||||
|
|
@ -369,14 +366,14 @@ public class NativeMethodStubsGenerator {
|
|||
return false;
|
||||
}
|
||||
|
||||
private static void generatePointerArrayInits(TypeMap type_map, PrintWriter writer, List<? extends VariableElement> params) {
|
||||
for ( VariableElement param : params ) {
|
||||
private static void generatePointerArrayInits(TypeMap type_map, PrintWriter writer, Collection<ParameterDeclaration> params) {
|
||||
for ( ParameterDeclaration param : params ) {
|
||||
PointerArray pointerArray_annotation = param.getAnnotation(PointerArray.class);
|
||||
if ( pointerArray_annotation != null ) {
|
||||
final Class java_type = Utils.getJavaType(param.asType());
|
||||
final Class java_type = Utils.getJavaType(param.getType());
|
||||
final Class<?> component_type = java_type.isArray() ? java_type.getComponentType() : null;
|
||||
final NativeTypeTranslator translator = new NativeTypeTranslator(type_map, param);
|
||||
param.asType().accept(translator, null);
|
||||
param.getType().accept(translator);
|
||||
|
||||
final String n = getPointerArrayName(java_type);
|
||||
if ( POINTER_LIST_NAME.equals(n) ) {
|
||||
|
|
@ -401,7 +398,7 @@ public class NativeMethodStubsGenerator {
|
|||
writer.println("\twhile ( " + n + "_i < " + pointerArray_annotation.value() + " ) {");
|
||||
if ( lengths.length() == 0 ) {
|
||||
writer.println("\t\t" + param.getSimpleName() + n + "[" + n + "_i++] = " + n + "_address;");
|
||||
writer.println("\t\t" + n + "_address += strlen((const char *)" + n + "_address) + 1;");
|
||||
writer.println("\t\t" + n + "_address += strlen(" + n + "_address) + 1;");
|
||||
} else {
|
||||
writer.println("\t\t" + param.getSimpleName() + n + "[" + n + "_i] = " + n + "_address;");
|
||||
writer.println("\t\t" + n + "_address += " + lengths + BUFFER_ADDRESS_POSTFIX + "[" + n + "_i++];");
|
||||
|
|
|
|||
|
|
@ -29,44 +29,48 @@
|
|||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.lwjgl.util.generator;
|
||||
|
||||
/**
|
||||
*
|
||||
* A TypeVisitor that translates types (and optional native type annotations) to
|
||||
* the native type string.
|
||||
* A TypeVisitor that translates types (and optional native type
|
||||
* annotations) to the native type string.
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$ $Id$
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
import org.lwjgl.PointerBuffer;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.nio.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.type.*;
|
||||
import javax.lang.model.util.SimpleTypeVisitor6;
|
||||
|
||||
import com.sun.mirror.declaration.AnnotationMirror;
|
||||
import com.sun.mirror.declaration.Declaration;
|
||||
import com.sun.mirror.type.*;
|
||||
import com.sun.mirror.util.TypeVisitor;
|
||||
|
||||
/**
|
||||
* $Id$
|
||||
* <p/>
|
||||
* A TypeVisitor that translates (annotated) TypeMirrors to native types
|
||||
* A TypeVisitor that translates (annotated) TypeMirrors to
|
||||
* native types
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
*/
|
||||
public class NativeTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
|
||||
public class NativeTypeTranslator implements TypeVisitor {
|
||||
|
||||
private Collection<Class> native_types;
|
||||
private boolean is_indirect;
|
||||
private final Element declaration;
|
||||
private final TypeMap type_map;
|
||||
private Collection<Class> native_types;
|
||||
private boolean is_indirect;
|
||||
private final Declaration declaration;
|
||||
private final TypeMap type_map;
|
||||
|
||||
public NativeTypeTranslator(TypeMap type_map, Element declaration) {
|
||||
public NativeTypeTranslator(TypeMap type_map, Declaration declaration) {
|
||||
this.declaration = declaration;
|
||||
this.type_map = type_map;
|
||||
}
|
||||
|
|
@ -77,9 +81,8 @@ public class NativeTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
|
|||
|
||||
public String getSignature(final boolean skipConst) {
|
||||
StringBuilder signature = new StringBuilder();
|
||||
if ( !skipConst && declaration.getAnnotation(Const.class) != null ) {
|
||||
if ( !skipConst && declaration.getAnnotation(Const.class) != null )
|
||||
signature.append("const ");
|
||||
}
|
||||
|
||||
if ( declaration.getAnnotation(PointerWrapper.class) != null ) {
|
||||
signature.append(declaration.getAnnotation(PointerWrapper.class).value());
|
||||
|
|
@ -90,22 +93,23 @@ public class NativeTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
|
|||
signature.append(getAnnotationType().getSimpleName());
|
||||
}
|
||||
|
||||
if ( is_indirect ) {
|
||||
if ( is_indirect )
|
||||
signature.append(" *");
|
||||
}
|
||||
return signature.toString();
|
||||
}
|
||||
|
||||
public Class getAnnotationType() {
|
||||
if ( native_types.size() != 1 ) {
|
||||
throw new RuntimeException("Expected only one native type for declaration " + declaration
|
||||
+ ", but got " + native_types.size());
|
||||
}
|
||||
if ( native_types.size() != 1 )
|
||||
throw new RuntimeException("Expected only one native type for declaration " + declaration +
|
||||
", but got " + native_types.size());
|
||||
return native_types.iterator().next();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitArray(ArrayType t, Void o) {
|
||||
public void visitAnnotationType(AnnotationType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitArrayType(ArrayType t) {
|
||||
final Class<?> type = Utils.getJavaType(t).getComponentType();
|
||||
|
||||
if ( CharSequence.class.isAssignableFrom(type) ) {
|
||||
|
|
@ -118,47 +122,43 @@ public class NativeTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
|
|||
native_types.add(type_map.getByteBufferArrayType());
|
||||
} else if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(type) ) {
|
||||
is_indirect = false;
|
||||
} else {
|
||||
} else
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
public static TypeKind getPrimitiveKindFromBufferClass(Class c) {
|
||||
if ( IntBuffer.class.equals(c) ) {
|
||||
return TypeKind.INT;
|
||||
} else if ( DoubleBuffer.class.equals(c) ) {
|
||||
return TypeKind.DOUBLE;
|
||||
} else if ( ShortBuffer.class.equals(c) ) {
|
||||
return TypeKind.SHORT;
|
||||
} else if ( ByteBuffer.class.equals(c) || PointerBuffer.class.equals(c) ) {
|
||||
return TypeKind.BYTE;
|
||||
} else if ( FloatBuffer.class.equals(c) ) {
|
||||
return TypeKind.FLOAT;
|
||||
} else if ( LongBuffer.class.equals(c) ) {
|
||||
return TypeKind.LONG;
|
||||
} else {
|
||||
public static PrimitiveType.Kind getPrimitiveKindFromBufferClass(Class c) {
|
||||
if ( IntBuffer.class.equals(c) )
|
||||
return PrimitiveType.Kind.INT;
|
||||
else if ( DoubleBuffer.class.equals(c) )
|
||||
return PrimitiveType.Kind.DOUBLE;
|
||||
else if ( ShortBuffer.class.equals(c) )
|
||||
return PrimitiveType.Kind.SHORT;
|
||||
else if ( ByteBuffer.class.equals(c) || PointerBuffer.class.equals(c) )
|
||||
return PrimitiveType.Kind.BYTE;
|
||||
else if ( FloatBuffer.class.equals(c) )
|
||||
return PrimitiveType.Kind.FLOAT;
|
||||
else if ( LongBuffer.class.equals(c) )
|
||||
return PrimitiveType.Kind.LONG;
|
||||
else
|
||||
throw new RuntimeException(c + " is not allowed");
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Class<? extends Annotation> getClassFromType(DeclaredType t) {
|
||||
try {
|
||||
return (Class<? extends Annotation>)Class.forName(t.toString());
|
||||
return (Class<? extends Annotation>)Class.forName(t.getDeclaration().getQualifiedName());
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void getNativeTypeFromAnnotatedPrimitiveType(TypeKind kind) {
|
||||
private void getNativeTypeFromAnnotatedPrimitiveType(PrimitiveType.Kind kind) {
|
||||
native_types = translateAnnotations();
|
||||
if ( native_types.isEmpty() ) {
|
||||
if ( native_types.size() == 0 )
|
||||
native_types.add(type_map.getNativeTypeFromPrimitiveType(kind));
|
||||
}
|
||||
}
|
||||
|
||||
private void visitClassType(DeclaredType t) {
|
||||
public void visitClassType(ClassType t) {
|
||||
is_indirect = true;
|
||||
|
||||
Class<?> c = getClassFromType(t);
|
||||
|
|
@ -169,25 +169,30 @@ public class NativeTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
|
|||
native_types = new ArrayList<Class>();
|
||||
native_types.add(type_map.getVoidType());
|
||||
} else if ( Buffer.class.isAssignableFrom(c) || PointerBuffer.class.isAssignableFrom(c) ) {
|
||||
TypeKind kind = getPrimitiveKindFromBufferClass(c);
|
||||
PrimitiveType.Kind kind = getPrimitiveKindFromBufferClass(c);
|
||||
getNativeTypeFromAnnotatedPrimitiveType(kind);
|
||||
} else if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(c) ) {
|
||||
native_types = new ArrayList<Class>();
|
||||
native_types.add(PointerWrapper.class);
|
||||
|
||||
is_indirect = false;
|
||||
} else {
|
||||
} else
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitPrimitive(PrimitiveType t, Void p) {
|
||||
public void visitPrimitiveType(PrimitiveType t) {
|
||||
getNativeTypeFromAnnotatedPrimitiveType(t.getKind());
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
private void visitInterfaceType(DeclaredType t) {
|
||||
public void visitDeclaredType(DeclaredType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitEnumType(EnumType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitInterfaceType(InterfaceType t) {
|
||||
// See ARB_debug_label.glObjectPtrLabel
|
||||
Class<?> c = getClassFromType(t);
|
||||
if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(c) ) {
|
||||
|
|
@ -195,39 +200,26 @@ public class NativeTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
|
|||
native_types.add(PointerWrapper.class);
|
||||
|
||||
is_indirect = false;
|
||||
} else {
|
||||
} else
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitDeclared(DeclaredType t, Void p) {
|
||||
if ( t.asElement().getKind().isInterface() ) {
|
||||
visitInterfaceType(t);
|
||||
} else if ( t.asElement().getKind().isClass() ) {
|
||||
visitClassType(t);
|
||||
}
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
// Check if the annotation is itself annotated with a certain annotation type
|
||||
|
||||
/* Check if the annotation is itself annotated with a certain annotation type
|
||||
* @discuss compare (DeclaredType).getAnnotation(Class) and (Element).getAnnotation(Class), they mean different Annotation's.
|
||||
*/
|
||||
public static <T extends Annotation> T getAnnotation(AnnotationMirror annotation, Class<T> type) {
|
||||
return annotation.getAnnotationType().asElement().getAnnotation(type);
|
||||
return annotation.getAnnotationType().getDeclaration().getAnnotation(type);
|
||||
}
|
||||
|
||||
private static Class translateAnnotation(AnnotationMirror annotation) {
|
||||
NativeType native_type = getAnnotation(annotation, NativeType.class);
|
||||
if ( native_type != null ) {
|
||||
return getClassFromType(annotation.getAnnotationType());
|
||||
} else {
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private List<Class> translateAnnotations() {
|
||||
List<Class> result = new ArrayList<Class>();
|
||||
private Collection<Class> translateAnnotations() {
|
||||
Collection<Class> result = new ArrayList<Class>();
|
||||
for ( AnnotationMirror annotation : Utils.getSortedAnnotations(declaration.getAnnotationMirrors()) ) {
|
||||
Class translated_result = translateAnnotation(annotation);
|
||||
if ( translated_result != null ) {
|
||||
|
|
@ -237,13 +229,25 @@ public class NativeTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitNoType(NoType t, Void p) {
|
||||
native_types = translateAnnotations();
|
||||
if ( native_types.isEmpty() ) {
|
||||
native_types.add(void.class);
|
||||
}
|
||||
return DEFAULT_VALUE;
|
||||
public void visitReferenceType(ReferenceType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitTypeMirror(TypeMirror t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitTypeVariable(TypeVariable t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitVoidType(VoidType t) {
|
||||
native_types = translateAnnotations();
|
||||
if ( native_types.size() == 0 )
|
||||
native_types.add(void.class);
|
||||
}
|
||||
|
||||
public void visitWildcardType(WildcardType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,21 +42,19 @@ package org.lwjgl.util.generator;
|
|||
* $Id$
|
||||
*/
|
||||
|
||||
import com.sun.mirror.declaration.*;
|
||||
import com.sun.mirror.type.*;
|
||||
import com.sun.mirror.util.*;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.nio.*;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.type.DeclaredType;
|
||||
import javax.lang.model.type.PrimitiveType;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
import javax.lang.model.util.SimpleTypeVisitor6;
|
||||
|
||||
public class PostfixTranslator extends SimpleTypeVisitor6<Void, Void> {
|
||||
public class PostfixTranslator implements TypeVisitor {
|
||||
private final StringBuilder signature = new StringBuilder();
|
||||
private final Element declaration;
|
||||
private final Declaration declaration;
|
||||
private final TypeMap type_map;
|
||||
|
||||
public PostfixTranslator(TypeMap type_map, Element declaration) {
|
||||
public PostfixTranslator(TypeMap type_map, Declaration declaration) {
|
||||
this.declaration = declaration;
|
||||
this.type_map = type_map;
|
||||
}
|
||||
|
|
@ -65,39 +63,52 @@ public class PostfixTranslator extends SimpleTypeVisitor6<Void, Void> {
|
|||
return signature.toString();
|
||||
}
|
||||
|
||||
private static TypeKind getPrimitiveKindFromBufferClass(Class c) {
|
||||
if ( IntBuffer.class.equals(c) || int.class.equals(c) )
|
||||
return TypeKind.INT;
|
||||
else if ( DoubleBuffer.class.equals(c) || double.class.equals(c) )
|
||||
return TypeKind.DOUBLE;
|
||||
else if ( ShortBuffer.class.equals(c) || short.class.equals(c) )
|
||||
return TypeKind.SHORT;
|
||||
else if ( ByteBuffer.class.equals(c) || byte.class.equals(c) )
|
||||
return TypeKind.BYTE;
|
||||
else if ( FloatBuffer.class.equals(c) || float.class.equals(c) )
|
||||
return TypeKind.FLOAT;
|
||||
else if ( LongBuffer.class.equals(c) || long.class.equals(c) )
|
||||
return TypeKind.LONG;
|
||||
public void visitAnnotationType(AnnotationType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitArrayType(ArrayType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
private static PrimitiveType.Kind getPrimitiveKindFromBufferClass(Class c) {
|
||||
if (IntBuffer.class.equals(c) || int.class.equals(c) )
|
||||
return PrimitiveType.Kind.INT;
|
||||
else if (DoubleBuffer.class.equals(c) || double.class.equals(c) )
|
||||
return PrimitiveType.Kind.DOUBLE;
|
||||
else if (ShortBuffer.class.equals(c) || short.class.equals(c) )
|
||||
return PrimitiveType.Kind.SHORT;
|
||||
else if (ByteBuffer.class.equals(c) || byte.class.equals(c) )
|
||||
return PrimitiveType.Kind.BYTE;
|
||||
else if (FloatBuffer.class.equals(c) || float.class.equals(c))
|
||||
return PrimitiveType.Kind.FLOAT;
|
||||
else if (LongBuffer.class.equals(c) || long.class.equals(c) )
|
||||
return PrimitiveType.Kind.LONG;
|
||||
else
|
||||
throw new RuntimeException(c + " is not allowed");
|
||||
}
|
||||
|
||||
private void visitClassType(DeclaredType t) {
|
||||
public void visitClassType(ClassType t) {
|
||||
Class<?> c = NativeTypeTranslator.getClassFromType(t);
|
||||
TypeKind kind = getPrimitiveKindFromBufferClass(c);
|
||||
PrimitiveType.Kind kind = getPrimitiveKindFromBufferClass(c);
|
||||
visitPrimitiveTypeKind(kind);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitDeclared(DeclaredType t, Void o) {
|
||||
if ( t.asElement().getKind().isClass() )
|
||||
visitClassType(t);
|
||||
return DEFAULT_VALUE;
|
||||
public void visitDeclaredType(DeclaredType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitEnumType(EnumType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitInterfaceType(InterfaceType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
private boolean translateAnnotation(AnnotationMirror annotation) {
|
||||
NativeType native_type = NativeTypeTranslator.getAnnotation(annotation, NativeType.class);
|
||||
if ( native_type != null ) {
|
||||
if (native_type != null) {
|
||||
Class<? extends Annotation> annotation_class = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
|
||||
signature.append(type_map.translateAnnotation(annotation_class));
|
||||
return true;
|
||||
|
|
@ -107,28 +118,26 @@ public class PostfixTranslator extends SimpleTypeVisitor6<Void, Void> {
|
|||
|
||||
private boolean translateAnnotations() {
|
||||
boolean result = false;
|
||||
for ( AnnotationMirror annotation : Utils.getSortedAnnotations(declaration.getAnnotationMirrors()) )
|
||||
if ( translateAnnotation(annotation) ) {
|
||||
if ( result )
|
||||
for (AnnotationMirror annotation : Utils.getSortedAnnotations(declaration.getAnnotationMirrors()))
|
||||
if (translateAnnotation(annotation)) {
|
||||
if (result)
|
||||
throw new RuntimeException("Multiple native types");
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitPrimitive(PrimitiveType t, Void o) {
|
||||
public void visitPrimitiveType(PrimitiveType t) {
|
||||
visitPrimitiveTypeKind(t.getKind());
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
private void visitPrimitiveTypeKind(TypeKind kind) {
|
||||
private void visitPrimitiveTypeKind(PrimitiveType.Kind kind) {
|
||||
boolean annotated_translation = translateAnnotations();
|
||||
if ( annotated_translation )
|
||||
if (annotated_translation)
|
||||
return;
|
||||
// No annotation type was specified, fall back to default
|
||||
String type;
|
||||
switch ( kind ) {
|
||||
switch (kind) {
|
||||
case INT:
|
||||
type = "i";
|
||||
break;
|
||||
|
|
@ -152,4 +161,23 @@ public class PostfixTranslator extends SimpleTypeVisitor6<Void, Void> {
|
|||
}
|
||||
signature.append(type);
|
||||
}
|
||||
|
||||
public void visitReferenceType(ReferenceType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitTypeMirror(TypeMirror t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitTypeVariable(TypeVariable t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitVoidType(VoidType t) {
|
||||
}
|
||||
|
||||
public void visitWildcardType(WildcardType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
}
|
||||
|
|
@ -29,6 +29,7 @@
|
|||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.lwjgl.util.generator;
|
||||
|
||||
/**
|
||||
|
|
@ -36,41 +37,35 @@ package org.lwjgl.util.generator;
|
|||
* This class generates the initNatives native function.
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$ $Id$
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
|
||||
import com.sun.mirror.declaration.*;
|
||||
import com.sun.mirror.type.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class RegisterStubsGenerator {
|
||||
|
||||
public static void generateMethodsNativeStubBind(PrintWriter writer, TypeElement d, boolean generate_error_checks, boolean context_specific) {
|
||||
Iterator<? extends ExecutableElement> it = Utils.getMethods(d).iterator();
|
||||
while ( it.hasNext() ) {
|
||||
ExecutableElement method = it.next();
|
||||
public static void generateMethodsNativeStubBind(PrintWriter writer, InterfaceDeclaration d, boolean generate_error_checks, boolean context_specific) {
|
||||
Iterator<? extends MethodDeclaration> it = d.getMethods().iterator();
|
||||
while (it.hasNext()) {
|
||||
MethodDeclaration method = it.next();
|
||||
Alternate alt_annotation = method.getAnnotation(Alternate.class);
|
||||
if ( (alt_annotation != null && (!alt_annotation.nativeAlt() || alt_annotation.skipNative())) || method.getAnnotation(Reuse.class) != null ) {
|
||||
if ( (alt_annotation != null && (!alt_annotation.nativeAlt() || alt_annotation.skipNative())) || method.getAnnotation(Reuse.class) != null )
|
||||
continue;
|
||||
}
|
||||
EnumSet<Platform> platforms;
|
||||
PlatformDependent platform_annotation = method.getAnnotation(PlatformDependent.class);
|
||||
if ( platform_annotation != null ) {
|
||||
if (platform_annotation != null)
|
||||
platforms = EnumSet.copyOf(Arrays.asList(platform_annotation.value()));
|
||||
} else {
|
||||
else
|
||||
platforms = EnumSet.of(Platform.ALL);
|
||||
}
|
||||
for ( Platform platform : platforms ) {
|
||||
for (Platform platform : platforms) {
|
||||
platform.printPrologue(writer);
|
||||
boolean has_buffer_parameter = Utils.hasMethodBufferObjectParameter(method);
|
||||
printMethodNativeStubBind(writer, d, method, platform, Mode.NORMAL, it.hasNext() || has_buffer_parameter, generate_error_checks, context_specific);
|
||||
if ( has_buffer_parameter ) {
|
||||
if (has_buffer_parameter) {
|
||||
printMethodNativeStubBind(writer, d, method, platform, Mode.BUFFEROBJECT, it.hasNext(), generate_error_checks, context_specific);
|
||||
}
|
||||
platform.printEpilogue(writer);
|
||||
|
|
@ -79,30 +74,27 @@ public class RegisterStubsGenerator {
|
|||
writer.println();
|
||||
}
|
||||
|
||||
private static String getTypeSignature(TypeMirror type) {
|
||||
SignatureTranslator v = new SignatureTranslator();
|
||||
type.accept(v, null);
|
||||
private static String getTypeSignature(TypeMirror type, boolean add_position_signature) {
|
||||
SignatureTranslator v = new SignatureTranslator(add_position_signature);
|
||||
type.accept(v);
|
||||
return v.getSignature();
|
||||
}
|
||||
|
||||
private static String getMethodSignature(ExecutableElement method, Mode mode) {
|
||||
List<? extends VariableElement> params = method.getParameters();
|
||||
private static String getMethodSignature(MethodDeclaration method, Mode mode) {
|
||||
Collection<ParameterDeclaration> params = method.getParameters();
|
||||
String signature = "(";
|
||||
for ( VariableElement param : params ) {
|
||||
if ( param.getAnnotation(Result.class) != null || (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative()) ) {
|
||||
for (ParameterDeclaration param : params) {
|
||||
if ( param.getAnnotation(Result.class) != null || (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative()) )
|
||||
continue;
|
||||
}
|
||||
|
||||
final Constant constant_annotation = param.getAnnotation(Constant.class);
|
||||
if ( constant_annotation != null && constant_annotation.isNative() ) {
|
||||
if ( constant_annotation != null && constant_annotation.isNative() )
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null ) {
|
||||
if (mode == Mode.BUFFEROBJECT && param.getAnnotation(BufferObject.class) != null)
|
||||
signature += "J";
|
||||
} else {
|
||||
signature += getTypeSignature(param.asType());
|
||||
}
|
||||
else
|
||||
signature += getTypeSignature(param.getType(), true);
|
||||
}
|
||||
|
||||
final TypeMirror result_type = Utils.getMethodReturnType(method);
|
||||
|
|
@ -110,40 +102,33 @@ public class RegisterStubsGenerator {
|
|||
final AutoSize auto_size_annotation = method.getAnnotation(AutoSize.class);
|
||||
|
||||
final boolean isNIOBuffer = Utils.getNIOBufferType(result_type) != null;
|
||||
if ( isNIOBuffer && (auto_size_annotation == null || !auto_size_annotation.isNative()) ) {
|
||||
if ( isNIOBuffer && (auto_size_annotation == null || !auto_size_annotation.isNative()) )
|
||||
signature += "J";
|
||||
}
|
||||
|
||||
final String result_type_signature = isNIOBuffer ? "Ljava/nio/ByteBuffer;" : getTypeSignature(result_type);
|
||||
if ( cached_result_annotation != null ) {
|
||||
final String result_type_signature = isNIOBuffer ? "Ljava/nio/ByteBuffer;" : getTypeSignature(result_type, false);
|
||||
if ( cached_result_annotation != null )
|
||||
signature += result_type_signature;
|
||||
}
|
||||
|
||||
signature += ")";
|
||||
signature += result_type_signature;
|
||||
return signature;
|
||||
}
|
||||
|
||||
private static final Pattern GL_PATTERN = Pattern.compile("gl");
|
||||
|
||||
private static void printMethodNativeStubBind(PrintWriter writer, TypeElement d, ExecutableElement method, Platform platform, Mode mode, boolean has_more, boolean generate_error_checks, boolean context_specific) {
|
||||
private static void printMethodNativeStubBind(PrintWriter writer, InterfaceDeclaration d, MethodDeclaration method, Platform platform, Mode mode, boolean has_more, boolean generate_error_checks, boolean context_specific) {
|
||||
writer.print("\t\t{\"" + Utils.getSimpleNativeMethodName(method, generate_error_checks, context_specific));
|
||||
if ( mode == Mode.BUFFEROBJECT ) {
|
||||
if (mode == Mode.BUFFEROBJECT)
|
||||
writer.print(Utils.BUFFER_OBJECT_METHOD_POSTFIX);
|
||||
}
|
||||
writer.print("\", \"" + getMethodSignature(method, mode) + "\", (void *)&");
|
||||
writer.print(Utils.getQualifiedNativeMethodName(Utils.getQualifiedClassName(d), method, generate_error_checks, context_specific));
|
||||
if ( mode == Mode.BUFFEROBJECT ) {
|
||||
if (mode == Mode.BUFFEROBJECT)
|
||||
writer.print(Utils.BUFFER_OBJECT_METHOD_POSTFIX);
|
||||
}
|
||||
|
||||
final Alternate alt_annotation = method.getAnnotation(Alternate.class);
|
||||
final String methodName = alt_annotation == null ? method.getSimpleName().toString() : alt_annotation.value();
|
||||
String opengl_handle_name = GL_PATTERN.matcher(methodName).replaceFirst(platform.getPrefix());
|
||||
final String methodName = alt_annotation == null ? method.getSimpleName() : alt_annotation.value();
|
||||
String opengl_handle_name = methodName.replaceFirst("gl", platform.getPrefix());
|
||||
writer.print(", \"" + opengl_handle_name + "\", (void *)&" + methodName + ", " + (method.getAnnotation(Optional.class) == null ? "false" : "true") + "}");
|
||||
if ( has_more ) {
|
||||
if (has_more)
|
||||
writer.println(",");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,57 +42,55 @@ package org.lwjgl.util.generator;
|
|||
*/
|
||||
|
||||
import org.lwjgl.PointerBuffer;
|
||||
import org.lwjgl.PointerWrapper;
|
||||
|
||||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.lang.model.type.ArrayType;
|
||||
import javax.lang.model.type.DeclaredType;
|
||||
import javax.lang.model.type.NoType;
|
||||
import javax.lang.model.type.PrimitiveType;
|
||||
import javax.lang.model.util.SimpleTypeVisitor6;
|
||||
import com.sun.mirror.type.*;
|
||||
import com.sun.mirror.util.*;
|
||||
|
||||
class SignatureTranslator extends SimpleTypeVisitor6<Void, Void> {
|
||||
import java.nio.*;
|
||||
|
||||
class SignatureTranslator implements TypeVisitor {
|
||||
private final boolean add_position_signature;
|
||||
private final StringBuilder signature = new StringBuilder();
|
||||
|
||||
SignatureTranslator() {}
|
||||
|
||||
private static final Pattern DOT_PATTERN = Pattern.compile("\\.");
|
||||
SignatureTranslator(boolean add_position_signature) {
|
||||
this.add_position_signature = add_position_signature;
|
||||
}
|
||||
|
||||
private static String getNativeNameFromClassName(String class_name) {
|
||||
return DOT_PATTERN.matcher(class_name).replaceAll("/");
|
||||
return class_name.replaceAll("\\.", "/");
|
||||
}
|
||||
|
||||
public String getSignature() {
|
||||
return signature.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitArray(ArrayType t, Void o) {
|
||||
public void visitAnnotationType(AnnotationType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitArrayType(ArrayType t) {
|
||||
final Class type = Utils.getJavaType(t.getComponentType());
|
||||
if ( CharSequence.class.isAssignableFrom(type) )
|
||||
signature.append("J");
|
||||
else if ( Buffer.class.isAssignableFrom(type) )
|
||||
signature.append("[Ljava/nio/ByteBuffer;");
|
||||
else if ( PointerWrapper.class.isAssignableFrom(type) )
|
||||
else if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(type) )
|
||||
signature.append("[L" + getNativeNameFromClassName(type.getName()) + ";");
|
||||
else
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
private void visitClassType(DeclaredType t) {
|
||||
public void visitClassType(ClassType t) {
|
||||
Class type = NativeTypeTranslator.getClassFromType(t);
|
||||
|
||||
if ( PointerWrapper.class.isAssignableFrom(type) || (Utils.isAddressableType(type) && !String.class.equals(type)) )
|
||||
if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(type) || (Utils.isAddressableType(type) && !String.class.equals(type)) )
|
||||
signature.append("J");
|
||||
else {
|
||||
String type_name;
|
||||
if ( (CharSequence.class.isAssignableFrom(type) && !String.class.equals(type)) || CharSequence[].class.isAssignableFrom(type) || PointerBuffer.class.isAssignableFrom(type) )
|
||||
type_name = ByteBuffer.class.getName();
|
||||
else
|
||||
type_name = t.toString();
|
||||
type_name = t.getDeclaration().getQualifiedName();
|
||||
|
||||
signature.append("L");
|
||||
signature.append(getNativeNameFromClassName(type_name));
|
||||
|
|
@ -100,26 +98,24 @@ class SignatureTranslator extends SimpleTypeVisitor6<Void, Void> {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitDeclared(DeclaredType t, Void o) {
|
||||
if ( t.asElement().getKind().isClass() )
|
||||
visitClassType(t);
|
||||
else if ( t.asElement().getKind().isInterface() )
|
||||
visitInterfaceType(t);
|
||||
return DEFAULT_VALUE;
|
||||
public void visitDeclaredType(DeclaredType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
private void visitInterfaceType(DeclaredType t) {
|
||||
public void visitEnumType(EnumType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitInterfaceType(InterfaceType t) {
|
||||
Class type = NativeTypeTranslator.getClassFromType(t);
|
||||
if ( PointerWrapper.class.isAssignableFrom(type) )
|
||||
if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(type) )
|
||||
signature.append("J");
|
||||
else
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitPrimitive(PrimitiveType t, Void o) {
|
||||
switch ( t.getKind() ) {
|
||||
public void visitPrimitiveType(PrimitiveType t) {
|
||||
switch (t.getKind()) {
|
||||
case BOOLEAN:
|
||||
signature.append("Z");
|
||||
break;
|
||||
|
|
@ -144,13 +140,25 @@ class SignatureTranslator extends SimpleTypeVisitor6<Void, Void> {
|
|||
default:
|
||||
throw new RuntimeException("Unsupported type " + t);
|
||||
}
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitNoType(NoType t, Void o) {
|
||||
public void visitReferenceType(ReferenceType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitTypeMirror(TypeMirror t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitTypeVariable(TypeVariable t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitVoidType(VoidType t) {
|
||||
signature.append("V");
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
public void visitWildcardType(WildcardType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,31 +33,30 @@ package org.lwjgl.util.generator;
|
|||
|
||||
/**
|
||||
*
|
||||
* This class represent a parameter configuration. There are multiple TypeInfos
|
||||
* in case of multityped parameters.
|
||||
* This class represent a parameter configuration. There are multiple
|
||||
* TypeInfos in case of multityped parameters.
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$ $Id$
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
import org.lwjgl.PointerBuffer;
|
||||
import org.lwjgl.util.generator.opengl.GLvoid;
|
||||
|
||||
import com.sun.mirror.declaration.*;
|
||||
import com.sun.mirror.type.*;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.nio.*;
|
||||
import java.util.*;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import java.nio.*;
|
||||
|
||||
public class TypeInfo {
|
||||
|
||||
public static final String UNSIGNED_PARAMETER_NAME = "unsigned";
|
||||
|
||||
private final Signedness signedness;
|
||||
private final Class type;
|
||||
private final String auto_type;
|
||||
private final Class type;
|
||||
private final String auto_type;
|
||||
|
||||
private TypeInfo(Class type, Signedness signedness, String auto_type) {
|
||||
this.type = type;
|
||||
|
|
@ -74,15 +73,14 @@ public class TypeInfo {
|
|||
}
|
||||
|
||||
public String getAutoType() {
|
||||
if ( auto_type == null ) {
|
||||
if (auto_type == null)
|
||||
throw new RuntimeException("No auto type assigned");
|
||||
}
|
||||
return auto_type;
|
||||
}
|
||||
|
||||
private static Class getTypeFromPrimitiveKind(TypeKind kind) {
|
||||
private static Class getTypeFromPrimitiveKind(PrimitiveType.Kind kind) {
|
||||
Class type;
|
||||
switch ( kind ) {
|
||||
switch (kind) {
|
||||
case LONG:
|
||||
type = long.class;
|
||||
break;
|
||||
|
|
@ -110,9 +108,9 @@ public class TypeInfo {
|
|||
return type;
|
||||
}
|
||||
|
||||
private static Class getBufferTypeFromPrimitiveKind(TypeKind kind, AnnotationMirror annotation) {
|
||||
private static Class getBufferTypeFromPrimitiveKind(PrimitiveType.Kind kind, AnnotationMirror annotation) {
|
||||
Class type;
|
||||
switch ( kind ) {
|
||||
switch (kind) {
|
||||
case INT:
|
||||
type = IntBuffer.class;
|
||||
break;
|
||||
|
|
@ -126,14 +124,12 @@ public class TypeInfo {
|
|||
type = ShortBuffer.class;
|
||||
break;
|
||||
case LONG:
|
||||
if ( annotation.getAnnotationType().asElement().getAnnotation(PointerType.class) != null ) {
|
||||
if ( annotation.getAnnotationType().getDeclaration().getAnnotation(PointerType.class) != null )
|
||||
type = PointerBuffer.class;
|
||||
} else {
|
||||
else
|
||||
type = LongBuffer.class;
|
||||
}
|
||||
break;
|
||||
case BYTE: /* fall through */
|
||||
|
||||
case BOOLEAN:
|
||||
type = ByteBuffer.class;
|
||||
break;
|
||||
|
|
@ -148,34 +144,33 @@ public class TypeInfo {
|
|||
return new TypeInfo(java_type, Signedness.NONE, null);
|
||||
}
|
||||
|
||||
public static Map<VariableElement, TypeInfo> getDefaultTypeInfoMap(ExecutableElement method) {
|
||||
Map<VariableElement, TypeInfo> map = new HashMap<VariableElement, TypeInfo>();
|
||||
for ( VariableElement param : method.getParameters() ) {
|
||||
TypeInfo type_info = getDefaultTypeInfo(param.asType());
|
||||
public static Map<ParameterDeclaration, TypeInfo> getDefaultTypeInfoMap(MethodDeclaration method) {
|
||||
Map<ParameterDeclaration, TypeInfo> map = new HashMap<ParameterDeclaration, TypeInfo>();
|
||||
for (ParameterDeclaration param : method.getParameters()) {
|
||||
TypeInfo type_info = getDefaultTypeInfo(param.getType());
|
||||
map.put(param, type_info);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private static Collection<TypeInfo> getTypeInfos(TypeMap type_map, VariableElement param) {
|
||||
List<? extends AnnotationMirror> annotations = Utils.getSortedAnnotations(param.getAnnotationMirrors());
|
||||
GLvoid void_annotation = param.getAnnotation(GLvoid.class);
|
||||
|
||||
private static Collection<TypeInfo> getTypeInfos(TypeMap type_map, Declaration param, TypeMirror decl_type) {
|
||||
Collection<AnnotationMirror> annotations = Utils.getSortedAnnotations(param.getAnnotationMirrors());
|
||||
Map<Class, TypeInfo> types = new HashMap<Class, TypeInfo>();
|
||||
Collection<TypeInfo> multityped_result = new ArrayList<TypeInfo>();
|
||||
boolean add_default_type = true;
|
||||
for ( AnnotationMirror annotation : annotations ) {
|
||||
for (AnnotationMirror annotation : annotations) {
|
||||
NativeType native_type_annotation = NativeTypeTranslator.getAnnotation(annotation, NativeType.class);
|
||||
if ( native_type_annotation != null ) {
|
||||
if (native_type_annotation != null) {
|
||||
Class<? extends Annotation> annotation_type = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
|
||||
Signedness signedness = type_map.getSignednessFromType(annotation_type);
|
||||
Class inverse_type = type_map.getInverseType(annotation_type);
|
||||
String auto_type = type_map.getAutoTypeFromAnnotation(annotation);
|
||||
if ( inverse_type != null ) {
|
||||
if ( types.containsKey(inverse_type) ) {
|
||||
if (inverse_type != null) {
|
||||
if (types.containsKey(inverse_type)) {
|
||||
TypeInfo inverse_type_info = types.get(inverse_type);
|
||||
String inverse_auto_type = inverse_type_info.getAutoType();
|
||||
auto_type = signedness == Signedness.UNSIGNED ? auto_type + " : " + inverse_auto_type : inverse_auto_type + " : " + auto_type;
|
||||
auto_type = signedness == Signedness.UNSIGNED ? auto_type + " : " + inverse_auto_type :
|
||||
inverse_auto_type + " : " + auto_type;
|
||||
auto_type = UNSIGNED_PARAMETER_NAME + " ? " + auto_type;
|
||||
signedness = Signedness.BOTH;
|
||||
types.remove(inverse_type);
|
||||
|
|
@ -183,59 +178,59 @@ public class TypeInfo {
|
|||
}
|
||||
}
|
||||
Class type;
|
||||
TypeKind kind;
|
||||
PrimitiveType.Kind kind;
|
||||
GLvoid void_annotation = param.getAnnotation(GLvoid.class);
|
||||
kind = void_annotation == null ? type_map.getPrimitiveTypeFromNativeType(annotation_type) : void_annotation.value();
|
||||
if ( Utils.getNIOBufferType(param.asType()) != null ) {
|
||||
if (Utils.getNIOBufferType(decl_type) != null)
|
||||
type = getBufferTypeFromPrimitiveKind(kind, annotation);
|
||||
} else {
|
||||
else
|
||||
type = getTypeFromPrimitiveKind(kind);
|
||||
}
|
||||
TypeInfo type_info = new TypeInfo(type, signedness, auto_type);
|
||||
types.put(annotation_type, type_info);
|
||||
multityped_result.add(type_info);
|
||||
add_default_type = false;
|
||||
}
|
||||
}
|
||||
if ( add_default_type ) {
|
||||
TypeInfo default_type_info = getDefaultTypeInfo(param.asType());
|
||||
if (add_default_type) {
|
||||
TypeInfo default_type_info = getDefaultTypeInfo(decl_type);
|
||||
Collection<TypeInfo> result = new ArrayList<TypeInfo>();
|
||||
result.add(default_type_info);
|
||||
return result;
|
||||
} else {
|
||||
} else
|
||||
return multityped_result;
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<VariableElement, Collection<TypeInfo>> getTypeInfoMap(TypeMap type_map, ExecutableElement method) {
|
||||
Map<VariableElement, Collection<TypeInfo>> map = new HashMap<VariableElement, Collection<TypeInfo>>();
|
||||
for ( VariableElement param : method.getParameters() ) {
|
||||
Collection<TypeInfo> types = getTypeInfos(type_map, param);
|
||||
private static Map<ParameterDeclaration, Collection<TypeInfo>> getTypeInfoMap(TypeMap type_map, MethodDeclaration method) {
|
||||
Map<ParameterDeclaration, Collection<TypeInfo>> map = new HashMap<ParameterDeclaration, Collection<TypeInfo>>();
|
||||
for (ParameterDeclaration param : method.getParameters()) {
|
||||
Collection<TypeInfo> types = getTypeInfos(type_map, param, param.getType());
|
||||
map.put(param, types);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public static Collection<Map<VariableElement, TypeInfo>> getTypeInfoCrossProduct(TypeMap type_map, ExecutableElement method) {
|
||||
List<? extends VariableElement> parameter_collection = method.getParameters();
|
||||
Collection<Map<VariableElement, TypeInfo>> cross_product = new ArrayList<Map<VariableElement, TypeInfo>>();
|
||||
getCrossProductRecursive(0, parameter_collection, getTypeInfoMap(type_map, method),
|
||||
new HashMap<VariableElement, TypeInfo>(), cross_product);
|
||||
public static Collection<Map<ParameterDeclaration, TypeInfo>> getTypeInfoCrossProduct(TypeMap type_map, MethodDeclaration method) {
|
||||
Collection<ParameterDeclaration> parameter_collection = method.getParameters();
|
||||
ParameterDeclaration[] parameters = new ParameterDeclaration[parameter_collection.size()];
|
||||
parameter_collection.toArray(parameters);
|
||||
Collection<Map<ParameterDeclaration, TypeInfo>> cross_product = new ArrayList<Map<ParameterDeclaration, TypeInfo>>();
|
||||
getCrossProductRecursive(0, parameters, getTypeInfoMap(type_map, method),
|
||||
new HashMap<ParameterDeclaration, TypeInfo>(), cross_product);
|
||||
return cross_product;
|
||||
}
|
||||
|
||||
private static void getCrossProductRecursive(int index, List<? extends VariableElement> parameters, Map<VariableElement, Collection<TypeInfo>> typeinfos_map, Map<VariableElement, TypeInfo> current_instance, Collection<Map<VariableElement, TypeInfo>> cross_product) {
|
||||
if ( index == parameters.size() ) {
|
||||
/**
|
||||
* the last parameter is treated as multi-type only
|
||||
*/
|
||||
private static void getCrossProductRecursive(int index, ParameterDeclaration[] parameters, Map<ParameterDeclaration,
|
||||
Collection<TypeInfo>> typeinfos_map, Map<ParameterDeclaration, TypeInfo> current_instance,
|
||||
Collection<Map<ParameterDeclaration, TypeInfo>> cross_product) {
|
||||
if (index == parameters.length) {
|
||||
cross_product.add(current_instance);
|
||||
return;
|
||||
}
|
||||
VariableElement param = parameters.get(index);
|
||||
ParameterDeclaration param = parameters[index];
|
||||
Collection<TypeInfo> typeinfos = typeinfos_map.get(param);
|
||||
if ( typeinfos != null ) {
|
||||
for ( TypeInfo typeinfo : typeinfos ) {
|
||||
Map<VariableElement, TypeInfo> instance = new HashMap<VariableElement, TypeInfo>(current_instance);
|
||||
if (typeinfos != null) {
|
||||
for (TypeInfo typeinfo : typeinfos) {
|
||||
Map<ParameterDeclaration, TypeInfo> instance = new HashMap<ParameterDeclaration, TypeInfo>(current_instance);
|
||||
instance.put(param, typeinfo);
|
||||
getCrossProductRecursive(index + 1, parameters, typeinfos_map, instance, cross_product);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,19 +41,19 @@ package org.lwjgl.util.generator;
|
|||
* $Id$
|
||||
*/
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import com.sun.mirror.declaration.*;
|
||||
import com.sun.mirror.type.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.annotation.Annotation;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
|
||||
public interface TypeMap {
|
||||
void printCapabilitiesInit(PrintWriter writer);
|
||||
String getCapabilities();
|
||||
String getAPIUtilParam(boolean comma);
|
||||
void printErrorCheckMethod(PrintWriter writer, ExecutableElement method, String tabs);
|
||||
void printErrorCheckMethod(PrintWriter writer, MethodDeclaration method, String tabs);
|
||||
String getRegisterNativesFunctionName();
|
||||
TypeKind getPrimitiveTypeFromNativeType(Class<? extends Annotation> native_type);
|
||||
PrimitiveType.Kind getPrimitiveTypeFromNativeType(Class<? extends Annotation> native_type);
|
||||
String getTypedefPostfix();
|
||||
String getFunctionPrefix();
|
||||
void printNativeIncludes(PrintWriter writer);
|
||||
|
|
@ -63,7 +63,7 @@ public interface TypeMap {
|
|||
Class[] getValidAnnotationTypes(Class type);
|
||||
Class<? extends Annotation> getVoidType();
|
||||
String translateAnnotation(Class<? extends Annotation> annotation_type);
|
||||
Class getNativeTypeFromPrimitiveType(TypeKind kind);
|
||||
Class getNativeTypeFromPrimitiveType(PrimitiveType.Kind kind);
|
||||
String getAutoTypeFromAnnotation(AnnotationMirror annotation);
|
||||
Class<? extends Annotation> getInverseType(Class<? extends Annotation> type);
|
||||
Signedness getSignednessFromType(Class<? extends Annotation> type);
|
||||
|
|
|
|||
|
|
@ -41,19 +41,19 @@ package org.lwjgl.util.generator;
|
|||
* $Id$
|
||||
*/
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Collection;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import com.sun.mirror.declaration.*;
|
||||
import com.sun.mirror.type.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class TypedefsGenerator {
|
||||
private static void generateNativeTypedefs(TypeMap type_map, PrintWriter writer, ExecutableElement method) {
|
||||
private static void generateNativeTypedefs(TypeMap type_map, PrintWriter writer, MethodDeclaration method) {
|
||||
TypeMirror return_type = method.getReturnType();
|
||||
writer.print("typedef ");
|
||||
writer.print(type_map.getTypedefPostfix());
|
||||
NativeTypeTranslator translator = new NativeTypeTranslator(type_map, method);
|
||||
return_type.accept(translator, null);
|
||||
return_type.accept(translator);
|
||||
writer.print(translator.getSignature());
|
||||
writer.print(" (");
|
||||
writer.print(type_map.getFunctionPrefix());
|
||||
|
|
@ -62,10 +62,10 @@ public class TypedefsGenerator {
|
|||
writer.println(");");
|
||||
}
|
||||
|
||||
private static void generateNativeTypedefsParameters(TypeMap type_map, PrintWriter writer, Collection<? extends VariableElement> params) {
|
||||
if ( params.size() > 0 ) {
|
||||
private static void generateNativeTypedefsParameters(TypeMap type_map, PrintWriter writer, Collection<ParameterDeclaration> params) {
|
||||
if (params.size() > 0) {
|
||||
boolean first = true;
|
||||
for ( VariableElement param : params ) {
|
||||
for ( ParameterDeclaration param : params ) {
|
||||
if ( param.getAnnotation(Helper.class) != null )
|
||||
continue;
|
||||
|
||||
|
|
@ -79,17 +79,17 @@ public class TypedefsGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
private static void generateNativeTypedefsParameter(TypeMap type_map, PrintWriter writer, VariableElement param) {
|
||||
private static void generateNativeTypedefsParameter(TypeMap type_map, PrintWriter writer, ParameterDeclaration param) {
|
||||
NativeTypeTranslator translator = new NativeTypeTranslator(type_map, param);
|
||||
param.asType().accept(translator, null);
|
||||
param.getType().accept(translator);
|
||||
writer.print(translator.getSignature());
|
||||
if ( param.getAnnotation(Result.class) != null || param.getAnnotation(Indirect.class) != null || param.getAnnotation(PointerArray.class) != null )
|
||||
if (param.getAnnotation(Result.class) != null || param.getAnnotation(Indirect.class) != null || param.getAnnotation(PointerArray.class) != null)
|
||||
writer.print("*");
|
||||
writer.print(" " + param.getSimpleName());
|
||||
}
|
||||
|
||||
public static void generateNativeTypedefs(TypeMap type_map, PrintWriter writer, Collection<? extends ExecutableElement> methods) {
|
||||
for ( ExecutableElement method : methods ) {
|
||||
public static void generateNativeTypedefs(TypeMap type_map, PrintWriter writer, Collection<? extends MethodDeclaration> methods) {
|
||||
for (MethodDeclaration method : methods) {
|
||||
if ( method.getAnnotation(Alternate.class) == null && method.getAnnotation(Reuse.class) == null )
|
||||
generateNativeTypedefs(type_map, writer, method);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,10 +36,11 @@ package org.lwjgl.util.generator;
|
|||
* Various utility methods to the generator.
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$ $Id$
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
import org.lwjgl.PointerBuffer;
|
||||
import org.lwjgl.PointerWrapper;
|
||||
import org.lwjgl.util.generator.opengl.GLboolean;
|
||||
import org.lwjgl.util.generator.opengl.GLchar;
|
||||
import org.lwjgl.util.generator.opengl.GLcharARB;
|
||||
|
|
@ -49,13 +50,10 @@ import java.io.PrintWriter;
|
|||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.lang.model.element.*;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
import javax.lang.model.type.TypeVisitor;
|
||||
import javax.lang.model.util.ElementFilter;
|
||||
|
||||
import com.sun.mirror.declaration.*;
|
||||
import com.sun.mirror.type.PrimitiveType;
|
||||
import com.sun.mirror.type.TypeMirror;
|
||||
|
||||
public class Utils {
|
||||
|
||||
|
|
@ -73,47 +71,43 @@ public class Utils {
|
|||
public static final String CACHED_BUFFER_NAME = "old_buffer";
|
||||
private static final String OVERLOADED_METHOD_PREFIX = "n";
|
||||
|
||||
public static String getTypedefName(ExecutableElement method) {
|
||||
public static String getTypedefName(MethodDeclaration method) {
|
||||
Alternate alt_annotation = method.getAnnotation(Alternate.class);
|
||||
return (alt_annotation == null ? method.getSimpleName() : alt_annotation.value()) + TYPEDEF_POSTFIX;
|
||||
}
|
||||
|
||||
public static String getFunctionAddressName(TypeElement interface_decl, ExecutableElement method) {
|
||||
public static String getFunctionAddressName(InterfaceDeclaration interface_decl, MethodDeclaration method) {
|
||||
return getFunctionAddressName(interface_decl, method, false);
|
||||
}
|
||||
|
||||
public static String getFunctionAddressName(TypeElement interface_decl, ExecutableElement method, boolean forceAlt) {
|
||||
public static String getFunctionAddressName(InterfaceDeclaration interface_decl, MethodDeclaration method, boolean forceAlt) {
|
||||
final Alternate alt_annotation = method.getAnnotation(Alternate.class);
|
||||
|
||||
/* Removed prefix so that we can identify reusable entry points, removed postfix because it's not needed and looks nicer.
|
||||
String interfaceName = interface_decl.getSimpleName(); // If we add this back, we need to fix @Reuse (add a param for the template name)
|
||||
if ( alt_annotation == null || (alt_annotation.nativeAlt() && !forceAlt) )
|
||||
return interfaceName + "_" + method.getSimpleName() + FUNCTION_POINTER_POSTFIX;
|
||||
else
|
||||
return interfaceName + "_" + alt_annotation.value() + FUNCTION_POINTER_POSTFIX;
|
||||
*/
|
||||
if ( alt_annotation == null || (alt_annotation.nativeAlt() && !forceAlt) ) {
|
||||
return method.getSimpleName().toString();
|
||||
} else {
|
||||
/* Removed prefix so that we can identify reusable entry points, removed postfix because it's not needed and looks nicer.
|
||||
String interfaceName = interface_decl.getSimpleName(); // If we add this back, we need to fix @Reuse (add a param for the template name)
|
||||
if ( alt_annotation == null || (alt_annotation.nativeAlt() && !forceAlt) )
|
||||
return interfaceName + "_" + method.getSimpleName() + FUNCTION_POINTER_POSTFIX;
|
||||
else
|
||||
return interfaceName + "_" + alt_annotation.value() + FUNCTION_POINTER_POSTFIX;
|
||||
*/
|
||||
if ( alt_annotation == null || (alt_annotation.nativeAlt() && !forceAlt) )
|
||||
return method.getSimpleName();
|
||||
else
|
||||
return alt_annotation.value();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isFinal(Element d) {
|
||||
public static boolean isFinal(InterfaceDeclaration d) {
|
||||
Extension extension_annotation = d.getAnnotation(Extension.class);
|
||||
return extension_annotation == null || extension_annotation.isFinal();
|
||||
}
|
||||
|
||||
private static class AnnotationMirrorComparator implements Comparator<AnnotationMirror> {
|
||||
|
||||
/**
|
||||
* Sort annotations.
|
||||
*/
|
||||
@Override
|
||||
public int compare(AnnotationMirror a1, AnnotationMirror a2) {
|
||||
String n1 = a1.getAnnotationType().toString();
|
||||
String n2 = a2.getAnnotationType().toString();
|
||||
return n1.compareTo(n2);
|
||||
String n1 = a1.getAnnotationType().getDeclaration().getQualifiedName();
|
||||
String n2 = a2.getAnnotationType().getDeclaration().getQualifiedName();
|
||||
int result = n1.compareTo(n2);
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean equals(AnnotationMirror a1, AnnotationMirror a2) {
|
||||
|
|
@ -121,13 +115,13 @@ public class Utils {
|
|||
}
|
||||
}
|
||||
|
||||
public static List<AnnotationMirror> getSortedAnnotations(List<? extends AnnotationMirror> annotations) {
|
||||
public static Collection<AnnotationMirror> getSortedAnnotations(Collection<AnnotationMirror> annotations) {
|
||||
List<AnnotationMirror> annotation_list = new ArrayList<AnnotationMirror>(annotations);
|
||||
Collections.sort(annotation_list, new AnnotationMirrorComparator());
|
||||
return annotation_list;
|
||||
}
|
||||
|
||||
public static String getReferenceName(TypeElement interface_decl, ExecutableElement method, VariableElement param) {
|
||||
public static String getReferenceName(InterfaceDeclaration interface_decl, MethodDeclaration method, ParameterDeclaration param) {
|
||||
return interface_decl.getSimpleName() + "_" + method.getSimpleName() + "_" + param.getSimpleName();
|
||||
}
|
||||
|
||||
|
|
@ -138,7 +132,7 @@ public class Utils {
|
|||
public static boolean isAddressableType(Class type) {
|
||||
if ( type.isArray() ) {
|
||||
final Class component_type = type.getComponentType();
|
||||
return isAddressableTypeImpl(component_type) || PointerWrapper.class.isAssignableFrom(component_type);
|
||||
return isAddressableTypeImpl(component_type) || org.lwjgl.PointerWrapper.class.isAssignableFrom(component_type);
|
||||
}
|
||||
return isAddressableTypeImpl(type);
|
||||
}
|
||||
|
|
@ -149,48 +143,42 @@ public class Utils {
|
|||
|
||||
public static Class getJavaType(TypeMirror type_mirror) {
|
||||
JavaTypeTranslator translator = new JavaTypeTranslator();
|
||||
type_mirror.accept((TypeVisitor)translator, null);
|
||||
type_mirror.accept(translator);
|
||||
return translator.getType();
|
||||
}
|
||||
|
||||
private static boolean hasParameterMultipleTypes(VariableElement param) {
|
||||
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(VariableElement param) {
|
||||
boolean result = Buffer.class.equals(Utils.getJavaType(param.asType()));
|
||||
if ( !result && hasParameterMultipleTypes(param) ) {
|
||||
public static boolean isParameterMultiTyped(ParameterDeclaration param) {
|
||||
boolean result = Buffer.class.equals(Utils.getJavaType(param.getType()));
|
||||
if ( !result && hasParameterMultipleTypes(param) )
|
||||
throw new RuntimeException(param + " not defined as java.nio.Buffer but has multiple types");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static VariableElement findParameter(ExecutableElement method, String name) {
|
||||
for ( VariableElement param : method.getParameters() ) {
|
||||
if ( param.getSimpleName().toString().equals(name) ) {
|
||||
public static ParameterDeclaration findParameter(MethodDeclaration method, String name) {
|
||||
for ( ParameterDeclaration param : method.getParameters() )
|
||||
if ( param.getSimpleName().equals(name) )
|
||||
return param;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("Parameter " + name + " not found");
|
||||
}
|
||||
|
||||
public static void printDocComment(PrintWriter writer, Element decl, ProcessingEnvironment pe) {
|
||||
public static void printDocComment(PrintWriter writer, Declaration decl) {
|
||||
final String overloadsComment;
|
||||
if ( (decl instanceof ExecutableElement) && decl.getAnnotation(Alternate.class) != null ) {
|
||||
if ( (decl instanceof MethodDeclaration) && decl.getAnnotation(Alternate.class) != null )
|
||||
overloadsComment = "Overloads " + decl.getAnnotation(Alternate.class).value() + ".";
|
||||
} else {
|
||||
else
|
||||
overloadsComment = null;
|
||||
}
|
||||
|
||||
String doc_comment = pe.getElementUtils().getDocComment(decl);
|
||||
String doc_comment = decl.getDocComment();
|
||||
if ( doc_comment != null ) {
|
||||
final String tab = (decl instanceof TypeElement) ? "" : "\t";
|
||||
final String tab = decl instanceof InterfaceDeclaration ? "" : "\t";
|
||||
writer.println(tab + "/**");
|
||||
|
||||
if ( overloadsComment != null ) {
|
||||
|
|
@ -203,9 +191,8 @@ public class Utils {
|
|||
while ( doc_lines.hasMoreTokens() ) {
|
||||
final String t = doc_lines.nextToken();
|
||||
if ( "\n".equals(t) ) {
|
||||
if ( lastWasNL ) {
|
||||
if ( lastWasNL )
|
||||
writer.println(tab + " * <p>");
|
||||
}
|
||||
lastWasNL = true;
|
||||
} else {
|
||||
writer.println(tab + " * " + t);
|
||||
|
|
@ -214,117 +201,107 @@ public class Utils {
|
|||
}
|
||||
|
||||
writer.println(tab + " */");
|
||||
} else if ( overloadsComment != null ) {
|
||||
} else if ( overloadsComment != null )
|
||||
writer.println("\t/** " + overloadsComment + " */");
|
||||
}
|
||||
}
|
||||
|
||||
public static AnnotationMirror getParameterAutoAnnotation(VariableElement param) {
|
||||
for ( AnnotationMirror annotation : param.getAnnotationMirrors() ) {
|
||||
if ( NativeTypeTranslator.getAnnotation(annotation, Auto.class) != null ) {
|
||||
public static AnnotationMirror getParameterAutoAnnotation(ParameterDeclaration param) {
|
||||
for ( AnnotationMirror annotation : param.getAnnotationMirrors() )
|
||||
if ( NativeTypeTranslator.getAnnotation(annotation, Auto.class) != null )
|
||||
return annotation;
|
||||
}
|
||||
}
|
||||
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, ExecutableElement method) {
|
||||
/*
|
||||
for (VariableElement param : method.getParameters()) {
|
||||
if (isAddressableType(param.getType()) || getParameterAutoAnnotation(param) != null ||
|
||||
param.getAnnotation(Constant.class) != null)
|
||||
return true;
|
||||
}
|
||||
return hasMethodBufferObjectParameter(method) || method.getAnnotation(Code.class) != null ||
|
||||
method.getAnnotation(CachedResult.class) != null ||
|
||||
(generate_error_checks && method.getAnnotation(NoErrorCheck.class) == null) ||
|
||||
context_specific;
|
||||
*/
|
||||
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)
|
||||
return true;
|
||||
}
|
||||
return hasMethodBufferObjectParameter(method) || method.getAnnotation(Code.class) != null ||
|
||||
method.getAnnotation(CachedResult.class) != null ||
|
||||
(generate_error_checks && method.getAnnotation(NoErrorCheck.class) == null) ||
|
||||
context_specific;
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
private static final Pattern DOT_PATTERN = Pattern.compile("\\.");
|
||||
|
||||
public static String getNativeQualifiedName(String qualified_name) {
|
||||
return DOT_PATTERN.matcher(qualified_name).replaceAll("_");
|
||||
return qualified_name.replaceAll("\\.", "_");
|
||||
}
|
||||
|
||||
public static String getQualifiedNativeMethodName(String qualified_class_name, String method_name) {
|
||||
// Escape '_' in method name
|
||||
if ( method_name.indexOf('_') != -1 ) {
|
||||
if ( method_name.indexOf('_') != -1 )
|
||||
method_name = method_name.replace("_", "_1");
|
||||
}
|
||||
|
||||
return "Java_" + getNativeQualifiedName(qualified_class_name) + "_" + method_name;
|
||||
}
|
||||
|
||||
public static String getQualifiedNativeMethodName(String qualified_class_name, ExecutableElement method, boolean generate_error_checks, boolean context_specific) {
|
||||
public static String getQualifiedNativeMethodName(String qualified_class_name, MethodDeclaration method, boolean generate_error_checks, boolean context_specific) {
|
||||
String method_name = getSimpleNativeMethodName(method, generate_error_checks, context_specific);
|
||||
return getQualifiedNativeMethodName(qualified_class_name, method_name);
|
||||
}
|
||||
|
||||
public static VariableElement getResultParameter(ExecutableElement method) {
|
||||
VariableElement result_param = null;
|
||||
for ( VariableElement param : method.getParameters() ) {
|
||||
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 ) {
|
||||
if ( result_param != null )
|
||||
throw new RuntimeException("Multiple parameters annotated with Result in method " + method);
|
||||
}
|
||||
result_param = param;
|
||||
}
|
||||
}
|
||||
return result_param;
|
||||
}
|
||||
|
||||
public static TypeMirror getMethodReturnType(ExecutableElement method) {
|
||||
public static TypeMirror getMethodReturnType(MethodDeclaration method) {
|
||||
TypeMirror result_type;
|
||||
VariableElement result_param = getResultParameter(method);
|
||||
ParameterDeclaration result_param = getResultParameter(method);
|
||||
if ( result_param != null ) {
|
||||
result_type = result_param.asType();
|
||||
} else {
|
||||
result_type = result_param.getType();
|
||||
} else
|
||||
result_type = method.getReturnType();
|
||||
}
|
||||
return result_type;
|
||||
}
|
||||
|
||||
public static String getMethodReturnType(ExecutableElement method, GLreturn return_annotation, boolean buffer) {
|
||||
VariableElement return_param = null;
|
||||
for ( VariableElement param : method.getParameters() ) {
|
||||
if ( param.getSimpleName().toString().equals(return_annotation.value()) ) {
|
||||
public static String getMethodReturnType(MethodDeclaration method, GLreturn return_annotation, boolean buffer) {
|
||||
ParameterDeclaration return_param = null;
|
||||
for ( ParameterDeclaration param : method.getParameters() ) {
|
||||
if ( param.getSimpleName().equals(return_annotation.value()) ) {
|
||||
return_param = param;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ( return_param == null ) {
|
||||
if ( return_param == null )
|
||||
throw new RuntimeException("The @GLreturn parameter \"" + return_annotation.value() + "\" could not be found in method: " + method);
|
||||
}
|
||||
|
||||
TypeKind kind = NativeTypeTranslator.getPrimitiveKindFromBufferClass(Utils.getJavaType(return_param.asType()));
|
||||
if ( return_param.getAnnotation(GLboolean.class) != null ) {
|
||||
kind = TypeKind.BOOLEAN;
|
||||
}
|
||||
PrimitiveType.Kind kind = NativeTypeTranslator.getPrimitiveKindFromBufferClass(Utils.getJavaType(return_param.getType()));
|
||||
if ( return_param.getAnnotation(GLboolean.class) != null )
|
||||
kind = PrimitiveType.Kind.BOOLEAN;
|
||||
|
||||
if ( kind == TypeKind.BYTE && (return_param.getAnnotation(GLchar.class) != null || return_param.getAnnotation(GLcharARB.class) != null) ) {
|
||||
if ( kind == PrimitiveType.Kind.BYTE && (return_param.getAnnotation(GLchar.class) != null || return_param.getAnnotation(GLcharARB.class) != null) )
|
||||
return "String";
|
||||
} else {
|
||||
else {
|
||||
final String type = JavaTypeTranslator.getPrimitiveClassFromKind(kind).getName();
|
||||
return buffer ? Character.toUpperCase(type.charAt(0)) + type.substring(1) : type;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean needResultSize(ExecutableElement method) {
|
||||
public static boolean needResultSize(MethodDeclaration method) {
|
||||
return getNIOBufferType(getMethodReturnType(method)) != null && method.getAnnotation(AutoSize.class) == null;
|
||||
}
|
||||
|
||||
public static void printExtraCallArguments(PrintWriter writer, ExecutableElement method, String size_parameter_name) {
|
||||
public static void printExtraCallArguments(PrintWriter writer, MethodDeclaration method, String size_parameter_name) {
|
||||
writer.print(size_parameter_name);
|
||||
if ( method.getAnnotation(CachedResult.class) != null ) {
|
||||
writer.print(", " + CACHED_BUFFER_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
private static String getClassName(TypeElement interface_decl, String opengl_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()) ) {
|
||||
return extension_annotation.className();
|
||||
|
|
@ -335,15 +312,14 @@ public class Utils {
|
|||
if ( ch == '_' ) {
|
||||
i++;
|
||||
result.appendCodePoint(Character.toUpperCase(opengl_name.codePointAt(i)));
|
||||
} else {
|
||||
} else
|
||||
result.appendCodePoint(ch);
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
public static boolean hasMethodBufferObjectParameter(ExecutableElement method) {
|
||||
for ( VariableElement param : method.getParameters() ) {
|
||||
public static boolean hasMethodBufferObjectParameter(MethodDeclaration method) {
|
||||
for ( ParameterDeclaration param : method.getParameters() ) {
|
||||
if ( param.getAnnotation(BufferObject.class) != null ) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -351,81 +327,71 @@ public class Utils {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static String getQualifiedClassName(TypeElement interface_decl) {
|
||||
return interface_decl.getEnclosingElement().asType().toString() + "." + getSimpleClassName(interface_decl);
|
||||
public static String getQualifiedClassName(InterfaceDeclaration interface_decl) {
|
||||
return interface_decl.getPackage().getQualifiedName() + "." + getSimpleClassName(interface_decl);
|
||||
}
|
||||
|
||||
public static String getSimpleClassName(TypeElement interface_decl) {
|
||||
return getClassName(interface_decl, interface_decl.getSimpleName().toString());
|
||||
public static String getSimpleClassName(InterfaceDeclaration interface_decl) {
|
||||
return getClassName(interface_decl, interface_decl.getSimpleName());
|
||||
}
|
||||
|
||||
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 ) {
|
||||
else if ( param_type == CharSequence.class || param_type == CharSequence[].class || param_type == PointerBuffer.class )
|
||||
return ByteBuffer.class;
|
||||
} else {
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getSimpleNativeMethodName(ExecutableElement method, boolean generate_error_checks, boolean context_specific) {
|
||||
public static String getSimpleNativeMethodName(MethodDeclaration method, boolean generate_error_checks, boolean context_specific) {
|
||||
String method_name;
|
||||
Alternate alt_annotation = method.getAnnotation(Alternate.class);
|
||||
method_name = alt_annotation == null || alt_annotation.nativeAlt() ? method.getSimpleName().toString() : alt_annotation.value();
|
||||
if ( isMethodIndirect(generate_error_checks, context_specific, method) ) {
|
||||
method_name = alt_annotation == null || alt_annotation.nativeAlt() ? method.getSimpleName() : alt_annotation.value();
|
||||
if ( isMethodIndirect(generate_error_checks, context_specific, method) )
|
||||
method_name = OVERLOADED_METHOD_PREFIX + method_name;
|
||||
}
|
||||
return method_name;
|
||||
}
|
||||
|
||||
static boolean isReturnParameter(ExecutableElement method, VariableElement param) {
|
||||
static boolean isReturnParameter(MethodDeclaration method, ParameterDeclaration param) {
|
||||
GLreturn string_annotation = method.getAnnotation(GLreturn.class);
|
||||
if ( string_annotation == null || !string_annotation.value().equals(param.getSimpleName().toString()) ) {
|
||||
if ( string_annotation == null || !string_annotation.value().equals(param.getSimpleName()) )
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( param.getAnnotation(OutParameter.class) == null ) {
|
||||
if ( param.getAnnotation(OutParameter.class) == null )
|
||||
throw new RuntimeException("The parameter specified in @GLreturn is not annotated with @OutParameter in method: " + method);
|
||||
}
|
||||
|
||||
if ( param.getAnnotation(Check.class) != null ) {
|
||||
if ( param.getAnnotation(Check.class) != null )
|
||||
throw new RuntimeException("The parameter specified in @GLreturn is annotated with @Check in method: " + method);
|
||||
}
|
||||
|
||||
if ( param.getAnnotation(GLchar.class) != null && Utils.getJavaType(param.asType()).equals(ByteBuffer.class) && string_annotation.maxLength().length() == 0 ) {
|
||||
if ( param.getAnnotation(GLchar.class) != null && Utils.getJavaType(param.getType()).equals(ByteBuffer.class) && string_annotation.maxLength().length() == 0 )
|
||||
throw new RuntimeException("The @GLreturn annotation is missing a maxLength parameter in method: " + method);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static String getStringOffset(ExecutableElement method, VariableElement param) {
|
||||
static String getStringOffset(MethodDeclaration method, ParameterDeclaration param) {
|
||||
String offset = null;
|
||||
for ( VariableElement p : method.getParameters() ) {
|
||||
if ( param != null && p.getSimpleName().equals(param.getSimpleName()) ) {
|
||||
for ( ParameterDeclaration p : method.getParameters() ) {
|
||||
if ( param != null && p.getSimpleName().equals(param.getSimpleName()) )
|
||||
break;
|
||||
}
|
||||
|
||||
if ( p.getAnnotation(NullTerminated.class) != null ) {
|
||||
if ( p.getAnnotation(NullTerminated.class) != null )
|
||||
continue;
|
||||
}
|
||||
|
||||
final Class type = Utils.getJavaType(p.asType());
|
||||
final Class type = Utils.getJavaType(p.getType());
|
||||
if ( type.equals(CharSequence.class) ) {
|
||||
if ( offset == null ) {
|
||||
if ( offset == null )
|
||||
offset = p.getSimpleName() + ".length()";
|
||||
} else {
|
||||
else
|
||||
offset += " + " + p.getSimpleName() + ".length()";
|
||||
}
|
||||
//if ( p.getAnnotation(NullTerminated.class) != null ) offset += " + 1";
|
||||
} else if ( type.equals(CharSequence[].class) ) {
|
||||
if ( offset == null ) {
|
||||
if ( offset == null )
|
||||
offset = "APIUtil.getTotalLength(" + p.getSimpleName() + ")";
|
||||
} else {
|
||||
else
|
||||
offset += " + APIUtil.getTotalLength(" + p.getSimpleName() + ")";
|
||||
}
|
||||
//if ( p.getAnnotation(NullTerminated.class) != null ) offset += " + " + p.getSimpleName() + ".length";
|
||||
}
|
||||
|
||||
|
|
@ -433,7 +399,7 @@ public class Utils {
|
|||
return offset;
|
||||
}
|
||||
|
||||
static void printGLReturnPre(PrintWriter writer, ExecutableElement method, GLreturn return_annotation, TypeMap type_map) {
|
||||
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) ) {
|
||||
|
|
@ -442,22 +408,20 @@ public class Utils {
|
|||
writer.print("\t\t");
|
||||
}
|
||||
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
|
||||
large enough to hold everything, so that no re-allocations happen while filling.
|
||||
*/
|
||||
/*
|
||||
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
|
||||
large enough to hold everything, so that no re-allocations happen while filling.
|
||||
*/
|
||||
final String offset = getStringOffset(method, null);
|
||||
if ( offset != null ) {
|
||||
if ( offset != null )
|
||||
writer.print(" + " + offset);
|
||||
}
|
||||
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 + "(" + type_map.getAPIUtilParam(false));
|
||||
if ( "Byte".equals(buffer_type) ) {
|
||||
if ( "Byte".equals(buffer_type) )
|
||||
writer.print((type_map.getAPIUtilParam(false).length() > 0 ? ", " : "") + "1");
|
||||
}
|
||||
writer.println(");");
|
||||
}
|
||||
|
||||
|
|
@ -465,42 +429,30 @@ public class Utils {
|
|||
if ( code_annotation != null && code_annotation.tryBlock() ) {
|
||||
writer.println("\t\ttry {");
|
||||
writer.print("\t\t\t");
|
||||
} else {
|
||||
} else
|
||||
writer.print("\t\t");
|
||||
}
|
||||
}
|
||||
|
||||
static void printGLReturnPost(PrintWriter writer, ExecutableElement method, GLreturn return_annotation, TypeMap type_map) {
|
||||
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() ) {
|
||||
if ( return_annotation.forceMaxLength() )
|
||||
writer.print(return_annotation.maxLength());
|
||||
} else {
|
||||
else
|
||||
writer.print(return_annotation.value() + "_length.get(0)");
|
||||
}
|
||||
writer.println(");");
|
||||
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) ) {
|
||||
if ( "Boolean".equals(return_type) )
|
||||
writer.print(" == 1");
|
||||
}
|
||||
writer.println(";");
|
||||
}
|
||||
}
|
||||
|
||||
public static Collection<VariableElement> getFields(TypeElement d) {
|
||||
return ElementFilter.fieldsIn(new LinkedHashSet<Element>(d.getEnclosedElements()));
|
||||
}
|
||||
|
||||
public static Collection<ExecutableElement> getMethods(TypeElement d) {
|
||||
return ElementFilter.methodsIn(new LinkedHashSet<Element>(d.getEnclosedElements()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,79 +44,74 @@ package org.lwjgl.util.generator.openal;
|
|||
import org.lwjgl.util.generator.Signedness;
|
||||
import org.lwjgl.util.generator.TypeMap;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import com.sun.mirror.declaration.*;
|
||||
import com.sun.mirror.type.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.*;
|
||||
import java.nio.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
|
||||
public class ALTypeMap implements TypeMap {
|
||||
private static final Map<Class, TypeKind> native_types_to_primitive;
|
||||
private static final Map<Class, PrimitiveType.Kind> native_types_to_primitive;
|
||||
|
||||
static {
|
||||
native_types_to_primitive = new HashMap<Class, TypeKind>();
|
||||
native_types_to_primitive.put(ALboolean.class, TypeKind.BOOLEAN);
|
||||
native_types_to_primitive.put(ALbyte.class, TypeKind.BYTE);
|
||||
native_types_to_primitive.put(ALenum.class, TypeKind.INT);
|
||||
native_types_to_primitive.put(ALfloat.class, TypeKind.FLOAT);
|
||||
native_types_to_primitive.put(ALdouble.class, TypeKind.DOUBLE);
|
||||
native_types_to_primitive.put(ALint.class, TypeKind.INT);
|
||||
native_types_to_primitive.put(ALshort.class, TypeKind.SHORT);
|
||||
native_types_to_primitive.put(ALsizei.class, TypeKind.INT);
|
||||
native_types_to_primitive.put(ALubyte.class, TypeKind.BYTE);
|
||||
native_types_to_primitive.put(ALuint.class, TypeKind.INT);
|
||||
native_types_to_primitive.put(ALvoid.class, TypeKind.BYTE);
|
||||
native_types_to_primitive = new HashMap<Class, PrimitiveType.Kind>();
|
||||
native_types_to_primitive.put(ALboolean.class, PrimitiveType.Kind.BOOLEAN);
|
||||
native_types_to_primitive.put(ALbyte.class, PrimitiveType.Kind.BYTE);
|
||||
native_types_to_primitive.put(ALenum.class, PrimitiveType.Kind.INT);
|
||||
native_types_to_primitive.put(ALfloat.class, PrimitiveType.Kind.FLOAT);
|
||||
native_types_to_primitive.put(ALdouble.class, PrimitiveType.Kind.DOUBLE);
|
||||
native_types_to_primitive.put(ALint.class, PrimitiveType.Kind.INT);
|
||||
native_types_to_primitive.put(ALshort.class, PrimitiveType.Kind.SHORT);
|
||||
native_types_to_primitive.put(ALsizei.class, PrimitiveType.Kind.INT);
|
||||
native_types_to_primitive.put(ALubyte.class, PrimitiveType.Kind.BYTE);
|
||||
native_types_to_primitive.put(ALuint.class, PrimitiveType.Kind.INT);
|
||||
native_types_to_primitive.put(ALvoid.class, PrimitiveType.Kind.BYTE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeKind getPrimitiveTypeFromNativeType(Class native_type) {
|
||||
TypeKind kind = native_types_to_primitive.get(native_type);
|
||||
if ( kind == null )
|
||||
public PrimitiveType.Kind getPrimitiveTypeFromNativeType(Class native_type) {
|
||||
PrimitiveType.Kind kind = native_types_to_primitive.get(native_type);
|
||||
if (kind == null)
|
||||
throw new RuntimeException("Unsupported type " + native_type);
|
||||
return kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Signedness getSignednessFromType(Class type) {
|
||||
if ( ALuint.class.equals(type) )
|
||||
if (ALuint.class.equals(type))
|
||||
return Signedness.UNSIGNED;
|
||||
else if ( ALint.class.equals(type) )
|
||||
else if (ALint.class.equals(type))
|
||||
return Signedness.SIGNED;
|
||||
else if ( ALshort.class.equals(type) )
|
||||
else if (ALshort.class.equals(type))
|
||||
return Signedness.SIGNED;
|
||||
else if ( ALbyte.class.equals(type) )
|
||||
else if (ALbyte.class.equals(type))
|
||||
return Signedness.SIGNED;
|
||||
else
|
||||
return Signedness.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String translateAnnotation(Class annotation_type) {
|
||||
if ( annotation_type.equals(ALuint.class) )
|
||||
if (annotation_type.equals(ALuint.class))
|
||||
return "i";
|
||||
else if ( annotation_type.equals(ALint.class) )
|
||||
else if (annotation_type.equals(ALint.class))
|
||||
return "i";
|
||||
else if ( annotation_type.equals(ALshort.class) )
|
||||
else if (annotation_type.equals(ALshort.class))
|
||||
return "s";
|
||||
else if ( annotation_type.equals(ALbyte.class) )
|
||||
else if (annotation_type.equals(ALbyte.class))
|
||||
return "b";
|
||||
else if ( annotation_type.equals(ALfloat.class) )
|
||||
else if (annotation_type.equals(ALfloat.class))
|
||||
return "f";
|
||||
else if ( annotation_type.equals(ALdouble.class) )
|
||||
else if (annotation_type.equals(ALdouble.class))
|
||||
return "d";
|
||||
else if ( annotation_type.equals(ALboolean.class) || annotation_type.equals(ALvoid.class) )
|
||||
else if (annotation_type.equals(ALboolean.class) || annotation_type.equals(ALvoid.class))
|
||||
return "";
|
||||
else
|
||||
throw new RuntimeException(annotation_type + " is not allowed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getNativeTypeFromPrimitiveType(TypeKind kind) {
|
||||
public Class getNativeTypeFromPrimitiveType(PrimitiveType.Kind kind) {
|
||||
Class type;
|
||||
switch ( kind ) {
|
||||
switch (kind) {
|
||||
case INT:
|
||||
type = ALint.class;
|
||||
break;
|
||||
|
|
@ -142,124 +137,109 @@ public class ALTypeMap implements TypeMap {
|
|||
}
|
||||
|
||||
private static Class[] getValidBufferTypes(Class type) {
|
||||
if ( type.equals(IntBuffer.class) )
|
||||
return new Class[] { ALenum.class, ALint.class, ALsizei.class, ALuint.class };
|
||||
else if ( type.equals(FloatBuffer.class) )
|
||||
return new Class[] { ALfloat.class };
|
||||
else if ( type.equals(ByteBuffer.class) )
|
||||
return new Class[] { ALboolean.class, ALbyte.class, ALvoid.class };
|
||||
else if ( type.equals(ShortBuffer.class) )
|
||||
return new Class[] { ALshort.class };
|
||||
else if ( type.equals(DoubleBuffer.class) )
|
||||
return new Class[] { ALdouble.class };
|
||||
if (type.equals(IntBuffer.class))
|
||||
return new Class[]{ALenum.class, ALint.class, ALsizei.class, ALuint.class};
|
||||
else if (type.equals(FloatBuffer.class))
|
||||
return new Class[]{ALfloat.class};
|
||||
else if (type.equals(ByteBuffer.class))
|
||||
return new Class[]{ALboolean.class, ALbyte.class, ALvoid.class};
|
||||
else if (type.equals(ShortBuffer.class))
|
||||
return new Class[]{ALshort.class};
|
||||
else if (type.equals(DoubleBuffer.class))
|
||||
return new Class[]{ALdouble.class};
|
||||
else
|
||||
return new Class[] { };
|
||||
return new Class[]{};
|
||||
}
|
||||
|
||||
private static Class[] getValidPrimitiveTypes(Class type) {
|
||||
if ( type.equals(int.class) )
|
||||
return new Class[] { ALenum.class, ALint.class, ALsizei.class, ALuint.class };
|
||||
else if ( type.equals(double.class) )
|
||||
return new Class[] { ALdouble.class };
|
||||
else if ( type.equals(float.class) )
|
||||
return new Class[] { ALfloat.class };
|
||||
else if ( type.equals(short.class) )
|
||||
return new Class[] { ALshort.class };
|
||||
else if ( type.equals(byte.class) )
|
||||
return new Class[] { ALbyte.class };
|
||||
else if ( type.equals(boolean.class) )
|
||||
return new Class[] { ALboolean.class };
|
||||
else if ( type.equals(void.class) )
|
||||
return new Class[] { ALvoid.class };
|
||||
if (type.equals(int.class))
|
||||
return new Class[]{ALenum.class, ALint.class, ALsizei.class, ALuint.class};
|
||||
else if (type.equals(double.class))
|
||||
return new Class[]{ALdouble.class};
|
||||
else if (type.equals(float.class))
|
||||
return new Class[]{ALfloat.class};
|
||||
else if (type.equals(short.class))
|
||||
return new Class[]{ALshort.class};
|
||||
else if (type.equals(byte.class))
|
||||
return new Class[]{ALbyte.class};
|
||||
else if (type.equals(boolean.class))
|
||||
return new Class[]{ALboolean.class};
|
||||
else if (type.equals(void.class))
|
||||
return new Class[]{ALvoid.class};
|
||||
else
|
||||
return new Class[] { };
|
||||
return new Class[]{};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printCapabilitiesInit(final PrintWriter writer) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCapabilities() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAPIUtilParam(boolean comma) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printErrorCheckMethod(final PrintWriter writer, final ExecutableElement method, final String tabs) {
|
||||
public void printErrorCheckMethod(final PrintWriter writer, final MethodDeclaration method, final String tabs) {
|
||||
writer.println(tabs + "Util.checkALError();");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRegisterNativesFunctionName() {
|
||||
return "extal_InitializeClass";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypedefPostfix() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFunctionPrefix() {
|
||||
return "ALAPIENTRY";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printNativeIncludes(PrintWriter writer) {
|
||||
writer.println("#include \"extal.h\"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getStringElementType() {
|
||||
public Class<? extends Annotation> getStringElementType() {
|
||||
return ALubyte.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getStringArrayType() {
|
||||
return ALubyte.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getByteBufferArrayType() {
|
||||
return ALubyte.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class[] getValidAnnotationTypes(Class type) {
|
||||
Class[] valid_types;
|
||||
if ( Buffer.class.isAssignableFrom(type) )
|
||||
if (Buffer.class.isAssignableFrom(type))
|
||||
valid_types = getValidBufferTypes(type);
|
||||
else if ( type.isPrimitive() )
|
||||
else if (type.isPrimitive())
|
||||
valid_types = getValidPrimitiveTypes(type);
|
||||
else if ( type.equals(String.class) )
|
||||
valid_types = new Class[] { ALubyte.class };
|
||||
else if (type.equals(String.class))
|
||||
valid_types = new Class[]{ALubyte.class};
|
||||
else
|
||||
valid_types = new Class[] { };
|
||||
valid_types = new Class[]{};
|
||||
return valid_types;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getVoidType() {
|
||||
return ALvoid.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getInverseType(Class type) {
|
||||
if ( ALuint.class.equals(type) )
|
||||
if (ALuint.class.equals(type))
|
||||
return ALint.class;
|
||||
else if ( ALint.class.equals(type) )
|
||||
else if (ALint.class.equals(type))
|
||||
return ALuint.class;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAutoTypeFromAnnotation(AnnotationMirror annotation) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,16 +29,18 @@
|
|||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.lwjgl.util.generator.opencl;
|
||||
|
||||
import org.lwjgl.util.generator.*;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
|
||||
import com.sun.mirror.declaration.InterfaceDeclaration;
|
||||
import com.sun.mirror.declaration.MethodDeclaration;
|
||||
import com.sun.mirror.declaration.TypeDeclaration;
|
||||
|
||||
/**
|
||||
* CLCapabilities generator.
|
||||
|
|
@ -48,94 +50,80 @@ import javax.lang.model.element.TypeElement;
|
|||
public class CLCapabilitiesGenerator {
|
||||
|
||||
static void generateClassPrologue(final PrintWriter writer) {
|
||||
writer.println("public final class " + CLGeneratorProcessor.CLCAPS_CLASS_NAME + " {");
|
||||
writer.println("public final class " + CLGeneratorProcessorFactory.CLCAPS_CLASS_NAME + " {");
|
||||
writer.println();
|
||||
}
|
||||
|
||||
static void generateSymbolAddresses(ProcessingEnvironment env, final PrintWriter writer, final TypeElement d) {
|
||||
if ( d.getAnnotation(CLPlatformExtension.class) == null && d.getAnnotation(CLDeviceExtension.class) == null && !d.getSimpleName().toString().startsWith("CL") ) {
|
||||
throw new RuntimeException("An OpenCL extension is missing an extension type annotation: " + d.getSimpleName());
|
||||
}
|
||||
static void generateSymbolAddresses(final PrintWriter writer, final InterfaceDeclaration d) {
|
||||
final Alias alias_annotation = d.getAnnotation(Alias.class);
|
||||
final boolean aliased = alias_annotation != null && alias_annotation.postfix().length() > 0;
|
||||
|
||||
boolean foundNative = false;
|
||||
for ( final ExecutableElement method : Utils.getMethods(d) ) {
|
||||
if ( method.getAnnotation(Alternate.class) != null || method.getAnnotation(Reuse.class) != null ) {
|
||||
for ( final MethodDeclaration method : d.getMethods() ) {
|
||||
if ( method.getAnnotation(Alternate.class) != null || method.getAnnotation(Reuse.class) != null )
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( !foundNative ) {
|
||||
//writer.println("\t// " + d.getSimpleName());
|
||||
writer.println("\tstatic final boolean " + CLGeneratorProcessor.getExtensionName(d.getSimpleName().toString() + ";"));
|
||||
writer.println("\tstatic final boolean " + CLGeneratorProcessorFactory.getExtensionName(d.getSimpleName()) + ";");
|
||||
foundNative = true;
|
||||
}
|
||||
writer.print("\tstatic final long " + Utils.getFunctionAddressName(d, method) + " = CL.getFunctionAddress(");
|
||||
|
||||
if ( aliased ) {
|
||||
if ( aliased )
|
||||
writer.println("new String [] {\"" + Utils.getFunctionAddressName(d, method) + "\",\"" + method.getSimpleName() + alias_annotation.postfix() + "\"});");
|
||||
} else {
|
||||
else
|
||||
writer.println("\"" + Utils.getFunctionAddressName(d, method) + "\");");
|
||||
}
|
||||
}
|
||||
|
||||
if ( foundNative ) {
|
||||
if ( foundNative )
|
||||
writer.println();
|
||||
}
|
||||
}
|
||||
|
||||
static void generateConstructor(ProcessingEnvironment env, final PrintWriter writer, final Set<? extends TypeElement> interface_decls) {
|
||||
writer.println("\tprivate " + CLGeneratorProcessor.CLCAPS_CLASS_NAME + "() {}");
|
||||
static void generateConstructor(final PrintWriter writer, final Collection<TypeDeclaration> interface_decls) {
|
||||
writer.println("\tprivate " + CLGeneratorProcessorFactory.CLCAPS_CLASS_NAME + "() {}");
|
||||
writer.println();
|
||||
writer.println("\tstatic {");
|
||||
|
||||
for ( final TypeElement d : interface_decls ) {
|
||||
if ( d.getKind().isInterface() ) {
|
||||
if ( Utils.getMethods(d).isEmpty() ) {
|
||||
continue;
|
||||
}
|
||||
for ( final TypeDeclaration d : interface_decls ) {
|
||||
if ( d.getMethods().isEmpty() )
|
||||
continue;
|
||||
|
||||
//writer.println("\t\tif ( " + getExtensionSupportedName(d.getSimpleName()) + "() )");
|
||||
//writer.println("\t\t\t" + SUPPORTED_EXTS + ".add(\"" + CLGeneratorProcessor.getExtensionName(d.getSimpleName()) + "\");");
|
||||
writer.println("\t\t" + CLGeneratorProcessor.getExtensionName(d.getSimpleName().toString()) + " = " + getExtensionSupportedName(d.getSimpleName().toString()) + "();");
|
||||
}
|
||||
//writer.println("\t\tif ( " + getExtensionSupportedName(d.getSimpleName()) + "() )");
|
||||
//writer.println("\t\t\t" + SUPPORTED_EXTS + ".add(\"" + CLGeneratorProcessorFactory.getExtensionName(d.getSimpleName()) + "\");");
|
||||
writer.println("\t\t" + CLGeneratorProcessorFactory.getExtensionName(d.getSimpleName()) + " = " + getExtensionSupportedName(d.getSimpleName()) + "();");
|
||||
}
|
||||
|
||||
writer.println("\t}\n");
|
||||
}
|
||||
|
||||
static void generateExtensionChecks(ProcessingEnvironment env, final PrintWriter writer, TypeElement d) {
|
||||
Iterator<? extends ExecutableElement> methods = Utils.getMethods(d).iterator();
|
||||
if ( !methods.hasNext() ) {
|
||||
static void generateExtensionChecks(final PrintWriter writer, final InterfaceDeclaration d) {
|
||||
Iterator<? extends MethodDeclaration> methods = d.getMethods().iterator();
|
||||
if ( !methods.hasNext() )
|
||||
return;
|
||||
}
|
||||
|
||||
writer.println("\tprivate static boolean " + getExtensionSupportedName(d.getSimpleName().toString()) + "() {");
|
||||
writer.println("\tprivate static boolean " + getExtensionSupportedName(d.getSimpleName()) + "() {");
|
||||
writer.println("\t\treturn ");
|
||||
|
||||
boolean first = true;
|
||||
while ( methods.hasNext() ) {
|
||||
ExecutableElement method = methods.next();
|
||||
if ( method.getAnnotation(Alternate.class) != null ) {
|
||||
MethodDeclaration method = methods.next();
|
||||
if ( method.getAnnotation(Alternate.class) != null )
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( !first ) {
|
||||
if ( !first )
|
||||
writer.println(" &");
|
||||
} else {
|
||||
else
|
||||
first = false;
|
||||
}
|
||||
|
||||
final boolean optional = method.getAnnotation(Optional.class) != null;
|
||||
|
||||
writer.print("\t\t\t");
|
||||
if ( optional ) {
|
||||
if ( optional )
|
||||
writer.print('(');
|
||||
}
|
||||
writer.print(Utils.getFunctionAddressName(d, method) + " != 0");
|
||||
if ( optional ) {
|
||||
if ( optional )
|
||||
writer.print(" || true)");
|
||||
}
|
||||
}
|
||||
writer.println(";");
|
||||
writer.println("\t}");
|
||||
|
|
@ -147,25 +135,25 @@ public class CLCapabilitiesGenerator {
|
|||
}
|
||||
|
||||
public static void generateCapabilitiesGetters(final PrintWriter writer) {
|
||||
writer.println("\tpublic static CLPlatformCapabilities getPlatformCapabilities(final CLPlatform platform) {\n"
|
||||
+ "\t\tplatform.checkValid();\n"
|
||||
+ "\n"
|
||||
+ "\t\tCLPlatformCapabilities caps = (CLPlatformCapabilities)platform.getCapabilities();\n"
|
||||
+ "\t\tif ( caps == null )\n"
|
||||
+ "\t\t\tplatform.setCapabilities(caps = new CLPlatformCapabilities(platform));\n"
|
||||
+ "\n"
|
||||
+ "\t\treturn caps;\n"
|
||||
+ "\t}\n");
|
||||
writer.println("\tpublic static CLPlatformCapabilities getPlatformCapabilities(final CLPlatform platform) {\n" +
|
||||
"\t\tplatform.checkValid();\n" +
|
||||
"\n" +
|
||||
"\t\tCLPlatformCapabilities caps = (CLPlatformCapabilities)platform.getCapabilities();\n" +
|
||||
"\t\tif ( caps == null )\n" +
|
||||
"\t\t\tplatform.setCapabilities(caps = new CLPlatformCapabilities(platform));\n" +
|
||||
"\n" +
|
||||
"\t\treturn caps;\n" +
|
||||
"\t}\n");
|
||||
|
||||
writer.println("\tpublic static CLDeviceCapabilities getDeviceCapabilities(final CLDevice device) {\n"
|
||||
+ "\t\tdevice.checkValid();\n"
|
||||
+ "\n"
|
||||
+ "\t\tCLDeviceCapabilities caps = (CLDeviceCapabilities)device.getCapabilities();\n"
|
||||
+ "\t\tif ( caps == null )\n"
|
||||
+ "\t\t\tdevice.setCapabilities(caps = new CLDeviceCapabilities(device));\n"
|
||||
+ "\n"
|
||||
+ "\t\treturn caps;\n"
|
||||
+ "\t}\n");
|
||||
writer.println("\tpublic static CLDeviceCapabilities getDeviceCapabilities(final CLDevice device) {\n" +
|
||||
"\t\tdevice.checkValid();\n" +
|
||||
"\n" +
|
||||
"\t\tCLDeviceCapabilities caps = (CLDeviceCapabilities)device.getCapabilities();\n" +
|
||||
"\t\tif ( caps == null )\n" +
|
||||
"\t\t\tdevice.setCapabilities(caps = new CLDeviceCapabilities(device));\n" +
|
||||
"\n" +
|
||||
"\t\treturn caps;\n" +
|
||||
"\t}\n");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,152 +0,0 @@
|
|||
/*
|
||||
* 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
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.lwjgl.util.generator.opencl;
|
||||
|
||||
import org.lwjgl.PointerWrapper;
|
||||
import org.lwjgl.opencl.CLDevice;
|
||||
import org.lwjgl.opencl.CLPlatform;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Set;
|
||||
import javax.annotation.processing.*;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.util.ElementFilter;
|
||||
|
||||
/**
|
||||
* Generator tool for creating the OpenCL capabilities classes
|
||||
*
|
||||
* @author Spasi
|
||||
*/
|
||||
@SupportedAnnotationTypes({ "*" })
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_7)
|
||||
@SupportedOptions({ "generatechecks", "contextspecific" })
|
||||
public class CLGeneratorProcessor extends AbstractProcessor {
|
||||
|
||||
public static final String CLCAPS_CLASS_NAME = "CLCapabilities";
|
||||
public static final String PLATFORM_CAPS_CLASS_NAME = "CLPlatformCapabilities";
|
||||
public static final String DEVICE_CAPS_CLASS_NAME = "CLDeviceCapabilities";
|
||||
|
||||
private static final String EXTENSION_PREFIX = "CL_";
|
||||
private static final String CORE_PREFIX = "Open";
|
||||
|
||||
private static boolean first_round = true;
|
||||
|
||||
static String getExtensionName(String interface_name) {
|
||||
if ( interface_name.startsWith("CL") ) {
|
||||
return CORE_PREFIX + interface_name;
|
||||
} else {
|
||||
return EXTENSION_PREFIX + interface_name;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||
if ( roundEnv.processingOver() || !first_round ) {
|
||||
System.exit(0);
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
Set<TypeElement> templates = ElementFilter.typesIn(roundEnv.getRootElements());
|
||||
/**
|
||||
* provide the full set of ex-InterfaceDeclaration
|
||||
* annotated templates elements
|
||||
*/
|
||||
generateCLCapabilitiesSource(templates);
|
||||
generateCLPDCapabilitiesSource(templates, CLPlatformExtension.class, PLATFORM_CAPS_CLASS_NAME, CLPlatform.class, "platform");
|
||||
generateCLPDCapabilitiesSource(templates, CLDeviceExtension.class, DEVICE_CAPS_CLASS_NAME, CLDevice.class, "device");
|
||||
first_round = false;
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void printHeader(final PrintWriter writer) {
|
||||
writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
|
||||
writer.println();
|
||||
writer.println("package org.lwjgl.opencl;");
|
||||
writer.println();
|
||||
}
|
||||
|
||||
private void generateCLCapabilitiesSource(Set<TypeElement> templates) throws IOException {
|
||||
final PrintWriter writer = new PrintWriter(processingEnv.getFiler().createSourceFile("org.lwjgl.opencl." + CLCAPS_CLASS_NAME, processingEnv.getElementUtils().getPackageElement("org.lwjgl.opencl")).openWriter());
|
||||
printHeader(writer);
|
||||
|
||||
CLCapabilitiesGenerator.generateClassPrologue(writer);
|
||||
for ( TypeElement d : templates ) {
|
||||
if ( d.getKind().isInterface() ) {
|
||||
CLCapabilitiesGenerator.generateSymbolAddresses(processingEnv, writer, d);
|
||||
}
|
||||
}
|
||||
writer.println();
|
||||
|
||||
CLCapabilitiesGenerator.generateConstructor(processingEnv, writer, templates);
|
||||
|
||||
CLCapabilitiesGenerator.generateCapabilitiesGetters(writer);
|
||||
for ( TypeElement d : templates ) {
|
||||
if ( d.getKind().isInterface() ) {
|
||||
CLCapabilitiesGenerator.generateExtensionChecks(processingEnv, writer, d);
|
||||
}
|
||||
}
|
||||
|
||||
writer.println("}");
|
||||
writer.close();
|
||||
}
|
||||
|
||||
private void generateCLPDCapabilitiesSource(Set<TypeElement> templates, final Class<? extends Annotation> capsType, final String capsName, final Class<? extends PointerWrapper> objectType, final String objectName) throws IOException {
|
||||
final PrintWriter writer = new PrintWriter(processingEnv.getFiler().createSourceFile("org.lwjgl.opencl." + capsName, processingEnv.getElementUtils().getPackageElement("org.lwjgl.opencl")).openWriter());
|
||||
printHeader(writer);
|
||||
writer.println("import java.util.*;");
|
||||
writer.println();
|
||||
|
||||
CLPDCapabilitiesGenerator.generateClassPrologue(writer, capsName);
|
||||
|
||||
for ( TypeElement t : templates ) {
|
||||
if ( t.getKind().isInterface() && t.getAnnotation(capsType) != null ) {
|
||||
CLPDCapabilitiesGenerator.generateExtensions(writer, (TypeElement)t);
|
||||
}
|
||||
}
|
||||
writer.println();
|
||||
|
||||
CLPDCapabilitiesGenerator.generateConstructor(processingEnv, writer, templates, capsType, capsName, objectType, objectName);
|
||||
|
||||
CLPDCapabilitiesGenerator.generateGetters(writer);
|
||||
|
||||
CLPDCapabilitiesGenerator.generateToString(writer, templates, capsType);
|
||||
|
||||
writer.println("}");
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,181 @@
|
|||
/*
|
||||
* 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
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.lwjgl.util.generator.opencl;
|
||||
|
||||
import org.lwjgl.PointerWrapper;
|
||||
import org.lwjgl.opencl.CLDevice;
|
||||
import org.lwjgl.opencl.CLPlatform;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sun.mirror.apt.*;
|
||||
import com.sun.mirror.declaration.AnnotationTypeDeclaration;
|
||||
import com.sun.mirror.declaration.InterfaceDeclaration;
|
||||
import com.sun.mirror.declaration.TypeDeclaration;
|
||||
import com.sun.mirror.util.DeclarationFilter;
|
||||
|
||||
import static java.util.Collections.*;
|
||||
|
||||
/**
|
||||
* Generator tool for creating the OpenCL capabilities classes
|
||||
*
|
||||
* @author Spasi
|
||||
*/
|
||||
public class CLGeneratorProcessorFactory implements AnnotationProcessorFactory, RoundCompleteListener {
|
||||
|
||||
public static final String CLCAPS_CLASS_NAME = "CLCapabilities";
|
||||
public static final String PLATFORM_CAPS_CLASS_NAME = "CLPlatformCapabilities";
|
||||
public static final String DEVICE_CAPS_CLASS_NAME = "CLDeviceCapabilities";
|
||||
|
||||
private static final String EXTENSION_PREFIX = "CL_";
|
||||
private static final String CORE_PREFIX = "Open";
|
||||
|
||||
private static boolean first_round = true;
|
||||
|
||||
// Process any set of annotations
|
||||
private static final Collection<String> supportedAnnotations = unmodifiableCollection(Arrays.asList("*"));
|
||||
|
||||
public Collection<String> supportedAnnotationTypes() {
|
||||
return supportedAnnotations;
|
||||
}
|
||||
|
||||
public Collection<String> supportedOptions() {
|
||||
return unmodifiableCollection(Arrays.asList("-Acontextspecific"));
|
||||
}
|
||||
|
||||
public void roundComplete(RoundCompleteEvent event) {
|
||||
first_round = false;
|
||||
}
|
||||
|
||||
public AnnotationProcessor getProcessorFor(Set<AnnotationTypeDeclaration> atds, AnnotationProcessorEnvironment env) {
|
||||
// Only process the initial types, not the generated ones
|
||||
if ( first_round ) {
|
||||
env.addListener(this);
|
||||
return new GeneratorProcessor(env);
|
||||
} else
|
||||
return AnnotationProcessors.NO_OP;
|
||||
}
|
||||
|
||||
static String getExtensionName(String interface_name) {
|
||||
if ( interface_name.startsWith("CL") )
|
||||
return CORE_PREFIX + interface_name;
|
||||
else
|
||||
return EXTENSION_PREFIX + interface_name;
|
||||
}
|
||||
|
||||
private static class GeneratorProcessor implements AnnotationProcessor {
|
||||
|
||||
private final AnnotationProcessorEnvironment env;
|
||||
|
||||
GeneratorProcessor(AnnotationProcessorEnvironment env) {
|
||||
this.env = env;
|
||||
}
|
||||
|
||||
public void process() {
|
||||
try {
|
||||
generateCLCapabilitiesSource();
|
||||
generateCLPDCapabilitiesSource(CLPlatformExtension.class, PLATFORM_CAPS_CLASS_NAME, CLPlatform.class, "platform");
|
||||
generateCLPDCapabilitiesSource(CLDeviceExtension.class, DEVICE_CAPS_CLASS_NAME, CLDevice.class, "device");
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void printHeader(final PrintWriter writer) {
|
||||
writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
|
||||
writer.println();
|
||||
writer.println("package org.lwjgl.opencl;");
|
||||
writer.println();
|
||||
}
|
||||
|
||||
private void generateCLCapabilitiesSource() throws IOException {
|
||||
final PrintWriter writer = env.getFiler().createTextFile(Filer.Location.SOURCE_TREE, "org.lwjgl.opencl", new File(CLCAPS_CLASS_NAME + ".java"), null);
|
||||
printHeader(writer);
|
||||
|
||||
CLCapabilitiesGenerator.generateClassPrologue(writer);
|
||||
|
||||
final Collection<TypeDeclaration> templates = DeclarationFilter.getFilter(InterfaceDeclaration.class).filter(env.getSpecifiedTypeDeclarations());
|
||||
|
||||
for ( final TypeDeclaration t : templates ) {
|
||||
if ( t.getAnnotation(CLPlatformExtension.class) == null && t.getAnnotation(CLDeviceExtension.class) == null && !t.getSimpleName().startsWith("CL") )
|
||||
throw new RuntimeException("An OpenCL extension is missing an extension type annotation: " + t.getSimpleName());
|
||||
|
||||
CLCapabilitiesGenerator.generateSymbolAddresses(writer, (InterfaceDeclaration)t);
|
||||
}
|
||||
writer.println();
|
||||
|
||||
CLCapabilitiesGenerator.generateConstructor(writer, templates);
|
||||
|
||||
CLCapabilitiesGenerator.generateCapabilitiesGetters(writer);
|
||||
|
||||
for ( final TypeDeclaration template : templates )
|
||||
CLCapabilitiesGenerator.generateExtensionChecks(writer, (InterfaceDeclaration)template);
|
||||
|
||||
writer.println("}");
|
||||
writer.close();
|
||||
}
|
||||
|
||||
private void generateCLPDCapabilitiesSource(final Class<? extends Annotation> capsType, final String capsName, final Class<? extends PointerWrapper> objectType, final String objectName) throws IOException {
|
||||
final PrintWriter writer = env.getFiler().createTextFile(Filer.Location.SOURCE_TREE, "org.lwjgl.opencl", new File(capsName + ".java"), null);
|
||||
printHeader(writer);
|
||||
writer.println("import java.util.*;");
|
||||
writer.println();
|
||||
|
||||
CLPDCapabilitiesGenerator.generateClassPrologue(writer, capsName);
|
||||
|
||||
final Collection<TypeDeclaration> templates = DeclarationFilter.getFilter(InterfaceDeclaration.class).filter(env.getSpecifiedTypeDeclarations());
|
||||
|
||||
for ( final TypeDeclaration t : templates ) {
|
||||
if ( t.getAnnotation(capsType) != null )
|
||||
CLPDCapabilitiesGenerator.generateExtensions(writer, (InterfaceDeclaration)t);
|
||||
}
|
||||
writer.println();
|
||||
|
||||
CLPDCapabilitiesGenerator.generateConstructor(writer, templates, capsType, capsName, objectType, objectName);
|
||||
|
||||
CLPDCapabilitiesGenerator.generateGetters(writer);
|
||||
|
||||
CLPDCapabilitiesGenerator.generateToString(writer, templates, capsType);
|
||||
|
||||
writer.println("}");
|
||||
writer.close();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -33,15 +33,14 @@
|
|||
package org.lwjgl.util.generator.opencl;
|
||||
|
||||
import org.lwjgl.PointerWrapper;
|
||||
import org.lwjgl.util.generator.Extension;
|
||||
import org.lwjgl.util.generator.Private;
|
||||
import org.lwjgl.util.generator.Utils;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.util.Set;
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import java.util.Collection;
|
||||
|
||||
import com.sun.mirror.declaration.InterfaceDeclaration;
|
||||
import com.sun.mirror.declaration.TypeDeclaration;
|
||||
|
||||
/**
|
||||
* CL platform/device capabilities generator.
|
||||
|
|
@ -68,18 +67,18 @@ public class CLPDCapabilitiesGenerator {
|
|||
writer.println();
|
||||
}
|
||||
|
||||
static void generateExtensions(final PrintWriter writer, final TypeElement d) {
|
||||
static void generateExtensions(final PrintWriter writer, final InterfaceDeclaration d) {
|
||||
writer.print("\t");
|
||||
|
||||
if ( d.getAnnotation(Private.class) == null )
|
||||
writer.print("public ");
|
||||
|
||||
writer.println("final boolean " + CLGeneratorProcessor.getExtensionName(d.getSimpleName().toString()) + ";");
|
||||
writer.println("final boolean " + CLGeneratorProcessorFactory.getExtensionName(d.getSimpleName()) + ";");
|
||||
}
|
||||
|
||||
static void generateConstructor(ProcessingEnvironment env, final PrintWriter writer, final Set<? extends TypeElement> templates,
|
||||
final Class<? extends Annotation> capsType, final String capsName,
|
||||
final Class<? extends PointerWrapper> objectType, final String objectName) {
|
||||
static void generateConstructor(final PrintWriter writer, final Collection<TypeDeclaration> templates,
|
||||
final Class<? extends Annotation> capsType, final String capsName,
|
||||
final Class<? extends PointerWrapper> objectType, final String objectName) {
|
||||
writer.println("\tpublic " + capsName + "(final " + objectType.getSimpleName() + ' ' + objectName + ") {");
|
||||
|
||||
writer.println("\t\tfinal String extensionList = " + objectName + ".getInfoString(CL10.CL_" + objectName.toUpperCase() + "_EXTENSIONS);\n" +
|
||||
|
|
@ -103,19 +102,14 @@ public class CLPDCapabilitiesGenerator {
|
|||
|
||||
writer.println("\t\tfinal Set<String> extensions = APIUtil.getExtensions(extensionList);");
|
||||
|
||||
for ( final TypeElement t : templates ) {
|
||||
for ( final TypeDeclaration t : templates ) {
|
||||
if ( t.getAnnotation(capsType) == null )
|
||||
continue;
|
||||
|
||||
final String extName = CLGeneratorProcessor.getExtensionName(t.getSimpleName().toString());
|
||||
final String extName = CLGeneratorProcessorFactory.getExtensionName(t.getSimpleName());
|
||||
|
||||
String nativeName = extName.toLowerCase();
|
||||
Extension ext = t.getAnnotation(Extension.class);
|
||||
if ( ext != null && !ext.nativeName().isEmpty() )
|
||||
nativeName = ext.nativeName();
|
||||
|
||||
writer.print("\t\t" + extName + " = extensions.contains(\"" + nativeName + "\")");
|
||||
if ( !Utils.getMethods(t).isEmpty() )
|
||||
writer.print("\t\t" + extName + " = extensions.contains(\"" + extName.toLowerCase() + "\")");
|
||||
if ( !t.getMethods().isEmpty() )
|
||||
writer.print(" && CLCapabilities." + extName);
|
||||
writer.println(";");
|
||||
}
|
||||
|
|
@ -133,18 +127,18 @@ public class CLPDCapabilitiesGenerator {
|
|||
writer.println("\t}\n");
|
||||
}
|
||||
|
||||
public static void generateToString(final PrintWriter writer, final Set<? extends TypeElement> templates, final Class<? extends Annotation> capsType) {
|
||||
public static void generateToString(final PrintWriter writer, final Collection<TypeDeclaration> templates, final Class<? extends Annotation> capsType) {
|
||||
writer.println("\tpublic String toString() {");
|
||||
writer.println("\t\tfinal StringBuilder buf = new StringBuilder();\n");
|
||||
|
||||
writer.println("\t\tbuf.append(\"OpenCL \").append(majorVersion).append('.').append(minorVersion);");
|
||||
writer.println();
|
||||
writer.println("\t\tbuf.append(\" - Extensions: \");");
|
||||
for ( final TypeElement t : templates ) {
|
||||
for ( final TypeDeclaration t : templates ) {
|
||||
if ( t.getAnnotation(capsType) == null )
|
||||
continue;
|
||||
|
||||
writer.println("\t\tif ( " + CLGeneratorProcessor.getExtensionName(t.getSimpleName().toString()) + " ) buf.append(\"" + CLGeneratorProcessor.getExtensionName(t.getSimpleName().toString()).toLowerCase() + " \");");
|
||||
writer.println("\t\tif ( " + CLGeneratorProcessorFactory.getExtensionName(t.getSimpleName()) + " ) buf.append(\"" + CLGeneratorProcessorFactory.getExtensionName(t.getSimpleName()).toLowerCase() + " \");");
|
||||
}
|
||||
|
||||
writer.println("\n\t\treturn buf.toString();");
|
||||
|
|
|
|||
|
|
@ -48,56 +48,52 @@ import java.lang.annotation.Annotation;
|
|||
import java.nio.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
|
||||
import com.sun.mirror.declaration.AnnotationMirror;
|
||||
import com.sun.mirror.declaration.MethodDeclaration;
|
||||
import com.sun.mirror.declaration.ParameterDeclaration;
|
||||
import com.sun.mirror.type.PrimitiveType;
|
||||
|
||||
public class CLTypeMap implements TypeMap {
|
||||
|
||||
private static final Map<Class, TypeKind> native_types_to_primitive;
|
||||
private static final Map<Class, PrimitiveType.Kind> native_types_to_primitive;
|
||||
|
||||
static {
|
||||
native_types_to_primitive = new HashMap<Class, TypeKind>();
|
||||
native_types_to_primitive.put(cl_void.class, TypeKind.BYTE);
|
||||
native_types_to_primitive.put(cl_byte.class, TypeKind.BYTE);
|
||||
native_types_to_primitive.put(cl_char.class, TypeKind.BYTE);
|
||||
native_types_to_primitive.put(cl_uchar.class, TypeKind.BYTE);
|
||||
native_types_to_primitive.put(cl_short.class, TypeKind.SHORT);
|
||||
native_types_to_primitive.put(cl_bool.class, TypeKind.INT);
|
||||
native_types_to_primitive.put(cl_int.class, TypeKind.INT);
|
||||
native_types_to_primitive.put(cl_uint.class, TypeKind.INT);
|
||||
native_types_to_primitive.put(cl_long.class, TypeKind.LONG);
|
||||
native_types_to_primitive.put(size_t.class, TypeKind.LONG);
|
||||
native_types_to_primitive.put(cl_bitfield.class, TypeKind.LONG);
|
||||
native_types_to_primitive.put(cl_float.class, TypeKind.FLOAT);
|
||||
native_types_to_primitive.put(cl_double.class, TypeKind.DOUBLE);
|
||||
native_types_to_primitive = new HashMap<Class, PrimitiveType.Kind>();
|
||||
native_types_to_primitive.put(cl_void.class, PrimitiveType.Kind.BYTE);
|
||||
native_types_to_primitive.put(cl_byte.class, PrimitiveType.Kind.BYTE);
|
||||
native_types_to_primitive.put(cl_char.class, PrimitiveType.Kind.BYTE);
|
||||
native_types_to_primitive.put(cl_uchar.class, PrimitiveType.Kind.BYTE);
|
||||
native_types_to_primitive.put(cl_short.class, PrimitiveType.Kind.SHORT);
|
||||
native_types_to_primitive.put(cl_bool.class, PrimitiveType.Kind.INT);
|
||||
native_types_to_primitive.put(cl_int.class, PrimitiveType.Kind.INT);
|
||||
native_types_to_primitive.put(cl_uint.class, PrimitiveType.Kind.INT);
|
||||
native_types_to_primitive.put(cl_long.class, PrimitiveType.Kind.LONG);
|
||||
native_types_to_primitive.put(size_t.class, PrimitiveType.Kind.LONG);
|
||||
native_types_to_primitive.put(cl_bitfield.class, PrimitiveType.Kind.LONG);
|
||||
native_types_to_primitive.put(cl_float.class, PrimitiveType.Kind.FLOAT);
|
||||
native_types_to_primitive.put(cl_double.class, PrimitiveType.Kind.DOUBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeKind getPrimitiveTypeFromNativeType(Class native_type) {
|
||||
TypeKind kind = native_types_to_primitive.get(native_type);
|
||||
public PrimitiveType.Kind getPrimitiveTypeFromNativeType(Class native_type) {
|
||||
PrimitiveType.Kind kind = native_types_to_primitive.get(native_type);
|
||||
if ( kind == null )
|
||||
throw new RuntimeException("Unsupported type " + native_type);
|
||||
return kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printCapabilitiesInit(final PrintWriter writer) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCapabilities() {
|
||||
return "CLCapabilities";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAPIUtilParam(boolean comma) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printErrorCheckMethod(final PrintWriter writer, final ExecutableElement method, final String tabs) {
|
||||
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
|
||||
writer.println(tabs + "Util.checkCLError(" + check.value() + ".get(" + check.value() + ".position()));");
|
||||
|
|
@ -107,8 +103,8 @@ public class CLTypeMap implements TypeMap {
|
|||
writer.println(tabs + "Util.checkCLError(__result);");
|
||||
else {
|
||||
boolean hasErrCodeParam = false;
|
||||
for ( final VariableElement param : method.getParameters() ) {
|
||||
if ( "errcode_ret".equals(param.getSimpleName().toString()) && Utils.getJavaType(param.asType()) == IntBuffer.class ) {
|
||||
for ( final ParameterDeclaration param : method.getParameters() ) {
|
||||
if ( "errcode_ret".equals(param.getSimpleName()) && Utils.getJavaType(param.getType()) == IntBuffer.class ) {
|
||||
hasErrCodeParam = true;
|
||||
break;
|
||||
}
|
||||
|
|
@ -119,12 +115,10 @@ public class CLTypeMap implements TypeMap {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRegisterNativesFunctionName() {
|
||||
return "extcl_InitializeClass";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Signedness getSignednessFromType(Class type) {
|
||||
if ( cl_uint.class.equals(type) )
|
||||
return Signedness.UNSIGNED;
|
||||
|
|
@ -134,7 +128,6 @@ public class CLTypeMap implements TypeMap {
|
|||
return Signedness.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String translateAnnotation(Class annotation_type) {
|
||||
if ( annotation_type.equals(cl_uint.class) || annotation_type.equals(cl_int.class) )
|
||||
return "i";
|
||||
|
|
@ -150,8 +143,7 @@ public class CLTypeMap implements TypeMap {
|
|||
throw new RuntimeException(annotation_type + " is not allowed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getNativeTypeFromPrimitiveType(TypeKind kind) {
|
||||
public Class getNativeTypeFromPrimitiveType(PrimitiveType.Kind kind) {
|
||||
Class type;
|
||||
switch ( kind ) {
|
||||
case INT:
|
||||
|
|
@ -181,22 +173,18 @@ public class CLTypeMap implements TypeMap {
|
|||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getVoidType() {
|
||||
return cl_void.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getStringElementType() {
|
||||
return cl_char.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getStringArrayType() {
|
||||
return cl_char.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getByteBufferArrayType() {
|
||||
return cl_uchar.class;
|
||||
}
|
||||
|
|
@ -241,22 +229,18 @@ public class CLTypeMap implements TypeMap {
|
|||
return new Class[] { };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypedefPostfix() {
|
||||
return "CL_API_ENTRY ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFunctionPrefix() {
|
||||
return "CL_API_CALL";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printNativeIncludes(PrintWriter writer) {
|
||||
writer.println("#include \"extcl.h\"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class[] getValidAnnotationTypes(Class type) {
|
||||
Class[] valid_types;
|
||||
if ( Buffer.class.isAssignableFrom(type) || PointerBuffer.class.isAssignableFrom(type) )
|
||||
|
|
@ -276,12 +260,10 @@ public class CLTypeMap implements TypeMap {
|
|||
return valid_types;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getInverseType(Class type) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAutoTypeFromAnnotation(AnnotationMirror annotation) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,10 +35,11 @@ import org.lwjgl.util.generator.NativeType;
|
|||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
|
||||
import com.sun.mirror.type.PrimitiveType;
|
||||
|
||||
@NativeType
|
||||
@Target({ ElementType.PARAMETER, ElementType.METHOD })
|
||||
public @interface cl_void {
|
||||
TypeKind value() default TypeKind.BYTE;
|
||||
PrimitiveType.Kind value() default PrimitiveType.Kind.BYTE;
|
||||
}
|
||||
|
|
@ -36,13 +36,13 @@ import org.lwjgl.util.generator.*;
|
|||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
|
||||
import com.sun.mirror.declaration.InterfaceDeclaration;
|
||||
import com.sun.mirror.declaration.MethodDeclaration;
|
||||
import com.sun.mirror.type.InterfaceType;
|
||||
|
||||
/**
|
||||
* Generator visitor for the context capabilities generator tool
|
||||
|
|
@ -53,13 +53,13 @@ import javax.lang.model.type.TypeMirror;
|
|||
*/
|
||||
public class GLCapabilitiesGenerator {
|
||||
|
||||
private static final String STUBS_LOADED_NAME = "loaded_stubs";
|
||||
private static final String ALL_INIT_METHOD_NAME = "initAllStubs";
|
||||
private static final String STUBS_LOADED_NAME = "loaded_stubs";
|
||||
private static final String ALL_INIT_METHOD_NAME = "initAllStubs";
|
||||
private static final String POINTER_INITIALIZER_POSTFIX = "_initNativeFunctionAddresses";
|
||||
private static final String CACHED_EXTS_VAR_NAME = "supported_extensions";
|
||||
private static final String PROFILE_MASK_VAR_NAME = "profileMask";
|
||||
private static final String EXTENSION_PREFIX = "GL_";
|
||||
private static final String CORE_PREFIX = "Open";
|
||||
private static final String CACHED_EXTS_VAR_NAME = "supported_extensions";
|
||||
private static final String PROFILE_MASK_VAR_NAME = "profileMask";
|
||||
private static final String EXTENSION_PREFIX = "GL_";
|
||||
private static final String CORE_PREFIX = "Open";
|
||||
|
||||
public static void generateClassPrologue(PrintWriter writer, boolean context_specific, boolean generate_error_checks) {
|
||||
writer.println("public class " + Utils.CONTEXT_CAPS_CLASS_NAME + " {");
|
||||
|
|
@ -84,32 +84,32 @@ public class GLCapabilitiesGenerator {
|
|||
return EXTENSION_PREFIX + interface_name;
|
||||
}
|
||||
|
||||
public static void generateSuperClassAdds(PrintWriter writer, TypeElement d, ProcessingEnvironment env) {
|
||||
List<? extends TypeMirror> super_interfaces = d.getInterfaces();
|
||||
public static void generateSuperClassAdds(PrintWriter writer, InterfaceDeclaration d) {
|
||||
Collection<InterfaceType> super_interfaces = d.getSuperinterfaces();
|
||||
if ( super_interfaces.size() > 1 )
|
||||
throw new RuntimeException(d + " extends more than one other interface");
|
||||
if ( super_interfaces.size() == 1 ) {
|
||||
TypeMirror super_interface = super_interfaces.iterator().next();
|
||||
InterfaceType super_interface = super_interfaces.iterator().next();
|
||||
writer.print("\t\tif (" + CACHED_EXTS_VAR_NAME + ".contains(\"");
|
||||
writer.println(translateFieldName(d.getSimpleName().toString()) + "\"))");
|
||||
writer.println(translateFieldName(d.getSimpleName()) + "\"))");
|
||||
writer.print("\t\t\t");
|
||||
generateAddExtension(writer, env.getElementUtils().getTypeElement(super_interface.toString()));
|
||||
generateAddExtension(writer, super_interface.getDeclaration());
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateInitializer(PrintWriter writer, TypeElement d, ProcessingEnvironment env) {
|
||||
String translated_field_name = translateFieldName(d.getSimpleName().toString());
|
||||
public static void generateInitializer(PrintWriter writer, InterfaceDeclaration d) {
|
||||
String translated_field_name = translateFieldName(d.getSimpleName());
|
||||
writer.print("\t\tthis." + translated_field_name + " = ");
|
||||
writer.print(CACHED_EXTS_VAR_NAME + ".contains(\"");
|
||||
writer.print(translated_field_name + "\")");
|
||||
List<? extends TypeMirror> super_interfaces = d.getInterfaces();
|
||||
Collection<InterfaceType> super_interfaces = d.getSuperinterfaces();
|
||||
if ( super_interfaces.size() > 1 )
|
||||
throw new RuntimeException(d + " extends more than one other interface");
|
||||
if ( super_interfaces.size() == 1 ) {
|
||||
TypeMirror super_interface = super_interfaces.iterator().next();
|
||||
InterfaceType super_interface = super_interfaces.iterator().next();
|
||||
writer.println();
|
||||
writer.print("\t\t\t&& " + CACHED_EXTS_VAR_NAME + ".contains(\"");
|
||||
writer.print(translateFieldName(env.getElementUtils().getTypeElement(super_interface.toString()).getSimpleName().toString()) + "\")");
|
||||
writer.print(translateFieldName(super_interface.getDeclaration().getSimpleName()) + "\")");
|
||||
}
|
||||
Alias alias_annotation = d.getAnnotation(Alias.class);
|
||||
if ( alias_annotation != null ) {
|
||||
|
|
@ -163,30 +163,30 @@ public class GLCapabilitiesGenerator {
|
|||
writer.println("\t}");
|
||||
}
|
||||
|
||||
public static void generateUnloadStubs(ProcessingEnvironment env, PrintWriter writer, TypeElement d) {
|
||||
if ( Utils.getMethods(d).size() > 0 ) {
|
||||
public static void generateUnloadStubs(PrintWriter writer, InterfaceDeclaration d) {
|
||||
if ( d.getMethods().size() > 0 ) {
|
||||
writer.print("\t\tGLContext.resetNativeStubs(" + Utils.getSimpleClassName(d));
|
||||
writer.println(".class);");
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateInitStubs(ProcessingEnvironment env, PrintWriter writer, TypeElement d, boolean context_specific) {
|
||||
if ( Utils.getMethods(d).size() > 0 ) {
|
||||
public static void generateInitStubs(PrintWriter writer, InterfaceDeclaration d, boolean context_specific) {
|
||||
if ( d.getMethods().size() > 0 ) {
|
||||
if ( context_specific ) {
|
||||
final Alias alias_annotation = d.getAnnotation(Alias.class);
|
||||
|
||||
if ( d.getAnnotation(ForceInit.class) != null )
|
||||
writer.println("\t\t" + CACHED_EXTS_VAR_NAME + ".add(\"" + translateFieldName(d.getSimpleName().toString()) + "\");");
|
||||
writer.println("\t\t" + CACHED_EXTS_VAR_NAME + ".add(\"" + translateFieldName(d.getSimpleName()) + "\");");
|
||||
writer.print("\t\tif (");
|
||||
if ( alias_annotation != null )
|
||||
writer.print("(");
|
||||
writer.print(CACHED_EXTS_VAR_NAME + ".contains(\"");
|
||||
writer.print(translateFieldName(d.getSimpleName().toString()) + "\")");
|
||||
writer.print(translateFieldName(d.getSimpleName()) + "\")");
|
||||
if ( alias_annotation != null ) {
|
||||
writer.print(" || " + CACHED_EXTS_VAR_NAME + ".contains(\"");
|
||||
writer.print(translateFieldName(alias_annotation.value()) + "\"))");
|
||||
}
|
||||
writer.print(" && !" + getAddressesInitializerName(d.getSimpleName().toString()) + "(");
|
||||
writer.print(" && !" + getAddressesInitializerName(d.getSimpleName()) + "(");
|
||||
if ( d.getAnnotation(DeprecatedGL.class) != null )
|
||||
writer.print("forwardCompatible");
|
||||
if ( d.getAnnotation(Dependent.class) != null ) {
|
||||
|
|
@ -201,27 +201,27 @@ public class GLCapabilitiesGenerator {
|
|||
} else
|
||||
writer.println("))");
|
||||
writer.print("\t\t\tremove(" + CACHED_EXTS_VAR_NAME + ", \"");
|
||||
writer.println(translateFieldName(d.getSimpleName().toString()) + "\");");
|
||||
writer.println(translateFieldName(d.getSimpleName()) + "\");");
|
||||
if ( alias_annotation != null )
|
||||
writer.println("\t\t}");
|
||||
} else {
|
||||
writer.print("\t\tGLContext." + Utils.STUB_INITIALIZER_NAME + "(" + Utils.getSimpleClassName(d));
|
||||
writer.println(".class, " + CACHED_EXTS_VAR_NAME + ", \"" + translateFieldName(d.getSimpleName().toString()) + "\");");
|
||||
writer.println(".class, " + CACHED_EXTS_VAR_NAME + ", \"" + translateFieldName(d.getSimpleName()) + "\");");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateAddExtension(PrintWriter writer, TypeElement d) {
|
||||
private static void generateAddExtension(PrintWriter writer, InterfaceDeclaration d) {
|
||||
writer.print(CACHED_EXTS_VAR_NAME + ".add(\"");
|
||||
writer.println(translateFieldName(d.getSimpleName().toString()) + "\");");
|
||||
writer.println(translateFieldName(d.getSimpleName()) + "\");");
|
||||
}
|
||||
|
||||
public static void generateAddressesInitializers(ProcessingEnvironment env, PrintWriter writer, TypeElement d) {
|
||||
Iterator<? extends ExecutableElement> methods = Utils.getMethods(d).iterator();
|
||||
public static void generateAddressesInitializers(PrintWriter writer, InterfaceDeclaration d) {
|
||||
Iterator<? extends MethodDeclaration> methods = d.getMethods().iterator();
|
||||
if ( !methods.hasNext() )
|
||||
return;
|
||||
|
||||
writer.print("\tprivate boolean " + getAddressesInitializerName(d.getSimpleName().toString()) + "(");
|
||||
writer.print("\tprivate boolean " + getAddressesInitializerName(d.getSimpleName()) + "(");
|
||||
|
||||
boolean optional;
|
||||
boolean deprecated = d.getAnnotation(DeprecatedGL.class) != null;
|
||||
|
|
@ -242,7 +242,7 @@ public class GLCapabilitiesGenerator {
|
|||
|
||||
boolean first = true;
|
||||
while ( methods.hasNext() ) {
|
||||
ExecutableElement method = methods.next();
|
||||
MethodDeclaration method = methods.next();
|
||||
if ( method.getAnnotation(Alternate.class) != null )
|
||||
continue;
|
||||
|
||||
|
|
@ -309,9 +309,9 @@ public class GLCapabilitiesGenerator {
|
|||
writer.println();
|
||||
}
|
||||
|
||||
public static void generateSymbolAddresses(ProcessingEnvironment env, PrintWriter writer, TypeElement d) {
|
||||
public static void generateSymbolAddresses(PrintWriter writer, InterfaceDeclaration d) {
|
||||
boolean first = true;
|
||||
for ( final ExecutableElement method : Utils.getMethods(d) ) {
|
||||
for ( final MethodDeclaration method : d.getMethods() ) {
|
||||
if ( method.getAnnotation(Alternate.class) != null || method.getAnnotation(Reuse.class) != null )
|
||||
continue;
|
||||
|
||||
|
|
@ -323,7 +323,7 @@ public class GLCapabilitiesGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
public static void generateField(PrintWriter writer, TypeElement d) {
|
||||
writer.println("\tpublic final boolean " + translateFieldName(d.getSimpleName().toString()) + ";");
|
||||
public static void generateField(PrintWriter writer, InterfaceDeclaration d) {
|
||||
writer.println("\tpublic final boolean " + translateFieldName(d.getSimpleName()) + ";");
|
||||
}
|
||||
}
|
||||
|
|
@ -36,13 +36,13 @@ import org.lwjgl.util.generator.*;
|
|||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.type.TypeMirror;
|
||||
|
||||
import com.sun.mirror.declaration.InterfaceDeclaration;
|
||||
import com.sun.mirror.declaration.MethodDeclaration;
|
||||
import com.sun.mirror.type.InterfaceType;
|
||||
|
||||
/**
|
||||
* Generator visitor for the context capabilities generator tool
|
||||
|
|
@ -53,12 +53,12 @@ import javax.lang.model.type.TypeMirror;
|
|||
*/
|
||||
public class GLESCapabilitiesGenerator {
|
||||
|
||||
private static final String STUBS_LOADED_NAME = "loaded_stubs";
|
||||
private static final String ALL_INIT_METHOD_NAME = "initAllStubs";
|
||||
private static final String STUBS_LOADED_NAME = "loaded_stubs";
|
||||
private static final String ALL_INIT_METHOD_NAME = "initAllStubs";
|
||||
private static final String POINTER_INITIALIZER_POSTFIX = "_initNativeFunctionAddresses";
|
||||
private static final String CACHED_EXTS_VAR_NAME = "supported_extensions";
|
||||
private static final String EXTENSION_PREFIX = "GL_";
|
||||
private static final String CORE_PREFIX = "Open";
|
||||
private static final String CACHED_EXTS_VAR_NAME = "supported_extensions";
|
||||
private static final String EXTENSION_PREFIX = "GL_";
|
||||
private static final String CORE_PREFIX = "Open";
|
||||
|
||||
public static void generateClassPrologue(PrintWriter writer, boolean context_specific, boolean generate_error_checks) {
|
||||
writer.println("public class " + Utils.CONTEXT_CAPS_CLASS_NAME + " {");
|
||||
|
|
@ -81,32 +81,32 @@ public class GLESCapabilitiesGenerator {
|
|||
return EXTENSION_PREFIX + interface_name;
|
||||
}
|
||||
|
||||
public static void generateSuperClassAdds(PrintWriter writer, TypeElement d, ProcessingEnvironment env) {
|
||||
List<? extends TypeMirror> super_interfaces = d.getInterfaces();
|
||||
public static void generateSuperClassAdds(PrintWriter writer, InterfaceDeclaration d) {
|
||||
Collection<InterfaceType> super_interfaces = d.getSuperinterfaces();
|
||||
if ( super_interfaces.size() > 1 )
|
||||
throw new RuntimeException(d + " extends more than one other interface");
|
||||
if ( super_interfaces.size() == 1 ) {
|
||||
TypeMirror super_interface = super_interfaces.iterator().next();
|
||||
InterfaceType super_interface = super_interfaces.iterator().next();
|
||||
writer.print("\t\tif (" + CACHED_EXTS_VAR_NAME + ".contains(\"");
|
||||
writer.println(translateFieldName(d.getSimpleName().toString() + "\"))"));
|
||||
writer.println(translateFieldName(d.getSimpleName()) + "\"))");
|
||||
writer.print("\t\t\t");
|
||||
generateAddExtension(writer, env.getElementUtils().getTypeElement(super_interface.toString()));
|
||||
generateAddExtension(writer, super_interface.getDeclaration());
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateInitializer(PrintWriter writer, TypeElement d, ProcessingEnvironment env) {
|
||||
String translated_field_name = translateFieldName(d.getSimpleName().toString());
|
||||
public static void generateInitializer(PrintWriter writer, InterfaceDeclaration d) {
|
||||
String translated_field_name = translateFieldName(d.getSimpleName());
|
||||
writer.print("\t\tthis." + translated_field_name + " = ");
|
||||
writer.print(CACHED_EXTS_VAR_NAME + ".contains(\"");
|
||||
writer.print(translated_field_name + "\")");
|
||||
List<? extends TypeMirror> super_interfaces = d.getInterfaces();
|
||||
Collection<InterfaceType> super_interfaces = d.getSuperinterfaces();
|
||||
if ( super_interfaces.size() > 1 )
|
||||
throw new RuntimeException(d + " extends more than one other interface");
|
||||
if ( super_interfaces.size() == 1 ) {
|
||||
TypeMirror super_interface = super_interfaces.iterator().next();
|
||||
InterfaceType super_interface = super_interfaces.iterator().next();
|
||||
writer.println();
|
||||
writer.print("\t\t\t&& " + CACHED_EXTS_VAR_NAME + ".contains(\"");
|
||||
writer.print(translateFieldName(env.getElementUtils().getTypeElement(super_interface.toString()).getSimpleName() + "\")"));
|
||||
writer.print(translateFieldName(super_interface.getDeclaration().getSimpleName()) + "\")");
|
||||
}
|
||||
Alias alias_annotation = d.getAnnotation(Alias.class);
|
||||
if ( alias_annotation != null ) {
|
||||
|
|
@ -125,9 +125,9 @@ public class GLESCapabilitiesGenerator {
|
|||
writer.println("\tprivate Set<String> " + ALL_INIT_METHOD_NAME + "() throws LWJGLException {");
|
||||
|
||||
if ( context_specific ) {
|
||||
// Load the basic pointers we need to detect OpenGL version and supported extensions.
|
||||
writer.println("\t\tglGetError = GLContext.getFunctionAddress(\"glGetError\");");
|
||||
writer.println("\t\tglGetString = GLContext.getFunctionAddress(\"glGetString\");");
|
||||
// Load the basic pointers we need to detect OpenGL version and supported extensions.
|
||||
writer.println("\t\tglGetError = GLContext.getFunctionAddress(\"glGetError\");");
|
||||
writer.println("\t\tglGetString = GLContext.getFunctionAddress(\"glGetString\");");
|
||||
}
|
||||
|
||||
// Get the supported extensions set.
|
||||
|
|
@ -153,31 +153,31 @@ public class GLESCapabilitiesGenerator {
|
|||
writer.println("\t}");
|
||||
}
|
||||
|
||||
public static void generateUnloadStubs(ProcessingEnvironment env, PrintWriter writer, TypeElement d) {
|
||||
public static void generateUnloadStubs(PrintWriter writer, InterfaceDeclaration d) {
|
||||
// TODO: Remove GLES
|
||||
if ( Utils.getMethods(d).size() > 0 && !d.getSimpleName().toString().startsWith("GLES") ) {
|
||||
if ( d.getMethods().size() > 0 && !d.getSimpleName().startsWith("GLES") ) {
|
||||
writer.print("\t\tGLContext.resetNativeStubs(" + Utils.getSimpleClassName(d));
|
||||
writer.println(".class);");
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateInitStubs(ProcessingEnvironment env, PrintWriter writer, TypeElement d, boolean context_specific) {
|
||||
if ( Utils.getMethods(d).size() > 0 ) {
|
||||
public static void generateInitStubs(PrintWriter writer, InterfaceDeclaration d, boolean context_specific) {
|
||||
if ( d.getMethods().size() > 0 ) {
|
||||
if ( context_specific ) {
|
||||
final Alias alias_annotation = d.getAnnotation(Alias.class);
|
||||
|
||||
if ( d.getAnnotation(ForceInit.class) != null )
|
||||
writer.println("\t\t" + CACHED_EXTS_VAR_NAME + ".add(\"" + translateFieldName(d.getSimpleName().toString()) + "\");");
|
||||
writer.println("\t\t" + CACHED_EXTS_VAR_NAME + ".add(\"" + translateFieldName(d.getSimpleName()) + "\");");
|
||||
writer.print("\t\tif (");
|
||||
if ( alias_annotation != null )
|
||||
writer.print("(");
|
||||
writer.print(CACHED_EXTS_VAR_NAME + ".contains(\"");
|
||||
writer.print(translateFieldName(d.getSimpleName().toString()) + "\")");
|
||||
writer.print(translateFieldName(d.getSimpleName()) + "\")");
|
||||
if ( alias_annotation != null ) {
|
||||
writer.print(" || " + CACHED_EXTS_VAR_NAME + ".contains(\"");
|
||||
writer.print(translateFieldName(alias_annotation.value()) + "\"))");
|
||||
}
|
||||
writer.print(" && !" + getAddressesInitializerName(d.getSimpleName().toString()) + "(");
|
||||
writer.print(" && !" + getAddressesInitializerName(d.getSimpleName()) + "(");
|
||||
if ( d.getAnnotation(Dependent.class) != null )
|
||||
writer.print("supported_extensions");
|
||||
if ( alias_annotation != null ) {
|
||||
|
|
@ -187,27 +187,27 @@ public class GLESCapabilitiesGenerator {
|
|||
} else
|
||||
writer.println("))");
|
||||
writer.print("\t\t\tremove(" + CACHED_EXTS_VAR_NAME + ", \"");
|
||||
writer.println(translateFieldName(d.getSimpleName().toString()) + "\");");
|
||||
writer.println(translateFieldName(d.getSimpleName()) + "\");");
|
||||
if ( alias_annotation != null )
|
||||
writer.println("\t\t}");
|
||||
} else {
|
||||
writer.print("\t\tGLContext." + Utils.STUB_INITIALIZER_NAME + "(" + Utils.getSimpleClassName(d));
|
||||
writer.println(".class, " + CACHED_EXTS_VAR_NAME + ", \"" + translateFieldName(d.getSimpleName().toString()) + "\");");
|
||||
writer.println(".class, " + CACHED_EXTS_VAR_NAME + ", \"" + translateFieldName(d.getSimpleName()) + "\");");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateAddExtension(PrintWriter writer, TypeElement d) {
|
||||
private static void generateAddExtension(PrintWriter writer, InterfaceDeclaration d) {
|
||||
writer.print(CACHED_EXTS_VAR_NAME + ".add(\"");
|
||||
writer.println(translateFieldName(d.getSimpleName().toString()) + "\");");
|
||||
writer.println(translateFieldName(d.getSimpleName()) + "\");");
|
||||
}
|
||||
|
||||
public static void generateAddressesInitializers(ProcessingEnvironment env, PrintWriter writer, TypeElement d) {
|
||||
Iterator<? extends ExecutableElement> methods = Utils.getMethods(d).iterator();
|
||||
public static void generateAddressesInitializers(PrintWriter writer, InterfaceDeclaration d) {
|
||||
Iterator<? extends MethodDeclaration> methods = d.getMethods().iterator();
|
||||
if ( !methods.hasNext() )
|
||||
return;
|
||||
|
||||
writer.print("\tprivate boolean " + getAddressesInitializerName(d.getSimpleName().toString()) + "(");
|
||||
writer.print("\tprivate boolean " + getAddressesInitializerName(d.getSimpleName()) + "(");
|
||||
|
||||
boolean optional;
|
||||
Dependent dependent = d.getAnnotation(Dependent.class);
|
||||
|
|
@ -223,7 +223,7 @@ public class GLESCapabilitiesGenerator {
|
|||
|
||||
boolean first = true;
|
||||
while ( methods.hasNext() ) {
|
||||
ExecutableElement method = methods.next();
|
||||
MethodDeclaration method = methods.next();
|
||||
if ( method.getAnnotation(Alternate.class) != null )
|
||||
continue;
|
||||
|
||||
|
|
@ -287,9 +287,9 @@ public class GLESCapabilitiesGenerator {
|
|||
writer.println();
|
||||
}
|
||||
|
||||
public static void generateSymbolAddresses(ProcessingEnvironment env, PrintWriter writer, TypeElement d) {
|
||||
public static void generateSymbolAddresses(PrintWriter writer, InterfaceDeclaration d) {
|
||||
boolean first = true;
|
||||
for ( final ExecutableElement method : Utils.getMethods(d) ) {
|
||||
for ( final MethodDeclaration method : d.getMethods() ) {
|
||||
if ( method.getAnnotation(Alternate.class) != null || method.getAnnotation(Reuse.class) != null )
|
||||
continue;
|
||||
|
||||
|
|
@ -301,8 +301,8 @@ public class GLESCapabilitiesGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
public static void generateField(PrintWriter writer, TypeElement d) {
|
||||
writer.println("\tpublic final boolean " + translateFieldName(d.getSimpleName().toString()) + ";");
|
||||
public static void generateField(PrintWriter writer, InterfaceDeclaration d) {
|
||||
writer.println("\tpublic final boolean " + translateFieldName(d.getSimpleName()) + ";");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,161 +0,0 @@
|
|||
/*
|
||||
* 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
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.lwjgl.util.generator.opengl;
|
||||
|
||||
import org.lwjgl.util.generator.Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.annotation.processing.*;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.util.ElementFilter;
|
||||
|
||||
/**
|
||||
* Generator tool for creating the ContexCapabilities class
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision: 3316 $ $Id: ContextGeneratorProcessorFactory.java 3316
|
||||
* 2010-04-09 23:57:40Z spasi $
|
||||
*/
|
||||
@SupportedAnnotationTypes({ "*" })
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_7)
|
||||
@SupportedOptions({ "contextspecific", "generatechecks" })
|
||||
public class GLESGeneratorProcessor extends AbstractProcessor {
|
||||
|
||||
private static boolean first_round = true;
|
||||
|
||||
@Override
|
||||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||
if ( roundEnv.processingOver() || !first_round ) {
|
||||
System.exit(0);
|
||||
return true;
|
||||
}
|
||||
Map<String, String> options = processingEnv.getOptions();
|
||||
boolean generate_error_checks = options.containsKey("generatechecks");
|
||||
boolean context_specific = options.containsKey("contextspecific");
|
||||
try {
|
||||
generateContextCapabilitiesSource(ElementFilter.typesIn(roundEnv.getRootElements()), context_specific, generate_error_checks);
|
||||
first_round = false;
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void generateContextCapabilitiesSource(Set<TypeElement> templates, boolean context_specific, boolean generate_error_checks) throws IOException {
|
||||
PrintWriter writer = new PrintWriter(processingEnv.getFiler().createSourceFile("org.lwjgl.opengles." + Utils.CONTEXT_CAPS_CLASS_NAME, processingEnv.getElementUtils().getPackageElement("org.lwjgl.opengles")).openWriter());
|
||||
writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
|
||||
writer.println();
|
||||
writer.println("package org.lwjgl.opengles;");
|
||||
writer.println();
|
||||
writer.println("import org.lwjgl.LWJGLException;");
|
||||
writer.println("import org.lwjgl.LWJGLUtil;");
|
||||
writer.println("import java.util.Set;");
|
||||
writer.println("import java.util.HashSet;");
|
||||
writer.println();
|
||||
GLESCapabilitiesGenerator.generateClassPrologue(writer, context_specific, generate_error_checks);
|
||||
for ( TypeElement interface_decl : templates ) {
|
||||
if ( interface_decl.getKind().isInterface() ) {
|
||||
if ( Utils.isFinal(interface_decl) ) {
|
||||
GLESCapabilitiesGenerator.generateField(writer, interface_decl);
|
||||
}
|
||||
}
|
||||
}
|
||||
writer.println();
|
||||
if ( context_specific ) {
|
||||
for ( TypeElement interface_decl : templates ) {
|
||||
if ( interface_decl.getKind().isInterface() ) {
|
||||
GLESCapabilitiesGenerator.generateSymbolAddresses(processingEnv, writer, interface_decl);
|
||||
}
|
||||
}
|
||||
writer.println();
|
||||
for ( TypeElement interface_decl : templates ) {
|
||||
if ( interface_decl.getKind().isInterface() ) {
|
||||
GLESCapabilitiesGenerator.generateAddressesInitializers(processingEnv, writer, interface_decl);
|
||||
}
|
||||
}
|
||||
writer.println();
|
||||
}
|
||||
|
||||
if ( context_specific ) {
|
||||
writer.println("\tprivate static void remove(Set supported_extensions, String extension) {");
|
||||
writer.println("\t\tLWJGLUtil.log(extension + \" was reported as available but an entry point is missing\");");
|
||||
writer.println("\t\tsupported_extensions.remove(extension);");
|
||||
writer.println("\t}\n");
|
||||
}
|
||||
|
||||
GLESCapabilitiesGenerator.generateInitStubsPrologue(writer, context_specific);
|
||||
for ( TypeElement interface_decl : templates ) {
|
||||
if ( interface_decl.getKind().isInterface() ) {
|
||||
GLESCapabilitiesGenerator.generateSuperClassAdds(writer, interface_decl, processingEnv);
|
||||
}
|
||||
}
|
||||
for ( TypeElement interface_decl : templates ) {
|
||||
if ( interface_decl.getKind().isInterface() ) {
|
||||
if ( "GLES20".equals(interface_decl.getSimpleName().toString()) ) {
|
||||
continue;
|
||||
}
|
||||
GLESCapabilitiesGenerator.generateInitStubs(processingEnv, writer, interface_decl, context_specific);
|
||||
}
|
||||
}
|
||||
GLESCapabilitiesGenerator.generateInitStubsEpilogue(writer, context_specific);
|
||||
writer.println();
|
||||
writer.println("\tstatic void unloadAllStubs() {");
|
||||
if ( !context_specific ) {
|
||||
writer.println("\t\tif (!loaded_stubs)");
|
||||
writer.println("\t\t\treturn;");
|
||||
for ( TypeElement interface_decl : templates ) {
|
||||
if ( interface_decl.getKind().isInterface() ) {
|
||||
GLESCapabilitiesGenerator.generateUnloadStubs(processingEnv, writer, interface_decl);
|
||||
}
|
||||
}
|
||||
writer.println("\t\tloaded_stubs = false;");
|
||||
}
|
||||
writer.println("\t}");
|
||||
writer.println();
|
||||
GLESCapabilitiesGenerator.generateInitializerPrologue(writer);
|
||||
for ( TypeElement interface_decl : templates ) {
|
||||
if ( interface_decl.getKind().isInterface() ) {
|
||||
if ( Utils.isFinal(interface_decl) ) {
|
||||
GLESCapabilitiesGenerator.generateInitializer(writer, interface_decl, processingEnv);
|
||||
}
|
||||
}
|
||||
}
|
||||
writer.println("\t}");
|
||||
writer.println("}");
|
||||
writer.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,184 @@
|
|||
/*
|
||||
* 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
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.lwjgl.util.generator.opengl;
|
||||
|
||||
import org.lwjgl.util.generator.Utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sun.mirror.apt.*;
|
||||
import com.sun.mirror.declaration.AnnotationTypeDeclaration;
|
||||
import com.sun.mirror.declaration.InterfaceDeclaration;
|
||||
import com.sun.mirror.declaration.TypeDeclaration;
|
||||
import com.sun.mirror.util.DeclarationFilter;
|
||||
|
||||
import static java.util.Collections.*;
|
||||
|
||||
/**
|
||||
* Generator tool for creating the ContexCapabilities class
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision: 3316 $
|
||||
* $Id: ContextGeneratorProcessorFactory.java 3316 2010-04-09 23:57:40Z spasi $
|
||||
*/
|
||||
public class GLESGeneratorProcessorFactory implements AnnotationProcessorFactory, RoundCompleteListener {
|
||||
|
||||
private static boolean first_round = true;
|
||||
|
||||
// Process any set of annotations
|
||||
private static final Collection<String> supportedAnnotations =
|
||||
unmodifiableCollection(Arrays.asList("*"));
|
||||
|
||||
public Collection<String> supportedAnnotationTypes() {
|
||||
return supportedAnnotations;
|
||||
}
|
||||
|
||||
public Collection<String> supportedOptions() {
|
||||
return unmodifiableCollection(Arrays.asList("-Acontextspecific", "-Ageneratechecks"));
|
||||
}
|
||||
|
||||
public void roundComplete(RoundCompleteEvent event) {
|
||||
first_round = false;
|
||||
}
|
||||
|
||||
public AnnotationProcessor getProcessorFor(Set<AnnotationTypeDeclaration> atds, AnnotationProcessorEnvironment env) {
|
||||
// Only process the initial types, not the generated ones
|
||||
if ( first_round ) {
|
||||
env.addListener(this);
|
||||
return new GeneratorProcessor(env);
|
||||
} else
|
||||
return AnnotationProcessors.NO_OP;
|
||||
}
|
||||
|
||||
private static class GeneratorProcessor implements AnnotationProcessor {
|
||||
|
||||
private final AnnotationProcessorEnvironment env;
|
||||
|
||||
GeneratorProcessor(AnnotationProcessorEnvironment env) {
|
||||
this.env = env;
|
||||
}
|
||||
|
||||
public void process() {
|
||||
Map<String, String> options = env.getOptions();
|
||||
boolean generate_error_checks = options.containsKey("-Ageneratechecks");
|
||||
boolean context_specific = options.containsKey("-Acontextspecific");
|
||||
try {
|
||||
generateContextCapabilitiesSource(context_specific, generate_error_checks);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void generateContextCapabilitiesSource(boolean context_specific, boolean generate_error_checks) throws IOException {
|
||||
PrintWriter writer = env.getFiler().createTextFile(Filer.Location.SOURCE_TREE, "org.lwjgl.opengles", new File(Utils.CONTEXT_CAPS_CLASS_NAME + ".java"), null);
|
||||
writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
|
||||
writer.println();
|
||||
writer.println("package org.lwjgl.opengles;");
|
||||
writer.println();
|
||||
writer.println("import org.lwjgl.LWJGLException;");
|
||||
writer.println("import org.lwjgl.LWJGLUtil;");
|
||||
writer.println("import java.util.Set;");
|
||||
writer.println("import java.util.HashSet;");
|
||||
writer.println();
|
||||
GLESCapabilitiesGenerator.generateClassPrologue(writer, context_specific, generate_error_checks);
|
||||
DeclarationFilter filter = DeclarationFilter.getFilter(InterfaceDeclaration.class);
|
||||
Collection<TypeDeclaration> interface_decls = filter.filter(env.getSpecifiedTypeDeclarations());
|
||||
for ( TypeDeclaration typedecl : interface_decls ) {
|
||||
InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
|
||||
if ( Utils.isFinal(interface_decl) )
|
||||
GLESCapabilitiesGenerator.generateField(writer, interface_decl);
|
||||
}
|
||||
writer.println();
|
||||
if ( context_specific ) {
|
||||
for ( TypeDeclaration typedecl : interface_decls ) {
|
||||
InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
|
||||
GLESCapabilitiesGenerator.generateSymbolAddresses(writer, interface_decl);
|
||||
}
|
||||
writer.println();
|
||||
for ( TypeDeclaration typedecl : interface_decls ) {
|
||||
InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
|
||||
GLESCapabilitiesGenerator.generateAddressesInitializers(writer, interface_decl);
|
||||
}
|
||||
writer.println();
|
||||
}
|
||||
|
||||
if ( context_specific ) {
|
||||
writer.println("\tprivate static void remove(Set supported_extensions, String extension) {");
|
||||
writer.println("\t\tLWJGLUtil.log(extension + \" was reported as available but an entry point is missing\");");
|
||||
writer.println("\t\tsupported_extensions.remove(extension);");
|
||||
writer.println("\t}\n");
|
||||
}
|
||||
|
||||
GLESCapabilitiesGenerator.generateInitStubsPrologue(writer, context_specific);
|
||||
for ( TypeDeclaration typedecl : interface_decls ) {
|
||||
InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
|
||||
GLESCapabilitiesGenerator.generateSuperClassAdds(writer, interface_decl);
|
||||
}
|
||||
for ( TypeDeclaration typedecl : interface_decls ) {
|
||||
InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
|
||||
if ( "GLES20".equals(interface_decl.getSimpleName()) )
|
||||
continue;
|
||||
GLESCapabilitiesGenerator.generateInitStubs(writer, interface_decl, context_specific);
|
||||
}
|
||||
GLESCapabilitiesGenerator.generateInitStubsEpilogue(writer, context_specific);
|
||||
writer.println();
|
||||
writer.println("\tstatic void unloadAllStubs() {");
|
||||
if ( !context_specific ) {
|
||||
writer.println("\t\tif (!loaded_stubs)");
|
||||
writer.println("\t\t\treturn;");
|
||||
for ( TypeDeclaration typedecl : interface_decls ) {
|
||||
InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
|
||||
GLESCapabilitiesGenerator.generateUnloadStubs(writer, interface_decl);
|
||||
}
|
||||
writer.println("\t\tloaded_stubs = false;");
|
||||
}
|
||||
writer.println("\t}");
|
||||
writer.println();
|
||||
GLESCapabilitiesGenerator.generateInitializerPrologue(writer);
|
||||
for ( TypeDeclaration typedecl : interface_decls ) {
|
||||
InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
|
||||
if ( Utils.isFinal(interface_decl) )
|
||||
GLESCapabilitiesGenerator.generateInitializer(writer, interface_decl);
|
||||
}
|
||||
writer.println("\t}");
|
||||
writer.println("}");
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -51,73 +51,67 @@ import java.lang.annotation.Annotation;
|
|||
import java.nio.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
|
||||
import com.sun.mirror.declaration.AnnotationMirror;
|
||||
import com.sun.mirror.declaration.MethodDeclaration;
|
||||
import com.sun.mirror.type.PrimitiveType;
|
||||
|
||||
public class GLESTypeMap implements TypeMap {
|
||||
|
||||
private static final Map<Class<? extends Annotation>, TypeKind> native_types_to_primitive;
|
||||
private static final Map<Class<? extends Annotation>, PrimitiveType.Kind> native_types_to_primitive;
|
||||
|
||||
static {
|
||||
native_types_to_primitive = new HashMap<Class<? extends Annotation>, TypeKind>();
|
||||
native_types_to_primitive.put(GLbitfield.class, TypeKind.INT);
|
||||
native_types_to_primitive.put(GLclampf.class, TypeKind.FLOAT);
|
||||
native_types_to_primitive.put(GLfloat.class, TypeKind.FLOAT);
|
||||
native_types_to_primitive.put(GLint.class, TypeKind.INT);
|
||||
native_types_to_primitive.put(GLshort.class, TypeKind.SHORT);
|
||||
native_types_to_primitive.put(GLsizeiptr.class, TypeKind.LONG);
|
||||
native_types_to_primitive.put(GLuint.class, TypeKind.INT);
|
||||
native_types_to_primitive.put(GLboolean.class, TypeKind.BOOLEAN);
|
||||
native_types_to_primitive.put(GLchar.class, TypeKind.BYTE);
|
||||
native_types_to_primitive.put(GLhalf.class, TypeKind.SHORT);
|
||||
native_types_to_primitive.put(GLsizei.class, TypeKind.INT);
|
||||
native_types_to_primitive.put(GLushort.class, TypeKind.SHORT);
|
||||
native_types_to_primitive.put(GLbyte.class, TypeKind.BYTE);
|
||||
native_types_to_primitive.put(GLenum.class, TypeKind.INT);
|
||||
native_types_to_primitive.put(GLintptr.class, TypeKind.LONG);
|
||||
native_types_to_primitive.put(GLubyte.class, TypeKind.BYTE);
|
||||
native_types_to_primitive.put(GLvoid.class, TypeKind.BYTE);
|
||||
native_types_to_primitive.put(EGLint64NV.class, TypeKind.LONG);
|
||||
native_types_to_primitive.put(EGLuint64NV.class, TypeKind.LONG);
|
||||
native_types_to_primitive.put(GLint64.class, TypeKind.LONG);
|
||||
native_types_to_primitive.put(GLuint64.class, TypeKind.LONG);
|
||||
native_types_to_primitive = new HashMap<Class<? extends Annotation>, PrimitiveType.Kind>();
|
||||
native_types_to_primitive.put(GLbitfield.class, PrimitiveType.Kind.INT);
|
||||
native_types_to_primitive.put(GLclampf.class, PrimitiveType.Kind.FLOAT);
|
||||
native_types_to_primitive.put(GLfloat.class, PrimitiveType.Kind.FLOAT);
|
||||
native_types_to_primitive.put(GLint.class, PrimitiveType.Kind.INT);
|
||||
native_types_to_primitive.put(GLshort.class, PrimitiveType.Kind.SHORT);
|
||||
native_types_to_primitive.put(GLsizeiptr.class, PrimitiveType.Kind.LONG);
|
||||
native_types_to_primitive.put(GLuint.class, PrimitiveType.Kind.INT);
|
||||
native_types_to_primitive.put(GLboolean.class, PrimitiveType.Kind.BOOLEAN);
|
||||
native_types_to_primitive.put(GLchar.class, PrimitiveType.Kind.BYTE);
|
||||
native_types_to_primitive.put(GLhalf.class, PrimitiveType.Kind.SHORT);
|
||||
native_types_to_primitive.put(GLsizei.class, PrimitiveType.Kind.INT);
|
||||
native_types_to_primitive.put(GLushort.class, PrimitiveType.Kind.SHORT);
|
||||
native_types_to_primitive.put(GLbyte.class, PrimitiveType.Kind.BYTE);
|
||||
native_types_to_primitive.put(GLenum.class, PrimitiveType.Kind.INT);
|
||||
native_types_to_primitive.put(GLintptr.class, PrimitiveType.Kind.LONG);
|
||||
native_types_to_primitive.put(GLubyte.class, PrimitiveType.Kind.BYTE);
|
||||
native_types_to_primitive.put(GLvoid.class, PrimitiveType.Kind.BYTE);
|
||||
native_types_to_primitive.put(EGLint64NV.class, PrimitiveType.Kind.LONG);
|
||||
native_types_to_primitive.put(EGLuint64NV.class, PrimitiveType.Kind.LONG);
|
||||
native_types_to_primitive.put(GLint64.class, PrimitiveType.Kind.LONG);
|
||||
native_types_to_primitive.put(GLuint64.class, PrimitiveType.Kind.LONG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeKind getPrimitiveTypeFromNativeType(Class<? extends Annotation> native_type) {
|
||||
TypeKind kind = native_types_to_primitive.get(native_type);
|
||||
public PrimitiveType.Kind getPrimitiveTypeFromNativeType(Class<? extends Annotation> native_type) {
|
||||
PrimitiveType.Kind kind = native_types_to_primitive.get(native_type);
|
||||
if ( kind == null )
|
||||
throw new RuntimeException("Unsupported type " + native_type);
|
||||
return kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printCapabilitiesInit(final PrintWriter writer) {
|
||||
writer.println("\t\tContextCapabilities caps = GLContext.getCapabilities();");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCapabilities() {
|
||||
return "caps";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAPIUtilParam(boolean comma) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printErrorCheckMethod(final PrintWriter writer, final ExecutableElement method, final String tabs) {
|
||||
public void printErrorCheckMethod(final PrintWriter writer, final MethodDeclaration method, final String tabs) {
|
||||
writer.println(tabs + "Util.checkGLError();");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRegisterNativesFunctionName() {
|
||||
return "extgl_InitializeClass";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Signedness getSignednessFromType(Class<? extends Annotation> type) {
|
||||
if ( GLuint.class.equals(type) )
|
||||
return Signedness.UNSIGNED;
|
||||
|
|
@ -139,7 +133,6 @@ public class GLESTypeMap implements TypeMap {
|
|||
return Signedness.NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String translateAnnotation(Class annotation_type) {
|
||||
if ( annotation_type.equals(GLuint64.class) || annotation_type.equals(GLint64.class) )
|
||||
return "i64";
|
||||
|
|
@ -161,8 +154,7 @@ public class GLESTypeMap implements TypeMap {
|
|||
throw new RuntimeException(annotation_type + " is not allowed");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getNativeTypeFromPrimitiveType(TypeKind kind) {
|
||||
public Class<? extends Annotation> getNativeTypeFromPrimitiveType(PrimitiveType.Kind kind) {
|
||||
Class<? extends Annotation> type;
|
||||
switch ( kind ) {
|
||||
case INT:
|
||||
|
|
@ -189,22 +181,18 @@ public class GLESTypeMap implements TypeMap {
|
|||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getVoidType() {
|
||||
return GLvoid.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getStringElementType() {
|
||||
return GLubyte.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getStringArrayType() {
|
||||
return GLchar.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getByteBufferArrayType() {
|
||||
return GLubyte.class;
|
||||
}
|
||||
|
|
@ -243,22 +231,18 @@ public class GLESTypeMap implements TypeMap {
|
|||
return new Class[] { };
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypedefPostfix() {
|
||||
return "GL_APICALL ";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFunctionPrefix() {
|
||||
return "GL_APIENTRY";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printNativeIncludes(PrintWriter writer) {
|
||||
writer.println("#include \"extgl.h\"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class[] getValidAnnotationTypes(Class type) {
|
||||
Class[] valid_types;
|
||||
if ( Buffer.class.isAssignableFrom(type) )
|
||||
|
|
@ -276,7 +260,6 @@ public class GLESTypeMap implements TypeMap {
|
|||
return valid_types;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getInverseType(Class<? extends Annotation> type) {
|
||||
if ( GLuint64.class.equals(type) )
|
||||
return GLint64.class;
|
||||
|
|
@ -296,7 +279,6 @@ public class GLESTypeMap implements TypeMap {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAutoTypeFromAnnotation(AnnotationMirror annotation) {
|
||||
Class annotation_class = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
|
||||
if ( annotation_class.equals(GLint.class) )
|
||||
|
|
|
|||
|
|
@ -1,160 +0,0 @@
|
|||
/*
|
||||
* 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
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.lwjgl.util.generator.opengl;
|
||||
|
||||
import org.lwjgl.util.generator.Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import javax.annotation.processing.*;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.util.ElementFilter;
|
||||
|
||||
/**
|
||||
* Generator tool for creating the ContexCapabilities class
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision: 3316 $ $Id: ContextGeneratorProcessorFactory.java 3316
|
||||
* 2010-04-09 23:57:40Z spasi $
|
||||
*/
|
||||
@SupportedAnnotationTypes({ "*" })
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_7)
|
||||
@SupportedOptions({ "generatechecks", "contextspecific" })
|
||||
public class GLGeneratorProcessor extends AbstractProcessor {
|
||||
|
||||
private static boolean first_round = true;
|
||||
|
||||
@Override
|
||||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||
if ( roundEnv.processingOver() || !first_round ) {
|
||||
System.exit(0);
|
||||
return true;
|
||||
}
|
||||
Map<String, String> options = processingEnv.getOptions();
|
||||
boolean generate_error_checks = options.containsKey("generatechecks");
|
||||
boolean context_specific = options.containsKey("contextspecific");
|
||||
try {
|
||||
generateContextCapabilitiesSource(ElementFilter.typesIn(roundEnv.getRootElements()), context_specific, generate_error_checks);
|
||||
first_round = false;
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void generateContextCapabilitiesSource(Set<TypeElement> templates, boolean context_specific, boolean generate_error_checks) throws IOException {
|
||||
PrintWriter writer = new PrintWriter(processingEnv.getFiler().createSourceFile("org.lwjgl.opengl." + Utils.CONTEXT_CAPS_CLASS_NAME, processingEnv.getElementUtils().getPackageElement("org.lwjgl.opengl")).openWriter());
|
||||
writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
|
||||
writer.println();
|
||||
writer.println("package org.lwjgl.opengl;");
|
||||
writer.println();
|
||||
writer.println("import org.lwjgl.LWJGLException;");
|
||||
writer.println("import org.lwjgl.LWJGLUtil;");
|
||||
writer.println("import java.util.Set;");
|
||||
writer.println("import java.util.HashSet;");
|
||||
writer.println();
|
||||
GLCapabilitiesGenerator.generateClassPrologue(writer, context_specific, generate_error_checks);
|
||||
for ( TypeElement interface_decl : templates ) {
|
||||
if ( interface_decl.getKind().isInterface() ) {
|
||||
if ( Utils.isFinal(interface_decl) ) {
|
||||
GLCapabilitiesGenerator.generateField(writer, interface_decl);
|
||||
}
|
||||
}
|
||||
}
|
||||
writer.println();
|
||||
for ( TypeElement interface_decl : templates ) {
|
||||
if ( interface_decl.getKind().isInterface() ) {
|
||||
GLCapabilitiesGenerator.generateSymbolAddresses(processingEnv, writer, interface_decl);
|
||||
}
|
||||
}
|
||||
writer.println();
|
||||
if ( context_specific ) {
|
||||
for ( TypeElement interface_decl : templates ) {
|
||||
if ( interface_decl.getKind().isInterface() ) {
|
||||
GLCapabilitiesGenerator.generateAddressesInitializers(processingEnv, writer, interface_decl);
|
||||
}
|
||||
}
|
||||
writer.println();
|
||||
}
|
||||
|
||||
writer.println("\tprivate static void remove(Set supported_extensions, String extension) {");
|
||||
writer.println("\t\tLWJGLUtil.log(extension + \" was reported as available but an entry point is missing\");");
|
||||
writer.println("\t\tsupported_extensions.remove(extension);");
|
||||
writer.println("\t}\n");
|
||||
|
||||
GLCapabilitiesGenerator.generateInitStubsPrologue(writer, context_specific);
|
||||
for ( TypeElement interface_decl : templates ) {
|
||||
if ( interface_decl.getKind().isInterface() ) {
|
||||
GLCapabilitiesGenerator.generateSuperClassAdds(writer, interface_decl, processingEnv);
|
||||
}
|
||||
}
|
||||
for ( TypeElement interface_decl : templates ) {
|
||||
if ( interface_decl.getKind().isInterface() ) {
|
||||
String simple_name = interface_decl.getSimpleName().toString();
|
||||
if ( "GL11".equals(simple_name) ) {
|
||||
continue;
|
||||
}
|
||||
GLCapabilitiesGenerator.generateInitStubs(processingEnv, writer, interface_decl, context_specific);
|
||||
}
|
||||
}
|
||||
GLCapabilitiesGenerator.generateInitStubsEpilogue(writer, context_specific);
|
||||
writer.println();
|
||||
writer.println("\tstatic void unloadAllStubs() {");
|
||||
if ( !context_specific ) {
|
||||
writer.println("\t\tif (!loaded_stubs)");
|
||||
writer.println("\t\t\treturn;");
|
||||
for ( TypeElement interface_decl : templates ) {
|
||||
if ( interface_decl.getKind().isInterface() ) {
|
||||
GLCapabilitiesGenerator.generateUnloadStubs(processingEnv, writer, interface_decl);
|
||||
}
|
||||
}
|
||||
writer.println("\t\tloaded_stubs = false;");
|
||||
}
|
||||
writer.println("\t}");
|
||||
writer.println();
|
||||
GLCapabilitiesGenerator.generateInitializerPrologue(writer);
|
||||
for ( TypeElement interface_decl : templates ) {
|
||||
if ( interface_decl.getKind().isInterface() ) {
|
||||
if ( Utils.isFinal(interface_decl) ) {
|
||||
GLCapabilitiesGenerator.generateInitializer(writer, interface_decl, processingEnv);
|
||||
}
|
||||
}
|
||||
}
|
||||
writer.println("\t\ttracker.init();");
|
||||
writer.println("\t}");
|
||||
writer.println("}");
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,189 @@
|
|||
/*
|
||||
* 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
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.lwjgl.util.generator.opengl;
|
||||
|
||||
import org.lwjgl.util.generator.Utils;
|
||||
|
||||
import static java.util.Collections.unmodifiableCollection;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sun.mirror.apt.AnnotationProcessor;
|
||||
import com.sun.mirror.apt.AnnotationProcessorEnvironment;
|
||||
import com.sun.mirror.apt.AnnotationProcessorFactory;
|
||||
import com.sun.mirror.apt.AnnotationProcessors;
|
||||
import com.sun.mirror.apt.Filer;
|
||||
import com.sun.mirror.apt.RoundCompleteEvent;
|
||||
import com.sun.mirror.apt.RoundCompleteListener;
|
||||
import com.sun.mirror.declaration.AnnotationTypeDeclaration;
|
||||
import com.sun.mirror.declaration.InterfaceDeclaration;
|
||||
import com.sun.mirror.declaration.TypeDeclaration;
|
||||
import com.sun.mirror.util.DeclarationFilter;
|
||||
|
||||
/**
|
||||
*
|
||||
* Generator tool for creating the ContexCapabilities class
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision: 3316 $
|
||||
* $Id: ContextGeneratorProcessorFactory.java 3316 2010-04-09 23:57:40Z spasi $
|
||||
*/
|
||||
public class GLGeneratorProcessorFactory implements AnnotationProcessorFactory, RoundCompleteListener {
|
||||
private static boolean first_round = true;
|
||||
|
||||
// Process any set of annotations
|
||||
private static final Collection<String> supportedAnnotations =
|
||||
unmodifiableCollection(Arrays.asList("*"));
|
||||
|
||||
public Collection<String> supportedAnnotationTypes() {
|
||||
return supportedAnnotations;
|
||||
}
|
||||
|
||||
public Collection<String> supportedOptions() {
|
||||
return unmodifiableCollection(Arrays.asList("-Acontextspecific", "-Ageneratechecks"));
|
||||
}
|
||||
|
||||
public void roundComplete(RoundCompleteEvent event) {
|
||||
first_round = false;
|
||||
}
|
||||
|
||||
public AnnotationProcessor getProcessorFor(Set<AnnotationTypeDeclaration> atds, AnnotationProcessorEnvironment env) {
|
||||
// Only process the initial types, not the generated ones
|
||||
if (first_round) {
|
||||
env.addListener(this);
|
||||
return new GeneratorProcessor(env);
|
||||
} else
|
||||
return AnnotationProcessors.NO_OP;
|
||||
}
|
||||
|
||||
private static class GeneratorProcessor implements AnnotationProcessor {
|
||||
private final AnnotationProcessorEnvironment env;
|
||||
|
||||
GeneratorProcessor(AnnotationProcessorEnvironment env) {
|
||||
this.env = env;
|
||||
}
|
||||
|
||||
public void process() {
|
||||
Map<String, String> options = env.getOptions();
|
||||
boolean generate_error_checks = options.containsKey("-Ageneratechecks");
|
||||
boolean context_specific = options.containsKey("-Acontextspecific");
|
||||
try {
|
||||
generateContextCapabilitiesSource(context_specific, generate_error_checks);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void generateContextCapabilitiesSource(boolean context_specific, boolean generate_error_checks) throws IOException {
|
||||
PrintWriter writer = env.getFiler().createTextFile(Filer.Location.SOURCE_TREE, "org.lwjgl.opengl", new File(Utils.CONTEXT_CAPS_CLASS_NAME + ".java"), null);
|
||||
writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
|
||||
writer.println();
|
||||
writer.println("package org.lwjgl.opengl;");
|
||||
writer.println();
|
||||
writer.println("import org.lwjgl.LWJGLException;");
|
||||
writer.println("import org.lwjgl.LWJGLUtil;");
|
||||
writer.println("import java.util.Set;");
|
||||
writer.println("import java.util.HashSet;");
|
||||
writer.println();
|
||||
GLCapabilitiesGenerator.generateClassPrologue(writer, context_specific, generate_error_checks);
|
||||
DeclarationFilter filter = DeclarationFilter.getFilter(InterfaceDeclaration.class);
|
||||
Collection<TypeDeclaration> interface_decls = filter.filter(env.getSpecifiedTypeDeclarations());
|
||||
for (TypeDeclaration typedecl : interface_decls) {
|
||||
InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
|
||||
if (Utils.isFinal(interface_decl))
|
||||
GLCapabilitiesGenerator.generateField(writer, interface_decl);
|
||||
}
|
||||
writer.println();
|
||||
for (TypeDeclaration typedecl : interface_decls) {
|
||||
InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
|
||||
GLCapabilitiesGenerator.generateSymbolAddresses(writer, interface_decl);
|
||||
}
|
||||
writer.println();
|
||||
if (context_specific) {
|
||||
for (TypeDeclaration typedecl : interface_decls) {
|
||||
InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
|
||||
GLCapabilitiesGenerator.generateAddressesInitializers(writer, interface_decl);
|
||||
}
|
||||
writer.println();
|
||||
}
|
||||
|
||||
writer.println("\tprivate static void remove(Set supported_extensions, String extension) {");
|
||||
writer.println("\t\tLWJGLUtil.log(extension + \" was reported as available but an entry point is missing\");");
|
||||
writer.println("\t\tsupported_extensions.remove(extension);");
|
||||
writer.println("\t}\n");
|
||||
|
||||
GLCapabilitiesGenerator.generateInitStubsPrologue(writer, context_specific);
|
||||
for (TypeDeclaration typedecl : interface_decls) {
|
||||
InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
|
||||
GLCapabilitiesGenerator.generateSuperClassAdds(writer, interface_decl);
|
||||
}
|
||||
for (TypeDeclaration typedecl : interface_decls) {
|
||||
InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
|
||||
String simple_name = interface_decl.getSimpleName();
|
||||
if ( "GL11".equals(simple_name) )
|
||||
continue;
|
||||
GLCapabilitiesGenerator.generateInitStubs(writer, interface_decl, context_specific);
|
||||
}
|
||||
GLCapabilitiesGenerator.generateInitStubsEpilogue(writer, context_specific);
|
||||
writer.println();
|
||||
writer.println("\tstatic void unloadAllStubs() {");
|
||||
if (!context_specific) {
|
||||
writer.println("\t\tif (!loaded_stubs)");
|
||||
writer.println("\t\t\treturn;");
|
||||
for (TypeDeclaration typedecl : interface_decls) {
|
||||
InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
|
||||
GLCapabilitiesGenerator.generateUnloadStubs(writer, interface_decl);
|
||||
}
|
||||
writer.println("\t\tloaded_stubs = false;");
|
||||
}
|
||||
writer.println("\t}");
|
||||
writer.println();
|
||||
GLCapabilitiesGenerator.generateInitializerPrologue(writer);
|
||||
for (TypeDeclaration typedecl : interface_decls) {
|
||||
InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
|
||||
if (Utils.isFinal(interface_decl))
|
||||
GLCapabilitiesGenerator.generateInitializer(writer, interface_decl);
|
||||
}
|
||||
writer.println("\t\ttracker.init();");
|
||||
writer.println("\t}");
|
||||
writer.println("}");
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,186 +0,0 @@
|
|||
/*
|
||||
* 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
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
package org.lwjgl.util.generator.opengl;
|
||||
|
||||
import org.lwjgl.util.generator.Alternate;
|
||||
import org.lwjgl.util.generator.CachedReference;
|
||||
import org.lwjgl.util.generator.Utils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Set;
|
||||
import javax.annotation.processing.*;
|
||||
import javax.lang.model.SourceVersion;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.util.ElementFilter;
|
||||
|
||||
/**
|
||||
* Generator tool for creating the References class
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision: 3237 $ $Id: ReferencesGeneratorProcessorFactory.java 3237
|
||||
* 2009-09-08 15:07:15Z spasi $
|
||||
*/
|
||||
@SupportedAnnotationTypes({ "*" })
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_7)
|
||||
@SupportedOptions({ "generatechecks", "contextspecific" })
|
||||
public class GLReferencesGeneratorProcessor extends AbstractProcessor {
|
||||
|
||||
private static final String REFERENCES_CLASS_NAME = "References";
|
||||
private static final String REFERENCES_PARAMETER_NAME = "references";
|
||||
|
||||
private static boolean first_round = true;
|
||||
|
||||
@Override
|
||||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||
if ( roundEnv.processingOver() || !first_round ) {
|
||||
System.exit(0);
|
||||
return true;
|
||||
}
|
||||
try {
|
||||
generateReferencesSource(processingEnv, ElementFilter.typesIn(roundEnv.getRootElements()));
|
||||
first_round = false;
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateClearsFromParameters(PrintWriter writer, TypeElement interface_decl, ExecutableElement method) {
|
||||
for ( VariableElement param : method.getParameters() ) {
|
||||
CachedReference cached_reference_annotation = param.getAnnotation(CachedReference.class);
|
||||
if ( cached_reference_annotation != null && cached_reference_annotation.name().length() == 0 ) {
|
||||
Class nio_type = Utils.getNIOBufferType(param.asType());
|
||||
String reference_name = Utils.getReferenceName(interface_decl, method, param);
|
||||
writer.println("\t\tthis." + reference_name + " = null;");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateCopiesFromParameters(PrintWriter writer, TypeElement interface_decl, ExecutableElement method) {
|
||||
for ( VariableElement param : method.getParameters() ) {
|
||||
CachedReference cached_reference_annotation = param.getAnnotation(CachedReference.class);
|
||||
if ( cached_reference_annotation != null && cached_reference_annotation.name().length() == 0 ) {
|
||||
Class nio_type = Utils.getNIOBufferType(param.asType());
|
||||
String reference_name = Utils.getReferenceName(interface_decl, method, param);
|
||||
writer.print("\t\t\tthis." + reference_name + " = ");
|
||||
writer.println(REFERENCES_PARAMETER_NAME + "." + reference_name + ";");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateClearsFromMethods(ProcessingEnvironment env, PrintWriter writer, TypeElement interface_decl) {
|
||||
for ( ExecutableElement method : Utils.getMethods(interface_decl) ) {
|
||||
if ( method.getAnnotation(Alternate.class) != null ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
generateClearsFromParameters(writer, interface_decl, method);
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateCopiesFromMethods(ProcessingEnvironment env, PrintWriter writer, TypeElement interface_decl) {
|
||||
for ( ExecutableElement method : Utils.getMethods(interface_decl) ) {
|
||||
if ( method.getAnnotation(Alternate.class) != null ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
generateCopiesFromParameters(writer, interface_decl, method);
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateReferencesFromParameters(PrintWriter writer, TypeElement interface_decl, ExecutableElement method) {
|
||||
for ( VariableElement param : method.getParameters() ) {
|
||||
CachedReference cached_reference_annotation = param.getAnnotation(CachedReference.class);
|
||||
if ( cached_reference_annotation != null && cached_reference_annotation.name().length() == 0 ) {
|
||||
Class nio_type = Utils.getNIOBufferType(param.asType());
|
||||
if ( nio_type == null ) {
|
||||
throw new RuntimeException(param + " in method " + method + " in " + interface_decl + " is annotated with "
|
||||
+ cached_reference_annotation.annotationType().getSimpleName() + " but the parameter is not a NIO buffer");
|
||||
}
|
||||
writer.print("\t" + nio_type.getName() + " " + Utils.getReferenceName(interface_decl, method, param));
|
||||
writer.println(";");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateReferencesFromMethods(ProcessingEnvironment env, PrintWriter writer, TypeElement interface_decl) {
|
||||
for ( ExecutableElement method : Utils.getMethods(interface_decl) ) {
|
||||
if ( method.getAnnotation(Alternate.class) != null ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
generateReferencesFromParameters(writer, interface_decl, method);
|
||||
}
|
||||
}
|
||||
|
||||
private void generateReferencesSource(ProcessingEnvironment env, Set<TypeElement> templates) throws IOException {
|
||||
PrintWriter writer = new PrintWriter(processingEnv.getFiler().createSourceFile("org.lwjgl.opengl." + REFERENCES_CLASS_NAME, processingEnv.getElementUtils().getPackageElement("org.lwjgl.opengl")).openWriter());
|
||||
writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
|
||||
writer.println();
|
||||
writer.println("package org.lwjgl.opengl;");
|
||||
writer.println();
|
||||
writer.println("class " + REFERENCES_CLASS_NAME + " extends BaseReferences {");
|
||||
writer.println("\t" + REFERENCES_CLASS_NAME + "(ContextCapabilities caps) {");
|
||||
writer.println("\t\tsuper(caps);");
|
||||
writer.println("\t}");
|
||||
for ( TypeElement interface_decl : templates ) {
|
||||
if ( interface_decl.getKind().isInterface() ) {
|
||||
generateReferencesFromMethods(env, writer, interface_decl);
|
||||
}
|
||||
}
|
||||
writer.println();
|
||||
writer.println("\tvoid copy(" + REFERENCES_CLASS_NAME + " " + REFERENCES_PARAMETER_NAME + ", int mask) {");
|
||||
writer.println("\t\tsuper.copy(" + REFERENCES_PARAMETER_NAME + ", mask);");
|
||||
writer.println("\t\tif ( (mask & GL11.GL_CLIENT_VERTEX_ARRAY_BIT) != 0 ) {");
|
||||
for ( TypeElement interface_decl : templates ) {
|
||||
if ( interface_decl.getKind().isInterface() ) {
|
||||
generateCopiesFromMethods(processingEnv, writer, interface_decl);
|
||||
}
|
||||
}
|
||||
writer.println("\t\t}");
|
||||
writer.println("\t}");
|
||||
writer.println("\tvoid clear() {");
|
||||
writer.println("\t\tsuper.clear();");
|
||||
for ( TypeElement interface_decl : templates ) {
|
||||
if ( interface_decl.getKind().isInterface() ) {
|
||||
generateClearsFromMethods(processingEnv, writer, interface_decl);
|
||||
}
|
||||
}
|
||||
writer.println("\t}");
|
||||
writer.println("}");
|
||||
writer.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,218 @@
|
|||
/*
|
||||
* 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
|
||||
* met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of 'LWJGL' nor the names of
|
||||
* its contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.lwjgl.util.generator.opengl;
|
||||
|
||||
import org.lwjgl.util.generator.Alternate;
|
||||
import org.lwjgl.util.generator.CachedReference;
|
||||
import org.lwjgl.util.generator.Utils;
|
||||
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.unmodifiableCollection;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import com.sun.mirror.apt.AnnotationProcessor;
|
||||
import com.sun.mirror.apt.AnnotationProcessorEnvironment;
|
||||
import com.sun.mirror.apt.AnnotationProcessorFactory;
|
||||
import com.sun.mirror.apt.AnnotationProcessors;
|
||||
import com.sun.mirror.apt.Filer;
|
||||
import com.sun.mirror.apt.RoundCompleteEvent;
|
||||
import com.sun.mirror.apt.RoundCompleteListener;
|
||||
import com.sun.mirror.declaration.AnnotationTypeDeclaration;
|
||||
import com.sun.mirror.declaration.InterfaceDeclaration;
|
||||
import com.sun.mirror.declaration.MethodDeclaration;
|
||||
import com.sun.mirror.declaration.ParameterDeclaration;
|
||||
import com.sun.mirror.declaration.TypeDeclaration;
|
||||
import com.sun.mirror.util.DeclarationFilter;
|
||||
|
||||
/**
|
||||
*
|
||||
* Generator tool for creating the References class
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision: 3237 $
|
||||
* $Id: ReferencesGeneratorProcessorFactory.java 3237 2009-09-08 15:07:15Z spasi $
|
||||
*/
|
||||
public class GLReferencesGeneratorProcessorFactory implements AnnotationProcessorFactory, RoundCompleteListener {
|
||||
private static final String REFERENCES_CLASS_NAME = "References";
|
||||
private static final String REFERENCES_PARAMETER_NAME = "references";
|
||||
|
||||
private static boolean first_round = true;
|
||||
|
||||
// Process any set of annotations
|
||||
private static final Collection<String> supportedAnnotations =
|
||||
unmodifiableCollection(Arrays.asList("*"));
|
||||
|
||||
public Collection<String> supportedAnnotationTypes() {
|
||||
return supportedAnnotations;
|
||||
}
|
||||
|
||||
public Collection<String> supportedOptions() {
|
||||
return emptyList();
|
||||
}
|
||||
|
||||
public void roundComplete(RoundCompleteEvent event) {
|
||||
first_round = false;
|
||||
}
|
||||
|
||||
public AnnotationProcessor getProcessorFor(Set<AnnotationTypeDeclaration> atds, AnnotationProcessorEnvironment env) {
|
||||
// Only process the initial types, not the generated ones
|
||||
if (first_round) {
|
||||
env.addListener(this);
|
||||
return new GeneratorProcessor(env);
|
||||
} else
|
||||
return AnnotationProcessors.NO_OP;
|
||||
}
|
||||
|
||||
private static class GeneratorProcessor implements AnnotationProcessor {
|
||||
private final AnnotationProcessorEnvironment env;
|
||||
|
||||
GeneratorProcessor(AnnotationProcessorEnvironment env) {
|
||||
this.env = env;
|
||||
}
|
||||
|
||||
public void process() {
|
||||
try {
|
||||
generateReferencesSource();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateClearsFromParameters(PrintWriter writer, InterfaceDeclaration interface_decl, MethodDeclaration method) {
|
||||
for (ParameterDeclaration param : method.getParameters()) {
|
||||
CachedReference cached_reference_annotation = param.getAnnotation(CachedReference.class);
|
||||
if (cached_reference_annotation != null && cached_reference_annotation.name().length() == 0) {
|
||||
Class nio_type = Utils.getNIOBufferType(param.getType());
|
||||
String reference_name = Utils.getReferenceName(interface_decl, method, param);
|
||||
writer.println("\t\tthis." + reference_name + " = null;");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateCopiesFromParameters(PrintWriter writer, InterfaceDeclaration interface_decl, MethodDeclaration method) {
|
||||
for (ParameterDeclaration param : method.getParameters()) {
|
||||
CachedReference cached_reference_annotation = param.getAnnotation(CachedReference.class);
|
||||
if (cached_reference_annotation != null && cached_reference_annotation.name().length() == 0) {
|
||||
Class nio_type = Utils.getNIOBufferType(param.getType());
|
||||
String reference_name = Utils.getReferenceName(interface_decl, method, param);
|
||||
writer.print("\t\t\tthis." + reference_name + " = ");
|
||||
writer.println(REFERENCES_PARAMETER_NAME + "." + reference_name + ";");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateClearsFromMethods(PrintWriter writer, InterfaceDeclaration interface_decl) {
|
||||
for (MethodDeclaration method : interface_decl.getMethods()) {
|
||||
if ( method.getAnnotation(Alternate.class) != null )
|
||||
continue;
|
||||
|
||||
generateClearsFromParameters(writer, interface_decl, method);
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateCopiesFromMethods(PrintWriter writer, InterfaceDeclaration interface_decl) {
|
||||
for (MethodDeclaration method : interface_decl.getMethods()) {
|
||||
if ( method.getAnnotation(Alternate.class) != null )
|
||||
continue;
|
||||
|
||||
generateCopiesFromParameters(writer, interface_decl, method);
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateReferencesFromParameters(PrintWriter writer, InterfaceDeclaration interface_decl, MethodDeclaration method) {
|
||||
for (ParameterDeclaration param : method.getParameters()) {
|
||||
CachedReference cached_reference_annotation = param.getAnnotation(CachedReference.class);
|
||||
if (cached_reference_annotation != null && cached_reference_annotation.name().length() == 0) {
|
||||
Class nio_type = Utils.getNIOBufferType(param.getType());
|
||||
if (nio_type == null)
|
||||
throw new RuntimeException(param + " in method " + method + " in " + interface_decl + " is annotated with "
|
||||
+ cached_reference_annotation.annotationType().getSimpleName() + " but the parameter is not a NIO buffer");
|
||||
writer.print("\t" + nio_type.getName() + " " + Utils.getReferenceName(interface_decl, method, param));
|
||||
writer.println(";");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateReferencesFromMethods(PrintWriter writer, InterfaceDeclaration interface_decl) {
|
||||
for (MethodDeclaration method : interface_decl.getMethods()) {
|
||||
if ( method.getAnnotation(Alternate.class) != null )
|
||||
continue;
|
||||
|
||||
generateReferencesFromParameters(writer, interface_decl, method);
|
||||
}
|
||||
}
|
||||
|
||||
private void generateReferencesSource() throws IOException {
|
||||
PrintWriter writer = env.getFiler().createTextFile(Filer.Location.SOURCE_TREE, "org.lwjgl.opengl", new File(REFERENCES_CLASS_NAME + ".java"), null);
|
||||
writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
|
||||
writer.println();
|
||||
writer.println("package org.lwjgl.opengl;");
|
||||
writer.println();
|
||||
writer.println("class " + REFERENCES_CLASS_NAME + " extends BaseReferences {");
|
||||
writer.println("\t" + REFERENCES_CLASS_NAME + "(ContextCapabilities caps) {");
|
||||
writer.println("\t\tsuper(caps);");
|
||||
writer.println("\t}");
|
||||
DeclarationFilter filter = DeclarationFilter.getFilter(InterfaceDeclaration.class);
|
||||
Collection<TypeDeclaration> interface_decls = filter.filter(env.getSpecifiedTypeDeclarations());
|
||||
for (TypeDeclaration typedecl : interface_decls) {
|
||||
InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
|
||||
generateReferencesFromMethods(writer, interface_decl);
|
||||
}
|
||||
writer.println();
|
||||
writer.println("\tvoid copy(" + REFERENCES_CLASS_NAME + " " + REFERENCES_PARAMETER_NAME + ", int mask) {");
|
||||
writer.println("\t\tsuper.copy(" + REFERENCES_PARAMETER_NAME + ", mask);");
|
||||
writer.println("\t\tif ( (mask & GL11.GL_CLIENT_VERTEX_ARRAY_BIT) != 0 ) {");
|
||||
for (TypeDeclaration typedecl : interface_decls) {
|
||||
InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
|
||||
generateCopiesFromMethods(writer, interface_decl);
|
||||
}
|
||||
writer.println("\t\t}");
|
||||
writer.println("\t}");
|
||||
writer.println("\tvoid clear() {");
|
||||
writer.println("\t\tsuper.clear();");
|
||||
for (TypeDeclaration typedecl : interface_decls) {
|
||||
InterfaceDeclaration interface_decl = (InterfaceDeclaration)typedecl;
|
||||
generateClearsFromMethods(writer, interface_decl);
|
||||
}
|
||||
writer.println("\t}");
|
||||
writer.println("}");
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -29,6 +29,7 @@
|
|||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
package org.lwjgl.util.generator.opengl;
|
||||
|
||||
/**
|
||||
|
|
@ -36,9 +37,10 @@ package org.lwjgl.util.generator.opengl;
|
|||
* OpenGL sepcific generator behaviour
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision: 3392 $ $Id: GLTypeMap.java 3392 2010-07-27 15:33:22Z
|
||||
* spasi $
|
||||
* @version $Revision: 3392 $
|
||||
* $Id: GLTypeMap.java 3392 2010-07-27 15:33:22Z spasi $
|
||||
*/
|
||||
|
||||
import org.lwjgl.PointerBuffer;
|
||||
import org.lwjgl.util.generator.NativeTypeTranslator;
|
||||
import org.lwjgl.util.generator.PointerWrapper;
|
||||
|
|
@ -50,131 +52,120 @@ import java.lang.annotation.Annotation;
|
|||
import java.nio.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
|
||||
import com.sun.mirror.declaration.AnnotationMirror;
|
||||
import com.sun.mirror.declaration.MethodDeclaration;
|
||||
import com.sun.mirror.type.PrimitiveType;
|
||||
|
||||
public class GLTypeMap implements TypeMap {
|
||||
|
||||
private static final Map<Class, TypeKind> native_types_to_primitive;
|
||||
private static final Map<Class, PrimitiveType.Kind> native_types_to_primitive;
|
||||
|
||||
static {
|
||||
native_types_to_primitive = new HashMap<Class, TypeKind>();
|
||||
native_types_to_primitive.put(GLbitfield.class, TypeKind.INT);
|
||||
native_types_to_primitive.put(GLcharARB.class, TypeKind.BYTE);
|
||||
native_types_to_primitive.put(GLclampf.class, TypeKind.FLOAT);
|
||||
native_types_to_primitive.put(GLfloat.class, TypeKind.FLOAT);
|
||||
native_types_to_primitive.put(GLint.class, TypeKind.INT);
|
||||
native_types_to_primitive.put(GLshort.class, TypeKind.SHORT);
|
||||
native_types_to_primitive.put(GLsizeiptr.class, TypeKind.LONG);
|
||||
native_types_to_primitive.put(GLuint.class, TypeKind.INT);
|
||||
native_types_to_primitive.put(GLboolean.class, TypeKind.BOOLEAN);
|
||||
native_types_to_primitive.put(GLchar.class, TypeKind.BYTE);
|
||||
native_types_to_primitive.put(GLdouble.class, TypeKind.DOUBLE);
|
||||
native_types_to_primitive.put(GLhalf.class, TypeKind.SHORT);
|
||||
native_types_to_primitive.put(GLintptrARB.class, TypeKind.LONG);
|
||||
native_types_to_primitive.put(GLsizei.class, TypeKind.INT);
|
||||
native_types_to_primitive.put(GLushort.class, TypeKind.SHORT);
|
||||
native_types_to_primitive.put(GLbyte.class, TypeKind.BYTE);
|
||||
native_types_to_primitive.put(GLclampd.class, TypeKind.DOUBLE);
|
||||
native_types_to_primitive.put(GLenum.class, TypeKind.INT);
|
||||
native_types_to_primitive.put(GLhandleARB.class, TypeKind.INT);
|
||||
native_types_to_primitive.put(GLintptr.class, TypeKind.LONG);
|
||||
native_types_to_primitive.put(GLsizeiptrARB.class, TypeKind.LONG);
|
||||
native_types_to_primitive.put(GLubyte.class, TypeKind.BYTE);
|
||||
native_types_to_primitive.put(GLvoid.class, TypeKind.BYTE);
|
||||
native_types_to_primitive.put(GLint64EXT.class, TypeKind.LONG);
|
||||
native_types_to_primitive.put(GLuint64EXT.class, TypeKind.LONG);
|
||||
native_types_to_primitive.put(GLint64.class, TypeKind.LONG);
|
||||
native_types_to_primitive.put(GLuint64.class, TypeKind.LONG);
|
||||
native_types_to_primitive = new HashMap<Class, PrimitiveType.Kind>();
|
||||
native_types_to_primitive.put(GLbitfield.class, PrimitiveType.Kind.INT);
|
||||
native_types_to_primitive.put(GLcharARB.class, PrimitiveType.Kind.BYTE);
|
||||
native_types_to_primitive.put(GLclampf.class, PrimitiveType.Kind.FLOAT);
|
||||
native_types_to_primitive.put(GLfloat.class, PrimitiveType.Kind.FLOAT);
|
||||
native_types_to_primitive.put(GLint.class, PrimitiveType.Kind.INT);
|
||||
native_types_to_primitive.put(GLshort.class, PrimitiveType.Kind.SHORT);
|
||||
native_types_to_primitive.put(GLsizeiptr.class, PrimitiveType.Kind.LONG);
|
||||
native_types_to_primitive.put(GLuint.class, PrimitiveType.Kind.INT);
|
||||
native_types_to_primitive.put(GLboolean.class, PrimitiveType.Kind.BOOLEAN);
|
||||
native_types_to_primitive.put(GLchar.class, PrimitiveType.Kind.BYTE);
|
||||
native_types_to_primitive.put(GLdouble.class, PrimitiveType.Kind.DOUBLE);
|
||||
native_types_to_primitive.put(GLhalf.class, PrimitiveType.Kind.SHORT);
|
||||
native_types_to_primitive.put(GLintptrARB.class, PrimitiveType.Kind.LONG);
|
||||
native_types_to_primitive.put(GLsizei.class, PrimitiveType.Kind.INT);
|
||||
native_types_to_primitive.put(GLushort.class, PrimitiveType.Kind.SHORT);
|
||||
native_types_to_primitive.put(GLbyte.class, PrimitiveType.Kind.BYTE);
|
||||
native_types_to_primitive.put(GLclampd.class, PrimitiveType.Kind.DOUBLE);
|
||||
native_types_to_primitive.put(GLenum.class, PrimitiveType.Kind.INT);
|
||||
native_types_to_primitive.put(GLhandleARB.class, PrimitiveType.Kind.INT);
|
||||
native_types_to_primitive.put(GLintptr.class, PrimitiveType.Kind.LONG);
|
||||
native_types_to_primitive.put(GLsizeiptrARB.class, PrimitiveType.Kind.LONG);
|
||||
native_types_to_primitive.put(GLubyte.class, PrimitiveType.Kind.BYTE);
|
||||
native_types_to_primitive.put(GLvoid.class, PrimitiveType.Kind.BYTE);
|
||||
native_types_to_primitive.put(GLint64EXT.class, PrimitiveType.Kind.LONG);
|
||||
native_types_to_primitive.put(GLuint64EXT.class, PrimitiveType.Kind.LONG);
|
||||
native_types_to_primitive.put(GLint64.class, PrimitiveType.Kind.LONG);
|
||||
native_types_to_primitive.put(GLuint64.class, PrimitiveType.Kind.LONG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TypeKind getPrimitiveTypeFromNativeType(Class native_type) {
|
||||
TypeKind kind = native_types_to_primitive.get(native_type);
|
||||
if ( kind == null ) {
|
||||
public PrimitiveType.Kind getPrimitiveTypeFromNativeType(Class native_type) {
|
||||
PrimitiveType.Kind kind = native_types_to_primitive.get(native_type);
|
||||
if ( kind == null )
|
||||
throw new RuntimeException("Unsupported type " + native_type);
|
||||
}
|
||||
return kind;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printCapabilitiesInit(final PrintWriter writer) {
|
||||
writer.println("\t\tContextCapabilities caps = GLContext.getCapabilities();");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCapabilities() {
|
||||
return "caps";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAPIUtilParam(boolean comma) {
|
||||
return comma ? "caps, " : "caps";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printErrorCheckMethod(final PrintWriter writer, final ExecutableElement method, final String tabs) {
|
||||
public void printErrorCheckMethod(final PrintWriter writer, final MethodDeclaration method, final String tabs) {
|
||||
writer.println(tabs + "Util.checkGLError();");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRegisterNativesFunctionName() {
|
||||
return "extgl_InitializeClass";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Signedness getSignednessFromType(Class type) {
|
||||
if ( GLuint.class.equals(type) ) {
|
||||
if ( GLuint.class.equals(type) )
|
||||
return Signedness.UNSIGNED;
|
||||
} else if ( GLint.class.equals(type) ) {
|
||||
else if ( GLint.class.equals(type) )
|
||||
return Signedness.SIGNED;
|
||||
} else if ( GLushort.class.equals(type) ) {
|
||||
else if ( GLushort.class.equals(type) )
|
||||
return Signedness.UNSIGNED;
|
||||
} else if ( GLshort.class.equals(type) ) {
|
||||
else if ( GLshort.class.equals(type) )
|
||||
return Signedness.SIGNED;
|
||||
} else if ( GLubyte.class.equals(type) ) {
|
||||
else if ( GLubyte.class.equals(type) )
|
||||
return Signedness.UNSIGNED;
|
||||
} else if ( GLbyte.class.equals(type) ) {
|
||||
else if ( GLbyte.class.equals(type) )
|
||||
return Signedness.SIGNED;
|
||||
} else if ( GLuint64EXT.class.equals(type) ) {
|
||||
else if ( GLuint64EXT.class.equals(type) )
|
||||
return Signedness.UNSIGNED;
|
||||
} else if ( GLint64EXT.class.equals(type) ) {
|
||||
else if ( GLint64EXT.class.equals(type) )
|
||||
return Signedness.SIGNED;
|
||||
} else if ( GLuint64.class.equals(type) ) {
|
||||
else if ( GLuint64.class.equals(type) )
|
||||
return Signedness.UNSIGNED;
|
||||
} else if ( GLint64.class.equals(type) ) {
|
||||
else if ( GLint64.class.equals(type) )
|
||||
return Signedness.SIGNED;
|
||||
} else {
|
||||
else
|
||||
return Signedness.NONE;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String translateAnnotation(Class annotation_type) {
|
||||
if ( annotation_type.equals(GLuint.class) || annotation_type.equals(GLint.class) ) {
|
||||
if ( annotation_type.equals(GLuint.class) || annotation_type.equals(GLint.class) )
|
||||
return "i";
|
||||
} else if ( annotation_type.equals(GLushort.class) || annotation_type.equals(GLshort.class) ) {
|
||||
else if ( annotation_type.equals(GLushort.class) || annotation_type.equals(GLshort.class) )
|
||||
return "s";
|
||||
} else if ( annotation_type.equals(GLubyte.class) || annotation_type.equals(GLbyte.class) ) {
|
||||
else if ( annotation_type.equals(GLubyte.class) || annotation_type.equals(GLbyte.class) )
|
||||
return "b";
|
||||
} else if ( annotation_type.equals(GLfloat.class) || annotation_type.equals(GLclampf.class) ) {
|
||||
else if ( annotation_type.equals(GLfloat.class) || annotation_type.equals(GLclampf.class) )
|
||||
return "f";
|
||||
} else if ( annotation_type.equals(GLdouble.class) || annotation_type.equals(GLclampd.class) ) {
|
||||
else if ( annotation_type.equals(GLdouble.class) || annotation_type.equals(GLclampd.class) )
|
||||
return "d";
|
||||
} else if ( annotation_type.equals(GLhalf.class) ) {
|
||||
else if ( annotation_type.equals(GLhalf.class) )
|
||||
return "h";
|
||||
} else if ( annotation_type.equals(GLuint64EXT.class) || annotation_type.equals(GLint64EXT.class) || annotation_type.equals(GLuint64.class) || annotation_type.equals(GLint64.class) ) {
|
||||
else if ( annotation_type.equals(GLuint64EXT.class) || annotation_type.equals(GLint64EXT.class) || annotation_type.equals(GLuint64.class) || annotation_type.equals(GLint64.class) )
|
||||
return "i64";
|
||||
} else if ( annotation_type.equals(GLboolean.class) || annotation_type.equals(GLvoid.class) ) {
|
||||
else if ( annotation_type.equals(GLboolean.class) || annotation_type.equals(GLvoid.class) )
|
||||
return "";
|
||||
} else {
|
||||
else
|
||||
throw new RuntimeException(annotation_type + " is not allowed");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class getNativeTypeFromPrimitiveType(TypeKind kind) {
|
||||
public Class getNativeTypeFromPrimitiveType(PrimitiveType.Kind kind) {
|
||||
Class type;
|
||||
switch ( kind ) {
|
||||
case INT:
|
||||
|
|
@ -204,153 +195,137 @@ public class GLTypeMap implements TypeMap {
|
|||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getVoidType() {
|
||||
return GLvoid.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getStringElementType() {
|
||||
return GLubyte.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getStringArrayType() {
|
||||
return GLchar.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getByteBufferArrayType() {
|
||||
return GLchar.class;
|
||||
}
|
||||
|
||||
private static Class[] getValidBufferTypes(Class type) {
|
||||
if ( type.equals(IntBuffer.class) ) {
|
||||
if ( type.equals(IntBuffer.class) )
|
||||
return new Class[] { GLbitfield.class, GLenum.class, GLhandleARB.class, GLint.class,
|
||||
GLsizei.class, GLuint.class, GLvoid.class };
|
||||
} else if ( type.equals(FloatBuffer.class) ) {
|
||||
else if ( type.equals(FloatBuffer.class) )
|
||||
return new Class[] { GLclampf.class, GLfloat.class };
|
||||
} else if ( type.equals(ByteBuffer.class) ) {
|
||||
else if ( type.equals(ByteBuffer.class) )
|
||||
return new Class[] { GLboolean.class, GLbyte.class, GLcharARB.class, GLchar.class, GLubyte.class, GLvoid.class };
|
||||
} else if ( type.equals(ShortBuffer.class) ) {
|
||||
else if ( type.equals(ShortBuffer.class) )
|
||||
return new Class[] { GLhalf.class, GLshort.class, GLushort.class };
|
||||
} else if ( type.equals(DoubleBuffer.class) ) {
|
||||
else if ( type.equals(DoubleBuffer.class) )
|
||||
return new Class[] { GLclampd.class, GLdouble.class };
|
||||
} else if ( type.equals(LongBuffer.class) ) {
|
||||
else if ( type.equals(LongBuffer.class) )
|
||||
return new Class[] { GLint64EXT.class, GLuint64EXT.class, GLint64.class, GLuint64.class };
|
||||
} else {
|
||||
else
|
||||
return new Class[] { };
|
||||
}
|
||||
}
|
||||
|
||||
private static Class[] getValidPrimitiveTypes(Class type) {
|
||||
if ( type.equals(long.class) ) {
|
||||
if ( type.equals(long.class) )
|
||||
return new Class[] { GLintptrARB.class, GLuint.class, GLintptr.class, GLsizeiptrARB.class, GLsizeiptr.class, GLint64EXT.class, GLuint64EXT.class, GLint64.class, GLuint64.class };
|
||||
} else if ( type.equals(int.class) ) {
|
||||
else if ( type.equals(int.class) )
|
||||
return new Class[] { GLbitfield.class, GLenum.class, GLhandleARB.class, GLint.class, GLuint.class,
|
||||
GLsizei.class };
|
||||
} else if ( type.equals(double.class) ) {
|
||||
else if ( type.equals(double.class) )
|
||||
return new Class[] { GLclampd.class, GLdouble.class };
|
||||
} else if ( type.equals(float.class) ) {
|
||||
else if ( type.equals(float.class) )
|
||||
return new Class[] { GLclampf.class, GLfloat.class };
|
||||
} else if ( type.equals(short.class) ) {
|
||||
else if ( type.equals(short.class) )
|
||||
return new Class[] { GLhalf.class, GLshort.class, GLushort.class };
|
||||
} else if ( type.equals(byte.class) ) {
|
||||
else if ( type.equals(byte.class) )
|
||||
return new Class[] { GLbyte.class, GLcharARB.class, GLchar.class, GLubyte.class };
|
||||
} else if ( type.equals(boolean.class) ) {
|
||||
else if ( type.equals(boolean.class) )
|
||||
return new Class[] { GLboolean.class };
|
||||
} else if ( type.equals(void.class) ) {
|
||||
else if ( type.equals(void.class) )
|
||||
return new Class[] { GLvoid.class, GLreturn.class };
|
||||
} else {
|
||||
else
|
||||
return new Class[] { };
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTypedefPostfix() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFunctionPrefix() {
|
||||
return "APIENTRY";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void printNativeIncludes(PrintWriter writer) {
|
||||
writer.println("#include \"extgl.h\"");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class[] getValidAnnotationTypes(Class type) {
|
||||
Class[] valid_types;
|
||||
if ( Buffer.class.isAssignableFrom(type) ) {
|
||||
if ( Buffer.class.isAssignableFrom(type) )
|
||||
valid_types = getValidBufferTypes(type);
|
||||
} else if ( type.isPrimitive() ) {
|
||||
else if ( type.isPrimitive() )
|
||||
valid_types = getValidPrimitiveTypes(type);
|
||||
} else if ( String.class.equals(type) ) {
|
||||
else if ( String.class.equals(type) )
|
||||
valid_types = new Class[] { GLubyte.class };
|
||||
} else if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(type) ) {
|
||||
else if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(type) )
|
||||
valid_types = new Class[] { PointerWrapper.class };
|
||||
} else if ( void.class.equals(type) ) {
|
||||
else if (void.class.equals(type) )
|
||||
valid_types = new Class[] { GLreturn.class };
|
||||
} else if ( PointerBuffer.class.equals(type) ) {
|
||||
else if ( PointerBuffer.class.equals(type) )
|
||||
valid_types = new Class[] { GLintptr.class, GLintptrARB.class, GLsizeiptr.class, GLsizeiptrARB.class };
|
||||
} else {
|
||||
else
|
||||
valid_types = new Class[] { };
|
||||
}
|
||||
return valid_types;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Annotation> getInverseType(Class type) {
|
||||
if ( GLuint.class.equals(type) ) {
|
||||
if ( GLuint.class.equals(type) )
|
||||
return GLint.class;
|
||||
} else if ( GLint.class.equals(type) ) {
|
||||
else if ( GLint.class.equals(type) )
|
||||
return GLuint.class;
|
||||
} else if ( GLushort.class.equals(type) ) {
|
||||
else if ( GLushort.class.equals(type) )
|
||||
return GLshort.class;
|
||||
} else if ( GLshort.class.equals(type) ) {
|
||||
else if ( GLshort.class.equals(type) )
|
||||
return GLushort.class;
|
||||
} else if ( GLubyte.class.equals(type) ) {
|
||||
else if ( GLubyte.class.equals(type) )
|
||||
return GLbyte.class;
|
||||
} else if ( GLbyte.class.equals(type) ) {
|
||||
else if ( GLbyte.class.equals(type) )
|
||||
return GLubyte.class;
|
||||
} else if ( GLuint64EXT.class.equals(type) ) {
|
||||
else if ( GLuint64EXT.class.equals(type) )
|
||||
return GLint64EXT.class;
|
||||
} else if ( GLint64EXT.class.equals(type) ) {
|
||||
else if ( GLint64EXT.class.equals(type) )
|
||||
return GLuint64EXT.class;
|
||||
} else if ( GLuint64.class.equals(type) ) {
|
||||
else if ( GLuint64.class.equals(type) )
|
||||
return GLint64.class;
|
||||
} else if ( GLint64.class.equals(type) ) {
|
||||
else if ( GLint64.class.equals(type) )
|
||||
return GLuint64.class;
|
||||
} else {
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAutoTypeFromAnnotation(AnnotationMirror annotation) {
|
||||
Class annotation_class = NativeTypeTranslator.getClassFromType(annotation.getAnnotationType());
|
||||
if ( annotation_class.equals(GLint.class) ) {
|
||||
if ( annotation_class.equals(GLint.class) )
|
||||
return "GL11.GL_INT";
|
||||
} else if ( annotation_class.equals(GLbyte.class) ) {
|
||||
else if ( annotation_class.equals(GLbyte.class) )
|
||||
return "GL11.GL_BYTE";
|
||||
} else if ( annotation_class.equals(GLshort.class) ) {
|
||||
else if ( annotation_class.equals(GLshort.class) )
|
||||
return "GL11.GL_SHORT";
|
||||
}
|
||||
if ( annotation_class.equals(GLuint.class) ) {
|
||||
if ( annotation_class.equals(GLuint.class) )
|
||||
return "GL11.GL_UNSIGNED_INT";
|
||||
} else if ( annotation_class.equals(GLubyte.class) ) {
|
||||
else if ( annotation_class.equals(GLubyte.class) )
|
||||
return "GL11.GL_UNSIGNED_BYTE";
|
||||
} else if ( annotation_class.equals(GLushort.class) ) {
|
||||
else if ( annotation_class.equals(GLushort.class) )
|
||||
return "GL11.GL_UNSIGNED_SHORT";
|
||||
} else if ( annotation_class.equals(GLfloat.class) ) {
|
||||
else if ( annotation_class.equals(GLfloat.class) )
|
||||
return "GL11.GL_FLOAT";
|
||||
} else if ( annotation_class.equals(GLdouble.class) ) {
|
||||
else if ( annotation_class.equals(GLdouble.class) )
|
||||
return "GL11.GL_DOUBLE";
|
||||
} else {
|
||||
else
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,12 +40,13 @@ package org.lwjgl.util.generator.opengl;
|
|||
|
||||
import org.lwjgl.util.generator.NativeType;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
import java.lang.annotation.ElementType;
|
||||
|
||||
import com.sun.mirror.type.PrimitiveType;
|
||||
|
||||
@NativeType
|
||||
@Target({ ElementType.PARAMETER, ElementType.METHOD })
|
||||
@Target({ElementType.PARAMETER, ElementType.METHOD})
|
||||
public @interface GLvoid {
|
||||
TypeKind value() default TypeKind.BYTE;
|
||||
PrimitiveType.Kind value() default PrimitiveType.Kind.BYTE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ public class Project extends Util {
|
|||
* @param src
|
||||
* @param inverse
|
||||
*
|
||||
* @return true if the matrix was succesfully inverted
|
||||
* @return
|
||||
*/
|
||||
private static boolean __gluInvertMatrixf(FloatBuffer src, FloatBuffer inverse) {
|
||||
int i, j, k, swap;
|
||||
|
|
|
|||
|
|
@ -52,15 +52,15 @@ public @interface CacheLinePad {
|
|||
/**
|
||||
* When true, cache-line padding will be inserted before the field.
|
||||
*
|
||||
* @return true if cache-line padding will be inserted before the field
|
||||
* @return
|
||||
*/
|
||||
boolean before() default false;
|
||||
|
||||
/**
|
||||
* When true, cache-line padding will be inserted after the field.
|
||||
*
|
||||
* @return true if cache-line padding will be inserted after the field
|
||||
* @return
|
||||
*/
|
||||
boolean after() default true;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -52,21 +52,21 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f,
|
|||
public float x, y;
|
||||
|
||||
/**
|
||||
* Constructor for Vector2f.
|
||||
* Constructor for Vector3f.
|
||||
*/
|
||||
public Vector2f() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Constructor
|
||||
*/
|
||||
public Vector2f(ReadableVector2f src) {
|
||||
set(src);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
* Constructor
|
||||
*/
|
||||
public Vector2f(float x, float y) {
|
||||
set(x, y);
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_CallbackUtil_deleteGlobalRef(JNIEnv
|
|||
|
||||
// ----------------- [ KHR_debug ] -----------------
|
||||
|
||||
static void EGLAPIENTRY debugCallbackKHR(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, GLvoid* userParam) {
|
||||
static void APIENTRY debugCallbackKHR(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, GLvoid* userParam) {
|
||||
JNIEnv *env = attachCurrentThread();
|
||||
|
||||
if ( env != NULL && !(*env)->ExceptionOccurred(env) && debugCallbackKHRJ != NULL ) {
|
||||
|
|
@ -78,5 +78,5 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_opengl_CallbackUtil_getDebugCallbackKHR(J
|
|||
debugCallbackKHRJ = (*env)->GetMethodID(env, callbackClass, "handleMessage", "(IIIILjava/lang/String;)V");
|
||||
}
|
||||
|
||||
return (jlong)(intptr_t)&debugCallbackKHR;
|
||||
return (jlong)(intptr_t)&debugCallbackKHRJ;
|
||||
}
|
||||
|
|
@ -39,7 +39,11 @@
|
|||
*/
|
||||
|
||||
#include <jni.h>
|
||||
#ifdef __MACH__
|
||||
#include <JavaVM/jawt_md.h>
|
||||
#else
|
||||
#include <jawt_md.h>
|
||||
#endif
|
||||
#include "org_lwjgl_opengl_AWTSurfaceLock.h"
|
||||
#include "awt_tools.h"
|
||||
#include "common_tools.h"
|
||||
|
|
|
|||
|
|
@ -220,11 +220,7 @@ bool extgl_Open(JNIEnv *env) {
|
|||
*
|
||||
* DRI drivers need this flag to work properly
|
||||
*/
|
||||
#ifdef __OpenBSD__
|
||||
lib_gl_handle = dlopen("libGL.so", RTLD_LAZY | RTLD_GLOBAL);
|
||||
#else
|
||||
lib_gl_handle = dlopen("libGL.so.1", RTLD_LAZY | RTLD_GLOBAL);
|
||||
#endif
|
||||
if (lib_gl_handle == NULL) {
|
||||
throwFormattedException(env, "Error loading libGL.so.1: %s", dlerror());
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -174,32 +174,22 @@ static bool isLegacyFullscreen(jint window_mode) {
|
|||
}
|
||||
|
||||
static void setWindowTitle(Display *disp, Window window, jlong title, jint len) {
|
||||
Atom UTF8_STRING = XInternAtom(disp, "UTF8_STRING", True);
|
||||
Atom _NET_WM_NAME = XInternAtom(disp, "_NET_WM_NAME", True);
|
||||
Atom _NET_WM_ICON_NAME = XInternAtom(disp, "_NET_WM_ICON_NAME", True);
|
||||
|
||||
// ASCII fallback if XChangeProperty fails.
|
||||
XmbSetWMProperties(disp, window, (const char *)(intptr_t)title, (const char *)(intptr_t)title, NULL, 0, NULL, NULL, NULL);
|
||||
XStoreName(disp, window, (const char *)(intptr_t)title);
|
||||
|
||||
// Set the UTF-8 encoded title
|
||||
if ( _NET_WM_NAME )
|
||||
XChangeProperty(
|
||||
disp, window, _NET_WM_NAME, UTF8_STRING,
|
||||
8, PropModeReplace, (const unsigned char *)(intptr_t)title, len
|
||||
);
|
||||
|
||||
if ( _NET_WM_ICON_NAME )
|
||||
XChangeProperty(
|
||||
disp, window, _NET_WM_ICON_NAME, UTF8_STRING,
|
||||
8, PropModeReplace, (const unsigned char *)(intptr_t)title, len
|
||||
);
|
||||
XChangeProperty(disp, window,
|
||||
XInternAtom(disp, "_NET_WM_NAME", False),
|
||||
XInternAtom(disp, "UTF8_STRING", False),
|
||||
8, PropModeReplace, (const unsigned char *)(intptr_t)title,
|
||||
len);
|
||||
}
|
||||
|
||||
static void setClassHint(Display *disp, Window window, jlong wm_name, jlong wm_class) {
|
||||
XClassHint* hint = XAllocClassHint();
|
||||
|
||||
hint->res_name = (char *)(intptr_t)wm_name;
|
||||
hint->res_class = (char *)(intptr_t)wm_class;
|
||||
hint->res_name = (const unsigned char *)(intptr_t)wm_name;
|
||||
hint->res_class = (const unsigned char *)(intptr_t)wm_class;
|
||||
|
||||
XSetClassHint(disp, window, hint);
|
||||
|
||||
|
|
|
|||
|
|
@ -185,8 +185,8 @@ static void setWindowTitle(Display *disp, Window window, jlong title, jint len)
|
|||
static void setClassHint(Display *disp, Window window, jlong wm_name, jlong wm_class) {
|
||||
XClassHint* hint = XAllocClassHint();
|
||||
|
||||
hint->res_name = (char *)(intptr_t)wm_name;
|
||||
hint->res_class = (char *)(intptr_t)wm_class;
|
||||
hint->res_name = (const unsigned char *)(intptr_t)wm_name;
|
||||
hint->res_class = (const unsigned char *)(intptr_t)wm_class;
|
||||
|
||||
XSetClassHint(disp, window, hint);
|
||||
|
||||
|
|
|
|||
|
|
@ -50,11 +50,6 @@
|
|||
#include "common_tools.h"
|
||||
#include <jawt_md.h>
|
||||
|
||||
typedef struct JAWT_MacOSXDrawingSurfaceInfo {
|
||||
NSView *cocoaViewRef; // the view is guaranteed to be valid only for the duration of Component.paint method
|
||||
}
|
||||
JAWT_MacOSXDrawingSurfaceInfo;
|
||||
|
||||
enum {
|
||||
NSControlLeftKeyMask = 0x0001,
|
||||
NSControlRightKeyMask = 0x2000,
|
||||
|
|
|
|||
|
|
@ -101,11 +101,8 @@ NSOpenGLPixelFormat *choosePixelFormat(JNIEnv *env, jobject pixel_format, bool g
|
|||
bpp = 16;
|
||||
else if(CFStringCompare(pixEnc, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
|
||||
bpp = 8;
|
||||
else {
|
||||
throwException(env, "unknown pixel encoding");
|
||||
}
|
||||
} else {
|
||||
throwException(env, "unreachable");
|
||||
bpp = CGDisplayBitsPerPixel(kCGDirectMainDisplay);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -121,9 +118,9 @@ NSOpenGLPixelFormat *choosePixelFormat(JNIEnv *env, jobject pixel_format, bool g
|
|||
bool stereo = (bool)(*env)->GetBooleanField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "stereo", "Z"));
|
||||
bool floating_point = (bool)(*env)->GetBooleanField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "floating_point", "Z"));
|
||||
// TODO: Add floating_point_packed attribute below
|
||||
//bool floating_point_packed = (bool)(*env)->GetBooleanField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "floating_point_packed", "Z"));
|
||||
bool floating_point_packed = (bool)(*env)->GetBooleanField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "floating_point_packed", "Z"));
|
||||
// TODO: Add sRGB attribute below
|
||||
//bool sRGB = (bool)(*env)->GetBooleanField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "sRGB", "Z"));
|
||||
bool sRGB = (bool)(*env)->GetBooleanField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "sRGB", "Z"));
|
||||
|
||||
attrib_list_t attribs;
|
||||
jboolean allow_software_acceleration = getBooleanProperty(env, "org.lwjgl.opengl.Display.allowSoftwareOpenGL");
|
||||
|
|
|
|||
|
|
@ -1,12 +0,0 @@
|
|||
#import <jni.h>
|
||||
#import <AppKit/NSWorkspace.h>
|
||||
#import "org_lwjgl_MacOSXSysImplementation.h"
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_MacOSXSysImplementation_openURL(JNIEnv * env, jobject this, jstring url) {
|
||||
@autoreleasepool {
|
||||
const jchar *chars = (*env)->GetStringChars(env, url, NULL);
|
||||
NSString *s = [NSString stringWithCharacters:chars length:(*env)->GetStringLength(env, url)];
|
||||
[[NSWorkspace shared] openURL: [NSURL URLWithString:s]];
|
||||
(*env)->ReleaseStringChars(env, url, chars);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue