FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

trying to get smooth change to work · pjryan93/processing@9de843c · GitHub

Repository navigation

Commit 9de843c

Browse files
committed
trying to get smooth change to work
1 parent 6c3c4bf commit 9de843c

3 files changed

Lines changed: 133 additions & 38 deletions

File tree

‎core/src/processing/opengl/PGL.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ public abstract class PGL {
6666
// Parameters
6767

6868
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;
7272

7373
/** Switches between the use of regular and direct buffers. */
7474
protected static boolean USE_DIRECT_BUFFERS = true;
@@ -139,7 +139,7 @@ public abstract class PGL {
139139
protected boolean fboLayerCreated = false;
140140
protected boolean fboLayerInUse = false;
141141
protected boolean firstFrame = true;
142-
protected int reqNumSamples;
142+
public int reqNumSamples;
143143
protected int numSamples;
144144
protected IntBuffer glColorFbo;
145145
protected IntBuffer glMultiFbo;

‎core/src/processing/opengl/PGraphicsOpenGL.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6521,7 +6521,8 @@ protected void setDrawDefaults() {
65216521
pgl.getIntegerv(PGL.SAMPLES, intBuffer);
65226522
int temp = intBuffer.get(0);
65236523
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;
65256526
}
65266527
}
65276528
if (quality < 2) {

‎java/libraries/lwjgl/src/processing/lwjgl/PSurfaceLWJGL.java‎

Lines changed: 127 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.lwjgl.input.Mouse;
2020
import org.lwjgl.opengl.Display;
2121
import org.lwjgl.opengl.DisplayMode;
22+
import org.lwjgl.opengl.PixelFormat;
2223

2324
import processing.core.PApplet;
2425
import processing.core.PConstants;
@@ -28,6 +29,7 @@
2829
import processing.event.Event;
2930
import processing.event.KeyEvent;
3031
import processing.event.MouseEvent;
32+
import processing.opengl.PGL;
3133
import processing.opengl.PGraphicsOpenGL;
3234

3335
public class PSurfaceLWJGL implements PSurface {
@@ -61,6 +63,8 @@ public class PSurfaceLWJGL implements PSurface {
6163
protected static KeyPoller keyPoller;
6264
protected static MousePoller mousePoller;
6365

66+
protected static DisplayResarter restarter;
67+
6468
Thread thread;
6569
boolean paused;
6670
Object pauseObject = new Object();
@@ -173,6 +177,31 @@ public Frame initFrame(PApplet sketch, Color backgroundColor,
173177
// pgl.pixel_scale = 2;
174178
}
175179

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+
176205
// sketchWidth = sketch.width = sketch.sketchWidth();
177206
// sketchHeight = sketch.height = sketch.sketchHeight();
178207

@@ -323,10 +352,12 @@ public void setSize(int width, int height) {
323352
}
324353

325354

326-
@Override
355+
boolean forceExit = false;
356+
@Override
327357
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;
330361
}
331362

332363

@@ -353,7 +384,7 @@ public void requestFocus() {
353384

354385
@Override
355386
public void blit() {
356-
Display.update(); // maybe this ??
387+
// Nothing to do here
357388
}
358389

359390
@Override
@@ -421,27 +452,23 @@ public void run() { // not good to make this synchronized, locks things up
421452
// DisplayMode[] modes = Display.getAvailableDisplayModes();
422453
// for (DisplayMode mode: modes) {
423454
// 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+
// }
434456
// Display.setDisplayMode(Display.getDesktopDisplayMode());
435457
//
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);
440465
} catch (LWJGLException e) {
441466
e.printStackTrace();
442467
System.exit(0);
443468
}
444469

470+
boolean deinit = true;
471+
445472
keyPoller = new KeyPoller(sketch);
446473
keyPoller.start();
447474

@@ -537,22 +564,31 @@ public void run() { // not good to make this synchronized, locks things up
537564
y0 = y;
538565

539566
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+
}
544572
}
545573

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+
}
555589
}
590+
591+
556592
}
557593
}
558594

@@ -669,7 +705,10 @@ public void run() {
669705
try {
670706
Thread.sleep(10);
671707
} 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;
673712
}
674713
}
675714
}
@@ -679,6 +718,59 @@ public void requestStop() {
679718
}
680719
}
681720

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+
682774

683775
protected class MousePoller extends Thread {
684776
protected PApplet parent;
@@ -791,7 +883,9 @@ public void run() {
791883
try {
792884
Thread.sleep(10);
793885
} catch (InterruptedException e) {
794-
e.printStackTrace();
886+
// e.printStackTrace();
887+
Thread.currentThread().interrupt(); // restore interrupted status
888+
break;
795889
}
796890
}
797891
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL