Looped drawing and shaders: performance question

*Note I posted this in beginners but it would seem that its an advanced question - please read carefully before responding.

If you do:

void ofApp::setup() {
ofBackground(0);
ofSetColor (255);
ofDrawCircle(ofGetWidth() / 2, ofGetHeight() / 2, 400);
ofSetBackgroundAuto(false);
}
void ofApp::update() {}
void ofApp::draw() {}

You get the background drawn but not the circle. If you draw a circle in either update() or draw() you do get a circle. Am I right in assuming that unlike Processing all drawing has to be done in either update() or draw()? You can draw to buffer but that is still drawn in either update or draw.

Leading on from this, is it safe to assume that shaders cannot be accessed in setup? In other words if I want to make an image in say an fbo with a shader effect on it in setup I can’t do that.?

Given that the tutorials on shaders and graphics emphasise that moving information from the CPU to the GPU slows down processing time it seems inconsistent to me that the default method for doing so (continuously drawing in the draw loop) does precisely that (continuously sending drawing commands from the CPU to the GPU). I don’t mean this to be a criticism (I don’t understand enough to know whether it is a criticism or not).

I’m thinking of making a function like:

void ofApp::makeFbo(){

fbo1.begin();
ofClear(0, 0); // to make the buffer transparent
generate2000Circles(); // another function
fbo1.end();

fbo2.begin()
ofClear(0, 0); // to make the buffer transparent
shader.begin();
fbo1.draw();
shader.end();
fbo2.end();

}

and calling that once only during either an update or draw loop. Then drawing fbo2 in the draw loop. This seems pretty clunky and suggest to me that I’m not understanding something about how information is passed from CPU to GPU.

so my specific questions are:

  1. are the assumptions about drawing in update and draw correct?
  2. is there a saving in performance if a shader function is called once in situations where you want to draw a complex static image?

Thanks in advance
Peter Mc

ps it would be great if the shader examples included a way to blur drawn images - this is what has prompted all of this and its been very frustrating as many shader examples assume you are working with video (specially the blur shaders).

Hi .
setup() function is called once at the beginning of the application, this is the place to load images, shaders,fonts, initialization of the variables etc…

update() function is called after setup() , this is the place to update cameras, images, texture and other computation etc…

draw() function is called after update() and this is the place to draw anything you want to show on the screen.

In openFrameworks update() and draw() are called again and again in an infinite loop depending on the frame rate.

If you want to draw image effect with shader in fbo you can do:
In setup() -> load image, load shader and allocate fbo.
in update() ->
fbo.begin(); do calculation shader.begin(); access the shader uniforms, variables, textures draw image shader.end(); fbo.end();

in draw() ->
fbo.draw();

Hi Dorald
thanks for taking the time to give me a response. You don’t seem to have read my specific questions or understood what I was asking about. Maybe I should post this in advanced - its hard to know what level to go for.