mirror of
https://github.com/shadowfacts/lwjgl2-arm64.git
synced 2025-12-06 08:01:59 +01:00
Compare commits
99 commits
lwjgl2.9.1
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
08c5bb1927 | ||
|
|
2df01dd762 | ||
|
|
8bb7dfefc6 | ||
|
|
d0c96dfef2 | ||
|
|
ff352b63dd | ||
|
|
669689f288 | ||
|
|
9fd235ddf6 | ||
|
|
5d716b2b5a | ||
|
|
a5d81379f7 | ||
|
|
6650201a6d | ||
|
|
40694134ab | ||
|
|
a5c4462a3e | ||
|
|
1dbca8b623 | ||
|
|
0b83683ed1 | ||
|
|
a33e83ee38 | ||
|
|
36e7e73043 | ||
|
|
ef5149a3c3 | ||
|
|
589ce0bd5c | ||
|
|
e4b098c5e2 | ||
|
|
ae4606c53f | ||
|
|
70a8746f9a | ||
|
|
89b22fa151 | ||
|
|
831ac15619 | ||
|
|
67d29a75a0 | ||
|
|
301a37c5fe | ||
|
|
ee2a1c79a3 | ||
|
|
85e5488e4d | ||
|
|
54df7fb066 | ||
|
|
6ae9382a11 | ||
|
|
4a8e5bf4f7 | ||
|
|
e503ea631c | ||
|
|
8cdaf59905 | ||
|
|
45678633f9 | ||
|
|
e429e2699c | ||
|
|
132cecf861 | ||
|
|
751e1023f7 | ||
|
|
37ebf89df0 | ||
|
|
4d451457b4 | ||
|
|
220f55d914 | ||
|
|
ca19ebd11b | ||
|
|
b44f503882 | ||
|
|
f25e503ce0 | ||
|
|
42ccc83499 | ||
|
|
035a4d679b | ||
|
|
079a4b2e9c | ||
|
|
76867b161f | ||
|
|
1dff231df3 | ||
|
|
a570c1c085 | ||
|
|
e08c0fbf56 | ||
|
|
e4fc386372 | ||
|
|
d17c19fe01 | ||
|
|
78911cc0d4 | ||
|
|
59323ff03f | ||
|
|
774bd17ece | ||
|
|
202ce1d522 | ||
|
|
f760abeb81 | ||
|
|
f05778f073 | ||
|
|
46f602f0c6 | ||
|
|
818adb7312 | ||
|
|
e74811e5e7 | ||
|
|
30412de229 | ||
|
|
1ea14545f6 | ||
|
|
33e50400d2 | ||
|
|
5f5b39d3ca | ||
|
|
99afa57380 | ||
|
|
52933da812 | ||
|
|
518ad21d6c | ||
|
|
5d094b5763 | ||
|
|
cb759158e7 | ||
|
|
4aac231951 | ||
|
|
2b3e069d3a | ||
|
|
fcc0d679b0 | ||
|
|
e38fa15535 | ||
|
|
5cf86767bb | ||
|
|
85b7a2f5bb | ||
|
|
fd726e545f | ||
|
|
b83d29e265 | ||
|
|
50c0c30499 | ||
|
|
92f309d7ce | ||
|
|
132ff0191d | ||
|
|
c17617175b | ||
|
|
3ac0b43efd | ||
|
|
a6bb6e31d8 | ||
|
|
e6522d930d | ||
|
|
b699797a27 | ||
|
|
fc5749e42e | ||
|
|
a595fe1a5a | ||
|
|
7a81bde884 | ||
|
|
211b14c8d5 | ||
|
|
d5d9f06160 | ||
|
|
2976194124 | ||
|
|
5c7b35fa96 | ||
|
|
55bfecf514 | ||
|
|
561a80af3c | ||
|
|
5747615c41 | ||
|
|
66c987f9c2 | ||
|
|
1703b62ed5 | ||
|
|
0d70b5a8d5 | ||
|
|
27d444ed74 |
17
.github/CONTRIBUTING.md
vendored
Normal file
17
.github/CONTRIBUTING.md
vendored
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
## 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,3 +17,6 @@
|
|||
/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,13 +1,17 @@
|
|||
LWJGL - Lightweight Java Game Library
|
||||
[LEGACY] 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://lwjgl.org](http://lwjgl.org)
|
||||
Forum: [http://lwjgl.org/forum](http://lwjgl.org/forum)
|
||||
Website: [http://legacy.lwjgl.org](http://legacy.lwjgl.org)
|
||||
Forum: [http://forum.lwjgl.org](http://forum.lwjgl.org)
|
||||
Bugs/Suggestions: [https://github.com/LWJGL/lwjgl/issues](https://github.com/LWJGL/lwjgl/issues)
|
||||
|
||||
Compilation
|
||||
|
|
|
|||
300
build.xml
300
build.xml
|
|
@ -33,6 +33,7 @@
|
|||
<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>
|
||||
|
|
@ -87,8 +88,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">
|
||||
|
|
@ -96,15 +97,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>
|
||||
|
||||
|
|
@ -162,7 +163,7 @@
|
|||
<attribute name="Permissions" value="all-permissions"/>
|
||||
<attribute name="Codebase" value="*"/>
|
||||
<attribute name="Caller-Allowable-Codebase" value="*"/>
|
||||
<attribute name="Application-Library-Allowable-Codebase" value="true"/>
|
||||
<attribute name="Application-Library-Allowable-Codebase" value="*"/>
|
||||
</manifest>
|
||||
</jar>
|
||||
|
||||
|
|
@ -249,6 +250,11 @@
|
|||
<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" />
|
||||
|
|
@ -289,82 +295,88 @@
|
|||
|
||||
<!-- 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> -->
|
||||
|
||||
<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>
|
||||
<echo>lwjgl.src.headers = ${lwjgl.src.headers}</echo>
|
||||
|
||||
<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.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}/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}">
|
||||
<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}/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>
|
||||
<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>
|
||||
</target>
|
||||
|
||||
<target name="touch-version">
|
||||
|
|
@ -374,58 +386,60 @@
|
|||
</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.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.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> -->
|
||||
</target>
|
||||
|
||||
<macrodef name="version-check">
|
||||
|
|
@ -454,7 +468,7 @@
|
|||
|
||||
<!-- Compiles the Java source code -->
|
||||
<target name="compile" description="Compiles the java source code" depends="-initialize">
|
||||
<javac debug="yes" destdir="${lwjgl.bin}" source="1.5" target="1.5" classpath="${lwjgl.lib}/jinput.jar:${lwjgl.lib}/AppleJavaExtensions.jar:${lwjgl.lib}/asm-debug-all.jar" taskname="core">
|
||||
<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">
|
||||
<!--<compilerarg value="-Xlint:unchecked"/>-->
|
||||
<src path="${lwjgl.src}/java/"/>
|
||||
<src path="${lwjgl.src}/generated/"/>
|
||||
|
|
@ -467,8 +481,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.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" />
|
||||
<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" />
|
||||
</target>
|
||||
|
||||
<target name="compile_native" depends="-initialize, headers, touch-version, version-mismatch" description="Compiles the native files">
|
||||
|
|
@ -487,6 +501,11 @@
|
|||
</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>
|
||||
|
|
@ -524,6 +543,15 @@
|
|||
</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 -->
|
||||
|
|
@ -537,8 +565,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.jnilib" todir="${lwjgl.lib}/macosx"/>
|
||||
<version-check platform="macosx"/>
|
||||
<copy file="${lwjgl.bin}/lwjgl/liblwjgl.dylib" 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">
|
||||
|
|
@ -659,7 +687,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/view/LWJGL/job/LWJGL-git-dist/lastSuccessfulBuild/artifact/dist/lwjgl-${lwjgl.version}.zip" dest="${lwjgl.temp}" verbose="true"/>
|
||||
<get src="http://ci.newdawnsoftware.com/job/LWJGL-git-dist/lastBuild/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/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="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="cflags32" value="-O2 -Wall -c -fPIC -std=c99 -Wunused"/>
|
||||
|
||||
<target name="clean">
|
||||
|
|
@ -49,6 +49,13 @@
|
|||
</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>
|
||||
|
|
@ -57,6 +64,13 @@
|
|||
</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>
|
||||
|
|
@ -67,9 +81,12 @@
|
|||
<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"/>
|
||||
|
|
@ -99,9 +116,12 @@
|
|||
<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.1" />
|
||||
<property name="lwjgl.version" value="2.9.4" />
|
||||
<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.jnilib" />
|
||||
<include name="liblwjgl.dylib" />
|
||||
<include name="openal.dylib" />
|
||||
</patternset>
|
||||
<patternset id="lwjgl-macosx-jinput.fileset">
|
||||
<include name="libjinput-osx.jnilib" />
|
||||
<include name="libjinput-osx-legacy.jnilib" />
|
||||
<include name="libjinput-osx.dylib" />
|
||||
<include name="libjinput-osx-legacy.dylib" />
|
||||
</patternset>
|
||||
</patternset>
|
||||
|
||||
|
|
|
|||
|
|
@ -17,15 +17,23 @@
|
|||
|
||||
<!-- Compiles the Java generator source code -->
|
||||
<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">
|
||||
<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">
|
||||
<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.5" target="1.5" taskname="generator">
|
||||
|
||||
<!-- 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">
|
||||
<include name="org/lwjgl/PointerWrapper.java"/>
|
||||
<include name="org/lwjgl/PointerBuffer.java"/>
|
||||
<!-- OpenGL -->
|
||||
|
|
@ -61,39 +69,47 @@
|
|||
|
||||
<!-- Generate OpenAL -->
|
||||
<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>
|
||||
<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>
|
||||
|
||||
<!-- Generate OpenAL [DEBUG] -->
|
||||
<target name="generate-openal-debug" 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"/>
|
||||
<arg value="-Ageneratechecks"/>
|
||||
<fileset dir="${lwjgl.src.templates.al}" includes="${openal-template-pattern}"/>
|
||||
</apply>
|
||||
<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>
|
||||
</target>
|
||||
|
||||
<!-- ********************************************************************************
|
||||
|
|
@ -104,86 +120,106 @@
|
|||
|
||||
<!-- Generate OpenGL -->
|
||||
<target name="generate-opengl" depends="generators" description="Generates java and native source for GL">
|
||||
<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>
|
||||
<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>
|
||||
</target>
|
||||
|
||||
<!-- Generate OpenGL [DEBUG] -->
|
||||
<target name="generate-opengl-debug" depends="generators" description="Generates debug java and native source for GL">
|
||||
<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>
|
||||
<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>
|
||||
</target>
|
||||
|
||||
<!-- Generate OpenGL references -->
|
||||
<target name="generate-opengl-references" depends="generators" description="Generates java and native source for GL">
|
||||
<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>
|
||||
<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>
|
||||
</target>
|
||||
|
||||
<!-- Generate OpenGL context capabilities -->
|
||||
<target name="generate-opengl-capabilities" depends="generators" description="Generates java and native source for GL">
|
||||
<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>
|
||||
<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>
|
||||
</target>
|
||||
|
||||
<!-- Generate OpenGL context capabilities [DEBUG] -->
|
||||
<target name="generate-opengl-capabilities-debug" depends="generators" description="Generates debug java and native source for GL">
|
||||
<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>
|
||||
<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>
|
||||
</target>
|
||||
|
||||
<!-- ********************************************************************************
|
||||
|
|
@ -194,72 +230,88 @@
|
|||
|
||||
<!-- Generate OpenGL ES -->
|
||||
<target name="generate-opengles" depends="generators" description="Generates java and native source for GL ES">
|
||||
<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>
|
||||
<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>
|
||||
</target>
|
||||
|
||||
<!-- Generate OpenGL ES [DEBUG] -->
|
||||
<target name="generate-opengles-debug" depends="generators" description="Generates debug java and native source for GL ES">
|
||||
<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>
|
||||
<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>
|
||||
</target>
|
||||
|
||||
<!-- Generate OpenGL ES context capabilities -->
|
||||
<target name="generate-opengles-capabilities" depends="generators" description="Generates java and native source for GL ES">
|
||||
<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>
|
||||
<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>
|
||||
</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">
|
||||
<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>
|
||||
<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>
|
||||
</target>
|
||||
|
||||
<!-- ********************************************************************************
|
||||
|
|
@ -270,71 +322,87 @@
|
|||
|
||||
<!-- Generate OpenCL -->
|
||||
<target name="generate-opencl" depends="generators" description="Generates java and native source for CL">
|
||||
<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>
|
||||
<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>
|
||||
</target>
|
||||
|
||||
<!-- Generate OpenCL [DEBUG] -->
|
||||
<target name="generate-opencl-debug" depends="generators" description="Generates debug java and native source for CL">
|
||||
<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>
|
||||
<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>
|
||||
</target>
|
||||
|
||||
<!-- Generate OpenCL capabilities -->
|
||||
<target name="generate-opencl-capabilities" depends="generators" description="Generates capabilities for CL">
|
||||
<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>
|
||||
<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>
|
||||
</target>
|
||||
|
||||
<!-- Generate OpenCL capabilities [DEBUG] -->
|
||||
<target name="generate-opencl-capabilities-debug" depends="generators" description="Generates debug capabilities for CL">
|
||||
<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>
|
||||
<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>
|
||||
</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">
|
||||
<apply dir="x32" executable="gcc" skipemptyfilesets="true" failonerror="true" parallel="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">
|
||||
<apply dir="x64" executable="gcc" skipemptyfilesets="true" failonerror="true" parallel="true">
|
||||
<arg line="${cflags64} ${cflags_pthread}"/>
|
||||
<arg value="-I${java.home}/include"/>
|
||||
<arg value="-I${java.home}/include/linux"/>
|
||||
|
|
|
|||
|
|
@ -4,7 +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/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="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="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"/>
|
||||
|
||||
|
|
@ -21,9 +22,6 @@
|
|||
<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>
|
||||
|
|
@ -39,8 +37,8 @@
|
|||
<os name="SunOS" />
|
||||
</condition>
|
||||
|
||||
<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}"/>
|
||||
<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}"/>
|
||||
|
||||
<condition property="build.32bit.only">
|
||||
<not>
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
nm -g "$1"/*.o | grep "Java_" | cut -d ' ' -f3 | cut -c 1-
|
||||
nm -g "$1"/*.o | grep "JNI_" | cut -d ' ' -f3 | cut -c 1-
|
||||
nm -j -g "$1"/*.o | grep -E "J(ava|NI)_[^.]*$"
|
||||
|
|
|
|||
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("SunOS") || osName.startsWith("Unix") )
|
||||
else if ( osName.startsWith("Linux") || osName.startsWith("FreeBSD") || osName.startsWith("OpenBSD") || osName.startsWith("SunOS") || osName.startsWith("Unix") )
|
||||
PLATFORM = PLATFORM_LINUX;
|
||||
else if ( osName.startsWith("Mac OS X") || osName.startsWith("Darwin") )
|
||||
PLATFORM = PLATFORM_MACOSX;
|
||||
|
|
@ -319,6 +319,21 @@ 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.
|
||||
*
|
||||
|
|
@ -605,7 +620,7 @@ public class LWJGLUtil {
|
|||
* @param field the Field to test
|
||||
* @param value the integer value of the field
|
||||
*
|
||||
* @result true if the Field is accepted
|
||||
* @return true if the Field is accepted
|
||||
*/
|
||||
boolean accept(Field field, int value);
|
||||
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@
|
|||
*/
|
||||
package org.lwjgl;
|
||||
|
||||
import com.apple.eio.FileManager;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.security.PrivilegedExceptionAction;
|
||||
|
|
@ -55,13 +54,5 @@ final class MacOSXSysImplementation extends J2SESysImplementation {
|
|||
return JNI_VERSION;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
public native boolean openURL(String url);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,7 +282,8 @@ public final class MemoryUtil {
|
|||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
out.flip();
|
||||
// cast to use Buffer's implementation of flip even when compiling against versions of java that have ByteBuffer::flip
|
||||
((Buffer)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.1";
|
||||
private static final String VERSION = "2.9.4";
|
||||
|
||||
private static final String POSTFIX64BIT = "64";
|
||||
|
||||
|
|
@ -67,8 +67,7 @@ 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 +
|
||||
System.mapLibraryName(lib_name));
|
||||
System.load(library_path + File.separator + LWJGLUtil.mapLibraryName(lib_name));
|
||||
} else {
|
||||
System.loadLibrary(lib_name);
|
||||
}
|
||||
|
|
@ -80,13 +79,15 @@ 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 is64bit = "amd64".equals(osArch) || "x86_64".equals(osArch);
|
||||
if(is64bit) {
|
||||
boolean try64First = LWJGLUtil.getPlatform() != LWJGLUtil.PLATFORM_MACOSX && ("amd64".equals(osArch) || "x86_64".equals(osArch));
|
||||
|
||||
Error err = null;
|
||||
if ( try64First ) {
|
||||
try {
|
||||
doLoadLibrary(lib_name + POSTFIX64BIT);
|
||||
return;
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
LWJGLUtil.log("Failed to load 64 bit library: " + e.getMessage());
|
||||
err = e;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -94,6 +95,9 @@ public final class Sys {
|
|||
try {
|
||||
doLoadLibrary(lib_name);
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
if ( try64First )
|
||||
throw err;
|
||||
|
||||
if (implementation.has64Bit()) {
|
||||
try {
|
||||
doLoadLibrary(lib_name + POSTFIX64BIT);
|
||||
|
|
@ -102,6 +106,7 @@ public final class Sys {
|
|||
LWJGLUtil.log("Failed to load 64 bit library: " + e2.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Throw original error
|
||||
throw e;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ 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;
|
||||
|
|
@ -331,7 +332,7 @@ public class Keyboard {
|
|||
}
|
||||
|
||||
private static void reset() {
|
||||
readBuffer.limit(0);
|
||||
((Buffer)readBuffer).limit(0);
|
||||
for (int i = 0; i < keyDownBuffer.remaining(); i++)
|
||||
keyDownBuffer.put(i, (byte)0);
|
||||
current_event.reset();
|
||||
|
|
@ -392,7 +393,7 @@ public class Keyboard {
|
|||
private static void read() {
|
||||
readBuffer.compact();
|
||||
implementation.readKeyboard(readBuffer);
|
||||
readBuffer.flip();
|
||||
((Buffer)readBuffer).flip();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -453,7 +454,7 @@ public class Keyboard {
|
|||
int num_events = 0;
|
||||
while (readNext(tmp_event) && (!tmp_event.repeat || repeat_enabled))
|
||||
num_events++;
|
||||
readBuffer.position(old_position);
|
||||
((Buffer)readBuffer).position(old_position);
|
||||
return num_events;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
*/
|
||||
package org.lwjgl.input;
|
||||
|
||||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.security.AccessController;
|
||||
|
|
@ -249,7 +250,7 @@ public class Mouse {
|
|||
|
||||
private static void resetMouse() {
|
||||
dx = dy = dwheel = 0;
|
||||
readBuffer.position(readBuffer.limit());
|
||||
((Buffer)readBuffer).position(readBuffer.limit());
|
||||
}
|
||||
|
||||
static InputImplementation getImplementation() {
|
||||
|
|
@ -279,7 +280,7 @@ public class Mouse {
|
|||
if (currentCursor != null && implementation.getNativeCursorCapabilities() != 0)
|
||||
setNativeCursor(currentCursor);
|
||||
readBuffer = ByteBuffer.allocate(EVENT_SIZE * BUFFER_SIZE);
|
||||
readBuffer.limit(0);
|
||||
((Buffer)readBuffer).limit(0);
|
||||
setGrabbed(isGrabbed);
|
||||
}
|
||||
|
||||
|
|
@ -383,7 +384,7 @@ public class Mouse {
|
|||
private static void read() {
|
||||
readBuffer.compact();
|
||||
implementation.readMouse(readBuffer);
|
||||
readBuffer.flip();
|
||||
((Buffer)readBuffer).flip();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -115,8 +115,13 @@ public final class AL {
|
|||
String[] library_names;
|
||||
switch (LWJGLUtil.getPlatform()) {
|
||||
case LWJGLUtil.PLATFORM_WINDOWS:
|
||||
libname = "OpenAL32";
|
||||
library_names = new String[]{"OpenAL64.dll", "OpenAL32.dll"};
|
||||
if ( Sys.is64Bit() ) {
|
||||
libname = "OpenAL64";
|
||||
library_names = new String[]{"OpenAL64.dll"};
|
||||
} else {
|
||||
libname = "OpenAL32";
|
||||
library_names = new String[]{"OpenAL32.dll"};
|
||||
}
|
||||
break;
|
||||
case LWJGLUtil.PLATFORM_LINUX:
|
||||
libname = "openal";
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
*/
|
||||
package org.lwjgl.openal;
|
||||
|
||||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
|
|
@ -177,7 +178,7 @@ public final class ALC11 {
|
|||
try {
|
||||
IntBuffer ib = BufferUtils.createIntBuffer(2);
|
||||
ALC10.alcGetInteger(AL.getDevice(), ALC10.ALC_MAJOR_VERSION, ib);
|
||||
ib.position(1);
|
||||
((Buffer)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
|
||||
* @return attribute list
|
||||
*/
|
||||
static IntBuffer createAttributeList(int contextFrequency, int contextRefresh, int contextSynchronized) {
|
||||
IntBuffer attribList = BufferUtils.createIntBuffer(7);
|
||||
|
|
|
|||
|
|
@ -31,9 +31,11 @@
|
|||
*/
|
||||
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.*;
|
||||
|
|
@ -137,7 +139,7 @@ final class CLChecks {
|
|||
*
|
||||
* @return the 2D image size in bytes
|
||||
*/
|
||||
static int calculateImage2DSize(final ByteBuffer format, final long w, final long h, long row_pitch) {
|
||||
static int calculateImage2DSize(final Buffer host_ptr, final ByteBuffer format, final long w, final long h, long row_pitch) {
|
||||
if ( !LWJGLUtil.CHECKS )
|
||||
return 0;
|
||||
|
||||
|
|
@ -151,7 +153,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);
|
||||
return (int)(row_pitch * h) >> BufferUtils.getElementSizeExponent(host_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -166,7 +168,7 @@ final class CLChecks {
|
|||
*
|
||||
* @return the 3D image size in bytes
|
||||
*/
|
||||
static int calculateImage3DSize(final ByteBuffer format, final long w, final long h, final long d, long row_pitch, long slice_pitch) {
|
||||
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) {
|
||||
if ( !LWJGLUtil.CHECKS )
|
||||
return 0;
|
||||
|
||||
|
|
@ -185,7 +187,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);
|
||||
return (int)(slice_pitch * d) >> BufferUtils.getElementSizeExponent(host_ptr);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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(formatBuffer, image_width, image_height, image_row_pitch)) : 0),
|
||||
(host_ptr != null ? BufferChecks.checkBuffer(host_ptr, CLChecks.calculateImage2DSize(host_ptr, 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(formatBuffer, image_width, image_height, image_depth, image_row_pitch, image_slice_pitch)) : 0),
|
||||
(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),
|
||||
MemoryUtil.getAddressSafe(errcode_ret), function_pointer), context);
|
||||
if ( LWJGLUtil.DEBUG )
|
||||
Util.checkCLError(errcode_ret.get(0));
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ final class APIUtil {
|
|||
buffer = BufferUtils.createByteBuffer(size);
|
||||
caps.util.buffer = buffer;
|
||||
} else
|
||||
buffer.clear();
|
||||
((Buffer)buffer).clear();
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
|
@ -114,8 +114,8 @@ final class APIUtil {
|
|||
bufferNew.put(buffer);
|
||||
caps.util.buffer = (buffer = bufferNew);
|
||||
} else {
|
||||
buffer.position(buffer.limit());
|
||||
buffer.limit(buffer.capacity());
|
||||
((Buffer)buffer).position(buffer.limit());
|
||||
((Buffer)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.flip();
|
||||
((Buffer)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.flip();
|
||||
((Buffer)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.flip();
|
||||
((Buffer)buffer).flip();
|
||||
return MemoryUtil.getAddress0(buffer);
|
||||
}
|
||||
|
||||
|
|
@ -245,7 +245,7 @@ final class APIUtil {
|
|||
for ( CharSequence string : strings )
|
||||
encode(buffer, string);
|
||||
|
||||
buffer.flip();
|
||||
((Buffer)buffer).flip();
|
||||
return MemoryUtil.getAddress0(buffer);
|
||||
}
|
||||
|
||||
|
|
@ -264,7 +264,7 @@ final class APIUtil {
|
|||
buffer.put((byte)0);
|
||||
}
|
||||
|
||||
buffer.flip();
|
||||
((Buffer)buffer).flip();
|
||||
return MemoryUtil.getAddress0(buffer);
|
||||
}
|
||||
|
||||
|
|
@ -281,7 +281,7 @@ final class APIUtil {
|
|||
for ( CharSequence string : strings )
|
||||
buffer.put(string.length());
|
||||
|
||||
buffer.flip();
|
||||
((Buffer)buffer).flip();
|
||||
return MemoryUtil.getAddress0(buffer);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2002-2008 LWJGL Project
|
||||
* Copyright (c) 2002-2014 LWJGL Project
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
@ -35,291 +35,399 @@ 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 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)
|
||||
* 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>
|
||||
* <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 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.
|
||||
* 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.
|
||||
* <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>new ContextAttribs(3, 2).withProfileCore()</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>ContextAttribs(3, 2, CONTEXT_CORE_PROFILE_BIT_ARB)</code>, anything else will be ignored.
|
||||
*
|
||||
* @author spasi <spasi@users.sourceforge.net>
|
||||
*/
|
||||
public final class ContextAttribs {
|
||||
|
||||
// Same values for GLX & WGL
|
||||
private static final int CONTEXT_ES2_PROFILE_BIT_EXT = 0x00000004;
|
||||
// ATTRIBUTES
|
||||
|
||||
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_MAJOR_VERSION_ARB = 0x2091;
|
||||
public static final int CONTEXT_MINOR_VERSION_ARB = 0x2092;
|
||||
|
||||
private static final int CONTEXT_RESET_ISOLATION_BIT_ARB = 0x00000008;
|
||||
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 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;
|
||||
|
||||
private boolean debug;
|
||||
private boolean forwardCompatible;
|
||||
private boolean robustAccess;
|
||||
|
||||
private boolean profileCore;
|
||||
private boolean profileCompatibility;
|
||||
private boolean profileES;
|
||||
|
||||
private boolean loseContextOnReset;
|
||||
private boolean contextResetIsolation;
|
||||
// CONSTRUCTORS
|
||||
|
||||
/** Creates the default ContextAttribs instance. No special attributes will be used when creating the OpenGL context. */
|
||||
public ContextAttribs() {
|
||||
this(1, 0);
|
||||
}
|
||||
|
||||
public ContextAttribs(final int majorVersion, final int minorVersion) {
|
||||
/** 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) {
|
||||
if ( majorVersion < 0 || 4 < majorVersion ||
|
||||
minorVersion < 0 ||
|
||||
(majorVersion == 4 && 4 < minorVersion) ||
|
||||
(majorVersion == 4 && 5 < 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;
|
||||
}
|
||||
|
||||
private ContextAttribs(final ContextAttribs attribs) {
|
||||
this.majorVersion = attribs.majorVersion;
|
||||
this.minorVersion = attribs.minorVersion;
|
||||
// Copy constructor
|
||||
private ContextAttribs(ContextAttribs other) {
|
||||
this.majorVersion = other.majorVersion;
|
||||
this.minorVersion = other.minorVersion;
|
||||
|
||||
this.layerPlane = attribs.layerPlane;
|
||||
this.profileMask = other.profileMask;
|
||||
this.contextFlags = other.contextFlags;
|
||||
|
||||
this.debug = attribs.debug;
|
||||
this.forwardCompatible = attribs.forwardCompatible;
|
||||
this.robustAccess = attribs.robustAccess;
|
||||
this.contextResetNotificationStrategy = other.contextResetNotificationStrategy;
|
||||
this.contextReleaseBehavior = other.contextReleaseBehavior;
|
||||
|
||||
this.profileCore = attribs.profileCore;
|
||||
this.profileCompatibility = attribs.profileCompatibility;
|
||||
this.profileES = attribs.profileES;
|
||||
|
||||
this.loseContextOnReset = attribs.loseContextOnReset;
|
||||
this.layerPlane = other.layerPlane;
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
public boolean isDebug() {
|
||||
return debug;
|
||||
}
|
||||
// CHAIN CONFIGURATION PATTERN
|
||||
|
||||
public boolean isForwardCompatible() {
|
||||
return forwardCompatible;
|
||||
}
|
||||
|
||||
public boolean isProfileCore() {
|
||||
return profileCore;
|
||||
}
|
||||
|
||||
public boolean isProfileCompatibility() {
|
||||
return profileCompatibility;
|
||||
}
|
||||
|
||||
public boolean isProfileES() {
|
||||
return profileES;
|
||||
}
|
||||
|
||||
public ContextAttribs withLayer(final int layerPlane) {
|
||||
if ( layerPlane < 0 )
|
||||
throw new IllegalArgumentException("Invalid layer plane specified: " + layerPlane);
|
||||
|
||||
if ( layerPlane == this.layerPlane )
|
||||
private ContextAttribs toggleMask(int mask, boolean value) {
|
||||
if ( value == hasMask(mask) )
|
||||
return 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;
|
||||
|
||||
ContextAttribs attribs = new ContextAttribs(this);
|
||||
attribs.profileMask = value ? mask : 0;
|
||||
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.
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/** 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 loseContextOnReset
|
||||
* @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 withLoseContextOnReset(final boolean loseContextOnReset) {
|
||||
if ( loseContextOnReset == this.loseContextOnReset )
|
||||
public ContextAttribs withResetNotificationStrategy(int strategy) {
|
||||
if ( strategy == contextResetNotificationStrategy )
|
||||
return this;
|
||||
|
||||
final ContextAttribs attribs = new ContextAttribs(this);
|
||||
attribs.loseContextOnReset = loseContextOnReset;
|
||||
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;
|
||||
}
|
||||
|
||||
public ContextAttribs withContextResetIsolation(final boolean contextResetIsolation) {
|
||||
if ( contextResetIsolation == this.contextResetIsolation )
|
||||
/**
|
||||
* 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;
|
||||
|
||||
final ContextAttribs attribs = new ContextAttribs(this);
|
||||
attribs.contextResetIsolation = contextResetIsolation;
|
||||
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;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
/** 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.");
|
||||
|
||||
if ( layerPlane == this.layerPlane )
|
||||
return this;
|
||||
|
||||
if ( layerPlane < 0 )
|
||||
throw new IllegalArgumentException("Invalid layer plane specified: " + layerPlane);
|
||||
|
||||
ContextAttribs attribs = new ContextAttribs(this);
|
||||
attribs.layerPlane = layerPlane;
|
||||
return attribs;
|
||||
}
|
||||
|
||||
IntBuffer getAttribList() {
|
||||
if ( LWJGLUtil.getPlatform() == LWJGLUtil.PLATFORM_MACOSX )
|
||||
return null;
|
||||
|
||||
ContextAttribsImplementation implementation = getImplementation();
|
||||
|
||||
int attribCount = 0;
|
||||
|
||||
if ( !(majorVersion == 1 && minorVersion == 0) )
|
||||
attribCount += 2;
|
||||
if ( 0 < layerPlane )
|
||||
attribCount++;
|
||||
|
||||
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++;
|
||||
|
||||
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 ( loseContextOnReset )
|
||||
attribCount++;
|
||||
|
||||
if ( attribCount == 0 )
|
||||
return null;
|
||||
|
||||
final IntBuffer attribs = BufferUtils.createIntBuffer((attribCount * 2) + 1);
|
||||
LinkedHashMap<Integer, Integer> map = new LinkedHashMap<Integer, Integer>(8);
|
||||
|
||||
if ( !(majorVersion == 1 && minorVersion == 0) ) {
|
||||
attribs.put(implementation.getMajorVersionAttrib()).put(majorVersion);
|
||||
attribs.put(implementation.getMinorVersionAttrib()).put(minorVersion);
|
||||
map.put(CONTEXT_MAJOR_VERSION_ARB, majorVersion);
|
||||
map.put(CONTEXT_MINOR_VERSION_ARB, 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);
|
||||
|
||||
if ( contextFlags != 0 )
|
||||
map.put(CONTEXT_FLAGS_ARB, contextFlags);
|
||||
|
||||
if ( profileMask != 0 )
|
||||
map.put(CONTEXT_PROFILE_MASK_ARB, profileMask);
|
||||
|
||||
if ( contextResetNotificationStrategy != NO_RESET_NOTIFICATION_ARB )
|
||||
map.put(CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB, contextResetNotificationStrategy);
|
||||
|
||||
if ( contextReleaseBehavior != CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB )
|
||||
map.put(CONTEXT_RELEASE_BEHABIOR_ARB, contextReleaseBehavior);
|
||||
|
||||
if ( layerPlane != 0 )
|
||||
map.put(CONTEXT_LAYER_PLANE_ARB, layerPlane);
|
||||
|
||||
if ( map.isEmpty() )
|
||||
return null;
|
||||
|
||||
IntBuffer attribs = BufferUtils.createIntBuffer((map.size() * 2) + 1);
|
||||
for ( Entry<Integer, Integer> attrib : map.entrySet() ) {
|
||||
attribs
|
||||
.put(attrib.getKey())
|
||||
.put(attrib.getValue());
|
||||
}
|
||||
attribs.put(0);
|
||||
attribs.rewind();
|
||||
return attribs;
|
||||
|
|
@ -330,19 +438,37 @@ public final class ContextAttribs {
|
|||
|
||||
sb.append("ContextAttribs:");
|
||||
sb.append(" Version=").append(majorVersion).append('.').append(minorVersion);
|
||||
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");
|
||||
|
||||
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);
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -253,8 +253,12 @@ final class ContextGL implements Context {
|
|||
boolean was_current = isCurrent();
|
||||
int error = GL_NO_ERROR;
|
||||
if ( was_current ) {
|
||||
if ( GLContext.getCapabilities() != null && GLContext.getCapabilities().OpenGL11 )
|
||||
try {
|
||||
// May fail on GLContext.getCapabilities()
|
||||
error = glGetError();
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
releaseCurrent();
|
||||
}
|
||||
checkDestroy();
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ 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;
|
||||
|
|
@ -239,21 +240,21 @@ public final class Display {
|
|||
throw new NullPointerException("mode must be non-null");
|
||||
boolean was_fullscreen = isFullscreen();
|
||||
current_mode = mode;
|
||||
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();
|
||||
if ( !isCreated() || parent != null )
|
||||
return;
|
||||
destroyWindow();
|
||||
// If mode is not fullscreen capable, make sure we are in windowed mode
|
||||
try {
|
||||
if ( was_fullscreen && !isFullscreen() )
|
||||
display_impl.resetDisplayMode();
|
||||
throw e;
|
||||
}
|
||||
else if ( isFullscreen() )
|
||||
switchDisplayMode();
|
||||
createWindow();
|
||||
makeCurrentAndSetSwapInterval();
|
||||
} catch (LWJGLException e) {
|
||||
drawable.destroy();
|
||||
display_impl.resetDisplayMode();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1222,8 +1223,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]);
|
||||
icons[i].position(old_position);
|
||||
cached_icons[i].flip();
|
||||
((Buffer)icons[i]).position(old_position);
|
||||
((Buffer)cached_icons[i]).flip();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ public final class DisplayMode {
|
|||
this.fullscreen = fullscreen;
|
||||
}
|
||||
|
||||
/** True iff this instance can be used for fullscreen modes */
|
||||
/** True if this instance can be used for fullscreen modes */
|
||||
public boolean isFullscreenCapable() {
|
||||
return fullscreen;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@ package org.lwjgl.opengl;
|
|||
* @author elias_naur
|
||||
*/
|
||||
|
||||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
class EventQueue {
|
||||
|
|
@ -58,12 +59,12 @@ class EventQueue {
|
|||
* Copy available events into the specified buffer.
|
||||
*/
|
||||
public synchronized void copyEvents(ByteBuffer dest) {
|
||||
queue.flip();
|
||||
((Buffer)queue).flip();
|
||||
int old_limit = queue.limit();
|
||||
if (dest.remaining() < queue.remaining())
|
||||
queue.limit(dest.remaining() + queue.position());
|
||||
((Buffer)queue).limit(dest.remaining() + queue.position());
|
||||
dest.put(queue);
|
||||
queue.limit(old_limit);
|
||||
((Buffer)queue).limit(old_limit);
|
||||
queue.compact();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ 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.*;
|
||||
|
||||
|
|
@ -65,22 +66,6 @@ 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 )
|
||||
|
|
@ -310,37 +295,36 @@ class GLChecks {
|
|||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
static int calculatePathColorGenModeElements(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("Unsupported gen mode: " + genMode);
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 }, // OpenGL 4
|
||||
{ 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
|
||||
};
|
||||
|
||||
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 keyboard buffer
|
||||
* Method to read the mouse buffer
|
||||
*/
|
||||
void readMouse(ByteBuffer buffer);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,91 +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.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,10 +143,12 @@ 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,7 +129,6 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
private DisplayMode saved_mode;
|
||||
private DisplayMode current_mode;
|
||||
|
||||
private Screen[] savedXrandrConfig;
|
||||
|
||||
private boolean keyboard_grabbed;
|
||||
private boolean pointer_grabbed;
|
||||
|
|
@ -484,6 +483,15 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
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
|
||||
|
|
@ -603,12 +611,17 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
}
|
||||
|
||||
private void switchDisplayModeOnTmpDisplay(DisplayMode mode) throws LWJGLException {
|
||||
incDisplay();
|
||||
try {
|
||||
nSwitchDisplayMode(getDisplay(), getDefaultScreen(), current_displaymode_extension, mode);
|
||||
} finally {
|
||||
decDisplay();
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
private static native void nSwitchDisplayMode(long display, int screen, int extension, DisplayMode mode) throws LWJGLException;
|
||||
|
||||
|
|
@ -625,11 +638,11 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
public void resetDisplayMode() {
|
||||
lockAWT();
|
||||
try {
|
||||
if( current_displaymode_extension == XRANDR && savedXrandrConfig.length > 0 )
|
||||
if( current_displaymode_extension == XRANDR )
|
||||
{
|
||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
public Object run() {
|
||||
XRandR.setConfiguration( savedXrandrConfig );
|
||||
XRandR.restoreConfiguration();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
|
@ -727,12 +740,11 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
throw new LWJGLException("No modes available");
|
||||
switch (current_displaymode_extension) {
|
||||
case XRANDR:
|
||||
savedXrandrConfig = AccessController.doPrivileged(new PrivilegedAction<Screen[]>() {
|
||||
public Screen[] run() {
|
||||
return XRandR.getConfiguration();
|
||||
saved_mode = AccessController.doPrivileged(new PrivilegedAction<DisplayMode>() {
|
||||
public DisplayMode run() {
|
||||
return XRandR.ScreentoDisplayMode(XRandR.getConfiguration());
|
||||
}
|
||||
});
|
||||
saved_mode = getCurrentXRandrMode();
|
||||
break;
|
||||
case XF86VIDMODE:
|
||||
saved_mode = modes[0];
|
||||
|
|
@ -774,9 +786,6 @@ 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);
|
||||
|
||||
|
|
@ -929,13 +938,29 @@ final class LinuxDisplay implements DisplayImplementation {
|
|||
public DisplayMode[] getAvailableDisplayModes() throws LWJGLException {
|
||||
lockAWT();
|
||||
try {
|
||||
incDisplay();
|
||||
try {
|
||||
DisplayMode[] modes = nGetAvailableDisplayModes(getDisplay(), getDefaultScreen(), current_displaymode_extension);
|
||||
return modes;
|
||||
} finally {
|
||||
decDisplay();
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
unlockAWT();
|
||||
}
|
||||
|
|
@ -1096,16 +1121,18 @@ 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 && savedXrandrConfig.length > 0 )
|
||||
if( current_displaymode_extension == XRANDR )
|
||||
{
|
||||
AccessController.doPrivileged(new PrivilegedAction<Object>() {
|
||||
public Object run() {
|
||||
XRandR.setConfiguration( savedXrandrConfig );
|
||||
XRandR.restoreConfiguration();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -257,46 +257,22 @@ final class LinuxKeyboard {
|
|||
private static native long lookupKeysym(long event_ptr, int index);
|
||||
private static native long toUpper(long keysym);
|
||||
|
||||
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 ((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 ((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;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
boolean shift = (event_state & (ShiftMask | shift_lock_mask)) != 0;
|
||||
int group = (event_state & modeswitch_mask) != 0 ? 1 : 0;
|
||||
long keysym;
|
||||
if ((event_state & numlock_mask) != 0 && isKeypadKeysym(keysym = getKeySym(event_ptr, group, 1))) {
|
||||
if ( shift )
|
||||
keysym = getKeySym(event_ptr, group, 0);
|
||||
} else {
|
||||
keysym = getKeySym(event_ptr, group, 0);
|
||||
if ( shift ^ ((event_state & caps_lock_mask) != 0) )
|
||||
keysym = toUpper(keysym);
|
||||
}
|
||||
return keycode;
|
||||
return LinuxKeycodes.mapKeySymToLWJGLKeyCode(keysym);
|
||||
}
|
||||
|
||||
private byte getKeyState(int event_type) {
|
||||
private static byte getKeyState(int event_type) {
|
||||
switch (event_type) {
|
||||
case LinuxEvent.KeyPress:
|
||||
return 1;
|
||||
|
|
@ -307,10 +283,22 @@ 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) {
|
||||
|
|
|
|||
|
|
@ -89,25 +89,7 @@ abstract class MacOSXCanvasPeerInfo extends MacOSXPeerInfo {
|
|||
// 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);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
reSetLayerBounds(component, getHandle());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -130,54 +112,14 @@ 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);
|
||||
nSetLayerBounds(getHandle(), component.getX() - left, component.getY() - top, component.getWidth(), component.getHeight());
|
||||
reSetLayerBounds(component, getHandle());
|
||||
}
|
||||
|
||||
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);
|
||||
nSetLayerBounds(getHandle(), component.getX() - left, component.getY() - top, component.getWidth(), component.getHeight());
|
||||
reSetLayerBounds(component, getHandle());
|
||||
}
|
||||
|
||||
public void componentShown(ComponentEvent e) {
|
||||
|
|
@ -198,38 +140,43 @@ 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 the Insets of the Window holding the Canvas
|
||||
*/
|
||||
private Insets getWindowInsets(Canvas canvas) {
|
||||
Container parent = canvas.getParent();
|
||||
/**
|
||||
* @return rootpane insets (peer insets) values.
|
||||
*/
|
||||
private static Insets getInsets(Canvas component) {
|
||||
Container c = SwingUtilities.getRootPane(component);
|
||||
|
||||
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;
|
||||
if(c != null) {
|
||||
return c.getInsets();
|
||||
} else {
|
||||
return new Insets(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -163,10 +163,8 @@ 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
|
||||
if (current_viewport.get(2) == 0 && current_viewport.get(3) == 0) {
|
||||
current_viewport.put(2, mode.getWidth());
|
||||
current_viewport.put(3, mode.getHeight());
|
||||
}
|
||||
current_viewport.put(2, mode.getWidth());
|
||||
current_viewport.put(3, mode.getHeight());
|
||||
}
|
||||
|
||||
native_mode = nIsNativeMode(peer_handle);
|
||||
|
|
@ -331,10 +329,15 @@ final class MacOSXDisplay implements DisplayImplementation {
|
|||
|
||||
DrawableGL drawable = (DrawableGL)Display.getDrawable();
|
||||
if (should_update) {
|
||||
drawable.context.update();
|
||||
/* This is necessary to make sure the context won't "forget" about the view size */
|
||||
|
||||
// Save the current viewport size as cocoa will automatically
|
||||
// set the viewport size to the window size on context update
|
||||
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,9 +38,8 @@ package org.lwjgl.opengl;
|
|||
*/
|
||||
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.KeyListener;
|
||||
import java.util.HashMap;
|
||||
import java.awt.Component;
|
||||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
|
@ -74,132 +73,132 @@ final class MacOSXNativeKeyboard extends EventQueue {
|
|||
|
||||
// These are from: <HIToolbox/Events.h>
|
||||
private void initKeyboardMappings() {
|
||||
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)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)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)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)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)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)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)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)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)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)0x3F, Keyboard.KEY_FUNCTION);
|
||||
nativeToLwjglMap.put((Short)(short)0x77, Keyboard.KEY_END);
|
||||
nativeToLwjglMap.put((short)0x3F, Keyboard.KEY_FUNCTION);
|
||||
nativeToLwjglMap.put((short)0x77, Keyboard.KEY_END);
|
||||
|
||||
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)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)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)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)0x0A, Keyboard.KEY_SECTION);
|
||||
nativeToLwjglMap.put((short)0x0A, Keyboard.KEY_SECTION);
|
||||
|
||||
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?
|
||||
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?
|
||||
}
|
||||
|
||||
public void register() {
|
||||
|
|
@ -211,9 +210,9 @@ final class MacOSXNativeKeyboard extends EventQueue {
|
|||
}
|
||||
|
||||
public void putKeyboardEvent(int key_code, byte state, int character, long nanos, boolean repeat) {
|
||||
event.clear();
|
||||
((Buffer)event).clear();
|
||||
event.putInt(key_code).put(state).putInt(character).putLong(nanos).put(repeat ? (byte)1 : (byte)0);
|
||||
event.flip();
|
||||
((Buffer)event).flip();
|
||||
putEvent(event);
|
||||
}
|
||||
|
||||
|
|
@ -221,7 +220,7 @@ final class MacOSXNativeKeyboard extends EventQueue {
|
|||
flushDeferredEvent();
|
||||
int old_position = key_down_buffer.position();
|
||||
key_down_buffer.put(key_states);
|
||||
key_down_buffer.position(old_position);
|
||||
((Buffer)key_down_buffer).position(old_position);
|
||||
}
|
||||
|
||||
public synchronized void copyEvents(ByteBuffer dest) {
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ package org.lwjgl.opengl;
|
|||
* @author kappaOne <one.kappa@gmail.com>
|
||||
*/
|
||||
|
||||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
|
||||
|
|
@ -156,9 +157,9 @@ final class MacOSXNativeMouse extends EventQueue {
|
|||
}
|
||||
|
||||
protected void putMouseEventWithCoords(byte button, byte state, int coord1, int coord2, int dz, long nanos) {
|
||||
event.clear();
|
||||
((Buffer)event).clear();
|
||||
event.put(button).put(state).putInt(coord1).putInt(coord2).putInt(dz).putLong(nanos);
|
||||
event.flip();
|
||||
((Buffer)event).flip();
|
||||
putEvent(event);
|
||||
}
|
||||
|
||||
|
|
@ -174,7 +175,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);
|
||||
buttons_buffer.position(old_position);
|
||||
((Buffer)buttons_buffer).position(old_position);
|
||||
}
|
||||
|
||||
private void setCursorPos(float x, float y, long nanos) {
|
||||
|
|
|
|||
|
|
@ -46,9 +46,9 @@ 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 && attribs.getMajorVersion() == 3 && attribs.getMinorVersion() == 2 && attribs.isProfileCore();
|
||||
boolean gl32 = attribs != null && (3 < attribs.getMajorVersion() || (attribs.getMajorVersion() == 3 && 2 <= attribs.getMinorVersion())) && 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,92 +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.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,7 +196,6 @@ 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;
|
||||
|
|
@ -210,7 +209,6 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
private boolean iconsLoaded;
|
||||
|
||||
private int captureMouse = -1;
|
||||
private boolean trackingMouse;
|
||||
private boolean mouseInside;
|
||||
|
||||
static {
|
||||
|
|
@ -227,17 +225,14 @@ 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);
|
||||
this.resizable=false;
|
||||
if ( Display.isResizable() && parent == null ) {
|
||||
setResizable(true);
|
||||
}
|
||||
|
||||
if (hwnd == 0) {
|
||||
throw new LWJGLException("Failed to create window");
|
||||
}
|
||||
|
|
@ -261,9 +256,6 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
updateWidthAndHeight();
|
||||
|
||||
if ( parent == null ) {
|
||||
if(Display.isResizable()) {
|
||||
setResizable(true);
|
||||
}
|
||||
setForegroundWindow(getHwnd());
|
||||
} else {
|
||||
parent_focused = new AtomicBoolean(false);
|
||||
|
|
@ -322,6 +314,15 @@ 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);
|
||||
|
|
@ -364,7 +365,7 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
/*
|
||||
* Called when the application is alt-tabbed to or from
|
||||
*/
|
||||
private void appActivate(boolean active) {
|
||||
private void appActivate(boolean active, long millis) {
|
||||
if (inAppActivate) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -379,16 +380,14 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
}
|
||||
setFocus(getHwnd());
|
||||
redoMakeContextCurrent = true;
|
||||
if (Display.isFullscreen())
|
||||
updateClipping();
|
||||
|
||||
} else {
|
||||
if ( keyboard != null )
|
||||
keyboard.fireLostKeyEvents();
|
||||
} else if (Display.isFullscreen()) {
|
||||
showWindow(getHwnd(), SW_SHOWMINNOACTIVE);
|
||||
resetDisplayMode();
|
||||
} else
|
||||
updateClipping();
|
||||
keyboard.releaseAll(millis);
|
||||
if ( Display.isFullscreen() ) {
|
||||
showWindow(getHwnd(), SW_SHOWMINNOACTIVE);
|
||||
resetDisplayMode();
|
||||
}
|
||||
}
|
||||
updateCursor();
|
||||
inAppActivate = false;
|
||||
}
|
||||
|
|
@ -601,7 +600,7 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
}
|
||||
|
||||
public void pollMouse(IntBuffer coord_buffer, ByteBuffer buttons) {
|
||||
mouse.poll(coord_buffer, buttons);
|
||||
mouse.poll(coord_buffer, buttons, this);
|
||||
}
|
||||
|
||||
public void readMouse(ByteBuffer buffer) {
|
||||
|
|
@ -609,7 +608,7 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
}
|
||||
|
||||
public void grabMouse(boolean grab) {
|
||||
mouse.grab(grab, shouldGrab());
|
||||
mouse.grab(grab);
|
||||
updateCursor();
|
||||
}
|
||||
|
||||
|
|
@ -633,13 +632,15 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
|
||||
private void updateCursor() {
|
||||
try {
|
||||
if (mouse != null && shouldGrab())
|
||||
if (mouse != null && shouldGrab()) {
|
||||
centerCursor(hwnd);
|
||||
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;
|
||||
|
||||
|
|
@ -860,12 +861,6 @@ 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();
|
||||
|
||||
|
|
@ -916,10 +911,6 @@ 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 {
|
||||
|
|
@ -933,8 +924,10 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
}
|
||||
|
||||
private void setMinimized(boolean m) {
|
||||
isMinimized = m;
|
||||
checkCursorState();
|
||||
if ( m != isMinimized ) {
|
||||
isMinimized = m;
|
||||
updateClipping();
|
||||
}
|
||||
}
|
||||
|
||||
private long doHandleMessage(long hwnd, int msg, long wParam, long lParam, long millis) {
|
||||
|
|
@ -975,7 +968,6 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
switch ((int)wParam) {
|
||||
case SIZE_RESTORED:
|
||||
case SIZE_MAXIMIZED:
|
||||
maximized = ((int)wParam) == SIZE_MAXIMIZED;
|
||||
resized = true;
|
||||
updateWidthAndHeight();
|
||||
setMinimized(false);
|
||||
|
|
@ -989,21 +981,11 @@ 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);
|
||||
appActivate(false, millis);
|
||||
return 0L;
|
||||
case WM_SETFOCUS:
|
||||
appActivate(true);
|
||||
appActivate(true, millis);
|
||||
return 0L;
|
||||
case WM_MOUSEACTIVATE:
|
||||
if ( parent != null ) {
|
||||
|
|
@ -1013,14 +995,16 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
}
|
||||
break;
|
||||
case WM_MOUSEMOVE:
|
||||
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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
return 0L;
|
||||
case WM_MOUSEWHEEL:
|
||||
int dwheel = (int)(short)((wParam >> 16) & 0xFFFF);
|
||||
|
|
@ -1063,6 +1047,11 @@ 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
|
||||
|
|
@ -1085,16 +1074,12 @@ 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:
|
||||
|
|
@ -1102,7 +1087,6 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
break;
|
||||
case WM_MOUSELEAVE:
|
||||
mouseInside = false;
|
||||
trackingMouse = false;
|
||||
break;
|
||||
case WM_CANCELMODE:
|
||||
nReleaseCapture();
|
||||
|
|
@ -1116,8 +1100,8 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
case WM_WINDOWPOSCHANGED:
|
||||
if(getWindowRect(hwnd, rect_buffer)) {
|
||||
rect.copyFromBuffer(rect_buffer);
|
||||
x = rect.top;
|
||||
y = rect.bottom;
|
||||
x = rect.left;
|
||||
y = rect.top;
|
||||
} else {
|
||||
LWJGLUtil.log("WM_WINDOWPOSCHANGED: Unable to get window rect");
|
||||
}
|
||||
|
|
@ -1155,31 +1139,42 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
}
|
||||
|
||||
public void setResizable(boolean resizable) {
|
||||
if(this.resizable != resizable) {
|
||||
int style = (int)getWindowLongPtr(hwnd, GWL_STYLE);
|
||||
int styleex = (int)getWindowLongPtr(hwnd, GWL_EXSTYLE);
|
||||
if ( this.resizable == resizable )
|
||||
return;
|
||||
|
||||
// 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.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);
|
||||
|
|
@ -1197,38 +1192,44 @@ final class WindowsDisplay implements DisplayImplementation {
|
|||
}
|
||||
|
||||
private static final class Rect {
|
||||
public int top;
|
||||
public int bottom;
|
||||
public int left;
|
||||
public int right;
|
||||
|
||||
public int
|
||||
left,
|
||||
top,
|
||||
right,
|
||||
bottom;
|
||||
|
||||
public void copyToBuffer(IntBuffer buffer) {
|
||||
buffer.put(0, top).put(1, bottom).put(2, left).put(3, right);
|
||||
buffer
|
||||
.put(0, left)
|
||||
.put(1, top)
|
||||
.put(2, right)
|
||||
.put(3, bottom);
|
||||
}
|
||||
|
||||
public void copyFromBuffer(IntBuffer buffer) {
|
||||
top = buffer.get(0);
|
||||
bottom = buffer.get(1);
|
||||
left = buffer.get(2);
|
||||
right = buffer.get(3);
|
||||
left = buffer.get(0);
|
||||
top = buffer.get(1);
|
||||
right = buffer.get(2);
|
||||
bottom = buffer.get(3);
|
||||
}
|
||||
|
||||
public void offset(int offset_x, int offset_y) {
|
||||
left += offset_x;
|
||||
right += offset_x;
|
||||
top += offset_y;
|
||||
right += offset_x;
|
||||
bottom += offset_y;
|
||||
}
|
||||
|
||||
public static void intersect(Rect r1, Rect r2, Rect dst) {
|
||||
dst.top = Math.max(r1.top, r2.top);
|
||||
dst.bottom = Math.min(r1.bottom, r2.bottom);
|
||||
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);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Rect: top = " + top + " bottom = " + bottom + " left = " + left + " right = " + right + ", width: " + (right - left) + ", height: " + (bottom - top);
|
||||
return "Rect: left = " + left + " top = " + top + " right = " + right + " bottom = " + bottom + ", width: " + (right - left) + ", height: " + (bottom - top);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -70,10 +70,11 @@ 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) && 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);
|
||||
}
|
||||
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);
|
||||
|
||||
int old_position = keyDownBuffer.position();
|
||||
keyDownBuffer.put(key_down_buffer);
|
||||
|
|
@ -122,6 +123,18 @@ 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]) )
|
||||
|
|
@ -132,6 +145,7 @@ 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;
|
||||
|
|
@ -141,13 +155,6 @@ 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) {
|
||||
public void poll(IntBuffer coord_buffer, ByteBuffer buttons, WindowsDisplay display) {
|
||||
for (int i = 0; i < coord_buffer.remaining(); i++)
|
||||
coord_buffer.put(coord_buffer.position() + i, 0);
|
||||
int num_buttons = mouse_button_count;
|
||||
|
|
@ -103,6 +103,9 @@ 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);
|
||||
|
|
@ -132,25 +135,8 @@ final class WindowsMouse {
|
|||
return blank_cursor;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
public void grab(boolean grab) {
|
||||
mouse_grabbed = grab;
|
||||
event_queue.clearEvents();
|
||||
}
|
||||
|
||||
|
|
@ -159,10 +145,6 @@ 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;
|
||||
|
|
@ -172,7 +154,7 @@ final class WindowsMouse {
|
|||
WindowsDisplay.doDestroyCursor(blank_cursor);
|
||||
}
|
||||
|
||||
public void handleMouseMoved(int x, int y, long millis, boolean should_center) {
|
||||
public void handleMouseMoved(int x, int y, long millis) {
|
||||
int dx = x - last_x;
|
||||
int dy = y - last_y;
|
||||
if (dx != 0 || dy != 0) {
|
||||
|
|
@ -183,8 +165,6 @@ 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,126 +27,178 @@
|
|||
|
||||
package org.lwjgl.opengl;
|
||||
|
||||
import org.lwjgl.LWJGLUtil;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
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 void populate()
|
||||
{
|
||||
if( screens == null )
|
||||
{
|
||||
screens = new HashMap<String, Screen[]>();
|
||||
private static final Pattern WHITESPACE_PATTERN = Pattern.compile("\\s+");
|
||||
|
||||
// ProcessBuilder pb = new ProcessBuilder( "xrandr", "-q" );
|
||||
// pb.redirectErrorStream();
|
||||
try
|
||||
{
|
||||
// Process p= pb.start();
|
||||
Process p = Runtime.getRuntime().exec( new String[] { "xrandr", "-q" } );
|
||||
private static void populate() {
|
||||
if ( screens != null )
|
||||
return;
|
||||
|
||||
List<Screen> currentList = new ArrayList<Screen>();
|
||||
List<Screen> possibles = new ArrayList<Screen>();
|
||||
String name = null;
|
||||
screens = new HashMap<String, Screen[]>();
|
||||
|
||||
BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) );
|
||||
String line;
|
||||
while( ( line = br.readLine() ) != null )
|
||||
{
|
||||
line = line.trim();
|
||||
String[] sa = line.split( "\\s+" );
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(new String[] { "xrandr", "-q" });
|
||||
|
||||
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 ];
|
||||
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];
|
||||
|
||||
// record the current config
|
||||
parseScreen( currentList, name, "primary".equals(sa[ 2 ]) ? sa[ 3 ] : sa[ 2 ] );
|
||||
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();
|
||||
}
|
||||
else if( Pattern.matches( "\\d*x\\d*", sa[ 0 ] ) )
|
||||
{
|
||||
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() ) {
|
||||
// found a new mode line
|
||||
parseScreen( possibles, name, sa[ 0 ] );
|
||||
parseScreenModeline(
|
||||
possibles, currentList, name,
|
||||
Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2)),
|
||||
sa, currentScreenPosition
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
screens.put( name, possibles.toArray( new Screen[ possibles.size() ] ) );
|
||||
|
||||
current = currentList.toArray(new Screen[currentList.size()]);
|
||||
}
|
||||
catch( Throwable e )
|
||||
{
|
||||
LWJGLUtil.log( "Exception in XRandR.populate(): " + e.getMessage() );
|
||||
screens.clear();
|
||||
current = new Screen[ 0 ];
|
||||
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The current screen configuration, or an empty array if
|
||||
* xrandr is not supported
|
||||
* @return The current screen configuration of the primary device,
|
||||
* 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 screens
|
||||
* The desired screen set, may not be <code>null</code>
|
||||
* @throws IllegalArgumentException
|
||||
* if no screens are specified
|
||||
* @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
|
||||
*/
|
||||
public static void setConfiguration(Screen... screens)
|
||||
{
|
||||
if( screens.length == 0 )
|
||||
throw new IllegalArgumentException( "Must specify at least one screen" );
|
||||
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();
|
||||
|
||||
List<String> cmd = new ArrayList<String>();
|
||||
cmd.add( "xrandr" );
|
||||
cmd.add("xrandr");
|
||||
|
||||
// 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 ( 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( !found ) {
|
||||
cmd.add("--output");
|
||||
cmd.add(screen.name);
|
||||
cmd.add("--off");
|
||||
if ( disable ) {
|
||||
cmd.add("--output");
|
||||
cmd.add(screen.name);
|
||||
cmd.add("--off");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -154,151 +206,196 @@ public class XRandR
|
|||
for ( Screen screen : screens )
|
||||
screen.getArgs(cmd);
|
||||
|
||||
try
|
||||
{
|
||||
// ProcessBuilder pb = new ProcessBuilder( cmd );
|
||||
// pb.redirectErrorStream();
|
||||
// Process p = pb.start();
|
||||
Process p =
|
||||
Runtime.getRuntime().exec( cmd.toArray( new String[ cmd.size() ] ) );
|
||||
try {
|
||||
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());
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @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_PATTERN1 =
|
||||
Pattern.compile( "^(\\d+)x(\\d+)\\+(\\d+)\\+(\\d+)$" );
|
||||
|
||||
private static final Pattern SCREEN_PATTERN2 = Pattern.compile( "^(\\d+)x(\\d+)$" );
|
||||
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*[+])?$");
|
||||
|
||||
/**
|
||||
* Parses a screen configuration and adds it to the list if it's
|
||||
* valid.
|
||||
* Parses a screen configuration and adds it to one of the lists if valid.
|
||||
*
|
||||
* @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
|
||||
* @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
|
||||
*/
|
||||
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 );
|
||||
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));
|
||||
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 ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Encapsulates the configuration of a monitor. Resolution is
|
||||
* fixed, position is mutable
|
||||
* 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
|
||||
*
|
||||
* @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;
|
||||
|
||||
/**
|
||||
* Position on the x-axis, in pixels
|
||||
*/
|
||||
/** 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 */
|
||||
public int xPos;
|
||||
|
||||
/**
|
||||
* Position on the y-axis, in pixels
|
||||
*/
|
||||
/** Position on the y-axis, in pixels */
|
||||
public int yPos;
|
||||
|
||||
private Screen( String name, int width, int height, int xPos, int yPos )
|
||||
{
|
||||
Screen(String name, int width, int height, String freq, 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( "--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("--rate");
|
||||
argList.add(freqOriginal);
|
||||
argList.add("--pos");
|
||||
argList.add(xPos + "x" + yPos);
|
||||
}
|
||||
|
||||
//@Override
|
||||
public String toString()
|
||||
{
|
||||
return name + " " + width + "x" + height + " @ " + xPos + "x" + yPos;
|
||||
public String toString() {
|
||||
return name + " " + width + "x" + height + " @ " + xPos + "x" + yPos + " with " + freqOriginal + "Hz";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -58,10 +58,6 @@ class GLChecks {
|
|||
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,18 +74,26 @@ public final class VersionTest {
|
|||
|
||||
if ( 2 < args.length ) {
|
||||
for ( int i = 2; i < args.length; 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]) )
|
||||
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] + "\'");
|
||||
}
|
||||
|
|
@ -236,15 +244,19 @@ 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', <layer>, 'debug', 'fc'}:\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'|'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("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("ws\t- Sets the OpenGL ES Profile bit (optional, requires 2.0).");
|
||||
System.out.println("layer\t- Layer plane (optional).");
|
||||
System.out.println("es\t- Sets the OpenGL ES Profile bit (optional, requires 2.0).");
|
||||
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,7 +174,6 @@ public final class SpriteShootout {
|
|||
// Setup geometry
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
Util.checkGLError();
|
||||
}
|
||||
|
|
@ -416,8 +415,6 @@ public final class SpriteShootout {
|
|||
glUniform1i(glGetUniformLocation(progID, "COLOR_MAP"), 0);
|
||||
|
||||
updateBallSize();
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
}
|
||||
|
||||
public void updateBallSize() {
|
||||
|
|
|
|||
|
|
@ -172,7 +172,6 @@ public final class SpriteShootout2P {
|
|||
// Setup geometry
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
Util.checkGLError();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -181,7 +181,6 @@ public final class SpriteShootoutMapped {
|
|||
// Setup geometry
|
||||
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
|
||||
Util.checkGLError();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@
|
|||
*/
|
||||
package org.lwjgl.util.applet;
|
||||
|
||||
import org.lwjgl.LWJGLUtil;
|
||||
|
||||
import java.applet.Applet;
|
||||
import java.applet.AppletStub;
|
||||
import java.awt.BorderLayout;
|
||||
|
|
@ -83,7 +85,6 @@ 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;
|
||||
|
|
@ -111,6 +112,7 @@ 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>
|
||||
|
|
@ -373,12 +375,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 */
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -775,6 +777,8 @@ 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;
|
||||
|
|
@ -1216,7 +1220,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 + System.mapLibraryName(libname);
|
||||
String libPath = path + "natives" + File.separator + LWJGLUtil.mapLibraryName(libname);
|
||||
|
||||
if (new File(libPath).exists()) {
|
||||
return libPath;
|
||||
|
|
@ -1675,20 +1679,21 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
|
|||
* @throws Exception if any errors occur
|
||||
*/
|
||||
protected void extractPack(String in, String out) throws Exception {
|
||||
File f = new File(in);
|
||||
FileOutputStream fostream = new FileOutputStream(out);
|
||||
JarOutputStream jostream = new JarOutputStream(fostream);
|
||||
throw new UnsupportedOperationException();
|
||||
// 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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1867,8 +1872,8 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
|
|||
/**
|
||||
* Compare two certificate chains to see if they match
|
||||
*
|
||||
* @param cert1 first chain of certificates
|
||||
* @param cert2 second chain of certificates
|
||||
* @param certs1 first chain of certificates
|
||||
* @param certs2 second chain of certificates
|
||||
*
|
||||
* @return true if the certificate chains are the same
|
||||
*/
|
||||
|
|
@ -2224,7 +2229,7 @@ public class AppletLoader extends Applet implements Runnable, AppletStub {
|
|||
|
||||
/**
|
||||
* set the state of applet loader
|
||||
* @param new state of applet loader
|
||||
* @param state new state of applet loader
|
||||
* */
|
||||
protected void setState(int state) {
|
||||
this.state = state;
|
||||
|
|
|
|||
|
|
@ -46,4 +46,7 @@ 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,22 +29,23 @@
|
|||
* 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 com.sun.mirror.declaration.FieldDeclaration;
|
||||
import com.sun.mirror.declaration.Modifier;
|
||||
import com.sun.mirror.type.PrimitiveType;
|
||||
import com.sun.mirror.type.TypeMirror;
|
||||
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;
|
||||
|
||||
public class FieldsGenerator {
|
||||
|
||||
private static void validateField(FieldDeclaration field) {
|
||||
private static void validateField(VariableElement field) {
|
||||
// Check if field is "public static final"
|
||||
Collection<Modifier> modifiers = field.getModifiers();
|
||||
Set<Modifier> modifiers = field.getModifiers();
|
||||
if ( modifiers.size() != 3
|
||||
|| !modifiers.contains(Modifier.PUBLIC)
|
||||
|| !modifiers.contains(Modifier.STATIC)
|
||||
|
|
@ -53,17 +54,17 @@ public class FieldsGenerator {
|
|||
}
|
||||
|
||||
// Check suported types (int, long, float, String)
|
||||
TypeMirror field_type = field.getType();
|
||||
if ( field_type instanceof PrimitiveType ) {
|
||||
TypeMirror field_type = field.asType();
|
||||
if ( "java.lang.String".equals(field_type.toString()) ) {
|
||||
} else if ( field_type instanceof PrimitiveType ) {
|
||||
PrimitiveType field_type_prim = (PrimitiveType)field_type;
|
||||
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'");
|
||||
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());
|
||||
}
|
||||
} else if ( "java.lang.String".equals(field_type.toString()) ) {
|
||||
} else {
|
||||
throw new RuntimeException("Field " + field.getSimpleName() + " is not a primitive type or String");
|
||||
}
|
||||
|
|
@ -74,7 +75,7 @@ public class FieldsGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
private static void generateField(PrintWriter writer, FieldDeclaration field, FieldDeclaration prev_field) {
|
||||
private static void generateField(PrintWriter writer, VariableElement field, VariableElement prev_field, ProcessingEnvironment env) {
|
||||
validateField(field);
|
||||
|
||||
Object value = field.getConstantValue();
|
||||
|
|
@ -94,27 +95,29 @@ public class FieldsGenerator {
|
|||
throw new RuntimeException("Field is of unexpected type. This means there is a bug in validateField().");
|
||||
}
|
||||
|
||||
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()));
|
||||
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)));
|
||||
|
||||
// Print field declaration
|
||||
if ( newBatch ) {
|
||||
if ( prev_field != null )
|
||||
if ( prev_field != null ) {
|
||||
writer.println(";\n");
|
||||
}
|
||||
|
||||
Utils.printDocComment(writer, field);
|
||||
writer.print("\tpublic static final " + field.getType().toString() + " " + field.getSimpleName() + " = " + field_value_string);
|
||||
} else
|
||||
Utils.printDocComment(writer, field, env);
|
||||
writer.print("\tpublic static final " + field.asType().toString() + " " + field.getSimpleName() + " = " + field_value_string);
|
||||
} else {
|
||||
writer.print(",\n\t\t" + field.getSimpleName() + " = " + field_value_string);
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateFields(PrintWriter writer, Collection<FieldDeclaration> fields) {
|
||||
public static void generateFields(ProcessingEnvironment env, PrintWriter writer, Collection<? extends VariableElement> fields) {
|
||||
if ( 0 < fields.size() ) {
|
||||
writer.println();
|
||||
FieldDeclaration prev_field = null;
|
||||
for ( FieldDeclaration field : fields ) {
|
||||
generateField(writer, field, prev_field);
|
||||
VariableElement prev_field = null;
|
||||
for ( VariableElement field : fields ) {
|
||||
generateField(writer, field, prev_field, env);
|
||||
prev_field = field;
|
||||
}
|
||||
writer.println(";");
|
||||
|
|
|
|||
140
src/java/org/lwjgl/util/generator/GeneratorProcessor.java
Normal file
140
src/java/org/lwjgl/util/generator/GeneratorProcessor.java
Normal file
|
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,176 +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.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,37 +29,43 @@
|
|||
* 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 com.sun.mirror.apt.*;
|
||||
import com.sun.mirror.declaration.*;
|
||||
import com.sun.mirror.type.*;
|
||||
import com.sun.mirror.util.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.util.*;
|
||||
|
||||
import java.nio.*;
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
* Generator visitor for the generator tool
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
* @version $Revision$ $Id$
|
||||
*/
|
||||
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;
|
||||
public class GeneratorVisitor extends ElementKindVisitor6<Void, Void> {
|
||||
|
||||
public GeneratorVisitor(AnnotationProcessorEnvironment env, TypeMap type_map, boolean generate_error_checks, boolean context_specific, 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) {
|
||||
this.env = env;
|
||||
this.type_map = type_map;
|
||||
this.generate_error_checks = generate_error_checks;
|
||||
|
|
@ -67,145 +73,166 @@ public class GeneratorVisitor extends SimpleDeclarationVisitor {
|
|||
this.generatorLM = generatorLM;
|
||||
}
|
||||
|
||||
private void validateMethod(MethodDeclaration method) {
|
||||
if (method.isVarArgs())
|
||||
private void validateMethod(ExecutableElement 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();
|
||||
ParameterDeclaration postfix_param = Utils.findParameter(method, postfix_param_name);
|
||||
if (Utils.isParameterMultiTyped(postfix_param))
|
||||
VariableElement 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.getType()) == null)
|
||||
}
|
||||
if ( Utils.getNIOBufferType(postfix_param.asType()) == null ) {
|
||||
throw new RuntimeException("Postfix parameter type must be a nio Buffer");
|
||||
}
|
||||
}
|
||||
if (Utils.getResultParameter(method) != null && !method.getReturnType().equals(env.getTypeUtils().getVoidType()))
|
||||
if ( Utils.getResultParameter(method) != null && !method.getReturnType().equals(env.getTypeUtils().getNoType(TypeKind.VOID)) ) {
|
||||
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(MethodDeclaration method, Class<?extends Annotation> annotation_type, Class type) {
|
||||
private void validateType(ExecutableElement 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(MethodDeclaration method, Collection<AnnotationMirror> annotations, TypeMirror type_mirror) {
|
||||
for (AnnotationMirror annotation : annotations) {
|
||||
private void validateTypes(ExecutableElement method, List<? extends 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(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) {
|
||||
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 ) {
|
||||
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 (ParameterDeclaration inner_param : method.getParameters()) {
|
||||
for ( VariableElement 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())) {
|
||||
if ( auto_size_annotation != null
|
||||
&& auto_size_annotation.value().equals(param.getSimpleName().toString()) ) {
|
||||
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 MethodDeclaration> methods) {
|
||||
for (MethodDeclaration method : methods) {
|
||||
if ( method.getAnnotation(Alternate.class) == null )
|
||||
private static void generateMethodsNativePointers(PrintWriter writer, Collection<? extends ExecutableElement> methods) {
|
||||
for ( ExecutableElement method : methods ) {
|
||||
if ( method.getAnnotation(Alternate.class) == null ) {
|
||||
generateMethodNativePointers(writer, method);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateMethodNativePointers(PrintWriter writer, MethodDeclaration method) {
|
||||
if ( method.getAnnotation(Extern.class) == null )
|
||||
private static void generateMethodNativePointers(PrintWriter writer, ExecutableElement method) {
|
||||
if ( method.getAnnotation(Extern.class) == null ) {
|
||||
writer.print("static ");
|
||||
}
|
||||
writer.println(Utils.getTypedefName(method) + " " + method.getSimpleName() + ";");
|
||||
}
|
||||
|
||||
private void generateJavaSource(InterfaceDeclaration d, PrintWriter java_writer) throws IOException {
|
||||
private void generateJavaSource(TypeElement d, PrintWriter java_writer) throws IOException {
|
||||
java_writer.println("/* MACHINE GENERATED FILE, DO NOT EDIT */");
|
||||
java_writer.println();
|
||||
java_writer.println("package " + d.getPackage().getQualifiedName() + ";");
|
||||
java_writer.println("package " + env.getElementUtils().getPackageOf(d).getQualifiedName().toString() + ";");
|
||||
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);
|
||||
if ( d.getAnnotation(Private.class) == null )
|
||||
Utils.printDocComment(java_writer, d, env);
|
||||
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));
|
||||
Collection<InterfaceType> super_interfaces = d.getSuperinterfaces();
|
||||
if (super_interfaces.size() > 1)
|
||||
List<? extends TypeMirror> super_interfaces = d.getInterfaces();
|
||||
if ( super_interfaces.size() > 1 ) {
|
||||
throw new RuntimeException(d + " extends more than one interface");
|
||||
if (super_interfaces.size() == 1) {
|
||||
InterfaceDeclaration super_interface = super_interfaces.iterator().next().getDeclaration();
|
||||
java_writer.print(" extends " + Utils.getSimpleClassName(super_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())));
|
||||
}
|
||||
java_writer.println(" {");
|
||||
FieldsGenerator.generateFields(java_writer, d.getFields());
|
||||
FieldsGenerator.generateFields(env, java_writer, Utils.getFields(d));
|
||||
java_writer.println();
|
||||
if (is_final) {
|
||||
if ( is_final ) {
|
||||
// Write private constructor to avoid instantiation
|
||||
java_writer.println("\tprivate " + Utils.getSimpleClassName(d) + "() {}");
|
||||
}
|
||||
if (d.getMethods().size() > 0 && !context_specific) {
|
||||
if ( Utils.getMethods(d).size() > 0 && !context_specific ) {
|
||||
java_writer.println();
|
||||
java_writer.println("\tstatic native void " + Utils.STUB_INITIALIZER_NAME + "() throws LWJGLException;");
|
||||
}
|
||||
|
|
@ -213,26 +240,29 @@ public class GeneratorVisitor extends SimpleDeclarationVisitor {
|
|||
java_writer.println("}");
|
||||
java_writer.close();
|
||||
String qualified_interface_name = Utils.getQualifiedClassName(d);
|
||||
env.getMessager().printNotice("Generated class " + qualified_interface_name);
|
||||
env.getMessager().printMessage(Diagnostic.Kind.NOTE, "Generated class " + qualified_interface_name);
|
||||
}
|
||||
|
||||
private void generateNativeSource(InterfaceDeclaration d) throws IOException {
|
||||
private void generateNativeSource(TypeElement d) throws IOException {
|
||||
if ( d.getKind().equals(ElementKind.ANNOTATION_TYPE) ) {
|
||||
return;
|
||||
}
|
||||
String qualified_interface_name = Utils.getQualifiedClassName(d);
|
||||
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");
|
||||
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());
|
||||
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, d.getMethods());
|
||||
TypedefsGenerator.generateNativeTypedefs(type_map, native_writer, Utils.getMethods(d));
|
||||
native_writer.println();
|
||||
if (!context_specific) {
|
||||
generateMethodsNativePointers(native_writer, d.getMethods());
|
||||
if ( !context_specific ) {
|
||||
generateMethodsNativePointers(native_writer, Utils.getMethods(d));
|
||||
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[] = {");
|
||||
|
|
@ -245,84 +275,63 @@ public class GeneratorVisitor extends SimpleDeclarationVisitor {
|
|||
native_writer.println("}");
|
||||
}
|
||||
native_writer.close();
|
||||
env.getMessager().printNotice("Generated C source " + qualified_interface_name);
|
||||
env.getMessager().printMessage(Kind.NOTE, "Generated C source " + qualified_interface_name);
|
||||
}
|
||||
|
||||
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");
|
||||
@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");
|
||||
|
||||
PrintWriter java_writer = null;
|
||||
|
||||
try {
|
||||
final Collection<? extends MethodDeclaration> methods = d.getMethods();
|
||||
if ( methods.size() == 0 && d.getFields().size() == 0 )
|
||||
return;
|
||||
final Collection<? extends ExecutableElement> methods = Utils.getMethods(e);
|
||||
if ( methods.isEmpty() && Utils.getFields(e).isEmpty() ) {
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
// 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;
|
||||
return DEFAULT_VALUE;
|
||||
|
||||
for ( final MethodDeclaration method : methods )
|
||||
//env.getMessager().printMessage(Kind.NOTE, "methods count : " + Utils.getMethods(e).size() + " fields count : " + Utils.getFields(e).size(), e);
|
||||
for ( final ExecutableElement method : methods ) {
|
||||
validateMethod(method);
|
||||
java_writer = env.getFiler().createTextFile(Filer.Location.SOURCE_TREE, d.getPackage().getQualifiedName(), new File(Utils.getSimpleClassName(d) + ".java"), null);
|
||||
generateJavaSource(d, java_writer);
|
||||
}
|
||||
|
||||
// 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);
|
||||
|
||||
if ( methods.size() > 0 ) {
|
||||
boolean noNative = true;
|
||||
for ( final MethodDeclaration method : methods ) {
|
||||
for ( final ExecutableElement 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;
|
||||
|
||||
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;
|
||||
if ( noNative ) {
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
try {
|
||||
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();
|
||||
generateNativeSource(e);
|
||||
} catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return DEFAULT_VALUE;
|
||||
} catch (Exception ex) {
|
||||
// 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(e);
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,20 +35,21 @@ package org.lwjgl.util.generator;
|
|||
import org.lwjgl.PointerBuffer;
|
||||
|
||||
import java.nio.Buffer;
|
||||
|
||||
import com.sun.mirror.type.*;
|
||||
import com.sun.mirror.util.*;
|
||||
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;
|
||||
|
||||
/**
|
||||
*
|
||||
* A TypeVisitor that translates TypeMirrors to JNI
|
||||
* type strings.
|
||||
*
|
||||
* @author elias_naur <elias_naur@users.sourceforge.net>
|
||||
* @version $Revision$
|
||||
* $Id$
|
||||
* $Id$
|
||||
*/
|
||||
public class JNITypeTranslator implements TypeVisitor {
|
||||
public class JNITypeTranslator extends SimpleTypeVisitor6<Void, Void> {
|
||||
|
||||
private final StringBuilder signature = new StringBuilder();
|
||||
|
||||
|
|
@ -62,11 +63,8 @@ public class JNITypeTranslator implements TypeVisitor {
|
|||
return objectReturn ? "jobject" : signature.toString();
|
||||
}
|
||||
|
||||
public void visitAnnotationType(AnnotationType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitArrayType(ArrayType t) {
|
||||
@Override
|
||||
public Void visitArray(ArrayType t, Void o) {
|
||||
final String className = t.getComponentType().toString();
|
||||
if ( "java.lang.CharSequence".equals(className) )
|
||||
signature.append("jlong");
|
||||
|
|
@ -76,9 +74,10 @@ public class JNITypeTranslator implements TypeVisitor {
|
|||
signature.append("jobjectArray");
|
||||
else
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
public void visitClassType(ClassType t) {
|
||||
private void visitClassType(DeclaredType t) {
|
||||
final Class<?> type = Utils.getJavaType(t);
|
||||
if ( Buffer.class.isAssignableFrom(type) || PointerBuffer.class.isAssignableFrom(type) ) {
|
||||
signature.append("jlong");
|
||||
|
|
@ -87,21 +86,17 @@ public class JNITypeTranslator implements TypeVisitor {
|
|||
signature.append("jobject");
|
||||
}
|
||||
|
||||
public void visitDeclaredType(DeclaredType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
@Override
|
||||
public Void visitDeclared(DeclaredType t, Void o) {
|
||||
if ( t.asElement().getKind().isClass() )
|
||||
visitClassType(t);
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
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) {
|
||||
@Override
|
||||
public Void visitPrimitive(PrimitiveType t, Void o) {
|
||||
String type;
|
||||
switch (t.getKind()) {
|
||||
switch ( t.getKind() ) {
|
||||
case LONG:
|
||||
type = "jlong";
|
||||
break;
|
||||
|
|
@ -127,25 +122,13 @@ public class JNITypeTranslator implements TypeVisitor {
|
|||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
signature.append(type);
|
||||
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) {
|
||||
@Override
|
||||
public Void visitNoType(NoType t, Void o) {
|
||||
signature.append(t.toString());
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
public void visitWildcardType(WildcardType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -29,54 +29,50 @@
|
|||
* 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 com.sun.mirror.type.*;
|
||||
import com.sun.mirror.util.*;
|
||||
import javax.lang.model.type.*;
|
||||
import javax.lang.model.util.SimpleTypeVisitor6;
|
||||
|
||||
/**
|
||||
* 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 implements TypeVisitor {
|
||||
public class JavaTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
|
||||
|
||||
private Class type;
|
||||
|
||||
public Class getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void visitAnnotationType(AnnotationType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitArrayType(ArrayType t) {
|
||||
@Override
|
||||
public Void visitArray(ArrayType t, Void o) {
|
||||
final TypeMirror componentType = t.getComponentType();
|
||||
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 {
|
||||
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 {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
}
|
||||
|
||||
public static Class getPrimitiveClassFromKind(PrimitiveType.Kind kind) {
|
||||
public static Class getPrimitiveClassFromKind(TypeKind kind) {
|
||||
switch ( kind ) {
|
||||
case LONG:
|
||||
return long.class;
|
||||
|
|
@ -97,7 +93,7 @@ public class JavaTypeTranslator implements TypeVisitor {
|
|||
}
|
||||
}
|
||||
|
||||
private static Class getPrimitiveArrayClassFromKind(PrimitiveType.Kind kind) {
|
||||
private static Class getPrimitiveArrayClassFromKind(TypeKind kind) {
|
||||
switch ( kind ) {
|
||||
case LONG:
|
||||
return long[].class;
|
||||
|
|
@ -118,43 +114,36 @@ public class JavaTypeTranslator implements TypeVisitor {
|
|||
}
|
||||
}
|
||||
|
||||
public void visitPrimitiveType(PrimitiveType t) {
|
||||
@Override
|
||||
public Void visitPrimitive(PrimitiveType t, Void p) {
|
||||
type = getPrimitiveClassFromKind(t.getKind());
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
public void visitDeclaredType(DeclaredType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
@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 visitEnumType(EnumType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitClassType(ClassType t) {
|
||||
private void visitClassType(DeclaredType t) {
|
||||
type = NativeTypeTranslator.getClassFromType(t);
|
||||
}
|
||||
|
||||
public void visitInterfaceType(InterfaceType t) {
|
||||
private void visitInterfaceType(DeclaredType t) {
|
||||
type = NativeTypeTranslator.getClassFromType(t);
|
||||
}
|
||||
|
||||
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) {
|
||||
@Override
|
||||
public Void visitNoType(NoType t, Void p) {
|
||||
type = void.class;
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
public void visitWildcardType(WildcardType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,33 +43,36 @@ package org.lwjgl.util.generator;
|
|||
|
||||
import org.lwjgl.PointerBuffer;
|
||||
|
||||
import com.sun.mirror.apt.*;
|
||||
import com.sun.mirror.declaration.*;
|
||||
import com.sun.mirror.type.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.nio.*;
|
||||
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;
|
||||
|
||||
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(AnnotationProcessorEnvironment env, TypeMap type_map, PrintWriter writer, InterfaceDeclaration d, boolean generate_error_checks, boolean context_specific) {
|
||||
for (MethodDeclaration method : d.getMethods()) {
|
||||
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) ) {
|
||||
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, Collection<ParameterDeclaration> params, Mode mode) {
|
||||
for (ParameterDeclaration param : params) {
|
||||
private static void generateParameters(PrintWriter writer, List<? extends VariableElement> params, Mode mode) {
|
||||
for ( VariableElement 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);
|
||||
|
|
@ -78,20 +81,20 @@ public class NativeMethodStubsGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
private static void generateParameter(PrintWriter writer, ParameterDeclaration param, Mode mode) {
|
||||
private static void generateParameter(PrintWriter writer, VariableElement 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.getType().accept(translator);
|
||||
param.asType().accept(translator, null);
|
||||
writer.print(translator.getSignature() + " " + param.getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
if ( !context_specific && method.getAnnotation(Alternate.class) == null )
|
||||
writer.print("static ");
|
||||
else
|
||||
|
|
@ -105,30 +108,30 @@ public class NativeMethodStubsGenerator {
|
|||
writer.print("jlong");
|
||||
} else {
|
||||
JNITypeTranslator translator = new JNITypeTranslator();
|
||||
result_type.accept(translator);
|
||||
result_type.accept(translator, null);
|
||||
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)");
|
||||
|
|
@ -137,7 +140,7 @@ public class NativeMethodStubsGenerator {
|
|||
|
||||
final Code code_annotation = method.getAnnotation(Code.class);
|
||||
|
||||
final boolean hasResult = !result_type.equals(env.getTypeUtils().getVoidType());
|
||||
final boolean hasResult = !result_type.equals(env.getTypeUtils().getNoType(TypeKind.VOID));
|
||||
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);
|
||||
|
|
@ -164,21 +167,21 @@ public class NativeMethodStubsGenerator {
|
|||
writer.println(code_annotation.nativeAfterCall());
|
||||
|
||||
generateStringDeallocations(writer, method.getParameters());
|
||||
if (!result_type.equals(env.getTypeUtils().getVoidType())) {
|
||||
if ( !result_type.equals(env.getTypeUtils().getNoType(TypeKind.VOID)) ) {
|
||||
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();
|
||||
|
|
@ -188,8 +191,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(";");
|
||||
}
|
||||
|
|
@ -197,24 +200,24 @@ public class NativeMethodStubsGenerator {
|
|||
writer.println();
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
final NativeTypeTranslator result_translator = new NativeTypeTranslator(type_map, return_declaration);
|
||||
result_type.accept(result_translator);
|
||||
result_type.accept(result_translator, null);
|
||||
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, Collection<ParameterDeclaration> params) {
|
||||
if (params.size() > 0) {
|
||||
private static void generateCallParameters(PrintWriter writer, TypeMap type_map, List<? extends VariableElement> params) {
|
||||
if ( params.size() > 0 ) {
|
||||
boolean first = true;
|
||||
for ( ParameterDeclaration param : params ) {
|
||||
for ( VariableElement param : params ) {
|
||||
if ( param.getAnnotation(Helper.class) != null )
|
||||
continue;
|
||||
|
||||
|
|
@ -228,7 +231,7 @@ public class NativeMethodStubsGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
private static void generateCallParameter(PrintWriter writer, TypeMap type_map, ParameterDeclaration param) {
|
||||
private static void generateCallParameter(PrintWriter writer, TypeMap type_map, VariableElement param) {
|
||||
if ( param.getAnnotation(Helper.class) != null )
|
||||
return;
|
||||
|
||||
|
|
@ -239,16 +242,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.getType().accept(translator);
|
||||
param.asType().accept(translator, null);
|
||||
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 ) {
|
||||
|
|
@ -256,42 +259,42 @@ public class NativeMethodStubsGenerator {
|
|||
} else {
|
||||
writer.print(param.getSimpleName());
|
||||
if ( param.getAnnotation(PointerArray.class) != null )
|
||||
writer.print(getPointerArrayName(Utils.getJavaType(param.getType())));
|
||||
else if ( Utils.isAddressableType(param.getType()) )
|
||||
writer.print(getPointerArrayName(Utils.getJavaType(param.asType())));
|
||||
else if ( Utils.isAddressableType(param.asType()) )
|
||||
writer.print(BUFFER_ADDRESS_POSTFIX);
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateStringDeallocations(PrintWriter writer, Collection<ParameterDeclaration> params) {
|
||||
for (ParameterDeclaration param : params) {
|
||||
final Class java_type = Utils.getJavaType(param.getType());
|
||||
private static void generateStringDeallocations(PrintWriter writer, List<? extends VariableElement> params) {
|
||||
for ( VariableElement param : params ) {
|
||||
final Class java_type = Utils.getJavaType(param.asType());
|
||||
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, MethodDeclaration method, Mode mode) {
|
||||
private static void generateBufferParameterAddresses(TypeMap type_map, PrintWriter writer, ExecutableElement method, Mode mode) {
|
||||
strLoopDeclared = false;
|
||||
ptrLoopDeclared = false;
|
||||
for ( ParameterDeclaration param : method.getParameters() ) {
|
||||
for ( VariableElement 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.getType()))
|
||||
generateBufferParameterAddress(type_map, writer, method, param, mode);
|
||||
if ( param.getAnnotation(Result.class) == null && (constant_annotation == null || !constant_annotation.isNative()) && Utils.isAddressableType(param.asType()) )
|
||||
generateBufferParameterAddress(type_map, writer, param, mode);
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean strLoopDeclared;
|
||||
private static boolean ptrLoopDeclared;
|
||||
|
||||
private static void generateBufferParameterAddress(TypeMap type_map, PrintWriter writer, MethodDeclaration method, ParameterDeclaration param, Mode mode) {
|
||||
private static void generateBufferParameterAddress(TypeMap type_map, PrintWriter writer, VariableElement 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.getType());
|
||||
final Class java_type = Utils.getJavaType(param.asType());
|
||||
|
||||
final NativeTypeTranslator translator = new NativeTypeTranslator(type_map, param);
|
||||
param.getType().accept(translator);
|
||||
param.asType().accept(translator, null);
|
||||
final String native_type = translator.getSignature();
|
||||
|
||||
if ( !java_type.isArray() || CharSequence.class.isAssignableFrom(java_type.getComponentType()) ) {
|
||||
|
|
@ -300,12 +303,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);
|
||||
|
|
@ -317,7 +320,7 @@ public class NativeMethodStubsGenerator {
|
|||
final String n = getPointerArrayName(java_type);
|
||||
final String arrayType;
|
||||
if ( POINTER_LIST_NAME.equals(n) ) {
|
||||
if ( n.equals(param.getSimpleName()) )
|
||||
if ( n.equals(param.getSimpleName().toString()) )
|
||||
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()) ? " " : "");
|
||||
|
|
@ -329,7 +332,7 @@ public class NativeMethodStubsGenerator {
|
|||
ptrLoopDeclared = true;
|
||||
}
|
||||
} else {
|
||||
if ( n.equals(param.getSimpleName()) )
|
||||
if ( n.equals(param.getSimpleName().toString()) )
|
||||
throw new RuntimeException("The name '" + n + "' is not valid for arguments annotated with PointerArray");
|
||||
|
||||
arrayType = translator.getSignature(true);
|
||||
|
|
@ -357,8 +360,8 @@ public class NativeMethodStubsGenerator {
|
|||
return STRING_LIST_NAME;
|
||||
}
|
||||
|
||||
private static boolean hasPointerArrayInits(Collection<ParameterDeclaration> params) {
|
||||
for ( ParameterDeclaration param : params ) {
|
||||
private static boolean hasPointerArrayInits(List<? extends VariableElement> params) {
|
||||
for ( VariableElement param : params ) {
|
||||
PointerArray pointerArray_annotation = param.getAnnotation(PointerArray.class);
|
||||
if ( pointerArray_annotation != null )
|
||||
return true;
|
||||
|
|
@ -366,14 +369,14 @@ public class NativeMethodStubsGenerator {
|
|||
return false;
|
||||
}
|
||||
|
||||
private static void generatePointerArrayInits(TypeMap type_map, PrintWriter writer, Collection<ParameterDeclaration> params) {
|
||||
for ( ParameterDeclaration param : params ) {
|
||||
private static void generatePointerArrayInits(TypeMap type_map, PrintWriter writer, List<? extends VariableElement> params) {
|
||||
for ( VariableElement param : params ) {
|
||||
PointerArray pointerArray_annotation = param.getAnnotation(PointerArray.class);
|
||||
if ( pointerArray_annotation != null ) {
|
||||
final Class java_type = Utils.getJavaType(param.getType());
|
||||
final Class java_type = Utils.getJavaType(param.asType());
|
||||
final Class<?> component_type = java_type.isArray() ? java_type.getComponentType() : null;
|
||||
final NativeTypeTranslator translator = new NativeTypeTranslator(type_map, param);
|
||||
param.getType().accept(translator);
|
||||
param.asType().accept(translator, null);
|
||||
|
||||
final String n = getPointerArrayName(java_type);
|
||||
if ( POINTER_LIST_NAME.equals(n) ) {
|
||||
|
|
@ -398,7 +401,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(" + n + "_address) + 1;");
|
||||
writer.println("\t\t" + n + "_address += strlen((const char *)" + 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,48 +29,44 @@
|
|||
* 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 com.sun.mirror.declaration.AnnotationMirror;
|
||||
import com.sun.mirror.declaration.Declaration;
|
||||
import com.sun.mirror.type.*;
|
||||
import com.sun.mirror.util.TypeVisitor;
|
||||
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;
|
||||
|
||||
/**
|
||||
* $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 implements TypeVisitor {
|
||||
public class NativeTypeTranslator extends SimpleTypeVisitor6<Void, Void> {
|
||||
|
||||
private Collection<Class> native_types;
|
||||
private boolean is_indirect;
|
||||
private final Declaration declaration;
|
||||
private final TypeMap type_map;
|
||||
private Collection<Class> native_types;
|
||||
private boolean is_indirect;
|
||||
private final Element declaration;
|
||||
private final TypeMap type_map;
|
||||
|
||||
public NativeTypeTranslator(TypeMap type_map, Declaration declaration) {
|
||||
public NativeTypeTranslator(TypeMap type_map, Element declaration) {
|
||||
this.declaration = declaration;
|
||||
this.type_map = type_map;
|
||||
}
|
||||
|
|
@ -81,8 +77,9 @@ public class NativeTypeTranslator implements TypeVisitor {
|
|||
|
||||
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());
|
||||
|
|
@ -93,23 +90,22 @@ public class NativeTypeTranslator implements TypeVisitor {
|
|||
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();
|
||||
}
|
||||
|
||||
public void visitAnnotationType(AnnotationType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitArrayType(ArrayType t) {
|
||||
@Override
|
||||
public Void visitArray(ArrayType t, Void o) {
|
||||
final Class<?> type = Utils.getJavaType(t).getComponentType();
|
||||
|
||||
if ( CharSequence.class.isAssignableFrom(type) ) {
|
||||
|
|
@ -122,43 +118,47 @@ public class NativeTypeTranslator implements TypeVisitor {
|
|||
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 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
|
||||
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 {
|
||||
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.getDeclaration().getQualifiedName());
|
||||
return (Class<? extends Annotation>)Class.forName(t.toString());
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void getNativeTypeFromAnnotatedPrimitiveType(PrimitiveType.Kind kind) {
|
||||
private void getNativeTypeFromAnnotatedPrimitiveType(TypeKind kind) {
|
||||
native_types = translateAnnotations();
|
||||
if ( native_types.size() == 0 )
|
||||
if ( native_types.isEmpty() ) {
|
||||
native_types.add(type_map.getNativeTypeFromPrimitiveType(kind));
|
||||
}
|
||||
}
|
||||
|
||||
public void visitClassType(ClassType t) {
|
||||
private void visitClassType(DeclaredType t) {
|
||||
is_indirect = true;
|
||||
|
||||
Class<?> c = getClassFromType(t);
|
||||
|
|
@ -169,30 +169,25 @@ public class NativeTypeTranslator implements TypeVisitor {
|
|||
native_types = new ArrayList<Class>();
|
||||
native_types.add(type_map.getVoidType());
|
||||
} else if ( Buffer.class.isAssignableFrom(c) || PointerBuffer.class.isAssignableFrom(c) ) {
|
||||
PrimitiveType.Kind kind = getPrimitiveKindFromBufferClass(c);
|
||||
TypeKind 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");
|
||||
}
|
||||
}
|
||||
|
||||
public void visitPrimitiveType(PrimitiveType t) {
|
||||
@Override
|
||||
public Void visitPrimitive(PrimitiveType t, Void p) {
|
||||
getNativeTypeFromAnnotatedPrimitiveType(t.getKind());
|
||||
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) {
|
||||
private void visitInterfaceType(DeclaredType t) {
|
||||
// See ARB_debug_label.glObjectPtrLabel
|
||||
Class<?> c = getClassFromType(t);
|
||||
if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(c) ) {
|
||||
|
|
@ -200,26 +195,39 @@ public class NativeTypeTranslator implements TypeVisitor {
|
|||
native_types.add(PointerWrapper.class);
|
||||
|
||||
is_indirect = false;
|
||||
} else
|
||||
} else {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the annotation is itself annotated with a certain annotation type
|
||||
@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
|
||||
* @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().getDeclaration().getAnnotation(type);
|
||||
return annotation.getAnnotationType().asElement().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 Collection<Class> translateAnnotations() {
|
||||
Collection<Class> result = new ArrayList<Class>();
|
||||
private List<Class> translateAnnotations() {
|
||||
List<Class> result = new ArrayList<Class>();
|
||||
for ( AnnotationMirror annotation : Utils.getSortedAnnotations(declaration.getAnnotationMirrors()) ) {
|
||||
Class translated_result = translateAnnotation(annotation);
|
||||
if ( translated_result != null ) {
|
||||
|
|
@ -229,25 +237,13 @@ public class NativeTypeTranslator implements TypeVisitor {
|
|||
return result;
|
||||
}
|
||||
|
||||
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) {
|
||||
@Override
|
||||
public Void visitNoType(NoType t, Void p) {
|
||||
native_types = translateAnnotations();
|
||||
if ( native_types.size() == 0 )
|
||||
if ( native_types.isEmpty() ) {
|
||||
native_types.add(void.class);
|
||||
}
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
public void visitWildcardType(WildcardType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,19 +42,21 @@ 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 implements TypeVisitor {
|
||||
public class PostfixTranslator extends SimpleTypeVisitor6<Void, Void> {
|
||||
private final StringBuilder signature = new StringBuilder();
|
||||
private final Declaration declaration;
|
||||
private final Element declaration;
|
||||
private final TypeMap type_map;
|
||||
|
||||
public PostfixTranslator(TypeMap type_map, Declaration declaration) {
|
||||
public PostfixTranslator(TypeMap type_map, Element declaration) {
|
||||
this.declaration = declaration;
|
||||
this.type_map = type_map;
|
||||
}
|
||||
|
|
@ -63,52 +65,39 @@ public class PostfixTranslator implements TypeVisitor {
|
|||
return signature.toString();
|
||||
}
|
||||
|
||||
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;
|
||||
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;
|
||||
else
|
||||
throw new RuntimeException(c + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitClassType(ClassType t) {
|
||||
private void visitClassType(DeclaredType t) {
|
||||
Class<?> c = NativeTypeTranslator.getClassFromType(t);
|
||||
PrimitiveType.Kind kind = getPrimitiveKindFromBufferClass(c);
|
||||
TypeKind kind = getPrimitiveKindFromBufferClass(c);
|
||||
visitPrimitiveTypeKind(kind);
|
||||
}
|
||||
|
||||
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");
|
||||
@Override
|
||||
public Void visitDeclared(DeclaredType t, Void o) {
|
||||
if ( t.asElement().getKind().isClass() )
|
||||
visitClassType(t);
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
@ -118,26 +107,28 @@ public class PostfixTranslator implements TypeVisitor {
|
|||
|
||||
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;
|
||||
}
|
||||
|
||||
public void visitPrimitiveType(PrimitiveType t) {
|
||||
@Override
|
||||
public Void visitPrimitive(PrimitiveType t, Void o) {
|
||||
visitPrimitiveTypeKind(t.getKind());
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
private void visitPrimitiveTypeKind(PrimitiveType.Kind kind) {
|
||||
private void visitPrimitiveTypeKind(TypeKind 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;
|
||||
|
|
@ -161,23 +152,4 @@ public class PostfixTranslator implements TypeVisitor {
|
|||
}
|
||||
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,7 +29,6 @@
|
|||
* 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;
|
||||
|
||||
/**
|
||||
|
|
@ -37,35 +36,41 @@ 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 com.sun.mirror.declaration.*;
|
||||
import com.sun.mirror.type.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
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;
|
||||
|
||||
public class RegisterStubsGenerator {
|
||||
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();
|
||||
|
||||
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();
|
||||
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);
|
||||
|
|
@ -74,27 +79,30 @@ public class RegisterStubsGenerator {
|
|||
writer.println();
|
||||
}
|
||||
|
||||
private static String getTypeSignature(TypeMirror type, boolean add_position_signature) {
|
||||
SignatureTranslator v = new SignatureTranslator(add_position_signature);
|
||||
type.accept(v);
|
||||
private static String getTypeSignature(TypeMirror type) {
|
||||
SignatureTranslator v = new SignatureTranslator();
|
||||
type.accept(v, null);
|
||||
return v.getSignature();
|
||||
}
|
||||
|
||||
private static String getMethodSignature(MethodDeclaration method, Mode mode) {
|
||||
Collection<ParameterDeclaration> params = method.getParameters();
|
||||
private static String getMethodSignature(ExecutableElement method, Mode mode) {
|
||||
List<? extends VariableElement> params = method.getParameters();
|
||||
String signature = "(";
|
||||
for (ParameterDeclaration param : params) {
|
||||
if ( param.getAnnotation(Result.class) != null || (param.getAnnotation(Helper.class) != null && !param.getAnnotation(Helper.class).passToNative()) )
|
||||
for ( VariableElement 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.getType(), true);
|
||||
} else {
|
||||
signature += getTypeSignature(param.asType());
|
||||
}
|
||||
}
|
||||
|
||||
final TypeMirror result_type = Utils.getMethodReturnType(method);
|
||||
|
|
@ -102,33 +110,40 @@ 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, false);
|
||||
if ( cached_result_annotation != null )
|
||||
final String result_type_signature = isNIOBuffer ? "Ljava/nio/ByteBuffer;" : getTypeSignature(result_type);
|
||||
if ( cached_result_annotation != null ) {
|
||||
signature += result_type_signature;
|
||||
}
|
||||
|
||||
signature += ")";
|
||||
signature += result_type_signature;
|
||||
return signature;
|
||||
}
|
||||
|
||||
private static void printMethodNativeStubBind(PrintWriter writer, InterfaceDeclaration d, MethodDeclaration method, Platform platform, Mode mode, boolean has_more, boolean generate_error_checks, boolean context_specific) {
|
||||
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) {
|
||||
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() : alt_annotation.value();
|
||||
String opengl_handle_name = methodName.replaceFirst("gl", platform.getPrefix());
|
||||
final String methodName = alt_annotation == null ? method.getSimpleName().toString() : alt_annotation.value();
|
||||
String opengl_handle_name = GL_PATTERN.matcher(methodName).replaceFirst(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,55 +42,57 @@ package org.lwjgl.util.generator;
|
|||
*/
|
||||
|
||||
import org.lwjgl.PointerBuffer;
|
||||
import org.lwjgl.PointerWrapper;
|
||||
|
||||
import com.sun.mirror.type.*;
|
||||
import com.sun.mirror.util.*;
|
||||
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 java.nio.*;
|
||||
|
||||
class SignatureTranslator implements TypeVisitor {
|
||||
private final boolean add_position_signature;
|
||||
class SignatureTranslator extends SimpleTypeVisitor6<Void, Void> {
|
||||
private final StringBuilder signature = new StringBuilder();
|
||||
|
||||
SignatureTranslator(boolean add_position_signature) {
|
||||
this.add_position_signature = add_position_signature;
|
||||
}
|
||||
SignatureTranslator() {}
|
||||
|
||||
private static final Pattern DOT_PATTERN = Pattern.compile("\\.");
|
||||
|
||||
private static String getNativeNameFromClassName(String class_name) {
|
||||
return class_name.replaceAll("\\.", "/");
|
||||
return DOT_PATTERN.matcher(class_name).replaceAll("/");
|
||||
}
|
||||
|
||||
public String getSignature() {
|
||||
return signature.toString();
|
||||
}
|
||||
|
||||
public void visitAnnotationType(AnnotationType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitArrayType(ArrayType t) {
|
||||
@Override
|
||||
public Void visitArray(ArrayType t, Void o) {
|
||||
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 ( org.lwjgl.PointerWrapper.class.isAssignableFrom(type) )
|
||||
else if ( PointerWrapper.class.isAssignableFrom(type) )
|
||||
signature.append("[L" + getNativeNameFromClassName(type.getName()) + ";");
|
||||
else
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
public void visitClassType(ClassType t) {
|
||||
private void visitClassType(DeclaredType t) {
|
||||
Class type = NativeTypeTranslator.getClassFromType(t);
|
||||
|
||||
if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(type) || (Utils.isAddressableType(type) && !String.class.equals(type)) )
|
||||
if ( 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.getDeclaration().getQualifiedName();
|
||||
type_name = t.toString();
|
||||
|
||||
signature.append("L");
|
||||
signature.append(getNativeNameFromClassName(type_name));
|
||||
|
|
@ -98,24 +100,26 @@ class SignatureTranslator implements TypeVisitor {
|
|||
}
|
||||
}
|
||||
|
||||
public void visitDeclaredType(DeclaredType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
@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 visitEnumType(EnumType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitInterfaceType(InterfaceType t) {
|
||||
private void visitInterfaceType(DeclaredType t) {
|
||||
Class type = NativeTypeTranslator.getClassFromType(t);
|
||||
if ( org.lwjgl.PointerWrapper.class.isAssignableFrom(type) )
|
||||
if ( PointerWrapper.class.isAssignableFrom(type) )
|
||||
signature.append("J");
|
||||
else
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
|
||||
public void visitPrimitiveType(PrimitiveType t) {
|
||||
switch (t.getKind()) {
|
||||
@Override
|
||||
public Void visitPrimitive(PrimitiveType t, Void o) {
|
||||
switch ( t.getKind() ) {
|
||||
case BOOLEAN:
|
||||
signature.append("Z");
|
||||
break;
|
||||
|
|
@ -140,25 +144,13 @@ class SignatureTranslator implements TypeVisitor {
|
|||
default:
|
||||
throw new RuntimeException("Unsupported type " + t);
|
||||
}
|
||||
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) {
|
||||
@Override
|
||||
public Void visitNoType(NoType t, Void o) {
|
||||
signature.append("V");
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
public void visitWildcardType(WildcardType t) {
|
||||
throw new RuntimeException(t + " is not allowed");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,30 +33,31 @@ 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.util.*;
|
||||
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;
|
||||
|
||||
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;
|
||||
|
|
@ -73,14 +74,15 @@ 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(PrimitiveType.Kind kind) {
|
||||
private static Class getTypeFromPrimitiveKind(TypeKind kind) {
|
||||
Class type;
|
||||
switch (kind) {
|
||||
switch ( kind ) {
|
||||
case LONG:
|
||||
type = long.class;
|
||||
break;
|
||||
|
|
@ -108,9 +110,9 @@ public class TypeInfo {
|
|||
return type;
|
||||
}
|
||||
|
||||
private static Class getBufferTypeFromPrimitiveKind(PrimitiveType.Kind kind, AnnotationMirror annotation) {
|
||||
private static Class getBufferTypeFromPrimitiveKind(TypeKind kind, AnnotationMirror annotation) {
|
||||
Class type;
|
||||
switch (kind) {
|
||||
switch ( kind ) {
|
||||
case INT:
|
||||
type = IntBuffer.class;
|
||||
break;
|
||||
|
|
@ -124,12 +126,14 @@ public class TypeInfo {
|
|||
type = ShortBuffer.class;
|
||||
break;
|
||||
case LONG:
|
||||
if ( annotation.getAnnotationType().getDeclaration().getAnnotation(PointerType.class) != null )
|
||||
if ( annotation.getAnnotationType().asElement().getAnnotation(PointerType.class) != null ) {
|
||||
type = PointerBuffer.class;
|
||||
else
|
||||
} else {
|
||||
type = LongBuffer.class;
|
||||
}
|
||||
break;
|
||||
case BYTE: /* fall through */
|
||||
|
||||
case BOOLEAN:
|
||||
type = ByteBuffer.class;
|
||||
break;
|
||||
|
|
@ -144,33 +148,34 @@ public class TypeInfo {
|
|||
return new TypeInfo(java_type, Signedness.NONE, null);
|
||||
}
|
||||
|
||||
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());
|
||||
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());
|
||||
map.put(param, type_info);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private static Collection<TypeInfo> getTypeInfos(TypeMap type_map, Declaration param, TypeMirror decl_type) {
|
||||
Collection<AnnotationMirror> annotations = Utils.getSortedAnnotations(param.getAnnotationMirrors());
|
||||
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);
|
||||
|
||||
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);
|
||||
|
|
@ -178,59 +183,59 @@ public class TypeInfo {
|
|||
}
|
||||
}
|
||||
Class type;
|
||||
PrimitiveType.Kind kind;
|
||||
GLvoid void_annotation = param.getAnnotation(GLvoid.class);
|
||||
TypeKind kind;
|
||||
kind = void_annotation == null ? type_map.getPrimitiveTypeFromNativeType(annotation_type) : void_annotation.value();
|
||||
if (Utils.getNIOBufferType(decl_type) != null)
|
||||
if ( Utils.getNIOBufferType(param.asType()) != 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(decl_type);
|
||||
if ( add_default_type ) {
|
||||
TypeInfo default_type_info = getDefaultTypeInfo(param.asType());
|
||||
Collection<TypeInfo> result = new ArrayList<TypeInfo>();
|
||||
result.add(default_type_info);
|
||||
return result;
|
||||
} else
|
||||
} else {
|
||||
return multityped_result;
|
||||
}
|
||||
}
|
||||
|
||||
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());
|
||||
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);
|
||||
map.put(param, types);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
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);
|
||||
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);
|
||||
return cross_product;
|
||||
}
|
||||
|
||||
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) {
|
||||
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
|
||||
*/
|
||||
cross_product.add(current_instance);
|
||||
return;
|
||||
}
|
||||
ParameterDeclaration param = parameters[index];
|
||||
VariableElement param = parameters.get(index);
|
||||
Collection<TypeInfo> typeinfos = typeinfos_map.get(param);
|
||||
if (typeinfos != null) {
|
||||
for (TypeInfo typeinfo : typeinfos) {
|
||||
Map<ParameterDeclaration, TypeInfo> instance = new HashMap<ParameterDeclaration, TypeInfo>(current_instance);
|
||||
if ( typeinfos != null ) {
|
||||
for ( TypeInfo typeinfo : typeinfos ) {
|
||||
Map<VariableElement, TypeInfo> instance = new HashMap<VariableElement, 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 com.sun.mirror.declaration.*;
|
||||
import com.sun.mirror.type.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.PrintWriter;
|
||||
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, MethodDeclaration method, String tabs);
|
||||
void printErrorCheckMethod(PrintWriter writer, ExecutableElement method, String tabs);
|
||||
String getRegisterNativesFunctionName();
|
||||
PrimitiveType.Kind getPrimitiveTypeFromNativeType(Class<? extends Annotation> native_type);
|
||||
TypeKind 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(PrimitiveType.Kind kind);
|
||||
Class getNativeTypeFromPrimitiveType(TypeKind 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 com.sun.mirror.declaration.*;
|
||||
import com.sun.mirror.type.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
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;
|
||||
|
||||
public class TypedefsGenerator {
|
||||
private static void generateNativeTypedefs(TypeMap type_map, PrintWriter writer, MethodDeclaration method) {
|
||||
private static void generateNativeTypedefs(TypeMap type_map, PrintWriter writer, ExecutableElement 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);
|
||||
return_type.accept(translator, null);
|
||||
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<ParameterDeclaration> params) {
|
||||
if (params.size() > 0) {
|
||||
private static void generateNativeTypedefsParameters(TypeMap type_map, PrintWriter writer, Collection<? extends VariableElement> params) {
|
||||
if ( params.size() > 0 ) {
|
||||
boolean first = true;
|
||||
for ( ParameterDeclaration param : params ) {
|
||||
for ( VariableElement 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, ParameterDeclaration param) {
|
||||
private static void generateNativeTypedefsParameter(TypeMap type_map, PrintWriter writer, VariableElement param) {
|
||||
NativeTypeTranslator translator = new NativeTypeTranslator(type_map, param);
|
||||
param.getType().accept(translator);
|
||||
param.asType().accept(translator, null);
|
||||
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 MethodDeclaration> methods) {
|
||||
for (MethodDeclaration method : methods) {
|
||||
public static void generateNativeTypedefs(TypeMap type_map, PrintWriter writer, Collection<? extends ExecutableElement> methods) {
|
||||
for ( ExecutableElement method : methods ) {
|
||||
if ( method.getAnnotation(Alternate.class) == null && method.getAnnotation(Reuse.class) == null )
|
||||
generateNativeTypedefs(type_map, writer, method);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,11 +36,10 @@ 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;
|
||||
|
|
@ -50,10 +49,13 @@ import java.io.PrintWriter;
|
|||
import java.nio.Buffer;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.*;
|
||||
|
||||
import com.sun.mirror.declaration.*;
|
||||
import com.sun.mirror.type.PrimitiveType;
|
||||
import com.sun.mirror.type.TypeMirror;
|
||||
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;
|
||||
|
||||
public class Utils {
|
||||
|
||||
|
|
@ -71,43 +73,47 @@ public class Utils {
|
|||
public static final String CACHED_BUFFER_NAME = "old_buffer";
|
||||
private static final String OVERLOADED_METHOD_PREFIX = "n";
|
||||
|
||||
public static String getTypedefName(MethodDeclaration method) {
|
||||
public static String getTypedefName(ExecutableElement method) {
|
||||
Alternate alt_annotation = method.getAnnotation(Alternate.class);
|
||||
return (alt_annotation == null ? method.getSimpleName() : alt_annotation.value()) + TYPEDEF_POSTFIX;
|
||||
}
|
||||
|
||||
public static String getFunctionAddressName(InterfaceDeclaration interface_decl, MethodDeclaration method) {
|
||||
public static String getFunctionAddressName(TypeElement interface_decl, ExecutableElement method) {
|
||||
return getFunctionAddressName(interface_decl, method, false);
|
||||
}
|
||||
|
||||
public static String getFunctionAddressName(InterfaceDeclaration interface_decl, MethodDeclaration method, boolean forceAlt) {
|
||||
public static String getFunctionAddressName(TypeElement interface_decl, ExecutableElement 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();
|
||||
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().toString();
|
||||
} else {
|
||||
return alt_annotation.value();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isFinal(InterfaceDeclaration d) {
|
||||
public static boolean isFinal(Element 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().getDeclaration().getQualifiedName();
|
||||
String n2 = a2.getAnnotationType().getDeclaration().getQualifiedName();
|
||||
int result = n1.compareTo(n2);
|
||||
return result;
|
||||
String n1 = a1.getAnnotationType().toString();
|
||||
String n2 = a2.getAnnotationType().toString();
|
||||
return n1.compareTo(n2);
|
||||
}
|
||||
|
||||
public boolean equals(AnnotationMirror a1, AnnotationMirror a2) {
|
||||
|
|
@ -115,13 +121,13 @@ public class Utils {
|
|||
}
|
||||
}
|
||||
|
||||
public static Collection<AnnotationMirror> getSortedAnnotations(Collection<AnnotationMirror> annotations) {
|
||||
public static List<AnnotationMirror> getSortedAnnotations(List<? extends AnnotationMirror> annotations) {
|
||||
List<AnnotationMirror> annotation_list = new ArrayList<AnnotationMirror>(annotations);
|
||||
Collections.sort(annotation_list, new AnnotationMirrorComparator());
|
||||
return annotation_list;
|
||||
}
|
||||
|
||||
public static String getReferenceName(InterfaceDeclaration interface_decl, MethodDeclaration method, ParameterDeclaration param) {
|
||||
public static String getReferenceName(TypeElement interface_decl, ExecutableElement method, VariableElement param) {
|
||||
return interface_decl.getSimpleName() + "_" + method.getSimpleName() + "_" + param.getSimpleName();
|
||||
}
|
||||
|
||||
|
|
@ -132,7 +138,7 @@ public class Utils {
|
|||
public static boolean isAddressableType(Class type) {
|
||||
if ( type.isArray() ) {
|
||||
final Class component_type = type.getComponentType();
|
||||
return isAddressableTypeImpl(component_type) || org.lwjgl.PointerWrapper.class.isAssignableFrom(component_type);
|
||||
return isAddressableTypeImpl(component_type) || PointerWrapper.class.isAssignableFrom(component_type);
|
||||
}
|
||||
return isAddressableTypeImpl(type);
|
||||
}
|
||||
|
|
@ -143,42 +149,48 @@ public class Utils {
|
|||
|
||||
public static Class getJavaType(TypeMirror type_mirror) {
|
||||
JavaTypeTranslator translator = new JavaTypeTranslator();
|
||||
type_mirror.accept(translator);
|
||||
type_mirror.accept((TypeVisitor)translator, null);
|
||||
return translator.getType();
|
||||
}
|
||||
|
||||
private static boolean hasParameterMultipleTypes(ParameterDeclaration param) {
|
||||
private static boolean hasParameterMultipleTypes(VariableElement param) {
|
||||
int num_native_annotations = 0;
|
||||
for ( AnnotationMirror annotation : param.getAnnotationMirrors() )
|
||||
if ( NativeTypeTranslator.getAnnotation(annotation, NativeType.class) != null )
|
||||
for ( AnnotationMirror annotation : param.getAnnotationMirrors() ) {
|
||||
if ( NativeTypeTranslator.getAnnotation(annotation, NativeType.class) != null ) {
|
||||
num_native_annotations++;
|
||||
}
|
||||
}
|
||||
return num_native_annotations > 1;
|
||||
}
|
||||
|
||||
public static boolean isParameterMultiTyped(ParameterDeclaration param) {
|
||||
boolean result = Buffer.class.equals(Utils.getJavaType(param.getType()));
|
||||
if ( !result && hasParameterMultipleTypes(param) )
|
||||
public static boolean isParameterMultiTyped(VariableElement param) {
|
||||
boolean result = Buffer.class.equals(Utils.getJavaType(param.asType()));
|
||||
if ( !result && hasParameterMultipleTypes(param) ) {
|
||||
throw new RuntimeException(param + " not defined as java.nio.Buffer but has multiple types");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static ParameterDeclaration findParameter(MethodDeclaration method, String name) {
|
||||
for ( ParameterDeclaration param : method.getParameters() )
|
||||
if ( param.getSimpleName().equals(name) )
|
||||
public static VariableElement findParameter(ExecutableElement method, String name) {
|
||||
for ( VariableElement param : method.getParameters() ) {
|
||||
if ( param.getSimpleName().toString().equals(name) ) {
|
||||
return param;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("Parameter " + name + " not found");
|
||||
}
|
||||
|
||||
public static void printDocComment(PrintWriter writer, Declaration decl) {
|
||||
public static void printDocComment(PrintWriter writer, Element decl, ProcessingEnvironment pe) {
|
||||
final String overloadsComment;
|
||||
if ( (decl instanceof MethodDeclaration) && decl.getAnnotation(Alternate.class) != null )
|
||||
if ( (decl instanceof ExecutableElement) && decl.getAnnotation(Alternate.class) != null ) {
|
||||
overloadsComment = "Overloads " + decl.getAnnotation(Alternate.class).value() + ".";
|
||||
else
|
||||
} else {
|
||||
overloadsComment = null;
|
||||
}
|
||||
|
||||
String doc_comment = decl.getDocComment();
|
||||
String doc_comment = pe.getElementUtils().getDocComment(decl);
|
||||
if ( doc_comment != null ) {
|
||||
final String tab = decl instanceof InterfaceDeclaration ? "" : "\t";
|
||||
final String tab = (decl instanceof TypeElement) ? "" : "\t";
|
||||
writer.println(tab + "/**");
|
||||
|
||||
if ( overloadsComment != null ) {
|
||||
|
|
@ -191,8 +203,9 @@ 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);
|
||||
|
|
@ -201,107 +214,117 @@ public class Utils {
|
|||
}
|
||||
|
||||
writer.println(tab + " */");
|
||||
} else if ( overloadsComment != null )
|
||||
} else if ( overloadsComment != null ) {
|
||||
writer.println("\t/** " + overloadsComment + " */");
|
||||
}
|
||||
}
|
||||
|
||||
public static AnnotationMirror getParameterAutoAnnotation(ParameterDeclaration param) {
|
||||
for ( AnnotationMirror annotation : param.getAnnotationMirrors() )
|
||||
if ( NativeTypeTranslator.getAnnotation(annotation, Auto.class) != null )
|
||||
public static AnnotationMirror getParameterAutoAnnotation(VariableElement 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, 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;
|
||||
*/
|
||||
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;
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
private static final Pattern DOT_PATTERN = Pattern.compile("\\.");
|
||||
|
||||
public static String getNativeQualifiedName(String qualified_name) {
|
||||
return qualified_name.replaceAll("\\.", "_");
|
||||
return DOT_PATTERN.matcher(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, MethodDeclaration method, boolean generate_error_checks, boolean context_specific) {
|
||||
public static String getQualifiedNativeMethodName(String qualified_class_name, ExecutableElement 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 ParameterDeclaration getResultParameter(MethodDeclaration method) {
|
||||
ParameterDeclaration result_param = null;
|
||||
for ( ParameterDeclaration param : method.getParameters() ) {
|
||||
public static VariableElement getResultParameter(ExecutableElement method) {
|
||||
VariableElement result_param = null;
|
||||
for ( VariableElement 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(MethodDeclaration method) {
|
||||
public static TypeMirror getMethodReturnType(ExecutableElement method) {
|
||||
TypeMirror result_type;
|
||||
ParameterDeclaration result_param = getResultParameter(method);
|
||||
VariableElement result_param = getResultParameter(method);
|
||||
if ( result_param != null ) {
|
||||
result_type = result_param.getType();
|
||||
} else
|
||||
result_type = result_param.asType();
|
||||
} else {
|
||||
result_type = method.getReturnType();
|
||||
}
|
||||
return result_type;
|
||||
}
|
||||
|
||||
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()) ) {
|
||||
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()) ) {
|
||||
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);
|
||||
}
|
||||
|
||||
PrimitiveType.Kind kind = NativeTypeTranslator.getPrimitiveKindFromBufferClass(Utils.getJavaType(return_param.getType()));
|
||||
if ( return_param.getAnnotation(GLboolean.class) != null )
|
||||
kind = PrimitiveType.Kind.BOOLEAN;
|
||||
TypeKind kind = NativeTypeTranslator.getPrimitiveKindFromBufferClass(Utils.getJavaType(return_param.asType()));
|
||||
if ( return_param.getAnnotation(GLboolean.class) != null ) {
|
||||
kind = TypeKind.BOOLEAN;
|
||||
}
|
||||
|
||||
if ( kind == PrimitiveType.Kind.BYTE && (return_param.getAnnotation(GLchar.class) != null || return_param.getAnnotation(GLcharARB.class) != null) )
|
||||
if ( kind == TypeKind.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(MethodDeclaration method) {
|
||||
public static boolean needResultSize(ExecutableElement method) {
|
||||
return getNIOBufferType(getMethodReturnType(method)) != null && method.getAnnotation(AutoSize.class) == null;
|
||||
}
|
||||
|
||||
public static void printExtraCallArguments(PrintWriter writer, MethodDeclaration method, String size_parameter_name) {
|
||||
public static void printExtraCallArguments(PrintWriter writer, ExecutableElement 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(InterfaceDeclaration interface_decl, String opengl_name) {
|
||||
private static String getClassName(TypeElement 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();
|
||||
|
|
@ -312,14 +335,15 @@ 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(MethodDeclaration method) {
|
||||
for ( ParameterDeclaration param : method.getParameters() ) {
|
||||
public static boolean hasMethodBufferObjectParameter(ExecutableElement method) {
|
||||
for ( VariableElement param : method.getParameters() ) {
|
||||
if ( param.getAnnotation(BufferObject.class) != null ) {
|
||||
return true;
|
||||
}
|
||||
|
|
@ -327,71 +351,81 @@ public class Utils {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static String getQualifiedClassName(InterfaceDeclaration interface_decl) {
|
||||
return interface_decl.getPackage().getQualifiedName() + "." + getSimpleClassName(interface_decl);
|
||||
public static String getQualifiedClassName(TypeElement interface_decl) {
|
||||
return interface_decl.getEnclosingElement().asType().toString() + "." + getSimpleClassName(interface_decl);
|
||||
}
|
||||
|
||||
public static String getSimpleClassName(InterfaceDeclaration interface_decl) {
|
||||
return getClassName(interface_decl, interface_decl.getSimpleName());
|
||||
public static String getSimpleClassName(TypeElement interface_decl) {
|
||||
return getClassName(interface_decl, interface_decl.getSimpleName().toString());
|
||||
}
|
||||
|
||||
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(MethodDeclaration method, boolean generate_error_checks, boolean context_specific) {
|
||||
public static String getSimpleNativeMethodName(ExecutableElement 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() : alt_annotation.value();
|
||||
if ( isMethodIndirect(generate_error_checks, context_specific, method) )
|
||||
method_name = alt_annotation == null || alt_annotation.nativeAlt() ? method.getSimpleName().toString() : alt_annotation.value();
|
||||
if ( isMethodIndirect(generate_error_checks, context_specific, method) ) {
|
||||
method_name = OVERLOADED_METHOD_PREFIX + method_name;
|
||||
}
|
||||
return method_name;
|
||||
}
|
||||
|
||||
static boolean isReturnParameter(MethodDeclaration method, ParameterDeclaration param) {
|
||||
static boolean isReturnParameter(ExecutableElement method, VariableElement param) {
|
||||
GLreturn string_annotation = method.getAnnotation(GLreturn.class);
|
||||
if ( string_annotation == null || !string_annotation.value().equals(param.getSimpleName()) )
|
||||
if ( string_annotation == null || !string_annotation.value().equals(param.getSimpleName().toString()) ) {
|
||||
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.getType()).equals(ByteBuffer.class) && string_annotation.maxLength().length() == 0 )
|
||||
if ( param.getAnnotation(GLchar.class) != null && Utils.getJavaType(param.asType()).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(MethodDeclaration method, ParameterDeclaration param) {
|
||||
static String getStringOffset(ExecutableElement method, VariableElement param) {
|
||||
String offset = null;
|
||||
for ( ParameterDeclaration p : method.getParameters() ) {
|
||||
if ( param != null && p.getSimpleName().equals(param.getSimpleName()) )
|
||||
for ( VariableElement 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.getType());
|
||||
final Class type = Utils.getJavaType(p.asType());
|
||||
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";
|
||||
}
|
||||
|
||||
|
|
@ -399,7 +433,7 @@ public class Utils {
|
|||
return offset;
|
||||
}
|
||||
|
||||
static void printGLReturnPre(PrintWriter writer, MethodDeclaration method, GLreturn return_annotation, TypeMap type_map) {
|
||||
static void printGLReturnPre(PrintWriter writer, ExecutableElement method, GLreturn return_annotation, TypeMap type_map) {
|
||||
final String return_type = getMethodReturnType(method, return_annotation, true);
|
||||
|
||||
if ( "String".equals(return_type) ) {
|
||||
|
|
@ -408,20 +442,22 @@ 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(");");
|
||||
}
|
||||
|
||||
|
|
@ -429,30 +465,42 @@ 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, MethodDeclaration method, GLreturn return_annotation, TypeMap type_map) {
|
||||
static void printGLReturnPost(PrintWriter writer, ExecutableElement 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,74 +44,79 @@ package org.lwjgl.util.generator.openal;
|
|||
import org.lwjgl.util.generator.Signedness;
|
||||
import org.lwjgl.util.generator.TypeMap;
|
||||
|
||||
import com.sun.mirror.declaration.*;
|
||||
import com.sun.mirror.type.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.io.PrintWriter;
|
||||
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, PrimitiveType.Kind> native_types_to_primitive;
|
||||
private static final Map<Class, TypeKind> native_types_to_primitive;
|
||||
|
||||
static {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
public PrimitiveType.Kind getPrimitiveTypeFromNativeType(Class native_type) {
|
||||
PrimitiveType.Kind kind = native_types_to_primitive.get(native_type);
|
||||
if (kind == null)
|
||||
@Override
|
||||
public TypeKind getPrimitiveTypeFromNativeType(Class native_type) {
|
||||
TypeKind 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");
|
||||
}
|
||||
|
||||
public Class getNativeTypeFromPrimitiveType(PrimitiveType.Kind kind) {
|
||||
@Override
|
||||
public Class getNativeTypeFromPrimitiveType(TypeKind kind) {
|
||||
Class type;
|
||||
switch (kind) {
|
||||
switch ( kind ) {
|
||||
case INT:
|
||||
type = ALint.class;
|
||||
break;
|
||||
|
|
@ -137,109 +142,124 @@ 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 "";
|
||||
}
|
||||
|
||||
public void printErrorCheckMethod(final PrintWriter writer, final MethodDeclaration method, final String tabs) {
|
||||
@Override
|
||||
public void printErrorCheckMethod(final PrintWriter writer, final ExecutableElement 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\"");
|
||||
}
|
||||
|
||||
public Class<? extends Annotation> getStringElementType() {
|
||||
@Override
|
||||
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,18 +29,16 @@
|
|||
* 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 com.sun.mirror.declaration.InterfaceDeclaration;
|
||||
import com.sun.mirror.declaration.MethodDeclaration;
|
||||
import com.sun.mirror.declaration.TypeDeclaration;
|
||||
import java.util.Set;
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
|
||||
/**
|
||||
* CLCapabilities generator.
|
||||
|
|
@ -50,80 +48,94 @@ import com.sun.mirror.declaration.TypeDeclaration;
|
|||
public class CLCapabilitiesGenerator {
|
||||
|
||||
static void generateClassPrologue(final PrintWriter writer) {
|
||||
writer.println("public final class " + CLGeneratorProcessorFactory.CLCAPS_CLASS_NAME + " {");
|
||||
writer.println("public final class " + CLGeneratorProcessor.CLCAPS_CLASS_NAME + " {");
|
||||
writer.println();
|
||||
}
|
||||
|
||||
static void generateSymbolAddresses(final PrintWriter writer, final InterfaceDeclaration d) {
|
||||
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());
|
||||
}
|
||||
final Alias alias_annotation = d.getAnnotation(Alias.class);
|
||||
final boolean aliased = alias_annotation != null && alias_annotation.postfix().length() > 0;
|
||||
|
||||
boolean foundNative = false;
|
||||
for ( final MethodDeclaration method : d.getMethods() ) {
|
||||
if ( method.getAnnotation(Alternate.class) != null || method.getAnnotation(Reuse.class) != null )
|
||||
for ( final ExecutableElement method : Utils.getMethods(d) ) {
|
||||
if ( method.getAnnotation(Alternate.class) != null || method.getAnnotation(Reuse.class) != null ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( !foundNative ) {
|
||||
//writer.println("\t// " + d.getSimpleName());
|
||||
writer.println("\tstatic final boolean " + CLGeneratorProcessorFactory.getExtensionName(d.getSimpleName()) + ";");
|
||||
writer.println("\tstatic final boolean " + CLGeneratorProcessor.getExtensionName(d.getSimpleName().toString() + ";"));
|
||||
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(final PrintWriter writer, final Collection<TypeDeclaration> interface_decls) {
|
||||
writer.println("\tprivate " + CLGeneratorProcessorFactory.CLCAPS_CLASS_NAME + "() {}");
|
||||
static void generateConstructor(ProcessingEnvironment env, final PrintWriter writer, final Set<? extends TypeElement> interface_decls) {
|
||||
writer.println("\tprivate " + CLGeneratorProcessor.CLCAPS_CLASS_NAME + "() {}");
|
||||
writer.println();
|
||||
writer.println("\tstatic {");
|
||||
|
||||
for ( final TypeDeclaration d : interface_decls ) {
|
||||
if ( d.getMethods().isEmpty() )
|
||||
continue;
|
||||
for ( final TypeElement d : interface_decls ) {
|
||||
if ( d.getKind().isInterface() ) {
|
||||
if ( Utils.getMethods(d).isEmpty() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//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\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}\n");
|
||||
}
|
||||
|
||||
static void generateExtensionChecks(final PrintWriter writer, final InterfaceDeclaration d) {
|
||||
Iterator<? extends MethodDeclaration> methods = d.getMethods().iterator();
|
||||
if ( !methods.hasNext() )
|
||||
static void generateExtensionChecks(ProcessingEnvironment env, final PrintWriter writer, TypeElement d) {
|
||||
Iterator<? extends ExecutableElement> methods = Utils.getMethods(d).iterator();
|
||||
if ( !methods.hasNext() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
writer.println("\tprivate static boolean " + getExtensionSupportedName(d.getSimpleName()) + "() {");
|
||||
writer.println("\tprivate static boolean " + getExtensionSupportedName(d.getSimpleName().toString()) + "() {");
|
||||
writer.println("\t\treturn ");
|
||||
|
||||
boolean first = true;
|
||||
while ( methods.hasNext() ) {
|
||||
MethodDeclaration method = methods.next();
|
||||
if ( method.getAnnotation(Alternate.class) != null )
|
||||
ExecutableElement 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}");
|
||||
|
|
@ -135,25 +147,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");
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,152 @@
|
|||
/*
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,181 +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.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,14 +33,15 @@
|
|||
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.Collection;
|
||||
|
||||
import com.sun.mirror.declaration.InterfaceDeclaration;
|
||||
import com.sun.mirror.declaration.TypeDeclaration;
|
||||
import java.util.Set;
|
||||
import javax.annotation.processing.ProcessingEnvironment;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
|
||||
/**
|
||||
* CL platform/device capabilities generator.
|
||||
|
|
@ -67,18 +68,18 @@ public class CLPDCapabilitiesGenerator {
|
|||
writer.println();
|
||||
}
|
||||
|
||||
static void generateExtensions(final PrintWriter writer, final InterfaceDeclaration d) {
|
||||
static void generateExtensions(final PrintWriter writer, final TypeElement d) {
|
||||
writer.print("\t");
|
||||
|
||||
if ( d.getAnnotation(Private.class) == null )
|
||||
writer.print("public ");
|
||||
|
||||
writer.println("final boolean " + CLGeneratorProcessorFactory.getExtensionName(d.getSimpleName()) + ";");
|
||||
writer.println("final boolean " + CLGeneratorProcessor.getExtensionName(d.getSimpleName().toString()) + ";");
|
||||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
writer.println("\tpublic " + capsName + "(final " + objectType.getSimpleName() + ' ' + objectName + ") {");
|
||||
|
||||
writer.println("\t\tfinal String extensionList = " + objectName + ".getInfoString(CL10.CL_" + objectName.toUpperCase() + "_EXTENSIONS);\n" +
|
||||
|
|
@ -102,14 +103,19 @@ public class CLPDCapabilitiesGenerator {
|
|||
|
||||
writer.println("\t\tfinal Set<String> extensions = APIUtil.getExtensions(extensionList);");
|
||||
|
||||
for ( final TypeDeclaration t : templates ) {
|
||||
for ( final TypeElement t : templates ) {
|
||||
if ( t.getAnnotation(capsType) == null )
|
||||
continue;
|
||||
|
||||
final String extName = CLGeneratorProcessorFactory.getExtensionName(t.getSimpleName());
|
||||
final String extName = CLGeneratorProcessor.getExtensionName(t.getSimpleName().toString());
|
||||
|
||||
writer.print("\t\t" + extName + " = extensions.contains(\"" + extName.toLowerCase() + "\")");
|
||||
if ( !t.getMethods().isEmpty() )
|
||||
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(" && CLCapabilities." + extName);
|
||||
writer.println(";");
|
||||
}
|
||||
|
|
@ -127,18 +133,18 @@ public class CLPDCapabilitiesGenerator {
|
|||
writer.println("\t}\n");
|
||||
}
|
||||
|
||||
public static void generateToString(final PrintWriter writer, final Collection<TypeDeclaration> templates, final Class<? extends Annotation> capsType) {
|
||||
public static void generateToString(final PrintWriter writer, final Set<? extends TypeElement> 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 TypeDeclaration t : templates ) {
|
||||
for ( final TypeElement t : templates ) {
|
||||
if ( t.getAnnotation(capsType) == null )
|
||||
continue;
|
||||
|
||||
writer.println("\t\tif ( " + CLGeneratorProcessorFactory.getExtensionName(t.getSimpleName()) + " ) buf.append(\"" + CLGeneratorProcessorFactory.getExtensionName(t.getSimpleName()).toLowerCase() + " \");");
|
||||
writer.println("\t\tif ( " + CLGeneratorProcessor.getExtensionName(t.getSimpleName().toString()) + " ) buf.append(\"" + CLGeneratorProcessor.getExtensionName(t.getSimpleName().toString()).toLowerCase() + " \");");
|
||||
}
|
||||
|
||||
writer.println("\n\t\treturn buf.toString();");
|
||||
|
|
|
|||
|
|
@ -48,52 +48,56 @@ import java.lang.annotation.Annotation;
|
|||
import java.nio.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.sun.mirror.declaration.AnnotationMirror;
|
||||
import com.sun.mirror.declaration.MethodDeclaration;
|
||||
import com.sun.mirror.declaration.ParameterDeclaration;
|
||||
import com.sun.mirror.type.PrimitiveType;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.VariableElement;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
|
||||
public class CLTypeMap implements TypeMap {
|
||||
|
||||
private static final Map<Class, PrimitiveType.Kind> native_types_to_primitive;
|
||||
private static final Map<Class, TypeKind> native_types_to_primitive;
|
||||
|
||||
static {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
public PrimitiveType.Kind getPrimitiveTypeFromNativeType(Class native_type) {
|
||||
PrimitiveType.Kind kind = native_types_to_primitive.get(native_type);
|
||||
@Override
|
||||
public TypeKind getPrimitiveTypeFromNativeType(Class native_type) {
|
||||
TypeKind 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 "";
|
||||
}
|
||||
|
||||
public void printErrorCheckMethod(final PrintWriter writer, final MethodDeclaration method, final String tabs) {
|
||||
@Override
|
||||
public void printErrorCheckMethod(final PrintWriter writer, final ExecutableElement 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()));");
|
||||
|
|
@ -103,8 +107,8 @@ public class CLTypeMap implements TypeMap {
|
|||
writer.println(tabs + "Util.checkCLError(__result);");
|
||||
else {
|
||||
boolean hasErrCodeParam = false;
|
||||
for ( final ParameterDeclaration param : method.getParameters() ) {
|
||||
if ( "errcode_ret".equals(param.getSimpleName()) && Utils.getJavaType(param.getType()) == IntBuffer.class ) {
|
||||
for ( final VariableElement param : method.getParameters() ) {
|
||||
if ( "errcode_ret".equals(param.getSimpleName().toString()) && Utils.getJavaType(param.asType()) == IntBuffer.class ) {
|
||||
hasErrCodeParam = true;
|
||||
break;
|
||||
}
|
||||
|
|
@ -115,10 +119,12 @@ 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;
|
||||
|
|
@ -128,6 +134,7 @@ 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";
|
||||
|
|
@ -143,7 +150,8 @@ public class CLTypeMap implements TypeMap {
|
|||
throw new RuntimeException(annotation_type + " is not allowed");
|
||||
}
|
||||
|
||||
public Class getNativeTypeFromPrimitiveType(PrimitiveType.Kind kind) {
|
||||
@Override
|
||||
public Class getNativeTypeFromPrimitiveType(TypeKind kind) {
|
||||
Class type;
|
||||
switch ( kind ) {
|
||||
case INT:
|
||||
|
|
@ -173,18 +181,22 @@ 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;
|
||||
}
|
||||
|
|
@ -229,18 +241,22 @@ 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) )
|
||||
|
|
@ -260,10 +276,12 @@ 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,11 +35,10 @@ import org.lwjgl.util.generator.NativeType;
|
|||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import com.sun.mirror.type.PrimitiveType;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
|
||||
@NativeType
|
||||
@Target({ ElementType.PARAMETER, ElementType.METHOD })
|
||||
public @interface cl_void {
|
||||
PrimitiveType.Kind value() default PrimitiveType.Kind.BYTE;
|
||||
TypeKind value() default TypeKind.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 com.sun.mirror.declaration.InterfaceDeclaration;
|
||||
import com.sun.mirror.declaration.MethodDeclaration;
|
||||
import com.sun.mirror.type.InterfaceType;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Generator visitor for the context capabilities generator tool
|
||||
|
|
@ -53,13 +53,13 @@ import com.sun.mirror.type.InterfaceType;
|
|||
*/
|
||||
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, InterfaceDeclaration d) {
|
||||
Collection<InterfaceType> super_interfaces = d.getSuperinterfaces();
|
||||
public static void generateSuperClassAdds(PrintWriter writer, TypeElement d, ProcessingEnvironment env) {
|
||||
List<? extends TypeMirror> super_interfaces = d.getInterfaces();
|
||||
if ( super_interfaces.size() > 1 )
|
||||
throw new RuntimeException(d + " extends more than one other interface");
|
||||
if ( super_interfaces.size() == 1 ) {
|
||||
InterfaceType super_interface = super_interfaces.iterator().next();
|
||||
TypeMirror super_interface = super_interfaces.iterator().next();
|
||||
writer.print("\t\tif (" + CACHED_EXTS_VAR_NAME + ".contains(\"");
|
||||
writer.println(translateFieldName(d.getSimpleName()) + "\"))");
|
||||
writer.println(translateFieldName(d.getSimpleName().toString()) + "\"))");
|
||||
writer.print("\t\t\t");
|
||||
generateAddExtension(writer, super_interface.getDeclaration());
|
||||
generateAddExtension(writer, env.getElementUtils().getTypeElement(super_interface.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateInitializer(PrintWriter writer, InterfaceDeclaration d) {
|
||||
String translated_field_name = translateFieldName(d.getSimpleName());
|
||||
public static void generateInitializer(PrintWriter writer, TypeElement d, ProcessingEnvironment env) {
|
||||
String translated_field_name = translateFieldName(d.getSimpleName().toString());
|
||||
writer.print("\t\tthis." + translated_field_name + " = ");
|
||||
writer.print(CACHED_EXTS_VAR_NAME + ".contains(\"");
|
||||
writer.print(translated_field_name + "\")");
|
||||
Collection<InterfaceType> super_interfaces = d.getSuperinterfaces();
|
||||
List<? extends TypeMirror> super_interfaces = d.getInterfaces();
|
||||
if ( super_interfaces.size() > 1 )
|
||||
throw new RuntimeException(d + " extends more than one other interface");
|
||||
if ( super_interfaces.size() == 1 ) {
|
||||
InterfaceType super_interface = super_interfaces.iterator().next();
|
||||
TypeMirror super_interface = super_interfaces.iterator().next();
|
||||
writer.println();
|
||||
writer.print("\t\t\t&& " + CACHED_EXTS_VAR_NAME + ".contains(\"");
|
||||
writer.print(translateFieldName(super_interface.getDeclaration().getSimpleName()) + "\")");
|
||||
writer.print(translateFieldName(env.getElementUtils().getTypeElement(super_interface.toString()).getSimpleName().toString()) + "\")");
|
||||
}
|
||||
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(PrintWriter writer, InterfaceDeclaration d) {
|
||||
if ( d.getMethods().size() > 0 ) {
|
||||
public static void generateUnloadStubs(ProcessingEnvironment env, PrintWriter writer, TypeElement d) {
|
||||
if ( Utils.getMethods(d).size() > 0 ) {
|
||||
writer.print("\t\tGLContext.resetNativeStubs(" + Utils.getSimpleClassName(d));
|
||||
writer.println(".class);");
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateInitStubs(PrintWriter writer, InterfaceDeclaration d, boolean context_specific) {
|
||||
if ( d.getMethods().size() > 0 ) {
|
||||
public static void generateInitStubs(ProcessingEnvironment env, PrintWriter writer, TypeElement d, boolean context_specific) {
|
||||
if ( Utils.getMethods(d).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()) + "\");");
|
||||
writer.println("\t\t" + CACHED_EXTS_VAR_NAME + ".add(\"" + translateFieldName(d.getSimpleName().toString()) + "\");");
|
||||
writer.print("\t\tif (");
|
||||
if ( alias_annotation != null )
|
||||
writer.print("(");
|
||||
writer.print(CACHED_EXTS_VAR_NAME + ".contains(\"");
|
||||
writer.print(translateFieldName(d.getSimpleName()) + "\")");
|
||||
writer.print(translateFieldName(d.getSimpleName().toString()) + "\")");
|
||||
if ( alias_annotation != null ) {
|
||||
writer.print(" || " + CACHED_EXTS_VAR_NAME + ".contains(\"");
|
||||
writer.print(translateFieldName(alias_annotation.value()) + "\"))");
|
||||
}
|
||||
writer.print(" && !" + getAddressesInitializerName(d.getSimpleName()) + "(");
|
||||
writer.print(" && !" + getAddressesInitializerName(d.getSimpleName().toString()) + "(");
|
||||
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()) + "\");");
|
||||
writer.println(translateFieldName(d.getSimpleName().toString()) + "\");");
|
||||
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()) + "\");");
|
||||
writer.println(".class, " + CACHED_EXTS_VAR_NAME + ", \"" + translateFieldName(d.getSimpleName().toString()) + "\");");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateAddExtension(PrintWriter writer, InterfaceDeclaration d) {
|
||||
private static void generateAddExtension(PrintWriter writer, TypeElement d) {
|
||||
writer.print(CACHED_EXTS_VAR_NAME + ".add(\"");
|
||||
writer.println(translateFieldName(d.getSimpleName()) + "\");");
|
||||
writer.println(translateFieldName(d.getSimpleName().toString()) + "\");");
|
||||
}
|
||||
|
||||
public static void generateAddressesInitializers(PrintWriter writer, InterfaceDeclaration d) {
|
||||
Iterator<? extends MethodDeclaration> methods = d.getMethods().iterator();
|
||||
public static void generateAddressesInitializers(ProcessingEnvironment env, PrintWriter writer, TypeElement d) {
|
||||
Iterator<? extends ExecutableElement> methods = Utils.getMethods(d).iterator();
|
||||
if ( !methods.hasNext() )
|
||||
return;
|
||||
|
||||
writer.print("\tprivate boolean " + getAddressesInitializerName(d.getSimpleName()) + "(");
|
||||
writer.print("\tprivate boolean " + getAddressesInitializerName(d.getSimpleName().toString()) + "(");
|
||||
|
||||
boolean optional;
|
||||
boolean deprecated = d.getAnnotation(DeprecatedGL.class) != null;
|
||||
|
|
@ -242,7 +242,7 @@ public class GLCapabilitiesGenerator {
|
|||
|
||||
boolean first = true;
|
||||
while ( methods.hasNext() ) {
|
||||
MethodDeclaration method = methods.next();
|
||||
ExecutableElement method = methods.next();
|
||||
if ( method.getAnnotation(Alternate.class) != null )
|
||||
continue;
|
||||
|
||||
|
|
@ -309,9 +309,9 @@ public class GLCapabilitiesGenerator {
|
|||
writer.println();
|
||||
}
|
||||
|
||||
public static void generateSymbolAddresses(PrintWriter writer, InterfaceDeclaration d) {
|
||||
public static void generateSymbolAddresses(ProcessingEnvironment env, PrintWriter writer, TypeElement d) {
|
||||
boolean first = true;
|
||||
for ( final MethodDeclaration method : d.getMethods() ) {
|
||||
for ( final ExecutableElement method : Utils.getMethods(d) ) {
|
||||
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, InterfaceDeclaration d) {
|
||||
writer.println("\tpublic final boolean " + translateFieldName(d.getSimpleName()) + ";");
|
||||
public static void generateField(PrintWriter writer, TypeElement d) {
|
||||
writer.println("\tpublic final boolean " + translateFieldName(d.getSimpleName().toString()) + ";");
|
||||
}
|
||||
}
|
||||
|
|
@ -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 com.sun.mirror.declaration.InterfaceDeclaration;
|
||||
import com.sun.mirror.declaration.MethodDeclaration;
|
||||
import com.sun.mirror.type.InterfaceType;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Generator visitor for the context capabilities generator tool
|
||||
|
|
@ -53,12 +53,12 @@ import com.sun.mirror.type.InterfaceType;
|
|||
*/
|
||||
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, InterfaceDeclaration d) {
|
||||
Collection<InterfaceType> super_interfaces = d.getSuperinterfaces();
|
||||
public static void generateSuperClassAdds(PrintWriter writer, TypeElement d, ProcessingEnvironment env) {
|
||||
List<? extends TypeMirror> super_interfaces = d.getInterfaces();
|
||||
if ( super_interfaces.size() > 1 )
|
||||
throw new RuntimeException(d + " extends more than one other interface");
|
||||
if ( super_interfaces.size() == 1 ) {
|
||||
InterfaceType super_interface = super_interfaces.iterator().next();
|
||||
TypeMirror super_interface = super_interfaces.iterator().next();
|
||||
writer.print("\t\tif (" + CACHED_EXTS_VAR_NAME + ".contains(\"");
|
||||
writer.println(translateFieldName(d.getSimpleName()) + "\"))");
|
||||
writer.println(translateFieldName(d.getSimpleName().toString() + "\"))"));
|
||||
writer.print("\t\t\t");
|
||||
generateAddExtension(writer, super_interface.getDeclaration());
|
||||
generateAddExtension(writer, env.getElementUtils().getTypeElement(super_interface.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateInitializer(PrintWriter writer, InterfaceDeclaration d) {
|
||||
String translated_field_name = translateFieldName(d.getSimpleName());
|
||||
public static void generateInitializer(PrintWriter writer, TypeElement d, ProcessingEnvironment env) {
|
||||
String translated_field_name = translateFieldName(d.getSimpleName().toString());
|
||||
writer.print("\t\tthis." + translated_field_name + " = ");
|
||||
writer.print(CACHED_EXTS_VAR_NAME + ".contains(\"");
|
||||
writer.print(translated_field_name + "\")");
|
||||
Collection<InterfaceType> super_interfaces = d.getSuperinterfaces();
|
||||
List<? extends TypeMirror> super_interfaces = d.getInterfaces();
|
||||
if ( super_interfaces.size() > 1 )
|
||||
throw new RuntimeException(d + " extends more than one other interface");
|
||||
if ( super_interfaces.size() == 1 ) {
|
||||
InterfaceType super_interface = super_interfaces.iterator().next();
|
||||
TypeMirror super_interface = super_interfaces.iterator().next();
|
||||
writer.println();
|
||||
writer.print("\t\t\t&& " + CACHED_EXTS_VAR_NAME + ".contains(\"");
|
||||
writer.print(translateFieldName(super_interface.getDeclaration().getSimpleName()) + "\")");
|
||||
writer.print(translateFieldName(env.getElementUtils().getTypeElement(super_interface.toString()).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(PrintWriter writer, InterfaceDeclaration d) {
|
||||
public static void generateUnloadStubs(ProcessingEnvironment env, PrintWriter writer, TypeElement d) {
|
||||
// TODO: Remove GLES
|
||||
if ( d.getMethods().size() > 0 && !d.getSimpleName().startsWith("GLES") ) {
|
||||
if ( Utils.getMethods(d).size() > 0 && !d.getSimpleName().toString().startsWith("GLES") ) {
|
||||
writer.print("\t\tGLContext.resetNativeStubs(" + Utils.getSimpleClassName(d));
|
||||
writer.println(".class);");
|
||||
}
|
||||
}
|
||||
|
||||
public static void generateInitStubs(PrintWriter writer, InterfaceDeclaration d, boolean context_specific) {
|
||||
if ( d.getMethods().size() > 0 ) {
|
||||
public static void generateInitStubs(ProcessingEnvironment env, PrintWriter writer, TypeElement d, boolean context_specific) {
|
||||
if ( Utils.getMethods(d).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()) + "\");");
|
||||
writer.println("\t\t" + CACHED_EXTS_VAR_NAME + ".add(\"" + translateFieldName(d.getSimpleName().toString()) + "\");");
|
||||
writer.print("\t\tif (");
|
||||
if ( alias_annotation != null )
|
||||
writer.print("(");
|
||||
writer.print(CACHED_EXTS_VAR_NAME + ".contains(\"");
|
||||
writer.print(translateFieldName(d.getSimpleName()) + "\")");
|
||||
writer.print(translateFieldName(d.getSimpleName().toString()) + "\")");
|
||||
if ( alias_annotation != null ) {
|
||||
writer.print(" || " + CACHED_EXTS_VAR_NAME + ".contains(\"");
|
||||
writer.print(translateFieldName(alias_annotation.value()) + "\"))");
|
||||
}
|
||||
writer.print(" && !" + getAddressesInitializerName(d.getSimpleName()) + "(");
|
||||
writer.print(" && !" + getAddressesInitializerName(d.getSimpleName().toString()) + "(");
|
||||
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()) + "\");");
|
||||
writer.println(translateFieldName(d.getSimpleName().toString()) + "\");");
|
||||
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()) + "\");");
|
||||
writer.println(".class, " + CACHED_EXTS_VAR_NAME + ", \"" + translateFieldName(d.getSimpleName().toString()) + "\");");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void generateAddExtension(PrintWriter writer, InterfaceDeclaration d) {
|
||||
private static void generateAddExtension(PrintWriter writer, TypeElement d) {
|
||||
writer.print(CACHED_EXTS_VAR_NAME + ".add(\"");
|
||||
writer.println(translateFieldName(d.getSimpleName()) + "\");");
|
||||
writer.println(translateFieldName(d.getSimpleName().toString()) + "\");");
|
||||
}
|
||||
|
||||
public static void generateAddressesInitializers(PrintWriter writer, InterfaceDeclaration d) {
|
||||
Iterator<? extends MethodDeclaration> methods = d.getMethods().iterator();
|
||||
public static void generateAddressesInitializers(ProcessingEnvironment env, PrintWriter writer, TypeElement d) {
|
||||
Iterator<? extends ExecutableElement> methods = Utils.getMethods(d).iterator();
|
||||
if ( !methods.hasNext() )
|
||||
return;
|
||||
|
||||
writer.print("\tprivate boolean " + getAddressesInitializerName(d.getSimpleName()) + "(");
|
||||
writer.print("\tprivate boolean " + getAddressesInitializerName(d.getSimpleName().toString()) + "(");
|
||||
|
||||
boolean optional;
|
||||
Dependent dependent = d.getAnnotation(Dependent.class);
|
||||
|
|
@ -223,7 +223,7 @@ public class GLESCapabilitiesGenerator {
|
|||
|
||||
boolean first = true;
|
||||
while ( methods.hasNext() ) {
|
||||
MethodDeclaration method = methods.next();
|
||||
ExecutableElement method = methods.next();
|
||||
if ( method.getAnnotation(Alternate.class) != null )
|
||||
continue;
|
||||
|
||||
|
|
@ -287,9 +287,9 @@ public class GLESCapabilitiesGenerator {
|
|||
writer.println();
|
||||
}
|
||||
|
||||
public static void generateSymbolAddresses(PrintWriter writer, InterfaceDeclaration d) {
|
||||
public static void generateSymbolAddresses(ProcessingEnvironment env, PrintWriter writer, TypeElement d) {
|
||||
boolean first = true;
|
||||
for ( final MethodDeclaration method : d.getMethods() ) {
|
||||
for ( final ExecutableElement method : Utils.getMethods(d) ) {
|
||||
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, InterfaceDeclaration d) {
|
||||
writer.println("\tpublic final boolean " + translateFieldName(d.getSimpleName()) + ";");
|
||||
public static void generateField(PrintWriter writer, TypeElement d) {
|
||||
writer.println("\tpublic final boolean " + translateFieldName(d.getSimpleName().toString()) + ";");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,161 @@
|
|||
/*
|
||||
* 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,184 +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.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,67 +51,73 @@ import java.lang.annotation.Annotation;
|
|||
import java.nio.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.sun.mirror.declaration.AnnotationMirror;
|
||||
import com.sun.mirror.declaration.MethodDeclaration;
|
||||
import com.sun.mirror.type.PrimitiveType;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
|
||||
public class GLESTypeMap implements TypeMap {
|
||||
|
||||
private static final Map<Class<? extends Annotation>, PrimitiveType.Kind> native_types_to_primitive;
|
||||
private static final Map<Class<? extends Annotation>, TypeKind> native_types_to_primitive;
|
||||
|
||||
static {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
public PrimitiveType.Kind getPrimitiveTypeFromNativeType(Class<? extends Annotation> native_type) {
|
||||
PrimitiveType.Kind kind = native_types_to_primitive.get(native_type);
|
||||
@Override
|
||||
public TypeKind getPrimitiveTypeFromNativeType(Class<? extends Annotation> native_type) {
|
||||
TypeKind 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 "";
|
||||
}
|
||||
|
||||
public void printErrorCheckMethod(final PrintWriter writer, final MethodDeclaration method, final String tabs) {
|
||||
@Override
|
||||
public void printErrorCheckMethod(final PrintWriter writer, final ExecutableElement 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;
|
||||
|
|
@ -133,6 +139,7 @@ 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";
|
||||
|
|
@ -154,7 +161,8 @@ public class GLESTypeMap implements TypeMap {
|
|||
throw new RuntimeException(annotation_type + " is not allowed");
|
||||
}
|
||||
|
||||
public Class<? extends Annotation> getNativeTypeFromPrimitiveType(PrimitiveType.Kind kind) {
|
||||
@Override
|
||||
public Class<? extends Annotation> getNativeTypeFromPrimitiveType(TypeKind kind) {
|
||||
Class<? extends Annotation> type;
|
||||
switch ( kind ) {
|
||||
case INT:
|
||||
|
|
@ -181,18 +189,22 @@ 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;
|
||||
}
|
||||
|
|
@ -231,18 +243,22 @@ 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) )
|
||||
|
|
@ -260,6 +276,7 @@ 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;
|
||||
|
|
@ -279,6 +296,7 @@ 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) )
|
||||
|
|
|
|||
|
|
@ -0,0 +1,160 @@
|
|||
/*
|
||||
* 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();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,189 +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 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,186 @@
|
|||
/*
|
||||
* 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,218 +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 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,7 +29,6 @@
|
|||
* 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;
|
||||
|
||||
/**
|
||||
|
|
@ -37,10 +36,9 @@ 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;
|
||||
|
|
@ -52,120 +50,131 @@ import java.lang.annotation.Annotation;
|
|||
import java.nio.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.sun.mirror.declaration.AnnotationMirror;
|
||||
import com.sun.mirror.declaration.MethodDeclaration;
|
||||
import com.sun.mirror.type.PrimitiveType;
|
||||
import javax.lang.model.element.AnnotationMirror;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
|
||||
public class GLTypeMap implements TypeMap {
|
||||
|
||||
private static final Map<Class, PrimitiveType.Kind> native_types_to_primitive;
|
||||
private static final Map<Class, TypeKind> native_types_to_primitive;
|
||||
|
||||
static {
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
public PrimitiveType.Kind getPrimitiveTypeFromNativeType(Class native_type) {
|
||||
PrimitiveType.Kind kind = native_types_to_primitive.get(native_type);
|
||||
if ( kind == null )
|
||||
@Override
|
||||
public TypeKind getPrimitiveTypeFromNativeType(Class native_type) {
|
||||
TypeKind 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";
|
||||
}
|
||||
|
||||
public void printErrorCheckMethod(final PrintWriter writer, final MethodDeclaration method, final String tabs) {
|
||||
@Override
|
||||
public void printErrorCheckMethod(final PrintWriter writer, final ExecutableElement 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");
|
||||
}
|
||||
}
|
||||
|
||||
public Class getNativeTypeFromPrimitiveType(PrimitiveType.Kind kind) {
|
||||
@Override
|
||||
public Class getNativeTypeFromPrimitiveType(TypeKind kind) {
|
||||
Class type;
|
||||
switch ( kind ) {
|
||||
case INT:
|
||||
|
|
@ -195,137 +204,153 @@ 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,13 +40,12 @@ package org.lwjgl.util.generator.opengl;
|
|||
|
||||
import org.lwjgl.util.generator.NativeType;
|
||||
|
||||
import java.lang.annotation.Target;
|
||||
import java.lang.annotation.ElementType;
|
||||
|
||||
import com.sun.mirror.type.PrimitiveType;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.lang.model.type.TypeKind;
|
||||
|
||||
@NativeType
|
||||
@Target({ElementType.PARAMETER, ElementType.METHOD})
|
||||
@Target({ ElementType.PARAMETER, ElementType.METHOD })
|
||||
public @interface GLvoid {
|
||||
PrimitiveType.Kind value() default PrimitiveType.Kind.BYTE;
|
||||
TypeKind value() default TypeKind.BYTE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ public class Project extends Util {
|
|||
* @param src
|
||||
* @param inverse
|
||||
*
|
||||
* @return
|
||||
* @return true if the matrix was succesfully inverted
|
||||
*/
|
||||
private static boolean __gluInvertMatrixf(FloatBuffer src, FloatBuffer inverse) {
|
||||
int i, j, k, swap;
|
||||
|
|
|
|||
|
|
@ -52,14 +52,14 @@ public @interface CacheLinePad {
|
|||
/**
|
||||
* When true, cache-line padding will be inserted before the field.
|
||||
*
|
||||
* @return
|
||||
* @return true if cache-line padding will be inserted before the field
|
||||
*/
|
||||
boolean before() default false;
|
||||
|
||||
/**
|
||||
* When true, cache-line padding will be inserted after the field.
|
||||
*
|
||||
* @return
|
||||
* @return true if cache-line padding will be inserted after the field
|
||||
*/
|
||||
boolean after() default true;
|
||||
|
||||
|
|
|
|||
|
|
@ -52,21 +52,21 @@ public class Vector2f extends Vector implements Serializable, ReadableVector2f,
|
|||
public float x, y;
|
||||
|
||||
/**
|
||||
* Constructor for Vector3f.
|
||||
* Constructor for Vector2f.
|
||||
*/
|
||||
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 APIENTRY debugCallbackKHR(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* message, GLvoid* userParam) {
|
||||
static void EGLAPIENTRY 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)&debugCallbackKHRJ;
|
||||
return (jlong)(intptr_t)&debugCallbackKHR;
|
||||
}
|
||||
|
|
@ -39,11 +39,7 @@
|
|||
*/
|
||||
|
||||
#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,7 +220,11 @@ 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,22 +174,32 @@ 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.
|
||||
XStoreName(disp, window, (const char *)(intptr_t)title);
|
||||
XmbSetWMProperties(disp, window, (const char *)(intptr_t)title, (const char *)(intptr_t)title, NULL, 0, NULL, NULL, NULL);
|
||||
|
||||
// Set the UTF-8 encoded title
|
||||
XChangeProperty(disp, window,
|
||||
XInternAtom(disp, "_NET_WM_NAME", False),
|
||||
XInternAtom(disp, "UTF8_STRING", False),
|
||||
8, PropModeReplace, (const unsigned char *)(intptr_t)title,
|
||||
len);
|
||||
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
|
||||
);
|
||||
}
|
||||
|
||||
static void setClassHint(Display *disp, Window window, jlong wm_name, jlong wm_class) {
|
||||
XClassHint* hint = XAllocClassHint();
|
||||
|
||||
hint->res_name = (const unsigned char *)(intptr_t)wm_name;
|
||||
hint->res_class = (const unsigned char *)(intptr_t)wm_class;
|
||||
hint->res_name = (char *)(intptr_t)wm_name;
|
||||
hint->res_class = (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 = (const unsigned char *)(intptr_t)wm_name;
|
||||
hint->res_class = (const unsigned char *)(intptr_t)wm_class;
|
||||
hint->res_name = (char *)(intptr_t)wm_name;
|
||||
hint->res_class = (char *)(intptr_t)wm_class;
|
||||
|
||||
XSetClassHint(disp, window, hint);
|
||||
|
||||
|
|
|
|||
|
|
@ -50,6 +50,11 @@
|
|||
#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,8 +101,11 @@ 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 {
|
||||
bpp = CGDisplayBitsPerPixel(kCGDirectMainDisplay);
|
||||
throwException(env, "unreachable");
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -118,9 +121,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");
|
||||
|
|
|
|||
12
src/native/macosx/org_lwjgl_MacOSXSysImplementation.m
Normal file
12
src/native/macosx/org_lwjgl_MacOSXSysImplementation.m
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#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);
|
||||
}
|
||||
}
|
||||
|
|
@ -77,10 +77,7 @@ static NSUInteger lastModifierFlags = 0;
|
|||
// Inform the view of its parent window info;
|
||||
[window_info->view setParent:window_info];
|
||||
|
||||
if (window_info->enableHighDPI) {
|
||||
// call method using runtime selector as its a 10.7+ api and allows compiling on older SDK's
|
||||
[window_info->view performSelector:NSSelectorFromString(@"setWantsBestResolutionOpenGLSurface:") withObject:YES];
|
||||
}
|
||||
[window_info->view setWantsBestResolutionOpenGLSurface:NO];
|
||||
|
||||
// set nsapp delegate for catching app quit events
|
||||
[NSApp setDelegate:window_info->view];
|
||||
|
|
@ -261,7 +258,9 @@ static NSUInteger lastModifierFlags = 0;
|
|||
if (context == nil) return;
|
||||
|
||||
if ([context view] != self) {
|
||||
[context setView:self];
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
[context setView:self];
|
||||
});
|
||||
}
|
||||
|
||||
[context makeCurrentContext];
|
||||
|
|
@ -594,7 +593,9 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nResizeWindow(JNIEnv
|
|||
MacOSXWindowInfo *window_info = (MacOSXWindowInfo *)(*env)->GetDirectBufferAddress(env, window_handle);
|
||||
window_info->display_rect = NSMakeRect(x, y, width, height);
|
||||
[window_info->window setFrame:window_info->display_rect display:false];
|
||||
[window_info->view update];
|
||||
dispatch_sync(dispatch_get_main_queue(), ^{
|
||||
[window_info->view update];
|
||||
});
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_MacOSXDisplay_nWasResized(JNIEnv *env, jobject this, jobject window_handle) {
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue