Smooth being disabled, any way to force smooth()

TSHTSH
edited January 2015 in Questions about Code

Hi guys I'm running a sketch with masks and I keep getting this error

"The smooth/noSmooth functions are being called too often. This results in screen flickering, so they will be disabled for the rest of the sketch's execution."

Anybody else faced this issue? Any way to avoid this or to force smooth() to stay enable?

Also any other way to have any kind of anti-aliasing beside smooth()?

Thanks, did some research first but can't find an answer

PS No GPU, doesn't seem to be an issue when running on a GPU system

Answers

  • Call smooth() only once, in setup().

  • Hi PhiLho smooth is only being called once in the setup. Also it seems I'm guetting the same error even when I use smooth(0)

    Not sure what's going on here. Are PGraphics, masks using smooth by default and overwriting the smooth setting in setup?

    Thanks!

  • Function noSmooth() is a more compatible alternative for smooth(0);:
    http://processing.org/reference/noSmooth_.html

  • A simple sketch reproducing your problem would be interesting to see. I don't understand why you get a warning about using smooth() too often if you call it only once.

  • TSHTSH
    edited June 2014

    Here are the errors I'm currently getting:

    com.jogamp.common.util.awt.AWTEDTExecutor.invoke(AWTEDTExecutor.java:58)
    jogamp.opengl.ThreadingImpl.invokeOnOpenGLThread(ThreadingImpl.java:206)
    javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:172)
    javax.media.opengl.Threading.invoke(Threading.java:191)
    javax.media.opengl.awt.GLCanvas.display(GLCanvas.java:541)
    processing.opengl.PJOGL.requestDraw(PJOGL.java:688)
    processing.opengl.PGraphicsOpenGL.requestDraw(PGraphicsOpenGL.java:1623)
    processing.core.PApplet.run(PApplet.java:2177)
    java.lang.Thread.run(Thread.java:724)
    Smooth level 2 is not available. Using 1 instead
    Smooth level 8 is not available. Using 1 instead
    ambiguous Java methods found, using background(int)
    OpenGL error 1281 at bot beginDraw(): invalid value
    ambiguous Java methods found, using fill(int)
    OpenGL error 1286 at top endDraw(): invalid framebuffer operation
    OpenGL error 1286 at bot endDraw(): invalid framebuffer operation
    

    A question, I can't seem to find an answer for: Can smooth run without a GPU? On a CPU only system?

    Thanks guys!

  • I see this error as well. For me, the inability to override automatic disabling of smooth() is a serious problem.

    My use case: I have a simulation of polymer chains (kind of like a bowl of spaghetti noodles floating around, only the noodles are single molecules) where the chains are made of complicated objects. I allow the user to select a renderer on the fly to view an ongoing simulation. The user is free to flick back and forth between simple/low-res/high-frame-rate renderers and detailed/high-res/low-frame-rate renderers as they like, kind of like switching between normal and x-ray vision. There are at present three renderers.

    Each renderer has its own smooth() setting. This is desired. Problem is, Processing decides that smooth() is being called too often if the user switches renderers too often for its taste, and disables the smooth function. This destroys control and information. My user should be able to switch as often as they like -- if they want to hold down the "Renderer switch" key because it looks cool, they should be able to do that.

    The present justification for disabling smooth() is to prevent flickering. Flickering is a problem if your renderer is constant, but it's a feature if you're jumping between views.

    The smooth() function should have an override to prevent the present intrusion on valuable and intentional decisions by programmers.

  • edited January 2015

    Class PGraphicsOpenGL overrides both PGraphics smooth() & noSmooth() in order to cap them:
    https://github.com/processing/processing/blob/master/core/src/processing/opengl/PGraphicsOpenGL.java#L3371

    What we can do is hack that class by subclassing it like I did below:
    http://forum.processing.org/two/discussion/8261/how-to-use-vertexfloat-v-

    Here's my simpler adaption of it. It resets both lastSmoothCall & smoothCallCount to some lower value: :ar!

    "HackedP3D.java":

    import processing.core.PApplet;
    import processing.opengl.PGraphics3D;
    
    public class HackedP3D extends PGraphics3D {
      public HackedP3D() {
        super();
      }
    
      public HackedP3D(int w, int h) {
        super();
        final PApplet p = getEnclosingPApplet();
        initialize(w, h, p, p.dataPath(""));
        ignite();
      }
    
      public HackedP3D(int w, int h, PApplet p) {
        super();
        initialize(w, h, p, p.dataPath(""));
        ignite();
      }
    
      public HackedP3D(int w, int h, PApplet p, String s) {
        super();
        initialize(w, h, p, s);
        ignite();
      }
    
      public void initialize(int w, int h, PApplet p, String s) {
        setParent(p);
        setPrimary(false);
        setPath(s);
        setSize(w, h);
      }
    
      public void ignite() {
        beginDraw();
        smooth(8);
        fill(-1);
        stroke(0);
        endDraw();
      }
    
      protected PApplet getEnclosingPApplet() {
        try {
          return (PApplet) getClass()
            .getDeclaredField("this$0").get(this);
        }
        catch (ReflectiveOperationException cause) {
          throw new RuntimeException(cause);
        }
      }
    
      @ Override public void smooth() {
        super.smooth();
        lastSmoothCall = smoothCallCount = -0100;
      }
    
      @ Override public void noSmooth() {
        super.noSmooth();
        lastSmoothCall = smoothCallCount = -0100;
      }
    
      @ Override public String toString() {
        return "Width: " + width + "\t Height: " + height
          + "\nPath:  " + path;
      }
    }
    


    "P3D_Subclass.pde":

    /**
     * P3D Subclass (v1.03)
     * by GoToLoop (2014/Dec/04)
     *
     * forum.processing.org/two/discussion/8261/
     * how-to-use-vertexfloat-v-
     *
     * forum.processing.org/two/discussion/6884/
     * question-about-pgraphics
     *
     * forum.processing.org/two/discussion/5858/
     * smooth-being-disabled-any-way-to-force-smooth
     */
    
    MyP3D pg;
    int w, h;
    
    void setup() {
      size(800, 600, P2D);
    
      frameRate(1);
      smooth(8);
      clear();
      imageMode(CORNER);
    
      println( pg = new MyP3D(width*3 >> 2, height*3 >> 2) );
      w = pg.width; 
      h = pg.height;
    
      pg.strokeWeight(3);
    }
    
    void draw() {
      final color c = (color) random(#000000);
    
      frame.setTitle("Frame: " + frameCount
        + "\t\tColor: #" + hex(c, 6));
    
      image(pg.script(c), width-w >> 1, height-h >> 1);
    }
    
    final class MyP3D extends HackedP3D {
      MyP3D(int w, int h) {
        super(w, h);
      }
    
      MyP3D(int w, int h, PApplet p) {
        super(w, h, p);
      }
    
      MyP3D script(color c) {
        beginDraw();
        background(c);
    
        smooth(1 << (int)random(5));
    
        fill(~c | ALPHA_MASK);
        ellipse(width>>1, height>>1, random(width), random(height));
    
        fill(#FF0000);
        beginShape(TRIANGLES);
        vertex(0, 0, -50);
        vertex(100, 0, -50);
        vertex(0, 100, -50);
        endShape();
    
        endDraw();
        return this;
      }
    }
    
  • Thanks for the reply. I confess I don't understand what's essential, here, and what's decoration/aimed at other issues. If my only objective is to override smooth() (a great suggestion), must I really subclass PGraphics3D twice, and include all this other business?

  • ... must I really subclass PGraphics3D twice...

    No! Class HackedP3D is enough! You can ignore the whole "P3D_Subclass.pde" test. :-B

  • Apologies, I'm still a bit confused. Simply including HackedP3D in my project is not enough (it appears). What else must I do? I'm hazy on how Processing sets up the graphics context for the user, obviously. Thanks for the assistance.

  • It's similar to createGraphics(), just pass width & height dimensions:
    http://processing.org/reference/createGraphics_.html

    Just like I did when instantiating MyP3D. Just replace it w/ HackedP3D:

    HackedP3D pg;
    pg = new HackedP3D(width*3 >> 2, height*3 >> 2);
    
Sign In or Register to comment.