Codebase list lwjgl / afc97ed
Imported Upstream version 2.5+dfsg Gabriele Giacone 13 years ago
76 changed file(s) with 4261 addition(s) and 800 deletion(s). Raw diff Collapse all Expand all
123123 <fileset refid="lwjgl.fileset" />
124124 <manifest>
125125 <attribute name="Sealed" value="true"/>
126 <attribute name="Trusted-Library" value="true"/>
127126 </manifest>
128127 </jar>
129128
132131 <fileset refid="lwjgl_util_applet.fileset" />
133132 <manifest>
134133 <attribute name="Sealed" value="true"/>
135 <attribute name="Trusted-Library" value="true"/>
136134 </manifest>
137135 </jar>
138136
252250 <class name="org.lwjgl.openal.AL" />
253251 <class name="org.lwjgl.opengl.GLContext" />
254252 <class name="org.lwjgl.opengl.Pbuffer" />
253 <class name="org.lwjgl.opengl.AMDDebugOutputCallback" />
255254 </javah>
256255 </target>
257256
1111 <property name="lwjgl.docs" location="doc" />
1212 <property name="lwjgl.temp" location="temp" />
1313 <property name="lwjgl.res" location="res" />
14 <property name="lwjgl.version" value="2.4.2" />
14 <property name="lwjgl.version" value="2.5" />
1515
1616 <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"/>
1717 <!-- ================================================================== -->
1212 <javac debug="yes" srcdir="${lwjgl.src}/java/" destdir="${lwjgl.bin}" includes="org/lwjgl/util/generator/**.java" source="1.5" target="1.5" taskname="generator">
1313 <compilerarg value="-Xlint:all"/>
1414 </javac>
15 <!-- Compile helper classes used by the templates -->
1516 <javac debug="yes" srcdir="${lwjgl.src}/java/" destdir="${lwjgl.bin}" source="1.4" target="1.4" taskname="generator">
1617 <include name="org/lwjgl/opengl/GLSync.java"/>
18 <include name="org/lwjgl/opengl/AMDDebugOutputCallback.java"/>
1719 <include name="org/lwjgl/opengl/PointerWrapper.java"/>
1820 </javac>
1921 </target>
3638 <arg value="-d"/>
3739 <arg path="${lwjgl.src.native}/generated"/>
3840 <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"/>
4042 </apply>
4143 </target>
4244
5456 <arg path="${lwjgl.src.native}/generated"/>
5557 <arg value="-Atypemap=org.lwjgl.util.generator.ALTypeMap"/>
5658 <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"/>
5860 </apply>
5961 </target>
6062
66 </antcall>
77 </target>
88
9 <target name="webstart_demo-release" depends="jars">
9 <target name="webstart_demo-release">
1010 <input message="Please type the password for the keystore" addproperty="sign.pwd"/>
1111
1212 <antcall target="-webstart_demo">
2424
2525 <!-- unzip common files -->
2626 <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"/>
2729
2830 <!-- move files to unified structure -->
2931 <move todir="${lwjgl.temp}/jnlp/temp">
3537 <!-- move relevant files to root -->
3638 <move todir="${lwjgl.temp}/jnlp/" flatten="true">
3739 <fileset dir="${lwjgl.temp}/jnlp/temp">
38 <include name="**/**.jar"/>
40 <include name="**/jinput.jar"/>
41 <include name="**/lwjgl*.jar"/>
3942 </fileset>
4043 </move>
4144
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
4265 <!-- 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>
4789
4890 <!-- 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>
5096
5197 <!-- sign 'em -->
5298 <signjar jar="${lwjgl.temp}/jnlp/lwjgl.jar" alias="${alias}" keystore="${keystore}" storepass="${password}"/>
56102 <signjar jar="${lwjgl.temp}/jnlp/native_macosx.jar" alias="${alias}" keystore="${keystore}" storepass="${password}"/>
57103 <signjar jar="${lwjgl.temp}/jnlp/native_windows.jar" alias="${alias}" keystore="${keystore}" storepass="${password}"/>
58104 <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}"/>
59106 </target>
60107 </project>
+0
-85
platform_build/build-webstart.xml.bak less more
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>
4747 * </p>
4848 * @author cix_foo <cix_foo@users.sourceforge.net>
4949 * @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 $
5252 */
5353 public class BufferChecks {
5454 /** Static methods only! */
5959 * Helper methods to ensure a function pointer is not-null (0)
6060 */
6161 public static void checkFunctionAddress(long pointer) {
62 if (pointer == 0) {
62 if (LWJGLUtil.CHECKS && pointer == 0) {
6363 throw new IllegalStateException("Function is not supported");
6464 }
6565 }
6868 * Helper methods to ensure a ByteBuffer is null-terminated
6969 */
7070 public static void checkNullTerminated(ByteBuffer buf) {
71 if (buf.get(buf.limit() - 1) != 0) {
71 if ( LWJGLUtil.CHECKS && buf.get(buf.limit() - 1) != 0) {
7272 throw new IllegalArgumentException("Missing null termination");
7373 }
7474 }
7575
7676 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 }
8587 }
8688
8789 /** Helper methods to ensure an IntBuffer is null-terminated */
9294 }
9395
9496 public static void checkNotNull(Object o) {
95 if (o == null)
97 if ( LWJGLUtil.CHECKS && o == null)
9698 throw new IllegalArgumentException("Null argument");
9799 }
98100
100102 * Helper methods to ensure a buffer is direct (and, implicitly, non-null).
101103 */
102104 public static void checkDirect(ByteBuffer buf) {
103 if (!buf.isDirect()) {
105 if ( LWJGLUtil.CHECKS && !buf.isDirect()) {
104106 throw new IllegalArgumentException("ByteBuffer is not direct");
105107 }
106108 }
107109
108110 public static void checkDirect(ShortBuffer buf) {
109 if (!buf.isDirect()) {
111 if ( LWJGLUtil.CHECKS && !buf.isDirect()) {
110112 throw new IllegalArgumentException("ShortBuffer is not direct");
111113 }
112114 }
113115
114116 public static void checkDirect(IntBuffer buf) {
115 if (!buf.isDirect()) {
117 if ( LWJGLUtil.CHECKS && !buf.isDirect()) {
116118 throw new IllegalArgumentException("IntBuffer is not direct");
117119 }
118120 }
119121
120122 public static void checkDirect(LongBuffer buf) {
121 if (!buf.isDirect()) {
123 if ( LWJGLUtil.CHECKS && !buf.isDirect()) {
122124 throw new IllegalArgumentException("LongBuffer is not direct");
123125 }
124126 }
125127
126128 public static void checkDirect(FloatBuffer buf) {
127 if (!buf.isDirect()) {
129 if ( LWJGLUtil.CHECKS && !buf.isDirect()) {
128130 throw new IllegalArgumentException("FloatBuffer is not direct");
129131 }
130132 }
131133
132134 public static void checkDirect(DoubleBuffer buf) {
133 if (!buf.isDirect()) {
135 if ( LWJGLUtil.CHECKS && !buf.isDirect()) {
134136 throw new IllegalArgumentException("DoubleBuffer is not direct");
135137 }
136138 }
153155 * @throws IllegalArgumentException
154156 */
155157 public static void checkBufferSize(Buffer buf, int size) {
156 if (buf.remaining() < size) {
158 if ( LWJGLUtil.CHECKS && buf.remaining() < size) {
157159 throwBufferSizeException(buf, size);
158160 }
159161 }
160162
161163 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 }
164168 }
165169
166170 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 }
169175 }
170176
171177 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 }
174182 }
175183
176184 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 }
179189 }
180190
181191 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 }
184196 }
185197
186198 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 }
189203 }
190204 }
4848 * </p>
4949 *
5050 * @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 $
5353 */
5454 public class LWJGLUtil {
5555 public static final int PLATFORM_LINUX = 1;
265265
266266 /** Debug flag. */
267267 public static final boolean DEBUG = getPrivilegedBoolean("org.lwjgl.util.Debug");
268
268
269 public static final boolean CHECKS = !getPrivilegedBoolean("org.lwjgl.util.NoChecks");
270
269271 static {
270272 LWJGLIcon16x16.flip();
271273 LWJGLIcon32x32.flip();
4545 * System class (named Sys so as not to conflict with java.lang.System)
4646 * </p>
4747 * @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 $
5050 */
5151 public final class Sys {
5252 /** The native library name */
5353 private static final String JNI_LIBRARY_NAME = "lwjgl";
5454
5555 /** Current version of library */
56 private static final String VERSION = "2.4.2";
56 private static final String VERSION = "2.5";
5757
5858 /** The implementation instance to delegate platform specific behavior to */
5959 private final static SysImplementation implementation;
5858 * @author cix_foo <cix_foo@users.sourceforge.net>
5959 * @author elias_naur <elias_naur@users.sourceforge.net>
6060 * @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 $
6363 */
6464 public class Mouse {
6565 /** Internal use - event size in bytes */
466466 }
467467
468468 /**
469 * @return Current events delta x. Only valid when the mouse is grabbed.
469 * @return Current events delta x.
470470 */
471471 public static int getEventDX() {
472472 synchronized (OpenGLPackageAccess.global_lock) {
475475 }
476476
477477 /**
478 * @return Current events delta y. Only valid when the mouse is grabbed.
478 * @return Current events delta y.
479479 */
480480 public static int getEventDY() {
481481 synchronized (OpenGLPackageAccess.global_lock) {
484484 }
485485
486486 /**
487 * @return Current events absolute x. Only valid when the mouse is not grabbed.
487 * @return Current events absolute x.
488488 */
489489 public static int getEventX() {
490490 synchronized (OpenGLPackageAccess.global_lock) {
493493 }
494494
495495 /**
496 * @return Current events absolute y. Only valid when the mouse is not grabbed.
496 * @return Current events absolute y.
497497 */
498498 public static int getEventY() {
499499 synchronized (OpenGLPackageAccess.global_lock) {
549549 }
550550
551551 /**
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.
553553 */
554554 public static int getDX() {
555555 synchronized (OpenGLPackageAccess.global_lock) {
560560 }
561561
562562 /**
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.
564564 */
565565 public static int getDY() {
566566 synchronized (OpenGLPackageAccess.global_lock) {
4141 * </p>
4242 *
4343 * @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 $
4646 */
4747 public final class AL {
4848 /** ALCdevice instance. */
159159
160160 if(openDevice) {
161161 device = ALC10.alcOpenDevice(deviceArguments);
162 if (device == null)
162 if (device == null) {
163163 throw new LWJGLException("Could not open ALC device");
164 }
164165
165166 if (contextFrequency == -1) {
166167 context = ALC10.alcCreateContext(device, null);
176177 throw e;
177178 }
178179
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 }
180192 }
181193
182194 /**
204216 device = null;
205217 }
206218 resetNativeStubs(AL10.class);
219 resetNativeStubs(AL11.class);
207220 resetNativeStubs(ALC10.class);
208221 resetNativeStubs(ALC11.class);
222 resetNativeStubs(EFX10.class);
209223
210224 if (created)
211225 nDestroy();
5757 public static final int ALC_CAPTURE_DEVICE_SPECIFIER = 0x310;
5858 public static final int ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER = 0x311;
5959 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;
6063
6164 /**
6265 * 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 }
157157 final InfiniteCharSequence infiniteSeq = getInfiniteSeq();
158158 infiniteSeq.setString(string);
159159 encoder.encode(infiniteSeq.buffer, buffer, true);
160 infiniteSeq.clear();
160161 }
161162
162163 /**
4646 * <p/>
4747 *
4848 * @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 $
5151 */
52 public class AWTGLCanvas extends Canvas implements Drawable, ComponentListener, HierarchyListener {
52 public class AWTGLCanvas extends Canvas implements DrawableLWJGL, ComponentListener, HierarchyListener {
5353
5454 private static final long serialVersionUID = 1L;
5555
108108 return context;
109109 }
110110
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
111120 /** Constructor using the default PixelFormat. */
112121 public AWTGLCanvas() throws LWJGLException {
113122 this(new PixelFormat());
174183 */
175184 public void removeNotify() {
176185 synchronized ( SYNC_LOCK ) {
177 destroyContext();
186 destroy();
178187 super.removeNotify();
179188 }
180189 }
199208 if ( context == null )
200209 throw new IllegalStateException("Canvas not yet displayable");
201210 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();
202231 }
203232 }
204233
211240 }
212241 }
213242
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
226243 /** Destroy the OpenGL context. This happens when the component becomes undisplayable */
227 private void destroyContext() {
244 public final void destroy() {
228245 synchronized ( SYNC_LOCK ) {
229246 try {
230247 if ( context != null ) {
268285 peer_info.lockAndGetHandle();
269286 try {
270287 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);
272289 first_run = true;
273290 }
274291
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 }
3131 package org.lwjgl.opengl;
3232
3333 import java.nio.Buffer;
34 import java.nio.IntBuffer;
3534 import java.util.Arrays;
3635
3736 class BaseReferences {
4847 int indirectBuffer;
4948
5049 BaseReferences(ContextCapabilities caps) {
51 IntBuffer temp = caps.scratch_int_buffer;
52
5350 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
5854 max_vertex_attribs = 0;
5955 glVertexAttribPointer_buffer = new Buffer[max_vertex_attribs];
6056
6157 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
6963 max_texture_units = 1;
7064 glTexCoordPointer_buffer = new Buffer[max_texture_units];
7165 }
4545 * This class is thread-safe.
4646 *
4747 * @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 $
5050 */
5151 final class Context {
5252
6060 private final ByteBuffer handle;
6161 private final PeerInfo peer_info;
6262
63 private final IntBuffer attribList;
63 private final ContextAttribs contextAttribs;
6464 private final boolean forwardCompatible;
6565
6666 /** Whether the context has been destroyed */
9191
9292 PeerInfo getPeerInfo() {
9393 return peer_info;
94 }
95
96 ContextAttribs getContextAttribs() {
97 return contextAttribs;
9498 }
9599
96100 static Context getCurrentContext() {
108112 GLContext.loadOpenGLLibrary();
109113 try {
110114 this.peer_info = peer_info;
115 this.contextAttribs = attribs;
116
117 IntBuffer attribList;
111118 if ( attribs != null ) {
112119 attribList = attribs.getAttribList();
113120 forwardCompatible = attribs.isForwardCompatible();
3636 import java.nio.IntBuffer;
3737
3838 /**
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.
4041 * These attributes can be used to indicate at context creation which OpenGL interface will be used. This includes the
4142 * 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)
4344 * <p/>
4445 * 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.
4949 * <p/>
5050 * If the forwardCompatible
5151 * attribute is used, LWJGL will not load the deprecated functionality (as defined in the OpenGL 3.0 specification). This
7171 }
7272
7373 public ContextAttribs(final int majorVersion, final int minorVersion) {
74 if ( majorVersion < 0 ||
75 3 < majorVersion ||
74 if ( majorVersion < 0 || 4 < majorVersion ||
7675 minorVersion < 0 ||
77 (majorVersion == 3 && 2 < minorVersion) ||
76 (majorVersion == 4 && 0 < minorVersion) ||
77 (majorVersion == 3 && 3 < minorVersion) ||
7878 (majorVersion == 2 && 1 < minorVersion) ||
7979 (majorVersion == 1 && 5 < minorVersion) )
8080 throw new IllegalArgumentException("Invalid OpenGL version specified: " + majorVersion + '.' + minorVersion);
8787 this.debug = false;
8888 this.forwardCompatible = false;
8989
90 this.profileCore = 3 < majorVersion || (majorVersion == 3 && 2 <= minorVersion) ? true : false;
90 this.profileCore = false;
9191 this.profileCompatibility = false;
9292 }
9393
105105 /** Swap interval */
106106 private static int swap_interval;
107107
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
112108 /** 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;
116112
117113 private static boolean parent_resized;
118114
136132 } catch (LWJGLException e) {
137133 throw new RuntimeException(e);
138134 }
139 drawable = new Drawable() {
140 public Context getContext() {
135 drawable = new AbstractDrawable() {
136 public void destroy() {
141137 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();
143148 }
144149 }
145150 };
237242 * @throws LWJGLException if the display mode could not be set
238243 */
239244 public static void setDisplayMode(DisplayMode mode) throws LWJGLException {
240 synchronized (GlobalLock.lock) {
241 if (mode == null)
245 synchronized ( GlobalLock.lock ) {
246 if ( mode == null )
242247 throw new NullPointerException("mode must be non-null");
243248 boolean was_fullscreen = isFullscreen();
244249 current_mode = mode;
245 if (isCreated()) {
250 if ( isCreated() ) {
246251 destroyWindow();
247252 // If mode is not fullscreen capable, make sure we are in windowed mode
248253 try {
249 if (was_fullscreen && !isFullscreen())
254 if ( was_fullscreen && !isFullscreen() )
250255 display_impl.resetDisplayMode();
251 else if (isFullscreen())
256 else if ( isFullscreen() )
252257 switchDisplayMode();
253258 createWindow();
254259 makeCurrentAndSetSwapInterval();
255260 } catch (LWJGLException e) {
256 destroyContext();
257 destroyPeerInfo();
261 drawable.destroy();
258262 display_impl.resetDisplayMode();
259263 throw e;
260264 }
267271 }
268272
269273 private static int getWindowX() {
270 if (!isFullscreen() && parent == null) {
274 if ( !isFullscreen() && parent == null ) {
271275 // if no display location set, center window
272 if (x == -1) {
276 if ( x == -1 ) {
273277 return Math.max(0, (initial_mode.getWidth() - current_mode.getWidth()) / 2);
274278 } else {
275279 return x;
280284 }
281285
282286 private static int getWindowY() {
283 if (!isFullscreen() && parent == null) {
287 if ( !isFullscreen() && parent == null ) {
284288 // if no display location set, center window
285289 if ( y == -1 ) {
286290 return Math.max(0, (initial_mode.getHeight() - current_mode.getHeight()) / 2);
323327
324328 private static void releaseDrawable() {
325329 try {
330 Context context = drawable.context;
326331 if ( context != null && context.isCurrent() ) {
327332 Context.releaseCurrentContext();
328333 context.releaseDrawable();
418423 savedTimeLate = timeLate;
419424 }
420425
421 while ( gapTo > timeNow + savedTimeLate ) {
422 try {
426 try {
427 while ( gapTo > timeNow + savedTimeLate ) {
423428 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();
427433 }
428434
429435 synchronized ( GlobalLock.lock ) {
462468 */
463469 public static void setParent(Canvas parent) throws LWJGLException {
464470 synchronized ( GlobalLock.lock ) {
465 if (Display.parent != parent) {
471 if ( Display.parent != parent ) {
466472 Display.parent = parent;
467473 if ( !isCreated() )
468474 return;
469475 destroyWindow();
470476 try {
471 if (isFullscreen()) {
477 if ( isFullscreen() ) {
472478 switchDisplayMode();
473479 } else {
474480 display_impl.resetDisplayMode();
476482 createWindow();
477483 makeCurrentAndSetSwapInterval();
478484 } catch (LWJGLException e) {
479 destroyContext();
480 destroyPeerInfo();
485 drawable.destroy();
481486 display_impl.resetDisplayMode();
482487 throw e;
483488 }
518523
519524 private static void setDisplayModeAndFullscreenInternal(boolean fullscreen, DisplayMode mode) throws LWJGLException {
520525 synchronized ( GlobalLock.lock ) {
521 if (mode == null)
526 if ( mode == null )
522527 throw new NullPointerException("mode must be non-null");
523528 DisplayMode old_mode = current_mode;
524529 current_mode = mode;
525530 boolean was_fullscreen = isFullscreen();
526531 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() )
529534 return;
530535 destroyWindow();
531536 try {
532 if (isFullscreen()) {
537 if ( isFullscreen() ) {
533538 switchDisplayMode();
534539 } else {
535540 display_impl.resetDisplayMode();
537542 createWindow();
538543 makeCurrentAndSetSwapInterval();
539544 } catch (LWJGLException e) {
540 destroyContext();
541 destroyPeerInfo();
545 drawable.destroy();
542546 display_impl.resetDisplayMode();
543547 throw e;
544548 }
548552
549553 /** @return whether the Display is in fullscreen mode */
550554 public static boolean isFullscreen() {
551 synchronized (GlobalLock.lock) {
555 synchronized ( GlobalLock.lock ) {
552556 return fullscreen && current_mode.isFullscreenCapable();
553557 }
554558 }
650654 * Update the window. If the window is visible clears
651655 * the dirty flag and calls swapBuffers() and finally
652656 * polls the input devices.
653 *
654657 */
655658 public static void update() {
656659 update(true);
709712 * @throws LWJGLException If the context could not be released
710713 */
711714 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();
718721 }
719722
720723 /**
723726 * @throws LWJGLException If the context could not be made current
724727 */
725728 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();
731730 }
732731
733732 private static void removeShutdownHook() {
847846 throw new NullPointerException("pixel_format cannot be null");
848847 removeShutdownHook();
849848 registerShutdownHook();
850 if (isFullscreen())
849 if ( isFullscreen() )
851850 switchDisplayMode();
852851 try {
853 peer_info = display_impl.createPeerInfo(pixel_format);
852 drawable.peer_info = display_impl.createPeerInfo(pixel_format);
854853 try {
855854 createWindow();
856855 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);
858857 try {
859858 makeCurrentAndSetSwapInterval();
860859 initContext();
861860 } catch (LWJGLException e) {
862 destroyContext();
861 drawable.destroy();
863862 throw e;
864863 }
865864 } catch (LWJGLException e) {
867866 throw e;
868867 }
869868 } catch (LWJGLException e) {
870 destroyPeerInfo();
869 drawable.destroy();
871870 throw e;
872871 }
873872 } catch (LWJGLException e) {
878877 }
879878
880879 /**
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 */
888887 public static void setInitialBackground(float red, float green, float blue) {
889888 r = red;
890889 g = green;
956955 * regardless of whether the Display was the current rendering context.
957956 */
958957 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();
988959 }
989960
990961 /*
991962 * Reset display mode if fullscreen. This method is also called from the shutdown hook added
992963 * in the static constructor
993964 */
965
994966 private static void reset() {
995967 display_impl.resetDisplayMode();
996968 current_mode = initial_mode;
10491021 y = new_y;
10501022
10511023 // offset if already created
1052 if (isCreated() && !isFullscreen()) {
1024 if ( isCreated() && !isFullscreen() ) {
10531025 reshape();
10541026 }
10551027 }
3030 */
3131 package org.lwjgl.opengl;
3232
33 import org.lwjgl.LWJGLException;
34
3335 /**
3436 * The Drawable interface describes an OpenGL drawable with an associated
3537 * Context.
3840 */
3941
4042 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
4264 }
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 }
3434 import java.nio.IntBuffer;
3535
3636 import org.lwjgl.BufferUtils;
37 import org.lwjgl.LWJGLUtil;
3738
3839 /**
3940 * A class to check buffer boundaries in GL methods. Many GL
4546 * Thrown by the debug build library of the LWJGL if any OpenGL operation causes an error.
4647 *
4748 * @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 $
5051 */
5152 class GLChecks {
5253
5960 }
6061
6162 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);
6564 }
6665
6766 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);
7168 }
7269
7370 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);
7772 }
7873
7974 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);
9076 }
9177
9278 /** Helper method to ensure that array buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */
9379 static void ensureArrayVBOdisabled(ContextCapabilities caps) {
94 if(StateTracker.getReferencesStack(caps).getReferences().arrayBuffer != 0)
80 if( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().arrayBuffer != 0 )
9581 throw new OpenGLException("Cannot use Buffers when Array Buffer Object is enabled");
9682 }
9783
9884 /** Helper method to ensure that array buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */
9985 static void ensureArrayVBOenabled(ContextCapabilities caps) {
100 if(StateTracker.getReferencesStack(caps).getReferences().arrayBuffer == 0)
86 if( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().arrayBuffer == 0 )
10187 throw new OpenGLException("Cannot use offsets when Array Buffer Object is disabled");
10288 }
10389
10490 /** Helper method to ensure that element array buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */
10591 static void ensureElementVBOdisabled(ContextCapabilities caps) {
106 if(StateTracker.getReferencesStack(caps).getReferences().elementArrayBuffer != 0)
92 if( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().elementArrayBuffer != 0 )
10793 throw new OpenGLException("Cannot use Buffers when Element Array Buffer Object is enabled");
10894 }
10995
11096 /** Helper method to ensure that element array buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */
11197 static void ensureElementVBOenabled(ContextCapabilities caps) {
112 if(StateTracker.getReferencesStack(caps).getReferences().elementArrayBuffer == 0)
98 if( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().elementArrayBuffer == 0 )
11399 throw new OpenGLException("Cannot use offsets when Element Array Buffer Object is disabled");
114100 }
115101
116102 /** Helper method to ensure that array buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */
117103 static void ensureIndirectBOdisabled(ContextCapabilities caps) {
118 if ( StateTracker.getReferencesStack(caps).getReferences().indirectBuffer != 0 )
104 if ( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().indirectBuffer != 0 )
119105 throw new OpenGLException("Cannot use Buffers when Draw Indirect Object is enabled");
120106 }
121107
122108 /** Helper method to ensure that array buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */
123109 static void ensureIndirectBOenabled(ContextCapabilities caps) {
124 if ( StateTracker.getReferencesStack(caps).getReferences().indirectBuffer == 0 )
110 if ( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().indirectBuffer == 0 )
125111 throw new OpenGLException("Cannot use offsets when Draw Indirect Object is disabled");
126112 }
127113
128114 /** Helper method to ensure that pixel pack buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */
129115 static void ensurePackPBOdisabled(ContextCapabilities caps) {
130 if ( StateTracker.getReferencesStack(caps).getReferences().pixelPackBuffer != 0 )
116 if ( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().pixelPackBuffer != 0 )
131117 throw new OpenGLException("Cannot use Buffers when Pixel Pack Buffer Object is enabled");
132118 }
133119
134120 /** Helper method to ensure that pixel pack buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */
135121 static void ensurePackPBOenabled(ContextCapabilities caps) {
136 if ( StateTracker.getReferencesStack(caps).getReferences().pixelPackBuffer == 0 )
122 if ( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().pixelPackBuffer == 0 )
137123 throw new OpenGLException("Cannot use offsets when Pixel Pack Buffer Object is disabled");
138124 }
139125
140126 /** Helper method to ensure that pixel unpack buffer objects are disabled. If they are enabled, we'll throw an OpenGLException */
141127 static void ensureUnpackPBOdisabled(ContextCapabilities caps) {
142 if ( StateTracker.getReferencesStack(caps).getReferences().pixelUnpackBuffer != 0 )
128 if ( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().pixelUnpackBuffer != 0 )
143129 throw new OpenGLException("Cannot use Buffers when Pixel Unpack Buffer Object is enabled");
144130 }
145131
146132 /** Helper method to ensure that pixel unpack buffer objects are enabled. If they are disabled, we'll throw an OpenGLException */
147133 static void ensureUnpackPBOenabled(ContextCapabilities caps) {
148 if ( StateTracker.getReferencesStack(caps).getReferences().pixelUnpackBuffer == 0 )
134 if ( LWJGLUtil.CHECKS && StateTracker.getReferencesStack(caps).getReferences().pixelUnpackBuffer == 0 )
149135 throw new OpenGLException("Cannot use offsets when Pixel Unpack Buffer Object is disabled");
150136 }
151137
161147 * @return the size, in elements, of the image
162148 */
163149 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;
165151 }
166152
167153 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;
169155 }
170156
171157 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;
173159 }
174160
175161 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;
177163 }
178164
179165 /**
5353 * That way, multiple threads can have multiple contexts current and render to them concurrently.
5454 *
5555 * @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 $
5858 */
5959 public final class GLContext {
6060
168168 return 0;
169169 }
170170
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
171187 /** Helper method to get a pointer to a named function in the OpenGL library */
172188 static native long getFunctionAddress(String name);
173189
3838 */
3939
4040 import java.awt.Canvas;
41 import java.io.BufferedReader;
42 import java.io.IOException;
43 import java.io.InputStreamReader;
4144 import java.nio.ByteBuffer;
4245 import java.nio.FloatBuffer;
4346 import java.nio.IntBuffer;
4649 import org.lwjgl.LWJGLException;
4750 import org.lwjgl.LWJGLUtil;
4851 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;
4958
5059 final class LinuxDisplay implements DisplayImplementation {
5160 /* X11 constants */
406415 ByteBuffer handle = peer_info.lockAndGetHandle();
407416 try {
408417 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"));
410427 this.parent = parent;
411428 parent_window = parent != null ? getHandle(parent) : getRootWindow(getDisplay(), getDefaultScreen());
412429 current_window = nCreateWindow(getDisplay(), getDefaultScreen(), handle, mode, current_window_mode, x, y, undecorated, parent_window);
440457 private static native void mapRaised(long display, long window);
441458 private static native void reparentWindow(long display, long window, long parent, int x, int y);
442459
443 private boolean isAncestorXEmbedded(long window) throws LWJGLException {
460 private static boolean isAncestorXEmbedded(long window) throws LWJGLException {
444461 long xembed_atom = internAtom("_XEMBED_INFO", true);
445462 if (xembed_atom != None) {
446463 long w = window;
482499 ungrabKeyboard();
483500 nDestroyWindow(getDisplay(), getWindow());
484501 decDisplay();
502
503 if ( current_window_mode != WINDOWED )
504 Compiz.setLegacyFullscreenSupport(false);
485505 } finally {
486506 unlockAWT();
487507 }
523543 try {
524544 if( current_displaymode_extension == XRANDR && savedXrandrConfig.length > 0 )
525545 {
526 XRandR.setConfiguration( savedXrandrConfig );
546 AccessController.doPrivileged(new PrivilegedAction() {
547 public Object run() {
548 XRandR.setConfiguration( savedXrandrConfig );
549 return null;
550 }
551 });
527552 }
528553 else
529554 {
531556 }
532557 if (isXF86VidModeSupported())
533558 doSetGamma(saved_gamma);
559
560 Compiz.setLegacyFullscreenSupport(false);
534561 } catch (LWJGLException e) {
535562 LWJGLUtil.log("Caught exception while resetting mode: " + e);
536563 } finally {
605632 public DisplayMode init() throws LWJGLException {
606633 lockAWT();
607634 try {
635 Compiz.init();
636
608637 delete_atom = internAtom("WM_DELETE_WINDOW", false);
609638 current_displaymode_extension = getBestDisplayModeExtension();
610639 if (current_displaymode_extension == NONE)
614643 throw new LWJGLException("No modes available");
615644 switch (current_displaymode_extension) {
616645 case XRANDR:
617 savedXrandrConfig = XRandR.getConfiguration();
646 savedXrandrConfig = (Screen[])AccessController.doPrivileged(new PrivilegedAction() {
647 public Object run() {
648 return XRandR.getConfiguration();
649 }
650 });
618651 saved_mode = getCurrentXRandrMode();
619652 break;
620653 case XF86VIDMODE:
846879 setInputFocusUnsafe(current_window);
847880 }
848881 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 //}
855888 }
856889
857890 private void setFocused(boolean got_focus, int focus_detail) {
889922 try {
890923 if( current_displaymode_extension == XRANDR && savedXrandrConfig.length > 0 )
891924 {
892 XRandR.setConfiguration( savedXrandrConfig );
925 AccessController.doPrivileged(new PrivilegedAction() {
926 public Object run() {
927 XRandR.setConfiguration( savedXrandrConfig );
928 return null;
929 }
930 });
893931 }
894932 else
895933 {
12111249 public boolean isInsideWindow() {
12121250 return true;
12131251 }
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 }
7777 AccessController.doPrivileged(new PrivilegedExceptionAction() {
7878 public Object run() throws Exception {
7979 Application.getApplication().addApplicationListener(new ApplicationAdapter() {
80 public final void handleQuit(ApplicationEvent event) {
80 public void handleQuit(ApplicationEvent event) {
8181 doHandleQuit();
8282 }
8383 });
270270 *
271271 * - elias
272272 */
273 AbstractDrawable drawable = (AbstractDrawable)Display.getDrawable();
273274 if (Display.isFullscreen() && (frame != null && frame.getCanvas().syncCanvasPainted() || should_update)) {
274275 try {
275 MacOSXContextImplementation.resetView(Display.getDrawable().getContext().getPeerInfo(), Display.getDrawable().getContext());
276 MacOSXContextImplementation.resetView(drawable.peer_info, drawable.context);
276277 } catch (LWJGLException e) {
277278 LWJGLUtil.log("Failed to reset context: " + e);
278279 }
279280 }
280281 if (should_update) {
281 Display.getDrawable().getContext().update();
282 drawable.context.update();
282283 /* This is necessary to make sure the context won't "forget" about the view size */
283284 GL11.glGetInteger(GL11.GL_VIEWPORT, current_viewport);
284285 GL11.glViewport(current_viewport.get(0), current_viewport.get(1), current_viewport.get(2), current_viewport.get(3));
3434
3535 import org.lwjgl.BufferUtils;
3636 import org.lwjgl.LWJGLException;
37 import org.lwjgl.LWJGLUtil;
3837 import org.lwjgl.Sys;
3938
4039 /**
4544 * This class is thread-safe.
4645 *
4746 * @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 $
5049 */
51 public final class Pbuffer implements Drawable {
50 public final class Pbuffer extends AbstractDrawable {
5251 /**
5352 * Indicates that Pbuffers can be created.
5453 */
135134 public static final int DEPTH_BUFFER = RenderTexture.WGL_DEPTH_COMPONENT_NV;
136135
137136 /**
138 * Handle to the native GL rendering context
139 */
140 private final PeerInfo peer_info;
141
142 /**
143137 * Width
144138 */
145139 private final int width;
148142 * Height
149143 */
150144 private final int height;
151
152 private final Context context;
153
154 private boolean destroyed;
155145
156146 static {
157147 Sys.initialize();
226216 this.width = width;
227217 this.height = height;
228218 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
237224 this.context = new Context(peer_info, attribs, shared_context);
238225 }
239226
250237 renderTexture.pBufferAttribs);
251238 }
252239
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
262240 /**
263241 * Method to test for validity of the buffer. If this function returns true, the buffer contents is lost. The buffer can still
264242 * be used, but the results are undefined. The application is expected to release the buffer if needed, destroy it and recreate
272250 }
273251
274252 /**
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 /**
284253 * Gets the Pbuffer capabilities.
285254 *
286255 * @return a bitmask of Pbuffer capabilities.
287256 */
288257 public static int getCapabilities() {
289258 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 }
306259 }
307260
308261 // -----------------------------------------------------------------------------------------
4444 * pixel format selection path, which could trigger a crash.
4545 *
4646 * @author elias_naur@sourceforge.net
47 * @version $Revision: 3116 $
47 * @version $Revision: 3355 $
4848 */
4949
5050 public final class PixelFormat {
6565 * 0 means that anti-aliasing is disabled.
6666 */
6767 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;
6876 /** The number of auxiliary buffers */
6977 private int num_aux_buffers;
7078 /** The number of bits per pixel in the accumulation buffer */
7583 private boolean stereo;
7684 /** Whether this format specifies a floating point format */
7785 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 */
7990 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 */
8195 private boolean sRGB;
8296
8397 /**
131145 this.stencil = pf.stencil;
132146
133147 this.samples = pf.samples;
148 this.colorSamples = pf.colorSamples;
134149
135150 this.num_aux_buffers = pf.num_aux_buffers;
136151
244259 return pf;
245260 }
246261
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
247294 public int getAuxBuffers() {
248295 return num_aux_buffers;
249296 }
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 }
436436 * is maximized helps some gfx cards recover from fullscreen
437437 */
438438 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();
441442 } catch (LWJGLException e) {
442443 LWJGLUtil.log("Exception occurred while trying to make context current: " + e);
443444 }
972973 return "Rect: top = " + top + " bottom = " + bottom + " left = " + left + " right = " + right;
973974 }
974975 }
975 }
976 }
00 /*
1 * Copyright (c) 2002-2010 LWJGL Project
2 * All rights reserved.
3 *
1 * Copyright (c) 2002-2010 LWJGL Project All rights reserved.
42 * 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,
2519 * 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.
3025 */
3126
3227 package org.lwjgl.opengl;
3833 import java.util.HashMap;
3934 import java.util.List;
4035 import java.util.Map;
36 import java.util.regex.Matcher;
4137 import java.util.regex.Pattern;
42 import java.security.AccessController;
43 import java.security.PrivilegedAction;
38
39 import org.lwjgl.LWJGLUtil;
4440
4541 /**
4642 * Utility for working with the xrandr commmand-line utility. Assumes
4844 *
4945 * @author ryanm
5046 */
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 {
5957 screens = new HashMap/* <String, Screen[]> */();
6058
6159 // ProcessBuilder pb = new ProcessBuilder( "xrandr", "-q" );
6260 // pb.redirectErrorStream();
63 try {
61 try
62 {
6463 // Process p= pb.start();
65 Process p = Runtime.getRuntime().exec(new String[] { "xrandr", "-q"});
64 Process p = Runtime.getRuntime().exec( new String[] { "xrandr", "-q" } );
6665
6766 List/* <Screen> */currentList = new ArrayList/* <Screen> */();
6867 List/* <Screen> */possibles = new ArrayList/* <Screen> */();
6968 String name = null;
7069
71 BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
70 BufferedReader br = new BufferedReader( new InputStreamReader( p.getInputStream() ) );
7271 String line;
73 while ((line = br.readLine()) != null) {
72 while( ( line = br.readLine() ) != null )
73 {
7474 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 {
7879 // 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() ] ) );
8183 possibles.clear();
8284 }
83 name = sa[0];
85 name = sa[ 0 ];
8486
8587 // 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 {
8892 // found a new mode line
89 possibles.add(new Screen(name, sa[0]));
93 parseScreen( possibles, name, sa[ 0 ] );
9094 }
9195 }
9296
93 screens.put(name, possibles.toArray(new Screen[possibles.size()]));
97 screens.put( name, possibles.toArray( new Screen[ possibles.size() ] ) );
9498
9599 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 ];
98106 }
99107 }
100108 }
103111 * @return The current screen configuration, or an empty array if
104112 * xrandr is not supported
105113 */
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();
113117
114118 return (Screen[]) current.clone();
115119 }
117121 /**
118122 * @param screens
119123 * 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" );
124132 }
125133
126134 List/* <String> */cmd = new ArrayList/* <String> */();
127 cmd.add("xrandr");
135 cmd.add( "xrandr" );
128136
129137 // 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 {
131140 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 {
134145 found = true;
135146 break;
136147 }
137148 }
138149
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" );
143155 }
144156 }
145157
146158 // 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 {
152166 // ProcessBuilder pb = new ProcessBuilder( cmd );
153167 // pb.redirectErrorStream();
154168 // 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() ] ) );
156171 // 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() ) );
158173 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 );
161177 }
162178 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 }
167184 }
168185
169186 /**
170187 * @return the name of connected screens, or an empty array if
171188 * xrandr is not supported
172189 */
173 public static String[] getScreenNames() {
190 public static String[] getScreenNames()
191 {
174192 populate();
175 return (String[]) screens.keySet().toArray(new String[screens.size()]);
193 return ( String[] ) screens.keySet().toArray( new String[ screens.size() ] );
176194 }
177195
178196 /**
180198 * @return the possible resolutions of the named screen, or
181199 * <code>null</code> if there is no such screen
182200 */
183 public static Screen[] getResolutions(String name) {
201 public static Screen[] getResolutions( String name )
202 {
184203 populate();
185204 // clone the array to prevent held copies being altered
186205 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 ) );
187251 }
188252
189253 /**
192256 *
193257 * @author ryanm
194258 */
195 public static class Screen implements Cloneable {
196
259 public static class Screen implements Cloneable
260 {
197261 /**
198262 * Name for this output
199263 */
200 public final String name;
264 public final String name;
201265
202266 /**
203267 * Width in pixels
204268 */
205 public final int width;
269 public final int width;
206270
207271 /**
208272 * Height in pixels
209273 */
210 public final int height;
274 public final int height;
211275
212276 /**
213277 * Position on the x-axis, in pixels
214278 */
215 public int xPos = 0;
279 public int xPos = 0;
216280
217281 /**
218282 * Position on the y-axis, in pixels
219283 */
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 {
230288 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 {
253308 return name + " " + width + "x" + height + " @ " + xPos + "x" + yPos;
254309 }
255310 }
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 {