background image costs lots of fps with p3d

hi everybody.

i have a p3d program, that gives me 40 fps when i define my background with "background(0,0,20)". when i use an image as background "background(pImage)" i get only 10 fps. is this drop in the framerate an expected behaviour? it seems way to much for me. the image is 1680px * 1050px (same dimension as the whole sketch). the image is loaded in the setup-function. i am running processing in version 2.2.1.

any help appreciated.

thanks martin

Tagged:

Answers

  • tested it in a basic sketch. i only get 14 fps. how can that be?

    PImage bg;
    
    void setup(){
      size(1680, 1050, P3D);
      smooth(8);
      frameRate(30000);
    
      bg = loadImage("bg.jpg");
    }
    
    void draw(){
        frame.setTitle(int(frameRate) + " fps");
    
        background(bg);
    }
    
  • Answer ✓

    Try getting rid of lines 5 and 6 then see what happens?

    Do you need a 3D renderer does P2D help?

    Also might try replacing line 14 with

    image(bg, 0, 0);
    

    Just some ideas I have no idea if these will help.

    In a situation like this is is always worthy experimenting with the code to try and get some hints as to the problem.

  • edited December 2014

    using image instead of backgroundmakes a big difference. now the test sketch gives me 300 fps. way better.

    but still strange. the test sketch runs at 400 fps when i do not use an image. 100 fps seems pretty costy for an image as background. maybe the reason is that the image is send over to the graphics card every frame. is there a way to avoid this? it's a static background. so it doesn't need to be send over every frame.

    thanks quark.

  • Renderer JAVA2D is currently the only 1 which isn't OpenGL.
    For JAVA2D, background() & set() would be much faster than image()! 8-}

  • ok, good to know. but i need my opengl/3d.

  • Answer ✓

    I tried the different options on my computer with Processing 2.2.1.

    Test settings

    • renderer: P3D
    • sketch dimensions: 1680 x 1050
    • image dimensions: 1680 x 1050
    • smooth level: 32

    Test results

    • nothing => 700+ fps
    • background(0, 0, 20); => 700+ fps

    • image(bg, 0, 0); => 500+ fps
    • beginShape-endShape (immediate) => 500+ fps
    • PShape (retained) => 500+ fps
    • PShader (shader) => 500+ fps
    • PShader (filter) => 400 fps

    • background(bg); => 60 fps

    So the only one that shows slowdown is background(bg). There are 5 other options that all give 400 or above fps. So whatever is causing this, I think the solution is fairly simple, use one of the other options.

  • cool. thanks for the effort. i will go on with the image-version.

    still looks like a bug to me. so i made an issue out of it: https://github.com/processing/processing/issues/3012

Sign In or Register to comment.