Imported Upstream version 2.5+dfsg
Gabriele Giacone
13 years ago
123 | 123 | <fileset refid="lwjgl.fileset" /> |
124 | 124 | <manifest> |
125 | 125 | <attribute name="Sealed" value="true"/> |
126 | <attribute name="Trusted-Library" value="true"/> | |
127 | 126 | </manifest> |
128 | 127 | </jar> |
129 | 128 | |
132 | 131 | <fileset refid="lwjgl_util_applet.fileset" /> |
133 | 132 | <manifest> |
134 | 133 | <attribute name="Sealed" value="true"/> |
135 | <attribute name="Trusted-Library" value="true"/> | |
136 | 134 | </manifest> |
137 | 135 | </jar> |
138 | 136 | |
252 | 250 | <class name="org.lwjgl.openal.AL" /> |
253 | 251 | <class name="org.lwjgl.opengl.GLContext" /> |
254 | 252 | <class name="org.lwjgl.opengl.Pbuffer" /> |
253 | <class name="org.lwjgl.opengl.AMDDebugOutputCallback" /> | |
255 | 254 | </javah> |
256 | 255 | </target> |
257 | 256 |
11 | 11 | <property name="lwjgl.docs" location="doc" /> |
12 | 12 | <property name="lwjgl.temp" location="temp" /> |
13 | 13 | <property name="lwjgl.res" location="res" /> |
14 | <property name="lwjgl.version" value="2.4.2" /> | |
14 | <property name="lwjgl.version" value="2.5" /> | |
15 | 15 | |
16 | 16 | <property name="opengl-template-pattern" value="org/lwjgl/opengl/GL*.java,org/lwjgl/opengl/ARB*.java,org/lwjgl/opengl/AMD*.java,org/lwjgl/opengl/APPLE*.java,org/lwjgl/opengl/ATI*.java,org/lwjgl/opengl/EXT*.java,org/lwjgl/opengl/NV*.java,org/lwjgl/opengl/NVX*.java,org/lwjgl/opengl/HP*.java,org/lwjgl/opengl/IBM*.java,org/lwjgl/opengl/SUN*.java,org/lwjgl/opengl/SGIS*.java,org/lwjgl/opengl/GREMEDY*.java"/> |
17 | 17 | <!-- ================================================================== --> |
12 | 12 | <javac debug="yes" srcdir="${lwjgl.src}/java/" destdir="${lwjgl.bin}" includes="org/lwjgl/util/generator/**.java" source="1.5" target="1.5" taskname="generator"> |
13 | 13 | <compilerarg value="-Xlint:all"/> |
14 | 14 | </javac> |
15 | <!-- Compile helper classes used by the templates --> | |
15 | 16 | <javac debug="yes" srcdir="${lwjgl.src}/java/" destdir="${lwjgl.bin}" source="1.4" target="1.4" taskname="generator"> |
16 | 17 | <include name="org/lwjgl/opengl/GLSync.java"/> |
18 | <include name="org/lwjgl/opengl/AMDDebugOutputCallback.java"/> | |
17 | 19 | <include name="org/lwjgl/opengl/PointerWrapper.java"/> |
18 | 20 | </javac> |
19 | 21 | </target> |
36 | 38 | <arg value="-d"/> |
37 | 39 | <arg path="${lwjgl.src.native}/generated"/> |
38 | 40 | <arg value="-Atypemap=org.lwjgl.util.generator.ALTypeMap"/> |
39 | <fileset dir="${lwjgl.src.templates}" includes="org/lwjgl/openal/AL10.java, org/lwjgl/openal/AL11.java"/> | |
41 | <fileset dir="${lwjgl.src.templates}" includes="org/lwjgl/openal/AL10.java, org/lwjgl/openal/AL11.java, org/lwjgl/openal/EFX10.java"/> | |
40 | 42 | </apply> |
41 | 43 | </target> |
42 | 44 | |
54 | 56 | <arg path="${lwjgl.src.native}/generated"/> |
55 | 57 | <arg value="-Atypemap=org.lwjgl.util.generator.ALTypeMap"/> |
56 | 58 | <arg value="-Ageneratechecks"/> |
57 | <fileset dir="${lwjgl.src.templates}" includes="org/lwjgl/openal/AL10.java, org/lwjgl/openal/AL11.java"/> | |
59 | <fileset dir="${lwjgl.src.templates}" includes="org/lwjgl/openal/AL10.java, org/lwjgl/openal/AL11.java, org/lwjgl/openal/EFX10.java"/> | |
58 | 60 | </apply> |
59 | 61 | </target> |
60 | 62 |
6 | 6 | </antcall> |
7 | 7 | </target> |
8 | 8 | |
9 | <target name="webstart_demo-release" depends="jars"> | |
9 | <target name="webstart_demo-release"> | |
10 | 10 | <input message="Please type the password for the keystore" addproperty="sign.pwd"/> |
11 | 11 | |
12 | 12 | <antcall target="-webstart_demo"> |
24 | 24 | |
25 | 25 | <!-- unzip common files --> |
26 | 26 | <unzip src="${lwjgl.dist}/lwjgl-${lwjgl.version}.zip" dest="${lwjgl.temp}/jnlp/temp" overwrite="true"/> |
27 | <copy file="${lwjgl.lib}/lwjgl_test.jar" tofile="${lwjgl.temp}/jnlp/temp/lwjgl-${lwjgl.version}/lwjgl_test.jar"/> | |
28 | <copy file="${lwjgl.lib}/lwjgl_util.jar" tofile="${lwjgl.temp}/jnlp/temp/lwjgl-${lwjgl.version}/lwjgl_util.jar"/> | |
27 | 29 | |
28 | 30 | <!-- move files to unified structure --> |
29 | 31 | <move todir="${lwjgl.temp}/jnlp/temp"> |
35 | 37 | <!-- move relevant files to root --> |
36 | 38 | <move todir="${lwjgl.temp}/jnlp/" flatten="true"> |
37 | 39 | <fileset dir="${lwjgl.temp}/jnlp/temp"> |
38 | <include name="**/**.jar"/> | |
40 | <include name="**/jinput.jar"/> | |
41 | <include name="**/lwjgl*.jar"/> | |
39 | 42 | </fileset> |
40 | 43 | </move> |
41 | 44 | |
45 | <!-- update Trusted-Library --> | |
46 | <jar destfile="${lwjgl.temp}/jnlp/lwjgl.jar" update="true"> | |
47 | <manifest> | |
48 | <attribute name="Sealed" value="true"/> | |
49 | <attribute name="Trusted-Library" value="true"/> | |
50 | </manifest> | |
51 | </jar> | |
52 | ||
53 | <jar destfile="${lwjgl.temp}/jnlp/jinput.jar" update="true"> | |
54 | <manifest> | |
55 | <attribute name="Sealed" value="true"/> | |
56 | </manifest> | |
57 | </jar> | |
58 | ||
59 | <jar destfile="${lwjgl.temp}/jnlp/lwjgl_util.jar" update="true"> | |
60 | <manifest> | |
61 | <attribute name="Sealed" value="true"/> | |
62 | </manifest> | |
63 | </jar> | |
64 | ||
42 | 65 | <!-- create native jars --> |
43 | <jar destfile="${lwjgl.temp}/jnlp/native_windows.jar" basedir="${lwjgl.temp}/jnlp/temp/native/windows"/> | |
44 | <jar destfile="${lwjgl.temp}/jnlp/native_linux.jar" basedir="${lwjgl.temp}/jnlp/temp/native/linux"/> | |
45 | <jar destfile="${lwjgl.temp}/jnlp/native_macosx.jar" basedir="${lwjgl.temp}/jnlp/temp/native/macosx"/> | |
46 | <jar destfile="${lwjgl.temp}/jnlp/native_solaris.jar" basedir="${lwjgl.temp}/jnlp/temp/native/solaris"/> | |
66 | <jar destfile="${lwjgl.temp}/jnlp/native_windows.jar" basedir="${lwjgl.temp}/jnlp/temp/native/windows"> | |
67 | <manifest> | |
68 | <attribute name="Sealed" value="true"/> | |
69 | </manifest> | |
70 | </jar> | |
71 | ||
72 | <jar destfile="${lwjgl.temp}/jnlp/native_linux.jar" basedir="${lwjgl.temp}/jnlp/temp/native/linux"> | |
73 | <manifest> | |
74 | <attribute name="Sealed" value="true"/> | |
75 | </manifest> | |
76 | </jar> | |
77 | ||
78 | <jar destfile="${lwjgl.temp}/jnlp/native_macosx.jar" basedir="${lwjgl.temp}/jnlp/temp/native/macosx"> | |
79 | <manifest> | |
80 | <attribute name="Sealed" value="true"/> | |
81 | </manifest> | |
82 | </jar> | |
83 | ||
84 | <jar destfile="${lwjgl.temp}/jnlp/native_solaris.jar" basedir="${lwjgl.temp}/jnlp/temp/native/solaris"> | |
85 | <manifest> | |
86 | <attribute name="Sealed" value="true"/> | |
87 | </manifest> | |
88 | </jar> | |
47 | 89 | |
48 | 90 | <!-- create media jar --> |
49 | <jar destfile="${lwjgl.temp}/jnlp/media.jar" basedir="${lwjgl.res}"/> | |
91 | <jar destfile="${lwjgl.temp}/jnlp/media.jar" basedir="${lwjgl.res}"> | |
92 | <manifest> | |
93 | <attribute name="Sealed" value="true"/> | |
94 | </manifest> | |
95 | </jar> | |
50 | 96 | |
51 | 97 | <!-- sign 'em --> |
52 | 98 | <signjar jar="${lwjgl.temp}/jnlp/lwjgl.jar" alias="${alias}" keystore="${keystore}" storepass="${password}"/> |
56 | 102 | <signjar jar="${lwjgl.temp}/jnlp/native_macosx.jar" alias="${alias}" keystore="${keystore}" storepass="${password}"/> |
57 | 103 | <signjar jar="${lwjgl.temp}/jnlp/native_windows.jar" alias="${alias}" keystore="${keystore}" storepass="${password}"/> |
58 | 104 | <signjar jar="${lwjgl.temp}/jnlp/jinput.jar" alias="${alias}" keystore="${keystore}" storepass="${password}"/> |
105 | <signjar jar="${lwjgl.temp}/jnlp/media.jar" alias="${alias}" keystore="${keystore}" storepass="${password}"/> | |
59 | 106 | </target> |
60 | 107 | </project>⏎ |
0 | <project name="webstart"> | |
1 | <target name="webstart_demo" depends="jars"> | |
2 | <antcall target="-webstart_demo"> | |
3 | <param name="keystore" value="applet/lwjglkeystore"/> | |
4 | <param name="alias" value="lwjgl"/> | |
5 | <param name="password" value="123456"/> | |
6 | </antcall> | |
7 | </target> | |
8 | ||
9 | <target name="webstart_demo-release"> | |
10 | <input message="Please type the password for the keystore" addproperty="sign.pwd"/> | |
11 | ||
12 | <antcall target="-webstart_demo"> | |
13 | <param name="keystore" value="signing/matzon_java_code_signing.keystore"/> | |
14 | <param name="alias" value="oddlabs_java_code_signing"/> | |
15 | <param name="password" value="${sign.pwd}"/> | |
16 | </antcall> | |
17 | </target> | |
18 | ||
19 | <!-- --> | |
20 | <target name="-webstart_demo" description="Using released files, creates the necessary files used for jnlp demos"> | |
21 | ||
22 | <!-- delete existing temp --> | |
23 | <delete dir="${lwjgl.temp}"/> | |
24 | ||
25 | <!-- unzip common files --> | |
26 | <unzip src="${lwjgl.dist}/lwjgl-${lwjgl.version}.zip" dest="${lwjgl.temp}/jnlp/temp" overwrite="true"/> | |
27 | ||
28 | <!-- move files to unified structure --> | |
29 | <move todir="${lwjgl.temp}/jnlp/temp"> | |
30 | <fileset dir="${lwjgl.temp}/jnlp/temp/lwjgl-${lwjgl.version}/"> | |
31 | <include name="**"/> | |
32 | </fileset> | |
33 | </move> | |
34 | ||
35 | <!-- move relevant files to root --> | |
36 | <move todir="${lwjgl.temp}/jnlp/" flatten="true"> | |
37 | <fileset dir="${lwjgl.temp}/jnlp/temp"> | |
38 | <include name="**/**.jar"/> | |
39 | </fileset> | |
40 | </move> | |
41 | ||
42 | <!-- create native jars --> | |
43 | <jar destfile="${lwjgl.temp}/jnlp/native_windows.jar" basedir="${lwjgl.temp}/jnlp/temp/native/windows"/> | |
44 | <jar destfile="${lwjgl.temp}/jnlp/native_linux.jar" basedir="${lwjgl.temp}/jnlp/temp/native/linux"/> | |
45 | <jar destfile="${lwjgl.temp}/jnlp/native_macosx.jar" basedir="${lwjgl.temp}/jnlp/temp/native/macosx"/> | |
46 | <jar destfile="${lwjgl.temp}/jnlp/native_solaris.jar" basedir="${lwjgl.temp}/jnlp/temp/native/solaris"/> | |
47 | ||
48 | <!-- add media and trusted info --> | |
49 | <jar destfile="${lwjgl.temp}/jnlp/lwjgl_test.jar" update="true"> | |
50 | <manifest> | |
51 | <attribute name="Sealed" value="true"/> | |
52 | <attribute name="Trusted-Only" value="true"/> | |
53 | </manifest> | |
54 | </jar> | |
55 | ||
56 | <jar destfile="${lwjgl.temp}/jnlp/lwjgl_util.jar" update="true"> | |
57 | <fileset dir="${lwjgl.res}"/> | |
58 | <manifest> | |
59 | <attribute name="Sealed" value="true"/> | |
60 | <attribute name="Trusted-Library" value="true"/> | |
61 | </manifest> | |
62 | </jar> | |
63 | ||
64 | <jar destfile="${lwjgl.temp}/jnlp/jinput.jar" update="true"> | |
65 | <manifest> | |
66 | <attribute name="Sealed" value="true"/> | |
67 | <attribute name="Trusted-Library" value="true"/> | |
68 | </manifest> | |
69 | </jar> | |
70 | ||
71 | <!-- sign 'em --> | |
72 | <signjar jar="${lwjgl.temp}/jnlp/lwjgl.jar" alias="${alias}" keystore="${keystore}" storepass="${password}"/> | |
73 | <signjar jar="${lwjgl.temp}/jnlp/lwjgl_util.jar" alias="${alias}" keystore="${keystore}" storepass="${password}"/> | |
74 | <signjar jar="${lwjgl.temp}/jnlp/jinput.jar" alias="${alias}" keystore="${keystore}" storepass="${password}"/> | |
75 | ||
76 | <signjar jar="${lwjgl.temp}/jnlp/native_solaris.jar" alias="${alias}" keystore="${keystore}" storepass="${password}"/> | |
77 | <signjar jar="${lwjgl.temp}/jnlp/native_linux.jar" alias="${alias}" keystore="${keystore}" storepass="${password}"/> | |
78 | <signjar jar="${lwjgl.temp}/jnlp/native_macosx.jar" alias="${alias}" keystore="${keystore}" storepass="${password}"/> | |
79 | <signjar jar="${lwjgl.temp}/jnlp/native_windows.jar" alias="${alias}" keystore="${keystore}" storepass="${password}"/> | |
80 | ||
81 | <signjar jar="${lwjgl.temp}/jnlp/lwjgl_test.jar" alias="${alias}" keystore="${keystore}" storepass="${password}"/> | |
82 | ||
83 | </target> | |
84 | </project>⏎ |
47 | 47 | * </p> |
48 | 48 | * @author cix_foo <cix_foo@users.sourceforge.net> |
49 | 49 | * @author elias_naur <elias_naur@users.sourceforge.net> |
50 | * @version $Revision: 3279 $ | |
51 | * $Id: BufferChecks.java 3279 2010-03-11 21:06:49Z spasi $ | |
50 | * @version $Revision: 3334 $ | |
51 | * $Id: BufferChecks.java 3334 2010-04-22 23:21:48Z spasi $ | |
52 | 52 | */ |
53 | 53 | public class BufferChecks { |
54 | 54 | /** Static methods only! */ |
59 | 59 | * Helper methods to ensure a function pointer is not-null (0) |
60 | 60 | */ |
61 | 61 | public static void checkFunctionAddress(long pointer) { |
62 | if (pointer == 0) { | |
62 | if (LWJGLUtil.CHECKS && pointer == 0) { | |
63 | 63 | throw new IllegalStateException("Function is not supported"); |
64 | 64 | } |
65 | 65 | } |
68 | 68 | * Helper methods to ensure a ByteBuffer is null-terminated |
69 | 69 | */ |
70 | 70 | public static void checkNullTerminated(ByteBuffer buf) { |
71 | if (buf.get(buf.limit() - 1) != 0) { | |
71 | if ( LWJGLUtil.CHECKS && buf.get(buf.limit() - 1) != 0) { | |
72 | 72 | throw new IllegalArgumentException("Missing null termination"); |
73 | 73 | } |
74 | 74 | } |
75 | 75 | |
76 | 76 | public static void checkNullTerminated(ByteBuffer buf, int count) { |
77 | int nullFound = 0; | |
78 | for ( int i = buf.position(); i < buf.limit(); i++ ) { | |
79 | if ( buf.get(i) == 0 ) | |
80 | nullFound++; | |
81 | } | |
82 | ||
83 | if ( nullFound < count ) | |
84 | throw new IllegalArgumentException("Missing null termination"); | |
77 | if ( LWJGLUtil.CHECKS ) { | |
78 | int nullFound = 0; | |
79 | for ( int i = buf.position(); i < buf.limit(); i++ ) { | |
80 | if ( buf.get(i) == 0 ) | |
81 | nullFound++; | |
82 | } | |
83 | ||
84 | if ( nullFound < count ) | |
85 | throw new IllegalArgumentException("Missing null termination"); | |
86 | } | |
85 | 87 | } |
86 | 88 | |
87 | 89 | /** Helper methods to ensure an IntBuffer is null-terminated */ |
92 | 94 | } |
93 | 95 | |
94 | 96 | public static void checkNotNull(Object o) { |
95 | if (o == null) | |
97 | if ( LWJGLUtil.CHECKS && o == null) | |
96 | 98 | throw new IllegalArgumentException("Null argument"); |
97 | 99 | } |
98 | 100 | |
100 | 102 | * Helper methods to ensure a buffer is direct (and, implicitly, non-null). |
101 | 103 | */ |
102 | 104 | public static void checkDirect(ByteBuffer buf) { |
103 | if (!buf.isDirect()) { | |
105 | if ( LWJGLUtil.CHECKS && !buf.isDirect()) { | |
104 | 106 | throw new IllegalArgumentException("ByteBuffer is not direct"); |
105 | 107 | } |
106 | 108 | } |
107 | 109 | |
108 | 110 | public static void checkDirect(ShortBuffer buf) { |
109 | if (!buf.isDirect()) { | |
111 | if ( LWJGLUtil.CHECKS && !buf.isDirect()) { | |
110 | 112 | throw new IllegalArgumentException("ShortBuffer is not direct"); |
111 | 113 | } |
112 | 114 | } |
113 | 115 | |
114 | 116 | public static void checkDirect(IntBuffer buf) { |
115 | if (!buf.isDirect()) { | |
117 | if ( LWJGLUtil.CHECKS && !buf.isDirect()) { | |
116 | 118 | throw new IllegalArgumentException("IntBuffer is not direct"); |
117 | 119 | } |
118 | 120 | } |
119 | 121 | |
120 | 122 | public static void checkDirect(LongBuffer buf) { |
121 | if (!buf.isDirect()) { | |
123 | if ( LWJGLUtil.CHECKS && !buf.isDirect()) { | |
122 | 124 | throw new IllegalArgumentException("LongBuffer is not direct"); |
123 | 125 | } |
124 | 126 | } |
125 | 127 | |
126 | 128 | public static void checkDirect(FloatBuffer buf) { |
127 | if (!buf.isDirect()) { | |
129 | if ( LWJGLUtil.CHECKS && !buf.isDirect()) { | |
128 | 130 | throw new IllegalArgumentException("FloatBuffer is not direct"); |
129 | 131 | } |
130 | 132 | } |
131 | 133 | |
132 | 134 | public static void checkDirect(DoubleBuffer buf) { |
133 | if (!buf.isDirect()) { | |
135 | if ( LWJGLUtil.CHECKS && !buf.isDirect()) { | |
134 | 136 | throw new IllegalArgumentException("DoubleBuffer is not direct"); |
135 | 137 | } |
136 | 138 | } |
153 | 155 | * @throws IllegalArgumentException |
154 | 156 | */ |
155 | 157 | public static void checkBufferSize(Buffer buf, int size) { |
156 | if (buf.remaining() < size) { | |
158 | if ( LWJGLUtil.CHECKS && buf.remaining() < size) { | |
157 | 159 | throwBufferSizeException(buf, size); |
158 | 160 | } |
159 | 161 | } |
160 | 162 | |
161 | 163 | public static void checkBuffer(ByteBuffer buf, int size) { |
162 | checkBufferSize(buf, size); | |
163 | checkDirect(buf); | |
164 | if ( LWJGLUtil.CHECKS ) { | |
165 | checkBufferSize(buf, size); | |
166 | checkDirect(buf); | |
167 | } | |
164 | 168 | } |
165 | 169 | |
166 | 170 | public static void checkBuffer(ShortBuffer buf, int size) { |
167 | checkBufferSize(buf, size); | |
168 | checkDirect(buf); | |
171 | if ( LWJGLUtil.CHECKS ) { | |
172 | checkBufferSize(buf, size); | |
173 | checkDirect(buf); | |
174 | } | |
169 | 175 | } |
170 | 176 | |
171 | 177 | public static void checkBuffer(IntBuffer buf, int size) { |
172 | checkBufferSize(buf, size); | |
173 | checkDirect(buf); | |
178 | if ( LWJGLUtil.CHECKS ) { | |
179 | checkBufferSize(buf, size); | |
180 | checkDirect(buf); | |
181 | } | |
174 | 182 | } |
175 | 183 | |
176 | 184 | public static void checkBuffer(LongBuffer buf, int size) { |
177 | checkBufferSize(buf, size); | |
178 | checkDirect(buf); | |
185 | if ( LWJGLUtil.CHECKS ) { | |
186 | checkBufferSize(buf, size); | |
187 | checkDirect(buf); | |
188 | } | |
179 | 189 | } |
180 | 190 | |
181 | 191 | public static void checkBuffer(FloatBuffer buf, int size) { |
182 | checkBufferSize(buf, size); | |
183 | checkDirect(buf); | |
192 | if ( LWJGLUtil.CHECKS ) { | |
193 | checkBufferSize(buf, size); | |
194 | checkDirect(buf); | |
195 | } | |
184 | 196 | } |
185 | 197 | |
186 | 198 | public static void checkBuffer(DoubleBuffer buf, int size) { |
187 | checkBufferSize(buf, size); | |
188 | checkDirect(buf); | |
199 | if ( LWJGLUtil.CHECKS ) { | |
200 | checkBufferSize(buf, size); | |
201 | checkDirect(buf); | |
202 | } | |
189 | 203 | } |
190 | 204 | } |
48 | 48 | * </p> |
49 | 49 | * |
50 | 50 | * @author Brian Matzon <brian@matzon.dk> |
51 | * @version $Revision: 2983 $ | |
52 | * $Id: LWJGLUtil.java 2983 2008-04-07 18:36:09Z matzon $ | |
51 | * @version $Revision: 3334 $ | |
52 | * $Id: LWJGLUtil.java 3334 2010-04-22 23:21:48Z spasi $ | |
53 | 53 | */ |
54 | 54 | public class LWJGLUtil { |
55 | 55 | public static final int PLATFORM_LINUX = 1; |
265 | 265 | |
266 | 266 | /** Debug flag. */ |
267 | 267 | public static final boolean DEBUG = getPrivilegedBoolean("org.lwjgl.util.Debug"); |
268 | ||
268 | ||
269 | public static final boolean CHECKS = !getPrivilegedBoolean("org.lwjgl.util.NoChecks"); | |
270 | ||
269 | 271 | static { |
270 | 272 | LWJGLIcon16x16.flip(); |
271 | 273 | LWJGLIcon32x32.flip(); |
45 | 45 | * System class (named Sys so as not to conflict with java.lang.System) |
46 | 46 | * </p> |
47 | 47 | * @author cix_foo <cix_foo@users.sourceforge.net> |
48 | * @version $Revision: 3328 $ | |
49 | * $Id: Sys.java 3328 2010-04-15 18:03:54Z matzon $ | |
48 | * @version $Revision: 3353 $ | |
49 | * $Id: Sys.java 3353 2010-05-24 22:39:06Z matzon $ | |
50 | 50 | */ |
51 | 51 | public final class Sys { |
52 | 52 | /** The native library name */ |
53 | 53 | private static final String JNI_LIBRARY_NAME = "lwjgl"; |
54 | 54 | |
55 | 55 | /** Current version of library */ |
56 | private static final String VERSION = "2.4.2"; | |
56 | private static final String VERSION = "2.5"; | |
57 | 57 | |
58 | 58 | /** The implementation instance to delegate platform specific behavior to */ |
59 | 59 | private final static SysImplementation implementation; |
58 | 58 | * @author cix_foo <cix_foo@users.sourceforge.net> |
59 | 59 | * @author elias_naur <elias_naur@users.sourceforge.net> |
60 | 60 | * @author Brian Matzon <brian@matzon.dk> |
61 | * @version $Revision: 3297 $ | |
62 | * $Id: Mouse.java 3297 2010-03-27 16:04:30Z kappa1 $ | |
61 | * @version $Revision: 3337 $ | |
62 | * $Id: Mouse.java 3337 2010-04-29 17:37:18Z matzon $ | |
63 | 63 | */ |
64 | 64 | public class Mouse { |
65 | 65 | /** Internal use - event size in bytes */ |
466 | 466 | } |
467 | 467 | |
468 | 468 | /** |
469 | * @return Current events delta x. Only valid when the mouse is grabbed. | |
469 | * @return Current events delta x. | |
470 | 470 | */ |
471 | 471 | public static int getEventDX() { |
472 | 472 | synchronized (OpenGLPackageAccess.global_lock) { |
475 | 475 | } |
476 | 476 | |
477 | 477 | /** |
478 | * @return Current events delta y. Only valid when the mouse is grabbed. | |
478 | * @return Current events delta y. | |
479 | 479 | */ |
480 | 480 | public static int getEventDY() { |
481 | 481 | synchronized (OpenGLPackageAccess.global_lock) { |
484 | 484 | } |
485 | 485 | |
486 | 486 | /** |
487 | * @return Current events absolute x. Only valid when the mouse is not grabbed. | |
487 | * @return Current events absolute x. | |
488 | 488 | */ |
489 | 489 | public static int getEventX() { |
490 | 490 | synchronized (OpenGLPackageAccess.global_lock) { |
493 | 493 | } |
494 | 494 | |
495 | 495 | /** |
496 | * @return Current events absolute y. Only valid when the mouse is not grabbed. | |
496 | * @return Current events absolute y. | |
497 | 497 | */ |
498 | 498 | public static int getEventY() { |
499 | 499 | synchronized (OpenGLPackageAccess.global_lock) { |
549 | 549 | } |
550 | 550 | |
551 | 551 | /** |
552 | * @return Movement on the x axis since last time getDX() was called. Only valid when the mouse is grabbed. | |
552 | * @return Movement on the x axis since last time getDX() was called. | |
553 | 553 | */ |
554 | 554 | public static int getDX() { |
555 | 555 | synchronized (OpenGLPackageAccess.global_lock) { |
560 | 560 | } |
561 | 561 | |
562 | 562 | /** |
563 | * @return Movement on the y axis since last time getDY() was called. Only valid when the mouse is grabbed. | |
563 | * @return Movement on the y axis since last time getDY() was called. | |
564 | 564 | */ |
565 | 565 | public static int getDY() { |
566 | 566 | synchronized (OpenGLPackageAccess.global_lock) { |
41 | 41 | * </p> |
42 | 42 | * |
43 | 43 | * @author Brian Matzon <brian@matzon.dk> |
44 | * @version $Revision: 3182 $ | |
45 | * $Id: AL.java 3182 2009-03-17 21:36:18Z matzon $ | |
44 | * @version $Revision: 3348 $ | |
45 | * $Id: AL.java 3348 2010-05-24 21:54:37Z matzon $ | |
46 | 46 | */ |
47 | 47 | public final class AL { |
48 | 48 | /** ALCdevice instance. */ |
159 | 159 | |
160 | 160 | if(openDevice) { |
161 | 161 | device = ALC10.alcOpenDevice(deviceArguments); |
162 | if (device == null) | |
162 | if (device == null) { | |
163 | 163 | throw new LWJGLException("Could not open ALC device"); |
164 | } | |
164 | 165 | |
165 | 166 | if (contextFrequency == -1) { |
166 | 167 | context = ALC10.alcCreateContext(device, null); |
176 | 177 | throw e; |
177 | 178 | } |
178 | 179 | |
179 | ALC11.initialize(); | |
180 | ALC11.initialize(); | |
181 | ||
182 | // Load EFX10 native stubs if ALC_EXT_EFX is supported. | |
183 | // Is there any situation where the current device supports ALC_EXT_EFX and one | |
184 | // later created by the user does not? | |
185 | // Do we have to call resetNativeStubs(EFX10.class); somewhere? Not done for AL11 | |
186 | // either. | |
187 | // This can either be here or in ALC11, since ALC_EXT_EFX indirectly requires AL 1.1 | |
188 | // for functions like alSource3i. | |
189 | if (ALC10.alcIsExtensionPresent(device, EFX10.ALC_EXT_EFX_NAME)){ | |
190 | EFX10.initNativeStubs(); | |
191 | } | |
180 | 192 | } |
181 | 193 | |
182 | 194 | /** |
204 | 216 | device = null; |
205 | 217 | } |
206 | 218 | resetNativeStubs(AL10.class); |
219 | resetNativeStubs(AL11.class); | |
207 | 220 | resetNativeStubs(ALC10.class); |
208 | 221 | resetNativeStubs(ALC11.class); |
222 | resetNativeStubs(EFX10.class); | |
209 | 223 | |
210 | 224 | if (created) |
211 | 225 | nDestroy(); |
57 | 57 | public static final int ALC_CAPTURE_DEVICE_SPECIFIER = 0x310; |
58 | 58 | public static final int ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER = 0x311; |
59 | 59 | public static final int ALC_CAPTURE_SAMPLES = 0x312; |
60 | ||
61 | public static final int ALC_MONO_SOURCES = 0x1010; | |
62 | public static final int ALC_STEREO_SOURCES = 0x1011; | |
60 | 63 | |
61 | 64 | /** |
62 | 65 | * The alcCaptureOpenDevice function allows the application to connect to a capture |
0 | /* | |
1 | * Copyright (c) 2002-2010 LWJGL Project | |
2 | * All rights reserved. | |
3 | * | |
4 | * Redistribution and use in source and binary forms, with or without | |
5 | * modification, are permitted provided that the following conditions are | |
6 | * met: | |
7 | * | |
8 | * * Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * | |
11 | * * Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | |
14 | * | |
15 | * * Neither the name of 'LWJGL' nor the names of | |
16 | * its contributors may be used to endorse or promote products derived | |
17 | * from this software without specific prior written permission. | |
18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | |
31 | package org.lwjgl.openal; | |
32 | ||
33 | /** | |
34 | * Utility class for the OpenAL extension ALC_EXT_EFX. Provides functions to check for the extension | |
35 | * and support of various effects and filters. | |
36 | * <p> | |
37 | * Currently supports ALC_EXT_EFX version 1.0 effects and filters. | |
38 | * | |
39 | * @author Ciardhubh <ciardhubh[at]ciardhubh.de> | |
40 | * @version $Revision$ | |
41 | * $Id$ | |
42 | */ | |
43 | public final class EFXUtil { | |
44 | ||
45 | /** Constant for testSupportGeneric to check an effect. */ | |
46 | private static final int EFFECT = 1111; | |
47 | /** Constant for testSupportGeneric to check a filter. */ | |
48 | private static final int FILTER = 2222; | |
49 | ||
50 | /** Utility class, hidden contructor. */ | |
51 | private EFXUtil() { | |
52 | } | |
53 | ||
54 | /** | |
55 | * Checks if OpenAL implementation is loaded and supports ALC_EXT_EFX. | |
56 | * | |
57 | * @return True if ALC_EXT_EFX is supported, false if not. | |
58 | * @throws OpenALException If OpenAL has not been created yet. | |
59 | */ | |
60 | public static boolean isEfxSupported() { | |
61 | if (!AL.isCreated()) { | |
62 | throw new OpenALException("OpenAL has not been created."); | |
63 | } | |
64 | return ALC10.alcIsExtensionPresent(AL.getDevice(), EFX10.ALC_EXT_EFX_NAME); | |
65 | } | |
66 | ||
67 | /** | |
68 | * Tests OpenAL to see whether the given effect type is supported. This is done by creating an | |
69 | * effect of the given type. If creation succeeds the effect is supported. | |
70 | * | |
71 | * @param effectType Type of effect whose support is to be tested, e.g. AL_EFFECT_REVERB. | |
72 | * @return True if it is supported, false if not. | |
73 | * @throws OpenALException If the request fails due to an AL_OUT_OF_MEMORY error or OpenAL has | |
74 | * not been created yet. | |
75 | * @throws IllegalArgumentException effectType is not a valid effect type. | |
76 | */ | |
77 | public static boolean isEffectSupported(final int effectType) { | |
78 | // Make sure type is a real effect. | |
79 | switch (effectType) { | |
80 | case EFX10.AL_EFFECT_NULL: | |
81 | case EFX10.AL_EFFECT_EAXREVERB: | |
82 | case EFX10.AL_EFFECT_REVERB: | |
83 | case EFX10.AL_EFFECT_CHORUS: | |
84 | case EFX10.AL_EFFECT_DISTORTION: | |
85 | case EFX10.AL_EFFECT_ECHO: | |
86 | case EFX10.AL_EFFECT_FLANGER: | |
87 | case EFX10.AL_EFFECT_FREQUENCY_SHIFTER: | |
88 | case EFX10.AL_EFFECT_VOCAL_MORPHER: | |
89 | case EFX10.AL_EFFECT_PITCH_SHIFTER: | |
90 | case EFX10.AL_EFFECT_RING_MODULATOR: | |
91 | case EFX10.AL_EFFECT_AUTOWAH: | |
92 | case EFX10.AL_EFFECT_COMPRESSOR: | |
93 | case EFX10.AL_EFFECT_EQUALIZER: | |
94 | break; | |
95 | default: | |
96 | throw new IllegalArgumentException("Unknown or invalid effect type: " + effectType); | |
97 | } | |
98 | ||
99 | return testSupportGeneric(EFFECT, effectType); | |
100 | } | |
101 | ||
102 | /** | |
103 | * Tests OpenAL to see whether the given filter type is supported. This is done by creating a | |
104 | * filter of the given type. If creation succeeds the filter is supported. | |
105 | * | |
106 | * @param filterType Type of filter whose support is to be tested, e.g. AL_FILTER_LOWPASS. | |
107 | * @return True if it is supported, false if not. | |
108 | * @throws OpenALException If the request fails due to an AL_OUT_OF_MEMORY error or OpenAL has | |
109 | * not been created yet. | |
110 | * @throws IllegalArgumentException filterType is not a valid filter type. | |
111 | */ | |
112 | public static boolean isFilterSupported(final int filterType) { | |
113 | // Make sure type is a real filter. | |
114 | switch (filterType) { | |
115 | case EFX10.AL_FILTER_NULL: | |
116 | case EFX10.AL_FILTER_LOWPASS: | |
117 | case EFX10.AL_FILTER_HIGHPASS: | |
118 | case EFX10.AL_FILTER_BANDPASS: | |
119 | break; | |
120 | default: | |
121 | throw new IllegalArgumentException("Unknown or invalid filter type: " + filterType); | |
122 | } | |
123 | ||
124 | return testSupportGeneric(FILTER, filterType); | |
125 | } | |
126 | ||
127 | /** | |
128 | * Generic test function to see if an EFX object supports a given kind of type. Works for | |
129 | * effects and filters. | |
130 | * | |
131 | * @param objectType Type of object to test. Must be either EFXUtil.EFFECT or EFXUtil.FILTER. | |
132 | * @param typeValue OpenAL type the object should be tested for support, e.g. AL_FILTER_LOWPASS | |
133 | * or AL_EFFECT_REVERB. | |
134 | * @return True if object supports typeValue, false else. | |
135 | */ | |
136 | private static boolean testSupportGeneric(final int objectType, final int typeValue) { | |
137 | // Check for supported objectType. | |
138 | switch (objectType) { | |
139 | case EFFECT: | |
140 | case FILTER: | |
141 | break; | |
142 | default: | |
143 | throw new IllegalArgumentException("Invalid objectType: " + objectType); | |
144 | } | |
145 | ||
146 | boolean supported = false; | |
147 | if (isEfxSupported()) { | |
148 | ||
149 | // Try to create object in order to check AL's response. | |
150 | AL10.alGetError(); | |
151 | int genError; | |
152 | int testObject = 0; | |
153 | try { | |
154 | switch (objectType) { // Create object based on type | |
155 | case EFFECT: | |
156 | testObject = EFX10.alGenEffects(); | |
157 | break; | |
158 | case FILTER: | |
159 | testObject = EFX10.alGenFilters(); | |
160 | break; | |
161 | default: | |
162 | throw new IllegalArgumentException("Invalid objectType: " + objectType); | |
163 | } | |
164 | genError = AL10.alGetError(); | |
165 | } catch (final OpenALException debugBuildException) { | |
166 | // Hack because OpenALException hides the original error code (short of parsing the | |
167 | // error message String which would break if it gets changed). | |
168 | if (debugBuildException.getMessage().contains("AL_OUT_OF_MEMORY")) { | |
169 | genError = AL10.AL_OUT_OF_MEMORY; | |
170 | } else { | |
171 | genError = AL10.AL_INVALID_OPERATION; | |
172 | } | |
173 | } | |
174 | ||
175 | if (genError == AL10.AL_NO_ERROR) { | |
176 | // Successfully created, now try to set type. | |
177 | AL10.alGetError(); | |
178 | int setError; | |
179 | try { | |
180 | switch (objectType) { // Set based on object type | |
181 | case EFFECT: | |
182 | EFX10.alEffecti(testObject, EFX10.AL_EFFECT_TYPE, typeValue); | |
183 | break; | |
184 | case FILTER: | |
185 | EFX10.alFilteri(testObject, EFX10.AL_FILTER_TYPE, typeValue); | |
186 | break; | |
187 | default: | |
188 | throw new IllegalArgumentException("Invalid objectType: " + objectType); | |
189 | } | |
190 | setError = AL10.alGetError(); | |
191 | } catch (final OpenALException debugBuildException) { | |
192 | // Hack because OpenALException hides the original error code (short of parsing | |
193 | // the error message String which would break when it gets changed). | |
194 | setError = AL10.AL_INVALID_VALUE; | |
195 | } | |
196 | ||
197 | if (setError == AL10.AL_NO_ERROR) { | |
198 | supported = true; | |
199 | } | |
200 | ||
201 | // Cleanup | |
202 | try { | |
203 | switch (objectType) { // Set based on object type | |
204 | case EFFECT: | |
205 | EFX10.alDeleteEffects(testObject); | |
206 | break; | |
207 | case FILTER: | |
208 | EFX10.alDeleteFilters(testObject); | |
209 | break; | |
210 | default: | |
211 | throw new IllegalArgumentException("Invalid objectType: " + objectType); | |
212 | } | |
213 | } catch (final OpenALException debugBuildException) { | |
214 | // Don't care about cleanup errors. | |
215 | } | |
216 | ||
217 | } else if (genError == AL10.AL_OUT_OF_MEMORY) { | |
218 | throw new OpenALException(genError); | |
219 | } | |
220 | } | |
221 | ||
222 | return supported; | |
223 | } | |
224 | } |
0 | /* | |
1 | * Copyright (c) 2002-2008 LWJGL Project | |
2 | * All rights reserved. | |
3 | * | |
4 | * Redistribution and use in source and binary forms, with or without | |
5 | * modification, are permitted provided that the following conditions are | |
6 | * met: | |
7 | * | |
8 | * * Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * | |
11 | * * Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | |
14 | * | |
15 | * * Neither the name of 'LWJGL' nor the names of | |
16 | * its contributors may be used to endorse or promote products derived | |
17 | * from this software without specific prior written permission. | |
18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | |
31 | package org.lwjgl.opengl; | |
32 | ||
33 | /** | |
34 | * Instances of this class are needed to use the callback functionality of the AMD_debug_output extension. | |
35 | * A debug context must be current before creating instances of this class. Users of this class may provide | |
36 | * implementations of the {@code Handler} interface to receive notifications. The same {@code Handler} | |
37 | * instance may be used by different contexts but it is not recommended. Handler notifications are synchronized. | |
38 | * | |
39 | * @author Spasi | |
40 | */ | |
41 | public final class AMDDebugOutputCallback implements PointerWrapper { | |
42 | ||
43 | /** Severity levels. */ | |
44 | private static final int GL_DEBUG_SEVERITY_HIGH_AMD = 0x9146, | |
45 | GL_DEBUG_SEVERITY_MEDIUM_AMD = 0x9147, | |
46 | GL_DEBUG_SEVERITY_LOW_AMD = 0x9148; | |
47 | ||
48 | /** Categories */ | |
49 | private static final int GL_DEBUG_CATEGORY_API_ERROR_AMD = 0x9149, | |
50 | GL_DEBUG_CATEGORY_WINDOW_SYSTEM_AMD = 0x914A, | |
51 | GL_DEBUG_CATEGORY_DEPRECATION_AMD = 0x914B, | |
52 | GL_DEBUG_CATEGORY_UNDEFINED_BEHAVIOR_AMD = 0x914C, | |
53 | GL_DEBUG_CATEGORY_PERFORMANCE_AMD = 0x914D, | |
54 | GL_DEBUG_CATEGORY_SHADER_COMPILER_AMD = 0x914E, | |
55 | GL_DEBUG_CATEGORY_APPLICATION_AMD = 0x914F, | |
56 | GL_DEBUG_CATEGORY_OTHER_AMD = 0x9150; | |
57 | ||
58 | private final long pointer; | |
59 | ||
60 | /** | |
61 | * Creates a AMDDebugOutputCallback with a default callback handler. | |
62 | * The default handler will simply print the message on System.err. | |
63 | */ | |
64 | public AMDDebugOutputCallback() { | |
65 | this(new Handler() { | |
66 | public void handleMessage(final int id, final int category, final int severity, final String message) { | |
67 | System.err.println("[LWJGL] AMD_debug_output message"); | |
68 | System.err.println("\tID: " + id); | |
69 | ||
70 | String description; | |
71 | switch ( category ) { | |
72 | case GL_DEBUG_CATEGORY_API_ERROR_AMD: | |
73 | description = "API ERROR"; | |
74 | break; | |
75 | case GL_DEBUG_CATEGORY_WINDOW_SYSTEM_AMD: | |
76 | description = "WINDOW SYSTEM"; | |
77 | break; | |
78 | case GL_DEBUG_CATEGORY_DEPRECATION_AMD: | |
79 | description = "DEPRECATION"; | |
80 | break; | |
81 | case GL_DEBUG_CATEGORY_UNDEFINED_BEHAVIOR_AMD: | |
82 | description = "UNDEFINED BEHAVIOR"; | |
83 | break; | |
84 | case GL_DEBUG_CATEGORY_PERFORMANCE_AMD: | |
85 | description = "PERFORMANCE"; | |
86 | break; | |
87 | case GL_DEBUG_CATEGORY_SHADER_COMPILER_AMD: | |
88 | description = "SHADER COMPILER"; | |
89 | break; | |
90 | case GL_DEBUG_CATEGORY_APPLICATION_AMD: | |
91 | description = "APPLICATION"; | |
92 | break; | |
93 | case GL_DEBUG_CATEGORY_OTHER_AMD: | |
94 | description = "OTHER"; | |
95 | break; | |
96 | default: | |
97 | description = "Unknown (" + Integer.toHexString(category) + ")"; | |
98 | } | |
99 | System.err.println("\tCategory: " + description); | |
100 | ||
101 | switch ( severity ) { | |
102 | case GL_DEBUG_SEVERITY_HIGH_AMD: | |
103 | description = "HIGH"; | |
104 | break; | |
105 | case GL_DEBUG_SEVERITY_MEDIUM_AMD: | |
106 | description = "MEDIUM"; | |
107 | break; | |
108 | case GL_DEBUG_SEVERITY_LOW_AMD: | |
109 | description = "LOW"; | |
110 | break; | |
111 | default: | |
112 | description = "Unknown (" + Integer.toHexString(category) + ")"; | |
113 | } | |
114 | System.err.println("\tSeverity: " + description); | |
115 | ||
116 | System.err.println("\tMessage: " + message); | |
117 | } | |
118 | }); | |
119 | } | |
120 | ||
121 | /** | |
122 | * Creates a AMDDebugOutputCallback with the specified callback handlers. | |
123 | * The handler's {@code handleMessage} method will be called whenever | |
124 | * debug output is generated by the GL. | |
125 | * | |
126 | * @param handler the callback handler | |
127 | */ | |
128 | public AMDDebugOutputCallback(final Handler handler) { | |
129 | try { | |
130 | // We have to call registerHandler reflectively because we need this class to compile before we run the Generator. | |
131 | // The registerHandler method depends on org.lwjgl.opengl.Context, if we touched that we would need to compile | |
132 | // the whole library (which is not possible). | |
133 | Class.forName("org.lwjgl.opengl.AMDDebugOutputUtil").getMethod("registerHandler", new Class[] { Handler.class }).invoke(null, new Object[] { handler }); | |
134 | } catch (Exception e) { | |
135 | throw new RuntimeException(e.getCause() != null ? e.getCause() : e); | |
136 | } | |
137 | this.pointer = getFunctionPointer(); | |
138 | } | |
139 | ||
140 | public long getPointer() { | |
141 | return pointer; | |
142 | } | |
143 | ||
144 | private static native long getFunctionPointer(); | |
145 | ||
146 | /** Implementations of this interface can be used to receive AMD_debug_output notifications. */ | |
147 | public interface Handler { | |
148 | ||
149 | /** | |
150 | * This method will be called when an AMD_debug_output message is generated. | |
151 | * | |
152 | * @param id the message ID | |
153 | * @param category the message category | |
154 | * @param severity the message severity | |
155 | * @param message the string representation of the message. | |
156 | */ | |
157 | void handleMessage(int id, int category, int severity, String message); | |
158 | ||
159 | } | |
160 | ||
161 | } |
0 | package org.lwjgl.opengl; | |
1 | ||
2 | import org.lwjgl.opengl.AMDDebugOutputCallback.Handler; | |
3 | ||
4 | import java.nio.ByteBuffer; | |
5 | import java.util.Map; | |
6 | import java.util.WeakHashMap; | |
7 | ||
8 | /** | |
9 | * This class handles AMDDebugOutputCallback.Handler registration and notification. | |
10 | * We could have put this in AMDDebugOutputCallback, but we need to compile it for | |
11 | * the generator. Registration is done reflectively in the AMDDebugOutputCallback | |
12 | * constructor. | |
13 | * | |
14 | * @author Spasi | |
15 | */ | |
16 | final class AMDDebugOutputUtil { | |
17 | ||
18 | private static final Map handlers = new WeakHashMap(); | |
19 | ||
20 | private AMDDebugOutputUtil() {} | |
21 | ||
22 | public static void registerHandler(final Handler handler) { | |
23 | final Context ctx = Context.getCurrentContext(); | |
24 | if ( ctx == null ) | |
25 | throw new IllegalStateException("No context is current."); | |
26 | ||
27 | if ( !ctx.getContextAttribs().isDebug() ) | |
28 | throw new IllegalStateException("The current context is not a debug context."); | |
29 | ||
30 | if ( !GLContext.getCapabilities().GL_AMD_debug_output ) | |
31 | throw new IllegalStateException("AMD_debug_output is not supported."); | |
32 | ||
33 | handlers.put(ctx, handler); | |
34 | } | |
35 | ||
36 | /** | |
37 | * This method is called by native code. If finds the callback handler associated | |
38 | * with the current Thread and calls its {@code handleMessage} method. | |
39 | * | |
40 | * @param id the message ID | |
41 | * @param category the message category | |
42 | * @param severity the message severity | |
43 | * @param message the string representation of the message. | |
44 | * @param userParam the user-specified data specified in glDebugMessageCallbackAMD. For the current implementation this is always null and we ignore it. | |
45 | */ | |
46 | private static void messageCallback(final int id, final int category, final int severity, final String message, final ByteBuffer userParam) { | |
47 | synchronized ( GlobalLock.lock ) { | |
48 | final Context ctx = Context.getCurrentContext(); | |
49 | if ( ctx == null ) | |
50 | return; | |
51 | ||
52 | final Handler handler = (Handler)handlers.get(ctx); | |
53 | if ( handler != null ) | |
54 | handler.handleMessage(id, category, severity, message); | |
55 | } | |
56 | } | |
57 | ||
58 | } |
157 | 157 | final InfiniteCharSequence infiniteSeq = getInfiniteSeq(); |
158 | 158 | infiniteSeq.setString(string); |
159 | 159 | encoder.encode(infiniteSeq.buffer, buffer, true); |
160 | infiniteSeq.clear(); | |
160 | 161 | } |
161 | 162 | |
162 | 163 | /** |
46 | 46 | * <p/> |
47 | 47 | * |
48 | 48 | * @author $Author: spasi $ |
49 | * $Id: AWTGLCanvas.java 3116 2008-08-19 16:46:03Z spasi $ | |
50 | * @version $Revision: 3116 $ | |
49 | * $Id: AWTGLCanvas.java 3334 2010-04-22 23:21:48Z spasi $ | |
50 | * @version $Revision: 3334 $ | |
51 | 51 | */ |
52 | public class AWTGLCanvas extends Canvas implements Drawable, ComponentListener, HierarchyListener { | |
52 | public class AWTGLCanvas extends Canvas implements DrawableLWJGL, ComponentListener, HierarchyListener { | |
53 | 53 | |
54 | 54 | private static final long serialVersionUID = 1L; |
55 | 55 | |
108 | 108 | return context; |
109 | 109 | } |
110 | 110 | |
111 | /** This method should only be called internally. */ | |
112 | public Context createSharedContext() throws LWJGLException { | |
113 | synchronized ( SYNC_LOCK ) { | |
114 | if ( context == null ) throw new IllegalStateException("Canvas not yet displayable"); | |
115 | ||
116 | return new Context(peer_info, context.getContextAttribs(), context); | |
117 | } | |
118 | } | |
119 | ||
111 | 120 | /** Constructor using the default PixelFormat. */ |
112 | 121 | public AWTGLCanvas() throws LWJGLException { |
113 | 122 | this(new PixelFormat()); |
174 | 183 | */ |
175 | 184 | public void removeNotify() { |
176 | 185 | synchronized ( SYNC_LOCK ) { |
177 | destroyContext(); | |
186 | destroy(); | |
178 | 187 | super.removeNotify(); |
179 | 188 | } |
180 | 189 | } |
199 | 208 | if ( context == null ) |
200 | 209 | throw new IllegalStateException("Canvas not yet displayable"); |
201 | 210 | Context.swapBuffers(); |
211 | } | |
212 | } | |
213 | ||
214 | public boolean isCurrent() throws LWJGLException { | |
215 | synchronized ( SYNC_LOCK ) { | |
216 | if ( context == null ) throw new IllegalStateException("Canvas not yet displayable"); | |
217 | ||
218 | return context.isCurrent(); | |
219 | } | |
220 | } | |
221 | ||
222 | /** | |
223 | * Make the canvas' context current. It is highly recommended that the context | |
224 | * is only made current inside the AWT thread (for example in an overridden paintGL()). | |
225 | */ | |
226 | public void makeCurrent() throws LWJGLException { | |
227 | synchronized ( SYNC_LOCK ) { | |
228 | if ( context == null ) | |
229 | throw new IllegalStateException("Canvas not yet displayable"); | |
230 | context.makeCurrent(); | |
202 | 231 | } |
203 | 232 | } |
204 | 233 | |
211 | 240 | } |
212 | 241 | } |
213 | 242 | |
214 | /** | |
215 | * Make the canvas' context current. It is highly recommended that the context | |
216 | * is only made current inside the AWT thread (for example in an overridden paintGL()). | |
217 | */ | |
218 | public void makeCurrent() throws LWJGLException { | |
219 | synchronized ( SYNC_LOCK ) { | |
220 | if ( context == null ) | |
221 | throw new IllegalStateException("Canvas not yet displayable"); | |
222 | context.makeCurrent(); | |
223 | } | |
224 | } | |
225 | ||
226 | 243 | /** Destroy the OpenGL context. This happens when the component becomes undisplayable */ |
227 | private void destroyContext() { | |
244 | public final void destroy() { | |
228 | 245 | synchronized ( SYNC_LOCK ) { |
229 | 246 | try { |
230 | 247 | if ( context != null ) { |
268 | 285 | peer_info.lockAndGetHandle(); |
269 | 286 | try { |
270 | 287 | if ( context == null ) { |
271 | this.context = new Context(peer_info, attribs, drawable != null ? drawable.getContext() : null); | |
288 | this.context = new Context(peer_info, attribs, drawable != null ? ((DrawableLWJGL)drawable).getContext() : null); | |
272 | 289 | first_run = true; |
273 | 290 | } |
274 | 291 |
0 | package org.lwjgl.opengl; | |
1 | ||
2 | import org.lwjgl.LWJGLException; | |
3 | import org.lwjgl.LWJGLUtil; | |
4 | ||
5 | /** | |
6 | * @author Spasi | |
7 | */ | |
8 | abstract class AbstractDrawable implements DrawableLWJGL { | |
9 | ||
10 | /** Handle to the native GL rendering context */ | |
11 | protected PeerInfo peer_info; | |
12 | ||
13 | /** The OpenGL Context. */ | |
14 | protected Context context; | |
15 | ||
16 | protected AbstractDrawable() { | |
17 | } | |
18 | ||
19 | public Context getContext() { | |
20 | synchronized ( GlobalLock.lock ) { | |
21 | return context; | |
22 | } | |
23 | } | |
24 | ||
25 | public Context createSharedContext() throws LWJGLException { | |
26 | synchronized ( GlobalLock.lock ) { | |
27 | checkDestroyed(); | |
28 | return new Context(peer_info, context.getContextAttribs(), context); | |
29 | } | |
30 | } | |
31 | ||
32 | public boolean isCurrent() throws LWJGLException { | |
33 | synchronized ( GlobalLock.lock ) { | |
34 | checkDestroyed(); | |
35 | return context.isCurrent(); | |
36 | } | |
37 | } | |
38 | ||
39 | public void makeCurrent() throws LWJGLException { | |
40 | synchronized ( GlobalLock.lock ) { | |
41 | checkDestroyed(); | |
42 | context.makeCurrent(); | |
43 | } | |
44 | } | |
45 | ||
46 | public void releaseContext() throws LWJGLException { | |
47 | synchronized ( GlobalLock.lock ) { | |
48 | checkDestroyed(); | |
49 | if ( context.isCurrent() ) | |
50 | Context.releaseCurrentContext(); | |
51 | } | |
52 | } | |
53 | ||
54 | public void destroy() { | |
55 | synchronized ( GlobalLock.lock ) { | |
56 | if ( context == null ) | |
57 | return; | |
58 | ||
59 | try { | |
60 | releaseContext(); | |
61 | ||
62 | context.forceDestroy(); | |
63 | context = null; | |
64 | ||
65 | if ( peer_info != null ) { | |
66 | peer_info.destroy(); | |
67 | peer_info = null; | |
68 | } | |
69 | } catch (LWJGLException e) { | |
70 | LWJGLUtil.log("Exception occurred while destroying Drawable: " + e); | |
71 | } | |
72 | } | |
73 | } | |
74 | ||
75 | protected final void checkDestroyed() { | |
76 | if ( context == null ) | |
77 | throw new IllegalStateException("The Drawable has no context available."); | |
78 | } | |
79 | ||
80 | } |
31 | 31 | package org.lwjgl.opengl; |
32 | 32 | |
33 | 33 | import java.nio.Buffer; |
34 | import java.nio.IntBuffer; | |
35 | 34 | import java.util.Arrays; |
36 | 35 | |
37 | 36 | class BaseReferences { |
48 | 47 | int indirectBuffer; |
49 | 48 | |
50 | 49 | BaseReferences(ContextCapabilities caps) { |
51 | IntBuffer temp = caps.scratch_int_buffer; | |
52 | ||
53 | 50 | int max_vertex_attribs; |
54 | if (caps.OpenGL20 || caps.GL_ARB_vertex_shader) { | |
55 | GL11.glGetInteger(ARBVertexShader.GL_MAX_VERTEX_ATTRIBS_ARB, temp); | |
56 | max_vertex_attribs = temp.get(0); | |
57 | } else | |
51 | if (caps.OpenGL20 || caps.GL_ARB_vertex_shader) | |
52 | max_vertex_attribs = GL11.glGetInteger(ARBVertexShader.GL_MAX_VERTEX_ATTRIBS_ARB); | |
53 | else | |
58 | 54 | max_vertex_attribs = 0; |
59 | 55 | glVertexAttribPointer_buffer = new Buffer[max_vertex_attribs]; |
60 | 56 | |
61 | 57 | int max_texture_units; |
62 | if (caps.OpenGL20) { | |
63 | GL11.glGetInteger(GL20.GL_MAX_TEXTURE_IMAGE_UNITS, temp); | |
64 | max_texture_units = temp.get(0); | |
65 | } else if (caps.OpenGL13 || caps.GL_ARB_multitexture) { | |
66 | GL11.glGetInteger(GL13.GL_MAX_TEXTURE_UNITS, temp); | |
67 | max_texture_units = temp.get(0); | |
68 | } else | |
58 | if (caps.OpenGL20) | |
59 | max_texture_units = GL11.glGetInteger(GL20.GL_MAX_TEXTURE_IMAGE_UNITS); | |
60 | else if (caps.OpenGL13 || caps.GL_ARB_multitexture) | |
61 | max_texture_units = GL11.glGetInteger(GL13.GL_MAX_TEXTURE_UNITS); | |
62 | else | |
69 | 63 | max_texture_units = 1; |
70 | 64 | glTexCoordPointer_buffer = new Buffer[max_texture_units]; |
71 | 65 | } |
45 | 45 | * This class is thread-safe. |
46 | 46 | * |
47 | 47 | * @author elias_naur <elias_naur@users.sourceforge.net> |
48 | * @version $Revision: 3117 $ | |
49 | * $Id: Context.java 3117 2008-08-19 17:47:24Z spasi $ | |
48 | * @version $Revision: 3332 $ | |
49 | * $Id: Context.java 3332 2010-04-20 18:21:05Z spasi $ | |
50 | 50 | */ |
51 | 51 | final class Context { |
52 | 52 | |
60 | 60 | private final ByteBuffer handle; |
61 | 61 | private final PeerInfo peer_info; |
62 | 62 | |
63 | private final IntBuffer attribList; | |
63 | private final ContextAttribs contextAttribs; | |
64 | 64 | private final boolean forwardCompatible; |
65 | 65 | |
66 | 66 | /** Whether the context has been destroyed */ |
91 | 91 | |
92 | 92 | PeerInfo getPeerInfo() { |
93 | 93 | return peer_info; |
94 | } | |
95 | ||
96 | ContextAttribs getContextAttribs() { | |
97 | return contextAttribs; | |
94 | 98 | } |
95 | 99 | |
96 | 100 | static Context getCurrentContext() { |
108 | 112 | GLContext.loadOpenGLLibrary(); |
109 | 113 | try { |
110 | 114 | this.peer_info = peer_info; |
115 | this.contextAttribs = attribs; | |
116 | ||
117 | IntBuffer attribList; | |
111 | 118 | if ( attribs != null ) { |
112 | 119 | attribList = attribs.getAttribList(); |
113 | 120 | forwardCompatible = attribs.isForwardCompatible(); |
36 | 36 | import java.nio.IntBuffer; |
37 | 37 | |
38 | 38 | /** |
39 | * This class represents the context attributes passed to CreateContextAttribs of the XGL_create_context extension. | |
39 | * This class represents the context attributes passed to CreateContextAttribs of the ARB_create_context and | |
40 | * ARB_create_context_profile extensions. | |
40 | 41 | * These attributes can be used to indicate at context creation which OpenGL interface will be used. This includes the |
41 | 42 | * OpenGL version, the layer plane on which rendering takes place and also optional debug and forward combatibility modes. |
42 | * (read the XGL_create_context spec for details) | |
43 | * (read the ARB_create_context spec for details) | |
43 | 44 | * <p/> |
44 | 45 | * Use of this class is optional. If an OpenGL context is created without passing an instance of this class |
45 | * (or XGL_create_context is not supported), the old context creation code will be used. Use of ContextAttribs is required | |
46 | * to create an OpenGL 3.0 or newer context. Support for debug and forward compatible mobes is not guaranteed by the OpenGL | |
47 | * implementation. Developers may encounter debug contexts being the same as non-debug contexts or forward compatible | |
48 | * contexts having support for deprecated functionality. | |
46 | * (or ARB_create_context is not supported), the old context creation code will be used. Support for debug and forward | |
47 | * compatible mobes is not guaranteed by the OpenGL implementation. Developers may encounter debug contexts being the same | |
48 | * as non-debug contexts or forward compatible contexts having support for deprecated functionality. | |
49 | 49 | * <p/> |
50 | 50 | * If the forwardCompatible |
51 | 51 | * attribute is used, LWJGL will not load the deprecated functionality (as defined in the OpenGL 3.0 specification). This |
71 | 71 | } |
72 | 72 | |
73 | 73 | public ContextAttribs(final int majorVersion, final int minorVersion) { |
74 | if ( majorVersion < 0 || | |
75 | 3 < majorVersion || | |
74 | if ( majorVersion < 0 || 4 < majorVersion || | |
76 | 75 | minorVersion < 0 || |
77 | (majorVersion == 3 && 2 < minorVersion) || | |
76 | (majorVersion == 4 && 0 < minorVersion) || | |
77 | (majorVersion == 3 && 3 < minorVersion) || | |
78 | 78 | (majorVersion == 2 && 1 < minorVersion) || |
79 | 79 | (majorVersion == 1 && 5 < minorVersion) ) |
80 | 80 | throw new IllegalArgumentException("Invalid OpenGL version specified: " + majorVersion + '.' + minorVersion); |
87 | 87 | this.debug = false; |
88 | 88 | this.forwardCompatible = false; |
89 | 89 | |
90 | this.profileCore = 3 < majorVersion || (majorVersion == 3 && 2 <= minorVersion) ? true : false; | |
90 | this.profileCore = false; | |
91 | 91 | this.profileCompatibility = false; |
92 | 92 | } |
93 | 93 |
105 | 105 | /** Swap interval */ |
106 | 106 | private static int swap_interval; |
107 | 107 | |
108 | /** A unique context object, so we can track different contexts between creates() and destroys() */ | |
109 | private static PeerInfo peer_info; | |
110 | private static Context context; | |
111 | ||
112 | 108 | /** The Drawable instance that tracks the current Display context */ |
113 | private final static Drawable drawable; | |
114 | ||
115 | private static boolean window_created = false; | |
109 | private static final AbstractDrawable drawable; | |
110 | ||
111 | private static boolean window_created; | |
116 | 112 | |
117 | 113 | private static boolean parent_resized; |
118 | 114 | |
136 | 132 | } catch (LWJGLException e) { |
137 | 133 | throw new RuntimeException(e); |
138 | 134 | } |
139 | drawable = new Drawable() { | |
140 | public Context getContext() { | |
135 | drawable = new AbstractDrawable() { | |
136 | public void destroy() { | |
141 | 137 | synchronized ( GlobalLock.lock ) { |
142 | return isCreated() ? context : null; | |
138 | if ( !isCreated() ) | |
139 | return; | |
140 | ||
141 | releaseDrawable(); | |
142 | super.destroy(); | |
143 | destroyWindow(); | |
144 | x = y = -1; | |
145 | cached_icons = null; | |
146 | reset(); | |
147 | removeShutdownHook(); | |
143 | 148 | } |
144 | 149 | } |
145 | 150 | }; |
237 | 242 | * @throws LWJGLException if the display mode could not be set |
238 | 243 | */ |
239 | 244 | public static void setDisplayMode(DisplayMode mode) throws LWJGLException { |
240 | synchronized (GlobalLock.lock) { | |
241 | if (mode == null) | |
245 | synchronized ( GlobalLock.lock ) { | |
246 | if ( mode == null ) | |
242 | 247 | throw new NullPointerException("mode must be non-null"); |
243 | 248 | boolean was_fullscreen = isFullscreen(); |
244 | 249 | current_mode = mode; |
245 | if (isCreated()) { | |
250 | if ( isCreated() ) { | |
246 | 251 | destroyWindow(); |
247 | 252 | // If mode is not fullscreen capable, make sure we are in windowed mode |
248 | 253 | try { |
249 | if (was_fullscreen && !isFullscreen()) | |
254 | if ( was_fullscreen && !isFullscreen() ) | |
250 | 255 | display_impl.resetDisplayMode(); |
251 | else if (isFullscreen()) | |
256 | else if ( isFullscreen() ) | |
252 | 257 | switchDisplayMode(); |
253 | 258 | createWindow(); |
254 | 259 | makeCurrentAndSetSwapInterval(); |
255 | 260 | } catch (LWJGLException e) { |
256 | destroyContext(); | |
257 | destroyPeerInfo(); | |
261 | drawable.destroy(); | |
258 | 262 | display_impl.resetDisplayMode(); |
259 | 263 | throw e; |
260 | 264 | } |
267 | 271 | } |
268 | 272 | |
269 | 273 | private static int getWindowX() { |
270 | if (!isFullscreen() && parent == null) { | |
274 | if ( !isFullscreen() && parent == null ) { | |
271 | 275 | // if no display location set, center window |
272 | if (x == -1) { | |
276 | if ( x == -1 ) { | |
273 | 277 | return Math.max(0, (initial_mode.getWidth() - current_mode.getWidth()) / 2); |
274 | 278 | } else { |
275 | 279 | return x; |
280 | 284 | } |
281 | 285 | |
282 | 286 | private static int getWindowY() { |
283 | if (!isFullscreen() && parent == null) { | |
287 | if ( !isFullscreen() && parent == null ) { | |
284 | 288 | // if no display location set, center window |
285 | 289 | if ( y == -1 ) { |
286 | 290 | return Math.max(0, (initial_mode.getHeight() - current_mode.getHeight()) / 2); |
323 | 327 | |
324 | 328 | private static void releaseDrawable() { |
325 | 329 | try { |
330 | Context context = drawable.context; | |
326 | 331 | if ( context != null && context.isCurrent() ) { |
327 | 332 | Context.releaseCurrentContext(); |
328 | 333 | context.releaseDrawable(); |
418 | 423 | savedTimeLate = timeLate; |
419 | 424 | } |
420 | 425 | |
421 | while ( gapTo > timeNow + savedTimeLate ) { | |
422 | try { | |
426 | try { | |
427 | while ( gapTo > timeNow + savedTimeLate ) { | |
423 | 428 | Thread.sleep(1); |
424 | } catch (InterruptedException e) { | |
425 | } | |
426 | timeNow = Sys.getTime(); | |
429 | timeNow = Sys.getTime(); | |
430 | } | |
431 | } catch (InterruptedException e) { | |
432 | Thread.currentThread().interrupt(); | |
427 | 433 | } |
428 | 434 | |
429 | 435 | synchronized ( GlobalLock.lock ) { |
462 | 468 | */ |
463 | 469 | public static void setParent(Canvas parent) throws LWJGLException { |
464 | 470 | synchronized ( GlobalLock.lock ) { |
465 | if (Display.parent != parent) { | |
471 | if ( Display.parent != parent ) { | |
466 | 472 | Display.parent = parent; |
467 | 473 | if ( !isCreated() ) |
468 | 474 | return; |
469 | 475 | destroyWindow(); |
470 | 476 | try { |
471 | if (isFullscreen()) { | |
477 | if ( isFullscreen() ) { | |
472 | 478 | switchDisplayMode(); |
473 | 479 | } else { |
474 | 480 | display_impl.resetDisplayMode(); |
476 | 482 | createWindow(); |
477 | 483 | makeCurrentAndSetSwapInterval(); |
478 | 484 | } catch (LWJGLException e) { |
479 | destroyContext(); | |
480 | destroyPeerInfo(); | |
485 | drawable.destroy(); | |
481 | 486 | display_impl.resetDisplayMode(); |
482 | 487 | throw e; |
483 | 488 | } |
518 | 523 | |
519 | 524 | private static void setDisplayModeAndFullscreenInternal(boolean fullscreen, DisplayMode mode) throws LWJGLException { |
520 | 525 | synchronized ( GlobalLock.lock ) { |
521 | if (mode == null) | |
526 | if ( mode == null ) | |
522 | 527 | throw new NullPointerException("mode must be non-null"); |
523 | 528 | DisplayMode old_mode = current_mode; |
524 | 529 | current_mode = mode; |
525 | 530 | boolean was_fullscreen = isFullscreen(); |
526 | 531 | Display.fullscreen = fullscreen; |
527 | if (was_fullscreen != isFullscreen() || !mode.equals(old_mode)) { | |
528 | if (!isCreated()) | |
532 | if ( was_fullscreen != isFullscreen() || !mode.equals(old_mode) ) { | |
533 | if ( !isCreated() ) | |
529 | 534 | return; |
530 | 535 | destroyWindow(); |
531 | 536 | try { |
532 | if (isFullscreen()) { | |
537 | if ( isFullscreen() ) { | |
533 | 538 | switchDisplayMode(); |
534 | 539 | } else { |
535 | 540 | display_impl.resetDisplayMode(); |
537 | 542 | createWindow(); |
538 | 543 | makeCurrentAndSetSwapInterval(); |
539 | 544 | } catch (LWJGLException e) { |
540 | destroyContext(); | |
541 | destroyPeerInfo(); | |
545 | drawable.destroy(); | |
542 | 546 | display_impl.resetDisplayMode(); |
543 | 547 | throw e; |
544 | 548 | } |
548 | 552 | |
549 | 553 | /** @return whether the Display is in fullscreen mode */ |
550 | 554 | public static boolean isFullscreen() { |
551 | synchronized (GlobalLock.lock) { | |
555 | synchronized ( GlobalLock.lock ) { | |
552 | 556 | return fullscreen && current_mode.isFullscreenCapable(); |
553 | 557 | } |
554 | 558 | } |
650 | 654 | * Update the window. If the window is visible clears |
651 | 655 | * the dirty flag and calls swapBuffers() and finally |
652 | 656 | * polls the input devices. |
653 | * | |
654 | 657 | */ |
655 | 658 | public static void update() { |
656 | 659 | update(true); |
709 | 712 | * @throws LWJGLException If the context could not be released |
710 | 713 | */ |
711 | 714 | public static void releaseContext() throws LWJGLException { |
712 | synchronized ( GlobalLock.lock ) { | |
713 | if ( !isCreated() ) | |
714 | throw new IllegalStateException("Display is not created"); | |
715 | if ( context.isCurrent() ) | |
716 | Context.releaseCurrentContext(); | |
717 | } | |
715 | drawable.releaseContext(); | |
716 | } | |
717 | ||
718 | /** Returns true if the Display's context is current in the current thread. */ | |
719 | public static boolean isCurrent() throws LWJGLException { | |
720 | return drawable.isCurrent(); | |
718 | 721 | } |
719 | 722 | |
720 | 723 | /** |
723 | 726 | * @throws LWJGLException If the context could not be made current |
724 | 727 | */ |
725 | 728 | public static void makeCurrent() throws LWJGLException { |
726 | synchronized ( GlobalLock.lock ) { | |
727 | if ( !isCreated() ) | |
728 | throw new IllegalStateException("Display is not created"); | |
729 | context.makeCurrent(); | |
730 | } | |
729 | drawable.makeCurrent(); | |
731 | 730 | } |
732 | 731 | |
733 | 732 | private static void removeShutdownHook() { |
847 | 846 | throw new NullPointerException("pixel_format cannot be null"); |
848 | 847 | removeShutdownHook(); |
849 | 848 | registerShutdownHook(); |
850 | if (isFullscreen()) | |
849 | if ( isFullscreen() ) | |
851 | 850 | switchDisplayMode(); |
852 | 851 | try { |
853 | peer_info = display_impl.createPeerInfo(pixel_format); | |
852 | drawable.peer_info = display_impl.createPeerInfo(pixel_format); | |
854 | 853 | try { |
855 | 854 | createWindow(); |
856 | 855 | try { |
857 | context = new Context(peer_info, attribs, shared_drawable != null ? shared_drawable.getContext() : null); | |
856 | drawable.context = new Context(drawable.peer_info, attribs, shared_drawable != null ? ((AbstractDrawable)shared_drawable).getContext() : null); | |
858 | 857 | try { |
859 | 858 | makeCurrentAndSetSwapInterval(); |
860 | 859 | initContext(); |
861 | 860 | } catch (LWJGLException e) { |
862 | destroyContext(); | |
861 | drawable.destroy(); | |
863 | 862 | throw e; |
864 | 863 | } |
865 | 864 | } catch (LWJGLException e) { |
867 | 866 | throw e; |
868 | 867 | } |
869 | 868 | } catch (LWJGLException e) { |
870 | destroyPeerInfo(); | |
869 | drawable.destroy(); | |
871 | 870 | throw e; |
872 | 871 | } |
873 | 872 | } catch (LWJGLException e) { |
878 | 877 | } |
879 | 878 | |
880 | 879 | /** |
881 | * Set the initial color of the Display. This method is called before the Display is created and will set the | |
882 | * background color to the one specified in this method. | |
883 | * | |
884 | * @param red - color value between 0 - 1 | |
885 | * @param green - color value between 0 - 1 | |
886 | * @param blue - color value between 0 - 1 | |
887 | */ | |
880 | * Set the initial color of the Display. This method is called before the Display is created and will set the | |
881 | * background color to the one specified in this method. | |
882 | * | |
883 | * @param red - color value between 0 - 1 | |
884 | * @param green - color value between 0 - 1 | |
885 | * @param blue - color value between 0 - 1 | |
886 | */ | |
888 | 887 | public static void setInitialBackground(float red, float green, float blue) { |
889 | 888 | r = red; |
890 | 889 | g = green; |
956 | 955 | * regardless of whether the Display was the current rendering context. |
957 | 956 | */ |
958 | 957 | public static void destroy() { |
959 | synchronized ( GlobalLock.lock ) { | |
960 | if ( !isCreated() ) { | |
961 | return; | |
962 | } | |
963 | ||
964 | releaseDrawable(); | |
965 | destroyContext(); | |
966 | destroyWindow(); | |
967 | destroyPeerInfo(); | |
968 | x = y = -1; | |
969 | cached_icons = null; | |
970 | reset(); | |
971 | removeShutdownHook(); | |
972 | } | |
973 | } | |
974 | ||
975 | private static void destroyPeerInfo() { | |
976 | peer_info.destroy(); | |
977 | peer_info = null; | |
978 | } | |
979 | ||
980 | private static void destroyContext() { | |
981 | try { | |
982 | context.forceDestroy(); | |
983 | } catch (LWJGLException e) { | |
984 | throw new RuntimeException(e); | |
985 | } finally { | |
986 | context = null; | |
987 | } | |
958 | drawable.destroy(); | |
988 | 959 | } |
989 | 960 | |
990 | 961 | /* |
991 | 962 | * Reset display mode if fullscreen. This method is also called from the shutdown hook added |
992 | 963 | * in the static constructor |
993 | 964 | */ |
965 | ||
994 | 966 | private static void reset() { |
995 | 967 | display_impl.resetDisplayMode(); |
996 | 968 | current_mode = initial_mode; |
1049 | 1021 | y = new_y; |
1050 | 1022 | |
1051 | 1023 | // offset if already created |
1052 | if (isCreated() && !isFullscreen()) { | |
1024 | if ( isCreated() && !isFullscreen() ) { | |
1053 | 1025 | reshape(); |
1054 | 1026 | } |
1055 | 1027 | } |
30 | 30 | */ |
31 | 31 | package org.lwjgl.opengl; |
32 | 32 | |
33 | import org.lwjgl.LWJGLException; | |
34 | ||
33 | 35 | /** |
34 | 36 | * The Drawable interface describes an OpenGL drawable with an associated |
35 | 37 | * Context. |
38 | 40 | */ |
39 | 41 | |
40 | 42 | public interface Drawable { |
41 | Context getContext(); | |
43 | ||
44 | /** Returns true if the Drawable's context is current in the current thread. */ | |
45 | boolean isCurrent() throws LWJGLException; | |
46 | ||
47 | /** | |
48 | * Makes the Drawable's context current in the current thread. | |
49 | * | |
50 | * @throws LWJGLException | |
51 | */ | |
52 | void makeCurrent() throws LWJGLException; | |
53 | ||
54 | /** | |
55 | * If the Drawable's context is current in the current thread, no context will be current after a call to this method. | |
56 | * | |
57 | * @throws LWJGLException | |
58 | */ | |
59 | void releaseContext() throws LWJGLException; | |
60 | ||
61 | /** Destroys the Drawable. */ | |
62 | void destroy(); | |
63 | ||
42 | 64 | } |
0 | package org.lwjgl.opengl; | |
1 | ||
2 | import org.lwjgl.LWJGLException; | |
3 | ||
4 | /** | |
5 | * @author Spasi | |
6 | */ | |
7 | interface DrawableLWJGL extends Drawable { | |
8 | ||
9 | /** | |
10 | * [INTERNAL USE ONLY] Returns the Drawable's Context. | |
11 | * | |
12 | * @return the Drawable's Context | |
13 | */ | |
14 | Context getContext(); | |
15 | ||
16 | /** | |
17 | * [INTERNAL USE ONLY] Creates a new Context that is shared with the Drawable's Context. | |
18 | * | |
19 | * @return a Context shared with the Drawable's Context. | |
20 | */ | |
21 | Context createSharedContext() throws LWJGLException; | |
22 | ||
23 | } |
34 | 34 | import java.nio.IntBuffer; |
35 | 35 | |
36 | 36 | import org.lwjgl.BufferUtils; |
37 | import org.lwjgl.LWJGLUtil; | |
37 | 38 | |
38 | 39 | /** |
39 | 40 | * A class to check buffer boundaries in GL methods. Many GL |
45 | 46 | * Thrown by the debug build library of the LWJGL if any OpenGL operation causes an error. |
46 | 47 | * |
47 | 48 | * @author cix_foo <cix_foo@users.sourceforge.net> |
48 | * @version $Revision: 3279 $ | |
49 | * $Id: GLChecks.java 3279 2010-03-11 21:06:49Z spasi $ | |
49 | * @version $Revision: 3334 $ | |
50 | * $Id: GLChecks.java 3334 2010-04-22 23:21:48Z spasi $ | |
50 | 51 | */ |
51 | 52 | class GLChecks { |
52 | 53 | |
59 | 60 | } |
60 | 61 | |
61 | 62 | static int getBufferObjectSize(ContextCapabilities caps, int buffer_enum) { |
62 | IntBuffer scratch_buffer = caps.scratch_int_buffer; | |
63 | GL15.glGetBufferParameter(buffer_enum, GL15.GL_BUFFER_SIZE, scratch_buffer); | |
64 | return scratch_buffer.get(0); | |
63 | return GL15.glGetBufferParameter(buffer_enum, GL15.GL_BUFFER_SIZE); | |
65 | 64 | } |
66 | 65 | |
67 | 66 | static int getBufferObjectSizeARB(ContextCapabilities caps, int buffer_enum) { |
68 | IntBuffer scratch_buffer = caps.scratch_int_buffer; | |
69 | ARBBufferObject.glGetBufferParameterARB(buffer_enum, ARBBufferObject.GL_BUFFER_SIZE_ARB, scratch_buffer); | |
70 | return scratch_buffer.get(0); | |
67 | return ARBBufferObject.glGetBufferParameterARB(buffer_enum, ARBBufferObject.GL_BUFFER_SIZE_ARB); | |
71 | 68 | } |
72 | 69 | |
73 | 70 | static int getBufferObjectSizeATI(ContextCapabilities caps, int buffer) { |
74 | IntBuffer scratch_buffer = caps.scratch_int_buffer; | |
75 | ATIVertexArrayObject.glGetObjectBufferATI(buffer, ATIVertexArrayObject.GL_OBJECT_BUFFER_SIZE_ATI, scratch_buffer); | |
76 | return scratch_buffer.get(0); | |
71 | return ATIVertexArrayObject.glGetObjectBufferATI(buffer, ATIVertexArrayObject.GL_OBJECT_BUFFER_SIZE_ATI); | |
77 | 72 | } |
78 | 73 | |
79 | 74 | static int getNamedBufferObjectSize(ContextCapabilities caps, int buffer) { |
80 | IntBuffer scratch_buffer = caps.scratch_int_buffer; | |
81 | EXTDirectStateAccess.glGetNamedBufferParameterEXT(buffer, GL15.GL_BUFFER_SIZE, scratch_buffer); | |
82 | return scratch_buffer.get(0); | |
83 | } | |
84 | ||
85 | private static boolean checkBufferObject(ContextCapabilities caps, int buffer_enum, boolean state) { | |
86 | IntBuffer scratch_buffer = caps.scratch_int_buffer; | |
87 | GL11.glGetInteger(buffer_enum, scratch_buffer); | |
88 | boolean is_enabled = scratch_buffer.get(0) != 0; | |
89 | return state == is_enabled; | |
75 | return EXTDirectStateAccess.glGetNamedBufferParameterEXT(buffer, GL15.GL_BUFFER_SIZE); | |
90 | 76 | } |
91 | 77 | |
92 | 78 | /** Helper method to ensure that array buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */ |
93 | 79 | static void ensureArrayVBOdisabled(ContextCapabilities caps) { |
94 | if(StateTracker.getReferencesStack(caps).getReferences().arrayBuffer != 0) | |
80 | if( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().arrayBuffer != 0 ) | |
95 | 81 | throw new OpenGLException("Cannot use Buffers when Array Buffer Object is enabled"); |
96 | 82 | } |
97 | 83 | |
98 | 84 | /** Helper method to ensure that array buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */ |
99 | 85 | static void ensureArrayVBOenabled(ContextCapabilities caps) { |
100 | if(StateTracker.getReferencesStack(caps).getReferences().arrayBuffer == 0) | |
86 | if( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().arrayBuffer == 0 ) | |
101 | 87 | throw new OpenGLException("Cannot use offsets when Array Buffer Object is disabled"); |
102 | 88 | } |
103 | 89 | |
104 | 90 | /** Helper method to ensure that element array buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */ |
105 | 91 | static void ensureElementVBOdisabled(ContextCapabilities caps) { |
106 | if(StateTracker.getReferencesStack(caps).getReferences().elementArrayBuffer != 0) | |
92 | if( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().elementArrayBuffer != 0 ) | |
107 | 93 | throw new OpenGLException("Cannot use Buffers when Element Array Buffer Object is enabled"); |
108 | 94 | } |
109 | 95 | |
110 | 96 | /** Helper method to ensure that element array buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */ |
111 | 97 | static void ensureElementVBOenabled(ContextCapabilities caps) { |
112 | if(StateTracker.getReferencesStack(caps).getReferences().elementArrayBuffer == 0) | |
98 | if( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().elementArrayBuffer == 0 ) | |
113 | 99 | throw new OpenGLException("Cannot use offsets when Element Array Buffer Object is disabled"); |
114 | 100 | } |
115 | 101 | |
116 | 102 | /** Helper method to ensure that array buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */ |
117 | 103 | static void ensureIndirectBOdisabled(ContextCapabilities caps) { |
118 | if ( StateTracker.getReferencesStack(caps).getReferences().indirectBuffer != 0 ) | |
104 | if ( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().indirectBuffer != 0 ) | |
119 | 105 | throw new OpenGLException("Cannot use Buffers when Draw Indirect Object is enabled"); |
120 | 106 | } |
121 | 107 | |
122 | 108 | /** Helper method to ensure that array buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */ |
123 | 109 | static void ensureIndirectBOenabled(ContextCapabilities caps) { |
124 | if ( StateTracker.getReferencesStack(caps).getReferences().indirectBuffer == 0 ) | |
110 | if ( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().indirectBuffer == 0 ) | |
125 | 111 | throw new OpenGLException("Cannot use offsets when Draw Indirect Object is disabled"); |
126 | 112 | } |
127 | 113 | |
128 | 114 | /** Helper method to ensure that pixel pack buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */ |
129 | 115 | static void ensurePackPBOdisabled(ContextCapabilities caps) { |
130 | if ( StateTracker.getReferencesStack(caps).getReferences().pixelPackBuffer != 0 ) | |
116 | if ( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().pixelPackBuffer != 0 ) | |
131 | 117 | throw new OpenGLException("Cannot use Buffers when Pixel Pack Buffer Object is enabled"); |
132 | 118 | } |
133 | 119 | |
134 | 120 | /** Helper method to ensure that pixel pack buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */ |
135 | 121 | static void ensurePackPBOenabled(ContextCapabilities caps) { |
136 | if ( StateTracker.getReferencesStack(caps).getReferences().pixelPackBuffer == 0 ) | |
122 | if ( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().pixelPackBuffer == 0 ) | |
137 | 123 | throw new OpenGLException("Cannot use offsets when Pixel Pack Buffer Object is disabled"); |
138 | 124 | } |
139 | 125 | |
140 | 126 | /** Helper method to ensure that pixel unpack buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */ |
141 | 127 | static void ensureUnpackPBOdisabled(ContextCapabilities caps) { |
142 | if ( StateTracker.getReferencesStack(caps).getReferences().pixelUnpackBuffer != 0 ) | |
128 | if ( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().pixelUnpackBuffer != 0 ) | |
143 | 129 | throw new OpenGLException("Cannot use Buffers when Pixel Unpack Buffer Object is enabled"); |
144 | 130 | } |
145 | 131 | |
146 | 132 | /** Helper method to ensure that pixel unpack buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */ |
147 | 133 | static void ensureUnpackPBOenabled(ContextCapabilities caps) { |
148 | if ( StateTracker.getReferencesStack(caps).getReferences().pixelUnpackBuffer == 0 ) | |
134 | if ( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().pixelUnpackBuffer == 0 ) | |
149 | 135 | throw new OpenGLException("Cannot use offsets when Pixel Unpack Buffer Object is disabled"); |
150 | 136 | } |
151 | 137 | |
161 | 147 | * @return the size, in elements, of the image |
162 | 148 | */ |
163 | 149 | static int calculateImageStorage(Buffer buffer, int format, int type, int width, int height, int depth) { |
164 | return calculateImageStorage(format, type, width, height, depth) >> BufferUtils.getElementSizeExponent(buffer); | |
150 | return LWJGLUtil.CHECKS ? calculateImageStorage(format, type, width, height, depth) >> BufferUtils.getElementSizeExponent(buffer) : 0; | |
165 | 151 | } |
166 | 152 | |
167 | 153 | static int calculateTexImage1DStorage(Buffer buffer, int format, int type, int width) { |
168 | return calculateTexImage1DStorage(format, type, width) >> BufferUtils.getElementSizeExponent(buffer); | |
154 | return LWJGLUtil.CHECKS ? calculateTexImage1DStorage(format, type, width) >> BufferUtils.getElementSizeExponent(buffer) : 0; | |
169 | 155 | } |
170 | 156 | |
171 | 157 | static int calculateTexImage2DStorage(Buffer buffer, int format, int type, int width, int height) { |
172 | return calculateTexImage2DStorage(format, type, width, height) >> BufferUtils.getElementSizeExponent(buffer); | |
158 | return LWJGLUtil.CHECKS ? calculateTexImage2DStorage(format, type, width, height) >> BufferUtils.getElementSizeExponent(buffer) : 0; | |
173 | 159 | } |
174 | 160 | |
175 | 161 | static int calculateTexImage3DStorage(Buffer buffer, int format, int type, int width, int height, int depth) { |
176 | return calculateTexImage3DStorage(format, type, width, height, depth) >> BufferUtils.getElementSizeExponent(buffer); | |
162 | return LWJGLUtil.CHECKS ? calculateTexImage3DStorage(format, type, width, height, depth) >> BufferUtils.getElementSizeExponent(buffer) : 0; | |
177 | 163 | } |
178 | 164 | |
179 | 165 | /** |
53 | 53 | * That way, multiple threads can have multiple contexts current and render to them concurrently. |
54 | 54 | * |
55 | 55 | * @author elias_naur <elias_naur@users.sourceforge.net> |
56 | * @version $Revision: 3279 $ | |
57 | * $Id: GLContext.java 3279 2010-03-11 21:06:49Z spasi $ | |
56 | * @version $Revision: 3355 $ | |
57 | * $Id: GLContext.java 3355 2010-05-27 22:56:29Z spasi $ | |
58 | 58 | */ |
59 | 59 | public final class GLContext { |
60 | 60 | |
168 | 168 | return 0; |
169 | 169 | } |
170 | 170 | |
171 | /** | |
172 | * Helper method to get a pointer to a named function with aliases in the OpenGL library. | |
173 | * | |
174 | * @param aliases the function name aliases. | |
175 | * | |
176 | * @return the function pointer address | |
177 | */ | |
178 | static long getFunctionAddress(String[] aliases) { | |
179 | for ( int i = 0; i < aliases.length; i++ ) { | |
180 | long address = getFunctionAddress(aliases[i]); | |
181 | if ( address != 0 ) | |
182 | return address; | |
183 | } | |
184 | return 0; | |
185 | } | |
186 | ||
171 | 187 | /** Helper method to get a pointer to a named function in the OpenGL library */ |
172 | 188 | static native long getFunctionAddress(String name); |
173 | 189 |
38 | 38 | */ |
39 | 39 | |
40 | 40 | import java.awt.Canvas; |
41 | import java.io.BufferedReader; | |
42 | import java.io.IOException; | |
43 | import java.io.InputStreamReader; | |
41 | 44 | import java.nio.ByteBuffer; |
42 | 45 | import java.nio.FloatBuffer; |
43 | 46 | import java.nio.IntBuffer; |
46 | 49 | import org.lwjgl.LWJGLException; |
47 | 50 | import org.lwjgl.LWJGLUtil; |
48 | 51 | import org.lwjgl.opengl.XRandR.Screen; |
52 | ||
53 | import java.security.AccessController; | |
54 | import java.security.PrivilegedAction; | |
55 | import java.util.ArrayList; | |
56 | import java.util.Iterator; | |
57 | import java.util.List; | |
49 | 58 | |
50 | 59 | final class LinuxDisplay implements DisplayImplementation { |
51 | 60 | /* X11 constants */ |
406 | 415 | ByteBuffer handle = peer_info.lockAndGetHandle(); |
407 | 416 | try { |
408 | 417 | current_window_mode = getWindowMode(Display.isFullscreen()); |
409 | boolean undecorated = Display.getPrivilegedBoolean("org.lwjgl.opengl.Window.undecorated") || current_window_mode != WINDOWED; | |
418 | // Try to enable Lecagy FullScreen Support in Compiz, else | |
419 | // we may have trouble with stuff overlapping our fullscreen window. | |
420 | if ( current_window_mode != WINDOWED ) | |
421 | Compiz.setLegacyFullscreenSupport(true); | |
422 | // Setting _MOTIF_WM_HINTS in fullscreen mode is problematic for certain window | |
423 | // managers. We do not set MWM_HINTS_DECORATIONS in fullscreen mode anymore, | |
424 | // unless org.lwjgl.opengl.Window.undecorated_fs has been specified. | |
425 | // See native/linux/org_lwjgl_opengl_Display.c, createWindow function. | |
426 | boolean undecorated = Display.getPrivilegedBoolean("org.lwjgl.opengl.Window.undecorated") || (current_window_mode != WINDOWED && Display.getPrivilegedBoolean("org.lwjgl.opengl.Window.undecorated_fs")); | |
410 | 427 | this.parent = parent; |
411 | 428 | parent_window = parent != null ? getHandle(parent) : getRootWindow(getDisplay(), getDefaultScreen()); |
412 | 429 | current_window = nCreateWindow(getDisplay(), getDefaultScreen(), handle, mode, current_window_mode, x, y, undecorated, parent_window); |
440 | 457 | private static native void mapRaised(long display, long window); |
441 | 458 | private static native void reparentWindow(long display, long window, long parent, int x, int y); |
442 | 459 | |
443 | private boolean isAncestorXEmbedded(long window) throws LWJGLException { | |
460 | private static boolean isAncestorXEmbedded(long window) throws LWJGLException { | |
444 | 461 | long xembed_atom = internAtom("_XEMBED_INFO", true); |
445 | 462 | if (xembed_atom != None) { |
446 | 463 | long w = window; |
482 | 499 | ungrabKeyboard(); |
483 | 500 | nDestroyWindow(getDisplay(), getWindow()); |
484 | 501 | decDisplay(); |
502 | ||
503 | if ( current_window_mode != WINDOWED ) | |
504 | Compiz.setLegacyFullscreenSupport(false); | |
485 | 505 | } finally { |
486 | 506 | unlockAWT(); |
487 | 507 | } |
523 | 543 | try { |
524 | 544 | if( current_displaymode_extension == XRANDR && savedXrandrConfig.length > 0 ) |
525 | 545 | { |
526 | XRandR.setConfiguration( savedXrandrConfig ); | |
546 | AccessController.doPrivileged(new PrivilegedAction() { | |
547 | public Object run() { | |
548 | XRandR.setConfiguration( savedXrandrConfig ); | |
549 | return null; | |
550 | } | |
551 | }); | |
527 | 552 | } |
528 | 553 | else |
529 | 554 | { |
531 | 556 | } |
532 | 557 | if (isXF86VidModeSupported()) |
533 | 558 | doSetGamma(saved_gamma); |
559 | ||
560 | Compiz.setLegacyFullscreenSupport(false); | |
534 | 561 | } catch (LWJGLException e) { |
535 | 562 | LWJGLUtil.log("Caught exception while resetting mode: " + e); |
536 | 563 | } finally { |
605 | 632 | public DisplayMode init() throws LWJGLException { |
606 | 633 | lockAWT(); |
607 | 634 | try { |
635 | Compiz.init(); | |
636 | ||
608 | 637 | delete_atom = internAtom("WM_DELETE_WINDOW", false); |
609 | 638 | current_displaymode_extension = getBestDisplayModeExtension(); |
610 | 639 | if (current_displaymode_extension == NONE) |
614 | 643 | throw new LWJGLException("No modes available"); |
615 | 644 | switch (current_displaymode_extension) { |
616 | 645 | case XRANDR: |
617 | savedXrandrConfig = XRandR.getConfiguration(); | |
646 | savedXrandrConfig = (Screen[])AccessController.doPrivileged(new PrivilegedAction() { | |
647 | public Object run() { | |
648 | return XRandR.getConfiguration(); | |
649 | } | |
650 | }); | |
618 | 651 | saved_mode = getCurrentXRandrMode(); |
619 | 652 | break; |
620 | 653 | case XF86VIDMODE: |
846 | 879 | setInputFocusUnsafe(current_window); |
847 | 880 | } |
848 | 881 | else if (xembedded) { |
849 | setInputFocusUnsafe(0); | |
850 | } | |
851 | } | |
852 | else if (parent_focus && !focused) { | |
853 | setInputFocusUnsafe(current_window); | |
854 | } | |
882 | setInputFocusUnsafe(1); | |
883 | } | |
884 | } | |
885 | //else if (parent_focus && !focused && !xembedded) { | |
886 | // setInputFocusUnsafe(current_window); | |
887 | //} | |
855 | 888 | } |
856 | 889 | |
857 | 890 | private void setFocused(boolean got_focus, int focus_detail) { |
889 | 922 | try { |
890 | 923 | if( current_displaymode_extension == XRANDR && savedXrandrConfig.length > 0 ) |
891 | 924 | { |
892 | XRandR.setConfiguration( savedXrandrConfig ); | |
925 | AccessController.doPrivileged(new PrivilegedAction() { | |
926 | public Object run() { | |
927 | XRandR.setConfiguration( savedXrandrConfig ); | |
928 | return null; | |
929 | } | |
930 | }); | |
893 | 931 | } |
894 | 932 | else |
895 | 933 | { |
1211 | 1249 | public boolean isInsideWindow() { |
1212 | 1250 | return true; |
1213 | 1251 | } |
1214 | } | |
1252 | ||
1253 | /** | |
1254 | * Helper class for managing Compiz's workarounds. We need this to enable Legacy | |
1255 | * Fullscreen Support in Compiz, else we'll have trouble with fullscreen windows | |
1256 | * when Compiz effects are enabled. | |
1257 | * | |
1258 | * Implementation Note: This code is probably too much for an inner class, but | |
1259 | * keeping it here until we're sure we cannot find a better solution. | |
1260 | */ | |
1261 | private static final class Compiz { | |
1262 | ||
1263 | private static boolean applyFix; | |
1264 | ||
1265 | private static Provider provider; | |
1266 | ||
1267 | private Compiz() { | |
1268 | } | |
1269 | ||
1270 | static void init() { | |
1271 | if ( Display.getPrivilegedBoolean("org.lwjgl.opengl.Window.nocompiz_lfs") ) | |
1272 | return; | |
1273 | ||
1274 | AccessController.doPrivileged(new PrivilegedAction() { | |
1275 | public Object run() { | |
1276 | try { | |
1277 | // Check if Compiz is active | |
1278 | if ( !isProcessActive("compiz") ) | |
1279 | return null; | |
1280 | ||
1281 | provider = null; | |
1282 | ||
1283 | String providerName = null; | |
1284 | ||
1285 | // Check if Dbus is available | |
1286 | if ( isProcessActive("dbus-daemon") ) { | |
1287 | providerName = "Dbus"; | |
1288 | provider = new Provider() { | |
1289 | ||
1290 | private static final String KEY = "/org/freedesktop/compiz/workarounds/allscreens/legacy_fullscreen"; | |
1291 | ||
1292 | public boolean hasLegacyFullscreenSupport() throws LWJGLException { | |
1293 | final List output = Compiz.run(new String[] { | |
1294 | "dbus-send", "--print-reply", "--type=method_call", "--dest=org.freedesktop.compiz", KEY, "org.freedesktop.compiz.get" | |
1295 | }); | |
1296 | ||
1297 | if ( output == null || output.size() < 2 ) | |
1298 | throw new LWJGLException("Invalid Dbus reply."); | |
1299 | ||
1300 | String line = (String)output.get(0); | |
1301 | ||
1302 | if ( !line.startsWith("method return") ) | |
1303 | throw new LWJGLException("Invalid Dbus reply."); | |
1304 | ||
1305 | line = ((String)output.get(1)).trim(); // value | |
1306 | if ( !line.startsWith("boolean") || line.length() < 12) | |
1307 | throw new LWJGLException("Invalid Dbus reply."); | |
1308 | ||
1309 | return "true".equalsIgnoreCase(line.substring("boolean".length() + 1)); | |
1310 | } | |
1311 | ||
1312 | public void setLegacyFullscreenSupport(final boolean state) throws LWJGLException { | |
1313 | if ( Compiz.run(new String[] { | |
1314 | "dbus-send", "--type=method_call", "--dest=org.freedesktop.compiz", KEY, "org.freedesktop.compiz.set", "boolean:" + Boolean.toString(state) | |
1315 | }) == null ) | |
1316 | throw new LWJGLException("Failed to apply Compiz LFS workaround."); | |
1317 | } | |
1318 | }; | |
1319 | } else { | |
1320 | try { | |
1321 | // Check if Gconf is available | |
1322 | Runtime.getRuntime().exec("gconftool"); | |
1323 | ||
1324 | providerName = "gconftool"; | |
1325 | provider = new Provider() { | |
1326 | ||
1327 | private static final String KEY = "/apps/compiz/plugins/workarounds/allscreens/options/legacy_fullscreen"; | |
1328 | ||
1329 | public boolean hasLegacyFullscreenSupport() throws LWJGLException { | |
1330 | final List output = Compiz.run(new String[] { | |
1331 | "gconftool", "-g", KEY | |
1332 | }); | |
1333 | ||
1334 | if ( output == null || output.size() == 0 ) | |
1335 | throw new LWJGLException("Invalid gconftool reply."); | |
1336 | ||
1337 | return Boolean.parseBoolean(((String)output.get(0)).trim()); | |
1338 | } | |
1339 | ||
1340 | public void setLegacyFullscreenSupport(final boolean state) throws LWJGLException { | |
1341 | if ( Compiz.run(new String[] { | |
1342 | "gconftool", "-s", KEY, "-s", Boolean.toString(state), "-t", "bool" | |
1343 | }) == null ) | |
1344 | throw new LWJGLException("Failed to apply Compiz LFS workaround."); | |
1345 | ||
1346 | if ( state ) { | |
1347 | try { | |
1348 | // gconftool will not apply the workaround immediately, sleep a bit | |
1349 | // to make sure it will be ok when we create the window. | |
1350 | Thread.sleep(200); // 100 is too low, 150 works, set to 200 to be safe. | |
1351 | } catch (InterruptedException e) { | |
1352 | e.printStackTrace(); | |
1353 | } | |
1354 | } | |
1355 | } | |
1356 | }; | |
1357 | } catch (IOException e) { | |
1358 | // Ignore | |
1359 | } | |
1360 | } | |
1361 | ||
1362 | if ( provider != null && !provider.hasLegacyFullscreenSupport() ) { // No need to do anything if LFS is already enabled. | |
1363 | applyFix = true; | |
1364 | LWJGLUtil.log("Using " + providerName + " to apply Compiz LFS workaround."); | |
1365 | } | |
1366 | } catch (LWJGLException e) { | |
1367 | // Ignore | |
1368 | } finally { | |
1369 | return null; | |
1370 | } | |
1371 | } | |
1372 | }); | |
1373 | } | |
1374 | ||
1375 | static void setLegacyFullscreenSupport(final boolean enabled) { | |
1376 | if ( !applyFix ) | |
1377 | return; | |
1378 | ||
1379 | AccessController.doPrivileged(new PrivilegedAction() { | |
1380 | public Object run() { | |
1381 | try { | |
1382 | provider.setLegacyFullscreenSupport(enabled); | |
1383 | } catch (LWJGLException e) { | |
1384 | LWJGLUtil.log("Failed to change Compiz Legacy Fullscreen Support. Reason: " + e.getMessage()); | |
1385 | } | |
1386 | return null; | |
1387 | } | |
1388 | }); | |
1389 | } | |
1390 | ||
1391 | private static List run(final String[] command) throws LWJGLException { | |
1392 | final List output = new ArrayList(); | |
1393 | ||
1394 | try { | |
1395 | final Process p = Runtime.getRuntime().exec(command); | |
1396 | try { | |
1397 | final int exitValue = p.waitFor(); | |
1398 | if ( exitValue != 0 ) | |
1399 | return null; | |
1400 | } catch (InterruptedException e) { | |
1401 | throw new LWJGLException("Process interrupted.", e); | |
1402 | } | |
1403 | ||
1404 | final BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); | |
1405 | ||
1406 | String line; | |
1407 | while ( (line = br.readLine()) != null ) | |
1408 | output.add(line); | |
1409 | ||
1410 | br.close(); | |
1411 | } catch (final IOException e) { | |
1412 | throw new LWJGLException("Process failed.", e); | |
1413 | } | |
1414 | ||
1415 | return output; | |
1416 | } | |
1417 | ||
1418 | private static boolean isProcessActive(final String processName) throws LWJGLException { | |
1419 | final List output = run(new String[] { "ps", "-C", processName }); | |
1420 | if ( output == null ) | |
1421 | return false; | |
1422 | ||
1423 | for ( Iterator iter = output.iterator(); iter.hasNext(); ) { | |
1424 | final String line = (String)iter.next(); | |
1425 | if ( line.contains(processName) ); | |
1426 | return true; | |
1427 | } | |
1428 | ||
1429 | return false; | |
1430 | } | |
1431 | ||
1432 | private interface Provider { | |
1433 | ||
1434 | boolean hasLegacyFullscreenSupport() throws LWJGLException; | |
1435 | ||
1436 | void setLegacyFullscreenSupport(boolean state) throws LWJGLException; | |
1437 | ||
1438 | } | |
1439 | } | |
1440 | ||
1441 | }⏎ |
77 | 77 | AccessController.doPrivileged(new PrivilegedExceptionAction() { |
78 | 78 | public Object run() throws Exception { |
79 | 79 | Application.getApplication().addApplicationListener(new ApplicationAdapter() { |
80 | public final void handleQuit(ApplicationEvent event) { | |
80 | public void handleQuit(ApplicationEvent event) { | |
81 | 81 | doHandleQuit(); |
82 | 82 | } |
83 | 83 | }); |
270 | 270 | * |
271 | 271 | * - elias |
272 | 272 | */ |
273 | AbstractDrawable drawable = (AbstractDrawable)Display.getDrawable(); | |
273 | 274 | if (Display.isFullscreen() && (frame != null && frame.getCanvas().syncCanvasPainted() || should_update)) { |
274 | 275 | try { |
275 | MacOSXContextImplementation.resetView(Display.getDrawable().getContext().getPeerInfo(), Display.getDrawable().getContext()); | |
276 | MacOSXContextImplementation.resetView(drawable.peer_info, drawable.context); | |
276 | 277 | } catch (LWJGLException e) { |
277 | 278 | LWJGLUtil.log("Failed to reset context: " + e); |
278 | 279 | } |
279 | 280 | } |
280 | 281 | if (should_update) { |
281 | Display.getDrawable().getContext().update(); | |
282 | drawable.context.update(); | |
282 | 283 | /* This is necessary to make sure the context won't "forget" about the view size */ |
283 | 284 | GL11.glGetInteger(GL11.GL_VIEWPORT, current_viewport); |
284 | 285 | GL11.glViewport(current_viewport.get(0), current_viewport.get(1), current_viewport.get(2), current_viewport.get(3)); |
34 | 34 | |
35 | 35 | import org.lwjgl.BufferUtils; |
36 | 36 | import org.lwjgl.LWJGLException; |
37 | import org.lwjgl.LWJGLUtil; | |
38 | 37 | import org.lwjgl.Sys; |
39 | 38 | |
40 | 39 | /** |
45 | 44 | * This class is thread-safe. |
46 | 45 | * |
47 | 46 | * @author elias_naur <elias_naur@users.sourceforge.net> |
48 | * @version $Revision: 3116 $ | |
49 | * $Id: Pbuffer.java 3116 2008-08-19 16:46:03Z spasi $ | |
47 | * @version $Revision: 3334 $ | |
48 | * $Id: Pbuffer.java 3334 2010-04-22 23:21:48Z spasi $ | |
50 | 49 | */ |
51 | public final class Pbuffer implements Drawable { | |
50 | public final class Pbuffer extends AbstractDrawable { | |
52 | 51 | /** |
53 | 52 | * Indicates that Pbuffers can be created. |
54 | 53 | */ |
135 | 134 | public static final int DEPTH_BUFFER = RenderTexture.WGL_DEPTH_COMPONENT_NV; |
136 | 135 | |
137 | 136 | /** |
138 | * Handle to the native GL rendering context | |
139 | */ | |
140 | private final PeerInfo peer_info; | |
141 | ||
142 | /** | |
143 | 137 | * Width |
144 | 138 | */ |
145 | 139 | private final int width; |
148 | 142 | * Height |
149 | 143 | */ |
150 | 144 | private final int height; |
151 | ||
152 | private final Context context; | |
153 | ||
154 | private boolean destroyed; | |
155 | 145 | |
156 | 146 | static { |
157 | 147 | Sys.initialize(); |
226 | 216 | this.width = width; |
227 | 217 | this.height = height; |
228 | 218 | this.peer_info = createPbuffer(width, height, pixel_format, renderTexture); |
229 | Context shared_context = null; | |
230 | if (shared_drawable != null) { | |
231 | shared_context = shared_drawable.getContext(); | |
232 | } else { | |
233 | Drawable display_drawable = Display.getDrawable(); | |
234 | if (display_drawable != null) | |
235 | shared_context = display_drawable.getContext(); | |
236 | } | |
219 | Context shared_context; | |
220 | if (shared_drawable != null) | |
221 | shared_context = ((DrawableLWJGL)shared_drawable).getContext(); | |
222 | else | |
223 | shared_context = ((DrawableLWJGL)Display.getDrawable()).getContext(); // May be null | |
237 | 224 | this.context = new Context(peer_info, attribs, shared_context); |
238 | 225 | } |
239 | 226 | |
250 | 237 | renderTexture.pBufferAttribs); |
251 | 238 | } |
252 | 239 | |
253 | public Context getContext() { | |
254 | return context; | |
255 | } | |
256 | ||
257 | private void checkDestroyed() { | |
258 | if (destroyed) | |
259 | throw new IllegalStateException("Pbuffer is destroyed"); | |
260 | } | |
261 | ||
262 | 240 | /** |
263 | 241 | * Method to test for validity of the buffer. If this function returns true, the buffer contents is lost. The buffer can still |
264 | 242 | * be used, but the results are undefined. The application is expected to release the buffer if needed, destroy it and recreate |
272 | 250 | } |
273 | 251 | |
274 | 252 | /** |
275 | * Method to make the Pbuffer context current. All subsequent OpenGL calls will go to this buffer. | |
276 | * @throws LWJGLException if the context could not be made current | |
277 | */ | |
278 | public synchronized void makeCurrent() throws LWJGLException { | |
279 | checkDestroyed(); | |
280 | context.makeCurrent(); | |
281 | } | |
282 | ||
283 | /** | |
284 | 253 | * Gets the Pbuffer capabilities. |
285 | 254 | * |
286 | 255 | * @return a bitmask of Pbuffer capabilities. |
287 | 256 | */ |
288 | 257 | public static int getCapabilities() { |
289 | 258 | return Display.getImplementation().getPbufferCapabilities(); |
290 | } | |
291 | ||
292 | /** | |
293 | * Destroys the Pbuffer. After this call, there will be no valid GL rendering context - regardless of whether this Pbuffer was | |
294 | * the current rendering context or not. | |
295 | */ | |
296 | public synchronized void destroy() { | |
297 | if (destroyed) | |
298 | return; | |
299 | try { | |
300 | context.forceDestroy(); | |
301 | peer_info.destroy(); | |
302 | destroyed = true; | |
303 | } catch (LWJGLException e) { | |
304 | LWJGLUtil.log("Exception occurred while destroying pbuffer: " + e); | |
305 | } | |
306 | 259 | } |
307 | 260 | |
308 | 261 | // ----------------------------------------------------------------------------------------- |
44 | 44 | * pixel format selection path, which could trigger a crash. |
45 | 45 | * |
46 | 46 | * @author elias_naur@sourceforge.net |
47 | * @version $Revision: 3116 $ | |
47 | * @version $Revision: 3355 $ | |
48 | 48 | */ |
49 | 49 | |
50 | 50 | public final class PixelFormat { |
65 | 65 | * 0 means that anti-aliasing is disabled. |
66 | 66 | */ |
67 | 67 | private int samples; |
68 | /** | |
69 | * The number of COLOR_SAMPLES_NV to use for Coverage Sample Anti-aliasing (CSAA). | |
70 | * When this number is greater than 0, the {@code samples} property will be treated | |
71 | * as if it were the COVERAGE_SAMPLES_NV property. | |
72 | * <p/> | |
73 | * This property is currently a no-op for the MacOS implementation. | |
74 | */ | |
75 | private int colorSamples; | |
68 | 76 | /** The number of auxiliary buffers */ |
69 | 77 | private int num_aux_buffers; |
70 | 78 | /** The number of bits per pixel in the accumulation buffer */ |
75 | 83 | private boolean stereo; |
76 | 84 | /** Whether this format specifies a floating point format */ |
77 | 85 | private boolean floating_point; |
78 | /** Whether this format specifies a packed floating point format (32 bit unsigned - R11F_G11F_B10F) */ | |
86 | /** | |
87 | * Whether this format specifies a packed floating point format (32 bit unsigned - R11F_G11F_B10F) | |
88 | * This property is currently a no-op for the MacOS implementation. | |
89 | */ | |
79 | 90 | private boolean floating_point_packed; |
80 | /** Whether this format specifies an sRGB format */ | |
91 | /** | |
92 | * Whether this format specifies an sRGB format | |
93 | * This property is currently a no-op for the MacOS implementation. | |
94 | */ | |
81 | 95 | private boolean sRGB; |
82 | 96 | |
83 | 97 | /** |
131 | 145 | this.stencil = pf.stencil; |
132 | 146 | |
133 | 147 | this.samples = pf.samples; |
148 | this.colorSamples = pf.colorSamples; | |
134 | 149 | |
135 | 150 | this.num_aux_buffers = pf.num_aux_buffers; |
136 | 151 | |
244 | 259 | return pf; |
245 | 260 | } |
246 | 261 | |
262 | /** | |
263 | * Returns a new PixelFormat object with the same properties as this PixelFormat and the new color samples values. | |
264 | * A value greater than 0 is valid only if the {@code samples} property is also greater than 0. Additionally, the | |
265 | * color samples value needs to be lower than or equal to the {@code samples} property. | |
266 | * | |
267 | * @param colorSamples the new color samples value. | |
268 | * | |
269 | * @return the new PixelFormat | |
270 | */ | |
271 | public PixelFormat withCoverageSamples(final int colorSamples) { | |
272 | return withCoverageSamples(colorSamples, samples); | |
273 | } | |
274 | ||
275 | /** | |
276 | * Returns a new PixelFormat object with the same properties as this PixelFormat and the new color samples | |
277 | * and coverage samples values. | |
278 | * | |
279 | * @param colorSamples the new color samples value. This value must be lower than or equal to the coverage samples value. | |
280 | * @param coverageSamples the new coverage samples value. | |
281 | * | |
282 | * @return the new PixelFormat | |
283 | */ | |
284 | public PixelFormat withCoverageSamples(final int colorSamples, final int coverageSamples) { | |
285 | if ( coverageSamples < 0 || colorSamples < 0 || (coverageSamples == 0 && 0 < colorSamples) || coverageSamples < colorSamples ) | |
286 | throw new IllegalArgumentException("Invalid number of coverage samples specified: " + coverageSamples + " - " + colorSamples); | |
287 | ||
288 | final PixelFormat pf = new PixelFormat(this); | |
289 | pf.samples = coverageSamples; | |
290 | pf.colorSamples = colorSamples; | |
291 | return pf; | |
292 | } | |
293 | ||
247 | 294 | public int getAuxBuffers() { |
248 | 295 | return num_aux_buffers; |
249 | 296 | } |
0 | /* | |
1 | * Copyright (c) 2002-2008 LWJGL Project | |
2 | * All rights reserved. | |
3 | * | |
4 | * Redistribution and use in source and binary forms, with or without | |
5 | * modification, are permitted provided that the following conditions are | |
6 | * met: | |
7 | * | |
8 | * * Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * | |
11 | * * Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | |
14 | * | |
15 | * * Neither the name of 'LWJGL' nor the names of | |
16 | * its contributors may be used to endorse or promote products derived | |
17 | * from this software without specific prior written permission. | |
18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | |
31 | package org.lwjgl.opengl; | |
32 | ||
33 | import org.lwjgl.LWJGLException; | |
34 | ||
35 | /** | |
36 | * @author Spasi | |
37 | */ | |
38 | ||
39 | /** | |
40 | * A Drawable implementation that shares its context with another Drawable. This is useful | |
41 | * for background loading of resources. See org.lwjgl.test.opengl.multithread.BackgroundLoad | |
42 | * for an example. | |
43 | * | |
44 | * @author Spasi | |
45 | */ | |
46 | public final class SharedDrawable extends AbstractDrawable { | |
47 | ||
48 | public SharedDrawable(final Drawable drawable) throws LWJGLException { | |
49 | this.context = ((DrawableLWJGL)drawable).createSharedContext(); | |
50 | } | |
51 | ||
52 | public Context createSharedContext() { | |
53 | throw new UnsupportedOperationException(); | |
54 | } | |
55 | ||
56 | } |
436 | 436 | * is maximized helps some gfx cards recover from fullscreen |
437 | 437 | */ |
438 | 438 | try { |
439 | if (Display.getDrawable().getContext() != null && Display.getDrawable().getContext().isCurrent()) | |
440 | Display.getDrawable().getContext().makeCurrent(); | |
439 | Context context = ((DrawableLWJGL)Display.getDrawable()).getContext(); | |
440 | if (context != null && context.isCurrent()) | |
441 | context.makeCurrent(); | |
441 | 442 | } catch (LWJGLException e) { |
442 | 443 | LWJGLUtil.log("Exception occurred while trying to make context current: " + e); |
443 | 444 | } |
972 | 973 | return "Rect: top = " + top + " bottom = " + bottom + " left = " + left + " right = " + right; |
973 | 974 | } |
974 | 975 | } |
975 | } | |
976 | }⏎ |
0 | 0 | /* |
1 | * Copyright (c) 2002-2010 LWJGL Project | |
2 | * All rights reserved. | |
3 | * | |
1 | * Copyright (c) 2002-2010 LWJGL Project All rights reserved. | |
4 | 2 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions are | |
6 | * met: | |
7 | * | |
8 | * * Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * | |
11 | * * Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | |
14 | * | |
15 | * * Neither the name of 'LWJGL' nor the names of | |
16 | * its contributors may be used to endorse or promote products derived | |
17 | * from this software without specific prior written permission. | |
18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
3 | * modification, are permitted provided that the following conditions | |
4 | * are met: * Redistributions of source code must retain the above | |
5 | * copyright notice, this list of conditions and the following | |
6 | * disclaimer. * Redistributions in binary form must reproduce the | |
7 | * above copyright notice, this list of conditions and the following | |
8 | * disclaimer in the documentation and/or other materials provided | |
9 | * with the distribution. * Neither the name of 'LWJGL' nor the names | |
10 | * of its contributors may be used to endorse or promote products | |
11 | * derived from this software without specific prior written | |
12 | * permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |
13 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |
14 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
15 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
16 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS | |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, | |
18 | * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
25 | 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE | |
23 | * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH | |
24 | * DAMAGE. | |
30 | 25 | */ |
31 | 26 | |
32 | 27 | package org.lwjgl.opengl; |
38 | 33 | import java.util.HashMap; |
39 | 34 | import java.util.List; |
40 | 35 | import java.util.Map; |
36 | import java.util.regex.Matcher; | |
41 | 37 | import java.util.regex.Pattern; |
42 | import java.security.AccessController; | |
43 | import java.security.PrivilegedAction; | |
38 | ||
39 | import org.lwjgl.LWJGLUtil; | |
44 | 40 | |
45 | 41 | /** |
46 | 42 | * Utility for working with the xrandr commmand-line utility. Assumes |
48 | 44 | * |
49 | 45 | * @author ryanm |
50 | 46 | */ |
51 | public class XRandR { | |
52 | ||
53 | private static Screen[] current; | |
54 | ||
55 | private static Map /* <String, Screen[]> */screens; | |
56 | ||
57 | private static void populate() { | |
58 | if (screens == null) { | |
47 | public class XRandR | |
48 | { | |
49 | private static Screen[] current; | |
50 | ||
51 | private static Map /* <String, Screen[]> */screens; | |
52 | ||
53 | private static void populate() | |
54 | { | |
55 | if( screens == null ) | |
56 | { | |
59 | 57 | screens = new HashMap/* <String, Screen[]> */(); |
60 | 58 | |
61 | 59 | // ProcessBuilder pb = new ProcessBuilder( "xrandr", "-q" ); |
62 | 60 | // pb.redirectErrorStream(); |
63 | try { | |
61 | try | |
62 | { | |
64 | 63 | // Process p= pb.start(); |
65 | Process p = Runtime.getRuntime().exec(new String[] { "xrandr", "-q"}); | |
64 | Process p = Runtime.getRuntime().exec( new String[] { "xrandr", "-q" } ); | |
66 | 65 | |
67 | 66 | List/* <Screen> */currentList = new ArrayList/* <Screen> */(); |
68 | 67 | List/* <Screen> */possibles = new ArrayList/* <Screen> */(); |
69 | 68 | String name = null; |
70 | 69 | |
71 | BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); | |
70 | BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) ); | |
72 | 71 | String line; |
73 | while ((line = br.readLine()) != null) { | |
72 | while( ( line = br.readLine() ) != null ) | |
73 | { | |
74 | 74 | line = line.trim(); |
75 | String[] sa = line.split("\\s+"); | |
76 | ||
77 | if (sa[1].equals("connected")) { | |
75 | String[] sa = line.split( "\\s+" ); | |
76 | ||
77 | if( sa[ 1 ].equals( "connected" ) ) | |
78 | { | |
78 | 79 | // found a new screen block |
79 | if (name != null) { | |
80 | screens.put(name, possibles.toArray(new Screen[possibles.size()])); | |
80 | if( name != null ) | |
81 | { | |
82 | screens.put( name, possibles.toArray( new Screen[ possibles.size() ] ) ); | |
81 | 83 | possibles.clear(); |
82 | 84 | } |
83 | name = sa[0]; | |
85 | name = sa[ 0 ]; | |
84 | 86 | |
85 | 87 | // record the current config |
86 | currentList.add(new Screen(name, sa[2])); | |
87 | } else if (Pattern.matches("\\d*x\\d*", sa[0])) { | |
88 | parseScreen( currentList, name, sa[ 2 ] ); | |
89 | } | |
90 | else if( Pattern.matches( "\\d*x\\d*", sa[ 0 ] ) ) | |
91 | { | |
88 | 92 | // found a new mode line |
89 | possibles.add(new Screen(name, sa[0])); | |
93 | parseScreen( possibles, name, sa[ 0 ] ); | |
90 | 94 | } |
91 | 95 | } |
92 | 96 | |
93 | screens.put(name, possibles.toArray(new Screen[possibles.size()])); | |
97 | screens.put( name, possibles.toArray( new Screen[ possibles.size() ] ) ); | |
94 | 98 | |
95 | 99 | current = (Screen[]) currentList.toArray(new Screen[currentList.size()]); |
96 | } catch (IOException e) { | |
97 | e.printStackTrace(); | |
100 | } | |
101 | catch( Throwable e ) | |
102 | { | |
103 | LWJGLUtil.log( "Exception in XRandR.populate(): " + e.getMessage() ); | |
104 | screens.clear(); | |
105 | current = new Screen[ 0 ]; | |
98 | 106 | } |
99 | 107 | } |
100 | 108 | } |
103 | 111 | * @return The current screen configuration, or an empty array if |
104 | 112 | * xrandr is not supported |
105 | 113 | */ |
106 | public static Screen[] getConfiguration() { | |
107 | AccessController.doPrivileged(new PrivilegedAction() { | |
108 | public Object run() { | |
109 | populate(); | |
110 | return null; | |
111 | } | |
112 | }); | |
114 | public static Screen[] getConfiguration() | |
115 | { | |
116 | populate(); | |
113 | 117 | |
114 | 118 | return (Screen[]) current.clone(); |
115 | 119 | } |
117 | 121 | /** |
118 | 122 | * @param screens |
119 | 123 | * The desired screen set, may not be <code>null</code> |
120 | */ | |
121 | public static void setConfiguration(Screen[]/* ... */screens) { | |
122 | if (screens.length == 0) { | |
123 | throw new IllegalArgumentException("Must specify at least one screen"); | |
124 | * @throws IllegalArgumentException | |
125 | * if no screens are specified | |
126 | */ | |
127 | public static void setConfiguration( Screen[]/* ... */screens ) | |
128 | { | |
129 | if( screens.length == 0 ) | |
130 | { | |
131 | throw new IllegalArgumentException( "Must specify at least one screen" ); | |
124 | 132 | } |
125 | 133 | |
126 | 134 | List/* <String> */cmd = new ArrayList/* <String> */(); |
127 | cmd.add("xrandr"); | |
135 | cmd.add( "xrandr" ); | |
128 | 136 | |
129 | 137 | // switch off those in the current set not in the new set |
130 | for (int i = 0; i < current.length; i++) { | |
138 | for( int i = 0; i < current.length; i++ ) | |
139 | { | |
131 | 140 | boolean found = false; |
132 | for (int j = 0; j < screens.length; j++) { | |
133 | if (screens[j].name.equals(current[i].name)) { | |
141 | for( int j = 0; j < screens.length; j++ ) | |
142 | { | |
143 | if( screens[ j ].name.equals( current[ i ].name ) ) | |
144 | { | |
134 | 145 | found = true; |
135 | 146 | break; |
136 | 147 | } |
137 | 148 | } |
138 | 149 | |
139 | if (!found) { | |
140 | cmd.add("--output"); | |
141 | cmd.add(current[i].name); | |
142 | cmd.add("--off"); | |
150 | if( !found ) | |
151 | { | |
152 | cmd.add( "--output" ); | |
153 | cmd.add( current[ i ].name ); | |
154 | cmd.add( "--off" ); | |
143 | 155 | } |
144 | 156 | } |
145 | 157 | |
146 | 158 | // set up new set |
147 | for (int i = 0; i < screens.length; i++) { | |
148 | screens[i].getArgs(cmd); | |
149 | } | |
150 | ||
151 | try { | |
159 | for( int i = 0; i < screens.length; i++ ) | |
160 | { | |
161 | screens[ i ].getArgs( cmd ); | |
162 | } | |
163 | ||
164 | try | |
165 | { | |
152 | 166 | // ProcessBuilder pb = new ProcessBuilder( cmd ); |
153 | 167 | // pb.redirectErrorStream(); |
154 | 168 | // Process p = pb.start(); |
155 | Process p = Runtime.getRuntime().exec((String[]) cmd.toArray(new String[cmd.size()])); | |
169 | Process p = | |
170 | Runtime.getRuntime().exec( ( String[] ) cmd.toArray( new String[ cmd.size() ] ) ); | |
156 | 171 | // no output is expected, but check anyway |
157 | BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream())); | |
172 | BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) ); | |
158 | 173 | String line; |
159 | while ((line = br.readLine()) != null) { | |
160 | System.out.println(line); | |
174 | while( ( line = br.readLine() ) != null ) | |
175 | { | |
176 | LWJGLUtil.log( "Unexpected output from xrandr process: " + line ); | |
161 | 177 | } |
162 | 178 | current = screens; |
163 | } catch (IOException e) { | |
164 | e.printStackTrace(); | |
165 | } | |
166 | ||
179 | } | |
180 | catch( IOException e ) | |
181 | { | |
182 | LWJGLUtil.log( "XRandR exception in setConfiguration(): " + e.getMessage() ); | |
183 | } | |
167 | 184 | } |
168 | 185 | |
169 | 186 | /** |
170 | 187 | * @return the name of connected screens, or an empty array if |
171 | 188 | * xrandr is not supported |
172 | 189 | */ |
173 | public static String[] getScreenNames() { | |
190 | public static String[] getScreenNames() | |
191 | { | |
174 | 192 | populate(); |
175 | return (String[]) screens.keySet().toArray(new String[screens.size()]); | |
193 | return ( String[] ) screens.keySet().toArray( new String[ screens.size() ] ); | |
176 | 194 | } |
177 | 195 | |
178 | 196 | /** |
180 | 198 | * @return the possible resolutions of the named screen, or |
181 | 199 | * <code>null</code> if there is no such screen |
182 | 200 | */ |
183 | public static Screen[] getResolutions(String name) { | |
201 | public static Screen[] getResolutions( String name ) | |
202 | { | |
184 | 203 | populate(); |
185 | 204 | // clone the array to prevent held copies being altered |
186 | 205 | return (Screen[]) ((Screen[]) screens.get(name)).clone(); |
206 | } | |
207 | ||
208 | private static final Pattern SCREEN_PATTERN1 = | |
209 | Pattern.compile( "^(\\d+)x(\\d+)\\+(\\d+)\\+(\\d+)$" ); | |
210 | ||
211 | private static final Pattern SCREEN_PATTERN2 = Pattern.compile( "^(\\d+)x(\\d+)$" ); | |
212 | ||
213 | /** | |
214 | * Parses a screen configuration and adds it to the list if it's | |
215 | * valid. | |
216 | * | |
217 | * @param list | |
218 | * the list to add the Screen to if it's valid | |
219 | * @param name | |
220 | * the name of this screen | |
221 | * @param what | |
222 | * config string, format either widthxheight or | |
223 | * widthxheight+xPos+yPos | |
224 | */ | |
225 | private static void parseScreen( List /* <Screen> */list, String name, String what ) | |
226 | { | |
227 | Matcher m = SCREEN_PATTERN1.matcher( what ); | |
228 | if( !m.matches() ) | |
229 | { | |
230 | m = SCREEN_PATTERN2.matcher( what ); | |
231 | if( !m.matches() ) | |
232 | { | |
233 | LWJGLUtil.log( "Did not match: " + what ); | |
234 | return; | |
235 | } | |
236 | } | |
237 | int width = Integer.parseInt( m.group( 1 ) ); | |
238 | int height = Integer.parseInt( m.group( 2 ) ); | |
239 | int xpos, ypos; | |
240 | if( m.groupCount() > 3 ) | |
241 | { | |
242 | xpos = Integer.parseInt( m.group( 3 ) ); | |
243 | ypos = Integer.parseInt( m.group( 4 ) ); | |
244 | } | |
245 | else | |
246 | { | |
247 | xpos = 0; | |
248 | ypos = 0; | |
249 | } | |
250 | list.add( new Screen( name, width, height, xpos, ypos ) ); | |
187 | 251 | } |
188 | 252 | |
189 | 253 | /** |
192 | 256 | * |
193 | 257 | * @author ryanm |
194 | 258 | */ |
195 | public static class Screen implements Cloneable { | |
196 | ||
259 | public static class Screen implements Cloneable | |
260 | { | |
197 | 261 | /** |
198 | 262 | * Name for this output |
199 | 263 | */ |
200 | public final String name; | |
264 | public final String name; | |
201 | 265 | |
202 | 266 | /** |
203 | 267 | * Width in pixels |
204 | 268 | */ |
205 | public final int width; | |
269 | public final int width; | |
206 | 270 | |
207 | 271 | /** |
208 | 272 | * Height in pixels |
209 | 273 | */ |
210 | public final int height; | |
274 | public final int height; | |
211 | 275 | |
212 | 276 | /** |
213 | 277 | * Position on the x-axis, in pixels |
214 | 278 | */ |
215 | public int xPos = 0; | |
279 | public int xPos = 0; | |
216 | 280 | |
217 | 281 | /** |
218 | 282 | * Position on the y-axis, in pixels |
219 | 283 | */ |
220 | public int yPos = 0; | |
221 | ||
222 | /** | |
223 | * @param name | |
224 | * name of the screen | |
225 | * @param conf | |
226 | * config string, format either widthxheight or | |
227 | * widthxheight+xPos+yPos | |
228 | */ | |
229 | private Screen(String name, String conf) { | |
284 | public int yPos = 0; | |
285 | ||
286 | private Screen( String name, int width, int height, int xPos, int yPos ) | |
287 | { | |
230 | 288 | this.name = name; |
231 | ||
232 | String[] sa = conf.split("\\D"); | |
233 | width = Integer.parseInt(sa[0]); | |
234 | height = Integer.parseInt(sa[1]); | |
235 | ||
236 | if (sa.length > 2) { | |
237 | xPos = Integer.parseInt(sa[2]); | |
238 | yPos = Integer.parseInt(sa[3]); | |
239 | } | |
240 | } | |
241 | ||
242 | private void getArgs(List/* <String> */argList) { | |
243 | argList.add("--output"); | |
244 | argList.add(name); | |
245 | argList.add("--mode"); | |
246 | argList.add(width + "x" + height); | |
247 | argList.add("--pos"); | |
248 | argList.add(xPos + "x" + yPos); | |
249 | } | |
250 | ||
251 | // @Override | |
252 | public String toString() { | |
289 | this.width = width; | |
290 | this.height = height; | |
291 | this.xPos = xPos; | |
292 | this.yPos = yPos; | |
293 | } | |
294 | ||
295 | private void getArgs( List/* <String> */argList ) | |
296 | { | |
297 | argList.add( "--output" ); | |
298 | argList.add( name ); | |
299 | argList.add( "--mode" ); | |
300 | argList.add( width + "x" + height ); | |
301 | argList.add( "--pos" ); | |
302 | argList.add( xPos + "x" + yPos ); | |
303 | } | |
304 | ||
305 | //@Override | |
306 | public String toString() | |
307 | { | |
253 | 308 | return name + " " + width + "x" + height + " @ " + xPos + "x" + yPos; |
254 | 309 | } |
255 | 310 | } |
256 | } | |
311 | }⏎ |
0 | /* | |
1 | * Copyright (c) 2002-2010 LWJGL Project | |
2 | * All rights reserved. | |
3 | * | |
4 | * Redistribution and use in source and binary forms, with or without | |
5 | * modification, are permitted provided that the following conditions are | |
6 | * met: | |
7 | * | |
8 | * * Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * | |
11 | * * Redistributions in binary form must reproduce the above copyright | |
12 | * notice, this list of conditions and the following disclaimer in the | |
13 | * documentation and/or other materials provided with the distribution. | |
14 | * | |
15 | * * Neither the name of 'LWJGL' nor the names of | |
16 | * its contributors may be used to endorse or promote products derived | |
17 | * from this software without specific prior written permission. | |
18 | * | |
19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
20 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | |
31 | package org.lwjgl.test.openal; | |
32 | ||
33 | import java.nio.IntBuffer; | |
34 | ||
35 | import org.lwjgl.BufferUtils; | |
36 | import org.lwjgl.openal.AL; | |
37 | import org.lwjgl.openal.AL10; | |
38 | import org.lwjgl.openal.AL11; | |
39 | import org.lwjgl.openal.ALC10; | |
40 | import org.lwjgl.openal.ALCcontext; | |
41 | import org.lwjgl.openal.ALCdevice; | |
42 | import org.lwjgl.openal.EFX10; | |
43 | import org.lwjgl.openal.EFXUtil; | |
44 | import org.lwjgl.util.WaveData; | |
45 | ||
46 | /** | |
47 | * Class with a few examples testing and demonstrating the use of the OpenAL extension ALC_EXT_EFX. | |
48 | * <p> | |
49 | * This class is not compatible with the LWJGL debug build (lwjgl-debug.jar), as the debug build | |
50 | * throws exceptions instead of alGetError checks. The redundant exception handling code was not | |
51 | * added in order to keep these examples simple. | |
52 | * | |
53 | * @author Ciardhubh <ciardhubh[at]ciardhubh.de> | |
54 | * @version $Revision$ | |
55 | * $Id$ | |
56 | */ | |
57 | public final class EFX10Test { | |
58 | ||
59 | public static void main(final String[] args) throws Exception { | |
60 | silentTests(); | |
61 | playbackTest(); | |
62 | efxUtilTest(); | |
63 | } | |
64 | ||
65 | /** | |
66 | * Loads OpenAL and makes sure ALC_EXT_EFX is supported. | |
67 | */ | |
68 | private static void setupEfx() throws Exception { | |
69 | // Load and create OpenAL | |
70 | if (!AL.isCreated()) { | |
71 | AL.create(); | |
72 | } | |
73 | // Query for Effect Extension | |
74 | if (!ALC10.alcIsExtensionPresent(AL.getDevice(), EFX10.ALC_EXT_EFX_NAME)) { | |
75 | throw new Exception("No ALC_EXT_EFX supported by driver."); | |
76 | } | |
77 | System.out.println("ALC_EXT_EFX found."); | |
78 | } | |
79 | ||
80 | /** | |
81 | * Runs a series of API calls similar to the tutorials in the Effects Extension Guide of the | |
82 | * OpenAL SDK. Nothing is played in this method. | |
83 | */ | |
84 | private static void silentTests() throws Exception { | |
85 | setupEfx(); | |
86 | ||
87 | final ALCdevice device = AL.getDevice(); | |
88 | ||
89 | // Create context (only necessary if LWJGL context isn't sufficient, done as example) | |
90 | final IntBuffer contextAttribList = BufferUtils.createIntBuffer(8); | |
91 | contextAttribList.put(ALC10.ALC_FREQUENCY); | |
92 | contextAttribList.put(44100); | |
93 | contextAttribList.put(ALC10.ALC_REFRESH); | |
94 | contextAttribList.put(60); | |
95 | contextAttribList.put(ALC10.ALC_SYNC); | |
96 | contextAttribList.put(ALC10.ALC_FALSE); | |
97 | contextAttribList.rewind(); | |
98 | // ALC_MAX_AUXILIARY_SENDS won't go above compile-time max. Set to compile-time max if | |
99 | // greater. | |
100 | contextAttribList.put(EFX10.ALC_MAX_AUXILIARY_SENDS); | |
101 | contextAttribList.put(2); | |
102 | final ALCcontext newContext = ALC10.alcCreateContext(device, contextAttribList); | |
103 | if (newContext == null) { | |
104 | throw new Exception("Failed to create context."); | |
105 | } | |
106 | final int contextCurResult = ALC10.alcMakeContextCurrent(newContext); | |
107 | if (contextCurResult == ALC10.ALC_FALSE) { | |
108 | throw new Exception("Failed to make context current."); | |
109 | } | |
110 | ||
111 | // Query EFX ALC values | |
112 | System.out.println("AL_VERSION: " + AL10.alGetString(AL10.AL_VERSION)); | |
113 | final IntBuffer buff = BufferUtils.createIntBuffer(1); | |
114 | ALC10.alcGetInteger(device, EFX10.ALC_EFX_MAJOR_VERSION, buff); | |
115 | System.out.println("ALC_EFX_MAJOR_VERSION: " + buff.get(0)); | |
116 | ALC10.alcGetInteger(device, EFX10.ALC_EFX_MINOR_VERSION, buff); | |
117 | System.out.println("ALC_EFX_MINOR_VERSION: " + buff.get(0)); | |
118 | ALC10.alcGetInteger(device, EFX10.ALC_MAX_AUXILIARY_SENDS, buff); | |
119 | final int maxAuxSends = buff.get(0); | |
120 | System.out.println("ALC_MAX_AUXILIARY_SENDS: " + maxAuxSends); | |
121 | ||
122 | ||
123 | // Try to create 4 Auxiliary Effect Slots | |
124 | int numAuxSlots = 0; | |
125 | final int[] auxEffectSlots = new int[4]; // try more to test | |
126 | AL10.alGetError(); | |
127 | for (numAuxSlots = 0; numAuxSlots < 4; numAuxSlots++) { | |
128 | auxEffectSlots[numAuxSlots] = EFX10.alGenAuxiliaryEffectSlots(); | |
129 | if (AL10.alGetError() != AL10.AL_NO_ERROR) { | |
130 | break; | |
131 | } | |
132 | } | |
133 | System.out.println("Created " + numAuxSlots + " aux effect slots."); | |
134 | ||
135 | // Try to create 2 Effects | |
136 | int numEffects = 0; | |
137 | final int[] effects = new int[2]; | |
138 | for (numEffects = 0; numEffects < 2; numEffects++) { | |
139 | effects[numEffects] = EFX10.alGenEffects(); | |
140 | if (AL10.alGetError() != AL10.AL_NO_ERROR) { | |
141 | break; | |
142 | } | |
143 | } | |
144 | System.out.println("Created " + numEffects + " effects."); | |
145 | ||
146 | // Set first Effect Type to Reverb and change Decay Time | |
147 | AL10.alGetError(); | |
148 | if (EFX10.alIsEffect(effects[0])) { | |
149 | EFX10.alEffecti(effects[0], EFX10.AL_EFFECT_TYPE, EFX10.AL_EFFECT_REVERB); | |
150 | if (AL10.alGetError() != AL10.AL_NO_ERROR) { | |
151 | System.out.println("Reverb effect not supported."); | |
152 | } else { | |
153 | EFX10.alEffectf(effects[0], EFX10.AL_REVERB_DECAY_TIME, 5.0f); | |
154 | System.out.println("Reverb effect created."); | |
155 | } | |
156 | } else { | |
157 | throw new Exception("First effect not a valid effect."); | |
158 | } | |
159 | ||
160 | // Set second Effect Type to Flanger and change Phase | |
161 | AL10.alGetError(); | |
162 | if (EFX10.alIsEffect(effects[1])) { | |
163 | EFX10.alEffecti(effects[1], EFX10.AL_EFFECT_TYPE, EFX10.AL_EFFECT_FLANGER); | |
164 | if (AL10.alGetError() != AL10.AL_NO_ERROR) { | |
165 | System.out.println("Flanger effect not support."); | |
166 | } else { | |
167 | EFX10.alEffecti(effects[1], EFX10.AL_FLANGER_PHASE, 180); | |
168 | System.out.println("Flanger effect created."); | |
169 | } | |
170 | } else { | |
171 | throw new Exception("Second effect not a valid effect."); | |
172 | } | |
173 | ||
174 | // Try to create a Filter | |
175 | AL10.alGetError(); | |
176 | final int filter = EFX10.alGenFilters(); | |
177 | if (AL10.alGetError() != AL10.AL_NO_ERROR) { | |
178 | throw new Exception("Failed to create filter."); | |
179 | } | |
180 | System.out.println("Generated a filter."); | |
181 | if (EFX10.alIsFilter(filter)) { | |
182 | // Set Filter type to Low-Pass and set parameters | |
183 | EFX10.alFilteri(filter, EFX10.AL_FILTER_TYPE, EFX10.AL_FILTER_LOWPASS); | |
184 | if (AL10.alGetError() != AL10.AL_NO_ERROR) { | |
185 | System.out.println("Low pass filter not supported."); | |
186 | } else { | |
187 | EFX10.alFilterf(filter, EFX10.AL_LOWPASS_GAIN, 0.5f); | |
188 | EFX10.alFilterf(filter, EFX10.AL_LOWPASS_GAINHF, 0.5f); | |
189 | System.out.println("Low pass filter created."); | |
190 | } | |
191 | } | |
192 | ||
193 | // Attach Effect to Auxiliary Effect Slot | |
194 | AL10.alGetError(); | |
195 | EFX10.alAuxiliaryEffectSloti(auxEffectSlots[0], EFX10.AL_EFFECTSLOT_EFFECT, effects[0]); | |
196 | if (AL10.alGetError() != AL10.AL_NO_ERROR) { | |
197 | throw new Exception("Failed to attach effect to aux effect slot."); | |
198 | } | |
199 | System.out.println("Successfully loaded effect into effect slot."); | |
200 | ||
201 | // Configure Source Auxiliary Effect Slot Sends | |
202 | final int source = AL10.alGenSources(); | |
203 | // Set Source Send 0 to feed auxEffectSlots[0] without filtering | |
204 | AL11.alSource3i(source, EFX10.AL_AUXILIARY_SEND_FILTER, auxEffectSlots[0], 0, | |
205 | EFX10.AL_FILTER_NULL); | |
206 | if (AL10.alGetError() != AL10.AL_NO_ERROR) { | |
207 | throw new Exception("Failed to configure Source Send 0"); | |
208 | } | |
209 | System.out.println("Linked aux effect slot to soutce slot 0"); | |
210 | // Set Source Send 1 to feed uiEffectSlot[1] with filter filter | |
211 | AL11.alSource3i(source, EFX10.AL_AUXILIARY_SEND_FILTER, auxEffectSlots[1], 1, filter); | |
212 | if (AL10.alGetError() != AL10.AL_NO_ERROR) { | |
213 | // e.g. if only 1 send per source is available | |
214 | throw new Exception("Failed to configure Source Send 1"); | |
215 | } | |
216 | System.out.println("Linked aux effect slot to soutce slot 1"); | |
217 | // Disable Send 0 | |
218 | AL11.alSource3i(source, EFX10.AL_AUXILIARY_SEND_FILTER, EFX10.AL_EFFECTSLOT_NULL, 0, | |
219 | EFX10.AL_FILTER_NULL); | |
220 | if (AL10.alGetError() != AL10.AL_NO_ERROR) { | |
221 | throw new Exception("Failed to disable Source Send 0"); | |
222 | } | |
223 | System.out.println("Disabled source send 0"); | |
224 | // Disable Send 1 | |
225 | AL11.alSource3i(source, EFX10.AL_AUXILIARY_SEND_FILTER, EFX10.AL_EFFECTSLOT_NULL, 1, | |
226 | EFX10.AL_FILTER_NULL); | |
227 | if (AL10.alGetError() != AL10.AL_NO_ERROR) { | |
228 | throw new Exception("Failed to disable Source Send 1"); | |
229 | } | |
230 | System.out.println("Disabled source send 1"); | |
231 | ||
232 | ||
233 | // Filter 'source', a generated Source | |
234 | AL10.alSourcei(source, EFX10.AL_DIRECT_FILTER, filter); | |
235 | if (AL10.alGetError() == AL10.AL_NO_ERROR) { | |
236 | { | |
237 | System.out.println("Successfully applied a direct path filter"); | |
238 | // Remove filter from 'source' | |
239 | AL10.alSourcei(source, EFX10.AL_DIRECT_FILTER, EFX10.AL_FILTER_NULL); | |
240 | if (AL10.alGetError() == AL10.AL_NO_ERROR) { | |
241 | System.out.println("Successfully removed direct filter"); | |
242 | } | |
243 | } | |
244 | // Filter the Source send 0 from 'source' to Auxiliary Effect Slot auxEffectSlot[0] | |
245 | // using Filter uiFilter[0] | |
246 | AL11.alSource3i(source, EFX10.AL_AUXILIARY_SEND_FILTER, auxEffectSlots[0], 0, filter); | |
247 | if (AL10.alGetError() == AL10.AL_NO_ERROR) { | |
248 | { | |