diff options
author | Kenneth Russel <[email protected]> | 2008-05-13 11:50:41 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2008-05-13 11:50:41 +0000 |
commit | 0e27cbfe6f60f0c39e826fcf374b7e7e03babe4f (patch) | |
tree | 6bc223b9bb1d7474179a6ec9e89a14ebc0c4f371 /src/classes | |
parent | 1f9c829513f1d6ca08081976bfed84822eecb385 (diff) |
Refactorings to support building JOGL for OpenGL ES 1 and OpenGL ES 2.
"ant -Djogl.es1=1" builds JOGL for OpenGL ES 1.
"ant -Djogl.es2=1" builds JOGL for OpenGL ES 2.
"ant" builds JOGL for desktop OpenGL (2.1).
Building desktop OpenGL is currently broken (FIXME) -- more
refactorings are necessary.
When compiling, it is currently necessary to specify
-Djogl.noglnatives=1 on the ant command line as well, because the
generated native code does not link properly since we do not have
OpenGL ES libraries on the desktop. Building the generated native code
using a cross-compiler is not yet hooked up into the ant build
mechanism. It is necessary to build the generated native code with
external tools.
Also incorporated spatialized audio framework using Windows waveOut
device; this is a temporary measure until a different workspace can be
found for this code.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1630 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/classes')
25 files changed, 2936 insertions, 339 deletions
diff --git a/src/classes/com/sun/javafx/audio/windows/waveout/Audio.java b/src/classes/com/sun/javafx/audio/windows/waveout/Audio.java new file mode 100755 index 000000000..8e4e97b0c --- /dev/null +++ b/src/classes/com/sun/javafx/audio/windows/waveout/Audio.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.sun.javafx.audio.windows.waveout; + +import java.io.*; + +public class Audio { + private static Audio instance = null; + private Mixer mixer; + + public synchronized static Audio getInstance() { + if (instance == null) { + instance = new Audio(); + } + return instance; + } + + private Audio() { + mixer = Mixer.getMixer(); + } + + public Mixer getMixer() { + return mixer; + } + + public Track newTrack(File file) throws IOException + { + Track res = new Track(file); + mixer.add(res); + return res; + } + + public void shutdown() { + mixer.shutdown(); + } +} diff --git a/src/classes/com/sun/javafx/audio/windows/waveout/Mixer.java b/src/classes/com/sun/javafx/audio/windows/waveout/Mixer.java new file mode 100755 index 000000000..814a74a8c --- /dev/null +++ b/src/classes/com/sun/javafx/audio/windows/waveout/Mixer.java @@ -0,0 +1,362 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.sun.javafx.audio.windows.waveout; + +import java.io.*; +import java.nio.*; +import java.util.*; + +// Needed only for NIO workarounds on CVM +import java.lang.reflect.*; + +public class Mixer { + // This class is a singleton + private static Mixer mixer; + + private volatile boolean shutdown; + private volatile Object shutdownLock = new Object(); + private volatile boolean shutdownDone; + + // Windows Event object + private long event; + + private volatile ArrayList/*<Track>*/ tracks = new ArrayList(); + + private Vec3f leftSpeakerPosition = new Vec3f(-1, 0, 0); + private Vec3f rightSpeakerPosition = new Vec3f( 1, 0, 0); + + private float falloffFactor = 1.0f; + + static { + mixer = new Mixer(); + } + + private Mixer() { + event = CreateEvent(); + new FillerThread().start(); + MixerThread m = new MixerThread(); + m.setPriority(Thread.MAX_PRIORITY - 1); + m.start(); + } + + public static Mixer getMixer() { + return mixer; + } + + synchronized void add(Track track) { + ArrayList/*<Track>*/ newTracks = (ArrayList) tracks.clone(); + newTracks.add(track); + tracks = newTracks; + } + + synchronized void remove(Track track) { + ArrayList/*<Track>*/ newTracks = (ArrayList) tracks.clone(); + newTracks.remove(track); + tracks = newTracks; + } + + // NOTE: due to a bug on the APX device, we only have mono sounds, + // so we currently only pay attention to the position of the left + // speaker + public void setLeftSpeakerPosition(float x, float y, float z) { + leftSpeakerPosition.set(x, y, z); + } + + // NOTE: due to a bug on the APX device, we only have mono sounds, + // so we currently only pay attention to the position of the left + // speaker + public void setRightSpeakerPosition(float x, float y, float z) { + rightSpeakerPosition.set(x, y, z); + } + + /** This defines a scale factor of sorts -- the higher the number, + the larger an area the sound will affect. Default value is + 1.0f. Valid values are [1.0f, ...]. The formula for the gain + for each channel is +<PRE> + falloffFactor + ------------------- + falloffFactor + r^2 +</PRE> +*/ + public void setFalloffFactor(float factor) { + falloffFactor = factor; + } + + public void shutdown() { + synchronized(shutdownLock) { + shutdown = true; + SetEvent(event); + try { + shutdownLock.wait(); + } catch (InterruptedException e) { + } + } + } + + class FillerThread extends Thread { + FillerThread() { + super("Mixer Thread"); + } + + public void run() { + while (!shutdown) { + List/*<Track>*/ curTracks = tracks; + + for (Iterator iter = curTracks.iterator(); iter.hasNext(); ) { + Track track = (Track) iter.next(); + try { + track.fill(); + } catch (IOException e) { + e.printStackTrace(); + remove(track); + } + } + + try { + // Run ten times per second + Thread.sleep(100); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + } + } + + class MixerThread extends Thread { + // Temporary mixing buffer + // Interleaved left and right channels + float[] mixingBuffer; + private Vec3f temp = new Vec3f(); + + MixerThread() { + super("Mixer Thread"); + if (!initializeWaveOut(event)) { + throw new InternalError("Error initializing waveout device"); + } + } + + public void run() { + while (!shutdown) { + // Get the next buffer + long mixerBuffer = getNextMixerBuffer(); + if (mixerBuffer != 0) { + ByteBuffer buf = getMixerBufferData(mixerBuffer); + + if (buf == null) { + // This is happening on CVM because + // JNI_NewDirectByteBuffer isn't implemented + // by default and isn't compatible with the + // JSR-239 NIO implementation (apparently) + buf = newDirectByteBuffer(getMixerBufferDataAddress(mixerBuffer), + getMixerBufferDataCapacity(mixerBuffer)); + } + + if (buf == null) { + throw new InternalError("Couldn't wrap the native address with a direct byte buffer"); + } + + // System.out.println("Mixing buffer"); + + // If we don't have enough samples in our mixing buffer, expand it + // FIXME: knowledge of native output rendering format + if ((mixingBuffer == null) || (mixingBuffer.length < (buf.capacity() / 2 /* bytes / sample */))) { + mixingBuffer = new float[buf.capacity() / 2]; + } else { + // Zap it + for (int i = 0; i < mixingBuffer.length; i++) { + mixingBuffer[i] = 0.0f; + } + } + + // This assertion should be in place if we have stereo + if ((mixingBuffer.length % 2) != 0) { + String msg = "FATAL ERROR: odd number of samples in the mixing buffer"; + System.out.println(msg); + throw new InternalError(msg); + } + + // Run down all of the registered tracks mixing them in + List/*<Track>*/ curTracks = tracks; + + for (Iterator iter = curTracks.iterator(); iter.hasNext(); ) { + Track track = (Track) iter.next(); + // Consider only playing tracks + if (track.isPlaying()) { + // First recompute its gain + Vec3f pos = track.getPosition(); + float leftGain = gain(pos, leftSpeakerPosition); + float rightGain = gain(pos, rightSpeakerPosition); + // Now mix it in + int i = 0; + while (i < mixingBuffer.length) { + if (track.hasNextSample()) { + float sample = track.nextSample(); + mixingBuffer[i++] = sample * leftGain; + mixingBuffer[i++] = sample * rightGain; + } else { + // This allows tracks to stall without being abruptly cancelled + if (track.done()) { + remove(track); + } + break; + } + } + } + } + + // Now that we have our data, send it down to the card + int outPos = 0; + for (int i = 0; i < mixingBuffer.length; i++) { + short val = (short) mixingBuffer[i]; + buf.put(outPos++, (byte) val); + buf.put(outPos++, (byte) (val >> 8)); + } + if (!prepareMixerBuffer(mixerBuffer)) { + throw new RuntimeException("Error preparing mixer buffer"); + } + if (!writeMixerBuffer(mixerBuffer)) { + throw new RuntimeException("Error writing mixer buffer to device"); + } + } else { + // System.out.println("No mixer buffer available"); + + // Wait for a buffer to become available + if (!WaitForSingleObject(event)) { + throw new RuntimeException("Error while waiting for event object"); + } + + /* + try { + Thread.sleep(10); + } catch (InterruptedException e) { + } + */ + } + } + + // Need to shut down + shutdownWaveOut(); + synchronized(shutdownLock) { + shutdownLock.notifyAll(); + } + } + + // This defines the 3D spatialization gain function. + // The function is defined as: + // falloffFactor + // ------------------- + // falloffFactor + r^2 + private float gain(Vec3f pos, Vec3f speakerPos) { + temp.sub(pos, speakerPos); + float dotp = temp.dot(temp); + return (falloffFactor / (falloffFactor + dotp)); + } + } + + // Initializes waveout device + private static native boolean initializeWaveOut(long eventObject); + // Shuts down waveout device + private static native void shutdownWaveOut(); + + // Gets the next (opaque) buffer of data to fill from the native + // code, or 0 if none was available yet (it should not happen that + // none is available the way the code is written). + private static native long getNextMixerBuffer(); + // Gets the next ByteBuffer to fill out of the mixer buffer. It + // requires interleaved left and right channel samples, 16 signed + // bits per sample, little endian. Implicit 44.1 kHz sample rate. + private static native ByteBuffer getMixerBufferData(long mixerBuffer); + // We need these to work around the lack of + // JNI_NewDirectByteBuffer in CVM + the JSR 239 NIO classes + private static native long getMixerBufferDataAddress(long mixerBuffer); + private static native int getMixerBufferDataCapacity(long mixerBuffer); + // Prepares this mixer buffer for writing to the device. + private static native boolean prepareMixerBuffer(long mixerBuffer); + // Writes this mixer buffer to the device. + private static native boolean writeMixerBuffer(long mixerBuffer); + + // Helpers to prevent mixer thread from busy waiting + private static native long CreateEvent(); + private static native boolean WaitForSingleObject(long event); + private static native void SetEvent(long event); + private static native void CloseHandle(long handle); + + // We need a reflective hack to wrap a direct ByteBuffer around + // the native memory because JNI_NewDirectByteBuffer doesn't work + // in CVM + JSR-239 NIO + private static Class directByteBufferClass; + private static Constructor directByteBufferConstructor; + private static Map createdBuffers = new HashMap(); // Map Long, ByteBuffer + + private static ByteBuffer newDirectByteBuffer(long address, long capacity) { + Long key = new Long(address); + ByteBuffer buf = (ByteBuffer) createdBuffers.get(key); + if (buf == null) { + buf = newDirectByteBufferImpl(address, capacity); + if (buf != null) { + createdBuffers.put(key, buf); + } + } + return buf; + } + private static ByteBuffer newDirectByteBufferImpl(long address, long capacity) { + if (directByteBufferClass == null) { + try { + directByteBufferClass = Class.forName("java.nio.DirectByteBuffer"); + byte[] tmp = new byte[0]; + directByteBufferConstructor = + directByteBufferClass.getDeclaredConstructor(new Class[] { Integer.TYPE, + tmp.getClass(), + Integer.TYPE }); + directByteBufferConstructor.setAccessible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + + if (directByteBufferConstructor != null) { + try { + return (ByteBuffer) + directByteBufferConstructor.newInstance(new Object[] { + new Integer((int) capacity), + null, + new Integer((int) address) + }); + } catch (Exception e) { + e.printStackTrace(); + } + } + return null; + } +} diff --git a/src/classes/com/sun/javafx/audio/windows/waveout/SoundBuffer.java b/src/classes/com/sun/javafx/audio/windows/waveout/SoundBuffer.java new file mode 100755 index 000000000..b0404673e --- /dev/null +++ b/src/classes/com/sun/javafx/audio/windows/waveout/SoundBuffer.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.sun.javafx.audio.windows.waveout; + +import java.io.*; + +class SoundBuffer { + private byte[] data; + private boolean needsByteSwap; + private int numBytes; + private int bytesPerSample; + private int numSamples; + private boolean playing; + private boolean empty; + + // Note: needsByteSwap argument makes assumptions about the format + SoundBuffer(int size, int bytesPerSample, boolean needsByteSwap) { + this.bytesPerSample = bytesPerSample; + this.needsByteSwap = needsByteSwap; + data = new byte[size * bytesPerSample]; + empty = true; + } + + boolean playing() { + return playing; + } + + void playing(boolean playing) { + this.playing = playing; + } + + boolean empty() { + return empty; + } + + void empty(boolean empty) { + this.empty = empty; + } + + void fill(InputStream input) throws IOException { + synchronized(this) { + if (playing) { + throw new IllegalStateException("Can not fill a buffer that is playing"); + } + } + + empty(true); + int num = input.read(data); + if (num > 0) { + numBytes = num; + numSamples = numBytes / bytesPerSample; + empty(false); + if ((numBytes % bytesPerSample) != 0) { + System.out.println("WARNING: needed integral multiple of " + bytesPerSample + + " bytes, but read " + numBytes + " bytes"); + } + } else { + numBytes = 0; + } + } + + int numSamples() { + return numSamples; + } + + // This is called by the mixer and must be extremely fast + // FIXME: may want to reconsider use of floating point at this point + // FIXME: assumes all sounds are of the same format to avoid normalization + float getSample(int sample) { + int startByte = sample * bytesPerSample; + // FIXME: assumes no more than 4 bytes per sample + int res = 0; + if (needsByteSwap) { + for (int i = startByte + bytesPerSample - 1; i >= startByte; i--) { + res <<= 8; + res |= (data[i] & 0xff); + } + } else { + int endByte = startByte + bytesPerSample - 1; + for (int i = startByte; i <= endByte; i++) { + res <<= 8; + res |= (data[i] & 0xff); + } + } + // Sign extend + if (bytesPerSample == 2) { + res = (short) res; + } else if (bytesPerSample == 1) { + res = (byte) res; + } + + return (float) res; + } +} diff --git a/src/classes/com/sun/javafx/audio/windows/waveout/TestSpatialization.java b/src/classes/com/sun/javafx/audio/windows/waveout/TestSpatialization.java new file mode 100755 index 000000000..e4ade6375 --- /dev/null +++ b/src/classes/com/sun/javafx/audio/windows/waveout/TestSpatialization.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.sun.javafx.audio.windows.waveout; + +import java.io.*; +import javax.media.opengl.GLDrawableFactory; + +public class TestSpatialization { + public static void main(String[] args) { + if (args.length != 1) { + System.out.println("Usage: TestSpatialization [file name]"); + System.exit(1); + } + + try { + // FIXME: this is a hack to get the native library loaded + GLDrawableFactory.getFactory(); + // Initialize the audio subsystem + Audio audio = Audio.getInstance(); + // Create a track + Track track = audio.newTrack(new File(args[0])); + track.setPosition(1, 0, 0); + // Run for ten seconds + long startTime = System.currentTimeMillis(); + long duration = 10000; + long curTime = 0; + try { + Thread.sleep(500); + } catch (InterruptedException e) { + } + System.out.println("Playing..."); + track.setLooping(true); + track.play(); + while ((curTime = System.currentTimeMillis()) < startTime + duration) { + // Make one revolution every two seconds + float rads = (float) (((2 * Math.PI) * (((float) (curTime - startTime)) / 1000.0f)) / 2); + track.setPosition((float) Math.cos(rads), 0, (float) Math.sin(rads)); + // Would like to make it go in a circle, but since + // stereo doesn't work now, make it move along a line + // track.setPosition(-1.0f, 0, 2.0f * (float) Math.sin(rads)); + // Sleep a little between updates + try { + Thread.sleep(10); + } catch (InterruptedException e) { + } + } + System.out.println("Shutting down audio subsystem"); + audio.shutdown(); + System.out.println("Exiting."); + System.exit(0); + } catch (Exception e) { + e.printStackTrace(); + System.exit(1); + } + } +} diff --git a/src/classes/com/sun/javafx/audio/windows/waveout/Track.java b/src/classes/com/sun/javafx/audio/windows/waveout/Track.java new file mode 100755 index 000000000..190396112 --- /dev/null +++ b/src/classes/com/sun/javafx/audio/windows/waveout/Track.java @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.sun.javafx.audio.windows.waveout; + +import java.io.*; +import java.nio.*; + +public class Track { + // Default number of samples per buffer + private static final int BUFFER_SIZE = 32768; + // Number of bytes per sample (FIXME: dependence on audio format) + static final int BYTES_PER_SAMPLE = 2; + // Whether we need byte swapping (FIXME: dependence on audio format) + static final boolean NEEDS_BYTE_SWAP = true; + + // This is the buffer this track is currently playing from + private SoundBuffer activeBuffer; + // This is the sample position in the active buffer + private int samplePosition; + // This is the total number of samples in the file + private int totalSamples; + // This is the total number of samples we have read + private int samplesRead; + // This is the buffer that the background filler thread may be filling + private SoundBuffer fillingBuffer; + // If we're playing the file, this is its input stream + private InputStream input; + // Keep around the file name + private File file; + // Whether we're playing this sound + private boolean playing; + // Whether we're looping this sound + private boolean looping; + // The position of this sound; defaults to being at the origin + private volatile Vec3f position = new Vec3f(); + + Track(File file) throws IOException { + if (!file.getName().endsWith(".rawsound")) { + throw new IOException("Unsupported file format (currently supports only raw sounds)"); + } + + this.file = file; + openInput(); + + // Allocate the buffers + activeBuffer = new SoundBuffer(BUFFER_SIZE, BYTES_PER_SAMPLE, NEEDS_BYTE_SWAP); + fillingBuffer = new SoundBuffer(BUFFER_SIZE, BYTES_PER_SAMPLE, NEEDS_BYTE_SWAP); + + // Fill the first buffer immediately + fill(); + swapBuffers(); + } + + private void openInput() throws IOException { + input = new BufferedInputStream(new FileInputStream(file)); + totalSamples = (int) file.length() / BYTES_PER_SAMPLE; + } + + public File getFile() { + return file; + } + + public synchronized void play() { + if (input == null) { + try { + openInput(); + // Fill it immediately + fill(); + } catch (IOException e) { + e.printStackTrace(); + return; + } + } + + playing = true; + } + + public synchronized boolean isPlaying() { + return playing; + } + + public synchronized void setLooping(boolean looping) { + this.looping = looping; + } + + public synchronized boolean isLooping() { + return looping; + } + + public void setPosition(float x, float y, float z) { + position = new Vec3f(x, y, z); + } + + synchronized void fill() throws IOException { + if (input == null) { + return; + } + SoundBuffer curBuffer = fillingBuffer; + if (!curBuffer.empty()) { + return; + } + curBuffer.fill(input); + if (curBuffer.empty()) { + // End of file + InputStream tmp = null; + synchronized(this) { + tmp = input; + input = null; + } + tmp.close(); + + // If looping, re-open + if (isLooping()) { + openInput(); + // and fill + fill(); + } + } + } + + // These are only for use by the Mixer + private float leftGain; + private float rightGain; + + void setLeftGain(float leftGain) { + this.leftGain = leftGain; + } + + float getLeftGain() { + return leftGain; + } + + void setRightGain(float rightGain) { + this.rightGain = rightGain; + } + + float getRightGain() { + return rightGain; + } + + Vec3f getPosition() { + return position; + } + + // This is called by the mixer and must be extremely fast + // Note this assumes mono sounds (FIXME) + boolean hasNextSample() { + return (!activeBuffer.empty() && samplePosition < activeBuffer.numSamples()); + } + + // This is called by the mixer and must be extremely fast + float nextSample() { + float res = activeBuffer.getSample(samplePosition++); + ++samplesRead; + if (!hasNextSample()) { + swapBuffers(); + samplePosition = 0; + if (done()) { + playing = false; + } + } + return res; + } + + synchronized void swapBuffers() { + SoundBuffer tmp = activeBuffer; + activeBuffer = fillingBuffer; + fillingBuffer = tmp; + fillingBuffer.empty(true); + } + + // This provides a more robust termination condition + boolean done() { + return (samplesRead == totalSamples) && !looping; + } +} diff --git a/src/classes/com/sun/javafx/audio/windows/waveout/Vec3f.java b/src/classes/com/sun/javafx/audio/windows/waveout/Vec3f.java new file mode 100755 index 000000000..9a3038e35 --- /dev/null +++ b/src/classes/com/sun/javafx/audio/windows/waveout/Vec3f.java @@ -0,0 +1,212 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +package com.sun.javafx.audio.windows.waveout; + +/** 3-element single-precision vector */ + +class Vec3f { + public static final Vec3f X_AXIS = new Vec3f( 1, 0, 0); + public static final Vec3f Y_AXIS = new Vec3f( 0, 1, 0); + public static final Vec3f Z_AXIS = new Vec3f( 0, 0, 1); + public static final Vec3f NEG_X_AXIS = new Vec3f(-1, 0, 0); + public static final Vec3f NEG_Y_AXIS = new Vec3f( 0, -1, 0); + public static final Vec3f NEG_Z_AXIS = new Vec3f( 0, 0, -1); + + private float x; + private float y; + private float z; + + public Vec3f() {} + + public Vec3f(Vec3f arg) { + set(arg); + } + + public Vec3f(float x, float y, float z) { + set(x, y, z); + } + + public Vec3f copy() { + return new Vec3f(this); + } + + public void set(Vec3f arg) { + set(arg.x, arg.y, arg.z); + } + + public void set(float x, float y, float z) { + this.x = x; + this.y = y; + this.z = z; + } + + /** Sets the ith component, 0 <= i < 3 */ + public void set(int i, float val) { + switch (i) { + case 0: x = val; break; + case 1: y = val; break; + case 2: z = val; break; + default: throw new IndexOutOfBoundsException(); + } + } + + /** Gets the ith component, 0 <= i < 3 */ + public float get(int i) { + switch (i) { + case 0: return x; + case 1: return y; + case 2: return z; + default: throw new IndexOutOfBoundsException(); + } + } + + public float x() { return x; } + public float y() { return y; } + public float z() { return z; } + + public void setX(float x) { this.x = x; } + public void setY(float y) { this.y = y; } + public void setZ(float z) { this.z = z; } + + public float dot(Vec3f arg) { + return x * arg.x + y * arg.y + z * arg.z; + } + + public float length() { + return (float) Math.sqrt(lengthSquared()); + } + + public float lengthSquared() { + return this.dot(this); + } + + public void normalize() { + float len = length(); + if (len == 0.0f) return; + scale(1.0f / len); + } + + /** Returns this * val; creates new vector */ + public Vec3f times(float val) { + Vec3f tmp = new Vec3f(this); + tmp.scale(val); + return tmp; + } + + /** this = this * val */ + public void scale(float val) { + x *= val; + y *= val; + z *= val; + } + + /** Returns this + arg; creates new vector */ + public Vec3f plus(Vec3f arg) { + Vec3f tmp = new Vec3f(); + tmp.add(this, arg); + return tmp; + } + + /** this = this + b */ + public void add(Vec3f b) { + add(this, b); + } + + /** this = a + b */ + public void add(Vec3f a, Vec3f b) { + x = a.x + b.x; + y = a.y + b.y; + z = a.z + b.z; + } + + /** Returns this + s * arg; creates new vector */ + public Vec3f addScaled(float s, Vec3f arg) { + Vec3f tmp = new Vec3f(); + tmp.addScaled(this, s, arg); + return tmp; + } + + /** this = a + s * b */ + public void addScaled(Vec3f a, float s, Vec3f b) { + x = a.x + s * b.x; + y = a.y + s * b.y; + z = a.z + s * b.z; + } + + /** Returns this - arg; creates new vector */ + public Vec3f minus(Vec3f arg) { + Vec3f tmp = new Vec3f(); + tmp.sub(this, arg); + return tmp; + } + + /** this = this - b */ + public void sub(Vec3f b) { + sub(this, b); + } + + /** this = a - b */ + public void sub(Vec3f a, Vec3f b) { + x = a.x - b.x; + y = a.y - b.y; + z = a.z - b.z; + } + + /** Returns this cross arg; creates new vector */ + public Vec3f cross(Vec3f arg) { + Vec3f tmp = new Vec3f(); + tmp.cross(this, arg); + return tmp; + } + + /** this = a cross b. NOTE: "this" must be a different vector than + both a and b. */ + public void cross(Vec3f a, Vec3f b) { + x = a.y * b.z - a.z * b.y; + y = a.z * b.x - a.x * b.z; + z = a.x * b.y - a.y * b.x; + } + + /** Sets each component of this vector to the product of the + component with the corresponding component of the argument + vector. */ + public void componentMul(Vec3f arg) { + x *= arg.x; + y *= arg.y; + z *= arg.z; + } + + public String toString() { + return "(" + x + ", " + y + ", " + z + ")"; + } +} diff --git a/src/classes/com/sun/opengl/impl/FunctionAvailabilityCache.java b/src/classes/com/sun/opengl/impl/FunctionAvailabilityCache.java index c2392baa9..4eb34b7f2 100644 --- a/src/classes/com/sun/opengl/impl/FunctionAvailabilityCache.java +++ b/src/classes/com/sun/opengl/impl/FunctionAvailabilityCache.java @@ -41,10 +41,8 @@ package com.sun.opengl.impl; import javax.media.opengl.*; import java.util.*; -import java.util.regex.*; -import java.awt.Canvas; -import java.awt.Graphics; -import java.awt.GraphicsConfiguration; +// FIXME: refactor Java SE dependencies +//import java.util.regex.*; import java.lang.reflect.*; /** @@ -325,6 +323,7 @@ public final class FunctionAvailabilityCache { major = Integer.valueOf(tok.nextToken()).intValue(); minor = Integer.valueOf(tok.nextToken()).intValue(); + /* // See if there's version-specific information which might // imply a more recent OpenGL version tok = new StringTokenizer(versionString, " "); @@ -347,14 +346,22 @@ public final class FunctionAvailabilityCache { } } } + */ } } catch (Exception e) { + // FIXME: refactor desktop OpenGL dependencies and make this + // class work properly for OpenGL ES + e.printStackTrace(); + major = 1; + minor = 0; + /* throw (IllegalArgumentException) new IllegalArgumentException( "Illegally formatted version identifier: \"" + versionString + "\"") .initCause(e); + */ } } diff --git a/src/classes/com/sun/opengl/impl/GLBufferSizeTracker.java b/src/classes/com/sun/opengl/impl/GLBufferSizeTracker.java index 4538f8450..3cc756788 100755 --- a/src/classes/com/sun/opengl/impl/GLBufferSizeTracker.java +++ b/src/classes/com/sun/opengl/impl/GLBufferSizeTracker.java @@ -151,10 +151,10 @@ public class GLBufferSizeTracker { if (sz == null) { // For robustness, try to query this value from the GL as we used to int[] tmp = new int[1]; - caller.glGetBufferParameterivARB(target, GL.GL_BUFFER_SIZE_ARB, tmp, 0); + caller.glGetBufferParameteriv(target, GL.GL_BUFFER_SIZE, tmp, 0); if (tmp[0] == 0) { // Assume something is wrong rather than silently going along - throw new GLException("Error: buffer size returned by glGetBufferParameterivARB was zero; probably application error"); + throw new GLException("Error: buffer size returned by glGetBufferParameteriv was zero; probably application error"); } // Assume we just don't know what's happening sz = new Integer(tmp[0]); @@ -170,7 +170,7 @@ public class GLBufferSizeTracker { } // We don't know what's going on in this case; query the GL for an answer int[] tmp = new int[1]; - caller.glGetBufferParameterivARB(target, GL.GL_BUFFER_SIZE_ARB, tmp, 0); + caller.glGetBufferParameteriv(target, GL.GL_BUFFER_SIZE, tmp, 0); if (DEBUG) { System.err.println("GLBufferSizeTracker.getBufferSize(): no cached buffer information"); } diff --git a/src/classes/com/sun/opengl/impl/GLBufferStateTracker.java b/src/classes/com/sun/opengl/impl/GLBufferStateTracker.java index 2c4a9963e..54acd8899 100755 --- a/src/classes/com/sun/opengl/impl/GLBufferStateTracker.java +++ b/src/classes/com/sun/opengl/impl/GLBufferStateTracker.java @@ -81,8 +81,9 @@ public class GLBufferStateTracker { private static final Integer arrayBufferEnum = new Integer(GL.GL_ARRAY_BUFFER); private static final Integer elementArrayBufferEnum = new Integer(GL.GL_ELEMENT_ARRAY_BUFFER); - private static final Integer pixelPackBufferEnum = new Integer(GL.GL_PIXEL_PACK_BUFFER); - private static final Integer pixelUnpackBufferEnum = new Integer(GL.GL_PIXEL_UNPACK_BUFFER); + // FIXME: refactor dependencies on desktop OpenGL + // private static final Integer pixelPackBufferEnum = new Integer(GL.GL_PIXEL_PACK_BUFFER); + // private static final Integer pixelUnpackBufferEnum = new Integer(GL.GL_PIXEL_UNPACK_BUFFER); private static final Integer zero = new Integer(0); // Maps binding targets to buffer objects. A null value indicates @@ -96,8 +97,9 @@ public class GLBufferStateTracker { // Start with known unbound targets for known keys bindingMap.put(arrayBufferEnum, zero); bindingMap.put(elementArrayBufferEnum, zero); - bindingMap.put(pixelPackBufferEnum, zero); - bindingMap.put(pixelUnpackBufferEnum, zero); + // FIXME: refactor dependencies on desktop OpenGL + // bindingMap.put(pixelPackBufferEnum, zero); + // bindingMap.put(pixelUnpackBufferEnum, zero); } public void setBoundBufferObject(int target, int buffer) { @@ -121,8 +123,9 @@ public class GLBufferStateTracker { switch (target) { case GL.GL_ARRAY_BUFFER: queryTarget = GL.GL_ARRAY_BUFFER_BINDING; break; case GL.GL_ELEMENT_ARRAY_BUFFER: queryTarget = GL.GL_ELEMENT_ARRAY_BUFFER_BINDING; break; - case GL.GL_PIXEL_PACK_BUFFER: queryTarget = GL.GL_PIXEL_PACK_BUFFER_BINDING; break; - case GL.GL_PIXEL_UNPACK_BUFFER: queryTarget = GL.GL_PIXEL_UNPACK_BUFFER_BINDING; break; + // FIXME: refactor dependencies on desktop OpenGL + // case GL.GL_PIXEL_PACK_BUFFER: queryTarget = GL.GL_PIXEL_PACK_BUFFER_BINDING; break; + // case GL.GL_PIXEL_UNPACK_BUFFER: queryTarget = GL.GL_PIXEL_UNPACK_BUFFER_BINDING; break; default: gotQueryTarget = false; break; } if (gotQueryTarget) { @@ -165,8 +168,9 @@ public class GLBufferStateTracker { case 0: return zero; case GL.GL_ARRAY_BUFFER: return arrayBufferEnum; case GL.GL_ELEMENT_ARRAY_BUFFER: return elementArrayBufferEnum; - case GL.GL_PIXEL_PACK_BUFFER: return pixelPackBufferEnum; - case GL.GL_PIXEL_UNPACK_BUFFER: return pixelUnpackBufferEnum; + // FIXME: refactor dependencies on desktop OpenGL + // case GL.GL_PIXEL_PACK_BUFFER: return pixelPackBufferEnum; + // case GL.GL_PIXEL_UNPACK_BUFFER: return pixelUnpackBufferEnum; default: return new Integer(key); } } diff --git a/src/classes/com/sun/opengl/impl/GLContextImpl.java b/src/classes/com/sun/opengl/impl/GLContextImpl.java index 21e6d6598..55ed1cc52 100644 --- a/src/classes/com/sun/opengl/impl/GLContextImpl.java +++ b/src/classes/com/sun/opengl/impl/GLContextImpl.java @@ -39,7 +39,8 @@ package com.sun.opengl.impl; -import java.awt.Component; +// FIXME: refactor +// import java.awt.Component; import java.nio.*; import javax.media.opengl.*; @@ -72,6 +73,8 @@ public abstract class GLContextImpl extends GLContext { // repeated glGet calls upon glMapBuffer operations private GLBufferSizeTracker bufferSizeTracker; + /* FIXME: needed only by the Java 2D / JOGL bridge; refactor + // Tracks creation and deletion of server-side OpenGL objects when // the Java2D/OpenGL pipeline is active and using FBOs to render private GLObjectTracker tracker; @@ -79,11 +82,16 @@ public abstract class GLContextImpl extends GLContext { // current which can support immediate deletion of them private GLObjectTracker deletedObjectTracker; + */ + protected GL gl; + + /* FIXME: refactor these dependencies on the Java 2D / JOGL bridge + public GLContextImpl(GLContext shareWith) { this(shareWith, false); } - + public GLContextImpl(GLContext shareWith, boolean dontShareWithJava2D) { functionAvailability = new FunctionAvailabilityCache(this); GLContext shareContext = shareWith; @@ -104,6 +112,18 @@ public abstract class GLContextImpl extends GLContext { setGL(createGL()); } + */ + + public GLContextImpl(GLContext shareWith) { + functionAvailability = new FunctionAvailabilityCache(this); + if (shareWith != null) { + GLContextShareSet.registerSharing(this, shareWith); + } + // This must occur after the above calls into the + // GLContextShareSet, which set up state needed by the GL object + setGL(createGL()); + } + public int makeCurrent() throws GLException { // Support calls to makeCurrent() over and over again with // different contexts without releasing them @@ -132,11 +152,13 @@ public abstract class GLContextImpl extends GLContext { int res = 0; try { res = makeCurrentImpl(); + /* FIXME: refactor dependence on Java 2D / JOGL bridge if ((tracker != null) && (res == CONTEXT_CURRENT_NEW)) { // Increase reference count of GLObjectTracker tracker.ref(); } + */ } catch (GLException e) { lock.unlock(); throw(e); @@ -146,11 +168,14 @@ public abstract class GLContextImpl extends GLContext { } else { setCurrent(this); + /* FIXME: refactor dependence on Java 2D / JOGL bridge + // Try cleaning up any stale server-side OpenGL objects // FIXME: not sure what to do here if this throws if (deletedObjectTracker != null) { deletedObjectTracker.clean(getGL()); } + */ } return res; } @@ -176,6 +201,7 @@ public abstract class GLContextImpl extends GLContext { throw new GLException("Can not destroy context while it is current"); } + /* FIXME: refactor dependence on Java 2D / JOGL bridge if (tracker != null) { // Don't need to do anything for contexts that haven't been // created yet @@ -190,6 +216,7 @@ public abstract class GLContextImpl extends GLContext { tracker.unref(deletedObjectTracker); } } + */ // Because we don't know how many other contexts we might be // sharing with (and it seems too complicated to implement the @@ -239,9 +266,11 @@ public abstract class GLContextImpl extends GLContext { /** Create the GL for this context. */ protected GL createGL() { GLImpl gl = new GLImpl(this); + /* FIXME: refactor dependence on Java 2D / JOGL bridge if (tracker != null) { gl.setObjectTracker(tracker); } + */ return gl; } @@ -386,6 +415,8 @@ public abstract class GLContextImpl extends GLContext { return bufferSizeTracker; } + /* FIXME: refactor dependence on Java 2D / JOGL bridge + //--------------------------------------------------------------------------- // Helpers for integration with Java2D/OpenGL pipeline when FBOs are // being used @@ -407,6 +438,8 @@ public abstract class GLContextImpl extends GLContext { return deletedObjectTracker; } + */ + //--------------------------------------------------------------------------- // Helpers for context optimization where the last context is left // current on the OpenGL worker thread diff --git a/src/classes/com/sun/opengl/impl/GLContextShareSet.java b/src/classes/com/sun/opengl/impl/GLContextShareSet.java index e02ef1fb5..a3614633d 100644 --- a/src/classes/com/sun/opengl/impl/GLContextShareSet.java +++ b/src/classes/com/sun/opengl/impl/GLContextShareSet.java @@ -39,9 +39,10 @@ package com.sun.opengl.impl; -import java.awt.GraphicsConfiguration; -import java.awt.GraphicsDevice; -import java.awt.GraphicsEnvironment; +// FIXME: refactor Java SE dependencies +// import java.awt.GraphicsConfiguration; +// import java.awt.GraphicsDevice; +// import java.awt.GraphicsEnvironment; import java.lang.ref.*; import java.util.*; import javax.media.opengl.*; @@ -51,7 +52,8 @@ import javax.media.opengl.*; context creation as is inherent in the AWT and Swing. */ public class GLContextShareSet { - private static boolean forceTracking = Debug.isPropertyDefined("jogl.glcontext.forcetracking"); + // FIXME: refactor Java SE dependencies + // private static boolean forceTracking = Debug.isPropertyDefined("jogl.glcontext.forcetracking"); private static final boolean DEBUG = Debug.debug("GLContextShareSet"); // This class is implemented with a WeakHashMap that goes from the @@ -148,122 +150,123 @@ public class GLContextShareSet { } } - /** Indicates that the two supplied contexts (which must be able to - share textures and display lists) should be in the same - namespace for tracking of server-side object creation and - deletion. Because the sharing necessary behind the scenes is - different than that requested at the user level, the two notions - are different. This must be called immediately after the - creation of the new context (which is the second argument) - before any server-side OpenGL objects have been created in that - context. */ - public static void registerForObjectTracking(GLContext olderContextOrNull, - GLContext newContext, - GLContext realShareContext) { - if (isObjectTrackingEnabled() || isObjectTrackingDebuggingEnabled()) { - GLContextImpl impl1 = null; - GLContextImpl impl2 = null; - GLObjectTracker tracker = null; - - synchronized (GLContextShareSet.class) { - if (olderContextOrNull != null && - newContext != null) { - if (entryFor(olderContextOrNull) != entryFor(newContext)) { - throw new IllegalArgumentException("old and new contexts must be able to share textures and display lists"); - } - } - - // FIXME: downcast to GLContextImpl undesirable - impl1 = (GLContextImpl) olderContextOrNull; - impl2 = (GLContextImpl) newContext; - - GLObjectTracker deletedObjectTracker = null; - GLContextImpl shareImpl = (GLContextImpl) realShareContext; - // Before we zap the "user-level" object trackers, make sure - // that all contexts in the share set share the destroyed object - // tracker - if (shareImpl != null) { - deletedObjectTracker = shareImpl.getDeletedObjectTracker(); - } - if (deletedObjectTracker == null) { - // Must create one and possibly set it up in the older context - deletedObjectTracker = new GLObjectTracker(); - if (DEBUG) { - System.err.println("Created deletedObjectTracker " + deletedObjectTracker + " because " + - ((shareImpl == null) ? "shareImpl was null" : "shareImpl's (" + shareImpl + ") deletedObjectTracker was null")); - } - - if (shareImpl != null) { - // FIXME: think should really assert in this case - shareImpl.setDeletedObjectTracker(deletedObjectTracker); - if (DEBUG) { - System.err.println("Set deletedObjectTracker " + deletedObjectTracker + " in shareImpl context " + shareImpl); - } - } - } - impl2.setDeletedObjectTracker(deletedObjectTracker); - if (DEBUG) { - System.err.println("Set deletedObjectTracker " + deletedObjectTracker + " in impl2 context " + impl2); - } - } - - // Must not hold lock around this operation - // Don't share object trackers with the primordial share context from Java2D - if (Java2D.isOGLPipelineActive()) { - // FIXME: probably need to do something different here - // Need to be able to figure out the GraphicsDevice for the - // older context if it's on-screen - GraphicsConfiguration gc = GraphicsEnvironment. - getLocalGraphicsEnvironment(). - getDefaultScreenDevice(). - getDefaultConfiguration(); - GLContext j2dShareContext = Java2D.getShareContext(gc); - if (impl1 != null && impl1 == j2dShareContext) { - impl1 = null; - } - } - - synchronized (GLContextShareSet.class) { - if (impl1 != null) { - tracker = impl1.getObjectTracker(); - assert (tracker != null) - : "registerForObjectTracking was not called properly for the older context"; - } - if (tracker == null) { - tracker = new GLObjectTracker(); - } - // Note that we don't assert that the tracker is non-null for - // impl2 because the way we use this functionality we actually - // overwrite the initially-set object tracker in the new context - impl2.setObjectTracker(tracker); - } - } - } - - /** In order to avoid glGet calls for buffer object checks related - to glVertexPointer, etc. calls as well as glMapBuffer calls, we - need to share the same GLBufferSizeTracker object between - contexts sharing textures and display lists. For now we keep - this mechanism orthogonal to the GLObjectTracker to hopefully - keep things easier to understand. (The GLObjectTracker is - currently only needed in a fairly esoteric case, when the - Java2D/JOGL bridge is active, but the GLBufferSizeTracker - mechanism is now always required.) */ - public static void registerForBufferObjectSharing(GLContext olderContextOrNull, GLContext newContext) { - // FIXME: downcasts to GLContextImpl undesirable - GLContextImpl older = (GLContextImpl) olderContextOrNull; - GLContextImpl newer = (GLContextImpl) newContext; - GLBufferSizeTracker tracker = null; - if (older != null) { - tracker = older.getBufferSizeTracker(); - assert (tracker != null) - : "registerForBufferObjectSharing was not called properly for the older context, or has a bug in it"; - } - if (tracker == null) { - tracker = new GLBufferSizeTracker(); - } - newer.setBufferSizeTracker(tracker); - } + // FIXME: refactor Java SE dependencies + // /** Indicates that the two supplied contexts (which must be able to + // share textures and display lists) should be in the same + // namespace for tracking of server-side object creation and + // deletion. Because the sharing necessary behind the scenes is + // different than that requested at the user level, the two notions + // are different. This must be called immediately after the + // creation of the new context (which is the second argument) + // before any server-side OpenGL objects have been created in that + // context. */ + // public static void registerForObjectTracking(GLContext olderContextOrNull, + // GLContext newContext, + // GLContext realShareContext) { + // if (isObjectTrackingEnabled() || isObjectTrackingDebuggingEnabled()) { + // GLContextImpl impl1 = null; + // GLContextImpl impl2 = null; + // GLObjectTracker tracker = null; + // + // synchronized (GLContextShareSet.class) { + // if (olderContextOrNull != null && + // newContext != null) { + // if (entryFor(olderContextOrNull) != entryFor(newContext)) { + // throw new IllegalArgumentException("old and new contexts must be able to share textures and display lists"); + // } + // } + // + // // FIXME: downcast to GLContextImpl undesirable + // impl1 = (GLContextImpl) olderContextOrNull; + // impl2 = (GLContextImpl) newContext; + // + // GLObjectTracker deletedObjectTracker = null; + // GLContextImpl shareImpl = (GLContextImpl) realShareContext; + // // Before we zap the "user-level" object trackers, make sure + // // that all contexts in the share set share the destroyed object + // // tracker + // if (shareImpl != null) { + // deletedObjectTracker = shareImpl.getDeletedObjectTracker(); + // } + // if (deletedObjectTracker == null) { + // // Must create one and possibly set it up in the older context + // deletedObjectTracker = new GLObjectTracker(); + // if (DEBUG) { + // System.err.println("Created deletedObjectTracker " + deletedObjectTracker + " because " + + // ((shareImpl == null) ? "shareImpl was null" : "shareImpl's (" + shareImpl + ") deletedObjectTracker was null")); + // } + // + // if (shareImpl != null) { + // // FIXME: think should really assert in this case + // shareImpl.setDeletedObjectTracker(deletedObjectTracker); + // if (DEBUG) { + // System.err.println("Set deletedObjectTracker " + deletedObjectTracker + " in shareImpl context " + shareImpl); + // } + // } + // } + // impl2.setDeletedObjectTracker(deletedObjectTracker); + // if (DEBUG) { + // System.err.println("Set deletedObjectTracker " + deletedObjectTracker + " in impl2 context " + impl2); + // } + // } + // + // // Must not hold lock around this operation + // // Don't share object trackers with the primordial share context from Java2D + // if (Java2D.isOGLPipelineActive()) { + // // FIXME: probably need to do something different here + // // Need to be able to figure out the GraphicsDevice for the + // // older context if it's on-screen + // GraphicsConfiguration gc = GraphicsEnvironment. + // getLocalGraphicsEnvironment(). + // getDefaultScreenDevice(). + // getDefaultConfiguration(); + // GLContext j2dShareContext = Java2D.getShareContext(gc); + // if (impl1 != null && impl1 == j2dShareContext) { + // impl1 = null; + // } + // } + // + // synchronized (GLContextShareSet.class) { + // if (impl1 != null) { + // tracker = impl1.getObjectTracker(); + // assert (tracker != null) + // : "registerForObjectTracking was not called properly for the older context"; + // } + // if (tracker == null) { + // tracker = new GLObjectTracker(); + // } + // // Note that we don't assert that the tracker is non-null for + // // impl2 because the way we use this functionality we actually + // // overwrite the initially-set object tracker in the new context + // impl2.setObjectTracker(tracker); + // } + // } + // } + // + // /** In order to avoid glGet calls for buffer object checks related + // to glVertexPointer, etc. calls as well as glMapBuffer calls, we + // need to share the same GLBufferSizeTracker object between + // contexts sharing textures and display lists. For now we keep + // this mechanism orthogonal to the GLObjectTracker to hopefully + // keep things easier to understand. (The GLObjectTracker is + // currently only needed in a fairly esoteric case, when the + // Java2D/JOGL bridge is active, but the GLBufferSizeTracker + // mechanism is now always required.) */ + // public static void registerForBufferObjectSharing(GLContext olderContextOrNull, GLContext newContext) { + // // FIXME: downcasts to GLContextImpl undesirable + // GLContextImpl older = (GLContextImpl) olderContextOrNull; + // GLContextImpl newer = (GLContextImpl) newContext; + // GLBufferSizeTracker tracker = null; + // if (older != null) { + // tracker = older.getBufferSizeTracker(); + // assert (tracker != null) + // : "registerForBufferObjectSharing was not called properly for the older context, or has a bug in it"; + // } + // if (tracker == null) { + // tracker = new GLBufferSizeTracker(); + // } + // newer.setBufferSizeTracker(tracker); + // } //---------------------------------------------------------------------- // Internals only below this point @@ -279,12 +282,13 @@ public class GLContextShareSet { } } - private static boolean isObjectTrackingEnabled() { - return ((Java2D.isOGLPipelineActive() && Java2D.isFBOEnabled()) || - isObjectTrackingDebuggingEnabled()); - } - - private static boolean isObjectTrackingDebuggingEnabled() { - return forceTracking; - } + // FIXME: refactor Java SE dependencies + // private static boolean isObjectTrackingEnabled() { + // return ((Java2D.isOGLPipelineActive() && Java2D.isFBOEnabled()) || + // isObjectTrackingDebuggingEnabled()); + // } + // + // private static boolean isObjectTrackingDebuggingEnabled() { + // return forceTracking; + // } } diff --git a/src/classes/com/sun/opengl/impl/GLDrawableFactoryImpl.java b/src/classes/com/sun/opengl/impl/GLDrawableFactoryImpl.java index d5b14c099..7f0718c44 100644 --- a/src/classes/com/sun/opengl/impl/GLDrawableFactoryImpl.java +++ b/src/classes/com/sun/opengl/impl/GLDrawableFactoryImpl.java @@ -39,10 +39,6 @@ package com.sun.opengl.impl; -import java.awt.Component; -import java.awt.Graphics; -import java.awt.GraphicsConfiguration; -import java.awt.GraphicsDevice; import java.nio.*; import javax.media.opengl.*; import com.sun.gluegen.runtime.*; @@ -87,10 +83,12 @@ public abstract class GLDrawableFactoryImpl extends GLDrawableFactory implements // implement this functionality on all other platforms // + /* FIXME: refactor dependencies on Java SE public abstract boolean canCreateContextOnJava2DSurface(); public abstract GLContext createContextOnJava2DSurface(Graphics g, GLContext shareWith) throws GLException; + */ //---------------------------------------------------------------------- // Gamma adjustment support diff --git a/src/classes/com/sun/opengl/impl/NativeLibLoader.java b/src/classes/com/sun/opengl/impl/NativeLibLoader.java index 522b81a03..ffe8df3e2 100644 --- a/src/classes/com/sun/opengl/impl/NativeLibLoader.java +++ b/src/classes/com/sun/opengl/impl/NativeLibLoader.java @@ -39,7 +39,8 @@ package com.sun.opengl.impl; -import java.awt.Toolkit; +// FIXME: refactor Java SE dependencies +//import java.awt.Toolkit; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.security.AccessController; @@ -114,6 +115,7 @@ public class NativeLibLoader { }); } + /* FIXME: refactor Java SE dependencies public static void loadAWTImpl() { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { @@ -134,6 +136,7 @@ public class NativeLibLoader { } }); } + */ public static void loadCgImpl() { AccessController.doPrivileged(new PrivilegedAction() { @@ -186,6 +189,8 @@ public class NativeLibLoader { throw (UnsatisfiedLinkError) new UnsatisfiedLinkError().initCause(e); } } else { + // FIXME: remove + // System.out.println("sun.boot.library.path=" + System.getProperty("sun.boot.library.path")); System.loadLibrary(libraryName); } } diff --git a/src/classes/com/sun/opengl/impl/ProjectES1.java b/src/classes/com/sun/opengl/impl/ProjectES1.java new file mode 100755 index 000000000..68b478641 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/ProjectES1.java @@ -0,0 +1,1033 @@ +/* +** License Applicability. Except to the extent portions of this file are +** made subject to an alternative license as permitted in the SGI Free +** Software License B, Version 1.1 (the "License"), the contents of this +** file are subject only to the provisions of the License. You may not use +** this file except in compliance with the License. You may obtain a copy +** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600 +** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at: +** +** http://oss.sgi.com/projects/FreeB +** +** Note that, as provided in the License, the Software is distributed on an +** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS +** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND +** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A +** PARTICULAR PURPOSE, AND NON-INFRINGEMENT. +** +** NOTE: The Original Code (as defined below) has been licensed to Sun +** Microsystems, Inc. ("Sun") under the SGI Free Software License B +** (Version 1.1), shown above ("SGI License"). Pursuant to Section +** 3.2(3) of the SGI License, Sun is distributing the Covered Code to +** you under an alternative license ("Alternative License"). This +** Alternative License includes all of the provisions of the SGI License +** except that Section 2.2 and 11 are omitted. Any differences between +** the Alternative License and the SGI License are offered solely by Sun +** and not by SGI. +** +** Original Code. The Original Code is: OpenGL Sample Implementation, +** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics, +** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc. +** Copyright in any portions created by third parties is as indicated +** elsewhere herein. All Rights Reserved. +** +** Additional Notice Provisions: The application programming interfaces +** established by SGI in conjunction with the Original Code are The +** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released +** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version +** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X +** Window System(R) (Version 1.3), released October 19, 1998. This software +** was created using the OpenGL(R) version 1.2.1 Sample Implementation +** published by SGI, but has not been independently verified as being +** compliant with the OpenGL(R) version 1.2.1 Specification. +** +** $Date$ $Revision$ +** $Header$ +*/ + +/* + * Copyright (c) 2002-2004 LWJGL Project + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * * Neither the name of 'LWJGL' nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Copyright (c) 2003 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * You acknowledge that this software is not designed or intended for use + * in the design, construction, operation or maintenance of any nuclear + * facility. + */ +package com.sun.opengl.impl; + +import java.nio.*; + +import javax.media.opengl.*; +import com.sun.opengl.util.*; + +/** + * ProjectES1.java + * <p/> + * <p/> + * Created 11-jan-2004 + * + * @author Erik Duijs + * @author Kenneth Russell + */ +public class ProjectES1 { + private static final float[] IDENTITY_MATRIX = + new float[] { + 1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f }; + + // Note that we have cloned parts of the implementation in order to + // support incoming Buffers. The reason for this is to avoid loading + // non-direct buffer subclasses unnecessarily, because doing so can + // cause performance decreases on direct buffer operations, at least + // on the current HotSpot JVM. It would be nicer (and make the code + // simpler) to simply have the array-based entry points delegate to + // the versions taking Buffers by wrapping the arrays. + + // Array-based implementation + private final float[] matrix = new float[16]; + + private final float[][] tempMatrix = new float[4][4]; + private final float[] in = new float[4]; + private final float[] out = new float[4]; + + private final float[] forward = new float[3]; + private final float[] side = new float[3]; + private final float[] up = new float[3]; + + // Buffer-based implementation + private final FloatBuffer matrixBuf; + + private final FloatBuffer tempMatrixBuf; + private final FloatBuffer inBuf; + private final FloatBuffer outBuf; + + private final FloatBuffer forwardBuf; + private final FloatBuffer sideBuf; + private final FloatBuffer upBuf; + + public ProjectES1() { + // Use direct buffers to avoid loading indirect buffer + // implementations for applications trying to avoid doing so. + // Slice up one big buffer because some NIO implementations + // allocate a huge amount of memory to back even the smallest of + // buffers. + FloatBuffer buf = BufferUtil.newFloatBuffer(128); + int pos = 0; + int sz = 16; + matrixBuf = slice(buf, pos, sz); + pos += sz; + tempMatrixBuf = slice(buf, pos, sz); + pos += sz; + sz = 4; + inBuf = slice(buf, pos, sz); + pos += sz; + outBuf = slice(buf, pos, sz); + pos += sz; + sz = 3; + forwardBuf = slice(buf, pos, sz); + pos += sz; + sideBuf = slice(buf, pos, sz); + pos += sz; + upBuf = slice(buf, pos, sz); + } + + private static FloatBuffer slice(FloatBuffer buf, int pos, int len) { + buf.position(pos); + buf.limit(pos + len); + return buf.slice(); + } + + /** + * Make matrix an identity matrix + */ + private void __gluMakeIdentityf(FloatBuffer m) { + int oldPos = m.position(); + m.put(IDENTITY_MATRIX); + m.position(oldPos); + } + + /** + * Make matrix an identity matrix + */ + private void __gluMakeIdentityf(float[] m) { + for (int i = 0; i < 16; i++) { + m[i] = IDENTITY_MATRIX[i]; + } + } + + /** + * Method __gluMultMatrixVecf + * + * @param matrix + * @param in + * @param out + */ + private void __gluMultMatrixVecf(float[] matrix, int matrix_offset, float[] in, float[] out) { + for (int i = 0; i < 4; i++) { + out[i] = + in[0] * matrix[0*4+i+matrix_offset] + + in[1] * matrix[1*4+i+matrix_offset] + + in[2] * matrix[2*4+i+matrix_offset] + + in[3] * matrix[3*4+i+matrix_offset]; + } + } + + /** + * Method __gluMultMatrixVecf + * + * @param matrix + * @param in + * @param out + */ + private void __gluMultMatrixVecf(FloatBuffer matrix, FloatBuffer in, FloatBuffer out) { + int inPos = in.position(); + int outPos = out.position(); + int matrixPos = matrix.position(); + for (int i = 0; i < 4; i++) { + out.put(i + outPos, + in.get(0+inPos) * matrix.get(0*4+i+matrixPos) + + in.get(1+inPos) * matrix.get(1*4+i+matrixPos) + + in.get(2+inPos) * matrix.get(2*4+i+matrixPos) + + in.get(3+inPos) * matrix.get(3*4+i+matrixPos)); + } + } + + /** + * @param src + * @param inverse + * + * @return + */ + private boolean __gluInvertMatrixf(float[] src, float[] inverse) { + int i, j, k, swap; + float t; + float[][] temp = tempMatrix; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + temp[i][j] = src[i*4+j]; + } + } + __gluMakeIdentityf(inverse); + + for (i = 0; i < 4; i++) { + // + // Look for largest element in column + // + swap = i; + for (j = i + 1; j < 4; j++) { + if (Math.abs(temp[j][i]) > Math.abs(temp[i][i])) { + swap = j; + } + } + + if (swap != i) { + // + // Swap rows. + // + for (k = 0; k < 4; k++) { + t = temp[i][k]; + temp[i][k] = temp[swap][k]; + temp[swap][k] = t; + + t = inverse[i*4+k]; + inverse[i*4+k] = inverse[swap*4+k]; + inverse[swap*4+k] = t; + } + } + + if (temp[i][i] == 0) { + // + // No non-zero pivot. The matrix is singular, which shouldn't + // happen. This means the user gave us a bad matrix. + // + return false; + } + + t = temp[i][i]; + for (k = 0; k < 4; k++) { + temp[i][k] /= t; + inverse[i*4+k] /= t; + } + for (j = 0; j < 4; j++) { + if (j != i) { + t = temp[j][i]; + for (k = 0; k < 4; k++) { + temp[j][k] -= temp[i][k] * t; + inverse[j*4+k] -= inverse[i*4+k]*t; + } + } + } + } + return true; + } + + /** + * @param src + * @param inverse + * + * @return + */ + private boolean __gluInvertMatrixf(FloatBuffer src, FloatBuffer inverse) { + int i, j, k, swap; + float t; + + int srcPos = src.position(); + int invPos = inverse.position(); + + FloatBuffer temp = tempMatrixBuf; + + for (i = 0; i < 4; i++) { + for (j = 0; j < 4; j++) { + temp.put(i*4+j, src.get(i*4+j + srcPos)); + } + } + __gluMakeIdentityf(inverse); + + for (i = 0; i < 4; i++) { + // + // Look for largest element in column + // + swap = i; + for (j = i + 1; j < 4; j++) { + if (Math.abs(temp.get(j*4+i)) > Math.abs(temp.get(i*4+i))) { + swap = j; + } + } + + if (swap != i) { + // + // Swap rows. + // + for (k = 0; k < 4; k++) { + t = temp.get(i*4+k); + temp.put(i*4+k, temp.get(swap*4+k)); + temp.put(swap*4+k, t); + + t = inverse.get(i*4+k + invPos); + inverse.put(i*4+k + invPos, inverse.get(swap*4+k + invPos)); + inverse.put(swap*4+k + invPos, t); + } + } + + if (temp.get(i*4+i) == 0) { + // + // No non-zero pivot. The matrix is singular, which shouldn't + // happen. This means the user gave us a bad matrix. + // + return false; + } + + t = temp.get(i*4+i); + for (k = 0; k < 4; k++) { + temp.put(i*4+k, temp.get(i*4+k) / t); + inverse.put(i*4+k + invPos, inverse.get(i*4+k + invPos) / t); + } + for (j = 0; j < 4; j++) { + if (j != i) { + t = temp.get(j*4+i); + for (k = 0; k < 4; k++) { + temp.put(j*4+k, temp.get(j*4+k) - temp.get(i*4+k) * t); + inverse.put(j*4+k + invPos, inverse.get(j*4+k + invPos) - inverse.get(i*4+k + invPos) * t); + } + } + } + } + return true; + } + + + /** + * @param a + * @param b + * @param r + */ + private void __gluMultMatricesf(float[] a, int a_offset, float[] b, int b_offset, float[] r) { + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + r[i*4+j] = + a[i*4+0+a_offset]*b[0*4+j+b_offset] + + a[i*4+1+a_offset]*b[1*4+j+b_offset] + + a[i*4+2+a_offset]*b[2*4+j+b_offset] + + a[i*4+3+a_offset]*b[3*4+j+b_offset]; + } + } + } + + + /** + * @param a + * @param b + * @param r + */ + private void __gluMultMatricesf(FloatBuffer a, FloatBuffer b, FloatBuffer r) { + int aPos = a.position(); + int bPos = b.position(); + int rPos = r.position(); + + for (int i = 0; i < 4; i++) { + for (int j = 0; j < 4; j++) { + r.put(i*4+j + rPos, + a.get(i*4+0+aPos)*b.get(0*4+j+bPos) + + a.get(i*4+1+aPos)*b.get(1*4+j+bPos) + + a.get(i*4+2+aPos)*b.get(2*4+j+bPos) + + a.get(i*4+3+aPos)*b.get(3*4+j+bPos)); + } + } + } + + /** + * Normalize vector + * + * @param v + */ + private static void normalize(float[] v) { + float r; + + r = (float) Math.sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); + if ( r == 0.0 ) + return; + + r = 1.0f / r; + + v[0] *= r; + v[1] *= r; + v[2] *= r; + + return; + } + + /** + * Normalize vector + * + * @param v + */ + private static void normalize(FloatBuffer v) { + float r; + + int vPos = v.position(); + + r = (float) Math.sqrt(v.get(0+vPos) * v.get(0+vPos) + + v.get(1+vPos) * v.get(1+vPos) + + v.get(2+vPos) * v.get(2+vPos)); + if ( r == 0.0 ) + return; + + r = 1.0f / r; + + v.put(0+vPos, v.get(0+vPos) * r); + v.put(1+vPos, v.get(1+vPos) * r); + v.put(2+vPos, v.get(2+vPos) * r); + + return; + } + + + /** + * Calculate cross-product + * + * @param v1 + * @param v2 + * @param result + */ + private static void cross(float[] v1, float[] v2, float[] result) { + result[0] = v1[1] * v2[2] - v1[2] * v2[1]; + result[1] = v1[2] * v2[0] - v1[0] * v2[2]; + result[2] = v1[0] * v2[1] - v1[1] * v2[0]; + } + + /** + * Calculate cross-product + * + * @param v1 + * @param v2 + * @param result + */ + private static void cross(FloatBuffer v1, FloatBuffer v2, FloatBuffer result) { + int v1Pos = v1.position(); + int v2Pos = v2.position(); + int rPos = result.position(); + + result.put(0+rPos, v1.get(1+v1Pos) * v2.get(2+v2Pos) - v1.get(2+v1Pos) * v2.get(1+v2Pos)); + result.put(1+rPos, v1.get(2+v1Pos) * v2.get(0+v2Pos) - v1.get(0+v1Pos) * v2.get(2+v2Pos)); + result.put(2+rPos, v1.get(0+v1Pos) * v2.get(1+v2Pos) - v1.get(1+v1Pos) * v2.get(0+v2Pos)); + } + + /** + * Method gluOrtho2D. + * + * @param left + * @param right + * @param bottom + * @param top + */ + public void gluOrtho2D(GL gl, float left, float right, float bottom, float top) { + gl.glOrthof(left, right, bottom, top, -1, 1); + } + + /** + * Method gluPerspective. + * + * @param fovy + * @param aspect + * @param zNear + * @param zFar + */ + public void gluPerspective(GL gl, float fovy, float aspect, float zNear, float zFar) { + float sine, cotangent, deltaZ; + float radians = fovy / 2 * (float) Math.PI / 180; + + deltaZ = zFar - zNear; + sine = (float) Math.sin(radians); + + if ((deltaZ == 0) || (sine == 0) || (aspect == 0)) { + return; + } + + cotangent = (float) Math.cos(radians) / sine; + + __gluMakeIdentityf(matrixBuf); + + matrixBuf.put(0 * 4 + 0, cotangent / aspect); + matrixBuf.put(1 * 4 + 1, cotangent); + matrixBuf.put(2 * 4 + 2, - (zFar + zNear) / deltaZ); + matrixBuf.put(2 * 4 + 3, -1); + matrixBuf.put(3 * 4 + 2, -2 * zNear * zFar / deltaZ); + matrixBuf.put(3 * 4 + 3, 0); + + gl.glMultMatrixf(matrixBuf); + } + + /** + * Method gluLookAt + * + * @param eyex + * @param eyey + * @param eyez + * @param centerx + * @param centery + * @param centerz + * @param upx + * @param upy + * @param upz + */ + public void gluLookAt(GL gl, + float eyex, + float eyey, + float eyez, + float centerx, + float centery, + float centerz, + float upx, + float upy, + float upz) { + FloatBuffer forward = this.forwardBuf; + FloatBuffer side = this.sideBuf; + FloatBuffer up = this.upBuf; + + forward.put(0, centerx - eyex); + forward.put(1, centery - eyey); + forward.put(2, centerz - eyez); + + up.put(0, upx); + up.put(1, upy); + up.put(2, upz); + + normalize(forward); + + /* Side = forward x up */ + cross(forward, up, side); + normalize(side); + + /* Recompute up as: up = side x forward */ + cross(side, forward, up); + + __gluMakeIdentityf(matrixBuf); + matrixBuf.put(0 * 4 + 0, side.get(0)); + matrixBuf.put(1 * 4 + 0, side.get(1)); + matrixBuf.put(2 * 4 + 0, side.get(2)); + + matrixBuf.put(0 * 4 + 1, up.get(0)); + matrixBuf.put(1 * 4 + 1, up.get(1)); + matrixBuf.put(2 * 4 + 1, up.get(2)); + + matrixBuf.put(0 * 4 + 2, -forward.get(0)); + matrixBuf.put(1 * 4 + 2, -forward.get(1)); + matrixBuf.put(2 * 4 + 2, -forward.get(2)); + + gl.glMultMatrixf(matrixBuf); + gl.glTranslatef(-eyex, -eyey, -eyez); + } + + /** + * Method gluProject + * + * @param objx + * @param objy + * @param objz + * @param modelMatrix + * @param projMatrix + * @param viewport + * @param win_pos + * + * @return + */ + public boolean gluProject(float objx, + float objy, + float objz, + float[] modelMatrix, + int modelMatrix_offset, + float[] projMatrix, + int projMatrix_offset, + int[] viewport, + int viewport_offset, + float[] win_pos, + int win_pos_offset ) { + + float[] in = this.in; + float[] out = this.out; + + in[0] = objx; + in[1] = objy; + in[2] = objz; + in[3] = 1.0f; + + __gluMultMatrixVecf(modelMatrix, modelMatrix_offset, in, out); + __gluMultMatrixVecf(projMatrix, projMatrix_offset, out, in); + + if (in[3] == 0.0f) + return false; + + in[3] = (1.0f / in[3]) * 0.5f; + + // Map x, y and z to range 0-1 + in[0] = in[0] * in[3] + 0.5f; + in[1] = in[1] * in[3] + 0.5f; + in[2] = in[2] * in[3] + 0.5f; + + // Map x,y to viewport + win_pos[0+win_pos_offset] = in[0] * viewport[2+viewport_offset] + viewport[0+viewport_offset]; + win_pos[1+win_pos_offset] = in[1] * viewport[3+viewport_offset] + viewport[1+viewport_offset]; + win_pos[2+win_pos_offset] = in[2]; + + return true; + } + + /** + * Method gluProject + * + * @param objx + * @param objy + * @param objz + * @param modelMatrix + * @param projMatrix + * @param viewport + * @param win_pos + * + * @return + */ + public boolean gluProject(float objx, + float objy, + float objz, + FloatBuffer modelMatrix, + FloatBuffer projMatrix, + IntBuffer viewport, + FloatBuffer win_pos) { + + FloatBuffer in = this.inBuf; + FloatBuffer out = this.outBuf; + + in.put(0, objx); + in.put(1, objy); + in.put(2, objz); + in.put(3, 1.0f); + + __gluMultMatrixVecf(modelMatrix, in, out); + __gluMultMatrixVecf(projMatrix, out, in); + + if (in.get(3) == 0.0f) + return false; + + in.put(3, (1.0f / in.get(3)) * 0.5f); + + // Map x, y and z to range 0-1 + in.put(0, in.get(0) * in.get(3) + 0.5f); + in.put(1, in.get(1) * in.get(3) + 0.5f); + in.put(2, in.get(2) * in.get(3) + 0.5f); + + // Map x,y to viewport + int vPos = viewport.position(); + int wPos = win_pos.position(); + win_pos.put(0+wPos, in.get(0) * viewport.get(2+vPos) + viewport.get(0+vPos)); + win_pos.put(1+wPos, in.get(1) * viewport.get(3+vPos) + viewport.get(1+vPos)); + win_pos.put(2+wPos, in.get(2)); + + return true; + } + + + /** + * Method gluUnproject + * + * @param winx + * @param winy + * @param winz + * @param modelMatrix + * @param projMatrix + * @param viewport + * @param obj_pos + * + * @return + */ + public boolean gluUnProject(float winx, + float winy, + float winz, + float[] modelMatrix, + int modelMatrix_offset, + float[] projMatrix, + int projMatrix_offset, + int[] viewport, + int viewport_offset, + float[] obj_pos, + int obj_pos_offset) { + float[] in = this.in; + float[] out = this.out; + + __gluMultMatricesf(modelMatrix, modelMatrix_offset, projMatrix, projMatrix_offset, matrix); + + if (!__gluInvertMatrixf(matrix, matrix)) + return false; + + in[0] = winx; + in[1] = winy; + in[2] = winz; + in[3] = 1.0f; + + // Map x and y from window coordinates + in[0] = (in[0] - viewport[0+viewport_offset]) / viewport[2+viewport_offset]; + in[1] = (in[1] - viewport[1+viewport_offset]) / viewport[3+viewport_offset]; + + // Map to range -1 to 1 + in[0] = in[0] * 2 - 1; + in[1] = in[1] * 2 - 1; + in[2] = in[2] * 2 - 1; + + __gluMultMatrixVecf(matrix, 0, in, out); + + if (out[3] == 0.0) + return false; + + out[3] = 1.0f / out[3]; + + obj_pos[0+obj_pos_offset] = out[0] * out[3]; + obj_pos[1+obj_pos_offset] = out[1] * out[3]; + obj_pos[2+obj_pos_offset] = out[2] * out[3]; + + return true; + } + + + /** + * Method gluUnproject + * + * @param winx + * @param winy + * @param winz + * @param modelMatrix + * @param projMatrix + * @param viewport + * @param obj_pos + * + * @return + */ + public boolean gluUnProject(float winx, + float winy, + float winz, + FloatBuffer modelMatrix, + FloatBuffer projMatrix, + IntBuffer viewport, + FloatBuffer obj_pos) { + FloatBuffer in = this.inBuf; + FloatBuffer out = this.outBuf; + + __gluMultMatricesf(modelMatrix, projMatrix, matrixBuf); + + if (!__gluInvertMatrixf(matrixBuf, matrixBuf)) + return false; + + in.put(0, winx); + in.put(1, winy); + in.put(2, winz); + in.put(3, 1.0f); + + // Map x and y from window coordinates + int vPos = viewport.position(); + int oPos = obj_pos.position(); + in.put(0, (in.get(0) - viewport.get(0+vPos)) / viewport.get(2+vPos)); + in.put(1, (in.get(1) - viewport.get(1+vPos)) / viewport.get(3+vPos)); + + // Map to range -1 to 1 + in.put(0, in.get(0) * 2 - 1); + in.put(1, in.get(1) * 2 - 1); + in.put(2, in.get(2) * 2 - 1); + + __gluMultMatrixVecf(matrixBuf, in, out); + + if (out.get(3) == 0.0f) + return false; + + out.put(3, 1.0f / out.get(3)); + + obj_pos.put(0+oPos, out.get(0) * out.get(3)); + obj_pos.put(1+oPos, out.get(1) * out.get(3)); + obj_pos.put(2+oPos, out.get(2) * out.get(3)); + + return true; + } + + + /** + * Method gluUnproject4 + * + * @param winx + * @param winy + * @param winz + * @param clipw + * @param modelMatrix + * @param projMatrix + * @param viewport + * @param near + * @param far + * @param obj_pos + * + * @return + */ + public boolean gluUnProject4(float winx, + float winy, + float winz, + float clipw, + float[] modelMatrix, + int modelMatrix_offset, + float[] projMatrix, + int projMatrix_offset, + int[] viewport, + int viewport_offset, + float near, + float far, + float[] obj_pos, + int obj_pos_offset ) { + float[] in = this.in; + float[] out = this.out; + + __gluMultMatricesf(modelMatrix, modelMatrix_offset, projMatrix, projMatrix_offset, matrix); + + if (!__gluInvertMatrixf(matrix, matrix)) + return false; + + in[0] = winx; + in[1] = winy; + in[2] = winz; + in[3] = clipw; + + // Map x and y from window coordinates + in[0] = (in[0] - viewport[0+viewport_offset]) / viewport[2+viewport_offset]; + in[1] = (in[1] - viewport[1+viewport_offset]) / viewport[3+viewport_offset]; + in[2] = (in[2] - near) / (far - near); + + // Map to range -1 to 1 + in[0] = in[0] * 2 - 1; + in[1] = in[1] * 2 - 1; + in[2] = in[2] * 2 - 1; + + __gluMultMatrixVecf(matrix, 0, in, out); + + if (out[3] == 0.0f) + return false; + + obj_pos[0+obj_pos_offset] = out[0]; + obj_pos[1+obj_pos_offset] = out[1]; + obj_pos[2+obj_pos_offset] = out[2]; + obj_pos[3+obj_pos_offset] = out[3]; + return true; + } + + /** + * Method gluUnproject4 + * + * @param winx + * @param winy + * @param winz + * @param clipw + * @param modelMatrix + * @param projMatrix + * @param viewport + * @param near + * @param far + * @param obj_pos + * + * @return + */ + public boolean gluUnProject4(float winx, + float winy, + float winz, + float clipw, + FloatBuffer modelMatrix, + FloatBuffer projMatrix, + IntBuffer viewport, + float near, + float far, + FloatBuffer obj_pos) { + FloatBuffer in = this.inBuf; + FloatBuffer out = this.outBuf; + + __gluMultMatricesf(modelMatrix, projMatrix, matrixBuf); + + if (!__gluInvertMatrixf(matrixBuf, matrixBuf)) + return false; + + in.put(0, winx); + in.put(1, winy); + in.put(2, winz); + in.put(3, clipw); + + // Map x and y from window coordinates + int vPos = viewport.position(); + in.put(0, (in.get(0) - viewport.get(0+vPos)) / viewport.get(2+vPos)); + in.put(1, (in.get(1) - viewport.get(1+vPos)) / viewport.get(3+vPos)); + in.put(2, (in.get(2) - near) / (far - near)); + + // Map to range -1 to 1 + in.put(0, in.get(0) * 2 - 1); + in.put(1, in.get(1) * 2 - 1); + in.put(2, in.get(2) * 2 - 1); + + __gluMultMatrixVecf(matrixBuf, in, out); + + if (out.get(3) == 0.0f) + return false; + + int oPos = obj_pos.position(); + obj_pos.put(0+oPos, out.get(0)); + obj_pos.put(1+oPos, out.get(1)); + obj_pos.put(2+oPos, out.get(2)); + obj_pos.put(3+oPos, out.get(3)); + return true; + } + + + /** + * Method gluPickMatrix + * + * @param x + * @param y + * @param deltaX + * @param deltaY + * @param viewport + */ + public void gluPickMatrix(GL gl, + float x, + float y, + float deltaX, + float deltaY, + IntBuffer viewport) { + if (deltaX <= 0 || deltaY <= 0) { + return; + } + + /* Translate and scale the picked region to the entire window */ + int vPos = viewport.position(); + gl.glTranslatef((viewport.get(2+vPos) - 2 * (x - viewport.get(0+vPos))) / deltaX, + (viewport.get(3+vPos) - 2 * (y - viewport.get(1+vPos))) / deltaY, + 0); + gl.glScalef(viewport.get(2) / deltaX, viewport.get(3) / deltaY, 1.0f); + } + + /** + * Method gluPickMatrix + * + * @param x + * @param y + * @param deltaX + * @param deltaY + * @param viewport + * @param viewport_offset + */ + public void gluPickMatrix(GL gl, + float x, + float y, + float deltaX, + float deltaY, + int[] viewport, + int viewport_offset) { + if (deltaX <= 0 || deltaY <= 0) { + return; + } + + /* Translate and scale the picked region to the entire window */ + gl.glTranslatef((viewport[2+viewport_offset] - 2 * (x - viewport[0+viewport_offset])) / deltaX, + (viewport[3+viewport_offset] - 2 * (y - viewport[1+viewport_offset])) / deltaY, + 0); + gl.glScalef(viewport[2+viewport_offset] / deltaX, viewport[3+viewport_offset] / deltaY, 1.0f); + } +} diff --git a/src/classes/com/sun/opengl/impl/egl/EGLContext.java b/src/classes/com/sun/opengl/impl/egl/EGLContext.java new file mode 100755 index 000000000..f1aa9172b --- /dev/null +++ b/src/classes/com/sun/opengl/impl/egl/EGLContext.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.sun.opengl.impl.egl; + +import javax.media.opengl.*; +import com.sun.opengl.impl.*; +import java.nio.*; + +public abstract class EGLContext extends GLContextImpl { + public EGLContext(EGLDrawable drawable, GLContext shareWith) { + super(shareWith); + } + + public Object getPlatformGLExtensions() { + return null; + } + + public GLDrawable getGLDrawable() { + return null; + } + + public void copy(GLContext source, int mask) throws GLException { + throw new GLException("Not yet implemented"); + } + + public void bindPbufferToTexture() { + throw new GLException("Should not call this"); + } + + public void releasePbufferFromTexture() { + throw new GLException("Should not call this"); + } + + public ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { + throw new GLException("Should not call this"); + } + + protected String mapToRealGLFunctionName(String glFunctionName) { + return glFunctionName; + } + + protected String mapToRealGLExtensionName(String glExtensionName) { + return glExtensionName; + } + + public String getPlatformExtensionsString() { + return ""; + } + + public boolean offscreenImageNeedsVerticalFlip() { + throw new GLException("Should not call this"); + } + + public int getOffscreenContextPixelDataType() { + throw new GLException("Should not call this"); + } +} diff --git a/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java b/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java new file mode 100755 index 000000000..2f0903a2b --- /dev/null +++ b/src/classes/com/sun/opengl/impl/egl/EGLDrawable.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.sun.opengl.impl.egl; + +public class EGLDrawable { +} diff --git a/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java b/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java new file mode 100755 index 000000000..06ba5b640 --- /dev/null +++ b/src/classes/com/sun/opengl/impl/egl/EGLDrawableFactory.java @@ -0,0 +1,259 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.sun.opengl.impl.egl; + +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public class EGLDrawableFactory extends GLDrawableFactoryImpl { + static { + NativeLibLoader.loadCore(); + } + + public AbstractGraphicsConfiguration chooseGraphicsConfiguration(GLCapabilities capabilities, + GLCapabilitiesChooser chooser, + AbstractGraphicsDevice device) { + return null; + } + + public GLDrawable getGLDrawable(Object target, + GLCapabilities capabilities, + GLCapabilitiesChooser chooser) { + throw new GLException("Not yet implemented"); + } + + public GLDrawableImpl createOffscreenDrawable(GLCapabilities capabilities, + GLCapabilitiesChooser chooser) { + throw new GLException("Not yet implemented"); + } + + public boolean canCreateGLPbuffer() { + // Not supported on OpenGL ES + return false; + } + public GLPbuffer createGLPbuffer(final GLCapabilities capabilities, + final GLCapabilitiesChooser chooser, + final int initialWidth, + final int initialHeight, + final GLContext shareWith) { + throw new GLException("Pbuffer support not available on OpenGL ES"); + } + + public GLContext createExternalGLContext() { + return new EGLExternalContext(); + } + + public boolean canCreateExternalGLDrawable() { + return false; + } + + public GLDrawable createExternalGLDrawable() { + throw new GLException("Not yet implemented"); + } + + public void loadGLULibrary() { + } + + public long dynamicLookupFunction(String glFuncName) { + return 0; + /* + long res = WGL.wglGetProcAddress(glFuncName); + if (res == 0) { + // GLU routines aren't known to the OpenGL function lookup + if (hglu32 != 0) { + res = WGL.GetProcAddress(hglu32, glFuncName); + } + } + return res; + */ + } + + public void lockAWTForJava2D() { + } + + public void unlockAWTForJava2D() { + } + + public boolean canCreateContextOnJava2DSurface() { + return false; + } + + // FIXME: this is the OpenGL ES 2 initialization order + + // Initialize everything + public void initialize() throws GLException { + System.out.println("EGLDrawableFactory.initEGL()"); + if (!initEGL()) { + throw new GLException("EGL init failed"); + } + System.out.println("EGLDrawableFactory.chooseConfig()"); + if (!chooseConfig()) { + throw new GLException("EGL choose config failed"); + } + System.out.println("EGLDrawableFactory.checkDisplay()"); + if (!checkDisplay()) { + throw new GLException("EGL check display failed"); + } + System.out.println("EGLDrawableFactory.checkConfig()"); + if (!checkConfig()) { + throw new GLException("EGL check config failed"); + } + System.out.println("EGLDrawableFactory.createWindow()"); + if (!createWindow()) { + throw new GLException("KD window init failed"); + } + System.out.println("EGLDrawableFactory.setWindowVisible()"); + setWindowVisible(); + System.out.println("EGLDrawableFactory.setWindowFullscreen()"); + setWindowFullscreen(); + System.out.println("EGLDrawableFactory.realizeWindow()"); + if (!realizeWindow()) { + throw new GLException("EGL/GLES window realize failed"); + } + System.out.println("EGLDrawableFactory.createSurface()"); + if (!createSurface()) { + throw new GLException("EGL create window surface failed"); + } + System.out.println("EGLDrawableFactory.createContext()"); + if (!createContext()) { + throw new GLException("EGL create context failed"); + } + System.out.println("EGLDrawableFactory.makeCurrent()"); + if (!makeCurrent()) { + throw new GLException("EGL make current failed"); + } + System.out.println("EGLDrawableFactory.updateWindowSize()"); + updateWindowSize(); + } + + /* + + // FIXME: this is the OpenGL ES 1 initialization order + + // Initialize everything + public void initialize() throws GLException { + System.out.println("EGLDrawableFactory.initEGL()"); + if (!initEGL()) { + throw new GLException("EGL init failed"); + } + System.out.println("EGLDrawableFactory.chooseConfig()"); + if (!chooseConfig()) { + throw new GLException("EGL choose config failed"); + } + System.out.println("EGLDrawableFactory.checkDisplay()"); + if (!checkDisplay()) { + throw new GLException("EGL check display failed"); + } + System.out.println("EGLDrawableFactory.checkConfig()"); + if (!checkConfig()) { + throw new GLException("EGL check config failed"); + } + System.out.println("EGLDrawableFactory.createContext()"); + if (!createContext()) { + throw new GLException("EGL create context failed"); + } + // + // OpenKODE Core window system initialisation. + // + System.out.println("EGLDrawableFactory.createWindow()"); + if (!createWindow()) { + throw new GLException("KD window init failed"); + } + // System.out.println("EGLDrawableFactory.setWindowVisible()"); + // setWindowVisible(); + System.out.println("EGLDrawableFactory.setWindowFullscreen()"); + setWindowFullscreen(); + System.out.println("EGLDrawableFactory.realizeWindow()"); + if (!realizeWindow()) { + throw new GLException("EGL/GLES window realize failed"); + } + System.out.println("EGLDrawableFactory.createSurface()"); + if (!createSurface()) { + throw new GLException("EGL create window surface failed"); + } + System.out.println("EGLDrawableFactory.makeCurrent()"); + if (!makeCurrent()) { + throw new GLException("EGL make current failed"); + } + System.out.println("EGLDrawableFactory.updateWindowSize()"); + updateWindowSize(); + } + + */ + + // Process incoming events -- must be called every frame + public void processEvents() { + if (shouldExit()) { + shutdown(); + } + } + + public void swapBuffers() { + swapBuffers0(); + } + + private native boolean initEGL(); + private native boolean chooseConfig(); + private native boolean checkDisplay(); + private native boolean checkConfig(); + private native boolean createWindow(); + private native void setWindowVisible(); + private native void setWindowFullscreen(); + private native boolean realizeWindow(); + private native boolean createSurface(); + private native boolean createContext(); + private native boolean makeCurrent(); + private native void updateWindowSize(); + private native void swapBuffers0(); + + // Runs the native message loop one step and checks to see if we should exit + private native boolean shouldExit(); + public native void shutdown(); + + public void testGetDirectBufferAddress() { + java.nio.FloatBuffer buf = com.sun.opengl.util.BufferUtil.newFloatBuffer(12); + int addr = getDirectBufferAddress(buf); + System.out.println("Direct FloatBuffer's address: 0x" + Integer.toHexString(addr)); + } + public native int getDirectBufferAddress(java.nio.Buffer buf); + + /* + public GLContext createContextOnJava2DSurface(Graphics g, GLContext shareWith) + throws GLException { + throw new GLException("Unimplemented on this platform"); + } + */ +} diff --git a/src/classes/com/sun/opengl/impl/egl/EGLExternalContext.java b/src/classes/com/sun/opengl/impl/egl/EGLExternalContext.java new file mode 100755 index 000000000..6466c767d --- /dev/null +++ b/src/classes/com/sun/opengl/impl/egl/EGLExternalContext.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * - Redistribution of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistribution in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * Neither the name of Sun Microsystems, Inc. or the names of + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * This software is provided "AS IS," without a warranty of any kind. ALL + * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, + * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A + * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN + * MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR + * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR + * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR + * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR + * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE + * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, + * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF + * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + * + * Sun gratefully acknowledges that this software was originally authored + * and developed by Kenneth Bradley Russell and Christopher John Kline. + */ + +package com.sun.opengl.impl.egl; + +import javax.media.opengl.*; +import com.sun.opengl.impl.*; + +public class EGLExternalContext extends EGLContext { + private boolean firstMakeCurrent = true; + private boolean created = true; + private GLContext lastContext; + + public EGLExternalContext() { + super(null, null); + GLContextShareSet.contextCreated(this); + resetGLFunctionAvailability(); + } + + public int makeCurrent() throws GLException { + // Save last context if necessary to allow external GLContexts to + // talk to other GLContexts created by this library + GLContext cur = getCurrent(); + if (cur != null && cur != this) { + lastContext = cur; + setCurrent(null); + } + return super.makeCurrent(); + } + + public void release() throws GLException { + super.release(); + setCurrent(lastContext); + lastContext = null; + } + + protected int makeCurrentImpl() throws GLException { + if (firstMakeCurrent) { + firstMakeCurrent = false; + return CONTEXT_CURRENT_NEW; + } + return CONTEXT_CURRENT; + } + + protected void releaseImpl() throws GLException { + } + + protected void destroyImpl() throws GLException { + created = false; + GLContextShareSet.contextDestroyed(this); + } + + public boolean isCreated() { + return created; + } +} diff --git a/src/classes/com/sun/opengl/impl/windows/WindowsDummyGLDrawable.java b/src/classes/com/sun/opengl/impl/windows/WindowsDummyGLDrawable.java index a307493d7..c52cf4067 100644 --- a/src/classes/com/sun/opengl/impl/windows/WindowsDummyGLDrawable.java +++ b/src/classes/com/sun/opengl/impl/windows/WindowsDummyGLDrawable.java @@ -80,7 +80,8 @@ public class WindowsDummyGLDrawable extends WindowsGLDrawable { // Construction failed return null; } - return new WindowsGLContext(this, shareWith, true); + // FIXME: figure out how to hook back in the Java 2D / JOGL bridge + return new WindowsGLContext(this, shareWith); } public void destroy() { diff --git a/src/classes/com/sun/opengl/impl/windows/WindowsExternalGLContext.java b/src/classes/com/sun/opengl/impl/windows/WindowsExternalGLContext.java index a73cc7ac4..36aba5011 100755 --- a/src/classes/com/sun/opengl/impl/windows/WindowsExternalGLContext.java +++ b/src/classes/com/sun/opengl/impl/windows/WindowsExternalGLContext.java @@ -50,7 +50,8 @@ public class WindowsExternalGLContext extends WindowsGLContext { private GLContext lastContext; public WindowsExternalGLContext() { - super(null, null, true); + // FIXME: figure out how to hook back in the Java 2D / JOGL bridge + super(null, null); hglrc = WGL.wglGetCurrentContext(); if (hglrc == 0) { throw new GLException("Error: attempted to make an external GLContext without a drawable/context current"); diff --git a/src/classes/com/sun/opengl/impl/windows/WindowsGLContext.java b/src/classes/com/sun/opengl/impl/windows/WindowsGLContext.java index 1276aea92..2681d42f4 100644 --- a/src/classes/com/sun/opengl/impl/windows/WindowsGLContext.java +++ b/src/classes/com/sun/opengl/impl/windows/WindowsGLContext.java @@ -66,18 +66,12 @@ public class WindowsGLContext extends GLContextImpl { extensionNameMap.put("GL_ARB_pixel_format", "WGL_ARB_pixel_format"); } + // FIXME: figure out how to hook back in the Java 2D / JOGL bridge public WindowsGLContext(WindowsGLDrawable drawable, GLContext shareWith) { - this(drawable, shareWith, false); + super(shareWith); } - public WindowsGLContext(WindowsGLDrawable drawable, - GLContext shareWith, - boolean dontShareWithJava2D) { - super(shareWith, dontShareWithJava2D); - this.drawable = drawable; - } - public Object getPlatformGLExtensions() { return getWGLExt(); } diff --git a/src/classes/com/sun/opengl/util/BufferUtil.java b/src/classes/com/sun/opengl/util/BufferUtil.java index e16c5685d..756f568b4 100755 --- a/src/classes/com/sun/opengl/util/BufferUtil.java +++ b/src/classes/com/sun/opengl/util/BufferUtil.java @@ -49,8 +49,9 @@ public class BufferUtil { public static final int SIZEOF_SHORT = 2; public static final int SIZEOF_INT = 4; public static final int SIZEOF_FLOAT = 4; - public static final int SIZEOF_LONG = 8; - public static final int SIZEOF_DOUBLE = 8; + // FIXME: refactor dependencies on Java SE buffer classes + // public static final int SIZEOF_LONG = 8; + // public static final int SIZEOF_DOUBLE = 8; private BufferUtil() {} @@ -58,22 +59,42 @@ public class BufferUtil { // Allocation routines // + + // FIXME: these are only for testing purposes + // public static ByteBuffer newByteBuffer(int numElements) { + // return ByteBuffer.wrap(new byte[numElements]); + // } + // + // public static FloatBuffer newFloatBuffer(int numElements) { + // return FloatBuffer.wrap(new float[numElements]); + // } + // + // public static IntBuffer newIntBuffer(int numElements) { + // return IntBuffer.wrap(new int[numElements]); + // } + // + // public static ShortBuffer newShortBuffer(int numElements) { + // return ShortBuffer.wrap(new short[numElements]); + // } + /** Allocates a new direct ByteBuffer with the specified number of elements. The returned buffer will have its byte order set to the host platform's native byte order. */ public static ByteBuffer newByteBuffer(int numElements) { ByteBuffer bb = ByteBuffer.allocateDirect(numElements); - bb.order(ByteOrder.nativeOrder()); + // FIXME: refactor dependencies on Java SE buffer classes + // bb.order(ByteOrder.nativeOrder()); return bb; } - - /** Allocates a new direct DoubleBuffer with the specified number of - elements. The returned buffer will have its byte order set to - the host platform's native byte order. */ - public static DoubleBuffer newDoubleBuffer(int numElements) { - ByteBuffer bb = newByteBuffer(numElements * SIZEOF_DOUBLE); - return bb.asDoubleBuffer(); - } + + // FIXME: refactor dependencies on Java SE buffer classes + // /** Allocates a new direct DoubleBuffer with the specified number of + // elements. The returned buffer will have its byte order set to + // the host platform's native byte order. */ + // public static DoubleBuffer newDoubleBuffer(int numElements) { + // ByteBuffer bb = newByteBuffer(numElements * SIZEOF_DOUBLE); + // return bb.asDoubleBuffer(); + // } /** Allocates a new direct FloatBuffer with the specified number of elements. The returned buffer will have its byte order set to @@ -82,7 +103,7 @@ public class BufferUtil { ByteBuffer bb = newByteBuffer(numElements * SIZEOF_FLOAT); return bb.asFloatBuffer(); } - + /** Allocates a new direct IntBuffer with the specified number of elements. The returned buffer will have its byte order set to the host platform's native byte order. */ @@ -90,14 +111,15 @@ public class BufferUtil { ByteBuffer bb = newByteBuffer(numElements * SIZEOF_INT); return bb.asIntBuffer(); } - - /** Allocates a new direct LongBuffer with the specified number of - elements. The returned buffer will have its byte order set to - the host platform's native byte order. */ - public static LongBuffer newLongBuffer(int numElements) { - ByteBuffer bb = newByteBuffer(numElements * SIZEOF_LONG); - return bb.asLongBuffer(); - } + + // FIXME: refactor dependencies on Java SE buffer classes + // /** Allocates a new direct LongBuffer with the specified number of + // elements. The returned buffer will have its byte order set to + // the host platform's native byte order. */ + // public static LongBuffer newLongBuffer(int numElements) { + // ByteBuffer bb = newByteBuffer(numElements * SIZEOF_LONG); + // return bb.asLongBuffer(); + // } /** Allocates a new direct ShortBuffer with the specified number of elements. The returned buffer will have its byte order set to @@ -107,162 +129,103 @@ public class BufferUtil { return bb.asShortBuffer(); } - //---------------------------------------------------------------------- - // Copy routines (type-to-type) + // FIXME: refactor dependencies on Java SE buffer classes + // These are only used by the GLU implementation anyway, which + // mostly disappears in the embedded OpenGL case + // //---------------------------------------------------------------------- + // // Copy routines (type-to-type) + // // // - - /** Copies the <i>remaining</i> elements (as defined by - <code>limit() - position()</code>) in the passed ByteBuffer into - a newly-allocated direct ByteBuffer. The returned buffer will - have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static ByteBuffer copyByteBuffer(ByteBuffer orig) { - ByteBuffer dest = newByteBuffer(orig.remaining()); - orig.mark(); - dest.put(orig); - orig.reset(); - dest.rewind(); - return dest; - } - - /** Copies the <i>remaining</i> elements (as defined by - <code>limit() - position()</code>) in the passed DoubleBuffer - into a newly-allocated direct DoubleBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static DoubleBuffer copyDoubleBuffer(DoubleBuffer orig) { - return copyDoubleBufferAsByteBuffer(orig).asDoubleBuffer(); - } - - /** Copies the <i>remaining</i> elements (as defined by - <code>limit() - position()</code>) in the passed FloatBuffer - into a newly-allocated direct FloatBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static FloatBuffer copyFloatBuffer(FloatBuffer orig) { - return copyFloatBufferAsByteBuffer(orig).asFloatBuffer(); - } - - /** Copies the <i>remaining</i> elements (as defined by - <code>limit() - position()</code>) in the passed IntBuffer - into a newly-allocated direct IntBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static IntBuffer copyIntBuffer(IntBuffer orig) { - return copyIntBufferAsByteBuffer(orig).asIntBuffer(); - } - - /** Copies the <i>remaining</i> elements (as defined by - <code>limit() - position()</code>) in the passed LongBuffer - into a newly-allocated direct LongBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static LongBuffer copyLongBuffer(LongBuffer orig) { - return copyLongBufferAsByteBuffer(orig).asLongBuffer(); - } - - /** Copies the <i>remaining</i> elements (as defined by - <code>limit() - position()</code>) in the passed ShortBuffer - into a newly-allocated direct ShortBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static ShortBuffer copyShortBuffer(ShortBuffer orig) { - return copyShortBufferAsByteBuffer(orig).asShortBuffer(); - } - - //---------------------------------------------------------------------- - // Copy routines (type-to-ByteBuffer) + // /** Copies the <i>remaining</i> elements (as defined by + // <code>limit() - position()</code>) in the passed ByteBuffer into + // a newly-allocated direct ByteBuffer. The returned buffer will + // have its byte order set to the host platform's native byte + // order. The position of the newly-allocated buffer will be zero, + // and the position of the passed buffer is unchanged (though its + // mark is changed). */ + // public static ByteBuffer copyByteBuffer(ByteBuffer orig) { + // ByteBuffer dest = newByteBuffer(orig.remaining()); + // dest.put(orig); + // dest.rewind(); + // return dest; + // } // - - /** Copies the <i>remaining</i> elements (as defined by - <code>limit() - position()</code>) in the passed DoubleBuffer - into a newly-allocated direct ByteBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static ByteBuffer copyDoubleBufferAsByteBuffer(DoubleBuffer orig) { - ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_DOUBLE); - orig.mark(); - dest.asDoubleBuffer().put(orig); - orig.reset(); - dest.rewind(); - return dest; - } - - /** Copies the <i>remaining</i> elements (as defined by - <code>limit() - position()</code>) in the passed FloatBuffer - into a newly-allocated direct ByteBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static ByteBuffer copyFloatBufferAsByteBuffer(FloatBuffer orig) { - ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_FLOAT); - orig.mark(); - dest.asFloatBuffer().put(orig); - orig.reset(); - dest.rewind(); - return dest; - } - - /** Copies the <i>remaining</i> elements (as defined by - <code>limit() - position()</code>) in the passed IntBuffer into - a newly-allocated direct ByteBuffer. The returned buffer will - have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static ByteBuffer copyIntBufferAsByteBuffer(IntBuffer orig) { - ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_INT); - orig.mark(); - dest.asIntBuffer().put(orig); - orig.reset(); - dest.rewind(); - return dest; - } - - /** Copies the <i>remaining</i> elements (as defined by - <code>limit() - position()</code>) in the passed LongBuffer into - a newly-allocated direct ByteBuffer. The returned buffer will - have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static ByteBuffer copyLongBufferAsByteBuffer(LongBuffer orig) { - ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_LONG); - orig.mark(); - dest.asLongBuffer().put(orig); - orig.reset(); - dest.rewind(); - return dest; - } - - /** Copies the <i>remaining</i> elements (as defined by - <code>limit() - position()</code>) in the passed ShortBuffer - into a newly-allocated direct ByteBuffer. The returned buffer - will have its byte order set to the host platform's native byte - order. The position of the newly-allocated buffer will be zero, - and the position of the passed buffer is unchanged (though its - mark is changed). */ - public static ByteBuffer copyShortBufferAsByteBuffer(ShortBuffer orig) { - ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_SHORT); - orig.mark(); - dest.asShortBuffer().put(orig); - orig.reset(); - dest.rewind(); - return dest; - } + // /** Copies the <i>remaining</i> elements (as defined by + // <code>limit() - position()</code>) in the passed FloatBuffer + // into a newly-allocated direct FloatBuffer. The returned buffer + // will have its byte order set to the host platform's native byte + // order. The position of the newly-allocated buffer will be zero, + // and the position of the passed buffer is unchanged (though its + // mark is changed). */ + // public static FloatBuffer copyFloatBuffer(FloatBuffer orig) { + // return copyFloatBufferAsByteBuffer(orig).asFloatBuffer(); + // } + // + // /** Copies the <i>remaining</i> elements (as defined by + // <code>limit() - position()</code>) in the passed IntBuffer + // into a newly-allocated direct IntBuffer. The returned buffer + // will have its byte order set to the host platform's native byte + // order. The position of the newly-allocated buffer will be zero, + // and the position of the passed buffer is unchanged (though its + // mark is changed). */ + // public static IntBuffer copyIntBuffer(IntBuffer orig) { + // return copyIntBufferAsByteBuffer(orig).asIntBuffer(); + // } + // + // /** Copies the <i>remaining</i> elements (as defined by + // <code>limit() - position()</code>) in the passed ShortBuffer + // into a newly-allocated direct ShortBuffer. The returned buffer + // will have its byte order set to the host platform's native byte + // order. The position of the newly-allocated buffer will be zero, + // and the position of the passed buffer is unchanged (though its + // mark is changed). */ + // public static ShortBuffer copyShortBuffer(ShortBuffer orig) { + // return copyShortBufferAsByteBuffer(orig).asShortBuffer(); + // } + // + // //---------------------------------------------------------------------- + // // Copy routines (type-to-ByteBuffer) + // // + // + // /** Copies the <i>remaining</i> elements (as defined by + // <code>limit() - position()</code>) in the passed FloatBuffer + // into a newly-allocated direct ByteBuffer. The returned buffer + // will have its byte order set to the host platform's native byte + // order. The position of the newly-allocated buffer will be zero, + // and the position of the passed buffer is unchanged (though its + // mark is changed). */ + // public static ByteBuffer copyFloatBufferAsByteBuffer(FloatBuffer orig) { + // ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_FLOAT); + // dest.asFloatBuffer().put(orig); + // dest.rewind(); + // return dest; + // } + // + // /** Copies the <i>remaining</i> elements (as defined by + // <code>limit() - position()</code>) in the passed IntBuffer into + // a newly-allocated direct ByteBuffer. The returned buffer will + // have its byte order set to the host platform's native byte + // order. The position of the newly-allocated buffer will be zero, + // and the position of the passed buffer is unchanged (though its + // mark is changed). */ + // public static ByteBuffer copyIntBufferAsByteBuffer(IntBuffer orig) { + // ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_INT); + // dest.asIntBuffer().put(orig); + // dest.rewind(); + // return dest; + // } + // + // /** Copies the <i>remaining</i> elements (as defined by + // <code>limit() - position()</code>) in the passed ShortBuffer + // into a newly-allocated direct ByteBuffer. The returned buffer + // will have its byte order set to the host platform's native byte + // order. The position of the newly-allocated buffer will be zero, + // and the position of the passed buffer is unchanged (though its + // mark is changed). */ + // public static ByteBuffer copyShortBufferAsByteBuffer(ShortBuffer orig) { + // ByteBuffer dest = newByteBuffer(orig.remaining() * SIZEOF_SHORT); + // dest.asShortBuffer().put(orig); + // dest.rewind(); + // return dest; + // } } diff --git a/src/classes/javax/media/opengl/GLAutoDrawable.java b/src/classes/javax/media/opengl/GLAutoDrawable.java index 5f3115da8..40e2603c6 100644 --- a/src/classes/javax/media/opengl/GLAutoDrawable.java +++ b/src/classes/javax/media/opengl/GLAutoDrawable.java @@ -52,7 +52,7 @@ import javax.media.opengl.glu.*; GLContext for the GLAutoDrawable to be used both by the event based rendering mechanism as well by end users directly. */ -public interface GLAutoDrawable extends GLDrawable, ComponentEvents { +public interface GLAutoDrawable extends GLDrawable /*, FIXME: ComponentEvents */ { /** * Returns the context associated with this drawable. The returned * context will be synchronized. diff --git a/src/classes/javax/media/opengl/GLDrawableFactory.java b/src/classes/javax/media/opengl/GLDrawableFactory.java index fd934195c..3945f42fc 100644 --- a/src/classes/javax/media/opengl/GLDrawableFactory.java +++ b/src/classes/javax/media/opengl/GLDrawableFactory.java @@ -83,6 +83,12 @@ public abstract class GLDrawableFactory { /** Returns the sole GLDrawableFactory instance. */ public static GLDrawableFactory getFactory() { if (factory == null) { + + // FIXME: hook this in to the normal reflective mechanism + factory = new com.sun.opengl.impl.egl.EGLDrawableFactory(); + + /* + try { String factoryClassName = (String) AccessController.doPrivileged(new PrivilegedAction() { @@ -119,6 +125,8 @@ public abstract class GLDrawableFactory { } catch (Exception e) { throw new GLException(e); } + + */ } return factory; diff --git a/src/classes/javax/media/opengl/Threading.java b/src/classes/javax/media/opengl/Threading.java index d3712c4c5..f14912a3c 100755 --- a/src/classes/javax/media/opengl/Threading.java +++ b/src/classes/javax/media/opengl/Threading.java @@ -39,7 +39,8 @@ package javax.media.opengl; -import java.awt.EventQueue; +// FIXME: refactor Java SE dependencies +//import java.awt.EventQueue; import java.lang.reflect.InvocationTargetException; import java.security.AccessController; import java.security.PrivilegedAction; @@ -125,14 +126,17 @@ public class Threading { private static final int AWT = 1; private static final int WORKER = 2; private static int mode; + /* FIXME: refactor Java SE dependencies // We need to know whether we're running on X11 platforms to change // our behavior when the Java2D/JOGL bridge is active private static boolean isX11; + */ static { AccessController.doPrivileged(new PrivilegedAction() { public Object run() { String workaround = System.getProperty("opengl.1thread"); + /* FIXME: refactor Java SE dependencies // Default to using the AWT thread on all platforms except // Windows. On OS X there is instability apparently due to // using the JAWT on non-AWT threads. On X11 platforms there @@ -144,6 +148,7 @@ public class Threading { String osName = System.getProperty("os.name"); boolean isWindows = osName.startsWith("Windows"); isX11 = !(isWindows || osName.startsWith("Mac OS")); + */ // int defaultMode = (isWindows ? WORKER : AWT); int defaultMode = AWT; mode = defaultMode; @@ -208,6 +213,7 @@ public class Threading { switch (mode) { case AWT: + /* FIXME: refactor Java SE dependencies if (Java2D.isOGLPipelineActive()) { // FIXME: ideally only the QFT would be considered to be the // "OpenGL thread", but we can not currently run all of @@ -218,7 +224,10 @@ public class Threading { } else { return EventQueue.isDispatchThread(); } + */ + return true; case WORKER: + /* FIXME: refactor Java SE dependencies if (Java2D.isOGLPipelineActive()) { // FIXME: ideally only the QFT would be considered to be the // "OpenGL thread", but we can not currently run all of @@ -229,6 +238,8 @@ public class Threading { } else { return GLWorkerThread.isWorkerThread(); } + */ + return GLWorkerThread.isWorkerThread(); default: throw new InternalError("Illegal single-threading mode " + mode); } @@ -254,6 +265,7 @@ public class Threading { switch (mode) { case AWT: + /* FIXME: refactor Java SE dependencies // FIXME: ideally should run all OpenGL work on the Java2D QFT // thread when it's enabled, but unfortunately there are // deadlock issues on X11 platforms when making our @@ -272,7 +284,9 @@ public class Threading { } catch (InterruptedException e) { throw new GLException(e); } - } + } + */ + r.run(); break; case WORKER: |