got opengl working again using alternate threading/component model

This commit is contained in:
benfry
2004-12-19 22:39:29 +00:00
parent 63f5b04286
commit 4581df6ef6
7 changed files with 160 additions and 76 deletions
+33 -33
View File
@@ -17,8 +17,8 @@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
@@ -39,11 +39,11 @@ import com.apple.mrj.*;
/**
* Primary role of this class is for platform identification and
* general interaction with the system (launching URLs, loading
* general interaction with the system (launching URLs, loading
* files and images, etc) that comes from that.
*/
public class PdeBase {
static final String VERSION = "0072 Alpha";
static final String VERSION = "0075 Alpha";
PdeEditor editor;
@@ -104,7 +104,7 @@ public class PdeBase {
} else {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
} catch (Exception e) {
} catch (Exception e) {
e.printStackTrace();
}
@@ -159,13 +159,13 @@ public class PdeBase {
/**
* Given the reference filename from the keywords list,
* Given the reference filename from the keywords list,
* builds a URL and passes it to openURL.
*/
static public void showReference(String referenceFile) {
String currentDir = System.getProperty("user.dir");
openURL(currentDir + File.separator +
"reference" + File.separator +
openURL(currentDir + File.separator +
"reference" + File.separator +
referenceFile + ".html");
}
@@ -173,24 +173,24 @@ public class PdeBase {
/**
* Implements the cross-platform headache of opening URLs
*/
static public void openURL(String url) {
static public void openURL(String url) {
//System.out.println("opening url " + url);
try {
if (platform == WINDOWS) {
// this is not guaranteed to work, because who knows if the
// this is not guaranteed to work, because who knows if the
// path will always be c:\progra~1 et al. also if the user has
// a different browser set as their default (which would
// a different browser set as their default (which would
// include me) it'd be annoying to be dropped into ie.
//Runtime.getRuntime().exec("c:\\progra~1\\intern~1\\iexplore "
// + currentDir
//Runtime.getRuntime().exec("c:\\progra~1\\intern~1\\iexplore "
// + currentDir
// the following uses a shell execute to launch the .html file
// the following uses a shell execute to launch the .html file
// note that under cygwin, the .html files have to be chmodded +x
// after they're unpacked from the zip file. i don't know why,
// and don't understand what this does in terms of windows
// permissions. without the chmod, the command prompt says
// and don't understand what this does in terms of windows
// permissions. without the chmod, the command prompt says
// "Access is denied" in both cygwin and the "dos" prompt.
//Runtime.getRuntime().exec("cmd /c " + currentDir + "\\reference\\" +
//Runtime.getRuntime().exec("cmd /c " + currentDir + "\\reference\\" +
// referenceFile + ".html");
if (url.startsWith("http://")) {
// open dos prompt, give it 'start' command, which will
@@ -248,13 +248,13 @@ public class PdeBase {
} catch (IOException e) {
PdeBase.showWarning("Could not open URL",
"An error occurred while trying to open\n" + url, e);
//e.printStackTrace();
}
}
/**
/**
* Implements the other cross-platform headache of opening
* a folder in the machine's native file browser.
*/
@@ -296,7 +296,7 @@ public class PdeBase {
/**
* Non-fatal error message with optional stack trace side dish.
*/
static public void showWarning(String title, String message,
static public void showWarning(String title, String message,
Exception e) {
if (title == null) title = "Warning";
JOptionPane.showMessageDialog(new Frame(), message, title,
@@ -312,7 +312,7 @@ public class PdeBase {
* This is an error that can't be recovered. Use showWarning()
* for errors that allow P5 to continue running.
*/
static public void showError(String title, String message,
static public void showError(String title, String message,
Exception e) {
if (title == null) title = "Error";
JOptionPane.showMessageDialog(new Frame(), message, title,
@@ -346,21 +346,21 @@ public class PdeBase {
tracker.addImage(image, 0);
try {
tracker.waitForAll();
} catch (InterruptedException e) { }
} catch (InterruptedException e) { }
return image;
}
static public InputStream getStream(String filename)
static public InputStream getStream(String filename)
throws IOException {
if ((PdeBase.platform == PdeBase.MACOSX) ||
if ((PdeBase.platform == PdeBase.MACOSX) ||
(PdeBase.platform == PdeBase.MACOS9)) {
// macos doesn't seem to think that files in the lib folder
// are part of the resources, unlike windows or linux.
// actually, this is only the case when running as a .app,
// actually, this is only the case when running as a .app,
// since it works fine from run.sh, but not Processing.app
return new FileInputStream("lib/" + filename);
}
}
// all other, more reasonable operating systems
//return cls.getResource(filename).openStream();
@@ -411,7 +411,7 @@ public class PdeBase {
/**
* Grab the contents of a file as a string.
*/
static public String loadFile(File file) throws IOException {
static public String loadFile(File file) throws IOException {
// empty code file.. no worries, might be getting filled up later
if (file.length() == 0) return "";
@@ -432,7 +432,7 @@ public class PdeBase {
/**
* Spew the contents of a String object out to a file.
*/
static public void saveFile(String str,
static public void saveFile(String str,
File file) throws IOException {
ByteArrayInputStream bis = new ByteArrayInputStream(str.getBytes());
@@ -451,7 +451,7 @@ public class PdeBase {
}
static public void copyDir(File sourceDir,
static public void copyDir(File sourceDir,
File targetDir) throws IOException {
targetDir.mkdirs();
String files[] = sourceDir.list();
@@ -482,9 +482,9 @@ public class PdeBase {
/**
* Recursively remove all files within a directory,
* Recursively remove all files within a directory,
* used with removeDir(), or when the contents of a dir
* should be removed, but not the directory itself.
* should be removed, but not the directory itself.
* (i.e. when cleaning temp files from lib/build)
*/
static public void removeDescendants(File dir) {
@@ -510,8 +510,8 @@ public class PdeBase {
/**
* Calculate the size of the contents of a folder.
* Used to determine whether sketches are empty or not.
* Calculate the size of the contents of a folder.
* Used to determine whether sketches are empty or not.
* Note that the function calls itself recursively.
*/
static public int calcFolderSize(File folder) {
+5 -4
View File
@@ -333,18 +333,18 @@ public class PdeRuntime implements PdeMessageConsumer {
//System.out.println("killing external process");
try {
System.out.println("writing to stop process");
//System.out.println("writing to stop process");
processOutput.write('s');
System.out.println("written");
//System.out.println("written");
processOutput.flush();
System.out.println("flushing");
//System.out.println("flushing");
} catch (IOException e) {
//System.err.println("error stopping external applet");
//e.printStackTrace();
close();
}
System.out.println("out");
//System.out.println("out");
}
}
@@ -411,6 +411,7 @@ public class PdeRuntime implements PdeMessageConsumer {
// always shove out the mesage, since it might not fall under
// the same setup as we're expecting
System.err.print(s);
System.err.flush();
// if s.length <=2, ignore it because that probably means
// that it's just the platform line-terminators.
+11
View File
@@ -167,5 +167,16 @@ mkdir -p ../../build/macosx/work/libraries/particles/library/
cp library/particles.jar ../../build/macosx/work/libraries/particles/library/
# OPENGL LIBRARY
echo Building OpenGL library...
cd ../../lib/opengl
../../build/macosx/work/jikes -target 1.1 +D -classpath "library/jogl.jar:$CLASSPATH" -d . *.java
rm -f library/opengl.jar
zip -r0q library/opengl.jar processing
rm -rf processing
mkdir -p ../../build/macosx/work/libraries/opengl/library/
cp library/opengl.jar ../../build/macosx/work/libraries/opengl/library/
echo
echo Done.
@@ -137,18 +137,19 @@ WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
//"\"" // begin quote
//"'"
"%s"
"%s"
//"%s"
"%s" // local jre or blank
"%s" // qtjava path
//"%s\\lib\\comm.jar;"
"%s\\lib;"
"%s\\lib\\build;"
"%s\\lib\\pde.jar;"
"%s\\lib\\core.jar;"
"%s\\lib\\mrj.jar;"
"%s\\lib\\oro.jar;"
"%s\\lib\\antlr.jar;",
"%s\\lib\\antlr.jar;"
"%s", // original CLASSPATH
//"C:\\WINNT\\system32\\QTJava.zip;" // worthless
//"C:\\WINDOWS\\system32\\QTJava.zip;"
@@ -161,11 +162,9 @@ WinMain (HINSTANCE hInst, HINSTANCE hPrev, LPSTR lpCmd, int nShow)
//local_jre_installed ? "java\\lib\\rt.jar;java\\lib\\jaws.jar;" : "",
local_jre_installed ? "java\\lib\\rt.jar;" : "",
qtjava_path,
//env_classpath,
// the next several %s args
loaddir, loaddir, loaddir, loaddir,
loaddir, loaddir, loaddir);
loaddir, loaddir, loaddir,
env_classpath);
//MessageBox(NULL, cp,
// "it's twoo! it's twoo!", MB_OK);
Binary file not shown.
+95 -30
View File
@@ -49,6 +49,7 @@ public class PApplet extends Applet
//toFloat(System.getProperty("java.version").substring(0,3));
public PGraphics g;
public Frame frame;
/** Command line options passed in from main() */
public String args[];
@@ -226,6 +227,7 @@ public class PApplet extends Applet
libraries = new PLibrary[10];
libraryCalls = new boolean[10][PLibrary.CALL_COUNT];
/*
// call the applet's setup method
setup();
@@ -233,6 +235,7 @@ public class PApplet extends Applet
this.pixels = g.pixels;
this.width = g.width;
this.height = g.height;
*/
try {
getAppletContext();
@@ -240,14 +243,14 @@ public class PApplet extends Applet
} catch (NullPointerException e) {
online = false;
}
start();
}
// override for subclasses (i.e. opengl)
// so that init() doesn't have to be replicated
public void initGraphics() {
g = new PGraphics(DEFAULT_WIDTH, DEFAULT_HEIGHT);
// 0073: moved here so that can be overridden for PAppletGL
addMouseListener(this);
addMouseMotionListener(this);
@@ -256,7 +259,19 @@ public class PApplet extends Applet
}
public void createGraphics() {
g = new PGraphics(DEFAULT_WIDTH, DEFAULT_HEIGHT);
}
/**
* Called via the first call to PApplet.paint(),
* because PAppletGL needs to have a usable screen
* before getting things rolling.
*/
public void start() {
if (thread != null) return;
thread = new Thread(this);
thread.start();
}
@@ -407,9 +422,7 @@ public class PApplet extends Applet
public void size(int iwidth, int iheight) {
//width = iwidth;
//height = iheight;
//if (g != null) return; // would this ever happen? is this a good idea?
if (g == null) return;
g.resize(iwidth, iheight);
this.pixels = g.pixels;
@@ -422,6 +435,23 @@ public class PApplet extends Applet
}
}
if (frame != null) {
Insets insets = frame.getInsets();
// msft windows has a limited minimum size for frames
int minW = 120;
int minH = 120;
int winW = Math.max(width, minW) + insets.left + insets.right;
int winH = Math.max(height, minH) + insets.top + insets.bottom;
frame.setSize(winW, winH);
setBounds((winW - width)/2,
insets.top + ((winH - insets.top - insets.bottom) - height)/2,
winW, winH);
} else {
setBounds(0, 0, width, height);
}
// set this here, and if not inside browser, getDocumentBase()
// will fail with a NullPointerException, and cause applet to
// be set to null. might be a better way to deal with that, but..
@@ -444,6 +474,7 @@ public class PApplet extends Applet
*/
public void update(Graphics screen) {
//System.out.println("PApplet.update()");
if (THREAD_DEBUG) println(Thread.currentThread().getName() +
" 4 update() external");
paint(screen);
@@ -451,13 +482,24 @@ public class PApplet extends Applet
//synchronized public void paint(Graphics screen) {
public void paint(Graphics screen) {
//System.out.println("PApplet.paint()");
if (THREAD_DEBUG) println(Thread.currentThread().getName() +
" 5a enter paint");
// ignore the very first call to paint, since it's coming
// from the o.s., and the applet will soon update itself anyway.
//if (firstFrame) return;
if (frameCount == 0) return;
if (frameCount == 0) {
// paint() may be called more than once before things
// are finally painted to the screen and the thread gets going
/*
if (thread == null) {
initGraphics();
start();
}
*/
return;
}
// without ignoring the first call, the first several frames
// are confused because paint() gets called in the midst of
@@ -498,6 +540,16 @@ public class PApplet extends Applet
public void run() {
try {
/*
// first time around, call the applet's setup method
setup();
// these are the same things as get run inside a call to size()
this.pixels = g.pixels;
this.width = g.width;
this.height = g.height;
*/
while ((Thread.currentThread() == thread) && !finished) {
//while (!finished) {
//updated = false;
@@ -508,6 +560,10 @@ public class PApplet extends Applet
if (looping || redraw) {
if (fpsTarget != 0) framerate_delay();
if (frameCount == 0) { // needed here for the sync
createGraphics();
}
synchronized (g) {
if (THREAD_DEBUG) println(Thread.currentThread().getName() +
" 1a beginFrame");
@@ -515,23 +571,33 @@ public class PApplet extends Applet
if (THREAD_DEBUG) println(Thread.currentThread().getName() +
" 1b draw");
for (int i = 0; i < libraryCount; i++) {
if (libraryCalls[i][PLibrary.PRE]) libraries[i].pre();
}
if (frameCount == 0) {
//initGraphics();
//createGraphics();
setup();
draw();
this.pixels = g.pixels;
this.width = g.width;
this.height = g.height;
// these are called *after* loop so that valid
// drawing commands can be run inside them. it can't
// be before, since a call to background() would wipe
// out anything that had been drawn so far.
dequeueMouseEvents();
dequeueKeyEvents();
if (THREAD_DEBUG) println(Thread.currentThread().getName() +
" 2b endFrame");
} else {
for (int i = 0; i < libraryCount; i++) {
if (libraryCalls[i][PLibrary.PRE]) libraries[i].pre();
}
draw();
for (int i = 0; i < libraryCount; i++) {
if (libraryCalls[i][PLibrary.DRAW]) libraries[i].draw();
// these are called *after* loop so that valid
// drawing commands can be run inside them. it can't
// be before, since a call to background() would wipe
// out anything that had been drawn so far.
dequeueMouseEvents();
dequeueKeyEvents();
if (THREAD_DEBUG) println(Thread.currentThread().getName() +
" 2b endFrame");
for (int i = 0; i < libraryCount; i++) {
if (libraryCalls[i][PLibrary.DRAW]) libraries[i].draw();
}
}
g.endFrame();
@@ -3938,6 +4004,7 @@ public class PApplet extends Applet
Thread ethread = new Thread() { //new Runnable() {
public void run() {
// this fixes the "code folder hanging bug" (mostly)
setPriority(Thread.MIN_PRIORITY);
while ((Thread.currentThread() == this) && !finished) {
@@ -4034,9 +4101,10 @@ public class PApplet extends Applet
Frame frame = new Frame();
frame.setResizable(false); // remove the grow box
frame.pack(); // get insets. get more.
//frame.show(); // gl hack
frame.show(); // gl hack
Class c = Class.forName(name);
PApplet applet = (PApplet) c.newInstance();
applet.frame = frame;
// these are needed before init/start
applet.folder = folder;
@@ -4044,16 +4112,14 @@ public class PApplet extends Applet
applet.args = new String[argc];
System.arraycopy(args, argc, applet.args, 0, argc);
System.out.println("calling applet.init");
applet.init();
applet.start();
System.out.println("applet inited, started");
//applet.start();
System.out.println("done calling applet.init");
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
if (external) {
System.out.println("applet is external");
Insets insets = frame.getInsets(); // does pack() first above
//System.out.println(insets);
@@ -4125,13 +4191,12 @@ public class PApplet extends Applet
}
});
}
System.out.println("showing frame");
//System.out.println("showing frame");
frame.show();
System.out.println("applet requesting focus");
//System.out.println("applet requesting focus");
applet.requestFocus(); // ask for keydowns
System.out.println("exiting main()");
//System.out.println("exiting main()");
} catch (Exception e) {
e.printStackTrace();
+8
View File
@@ -924,6 +924,14 @@ public class PGraphics extends PImage implements PMethods, PConstants {
vertex_end = vertex_count;
// don't try to draw if there are no vertices
// (fixes a bug in LINE_LOOP that re-adds a nonexistent vertex)
if (vertex_count == 0) {
shape = 0;
return;
}
// ------------------------------------------------------------------
// CREATE LINES