| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6c3c4bf commit 9de843c
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -66,9 +66,9 @@ public abstract class PGL { | |||
| 66 | 66 | // Parameters | |
| 67 | 67 | ||
| 68 | 68 | protected static boolean USE_FBOLAYER_BY_DEFAULT = false; | |
| 69 | - protected static int REQUESTED_DEPTH_BITS = 24; | ||
| 70 | - protected static int REQUESTED_STENCIL_BITS = 8; | ||
| 71 | - protected static int REQUESTED_ALPHA_BITS = 8; | ||
| 69 | + public static int REQUESTED_DEPTH_BITS = 24; | ||
| 70 | + public static int REQUESTED_STENCIL_BITS = 8; | ||
| 71 | + public static int REQUESTED_ALPHA_BITS = 8; | ||
| 72 | 72 | ||
| 73 | 73 | /** Switches between the use of regular and direct buffers. */ | |
| 74 | 74 | protected static boolean USE_DIRECT_BUFFERS = true; | |
@@ -139,7 +139,7 @@ public abstract class PGL { | |||
| 139 | 139 | protected boolean fboLayerCreated = false; | |
| 140 | 140 | protected boolean fboLayerInUse = false; | |
| 141 | 141 | protected boolean firstFrame = true; | |
| 142 | - protected int reqNumSamples; | ||
| 142 | + public int reqNumSamples; | ||
| 143 | 143 | protected int numSamples; | |
| 144 | 144 | protected IntBuffer glColorFbo; | |
| 145 | 145 | protected IntBuffer glMultiFbo; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6521,7 +6521,8 @@ protected void setDrawDefaults() { | |||
| 6521 | 6521 | pgl.getIntegerv(PGL.SAMPLES, intBuffer); | |
| 6522 | 6522 | int temp = intBuffer.get(0); | |
| 6523 | 6523 | if (quality != temp && 1 < temp && 1 < quality) { | |
| 6524 | - quality = temp; | ||
| 6524 | + // TODO check why the samples is higher that initialized smooth level. | ||
| 6525 | + // quality = temp; | ||
| 6525 | 6526 | } | |
| 6526 | 6527 | } | |
| 6527 | 6528 | if (quality < 2) { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,6 +19,7 @@ | |||
| 19 | 19 | import org.lwjgl.input.Mouse; | |
| 20 | 20 | import org.lwjgl.opengl.Display; | |
| 21 | 21 | import org.lwjgl.opengl.DisplayMode; | |
| 22 | + import org.lwjgl.opengl.PixelFormat; | ||
| 22 | 23 | ||
| 23 | 24 | import processing.core.PApplet; | |
| 24 | 25 | import processing.core.PConstants; | |
@@ -28,6 +29,7 @@ | |||
| 28 | 29 | import processing.event.Event; | |
| 29 | 30 | import processing.event.KeyEvent; | |
| 30 | 31 | import processing.event.MouseEvent; | |
| 32 | + import processing.opengl.PGL; | ||
| 31 | 33 | import processing.opengl.PGraphicsOpenGL; | |
| 32 | 34 | ||
| 33 | 35 | public class PSurfaceLWJGL implements PSurface { | |
@@ -61,6 +63,8 @@ public class PSurfaceLWJGL implements PSurface { | |||
| 61 | 63 | protected static KeyPoller keyPoller; | |
| 62 | 64 | protected static MousePoller mousePoller; | |
| 63 | 65 | ||
| 66 | + protected static DisplayResarter restarter; | ||
| 67 | + | ||
| 64 | 68 | Thread thread; | |
| 65 | 69 | boolean paused; | |
| 66 | 70 | Object pauseObject = new Object(); | |
@@ -173,6 +177,31 @@ public Frame initFrame(PApplet sketch, Color backgroundColor, | |||
| 173 | 177 | // pgl.pixel_scale = 2; | |
| 174 | 178 | } | |
| 175 | 179 | ||
| 180 | + pgl.reqNumSamples = graphics.quality; | ||
| 181 | + | ||
| 182 | + System.err.println("DISPLAY PARENT: " + Display.getParent()); | ||
| 183 | + System.err.println("DISPLAY SMOOTH: " + pgl.reqNumSamples); | ||
| 184 | + | ||
| 185 | + try { | ||
| 186 | + int argb = graphics.backgroundColor; | ||
| 187 | + float r = ((argb >> 16) & 0xff) / 255.0f; | ||
| 188 | + float g = ((argb >> 8) & 0xff) / 255.0f; | ||
| 189 | + float b = ((argb) & 0xff) / 255.0f; | ||
| 190 | + Display.setInitialBackground(r, g, b); | ||
| 191 | + Display.setDisplayMode(new DisplayMode(sketchWidth, sketchHeight)); | ||
| 192 | + System.err.println(sketchWidth + " " + sketchHeight); | ||
| 193 | + if (fullScreenRequested) { | ||
| 194 | + Display.setFullscreen(true); | ||
| 195 | + } | ||
| 196 | + } catch (LWJGLException e) { | ||
| 197 | + // TODO Auto-generated catch block | ||
| 198 | + e.printStackTrace(); | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + restarter = new DisplayResarter(); | ||
| 202 | + restarter.start(); | ||
| 203 | + | ||
| 204 | + | ||
| 176 | 205 | // sketchWidth = sketch.width = sketch.sketchWidth(); | |
| 177 | 206 | // sketchHeight = sketch.height = sketch.sketchHeight(); | |
| 178 | 207 | ||
@@ -323,10 +352,12 @@ public void setSize(int width, int height) { | |||
| 323 | 352 | } | |
| 324 | 353 | ||
| 325 | 354 | ||
| 326 | - @Override | ||
| 355 | + boolean forceExit = false; | ||
| 356 | + @Override | ||
| 327 | 357 | public void setSmooth(int level) { | |
| 328 | - // TODO Auto-generated method stub | ||
| 329 | - | ||
| 358 | + System.err.println("set smooth " + level); | ||
| 359 | + pgl.reqNumSamples = level; | ||
| 360 | + restarter.changeRequested = true; | ||
| 330 | 361 | } | |
| 331 | 362 | ||
| 332 | 363 | ||
@@ -353,7 +384,7 @@ public void requestFocus() { | |||
| 353 | 384 | ||
| 354 | 385 | @Override | |
| 355 | 386 | public void blit() { | |
| 356 | - Display.update(); // maybe this ?? | ||
| 387 | + // Nothing to do here | ||
| 357 | 388 | } | |
| 358 | 389 | ||
| 359 | 390 | @Override | |
@@ -421,27 +452,23 @@ public void run() { // not good to make this synchronized, locks things up | |||
| 421 | 452 | // DisplayMode[] modes = Display.getAvailableDisplayModes(); | |
| 422 | 453 | // for (DisplayMode mode: modes) { | |
| 423 | 454 | // System.err.println(mode.toString()); | |
| 424 | - // } | ||
| 425 | - | ||
| 426 | - System.err.println("DISPLAY PARENT: " + Display.getParent()); | ||
| 427 | - | ||
| 428 | - Display.setDisplayMode(new DisplayMode(sketchWidth, sketchHeight)); | ||
| 429 | - System.err.println(sketchWidth + " " + sketchHeight); | ||
| 430 | - if (fullScreenRequested) { | ||
| 431 | - Display.setFullscreen(true); | ||
| 432 | - } | ||
| 433 | - | ||
| 455 | + // } | ||
| 434 | 456 | // Display.setDisplayMode(Display.getDesktopDisplayMode()); | |
| 435 | 457 | // | |
| 436 | - // Display.create(); | ||
| 437 | - | ||
| 438 | - | ||
| 439 | - Display.create(); | ||
| 458 | + // Display.create(); | ||
| 459 | + // Display.destroy(); | ||
| 460 | + System.err.println("CREATE THE DISPLAY"); | ||
| 461 | + PixelFormat format = new PixelFormat(PGL.REQUESTED_ALPHA_BITS, | ||
| 462 | + PGL.REQUESTED_DEPTH_BITS, | ||
| 463 | + PGL.REQUESTED_STENCIL_BITS, pgl.reqNumSamples); | ||
| 464 | + Display.create(format); | ||
| 440 | 465 | } catch (LWJGLException e) { | |
| 441 | 466 | e.printStackTrace(); | |
| 442 | 467 | System.exit(0); | |
| 443 | 468 | } | |
| 444 | 469 | ||
| 470 | + boolean deinit = true; | ||
| 471 | + | ||
| 445 | 472 | keyPoller = new KeyPoller(sketch); | |
| 446 | 473 | keyPoller.start(); | |
| 447 | 474 | ||
@@ -537,22 +564,31 @@ public void run() { // not good to make this synchronized, locks things up | |||
| 537 | 564 | y0 = y; | |
| 538 | 565 | ||
| 539 | 566 | if (Display.isCloseRequested()) break; | |
| 540 | - } | ||
| 541 | - | ||
| 542 | - if (externalMessages) { | ||
| 543 | - sketch.exit(); // don't quit, need to just shut everything down (0133) | ||
| 567 | + if (forceExit) { | ||
| 568 | + System.err.println("QUIT"); | ||
| 569 | + deinit = false; | ||
| 570 | + break; | ||
| 571 | + } | ||
| 544 | 572 | } | |
| 545 | 573 | ||
| 546 | - keyPoller.requestStop(); | ||
| 547 | - mousePoller.requestStop(); | ||
| 548 | - sketch.dispose(); // call to shutdown libs? | ||
| 549 | - Display.destroy(); | ||
| 550 | - | ||
| 551 | - // If the user called the exit() function, the window should close, | ||
| 552 | - // rather than the sketch just halting. | ||
| 553 | - if (sketch.exitCalled()) { | ||
| 554 | - sketch.exitActual(); | ||
| 574 | + if (deinit) { | ||
| 575 | + if (externalMessages) { | ||
| 576 | + sketch.exit(); // don't quit, need to just shut everything down (0133) | ||
| 577 | + } | ||
| 578 | + | ||
| 579 | + keyPoller.requestStop(); | ||
| 580 | + mousePoller.requestStop(); | ||
| 581 | + sketch.dispose(); // call to shutdown libs? | ||
| 582 | + Display.destroy(); | ||
| 583 | + | ||
| 584 | + // If the user called the exit() function, the window should close, | ||
| 585 | + // rather than the sketch just halting. | ||
| 586 | + if (sketch.exitCalled()) { | ||
| 587 | + sketch.exitActual(); | ||
| 588 | + } | ||
| 555 | 589 | } | |
| 590 | + | ||
| 591 | + | ||
| 556 | 592 | } | |
| 557 | 593 | } | |
| 558 | 594 | ||
@@ -669,7 +705,10 @@ public void run() { | |||
| 669 | 705 | try { | |
| 670 | 706 | Thread.sleep(10); | |
| 671 | 707 | } catch (InterruptedException e) { | |
| 672 | - e.printStackTrace(); | ||
| 708 | + // http://stackoverflow.com/questions/1024651/do-i-have-to-worry-about-interruptedexceptions-if-i-dont-interrupt-anything-mys/1024719#1024719 | ||
| 709 | + // e.printStackTrace(); | ||
| 710 | + Thread.currentThread().interrupt(); // restore interrupted status | ||
| 711 | + break; | ||
| 673 | 712 | } | |
| 674 | 713 | } | |
| 675 | 714 | } | |
@@ -679,6 +718,59 @@ public void requestStop() { | |||
| 679 | 718 | } | |
| 680 | 719 | } | |
| 681 | 720 | ||
| 721 | + protected class DisplayResarter extends Thread { | ||
| 722 | + boolean changeRequested = false; | ||
| 723 | + | ||
| 724 | + @Override | ||
| 725 | + public void run() { | ||
| 726 | + while (true) { | ||
| 727 | + if (changeRequested) { | ||
| 728 | + forceExit = true; | ||
| 729 | + thread.interrupt(); | ||
| 730 | + while (thread.isAlive()) { | ||
| 731 | + // System.err.println("alive"); | ||
| 732 | + Thread.yield(); | ||
| 733 | + } | ||
| 734 | + thread = null; | ||
| 735 | + | ||
| 736 | + keyPoller.requestStop(); | ||
| 737 | + keyPoller.interrupt(); | ||
| 738 | + while (keyPoller.isAlive()) { | ||
| 739 | + Thread.yield(); | ||
| 740 | + } | ||
| 741 | + mousePoller.requestStop(); | ||
| 742 | + mousePoller.interrupt(); | ||
| 743 | + while (mousePoller.isAlive()) { | ||
| 744 | + Thread.yield(); | ||
| 745 | + } | ||
| 746 | + | ||
| 747 | + /* | ||
| 748 | + System.err.println("will destroy surface"); | ||
| 749 | + Display.destroy(); | ||
| 750 | + try { | ||
| 751 | + Display.setDisplayMode(new DisplayMode(sketchWidth, sketchHeight)); | ||
| 752 | + } catch (LWJGLException e) { | ||
| 753 | + // TODO Auto-generated catch block | ||
| 754 | + e.printStackTrace(); | ||
| 755 | + } | ||
| 756 | + */ | ||
| 757 | + startThread(); | ||
| 758 | + | ||
| 759 | + | ||
| 760 | + | ||
| 761 | + changeRequested = false; | ||
| 762 | + } | ||
| 763 | + try { | ||
| 764 | + Thread.sleep(10); | ||
| 765 | + } catch (InterruptedException e) { | ||
| 766 | + // e.printStackTrace(); | ||
| 767 | + Thread.currentThread().interrupt(); // restore interrupted status | ||
| 768 | + break; | ||
| 769 | + } | ||
| 770 | + } | ||
| 771 | + } | ||
| 772 | + } | ||
| 773 | + | ||
| 682 | 774 | ||
| 683 | 775 | protected class MousePoller extends Thread { | |
| 684 | 776 | protected PApplet parent; | |
@@ -791,7 +883,9 @@ public void run() { | |||
| 791 | 883 | try { | |
| 792 | 884 | Thread.sleep(10); | |
| 793 | 885 | } catch (InterruptedException e) { | |
| 794 | - e.printStackTrace(); | ||
| 886 | + // e.printStackTrace(); | ||
| 887 | + Thread.currentThread().interrupt(); // restore interrupted status | ||
| 888 | + break; | ||
| 795 | 889 | } | |
| 796 | 890 | } | |
| 797 | 891 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments